summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_Connectors.cpp
blob: e248c9a40c91aa3418d9e52fb385406b6cc61f9d (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
//$Id$
#include "tao/GIOP_Message_Connectors.h"
#include "tao/Any.h"
#include "tao/debug.h"
#include "tao/Principal.h"
#include "tao/TAOC.h"
#include "tao/operation_details.h"

#if !defined (__ACE_INLINE__)
# include "tao/GIOP_Message_Connectors.i"
#endif /* __ACE_INLINE__ */

int
TAO_GIOP_Message_Connectors::
  parse_reply (TAO_Message_State_Factory &mesg_state,
               TAO_Pluggable_Connector_Params &params)
{
  // @@ Bala: See how the message state is a per-protocol thing?
  //    Wouldn't it be better to have each protocol define its own
  //    message state and just use that type directly (i.e no
  //    message_state base class).  As far as i can see (but i may be
  //    wrong), only very tightly related messaging protocols and
  //    transport protocols can use the same message state (for
  //    example GIOP 1.x and GIOP Lite).  Furthermore, if i'm proven
  //    wrong and there is common functionality among different
  //    pluggable messaging protocols, we can simply re-factor at that
  //    point.
  //    IMHO the right approach is to factor out common functionality
  //    and interfaces 'a posteriori', otherwise we will define
  //    ackward interfaces that will have to be changed anyway!

  // Cast to the GIOP Message state
  TAO_GIOP_Message_State *state = ACE_dynamic_cast (TAO_GIOP_Message_State *,
                                                    &mesg_state);

  // Read the request id
  if (!state->cdr.read_ulong (params.request_id_))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t|%N|%l) : TAO_GIOP_Message_1_1::parse_reply, "
                    "extracting request id"));
      return -1;
    }

  // and the reply status type.  status can be NO_EXCEPTION,
  // SYSTEM_EXCEPTION, USER_EXCEPTION, LOCATION_FORWARD

  // Cannot handle LOCATION_FORWARD_PERM here
  CORBA::ULong rep_stat = 0;
  if (!state->cdr.read_ulong (rep_stat))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t|%N|%l) : TAO_GIOP_Message_1_1::parse_reply, "
                    "extracting reply status\n"));
      return -1;
    }

  // @@ Bala: More silly translations!

  // Pass the right Pluggable interface code to the transport layer
  switch (rep_stat)
    {
      // Request completed successfully
    case TAO_GIOP_NO_EXCEPTION:
      params.reply_status_ = TAO_PLUGGABLE_MESSAGE_NO_EXCEPTION;
      break;
      
      // Request terminated with user exception
    case TAO_GIOP_USER_EXCEPTION:
      params.reply_status_ = TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION;
      break;
      // Request terminated with system exception        
    case TAO_GIOP_SYSTEM_EXCEPTION:
      params.reply_status_ = TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION;
      break;
      // Reply is a location forward type
    case TAO_GIOP_LOCATION_FORWARD:
      params.reply_status_ = TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD;
      break;
    default:
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ASYS_TEXT ("(%N|%l) Unknown reply status \n")));
    }
  
  return 0;
}


int
TAO_GIOP_Message_Connectors::validate_version (TAO_GIOP_Message_State *state)
  
{
  // Grab the read pointer
  char *buf = state->cdr.rd_ptr ();

  if ((buf[TAO_GIOP_VERSION_MAJOR_OFFSET] != this->major_version ()) ||
       (buf[TAO_GIOP_VERSION_MINOR_OFFSET] != this->minor_version ()))
    return -1;
  
  state->giop_version.major = buf[TAO_GIOP_VERSION_MAJOR_OFFSET];
  state->giop_version.minor = buf[TAO_GIOP_VERSION_MINOR_OFFSET];
  
  return 0;
}

int
TAO_GIOP_Message_Connectors::
process_connector_messages (TAO_Transport * /*transport*/, 
                            TAO_ORB_Core * /*orb_core*/,
                            TAO_InputCDR & /*input*/,
                            CORBA::Octet /*message_type*/)
{
   ACE_NOTSUP_RETURN (-1);
}


///////////////////////////////////////////////////////////////////
// Methods for TAO_GIOP_Message_Connector_11
//////////////////////////////////////////////////////////////////

CORBA::Boolean
TAO_GIOP_Message_Connector_11::
  write_request_header (const TAO_Operation_Details &opdetails,
                        TAO_Target_Specification &spec,
                        TAO_OutputCDR &msg)
{
  // This is sepecific to GIOP 1.1. So put them here
  msg << opdetails.service_info ();

  // First the request id
  msg << opdetails.request_id ();

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

   // @@ (JP) Temporary hack until all of GIOP 1.2 is implemented.
  if (response_flags == 131)
    msg << CORBA::Any::from_octet (1);

  // Second the response flags
  // Sync scope - ignored by server if request is not oneway.
  else if (response_flags == CORBA::Octet (TAO::SYNC_WITH_TRANSPORT) ||
           response_flags == CORBA::Octet (TAO::SYNC_NONE) ||
           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 servant.  We're also setting the high
    // bit here. This is a temporary fix until the rest of GIOP 1.2 is
    // implemented in TAO.
    msg << CORBA::Any::from_octet (129);
  
  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;

  // In this case we cannot recognise anything other than the Object
  // key as the address disposition variable. But we do a sanity check
  // anyway.
  const TAO_ObjectKey *key = spec.object_key ();
  if (key)
    {
      // Put in the object key
      msg << *key;
    }
  else
    {
      if (TAO_debug_level)
        ACE_DEBUG ((LM_DEBUG,
                    ASYS_TEXT ("(%N |%l) Unable to handle this request \n")));
      return 0;
    }

  msg.write_string (opdetails.opname_len (), 
                    opdetails.opname ());
  
  // Last element of request header is the principal; no portable way
  // to get it, we just pass empty principal (convention: indicates
  // "anybody").  Steps upward in security include passing an
  // unverified user ID, and then verifying the message (i.e. a dummy
  // service context entry is set up to hold a digital signature for
  // this message, then patched shortly before it's sent).
  static CORBA::Principal_ptr principal = 0;
  msg << principal;


  return 1;

}




CORBA::Boolean
TAO_GIOP_Message_Connector_11::
  write_locate_request_header (CORBA::ULong request_id,
                               TAO_Target_Specification &spec,
                               TAO_OutputCDR &msg)
{
  msg << request_id;

  // In this case we cannot recognise anything other than the Object
  // key as the address disposition variable. But we do a sanity check
  // anyway.
  const TAO_ObjectKey *key = spec.object_key ();
  if (key)
    {
      // Everything is fine
      msg << *key;
    }
  else
    {
      if (TAO_debug_level)
        ACE_DEBUG ((LM_DEBUG,
                    ASYS_TEXT ("(%N | %l) Unable to handle this request \n")));
      return 0;
    }
 
  return 1;
}


int
TAO_GIOP_Message_Connector_11::
  parse_reply (TAO_Message_State_Factory &mesg_state,
               TAO_Pluggable_Connector_Params &params)
       
{
  // Cast to the GIOP Message state
  TAO_GIOP_Message_State *state = ACE_dynamic_cast (TAO_GIOP_Message_State *,
                                                    &mesg_state);

  switch (state->message_type)
    {
    case TAO_GIOP_REQUEST:
      // In GIOP 1.0 and GIOP 1.1 this is an error,
      ACE_ERROR_RETURN ((LM_ERROR,
                         "TAO (%P|%t) %N:%l TAO_GIOP_Message_1_1::parse_reply: "
                         "request.\n"),
                        -1);

    case TAO_GIOP_CANCELREQUEST:
    case TAO_GIOP_LOCATEREQUEST:
      // Errors
    case TAO_GIOP_CLOSECONNECTION:
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ASYS_TEXT ("TAO (%P|%t) %N:%l parse_reply: ") 
                           ASYS_TEXT ("wrong message.\n")),
                          -1);
    case TAO_GIOP_LOCATEREPLY:
      // Handle after the switch
      break;
    case TAO_GIOP_REPLY:
      if ((state->cdr >> params.svc_ctx_) == 0)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        ASYS_TEXT ("TAO (%P|%t) parse_reply, ")
                        ASYS_TEXT ("extracting context\n")));
          return -1;
        }
      // Rest of the stuff after the switch
      break;
    case TAO_GIOP_FRAGMENT:
      // Never happens: why??
      break;
    }
  
  if (TAO_GIOP_Message_Connectors::parse_reply (*state,
                                                params) 
      == -1)
    return -1;

  return 0;
}

CORBA::Octet
TAO_GIOP_Message_Connector_11:: major_version (void)
{
  // Any harm in hardcoding??
  return (CORBA::Octet) 1;
}

CORBA::Octet
TAO_GIOP_Message_Connector_11:: minor_version (void)
{
  // Any harm in hardcoding??
  return (CORBA::Octet) 1;
}


///////////////////////////////////////////////////////////////////
// Methods for TAO_GIOP_Message_Connector_10
//////////////////////////////////////////////////////////////////

CORBA::Octet
TAO_GIOP_Message_Connector_10:: minor_version (void)
{
  // Any harm in hardcoding??
  // @@ Bala: of course not...  but don't cast stuff that doen't need
  // casting! return 0 is enough.
  return (CORBA::Octet) 0;
}