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 80861 2008-03-07 13:48:34Z 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_ == false)
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 =
00291 status_info.forward_location_var.in ();
00292
00293 if ((output << object_ptr) == false)
00294 {
00295 if (TAO_debug_level > 0)
00296 {
00297 ACE_ERROR ((
00298 LM_ERROR,
00299 ACE_TEXT ("TAO (%P|%t|%N|%l) write_locate_reply_mesg-")
00300 ACE_TEXT (" cannot marshal object reference\n")
00301 ));
00302 }
00303 return false;
00304 }
00305 }
00306
00307 return true;
00308 }
00309
00310 bool
00311 TAO_GIOP_Message_Generator_Parser_10::write_fragment_header (
00312 TAO_OutputCDR & ,
00313 CORBA::ULong )
00314 {
00315
00316 return false;
00317 }
00318
00319
00320 int
00321 TAO_GIOP_Message_Generator_Parser_10::parse_request_header (
00322 TAO_ServerRequest &request)
00323 {
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 TAO_InputCDR & input = *request.incoming ();
00335
00336 IOP::ServiceContextList &service_info = request.request_service_info ();
00337
00338 if (!(input >> service_info))
00339 return -1;
00340
00341 CORBA::Boolean hdr_status = (CORBA::Boolean) input.good_bit ();
00342
00343 CORBA::ULong req_id = 0;
00344
00345
00346 hdr_status = hdr_status && input.read_ulong (req_id);
00347
00348 request.request_id (req_id);
00349
00350 CORBA::Octet response_flags = CORBA::Octet();
00351 hdr_status = hdr_status && input.read_octet (response_flags);
00352 request.response_expected ((response_flags != 0));
00353
00354
00355 request.sync_with_server (0);
00356
00357
00358
00359
00360
00361 hdr_status =
00362 hdr_status && request.profile ().unmarshall_object_key (input);
00363
00364
00365
00366
00367
00368
00369
00370
00371 CORBA::ULong length = 0;
00372 hdr_status = hdr_status && input.read_ulong (length);
00373
00374 if (hdr_status)
00375 {
00376
00377
00378
00379
00380
00381
00382 request.operation (input.rd_ptr (),
00383 length - 1,
00384 0 );
00385 hdr_status = input.skip_bytes (length);
00386 }
00387
00388 if (hdr_status)
00389 {
00390
00391
00392
00393
00394
00395
00396
00397 CORBA::OctetSeq oct_seq;
00398 input >> oct_seq;
00399 request.requesting_principal (oct_seq);
00400 hdr_status = (CORBA::Boolean) input.good_bit ();
00401 }
00402
00403
00404 return hdr_status ? 0 : -1;
00405 }
00406
00407 int
00408 TAO_GIOP_Message_Generator_Parser_10::parse_locate_header (
00409 TAO_GIOP_Locate_Request_Header &request)
00410 {
00411
00412 TAO_InputCDR &msg = request.incoming_stream ();
00413
00414
00415 CORBA::ULong req_id = 0;
00416 CORBA::Boolean hdr_status = msg.read_ulong (req_id);
00417
00418
00419 request.request_id (req_id);
00420
00421
00422 hdr_status = hdr_status && request.profile ().unmarshall_object_key (msg);
00423
00424 return hdr_status ? 0 : -1;
00425 }
00426
00427 int
00428 TAO_GIOP_Message_Generator_Parser_10::parse_reply (
00429 TAO_InputCDR &cdr,
00430 TAO_Pluggable_Reply_Params ¶ms)
00431 {
00432
00433 if (!(cdr >> params.svc_ctx_))
00434 {
00435 if (TAO_debug_level > 0)
00436 {
00437 ACE_ERROR ((LM_ERROR,
00438 ACE_TEXT ("TAO (%P|%t) parse_reply, ")
00439 ACE_TEXT ("extracting context\n")));
00440 }
00441 return -1;
00442 }
00443
00444
00445 if (TAO_GIOP_Message_Generator_Parser::parse_reply (cdr, params) == -1)
00446 return -1;
00447
00448 return 0;
00449 }
00450
00451
00452 int
00453 TAO_GIOP_Message_Generator_Parser_10::parse_locate_reply (
00454 TAO_InputCDR &cdr,
00455 TAO_Pluggable_Reply_Params ¶ms)
00456 {
00457 if (TAO_GIOP_Message_Generator_Parser::parse_locate_reply (cdr,
00458 params) == -1)
00459
00460 return -1;
00461
00462 return 0;
00463 }
00464
00465 CORBA::Octet
00466 TAO_GIOP_Message_Generator_Parser_10::major_version (void) const
00467 {
00468
00469 return static_cast<CORBA::Octet> (1);
00470 }
00471
00472 CORBA::Octet
00473 TAO_GIOP_Message_Generator_Parser_10::minor_version (void) const
00474 {
00475
00476 return 0;
00477 }
00478
00479 size_t
00480 TAO_GIOP_Message_Generator_Parser_10::fragment_header_length (void) const
00481 {
00482 return 0;
00483 }
00484
00485 TAO_END_VERSIONED_NAMESPACE_DECL