Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GIOP_Message_Generator_Parser_10.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // -*- C++ -*-
00003 
00004 #include "GIOP_Message_Generator_Parser_10.h"
00005 #include "GIOP_Utils.h"
00006 
00007 #include "GIOP_Message_Locate_Header.h"
00008 
00009 #include "operation_details.h"
00010 #include "CDR.h"
00011 #include "Any.h"
00012 #include "debug.h"
00013 #include "OctetSeqC.h"
00014 #include "Pluggable_Messaging_Utils.h"
00015 #include "TAO_Server_Request.h"
00016 #include "GIOP_Message_State.h"
00017 #include "CORBA_String.h"
00018 #include "ORB_Core.h"
00019 
00020 #if !defined (__ACE_INLINE__)
00021 # include "GIOP_Message_Generator_Parser_10.inl"
00022 #endif /* __ACE_INLINE__ */
00023 
00024 ACE_RCSID(tao, GIOP_Message_Gen_Parser_10, "$Id: GIOP_Message_Generator_Parser_10.cpp,v 1.1.1.2.2.2 2003/04/10 14:04:03 phil Exp $")
00025 
00026 int
00027 TAO_GIOP_Message_Generator_Parser_10::write_request_header (
00028     const TAO_Operation_Details &opdetails,
00029     TAO_Target_Specification &spec,
00030     TAO_OutputCDR &msg)
00031 {
00032   // Write the service context list
00033   msg << opdetails.request_service_info ();
00034 
00035   // The request ID
00036   msg << opdetails.request_id ();
00037 
00038   const CORBA::Octet response_flags = opdetails.response_flags ();
00039 
00040   // Write the response flags
00041   if (response_flags == TAO_TWOWAY_RESPONSE_FLAG)
00042     msg << CORBA::Any::from_octet (1);
00043   else
00044     msg << CORBA::Any::from_octet (0);
00045 
00046   // In this case we cannot recognise anything other than the Object
00047   // key as the address disposition variable. But we do a sanity check
00048   // anyway.
00049   const TAO_ObjectKey *key = spec.object_key ();
00050   if (key)
00051     {
00052       // Put in the object key
00053       msg << *key;
00054     }
00055   else
00056     {
00057       if (TAO_debug_level)
00058         ACE_DEBUG ((LM_DEBUG,
00059                     ACE_TEXT ("(%N |%l) Unable to handle this request \n")));
00060       return 0;
00061     }
00062 
00063   msg.write_string (opdetails.opname_len (),
00064                     opdetails.opname ());
00065 
00066   // Last element of request header is the principal; no portable way
00067   // to get it, we just pass empty principal (convention: indicates
00068   // "anybody").  Steps upward in security include passing an
00069   // unverified user ID, and then verifying the message (i.e. a dummy
00070   // service context entry is set up to hold a digital signature for
00071   // this message, then patched shortly before it's sent).
00072 
00073   /***** This has been deprecated in the 2.4 spec ******/
00074   //static CORBA::Principal_ptr principal = 0;
00075   //msg << principal;
00076 
00077   // This is now introduced in 2.4 spec
00078   CORBA::OctetSeq req_principal (0);
00079   req_principal.length (0);
00080   msg << req_principal;
00081 
00082   return 1;
00083 }
00084 
00085 
00086 
00087 
00088 int
00089 TAO_GIOP_Message_Generator_Parser_10::write_locate_request_header (
00090     CORBA::ULong request_id,
00091     TAO_Target_Specification  &spec,
00092     TAO_OutputCDR &msg)
00093 {
00094   msg << request_id;
00095 
00096   // In this case we cannot recognise anything other than the Object
00097   // key as the address disposition variable. But we do a sanity check
00098   // anyway.
00099   const TAO_ObjectKey *key = spec.object_key ();
00100   if (key)
00101     {
00102       // Everything is fine
00103       msg << *key;
00104     }
00105   else
00106     {
00107       if (TAO_debug_level)
00108         ACE_DEBUG ((LM_DEBUG,
00109                     ACE_TEXT ("(%N | %l) Unable to handle this request \n")));
00110       return 0;
00111     }
00112 
00113   return 1;
00114 }
00115 
00116 
00117 int
00118 TAO_GIOP_Message_Generator_Parser_10::write_reply_header (
00119     TAO_OutputCDR &output,
00120     TAO_Pluggable_Reply_Params_Base &reply
00121     ACE_ENV_ARG_DECL
00122   )
00123   ACE_THROW_SPEC ((CORBA::SystemException))
00124 {
00125   // Write the service context list.
00126 #if (TAO_HAS_MINIMUM_CORBA == 1)
00127   output << reply.service_context_notowned ();
00128   ACE_ENV_ARG_NOT_USED; // FUZZ: ignore check_for_ace_check
00129 #else
00130   if (reply.is_dsi_ == 0)
00131     {
00132       output << reply.service_context_notowned ();
00133     }
00134   else
00135     {
00136       // If lazy evaluation is enabled then we are going to insert an
00137       // extra node at the end of the service context list, just to
00138       // force the appropriate padding.
00139       // But first we take it out any of them..
00140       CORBA::ULong count = 0;
00141       IOP::ServiceContextList &svc_ctx =
00142         reply.service_context_notowned ();
00143       CORBA::ULong l = svc_ctx.length ();
00144       CORBA::ULong i;
00145 
00146       for (i = 0; i != l; ++i)
00147         {
00148           if (svc_ctx[i].context_id == TAO_SVC_CONTEXT_ALIGN)
00149             {
00150               continue;
00151             }
00152 
00153           count++;
00154         }
00155 
00156       // Now increment it to account for the last dummy one...
00157       count++;
00158 
00159       // Now marshal the rest of the service context objects
00160       output << count;
00161       for (i = 0; i != l; ++i)
00162         {
00163           if (svc_ctx[i].context_id == TAO_SVC_CONTEXT_ALIGN)
00164             {
00165               continue;
00166             }
00167 
00168           output << svc_ctx[i];
00169         }
00170 
00171     }
00172 
00173   if (reply.is_dsi_ == 1)
00174     {
00175       // @@ Much of this code is GIOP 1.1 specific and should be
00176       ptr_arith_t target = reply.dsi_nvlist_align_;
00177 
00178       ptr_arith_t current =
00179         ptr_arith_t (output.current_alignment ()) % ACE_CDR::MAX_ALIGNMENT;
00180 
00181       CORBA::ULong pad = 0;
00182 
00183       if (target == 0)
00184         {
00185           // We want to generate adequate padding to start the request
00186           // id on a 8 byte boundary, two cases:
00187           // - If the dummy tag starts on a 4 byte boundary and the
00188           //   dummy sequence has 0 elements then we have:
00189           //   4:tag 8:sequence_length 4:sequence_body 4:request_id
00190           //   8:payload
00191           // - If the dummy tag starts on an 8 byte boundary, with 4
00192           //   elements we get:
00193           //   8:tag 4:sequence_length 8:sequence_body 4:request_id
00194           //   8:payload
00195           if (current != 0 && current <= ACE_CDR::LONG_ALIGN)
00196             {
00197               pad = 4;
00198             }
00199         }
00200       else if (target != ACE_CDR::LONG_ALIGN)
00201         {
00202           // The situation reverses, we want to generate adequate
00203           // padding to start the request id on a 4 byte boundary, two
00204           // cases:
00205           // - If the dummy tag starts on a 4 byte boundary and the
00206           //   dummy sequence has 4 elements then we have:
00207           //   4:tag 8:sequence_length 4:sequence_body 8:request_id
00208           //   4:payload
00209           // - If the dummy tag starts on an 8 byte boundary, with 0
00210           //   elements we get:
00211           //   8:tag 4:sequence_length 8:sequence_body 8:request_id
00212           //   4:payload
00213           if (current > ACE_CDR::LONG_ALIGN)
00214             {
00215               pad = 4;
00216             }
00217         }
00218       else if (target == ACE_CDR::MAX_ALIGNMENT)
00219         {
00220           pad = 0;
00221         }
00222       else
00223         {
00224           // <target> can only have the values above
00225           ACE_THROW_RETURN (CORBA::MARSHAL (),
00226                             0);
00227         }
00228 
00229       output << CORBA::ULong (TAO_SVC_CONTEXT_ALIGN);
00230       output << pad;
00231 
00232       for (CORBA::ULong j = 0; j != pad; ++j)
00233         {
00234           output << ACE_OutputCDR::from_octet(0);
00235         }
00236     }
00237 #endif /* TAO_HAS_MINIMUM_CORBA */
00238 
00239   // Write the request ID
00240   output.write_ulong (reply.request_id_);
00241 
00242   // Write the reply status
00243   this->marshal_reply_status (output,
00244                               reply);
00245 
00246   return 1;
00247 }
00248 
00249 
00250 int
00251 TAO_GIOP_Message_Generator_Parser_10::write_locate_reply_mesg (
00252     TAO_OutputCDR &output,
00253     CORBA::ULong request_id,
00254     TAO_GIOP_Locate_Status_Msg &status_info
00255   )
00256 {
00257   // Make the header for the locate request
00258   output.write_ulong (request_id);
00259   output.write_ulong (status_info.status);
00260 
00261   if (status_info.status == TAO_GIOP_OBJECT_FORWARD)
00262     {
00263       CORBA::Object_ptr object_ptr =
00264         status_info.forward_location_var.in ();
00265 
00266       if ((output << object_ptr) == 0)
00267         {
00268           if (TAO_debug_level > 0)
00269             {
00270               ACE_DEBUG ((
00271                   LM_DEBUG,
00272                   ACE_TEXT ("TAO (%P|%t|%N|%l) write_locate_reply_mesg-")
00273                   ACE_TEXT (" cannot marshal object reference\n")
00274                 ));
00275             }
00276         }
00277     }
00278 
00279   return 1;
00280 }
00281 
00282 int
00283 TAO_GIOP_Message_Generator_Parser_10::parse_request_header (
00284     TAO_ServerRequest &request)
00285 {
00286   // Tear out the service context ... we currently ignore it, but it
00287   // should probably be passed to each ORB service as appropriate
00288   // (e.g. transactions, security).
00289   //
00290   // NOTE: As security support kicks in, this is a good place to
00291   // verify a digital signature, if that is required in this security
00292   // environment.  It may be required even when using IPSEC security
00293   // infrastructure.
00294 
00295   // Get the input CDR in the request class
00296   TAO_InputCDR& input = request.incoming ();
00297 
00298   IOP::ServiceContextList &service_info =
00299     request.request_service_info ();
00300 
00301   input >> service_info;
00302 
00303   CORBA::Boolean hdr_status =
00304     (CORBA::Boolean) input.good_bit ();
00305 
00306   CORBA::ULong req_id;
00307 
00308   // Get the rest of the request header ...
00309   hdr_status = hdr_status && input.read_ulong (req_id);
00310 
00311   request.request_id (req_id);
00312 
00313   CORBA::Octet response_flags;
00314   hdr_status = hdr_status && input.read_octet (response_flags);
00315   request.response_expected ((response_flags != 0));
00316 
00317   // This is not supported now in GIOP 1.1
00318   request.sync_with_server (0);
00319 
00320   // We use ad-hoc demarshalling here: there is no need to increase
00321   // the reference count on the CDR message block, because this key
00322   // will not outlive the request (or the message block).
00323 
00324   hdr_status =
00325     hdr_status && request.profile ().unmarshall_object_key (input);
00326 
00327   // According to the CORBA 2.6.1 (and older) specification, the operation
00328   // name is an IDL Identifier. Identifiers must be composed of ASCII letters,
00329   // numbers, and underscores, starting with a letter. Based on this, and
00330   // the fact that I could find no text explicitly requiring operation name
00331   // translation, nor could others in the CORBA community, the operation name
00332   // will not be translated regardless of the translation of other strings.
00333   //
00334   CORBA::ULong length = 0;
00335   hdr_status = hdr_status && input.read_ulong (length);
00336 
00337   if (hdr_status)
00338     {
00339       // Do not include NULL character at the end.
00340       // @@ This is not getting demarshaled using the codeset
00341       //    translators!
00342 
00343       // Notice that there are no memory allocations involved
00344       // here!
00345       request.operation (input.rd_ptr (),
00346                          length - 1,
00347                          0 /* TAO_ServerRequest does NOT own string */);
00348       hdr_status = input.skip_bytes (length);
00349     }
00350 
00351   if (hdr_status)
00352     {
00353       /**** This has been deprecated in 2.4 ****/
00354       /*CORBA::Principal_var principal;
00355 
00356       input >> principal.out ();
00357 
00358       request.requesting_principal (principal.in ()); */
00359 
00360       CORBA_OctetSeq oct_seq;
00361       input >> oct_seq;
00362       request.requesting_principal (oct_seq);
00363       hdr_status = (CORBA::Boolean) input.good_bit ();
00364     }
00365 
00366 
00367   return hdr_status ? 0 : -1;
00368 }
00369 
00370 
00371 
00372 int
00373 TAO_GIOP_Message_Generator_Parser_10::parse_locate_header (
00374     TAO_GIOP_Locate_Request_Header &request
00375   )
00376 {
00377   // Get the stream
00378   TAO_InputCDR &msg = request.incoming_stream ();
00379 
00380   CORBA::Boolean hdr_status = 1;
00381 
00382   // Get the request id
00383   CORBA::ULong req_id = 0;
00384   hdr_status = msg.read_ulong (req_id);
00385 
00386   // Store it in the Locate request classes
00387   request.request_id (req_id);
00388 
00389   // Get the object key
00390   hdr_status =
00391     hdr_status && request.profile ().unmarshall_object_key (msg);
00392 
00393   return hdr_status ? 0 : -1;
00394 }
00395 
00396 
00397 
00398 int
00399 TAO_GIOP_Message_Generator_Parser_10::parse_reply (
00400     TAO_InputCDR &cdr,
00401     TAO_Pluggable_Reply_Params &params)
00402 
00403 {
00404   // Read the service context list first
00405   if ((cdr >> params.svc_ctx_) == 0)
00406     {
00407       if (TAO_debug_level >     0)
00408         ACE_DEBUG ((LM_DEBUG,
00409                     ACE_TEXT ("TAO (%P|%t) parse_reply, ")
00410                     ACE_TEXT ("extracting context\n")));
00411       return -1;
00412     }
00413 
00414   // Call the base class for further processing
00415   if (TAO_GIOP_Message_Generator_Parser::parse_reply (cdr,
00416                                                       params) == -1)
00417     return -1;
00418 
00419   // Steal rest of the contents in to the reply params and loose
00420   // ownership of the  data block.
00421   params.input_cdr_.exchange_data_blocks (cdr);
00422 
00423   return 0;
00424 }
00425 
00426 
00427 int
00428 TAO_GIOP_Message_Generator_Parser_10::parse_locate_reply (
00429     TAO_InputCDR &cdr,
00430     TAO_Pluggable_Reply_Params &params
00431   )
00432 {
00433   if (TAO_GIOP_Message_Generator_Parser::parse_locate_reply (cdr,
00434                                                              params) == -1)
00435 
00436     return -1;
00437 
00438   // Steal the contents in to the reply CDR and loose ownership of the
00439   // data block.
00440   params.input_cdr_.exchange_data_blocks (cdr);
00441 
00442   return 0;
00443 }
00444 
00445 CORBA::Octet
00446 TAO_GIOP_Message_Generator_Parser_10::major_version (void)
00447 {
00448   // Any harm in hardcoding??
00449   return (CORBA::Octet) 1;
00450 }
00451 
00452 CORBA::Octet
00453 TAO_GIOP_Message_Generator_Parser_10::minor_version (void)
00454 {
00455   // Any harm in hardcoding??
00456   return 0;
00457 }

Generated on Mon Jun 16 13:48:24 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002