CSI_Utils.cpp

Go to the documentation of this file.
00001 // CSI_Utils.cpp,v 1.6 2006/03/14 06:14:35 jtc Exp
00002 
00003 #include "orbsvcs/Security/CSI_Utils.h"
00004 #include "orbsvcs/CSIC.h"
00005 
00006 #include "tao/CDR.h"
00007 
00008 #include "ace/OS_NS_string.h"
00009 
00010 
00011 ACE_RCSID (Security,
00012            CSI_Utils,
00013            "CSI_Utils.cpp,v 1.6 2006/03/14 06:14:35 jtc Exp")
00014 
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016 
00017 void
00018 TAO::CSI_Utils::create_sas_service_context (
00019   const CSI::SASContextBody & sas_context,
00020   IOP::ServiceContext & sc)
00021 {
00022   // Marshal CSI::SASContextBody union into an octet sequence suitable
00023   // for placement in an IOP::ServiceContext.
00024   // (TAO's compiled marshaling is used for performance reasons.)
00025 
00026   TAO_OutputCDR cdr;
00027   cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00028 
00029   cdr << sas_context;
00030 
00031   sc.context_id = IOP::SecurityAttributeService;
00032 
00033   // TAO extension, replace the contents of the octet sequence with
00034   // the CDR stream.
00035   const CORBA::ULong len = cdr.total_length ();
00036   sc.context_data.length (len);
00037   CORBA::Octet * buf = sc.context_data.get_buffer ();
00038   for (const ACE_Message_Block * i = cdr.begin ();
00039        i != 0;
00040        i = i->cont ())
00041     {
00042       ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00043       buf += i->length ();
00044     }
00045 }
00046 
00047 bool
00048 TAO::CSI_Utils::extract_sas_service_context (
00049   const IOP::ServiceContext & sc,
00050   CSI::SASContextBody & sas_context)
00051 {
00052   // Demarshal CSI::SASContextBody union from ServiceContext.
00053   // (TAO's compiled marshaling is used for performance reasons.)
00054 
00055   TAO_InputCDR cdr (reinterpret_cast<const char*> (
00056                       sc.context_data.get_buffer ()),
00057                     sc.context_data.length ());
00058 
00059   ACE_CDR::Boolean byte_order;
00060 
00061   if (!(cdr >> ACE_InputCDR::to_boolean (byte_order)))
00062     return false;
00063 
00064   cdr.reset_byte_order (static_cast<int> (byte_order));
00065 
00066   return (cdr >> sas_context);
00067 }
00068 
00069 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:50:46 2006 for TAO_Security by doxygen 1.3.6