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