Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / diffs / Object_Key.diff
blob0d05fbf5890eddc59c23b25aa35633ec0a9f40b5
1 --- orig/Object_KeyC.cpp 2008-03-27 08:12:27.000000000 -0500
2 +++ Object_KeyC.cpp 2008-03-27 08:13:40.000000000 -0500
3 @@ -37,6 +37,11 @@
4 #pragma option -w-rvl -w-rch -w-ccc -w-aus -w-sig
5 #endif /* __BORLANDC__ */
7 +#include "ace/ACE.h"
8 +#include "ace/Truncate.h"
9 +#include "ace/OS_NS_string.h"
10 +#include "ace/os_include/os_ctype.h"
12 // TAO_IDL - Generated from
13 // be\be_visitor_arg_traits.cpp:70
15 @@ -90,6 +95,159 @@
16 TAO::ObjectKey::~ObjectKey (void)
19 +// Hand crafted.
21 +void
22 +TAO::ObjectKey::encode_sequence_to_string (char* & str,
23 + TAO::unbounded_value_sequence<CORBA::Octet> const & seq)
25 + // We must allocate a buffer which is (gag) 3 times the length
26 + // of the sequence, which is the length required in the worst-case
27 + // scenario of all non-printable characters.
28 + //
29 + // There are two strategies here...we could allocate all that space here,
30 + // fill it up, then copy-allocate new space of just the right length.
31 + // OR, we could just return this space. The classic time-space tradeoff,
32 + // and for now we'll let time win out, which means that we only do the
33 + // allocation once.
34 + CORBA::ULong const seq_len = seq.length ();
35 + CORBA::ULong const len = 3 * seq_len; /* space for zero termination
36 + not needed */
37 + str = CORBA::string_alloc (len);
39 + char * const eos = str + len;
40 + char * cp = str;
42 + for (CORBA::ULong i = 0;
43 + cp < eos && i < seq_len;
44 + ++i)
45 + {
46 + unsigned char bt = seq[i];
47 + if (is_legal (bt))
48 + {
49 + *cp++ = static_cast<char> (bt);
50 + continue;
51 + }
53 + *cp++ = '%';
54 + *cp++ = static_cast<char> (ACE::nibble2hex ((bt >> 4) & 0x0f));
55 + *cp++ = static_cast<char> (ACE::nibble2hex (bt & 0x0f));
56 + }
57 + // Zero terminate
58 + *cp = '\0';
61 +CORBA::Boolean
62 +TAO::ObjectKey::is_legal (unsigned char c)
64 + if (isalnum (c))
65 + {
66 + return true;
67 + }
68 + else
69 + {
70 + return ( c == ';' || c == '/' ||c == ':' || c == '?' ||
71 + c == '@' || c == '&' ||c == '=' || c == '+' ||
72 + c == '$' || c == ',' ||c == '_' || c == '.' ||
73 + c == '!' || c == '~' ||c == '*' || c == '\'' ||
74 + c == '-' || c == '(' || c == ')' );
75 + }
78 +void
79 +TAO::ObjectKey::decode_string_to_sequence (
80 + TAO::unbounded_value_sequence<CORBA::Octet> & seq,
81 + char const * str)
83 + if (str == 0)
84 + {
85 + seq.length (0);
86 + return;
87 + }
89 + size_t const str_len = ACE_OS::strlen (str);
91 + // Ensure sequence length value does not exceed maximum value for
92 + // sequence index type (CORBA::ULong). This is mostly an issue for
93 + // 64-bit MS Windows builds.
94 + CORBA::ULong const len =
95 + ACE_Utils::truncate_cast<CORBA::ULong> (str_len);
97 + char const * const eos = str + str_len;
98 + char const * cp = str;
100 + // Set the length of the sequence to be as long as we'll possibly
101 + // need...we'll reset it to the actual length later.
102 + seq.length (len);
104 + CORBA::ULong i = 0;
105 + for (;
106 + cp < eos && i < len;
107 + ++i)
109 + if (*cp == '%' || *cp == '\\')
111 + // This is an escaped non-printable,
112 + // so we decode the hex values into
113 + // the sequence's octet
114 + seq[i] = static_cast<CORBA::Octet> (ACE::hex2byte (cp[1]) << 4);
115 + seq[i] |= static_cast<CORBA::Octet> (ACE::hex2byte (cp[2]));
116 + cp += 3;
118 + else
119 + // Copy it in
120 + seq[i] = *cp++;
123 + // Set the length appropriately
124 + seq.length (i);
127 +/*static*/ CORBA::Boolean
128 +TAO::ObjectKey::demarshal_key (TAO::ObjectKey &key,
129 + TAO_InputCDR &strm)
131 + CORBA::ULong _tao_seq_len;
133 + if (strm >> _tao_seq_len)
135 + // Add a check to the length of the sequence
136 + // to make sure it does not exceed the length
137 + // of the stream. (See bug 58.)
138 + if (_tao_seq_len > strm.length ())
140 + return 0;
143 + // Set the length of the sequence.
144 + key.length (_tao_seq_len);
146 + // If length is 0 we return true.
147 + if (0 >= _tao_seq_len)
149 + return 1;
152 + // Retrieve all the elements.
153 +#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
154 + if (ACE_BIT_DISABLED (strm.start ()->flags (),
155 + ACE_Message_Block::DONT_DELETE))
157 + key.replace (_tao_seq_len, strm.start ());
158 + key.mb ()->wr_ptr (key.mb()->rd_ptr () + _tao_seq_len);
159 + strm.skip_bytes (_tao_seq_len);
160 + return 1;
162 + return strm.read_octet_array (key.get_buffer (),
163 + _tao_seq_len);
164 +#else /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
165 + return strm.read_octet_array (key.get_buffer (), key.length ());
166 +#endif /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
169 + return 0;
172 #endif /* end #if !defined */
174 // TAO_IDL - Generated from
175 --- orig/Object_KeyC.h 2008-03-27 08:13:22.000000000 -0500
176 +++ Object_KeyC.h 2008-03-27 08:13:40.000000000 -0500
177 @@ -117,6 +117,24 @@
178 : TAO::unbounded_value_sequence<CORBA::Octet> (length, mb) {}
179 #endif /* TAO_NO_COPY_OCTET_SEQUENCE == 1 */
181 + // Hand crafted.
183 + static void encode_sequence_to_string (
184 + char* & str,
185 + TAO::unbounded_value_sequence<CORBA::Octet> const & seq
186 + );
187 + static void decode_string_to_sequence (
188 + TAO::unbounded_value_sequence<CORBA::Octet> &seq,
189 + char const * str
190 + );
191 + static CORBA::Boolean is_legal (unsigned char c);
193 + /// A special method that gives no regard to how the ORB has
194 + /// configured the resource factory. This will be used only
195 + /// during Profile decoding and should be safe. This is a solution
196 + /// for the bug report [Bug 1616]
197 + static CORBA::Boolean demarshal_key (ObjectKey & key,
198 + TAO_InputCDR & cdr);
201 #endif /* end #if !defined */