Go to the documentation of this file.00001
00002
00003 #include "tao/GIOP_Message_Generator_Parser_10.h"
00004 #include "tao/GIOP_Utils.h"
00005 #include "tao/GIOP_Message_Locate_Header.h"
00006 #include "tao/operation_details.h"
00007 #include "tao/debug.h"
00008 #include "tao/Pluggable_Messaging_Utils.h"
00009 #include "tao/TAO_Server_Request.h"
00010 #include "tao/ORB_Constants.h"
00011 #include "tao/CDR.h"
00012 #include "tao/SystemException.h"
00013
00014 #include "ace/Log_Msg.h"
00015
00016 ACE_RCSID (tao,
00017 GIOP_Message_Generator_Parser_10,
00018 "$Id: GIOP_Message_Generator_Parser_10.cpp 84443 2009-02-12 20:26:35Z johnnyw $")
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 bool
00023 TAO_GIOP_Message_Generator_Parser_10::write_request_header (
00024 const TAO_Operation_Details &opdetails,
00025 TAO_Target_Specification &spec,
00026 TAO_OutputCDR &msg)
00027 {
00028
00029 if (!(msg << opdetails.request_service_info ()))
00030 return false;
00031
00032
00033 if (!(msg << opdetails.request_id ()))
00034 return false;
00035
00036 CORBA::Octet const response_flags = opdetails.response_flags ();
00037
00038
00039 if (response_flags == TAO_TWOWAY_RESPONSE_FLAG)
00040 {
00041 msg << ACE_OutputCDR::from_octet (1);
00042 }
00043 else
00044 {
00045 msg << ACE_OutputCDR::from_octet (0);
00046 }
00047
00048
00049
00050
00051 const TAO::ObjectKey *key = spec.object_key ();
00052
00053 if (key)
00054 {
00055
00056 msg << *key;
00057 }
00058 else
00059 {
00060 if (TAO_debug_level)
00061 {
00062 ACE_ERROR ((LM_ERROR,
00063 ACE_TEXT ("(%N |%l) Unable to handle this request\n")));
00064 }
00065 return false;
00066 }
00067
00068 msg.write_string (opdetails.opname_len (), opdetails.opname ());
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #if defined (TAO_PEER_REQUIRES_PRINCIPAL)
00080
00081 char username[BUFSIZ];
00082 char *result =
00083 ACE_OS::cuserid (username,
00084 BUFSIZ);
00085
00086 if (result != 0)
00087 {
00088 const CORBA::ULong username_size =
00089 static_cast<CORBA::ULong> (ACE_OS::strlen (username));
00090
00091 CORBA::Octet *buffer =
00092 CORBA::OctetSeq::allocbuf (username_size + 1);
00093
00094 ACE_OS::memcpy (buffer,
00095 username,
00096 username_size + 1);
00097
00098 req_principal.replace (username_size + 1,
00099 username_size + 1,
00100 buffer,
00101 1);
00102 }
00103
00104 #else
00105
00106 CORBA::OctetSeq req_principal (0);
00107 req_principal.length (0);
00108
00109 #endif
00110
00111 msg << req_principal;
00112
00113 return true;
00114 }
00115
00116 bool
00117 TAO_GIOP_Message_Generator_Parser_10::write_locate_request_header (
00118 CORBA::ULong request_id,
00119 TAO_Target_Specification &spec,
00120 TAO_OutputCDR &msg)
00121 {
00122 msg << request_id;
00123
00124
00125
00126
00127 const TAO::ObjectKey *key = spec.object_key ();
00128
00129 if (key)
00130 {
00131
00132 msg << *key;
00133 }
00134 else
00135 {
00136 if (TAO_debug_level)
00137 {
00138 ACE_ERROR ((LM_ERROR,
00139 ACE_TEXT ("(%N | %l) Unable to handle this request\n")));
00140 }
00141 return false;
00142 }
00143
00144 return true;
00145 }
00146
00147 bool
00148 TAO_GIOP_Message_Generator_Parser_10::write_reply_header (
00149 TAO_OutputCDR &output,
00150 TAO_Pluggable_Reply_Params_Base &reply)
00151 {
00152
00153 #if (TAO_HAS_MINIMUM_CORBA == 1)
00154 if (!(output << reply.service_context_notowned ()))
00155 return false;
00156 #else
00157 if (!reply.is_dsi_)
00158 {
00159 if (!(output << reply.service_context_notowned ()))
00160 return false;
00161 }
00162 else
00163 {
00164
00165
00166
00167
00168 CORBA::ULong count = 0;
00169 IOP::ServiceContextList &svc_ctx = reply.service_context_notowned ();
00170 CORBA::ULong const l = svc_ctx.length ();
00171 CORBA::ULong i;
00172
00173 for (i = 0; i != l; ++i)
00174 {
00175 if (svc_ctx[i].context_id == TAO_SVC_CONTEXT_ALIGN)
00176 {
00177 continue;
00178 }
00179
00180 ++count;
00181 }
00182
00183
00184 ++count;
00185
00186
00187 if (!(output << count))
00188 return false;
00189
00190 for (i = 0; i != l; ++i)
00191 {
00192 if (svc_ctx[i].context_id == TAO_SVC_CONTEXT_ALIGN)
00193 {
00194 continue;
00195 }
00196
00197 if (!(output << svc_ctx[i]))
00198 return false;
00199 }
00200
00201 }
00202
00203 if (reply.is_dsi_ == true)
00204 {
00205
00206 ptrdiff_t target = reply.dsi_nvlist_align_;
00207
00208 ptrdiff_t const current =
00209 ptrdiff_t (output.current_alignment ()) % ACE_CDR::MAX_ALIGNMENT;
00210
00211 CORBA::ULong pad = 0;
00212
00213 if (target == 0)
00214 {
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 if (current != 0 && current <= ACE_CDR::LONG_ALIGN)
00226 {
00227 pad = 4;
00228 }
00229 }
00230 else if (target != ACE_CDR::LONG_ALIGN)
00231 {
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 if (current > ACE_CDR::LONG_ALIGN)
00244 {
00245 pad = 4;
00246 }
00247 }
00248 else if (target == ACE_CDR::MAX_ALIGNMENT)
00249 {
00250 pad = 0;
00251 }
00252 else
00253 {
00254
00255 throw ::CORBA::MARSHAL ();
00256 }
00257
00258 output << CORBA::ULong (TAO_SVC_CONTEXT_ALIGN);
00259 output << pad;
00260
00261 for (CORBA::ULong j = 0; j != pad; ++j)
00262 {
00263 output << ACE_OutputCDR::from_octet(0);
00264 }
00265 }
00266 #endif
00267
00268
00269 output.write_ulong (reply.request_id_);
00270
00271
00272 output.write_ulong (reply.reply_status ());
00273
00274 return true;
00275 }
00276
00277
00278 bool
00279 TAO_GIOP_Message_Generator_Parser_10::write_locate_reply_mesg (
00280 TAO_OutputCDR &output,
00281 CORBA::ULong request_id,
00282 TAO_GIOP_Locate_Status_Msg &status_info)
00283 {
00284
00285 output.write_ulong (request_id);
00286 output.write_ulong (status_info.status);
00287
00288 if (status_info.status == GIOP::OBJECT_FORWARD)
00289 {
00290 CORBA::Object_ptr object_ptr = status_info.forward_location_var.in ();
00291
00292 if (!(output << object_ptr))
00293 {
00294 if (TAO_debug_level > 0)
00295 {
00296 ACE_ERROR ((
00297 LM_ERROR,
00298 ACE_TEXT ("TAO (%P|%t|%N|%l) write_locate_reply_mesg-")
00299 ACE_TEXT (" cannot marshal object reference\n")
00300 ));
00301 }
00302 return false;
00303 }
00304 }
00305
00306 return true;
00307 }
00308
00309 bool
00310 TAO_GIOP_Message_Generator_Parser_10::write_fragment_header (
00311 TAO_OutputCDR & ,
00312 CORBA::ULong )
00313 {
00314
00315 return false;
00316 }
00317
00318
00319 int
00320 TAO_GIOP_Message_Generator_Parser_10::parse_request_header (
00321 TAO_ServerRequest &request)
00322 {
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 TAO_InputCDR & input = *request.incoming ();
00334
00335 IOP::ServiceContextList &service_info = request.request_service_info ();
00336
00337 if (!(input >> service_info))
00338 return -1;
00339
00340 CORBA::Boolean hdr_status = (CORBA::Boolean) input.good_bit ();
00341
00342 CORBA::ULong req_id = 0;
00343
00344
00345 hdr_status = hdr_status && input.read_ulong (req_id);
00346
00347 request.request_id (req_id);
00348
00349 CORBA::Octet response_flags = CORBA::Octet();
00350 hdr_status = hdr_status && input.read_octet (response_flags);
00351 request.response_expected ((response_flags != 0));
00352
00353
00354 request.sync_with_server (0);
00355
00356
00357
00358
00359
00360 hdr_status =
00361 hdr_status && request.profile ().unmarshall_object_key (input);
00362
00363
00364
00365
00366
00367
00368
00369
00370 CORBA::ULong length = 0;
00371 hdr_status = hdr_status && input.read_ulong (length);
00372
00373 if (hdr_status)
00374 {
00375
00376
00377
00378
00379
00380
00381 request.operation (input.rd_ptr (),
00382 length - 1,
00383 0 );
00384 hdr_status = input.skip_bytes (length);
00385 }
00386
00387 if (hdr_status)
00388 {
00389
00390
00391
00392
00393
00394
00395
00396 CORBA::OctetSeq oct_seq;
00397 input >> oct_seq;
00398 request.requesting_principal (oct_seq);
00399 hdr_status = (CORBA::Boolean) input.good_bit ();
00400 }
00401
00402 return hdr_status ? 0 : -1;
00403 }
00404
00405 int
00406 TAO_GIOP_Message_Generator_Parser_10::parse_locate_header (
00407 TAO_GIOP_Locate_Request_Header &request)
00408 {
00409
00410 TAO_InputCDR &msg = request.incoming_stream ();
00411
00412
00413 CORBA::ULong req_id = 0;
00414 CORBA::Boolean hdr_status = msg.read_ulong (req_id);
00415
00416
00417 request.request_id (req_id);
00418
00419
00420 hdr_status = hdr_status && request.profile ().unmarshall_object_key (msg);
00421
00422 return hdr_status ? 0 : -1;
00423 }
00424
00425 int
00426 TAO_GIOP_Message_Generator_Parser_10::parse_reply (
00427 TAO_InputCDR &cdr,
00428 TAO_Pluggable_Reply_Params ¶ms)
00429 {
00430
00431 if (!(cdr >> params.svc_ctx_))
00432 {
00433 if (TAO_debug_level > 0)
00434 {
00435 ACE_ERROR ((LM_ERROR,
00436 ACE_TEXT ("TAO (%P|%t) parse_reply, ")
00437 ACE_TEXT ("extracting context\n")));
00438 }
00439 return -1;
00440 }
00441
00442
00443 if (TAO_GIOP_Message_Generator_Parser::parse_reply (cdr, params) == -1)
00444 return -1;
00445
00446 return 0;
00447 }
00448
00449
00450 int
00451 TAO_GIOP_Message_Generator_Parser_10::parse_locate_reply (
00452 TAO_InputCDR &cdr,
00453 TAO_Pluggable_Reply_Params ¶ms)
00454 {
00455 if (TAO_GIOP_Message_Generator_Parser::parse_locate_reply (cdr,
00456 params) == -1)
00457
00458 return -1;
00459
00460 return 0;
00461 }
00462
00463 CORBA::Octet
00464 TAO_GIOP_Message_Generator_Parser_10::major_version (void) const
00465 {
00466
00467 return static_cast<CORBA::Octet> (1);
00468 }
00469
00470 CORBA::Octet
00471 TAO_GIOP_Message_Generator_Parser_10::minor_version (void) const
00472 {
00473
00474 return 0;
00475 }
00476
00477 size_t
00478 TAO_GIOP_Message_Generator_Parser_10::fragment_header_length (void) const
00479 {
00480 return 0;
00481 }
00482
00483 TAO_END_VERSIONED_NAMESPACE_DECL