00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "tao/Object_KeyC.h"
00033 #include "tao/CDR.h"
00034 #include "tao/ORB_Core.h"
00035
00036 #if defined (__BORLANDC__)
00037 #pragma option -w-rvl -w-rch -w-ccc -w-aus -w-sig
00038 #endif
00039
00040 #include "ace/ACE.h"
00041 #include "ace/OS_NS_string.h"
00042 #include "ace/os_include/os_ctype.h"
00043
00044
00045
00046
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048
00049
00050 namespace TAO
00051 {
00052 }
00053
00054
00055
00056
00057
00058 #if !defined (_TAO_OBJECTKEY_CS_)
00059 #define _TAO_OBJECTKEY_CS_
00060
00061 TAO::ObjectKey::ObjectKey (void)
00062 {}
00063
00064 TAO::ObjectKey::ObjectKey (
00065 CORBA::ULong max
00066 )
00067 : TAO::unbounded_value_sequence<
00068 CORBA::Octet
00069 >
00070 (max)
00071 {}
00072
00073 TAO::ObjectKey::ObjectKey (
00074 CORBA::ULong max,
00075 CORBA::ULong length,
00076 CORBA::Octet * buffer,
00077 CORBA::Boolean release
00078 )
00079 : TAO::unbounded_value_sequence<
00080 CORBA::Octet
00081 >
00082 (max, length, buffer, release)
00083 {}
00084
00085 TAO::ObjectKey::ObjectKey (
00086 const ObjectKey &seq
00087 )
00088 : TAO::unbounded_value_sequence<
00089 CORBA::Octet
00090 >
00091 (seq)
00092 {}
00093
00094 TAO::ObjectKey::~ObjectKey (void)
00095 {}
00096
00097
00098
00099 void
00100 TAO::ObjectKey::encode_sequence_to_string (char * &str,
00101 const TAO::unbounded_value_sequence<CORBA::Octet> &seq)
00102 {
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 u_int len = 3 * seq.length (); ;
00113 str = CORBA::string_alloc (len);
00114
00115 char *cp = str;
00116
00117 for (u_int i = 0;
00118 cp < (str + len) && i < seq.length();
00119 ++i)
00120 {
00121 u_char bt = seq[i];
00122 if (is_legal (bt))
00123 {
00124 *cp++ = (char) bt;
00125 continue;
00126 }
00127
00128 *cp++ = '%';
00129 *cp++ = ACE::nibble2hex ((bt >> 4) & 0x0f);
00130 *cp++ = ACE::nibble2hex (bt & 0x0f);
00131 }
00132
00133 *cp = '\0';
00134 }
00135
00136 int TAO::ObjectKey::is_legal (u_char & c)
00137 {
00138 if (isalnum(c))
00139 {
00140 return 1;
00141 }
00142 else
00143 {
00144 return ( c == ';' || c == '/' ||c == ':' || c == '?' ||
00145 c == '@' || c == '&' ||c == '=' || c == '+' ||
00146 c == '$' || c == ',' ||c == '_' || c == '.' ||
00147 c == '!' || c == '~' ||c == '*' || c == '\'' ||
00148 c == '-' || c == '(' || c == ')' );
00149 }
00150 }
00151
00152 void
00153 TAO::ObjectKey::decode_string_to_sequence (TAO::unbounded_value_sequence<CORBA::Octet> &seq,
00154 const char *str)
00155 {
00156 if (str == 0)
00157 {
00158 seq.length (0);
00159 return;
00160 }
00161
00162 size_t length = ACE_OS::strlen (str);
00163 const char *eos = str + length;
00164 const char *cp = str;
00165
00166
00167
00168
00169 seq.length (length);
00170
00171 u_int i = 0;
00172 for (;
00173 cp < eos && i < seq.length ();
00174 ++i)
00175 {
00176 if (*cp == '%' || *cp == '\\')
00177 {
00178
00179
00180
00181 seq[i] = (u_char) (ACE::hex2byte (cp[1]) << 4);
00182 seq[i] |= (u_char) ACE::hex2byte (cp[2]);
00183 cp += 3;
00184 }
00185 else
00186
00187 seq[i] = *cp++;
00188 }
00189
00190
00191 seq.length (i);
00192 }
00193
00194 CORBA::Boolean
00195 TAO::ObjectKey::demarshal_key (TAO::ObjectKey &key,
00196 TAO_InputCDR &strm)
00197 {
00198 CORBA::ULong _tao_seq_len;
00199
00200 if (strm >> _tao_seq_len)
00201 {
00202
00203
00204
00205 if (_tao_seq_len > strm.length ())
00206 {
00207 return 0;
00208 }
00209
00210
00211 key.length (_tao_seq_len);
00212
00213
00214 if (0 >= _tao_seq_len)
00215 {
00216 return 1;
00217 }
00218
00219
00220 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00221 if (ACE_BIT_DISABLED (strm.start ()->flags (),
00222 ACE_Message_Block::DONT_DELETE))
00223 {
00224 key.replace (_tao_seq_len, strm.start ());
00225 key.mb ()->wr_ptr (key.mb()->rd_ptr () + _tao_seq_len);
00226 strm.skip_bytes (_tao_seq_len);
00227 return 1;
00228 }
00229 return strm.read_octet_array (key.get_buffer (),
00230 _tao_seq_len);
00231 #else
00232 return strm.read_octet_array (key.get_buffer (), key.length ());
00233 #endif
00234
00235 }
00236 return 0;
00237 }
00238
00239 #endif
00240
00241
00242
00243
00244 #if !defined _TAO_CDR_OP_TAO_ObjectKey_CPP_
00245 #define _TAO_CDR_OP_TAO_ObjectKey_CPP_
00246
00247 CORBA::Boolean operator<< (
00248 TAO_OutputCDR &strm,
00249 const TAO::ObjectKey &_tao_sequence
00250 )
00251 {
00252 return TAO::marshal_sequence(strm, _tao_sequence);
00253 }
00254
00255 CORBA::Boolean operator>> (
00256 TAO_InputCDR &strm,
00257 TAO::ObjectKey &_tao_sequence
00258 )
00259 {
00260 return TAO::demarshal_sequence(strm, _tao_sequence);
00261 }
00262
00263 #endif
00264
00265 TAO_END_VERSIONED_NAMESPACE_DECL