00001
00002
00003 #include "tao/GIOP_Message_State.h"
00004 #include "tao/debug.h"
00005 #include "tao/GIOP_Message_Base.h"
00006
00007 #include "ace/Log_Msg.h"
00008
00009 #if !defined (__ACE_INLINE__)
00010 # include "tao/GIOP_Message_State.inl"
00011 #endif
00012
00013 ACE_RCSID (tao,
00014 GIOP_Message_State,
00015 "GIOP_Message_State.cpp,v 1.28 2006/05/16 12:30:35 jwillemsen Exp")
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO_GIOP_Message_State::TAO_GIOP_Message_State (void)
00020 : giop_version_ (TAO_DEF_GIOP_MAJOR,
00021 TAO_DEF_GIOP_MINOR),
00022 byte_order_ (0),
00023 message_type_ (0),
00024 message_size_ (0),
00025 more_fragments_ (0),
00026 missing_data_ (0)
00027 {
00028 }
00029
00030
00031 int
00032 TAO_GIOP_Message_State::parse_message_header (ACE_Message_Block &incoming)
00033 {
00034 if (incoming.length () >= TAO_GIOP_MESSAGE_HEADER_LEN)
00035 {
00036
00037 return this->parse_message_header_i (incoming);
00038 }
00039
00040
00041
00042 return 1;
00043 }
00044
00045 int
00046 TAO_GIOP_Message_State::parse_message_header_i (ACE_Message_Block &incoming)
00047 {
00048 if (TAO_debug_level > 8)
00049 {
00050 ACE_DEBUG ((LM_DEBUG,
00051 "TAO (%P|%t) - GIOP_Message_State::parse_message_header_i\n"
00052 ));
00053 }
00054
00055
00056 char *buf = incoming.rd_ptr ();
00057
00058
00059 if (this->parse_magic_bytes (buf) == -1)
00060 {
00061 return -1;
00062 }
00063
00064
00065 if (this->get_version_info (buf) == -1)
00066 return -1;
00067
00068
00069 if (this->get_byte_order_info (buf) == -1)
00070 return -1;
00071
00072
00073 this->message_type_ = buf[TAO_GIOP_MESSAGE_TYPE_OFFSET];
00074
00075
00076 this->get_payload_size (buf);
00077
00078 if (this->message_size_ == 0)
00079 {
00080 if (this->message_type_ == TAO_GIOP_MESSAGERROR)
00081 {
00082 if (TAO_debug_level > 0)
00083 {
00084 ACE_DEBUG ((LM_DEBUG,
00085 "TAO (%P|%t) -"
00086 "GIOP_MESSAGE_ERROR received \n"));
00087 }
00088 return 0;
00089 }
00090 else
00091 {
00092 if (TAO_debug_level > 0)
00093 ACE_DEBUG ((LM_DEBUG,
00094 "TAO (%P|%t) - "
00095 "Message of size zero recd. \n"));
00096 return -1;
00097 }
00098 }
00099
00100 return 0;
00101 }
00102
00103
00104
00105
00106 int
00107 TAO_GIOP_Message_State::parse_magic_bytes (char *buf)
00108 {
00109
00110 if (!(buf [0] == 0x47
00111 && buf [1] == 0x49
00112 && buf [2] == 0x4f
00113 && buf [3] == 0x50))
00114 {
00115 if (TAO_debug_level > 0)
00116 ACE_DEBUG ((LM_DEBUG,
00117 ACE_TEXT ("TAO (%P|%t) - ")
00118 ACE_TEXT ("TAO_GIOP_Message_State::parse_magic_bytes, ")
00119 ACE_TEXT ("bad header: ")
00120 ACE_TEXT ("magic word [%02x,%02x,%02x,%02x]\n"),
00121 buf[0],
00122 buf[1],
00123 buf[2],
00124 buf[3]));
00125 return -1;
00126 }
00127
00128 return 0;
00129 }
00130
00131 int
00132 TAO_GIOP_Message_State::get_version_info (char *buf)
00133 {
00134 if (TAO_debug_level > 8)
00135 {
00136 ACE_DEBUG ((LM_DEBUG,
00137 "TAO (%P|%t) - GIOP_Message_State::get_version_info\n"));
00138 }
00139
00140
00141 CORBA::Octet incoming_major =
00142 buf[TAO_GIOP_VERSION_MAJOR_OFFSET];
00143 CORBA::Octet incoming_minor =
00144 buf[TAO_GIOP_VERSION_MINOR_OFFSET];
00145
00146
00147 if (TAO_GIOP_Message_Generator_Parser_Impl::check_revision (
00148 incoming_major,
00149 incoming_minor) == 0)
00150 {
00151 if (TAO_debug_level > 0)
00152 {
00153 ACE_DEBUG ((LM_DEBUG,
00154 ACE_TEXT ("TAO (%P|%t) - bad version <%d.%d>\n"),
00155 incoming_major, incoming_minor));
00156 }
00157
00158 return -1;
00159 }
00160
00161
00162 this->giop_version_.minor = incoming_minor;
00163 this->giop_version_.major = incoming_major;
00164
00165 return 0;
00166 }
00167
00168 int
00169 TAO_GIOP_Message_State::get_byte_order_info (char *buf)
00170 {
00171 if (TAO_debug_level > 8)
00172 {
00173 ACE_DEBUG ((LM_DEBUG,
00174 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info\n") ));
00175 }
00176
00177
00178 if (this->giop_version_.minor == 0 &&
00179 this->giop_version_.major == 1)
00180 {
00181 this->byte_order_ =
00182 buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET];
00183
00184 if (this->byte_order_ != 0 &&
00185 this->byte_order_ != 1)
00186 {
00187 if (TAO_debug_level > 2)
00188 {
00189 ACE_DEBUG ((LM_DEBUG,
00190 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info, ")
00191 ACE_TEXT ("invalid byte order <%d> for version <1.0>\n"),
00192 this->byte_order_));
00193 }
00194 return -1;
00195 }
00196 }
00197 else
00198 {
00199
00200 this->byte_order_ =
00201 (CORBA::Octet) (buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET]& 0x01);
00202
00203
00204 this->more_fragments_ =
00205 (CORBA::Octet) (buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET]& 0x02);
00206
00207 if ((buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET] & ~0x3) != 0)
00208 {
00209 if (TAO_debug_level > 2)
00210 {
00211 ACE_DEBUG ((LM_DEBUG,
00212 ACE_TEXT ("TAO (%P|%t) - invalid flags for <%d> ")
00213 ACE_TEXT ("for version <%d %d> \n"),
00214 buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET],
00215 this->giop_version_.major,
00216 this->giop_version_.minor));
00217 }
00218 return -1;
00219 }
00220 }
00221
00222 return 0;
00223 }
00224
00225 void
00226 TAO_GIOP_Message_State::get_payload_size (char *rd_ptr)
00227 {
00228
00229 rd_ptr += TAO_GIOP_MESSAGE_SIZE_OFFSET;
00230
00231 this->message_size_ = this->read_ulong (rd_ptr);
00232 }
00233
00234 CORBA::ULong
00235 TAO_GIOP_Message_State::read_ulong (const char *rd_ptr) const
00236 {
00237 CORBA::ULong x = 0;
00238
00239
00240
00241
00242
00243 char buf[] =
00244 {
00245 *rd_ptr,
00246 *(rd_ptr + 1),
00247 *(rd_ptr + 2),
00248 *(rd_ptr + 3)
00249 };
00250
00251 #if !defined (ACE_DISABLE_SWAP_ON_READ)
00252 if (!(this->byte_order_ != ACE_CDR_BYTE_ORDER))
00253 {
00254 x = *reinterpret_cast<ACE_CDR::ULong*> (buf);
00255 }
00256 else
00257 {
00258 ACE_CDR::swap_4 (buf, reinterpret_cast<char*> (&x));
00259 }
00260 #else
00261 x = *reinterpret_cast<ACE_CDR::ULong*> (buf);
00262 #endif
00263
00264 return x;
00265 }
00266
00267 TAO_END_VERSIONED_NAMESPACE_DECL