TAO_CDR_Encaps_Codec. to Balachandran Natarajan

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Oleg Krayno » Wed, 04 Sep 2002 06:32:43



Hi.

Sorry... Damage of the hard disk.
My archive tao-bugs mailinglist and modified source files lost. :(

Please, repeat, in what file and what change it is necessary to do.
I immediately can begin to test.

--
Best regards,
 Oleg

 
 
 

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Krishnakumar » Wed, 04 Sep 2002 06:51:26



> Hi.

> Sorry... Damage of the hard disk.
> My archive tao-bugs mailinglist and modified source files lost. :(

> Please, repeat, in what file and what change it is necessary to do.
> I immediately can begin to test.

You can search one of the archives of the comp.soft-sys.ace newsgroups like
groups.google.com or groups.yahoo.com

-kitty.

--
Krishnakumar B <kitty at cs dot wustl dot edu>
Distributed Object Computing Laboratory, Washington University in St.Louis

 
 
 

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Balachandran Nataraja » Thu, 05 Sep 2002 03:06:25


Oleg-

 > Hi.
 >
 > Sorry... Damage of the hard disk.
 > My archive tao-bugs mailinglist and modified source files lost. :(
 >
 > Please, repeat, in what file and what change it is necessary to do.
 > I immediately can begin to test.

May be these links would help

http://groups.yahoo.com/group/tao-bugs/message/2518
http://groups.yahoo.com/group/tao-bugs/message/2521

Thanks
Bala

 
 
 

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Oleg Krayno » Thu, 05 Sep 2002 07:46:39


Hi.

Thanks.

--
Best regards,
 Oleg

 
 
 

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Oleg Krayno » Fri, 06 Sep 2002 05:15:12


Hi.

It is checked on WinXP Pro, BCB6 (Update 2).

Functions decode and decode_value:
---------------------------------------------

CORBA::Any *
TAO_CDR_Encaps_Codec::decode (const CORBA::OctetSeq & data
                              ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   IOP::Codec::FormatMismatch))
{
  // @todo How do we check for a format mismatch so that we can throw
  //       a IOP::Codec::FormatMismatch exception?
  // @todo Is this the best way to extract the Any from the OctetSeq?

  // Notice that we need to extract the TypeCode and the value from
  // the octet sequence, and place them into the Any.  We can't just
  // insert the octet sequence into the Any.

  ACE_Message_Block mb (data.length () + 2 * ACE_CDR::MAX_ALIGNMENT);
  ACE_CDR::mb_align (&mb);

  ACE_OS::memcpy (mb.rd_ptr (), data.get_buffer (), data.length ());

  size_t rd_pos = mb.rd_ptr () - mb.base ();
  size_t wr_pos = mb.wr_ptr () - mb.base () + data.length ();

  TAO_InputCDR cdr (mb.data_block (),
                    ACE_Message_Block::DONT_DELETE,
                    rd_pos,
                    wr_pos,
                    ACE_CDR_BYTE_ORDER,
                    this->major_,
                    this->minor_,
                    this->orb_core_);

  CORBA::Boolean byte_order;
  if (cdr >> TAO_InputCDR::to_boolean (byte_order))
    {
      cdr.reset_byte_order (ACE_static_cast (int, byte_order));

      CORBA::Any * any = 0;
      ACE_NEW_THROW_EX (any,
                        CORBA::Any,
                        CORBA::NO_MEMORY (
                          CORBA_SystemException::_tao_minor_code (
                           TAO_DEFAULT_MINOR_CODE,
                           ENOMEM),
                          CORBA::COMPLETED_NO));
      ACE_CHECK_RETURN (0);

      CORBA::Any_var safe_any = any;

      if (cdr >> (*any))
        return safe_any._retn ();
    }

  ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0);

}

CORBA::Any *
TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data,
                                    CORBA::TypeCode_ptr tc
                                    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   IOP::Codec::FormatMismatch,
                   IOP::Codec::TypeMismatch))
{
  // The ACE_CDR::mb_align() call can shift the rd_ptr by up
  // to ACE_CDR::MAX_ALIGNMENT-1 bytes. Similarly, the offset
  // adjustment can move the rd_ptr by up to the same amount.
  // We accommodate this by including
  // 2 * ACE_CDR::MAX_ALIGNMENT bytes of additional space in
  // the message block.
  ACE_Message_Block mb (data.length () + 2 * ACE_CDR::MAX_ALIGNMENT);
  ACE_CDR::mb_align (&mb);

  ACE_OS::memcpy (mb.rd_ptr (), data.get_buffer (), data.length ());

  // @todo How do we check for a type mismatch so that we can
  //       throw a IOP::Codec::TypeMismatch exception?
  //       @@ I added a check below.  See the comment.  I'm not sure
  //          if it is a valid check.
  //             -Ossama

  // @todo Most of this code was copied from
  //         operator>> (TAO_InputCDR &cdr, CORBA::Any &x)
  //       in Any.cpp.  Rather than copy the code, the code should be
  //       refactored to make it possible to use the given TypeCode
  //       rather than attempt to extract it from the CDR
  //       encapsulation.

  CORBA::ULong sequence_length = data.length ();

  size_t rd_pos = mb.rd_ptr () - mb.base ();
  size_t wr_pos = mb.wr_ptr () - mb.base () + data.length ();

  TAO_InputCDR cdr (mb.data_block (),
                    ACE_Message_Block::DONT_DELETE,
                    rd_pos,
                    wr_pos,
                    ACE_CDR_BYTE_ORDER,
                    this->major_,
                    this->minor_,
                    this->orb_core_);

  CORBA::Boolean byte_order;
  if (cdr >> TAO_InputCDR::to_boolean (byte_order))
    {
      cdr.reset_byte_order (ACE_static_cast (int, byte_order));

      // @@ (JP) The following code depends on the fact that
      //         TAO_InputCDR does not contain chained message blocks,
      //         otherwise <begin> and <end> could be part of
      //         different buffers!

      // This will be the start of a new message block.
      char *begin = cdr.rd_ptr ();

      // Skip over the next argument.
      CORBA::TypeCode::traverse_status status =
        TAO_Marshal_Object::perform_skip (tc,
                                          &cdr
                                          ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);  // @@ Should we throw a
                             //    IOP::Codec::TypeMismatch exception
                             //    here if this fails?

      if (status == CORBA::TypeCode::TRAVERSE_CONTINUE)
        {
          // This will be the end of the new message block.
          char *end = cdr.rd_ptr ();

          size_t size = end - begin;

          // @@ I added the following check, but I'm not sure if it is
          //    a valid check.  Can someone verify this?
          //          -Ossama

          // If the unaligned buffer size is not equal to the octet
          // sequence length (minus the "byte order byte") then the
          // TypeCode does not correspond to the data in the CDR
          // encapsulation.  However, even if they do match it is
          // still uncertain if the TypeCode corresponds to the data
          // in the octet sequence.  With this test, it is only
          // possible to determine if the TypeCode does *not* match
          // the data, not if it does match.
          if (size != sequence_length - 1)
            ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0);

          ptr_arith_t offset =
            ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT;
          mb.rd_ptr (offset);
          mb.wr_ptr (offset + size);

          CORBA::Any * any = 0;
          ACE_NEW_THROW_EX (any,
                            CORBA::Any,
                            CORBA::NO_MEMORY (
                              CORBA_SystemException::_tao_minor_code (
                                TAO_DEFAULT_MINOR_CODE,
                                ENOMEM),
                              CORBA::COMPLETED_NO));
          ACE_CHECK_RETURN (0);

          CORBA::Any_var safe_any = any;

          // Stick it into the Any.  It gets duplicated there.
          any->_tao_replace (tc,
                             cdr.byte_order (),
                             &mb);

          return safe_any._retn ();
        }
      else
        ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0);
    }

  ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0);

}

--
Best regards,
 Oleg
 
 
 

TAO_CDR_Encaps_Codec. to Balachandran Natarajan

Post by Balachandran Nataraja » Fri, 06 Sep 2002 05:48:33


Oleg-

Thanks for verifying this. Could you please pass the test case along
that you tested this with so that it can be part of the test suite?

Thanks
bala

On Thursday, 5 September, 2002 at 00:06:26 +0400, Oleg Kraynov wrote:

 > Hi.
 >
 > It is checked on WinXP Pro, BCB6 (Update 2).
 >
 > Functions decode and decode_value:
 > ---------------------------------------------
 >
 > CORBA::Any *
 > TAO_CDR_Encaps_Codec::decode (const CORBA::OctetSeq & data
 >                               ACE_ENV_ARG_DECL)
 >   ACE_THROW_SPEC ((CORBA::SystemException,
 >                    IOP::Codec::FormatMismatch))
 > {
 >   // @todo How do we check for a format mismatch so that we can throw
 >   //       a IOP::Codec::FormatMismatch exception?
 >   // @todo Is this the best way to extract the Any from the OctetSeq?
 >
 >   // Notice that we need to extract the TypeCode and the value from
 >   // the octet sequence, and place them into the Any.  We can't just
 >   // insert the octet sequence into the Any.
 >
 >   ACE_Message_Block mb (data.length () + 2 * ACE_CDR::MAX_ALIGNMENT);
 >   ACE_CDR::mb_align (&mb);
 >
 >   ACE_OS::memcpy (mb.rd_ptr (), data.get_buffer (), data.length ());
 >
 >   size_t rd_pos = mb.rd_ptr () - mb.base ();
 >   size_t wr_pos = mb.wr_ptr () - mb.base () + data.length ();
 >
 >   TAO_InputCDR cdr (mb.data_block (),
 >                     ACE_Message_Block::DONT_DELETE,
 >                     rd_pos,
 >                     wr_pos,
 >                     ACE_CDR_BYTE_ORDER,
 >                     this->major_,
 >                     this->minor_,
 >                     this->orb_core_);
 >
 >   CORBA::Boolean byte_order;
 >   if (cdr >> TAO_InputCDR::to_boolean (byte_order))
 >     {
 >       cdr.reset_byte_order (ACE_static_cast (int, byte_order));
 >
 >       CORBA::Any * any = 0;
 >       ACE_NEW_THROW_EX (any,
 >                         CORBA::Any,
 >                         CORBA::NO_MEMORY (
 >                           CORBA_SystemException::_tao_minor_code (
 >                            TAO_DEFAULT_MINOR_CODE,
 >                            ENOMEM),
 >                           CORBA::COMPLETED_NO));
 >       ACE_CHECK_RETURN (0);
 >
 >       CORBA::Any_var safe_any = any;
 >
 >       if (cdr >> (*any))
 >         return safe_any._retn ();
 >     }
 >
 >   ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0);
 > }
 >
 > CORBA::Any *
 > TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data,
 >                                     CORBA::TypeCode_ptr tc
 >                                     ACE_ENV_ARG_DECL)
 >   ACE_THROW_SPEC ((CORBA::SystemException,
 >                    IOP::Codec::FormatMismatch,
 >                    IOP::Codec::TypeMismatch))
 > {
 >   // The ACE_CDR::mb_align() call can shift the rd_ptr by up
 >   // to ACE_CDR::MAX_ALIGNMENT-1 bytes. Similarly, the offset
 >   // adjustment can move the rd_ptr by up to the same amount.
 >   // We accommodate this by including
 >   // 2 * ACE_CDR::MAX_ALIGNMENT bytes of additional space in
 >   // the message block.
 >   ACE_Message_Block mb (data.length () + 2 * ACE_CDR::MAX_ALIGNMENT);
 >   ACE_CDR::mb_align (&mb);
 >
 >   ACE_OS::memcpy (mb.rd_ptr (), data.get_buffer (), data.length ());
 >
 >   // @todo How do we check for a type mismatch so that we can
 >   //       throw a IOP::Codec::TypeMismatch exception?
 >   //       @@ I added a check below.  See the comment.  I'm not sure
 >   //          if it is a valid check.
 >   //             -Ossama
 >
 >   // @todo Most of this code was copied from
 >   //         operator>> (TAO_InputCDR &cdr, CORBA::Any &x)
 >   //       in Any.cpp.  Rather than copy the code, the code should be
 >   //       refactored to make it possible to use the given TypeCode
 >   //       rather than attempt to extract it from the CDR
 >   //       encapsulation.
 >
 >   CORBA::ULong sequence_length = data.length ();
 >
 >   size_t rd_pos = mb.rd_ptr () - mb.base ();
 >   size_t wr_pos = mb.wr_ptr () - mb.base () + data.length ();
 >
 >   TAO_InputCDR cdr (mb.data_block (),
 >                     ACE_Message_Block::DONT_DELETE,
 >                     rd_pos,
 >                     wr_pos,
 >                     ACE_CDR_BYTE_ORDER,
 >                     this->major_,
 >                     this->minor_,
 >                     this->orb_core_);
 >
 >   CORBA::Boolean byte_order;
 >   if (cdr >> TAO_InputCDR::to_boolean (byte_order))
 >     {
 >       cdr.reset_byte_order (ACE_static_cast (int, byte_order));
 >
 >       // @@ (JP) The following code depends on the fact that
 >       //         TAO_InputCDR does not contain chained message blocks,
 >       //         otherwise <begin> and <end> could be part of
 >       //         different buffers!
 >
 >       // This will be the start of a new message block.
 >       char *begin = cdr.rd_ptr ();
 >
 >       // Skip over the next argument.
 >       CORBA::TypeCode::traverse_status status =
 >         TAO_Marshal_Object::perform_skip (tc,
 >                                           &cdr
 >                                           ACE_ENV_ARG_PARAMETER);
 >       ACE_CHECK_RETURN (0);  // @@ Should we throw a
 >                              //    IOP::Codec::TypeMismatch exception
 >                              //    here if this fails?
 >
 >       if (status == CORBA::TypeCode::TRAVERSE_CONTINUE)
 >         {
 >           // This will be the end of the new message block.
 >           char *end = cdr.rd_ptr ();
 >
 >           size_t size = end - begin;
 >
 >           // @@ I added the following check, but I'm not sure if it is
 >           //    a valid check.  Can someone verify this?
 >           //          -Ossama
 >
 >           // If the unaligned buffer size is not equal to the octet
 >           // sequence length (minus the "byte order byte") then the
 >           // TypeCode does not correspond to the data in the CDR
 >           // encapsulation.  However, even if they do match it is
 >           // still uncertain if the TypeCode corresponds to the data
 >           // in the octet sequence.  With this test, it is only
 >           // possible to determine if the TypeCode does *not* match
 >           // the data, not if it does match.
 >           if (size != sequence_length - 1)
 >             ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0);
 >
 >           ptr_arith_t offset =
 >             ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT;
 >           mb.rd_ptr (offset);
 >           mb.wr_ptr (offset + size);
 >
 >           CORBA::Any * any = 0;
 >           ACE_NEW_THROW_EX (any,
 >                             CORBA::Any,
 >                             CORBA::NO_MEMORY (
 >                               CORBA_SystemException::_tao_minor_code (
 >                                 TAO_DEFAULT_MINOR_CODE,
 >                                 ENOMEM),
 >                               CORBA::COMPLETED_NO));
 >           ACE_CHECK_RETURN (0);
 >
 >           CORBA::Any_var safe_any = any;
 >
 >           // Stick it into the Any.  It gets duplicated there.
 >           any->_tao_replace (tc,
 >                              cdr.byte_order (),
 >                              &mb);
 >
 >           return safe_any._retn ();
 >         }
 >       else
 >         ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0);
 >     }
 >
 >   ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0);
 > }
 >
 >
 >
 > --
 > Best regards,
 >  Oleg