summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_State.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/GIOP_Message_State.cpp')
-rw-r--r--TAO/tao/GIOP_Message_State.cpp239
1 files changed, 124 insertions, 115 deletions
diff --git a/TAO/tao/GIOP_Message_State.cpp b/TAO/tao/GIOP_Message_State.cpp
index f9c7fbeda1a..e3a3ca20bf3 100644
--- a/TAO/tao/GIOP_Message_State.cpp
+++ b/TAO/tao/GIOP_Message_State.cpp
@@ -5,65 +5,20 @@
#include "tao/GIOP_Message_Base.h"
#include "ace/Log_Msg.h"
-#include "ace/OS_NS_string.h"
#if !defined (__ACE_INLINE__)
# include "tao/GIOP_Message_State.inl"
#endif /* __ACE_INLINE__ */
-
-class TAO_Debug_Msg_Emitter_Guard
-{
-public:
- TAO_Debug_Msg_Emitter_Guard (unsigned int debug_level, const char* msg)
- : which_level_(debug_level)
- {
- if (TAO_debug_level < this->which_level_)
- {
- msg_ = 0;
- return;
- }
-
- this->msg_ = new char[ACE_OS::strlen (msg) + MAGIC_LENGTH ];
- ACE_OS::strcpy (this->msg_, msg);
- ACE_OS::strcat (this->msg_, " begin\n");
-
- if (TAO_debug_level >= this->which_level_)
- {
- ACE_DEBUG ((LM_DEBUG, this->msg_ ));
- }
- }
-
- ~TAO_Debug_Msg_Emitter_Guard ()
- {
- if (this->msg_)
- {
- if (TAO_debug_level >= this->which_level_)
- {
- char* begin_start =
- this->msg_ + ACE_OS::strlen(this->msg_) - MAGIC_LENGTH + 1;
- ACE_OS::strcpy (begin_start, " end\n");
- ACE_DEBUG ((LM_DEBUG, this->msg_));
- }
-
- delete[] this->msg_;
- }
- }
-
-private:
- static const int MAGIC_LENGTH;
- unsigned int which_level_;
- char* msg_;
-};
-
-const int TAO_Debug_Msg_Emitter_Guard::MAGIC_LENGTH = 8; // " begin\n" + \000
-
-ACE_RCSID(tao, GIOP_Message_State, "$Id$")
+ACE_RCSID (tao,
+ GIOP_Message_State,
+ "$Id$")
TAO_GIOP_Message_State::TAO_GIOP_Message_State (
TAO_ORB_Core * /*orb_core*/,
- TAO_GIOP_Message_Base * /*base*/)
- : giop_version_ (TAO_DEF_GIOP_MAJOR,
+ TAO_GIOP_Message_Base *base)
+ : base_ (base),
+ giop_version_ (TAO_DEF_GIOP_MAJOR,
TAO_DEF_GIOP_MINOR),
byte_order_ (0),
message_type_ (0),
@@ -74,79 +29,125 @@ TAO_GIOP_Message_State::TAO_GIOP_Message_State (
{
}
-// This doesn't check the message block's length, so that means that
-// the *caller* needs to do that first.
+
int
-TAO_GIOP_Message_State::take_values_from_message_block (
- const ACE_Message_Block& mb
- )
+TAO_GIOP_Message_State::parse_message_header (ACE_Message_Block &incoming)
{
- const char* buf = mb.rd_ptr ();
+ if (incoming.length () >= TAO_GIOP_MESSAGE_HEADER_LEN)
+ {
+ // Parse the GIOP header
+ if (this->parse_message_header_i (incoming) == -1)
+ return -1;
+ }
- // Get the version information
- if (this->set_version_info_from_buffer (buf) == -1)
+ return 0;
+}
+
+int
+TAO_GIOP_Message_State::parse_message_header_i (ACE_Message_Block &incoming)
+{
+ if (TAO_debug_level > 8)
{
- return -1;
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) - GIOP_Message_State::parse_message_header_i\n"
+ ));
}
- // Get the byte order information...
- if (this->set_byte_order_info_from_buffer (buf) == -1)
+ // Grab the rd_ptr_ from the message block..
+ char *buf = incoming.rd_ptr ();
+
+ // Parse the magic bytes first
+ if (this->parse_magic_bytes (buf) == -1)
{
return -1;
}
+ // Get the version information
+ if (this->get_version_info (buf) == -1)
+ return -1;
+
+ // Get the byte order information...
+ if (this->get_byte_order_info (buf) == -1)
+ return -1;
+
// Get the message type
this->message_type_ = buf[TAO_GIOP_MESSAGE_TYPE_OFFSET];
- // Get the size of the message..
- this->set_payload_size_from_buffer (buf);
- // Get the request id
- this->parse_fragment_header (buf, mb.length ());
+ // Get the size of the message..
+ this->get_payload_size (buf);
if (this->message_size_ == 0)
{
- const char* msgname = 0;
-
- switch (this->message_type_)
- {
- case TAO_GIOP_MESSAGERROR:
- msgname = "GIOP_MESSAGE_ERROR"; break;
- case TAO_GIOP_CLOSECONNECTION:
- msgname = "GIOP_CLOSE_CONNECTION"; break;
- }
- if (msgname != 0)
+ if (this->message_type_ == TAO_GIOP_MESSAGERROR)
{
if (TAO_debug_level > 0)
{
- ACE_DEBUG ((
- LM_DEBUG,
- "(%P|%t) GIOP_Message_State::take_values: %s rcv'd.\n",
- msgname
- ));
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) -"
+ "GIOP_MESSAGE_ERROR received \n"));
}
+ return 0;
}
else
{
if (TAO_debug_level > 0)
- {
- ACE_DEBUG ((LM_DEBUG,
- "(%P|%t) GIOP_Message_State::take_values: "
- "Message of size zero rcv'd.\n"));
- }
-
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) - "
+ "Message of size zero recd. \n"));
return -1;
}
}
+
+ if (this->more_fragments_)
+ {
+ (void) this->parse_fragment_header (buf,
+ incoming.length ());
+ }
+
return 0;
}
+
+
+
+int
+TAO_GIOP_Message_State::parse_magic_bytes (char *buf)
+{
+ // The values are hard-coded to support non-ASCII platforms.
+ if (!(buf [0] == 0x47 // 'G'
+ && buf [1] == 0x49 // 'I'
+ && buf [2] == 0x4f // 'O'
+ && buf [3] == 0x50)) // 'P'
+ {
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("TAO (%P|%t) - bad header, ")
+ ACE_LIB_TEXT ("magic word [%2.2x,%2.2x,%2.2x,%2.2x]\n"),
+ buf[0],
+ buf[1],
+ buf[2],
+ buf[3]));
+ return -1;
+ }
+
+ return 0;
+}
+
int
-TAO_GIOP_Message_State::set_version_info_from_buffer (const char *buf)
+TAO_GIOP_Message_State::get_version_info (char *buf)
{
+ if (TAO_debug_level > 8)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) - GIOP_Message_State::get_version_info\n"));
+ }
+
// We have a GIOP message on hand. Get its revision numbers
- CORBA::Octet incoming_major = buf[TAO_GIOP_VERSION_MAJOR_OFFSET];
- CORBA::Octet incoming_minor = buf[TAO_GIOP_VERSION_MINOR_OFFSET];
+ CORBA::Octet incoming_major =
+ buf[TAO_GIOP_VERSION_MAJOR_OFFSET];
+ CORBA::Octet incoming_minor =
+ buf[TAO_GIOP_VERSION_MINOR_OFFSET];
// Check the revision information
if (TAO_GIOP_Message_Generator_Parser_Impl::check_revision (
@@ -156,9 +157,7 @@ TAO_GIOP_Message_State::set_version_info_from_buffer (const char *buf)
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("TAO (%P|%t) - ")
- ACE_TEXT ("GIOP_Message_State::set_version_info_from_buffer:")
- ACE_TEXT ("bad version <%d.%d>\n"),
+ ACE_TEXT ("TAO (%P|%t) - bad version <%d.%d>\n"),
incoming_major, incoming_minor));
}
@@ -173,9 +172,15 @@ TAO_GIOP_Message_State::set_version_info_from_buffer (const char *buf)
}
int
-TAO_GIOP_Message_State::set_byte_order_info_from_buffer (const char *buf)
+TAO_GIOP_Message_State::get_byte_order_info (char *buf)
{
- // Let us be specific that this is for 1.0
+ if (TAO_debug_level > 8)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) - GIOP_Message_State::get_byte_order_info\n"));
+ }
+
+ // Let us be specific that this is for 1.0
if (this->giop_version_.minor == 0 &&
this->giop_version_.major == 1)
{
@@ -186,14 +191,10 @@ TAO_GIOP_Message_State::set_byte_order_info_from_buffer (const char *buf)
this->byte_order_ != 1)
{
if (TAO_debug_level > 2)
- {
- ACE_DEBUG ((LM_DEBUG,
- "TAO (%P|%t) - GIOP_Message_State::"
- "get_byte_order_info, "
- "invalid byte order <%d> for version <1.0>\n",
- this->byte_order_));
- }
-
+ ACE_DEBUG ((LM_DEBUG,
+ "TAO (%P|%t) - GIOP_Message_State::get_byte_order_info, "
+ "invalid byte order <%d> for version <1.0>\n",
+ this->byte_order_));
return -1;
}
}
@@ -210,15 +211,12 @@ TAO_GIOP_Message_State::set_byte_order_info_from_buffer (const char *buf)
if ((buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET] & ~0x3) != 0)
{
if (TAO_debug_level > 2)
- {
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("TAO (%P|%t) - invalid flags for <%d>")
- ACE_TEXT (" for version <%d %d> \n"),
- buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET],
- this->giop_version_.major,
- this->giop_version_.minor));
- }
-
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("TAO (%P|%t) - invalid flags for <%d>")
+ ACE_TEXT (" for version <%d %d> \n"),
+ buf[TAO_GIOP_MESSAGE_FLAGS_OFFSET],
+ this->giop_version_.major,
+ this->giop_version_.minor));
return -1;
}
}
@@ -226,10 +224,19 @@ TAO_GIOP_Message_State::set_byte_order_info_from_buffer (const char *buf)
return 0;
}
+void
+TAO_GIOP_Message_State::get_payload_size (char *rd_ptr)
+{
+ // Move the read pointer
+ rd_ptr += TAO_GIOP_MESSAGE_SIZE_OFFSET;
+
+ this->message_size_ = this->read_ulong (rd_ptr);
+}
+
int
-TAO_GIOP_Message_State::parse_fragment_header (const char *buf,
+TAO_GIOP_Message_State::parse_fragment_header (char *buf,
size_t length)
{
size_t len =
@@ -239,7 +246,9 @@ TAO_GIOP_Message_State::parse_fragment_header (const char *buf,
// By this point we are doubly sure that we have a more or less
// valid GIOP message with a valid major revision number.
- if (this->giop_version_.minor >= 2 && length > len)
+ if (this->giop_version_.minor == 2 &&
+ this->message_type_ == TAO_GIOP_FRAGMENT &&
+ length > len)
{
// Fragmented message in GIOP 1.2 should have a fragment header
// following the GIOP header. Grab the rd_ptr to get that
@@ -254,7 +263,7 @@ TAO_GIOP_Message_State::parse_fragment_header (const char *buf,
}
CORBA::ULong
-TAO_GIOP_Message_State::read_ulong (const char *rd_ptr)
+TAO_GIOP_Message_State::read_ulong (char *rd_ptr)
{
CORBA::ULong x = 0;