1 #include "tao/GIOP_Message_State.h"
3 #include "tao/GIOP_Message_Base.h"
5 #include "ace/Log_Msg.h"
7 #if !defined (__ACE_INLINE__)
8 # include "tao/GIOP_Message_State.inl"
9 #endif /* __ACE_INLINE__ */
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO_GIOP_Message_State::parse_message_header (ACE_Message_Block
&incoming
)
16 if (incoming
.length () >= TAO_GIOP_MESSAGE_HEADER_LEN
)
18 // Parse the GIOP header
19 return this->parse_message_header_i (incoming
);
22 // One indicates that we didn't have enough data in the message to
28 TAO_GIOP_Message_State::parse_message_header_i (ACE_Message_Block
&incoming
)
30 if (TAO_debug_level
> 8)
32 TAOLIB_DEBUG ((LM_DEBUG
,
33 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::parse_message_header_i\n")
37 char * const buf
= incoming
.rd_ptr ();
39 if (this->parse_magic_bytes (buf
) == -1 // Parse magic bytes first
40 || this->get_version_info (buf
) == -1 // Get version information
41 || this->get_byte_order_info (buf
) == -1) // Get byte order information
46 // Get the message type
48 static_cast <GIOP::MsgType
> (buf
[TAO_GIOP_MESSAGE_TYPE_OFFSET
]);
50 // Get the size of the message..
51 this->get_payload_size (buf
);
53 if (this->payload_size_
== 0)
55 switch (this->message_type_
)
57 case GIOP::MessageError
:
58 case GIOP::CloseConnection
:
59 if (TAO_debug_level
> 0)
61 char const * const which
=
62 (this->message_type_
== GIOP::CloseConnection
) ? "CloseConnection" :
63 (this->message_type_
== GIOP::MessageError
) ? "MessageError" : "unknown";
64 TAOLIB_DEBUG ((LM_DEBUG
,
65 ACE_TEXT ("TAO (%P|%t) - GIOP %C received\n"), which
));
69 if (TAO_debug_level
> 0)
70 TAOLIB_DEBUG ((LM_DEBUG
,
71 ACE_TEXT ("TAO (%P|%t) - ")
72 ACE_TEXT ("TAO_GIOP_Message_State::parse_magic_bytes, ")
73 ACE_TEXT ("Message of size zero recd.\n")));
82 TAO_GIOP_Message_State::parse_magic_bytes (char *buf
)
84 if (!((buf
[0] == 0x5A || buf
[0] == 0x47) // 'Z' or 'G' (depending on compression)
85 && buf
[1] == 0x49 // 'I'
86 && buf
[2] == 0x4f // 'O'
87 && buf
[3] == 0x50)) // 'P'
89 if (TAO_debug_level
> 0)
90 TAOLIB_ERROR ((LM_ERROR
,
91 ACE_TEXT ("TAO (%P|%t) - ")
92 ACE_TEXT ("TAO_GIOP_Message_State::parse_magic_bytes, ")
93 ACE_TEXT ("bad %cIOP header: ")
94 ACE_TEXT ("magic word [%02x,%02x,%02x,%02x]\n"),
106 TAO_GIOP_Message_State::get_version_info (char *buf
)
108 if (TAO_debug_level
> 8)
110 TAOLIB_DEBUG ((LM_DEBUG
,
111 "TAO (%P|%t) - GIOP_Message_State::get_version_info\n"));
114 // We have a GIOP message on hand. Get its revision numbers
115 CORBA::Octet
const incoming_major
= buf
[TAO_GIOP_VERSION_MAJOR_OFFSET
];
116 CORBA::Octet
const incoming_minor
= buf
[TAO_GIOP_VERSION_MINOR_OFFSET
];
118 // Check the revision information
119 if (TAO_GIOP_Message_Generator_Parser_Impl::check_revision (
121 incoming_minor
) == 0)
123 if (TAO_debug_level
> 0)
125 TAOLIB_DEBUG ((LM_DEBUG
,
126 ACE_TEXT ("TAO (%P|%t) - bad version <%d.%d>\n"),
127 incoming_major
, incoming_minor
));
134 this->giop_version_
.minor
= incoming_minor
;
135 this->giop_version_
.major
= incoming_major
;
141 TAO_GIOP_Message_State::get_byte_order_info (char *buf
)
143 if (TAO_debug_level
> 8)
145 TAOLIB_DEBUG ((LM_DEBUG
,
146 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info\n") ));
149 // Let us be specific that this is for 1.0
150 if (this->giop_version_
.minor
== 0 && this->giop_version_
.major
== 1)
153 buf
[TAO_GIOP_MESSAGE_FLAGS_OFFSET
];
155 if (this->byte_order_
!= 0 && this->byte_order_
!= 1)
157 if (TAO_debug_level
> 2)
159 TAOLIB_DEBUG ((LM_DEBUG
,
160 ACE_TEXT ("TAO (%P|%t) - GIOP_Message_State::get_byte_order_info, ")
161 ACE_TEXT ("invalid byte order <%d> for version <1.0>\n"),
169 // Read the byte ORDER
171 (CORBA::Octet
) (buf
[TAO_GIOP_MESSAGE_FLAGS_OFFSET
]& 0x01);
173 // Read the fragment bit
174 this->more_fragments_
=
175 ((buf
[TAO_GIOP_MESSAGE_FLAGS_OFFSET
]& 0x02) == 2);
177 this->compressed_
= (buf
[0] == 0x5A);
184 TAO_GIOP_Message_State::get_payload_size (char *rd_ptr
)
186 // Move the read pointer
187 rd_ptr
+= TAO_GIOP_MESSAGE_SIZE_OFFSET
;
189 this->payload_size_
= this->read_ulong (rd_ptr
);
193 TAO_GIOP_Message_State::read_ulong (const char *rd_ptr
) const
197 // We don't need to do this sort of copy. But some compilers (read it
198 // as SunCC) have a problem in deferencing from the
199 // reinterpret_cast pointer of the <rd_ptr>, as the <rd_ptr> can be
200 // on stack. So let us go ahead with this copying...
209 #if !defined (ACE_DISABLE_SWAP_ON_READ)
210 if (!(this->byte_order_
!= ACE_CDR_BYTE_ORDER
))
212 ACE_CDR::ULong
* pul
= reinterpret_cast<ACE_CDR::ULong
*> (buf
);
217 ACE_CDR::swap_4 (buf
, reinterpret_cast<char*> (&x
));
220 x
= *reinterpret_cast<ACE_CDR::ULong
*> (buf
);
221 #endif /* ACE_DISABLE_SWAP_ON_READ */
226 TAO_END_VERSIONED_NAMESPACE_DECL