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