Go to the documentation of this file.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 "$Id: GIOP_Message_State.cpp 88871 2010-02-06 13:52:31Z mcorino $")
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 int
00020 TAO_GIOP_Message_State::parse_message_header (ACE_Message_Block &incoming)
00021 {
00022 if (incoming.length () >= TAO_GIOP_MESSAGE_HEADER_LEN)
00023 {
00024
00025 return this->parse_message_header_i (incoming);
00026 }
00027
00028
00029
00030 return 1;
00031 }
00032
00033 int
00034 TAO_GIOP_Message_State::parse_message_header_i (ACE_Message_Block &incoming)
00035 {
00036 if (TAO_debug_level > 8)
00037 {
00038 ACE_DEBUG ((LM_DEBUG,
00039 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::parse_message_header_i\n")
00040 ));
00041 }
00042
00043 char * const buf = incoming.rd_ptr ();
00044
00045 if (this->parse_magic_bytes (buf) == -1
00046 || this->get_version_info (buf) == -1
00047 || this->get_byte_order_info (buf) == -1)
00048 {
00049 return -1;
00050 }
00051
00052
00053 this->message_type_ =
00054 static_cast <GIOP::MsgType> (buf[TAO_GIOP_MESSAGE_TYPE_OFFSET]);
00055
00056
00057 this->get_payload_size (buf);
00058
00059 if (this->payload_size_ == 0)
00060 {
00061 switch (this->message_type_)
00062 {
00063 case GIOP::MessageError:
00064 case GIOP::CloseConnection:
00065 if (TAO_debug_level > 0)
00066 {
00067 char const * const which =
00068 (this->message_type_ == GIOP::CloseConnection) ? "CloseConnection" :
00069 (this->message_type_ == GIOP::MessageError) ? "MessageError" : "unknown";
00070 ACE_DEBUG ((LM_DEBUG,
00071 ACE_TEXT ("TAO (%P|%t) - GIOP %C received\n"), which));
00072 }
00073 return 0;
00074 default:
00075 if (TAO_debug_level > 0)
00076 ACE_DEBUG ((LM_DEBUG,
00077 ACE_TEXT ("TAO (%P|%t) - ")
00078 ACE_TEXT ("TAO_GIOP_Message_State::parse_magic_bytes, ")
00079 ACE_TEXT ("Message of size zero recd.\n")));
00080 return -1;
00081 }
00082 }
00083
00084 return 0;
00085 }
00086
00087 int
00088 TAO_GIOP_Message_State::parse_magic_bytes (char *buf)
00089 {
00090 if (!((buf [0] == 0x5A || buf [0] == 0x47)
00091 && buf [1] == 0x49
00092 && buf [2] == 0x4f
00093 && buf [3] == 0x50))
00094 {
00095 if (TAO_debug_level > 0)
00096 ACE_DEBUG ((LM_DEBUG,
00097 ACE_TEXT ("TAO (%P|%t) - ")
00098 ACE_TEXT ("TAO_GIOP_Message_State::parse_magic_bytes, ")
00099 ACE_TEXT ("bad %cIOP header: ")
00100 ACE_TEXT ("magic word [%02x,%02x,%02x,%02x]\n"),
00101 buf[0],
00102 buf[0],
00103 buf[1],
00104 buf[2],
00105 buf[3]));
00106 return -1;
00107 }
00108 return 0;
00109 }
00110
00111 int
00112 TAO_GIOP_Message_State::get_version_info (char *buf)
00113 {
00114 if (TAO_debug_level > 8)
00115 {
00116 ACE_DEBUG ((LM_DEBUG,
00117 "TAO (%P|%t) - GIOP_Message_State::get_version_info\n"));
00118 }
00119
00120
00121 CORBA::Octet incoming_major = buf[TAO_GIOP_VERSION_MAJOR_OFFSET];
00122 CORBA::Octet incoming_minor = buf[TAO_GIOP_VERSION_MINOR_OFFSET];
00123
00124
00125 if (TAO_GIOP_Message_Generator_Parser_Impl::check_revision (
00126 incoming_major,
00127 incoming_minor) == 0)
00128 {
00129 if (TAO_debug_level > 0)
00130 {
00131 ACE_DEBUG ((LM_DEBUG,
00132 ACE_TEXT ("TAO (%P|%t) - bad version <%d.%d>\n"),
00133 incoming_major, incoming_minor));
00134 }
00135
00136 return -1;
00137 }
00138
00139
00140 this->giop_version_.minor = incoming_minor;
00141 this->giop_version_.major = incoming_major;
00142
00143 return 0;
00144 }
00145
00146 int
00147 TAO_GIOP_Message_State::get_byte_order_info (char *buf)
00148 {
00149 if (TAO_debug_level > 8)
00150 {
00151 ACE_DEBUG ((LM_DEBUG,
00152 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info\n") ));
00153 }
00154
00155
00156 if (this->giop_version_.minor == 0 && this->giop_version_.major == 1)
00157 {
00158 this->byte_order_ =
00159 buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET];
00160
00161 if (this->byte_order_ != 0 && this->byte_order_ != 1)
00162 {
00163 if (TAO_debug_level > 2)
00164 {
00165 ACE_DEBUG ((LM_DEBUG,
00166 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info, ")
00167 ACE_TEXT ("invalid byte order <%d> for version <1.0>\n"),
00168 this->byte_order_));
00169 }
00170 return -1;
00171 }
00172 }
00173 else
00174 {
00175
00176 this->byte_order_ =
00177 (CORBA::Octet) (buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET]& 0x01);
00178
00179
00180 this->more_fragments_ =
00181 ((buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET]& 0x02) == 2);
00182
00183 this->compressed_ = (buf[0] == 0x5A);
00184 }
00185
00186 return 0;
00187 }
00188
00189 void
00190 TAO_GIOP_Message_State::get_payload_size (char *rd_ptr)
00191 {
00192
00193 rd_ptr += TAO_GIOP_MESSAGE_SIZE_OFFSET;
00194
00195 this->payload_size_ = this->read_ulong (rd_ptr);
00196 }
00197
00198 CORBA::ULong
00199 TAO_GIOP_Message_State::read_ulong (const char *rd_ptr) const
00200 {
00201 CORBA::ULong x = 0;
00202
00203
00204
00205
00206
00207 char buf[] =
00208 {
00209 *rd_ptr,
00210 *(rd_ptr + 1),
00211 *(rd_ptr + 2),
00212 *(rd_ptr + 3)
00213 };
00214
00215 #if !defined (ACE_DISABLE_SWAP_ON_READ)
00216 if (!(this->byte_order_ != ACE_CDR_BYTE_ORDER))
00217 {
00218 ACE_CDR::ULong* pul = reinterpret_cast<ACE_CDR::ULong*> (buf);
00219 x = *pul;
00220 }
00221 else
00222 {
00223 ACE_CDR::swap_4 (buf, reinterpret_cast<char*> (&x));
00224 }
00225 #else
00226 x = *reinterpret_cast<ACE_CDR::ULong*> (buf);
00227 #endif
00228
00229 return x;
00230 }
00231
00232 TAO_END_VERSIONED_NAMESPACE_DECL