summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_Generator_Parser_12.cpp
blob: 4f6f5b054cb2ad9e8939646ecfff20b8f2d849ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// $Id$

#include "GIOP_Message_Generator_Parser_12.h"
#include "GIOP_Utils.h"
#include "GIOP_Message_State.h"

#include "GIOP_Message_Locate_Header.h"

#include "operation_details.h"
#include "CDR.h"
#include "Any.h"
#include "debug.h"
#include "OctetSeqC.h"
#include "Pluggable_Messaging_Utils.h"
#include "TAO_Server_Request.h"
#include "TAOC.h"
#include "Service_Context.h"
#include "Pluggable.h"
#include "ORB_Core.h"
#include "Transport.h"

#if !defined (__ACE_INLINE__)
# include "GIOP_Message_Generator_Parser_12.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID (tao,
           GIOP_Message_Gen_Parser_12,
           "$Id$")

// This is used by GIOP1.2. This is to align the message body on a
// 8-octet boundary. This is declared static so that it is in file
// scope.
static const size_t TAO_GIOP_MESSAGE_ALIGN_PTR = 8;

int
TAO_GIOP_Message_Generator_Parser_12::write_request_header (
    const TAO_Operation_Details &opdetails,
    TAO_Target_Specification &spec,
    TAO_OutputCDR &msg
  )
{
  // First the request id
  msg << opdetails.request_id ();

  const CORBA::Octet response_flags = opdetails.response_flags ();

  // Here are the Octet values for different policies
  // '00000000' for SYNC_NONE
  // '00000000' for SYNC_WITH_TRANSPORT
  // '00000010' for SYNC_WITH_SERVER
  // '00000011' for SYNC_WITH_TARGET
  // '00000011' for regular two ways, but if they are invoked via a
  // DII with INV_NO_RESPONSE flag set then we need to send '00000001'
  //
  // We have not implemented the policy INV_NO_RESPONSE for DII.
  if (response_flags == TAO_TWOWAY_RESPONSE_FLAG)
    msg << CORBA::Any::from_octet (3);
  // Second the response flags
  // Sync scope - ignored by server if request is not oneway.
  else if (response_flags == CORBA::Octet (TAO::SYNC_NONE) ||
           response_flags == CORBA::Octet (TAO::SYNC_WITH_TRANSPORT) ||
           response_flags == CORBA::Octet (TAO::SYNC_EAGER_BUFFERING) ||
           response_flags == CORBA::Octet (TAO::SYNC_DELAYED_BUFFERING))
    // No response required.
    msg << CORBA::Any::from_octet (0);

  else if (response_flags == CORBA::Octet (TAO::SYNC_WITH_SERVER))
    // Return before dispatching to the servant
    msg << CORBA::Any::from_octet (1);

  else if (response_flags == CORBA::Octet (TAO::SYNC_WITH_TARGET))
    // Return after dispatching servant.
    msg << CORBA::Any::from_octet (3);
  else
    // Until more flags are defined by the OMG.
    return 0;

  // The reserved field
  CORBA::Octet reserved[3] = {0, 0, 0};

  msg.write_octet_array (reserved, 3);

  if (this->marshall_target_spec (spec,
                                  msg) == 0)
    return 0;

  // Write the operation name
  msg.write_string (opdetails.opname_len (),
                    opdetails.opname ());

  // Write the service context list
  msg << opdetails.request_service_info ();

  // We align the pointer only if the operation has arguments.
  if (opdetails.argument_flag ())
    {
      if (msg.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
        return 0;
    }

  return 1;
}


int
TAO_GIOP_Message_Generator_Parser_12::write_locate_request_header (
    CORBA::ULong request_id,
    TAO_Target_Specification    &spec,
    TAO_OutputCDR &msg
  )
{
  // Write the request id
  msg << request_id;

  // Write the target address
  if (this->marshall_target_spec (spec,
                                  msg) == 0)
    return 0;

  // I dont think we need to align the pointer to an 8 byte boundary
  // here.
  // We need to align the pointer
  //  if (msg.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
  //  return 0;

  // Return success
  return 1;
}

int
TAO_GIOP_Message_Generator_Parser_12::write_reply_header (
    TAO_OutputCDR & output,
    TAO_Pluggable_Reply_Params_Base &reply,
    CORBA::Environment & /* ACE_TRY_ENV */
  )
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Write the request ID
  output.write_ulong (reply.request_id_);

   // Write the reply status
  if (reply.reply_status_ ==
      TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD_PERM)
    {
      // Not sure when we will use this.
      output.write_ulong (TAO_GIOP_LOCATION_FORWARD_PERM);
    }
  else if (reply.reply_status_ ==
           TAO_PLUGGABLE_MESSAGE_NEEDS_ADDRESSING_MODE)
    {
      // Not sure when we will use this.
      output.write_ulong (TAO_GIOP_LOC_NEEDS_ADDRESSING_MODE);
    }
  else
    {
      this->marshal_reply_status (output,
                                  reply);
    }

#if (TAO_HAS_MINIMUM_CORBA == 1)
  output << reply.service_context_notowned ();
#else
  if (reply.is_dsi_ == 0)
    {
      output << reply.service_context_notowned ();
    }
  else
    {
      IOP::ServiceContextList &svc_ctx =
        reply.service_context_notowned ();
      CORBA::ULong l = svc_ctx.length ();

      // Now marshal the rest of the service context objects
      output << l;

      for (CORBA::ULong i = 0; i != l; ++i)
        {
          output << svc_ctx[i];
        }

    }
#endif /*TAO_HAS_MINIMUM_CORBA */

  if (reply.argument_flag_)
    {
      // If we have some data to be marshalled, then we align the
      // pointer to a 8 byte boundary.  Else, we just leave it throu
      if (output.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
        {
          return 0;
        }
    }
  return 1;
}


int
TAO_GIOP_Message_Generator_Parser_12::write_locate_reply_mesg (
    TAO_OutputCDR & output,
    CORBA::ULong request_id,
    TAO_GIOP_Locate_Status_Msg &status_info
  )
{
  output.write_ulong (request_id);

  // Make the header for the locate request
  output.write_ulong (status_info.status);

  if (status_info.status == TAO_GIOP_OBJECT_FORWARD ||
      status_info.status == TAO_GIOP_OBJECT_FORWARD_PERM)
    {
      // We have to send some data, so align the pointer
      if (output.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
        {
          return 0;
        }
    }

  switch (status_info.status)
    {
    case TAO_GIOP_OBJECT_FORWARD:

      // More likely than not we will not have this in TAO
    case TAO_GIOP_OBJECT_FORWARD_PERM:
      {
        CORBA::Object_ptr object_ptr =
          status_info.forward_location_var.in ();

        if ((output << object_ptr) == 0)
        {
          if (TAO_debug_level > 0)
            {
              ACE_DEBUG ((
                  LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t|%N|%l) write_locate_reply_mesg-")
                  ACE_TEXT (" cannot marshal object reference\n")
                ));
            }
        }
      }
      break;
    case TAO_GIOP_LOC_SYSTEM_EXCEPTION:
    case TAO_GIOP_LOC_NEEDS_ADDRESSING_MODE:
      // Do we do these in TAO??
      // What to do here???? I dont really know. I have to do a survey
      // of the specifications that uses this.
      break;
    default:
      break;
    }

  return 1;
}


int
TAO_GIOP_Message_Generator_Parser_12::parse_request_header (
    TAO_ServerRequest &request
  )
{

  // Get the input CDR in the request class
  TAO_InputCDR& input = request.incoming ();

  CORBA::Boolean hdr_status = (CORBA::Boolean) input.good_bit ();

  CORBA::ULong req_id;
  // Get the rest of the request header ...
  hdr_status = hdr_status && input.read_ulong (req_id);

  request.request_id (req_id);

  CORBA::Octet response_flags;
  hdr_status = hdr_status && input.read_octet (response_flags);

  request.response_expected ((response_flags > 0));

  // The high bit of the octet has been set if the SyncScope policy
  // value is SYNC_WITH_SERVER.
  request.sync_with_server ((response_flags == 1));

  // Reserved field
  input.skip_bytes (3);

  // Read the discriminant of the union.
  CORBA::Short disc = 0;
  hdr_status = hdr_status && input.read_short (disc);

  if (hdr_status)
    {
      if (disc == GIOP::KeyAddr)
          {
            hdr_status =
              this->unmarshall_object_key (request.object_key (),
                                           input);
          }
       else if (disc == GIOP::ProfileAddr)
          {
            hdr_status =
              this->unmarshall_iop_profile (request.profile (),
                                            input);
          }
      else if (disc == GIOP::ReferenceAddr)
        {
             hdr_status =
               this->unmarshall_ref_addr (request.profile (),
                                          input);
        }
    }

  if (input.char_translator () == 0)
    {
      CORBA::ULong length = 0;
      hdr_status = hdr_status && input.read_ulong (length);

      if (hdr_status)
        {
          // Do not include NULL character at the end.
          // @@ This is not getting demarshaled using the codeset
          //    translators!

          // Notice that there are no memory allocations involved
          // here!

          request.operation (input.rd_ptr (),
                             length - 1,
                             0 /* TAO_ServerRequest does NOT own string */);
          hdr_status = input.skip_bytes (length);
        }
    }
  else
    {
      // @@ We could optimize for this case too, i.e. do in-place
      //    demarshaling of the string... But there is an issue
      //    pending on the OMG as to whether the operation should be
      //    sent in the connection negotiated codeset or always in
      //    ISO8859-1.
      CORBA::String_var tmp;
      hdr_status = hdr_status && input.read_string (tmp.inout ());

      request.operation (tmp._retn (),
                         0,
                         1 /* TAO_ServerRequest owns string */);
    }

  // Tear out the service context ... we currently ignore it, but it
  // should probably be passed to each ORB service as appropriate
  // (e.g. transactions, security).
  //
  // NOTE: As security support kicks in, this is a good place to
  // verify a digital signature, if that is required in this security
  // environment.  It may be required even when using IPSEC security
  // infrastructure.
  IOP::ServiceContextList &req_service_info =
    request.request_service_info ();

  input >> req_service_info;

  // Check an process if BiDir contexts are available
  if (request.orb_core ()->bidir_giop_policy ())
    this->check_bidirectional_context (request);

  if (input.length () > 0)
    {
      // Reset the read_ptr to an 8-byte boundary.
      input.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
    }

  return hdr_status ? 0 : -1;
}


int
TAO_GIOP_Message_Generator_Parser_12::parse_locate_header (
    TAO_GIOP_Locate_Request_Header &request
  )
{
  // Get the stream .
  TAO_InputCDR &msg = request.incoming_stream ();

  CORBA::Boolean hdr_status = 1;

  // Get the request id.
  CORBA::ULong req_id = 0;
  hdr_status = msg.read_ulong (req_id);

  // Store it in the Locate request classes
  request.request_id (req_id);

  // Read the discriminant of the union.
  CORBA::Short disc = 0;
  hdr_status =
    hdr_status && msg.read_short (disc);

  if (hdr_status)
    {
      if (disc == GIOP::KeyAddr)
          {
            hdr_status =
              this->unmarshall_object_key (request.object_key (),
                                           msg);
          }
       else if (disc == GIOP::ProfileAddr)
          {
            hdr_status =
              this->unmarshall_iop_profile (request.profile (),
                                            msg);
          }
      else if (disc == GIOP::ReferenceAddr)
        {
             hdr_status =
               this->unmarshall_ref_addr (request.profile (),
                                          msg);
        }
    }

  // Reset the pointer to an 8-byte bouns]dary
  msg.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);

  return hdr_status ? 0 : -1;
}

int
TAO_GIOP_Message_Generator_Parser_12::parse_reply (
    TAO_InputCDR &cdr,
    TAO_Pluggable_Reply_Params &params
  )
{
  if (TAO_GIOP_Message_Generator_Parser::parse_reply (cdr,
                                                      params) == -1)

    return -1;

  if ((cdr >> params.svc_ctx_) == 0)
    {
      if (TAO_debug_level > 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) parse_reply, ")
                           ACE_TEXT ("extracting context\n")),
                          -1);
    }

  if (cdr.length () > 0)
    {
      // Align the read pointer on an 8-byte boundary
      cdr.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
    }




  // Steal the contents in to the reply CDR and loose ownership of the
  // data block.
  params.input_cdr_.exchange_data_blocks (cdr);

  return 0;
}

int
TAO_GIOP_Message_Generator_Parser_12::parse_locate_reply (
    TAO_InputCDR &cdr,
    TAO_Pluggable_Reply_Params &params
  )
{
  if (TAO_GIOP_Message_Generator_Parser::parse_locate_reply (cdr,
                                                             params) == -1)

    return -1;

  if (cdr.length () > 0)
    {
      // Align the read pointer on an 8-byte boundary
      cdr.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
    }

  // Steal the contents in to the reply CDR and loose ownership of the
  // data block.
  params.input_cdr_.exchange_data_blocks (cdr);

  return 0;
}


CORBA::Octet
TAO_GIOP_Message_Generator_Parser_12::major_version (void)
{
  return (CORBA::Octet) 1;
}


CORBA::Octet
TAO_GIOP_Message_Generator_Parser_12::minor_version (void)
{
  return (CORBA::Octet) 2;
}

int
TAO_GIOP_Message_Generator_Parser_12::is_ready_for_bidirectional (void)
{
  // We do support bidirectional
  return 1;
}



int
TAO_GIOP_Message_Generator_Parser_12::marshall_target_spec (
    TAO_Target_Specification &spec,
    TAO_OutputCDR &msg
  )
{
  switch (spec.specifier ())
    {
    case TAO_Target_Specification::Key_Addr:
      {
        // As this is a union send in the discriminant first
        msg << GIOP::KeyAddr;

        // Get the object key
        const TAO_ObjectKey *key = spec.object_key ();
        if (key)
          {
            // Marshall in the object key
            msg << *key;
          }
        else
          {
            if (TAO_debug_level)
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%N |%l) Unable to handle this request \n")));
            return 0;
          }
        break;
      }
    case TAO_Target_Specification::Profile_Addr:
      {
        // As this is a union send in the discriminant first
        msg << GIOP::ProfileAddr;

        // Get the profile
        const IOP::TaggedProfile *pfile = spec.profile ();

        if (pfile)
          {
            // Marshall in the object key
            msg << *pfile;
          }
        else
          {
            if (TAO_debug_level)
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%N |%l) Unable to handle this request \n")));
            return 0;
          }
        break;
      }
    case TAO_Target_Specification::Reference_Addr:
      {
        // As this is a union send in the discriminant first
        msg << GIOP::ReferenceAddr;

        // Get the IOR
        IOP::IOR *ior;
        CORBA::ULong index = spec.iop_ior (ior);

        if (ior)
          {
            // This is a struct IORAddressingInfo. So, marshall each
            // member of the struct one after another in the order
            // defined.
            msg << index;
            msg << *ior;
          }
        else
          {
            if (TAO_debug_level)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%N |%l) Unable to handle this request \n")));
            return 0;
          }
        break;
      }
    default:
      if (TAO_debug_level)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%N |%l) Unable to handle this request \n")));
      return 0;
    }

  return 1;
}


int
TAO_GIOP_Message_Generator_Parser_12::check_bidirectional_context (
    TAO_ServerRequest &request)
{
  TAO_Service_Context &service_context = request.request_service_context ();

  // Check whether we have the BiDir service context info available in
  // the ServiceContextList
  if (service_context.is_service_id (IOP::BI_DIR_IIOP)
      == 1)
    {
      return this->process_bidir_context (service_context,
                                          request.transport ());
    }

  return 0;
}

int
TAO_GIOP_Message_Generator_Parser_12::process_bidir_context (
    TAO_Service_Context &service_context,
    TAO_Transport *transport)
{
  // Get the context info
  IOP::ServiceContext context;
  context.context_id = IOP::BI_DIR_IIOP;

  if (service_context.get_context (context) != 1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%P|%t) Context info not found \n")),
                      -1);


  TAO_InputCDR cdr (ACE_reinterpret_cast
                    (const char*,
                     context.context_data.get_buffer ()),
                    context.context_data.length ());

  return transport->tear_listen_point_list (cdr);
}