summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_Invocation.cpp
blob: fc37ac66e74851a908ed45c881c6b4a77b33ed00 (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
//$id$
#include "tao/GIOP_Message_Invocation.h"
#include "tao/GIOPC.h"
#include "tao/Profile.h"
#include "tao/Stub.h"
#include "tao/Object_KeyC.h"
#include "tao/Principal.h"
#include "tao/GIOP_Utils.h"

//$Id$

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

TAO_GIOP_Client_Message_1_1::TAO_GIOP_Client_Message_1_1 (void)
  :our_major_version_ (1),
   our_minor_version_ (1)
{
  //no-op
}


TAO_GIOP_Client_Message_1_1::~TAO_GIOP_Client_Message_1_1 (void)
{
  //no-op
}

int
TAO_GIOP_Client_Message_1_1::parse_header (TAO_GIOP_Message_State *state)
{
  if (TAO_GIOP_Utils::parse_giop_header (state,
                                         state->cdr) == -1)
    {
      if (TAO_debug_level > 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N|%l) Error in parsing headers \n"),
                            -1);
        }
      return -1;
    }
     
  if (state->cdr.grow (this->get_header_len () +
                       state->message_size) == -1)
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - %p\n",
                    "TAO_GIOP::handle_input, ACE_CDR::grow"));
      return -1;
    }

  // Growing the buffer may have reset the rd_ptr(), but we want
  // to leave it just after the GIOP header (that was parsed
  // already);
  state->cdr.skip_bytes (this->get_header_len ());
  
  return 1;
}

int
TAO_GIOP_Client_Message_1_1::parse_magic_bytes (TAO_InputCDR &input)
{
  // Grab the read pointer
  char *buf = input.rd_ptr ();
  
  // The values are hard-coded to support non-ASCII platforms.
  if (!(buf [0] == 0x47      // 'G'
        && buf [1] == 0x49   // 'I'
        && buf [2] == 0x4f   // 'O'
        && buf [3] == 0x50)) // 'P'
    {
      // Could be GIOPlite.. 
      //...
      
      // For the present...
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) bad header, magic word [%c%c%c%c]\n",
                    buf[0],
                    buf[1],
                    buf[2],
                    buf[3]));
      return -1;
    }
  
  if ((buf[TAO_GIOP_VERSION_MAJOR_OFFSET] != this->our_major_version_) ||
      (buf[TAO_GIOP_VERSION_MINOR_OFFSET] != this->our_minor_version_))
      return -1;

  return 1;
}

CORBA::Boolean
TAO_GIOP_Client_Message_1_1::write_request_header (const IOP::ServiceContextList& svc_ctx,
                                                   CORBA::ULong request_id,
                                                   CORBA::Octet response_flags,
                                                   TAO_Target_Specification &spec,
                                                   const char *opname,
                                                   TAO_OutputCDR &msg)
{
  // This i sepecific to GIOP 1.1. So put them here
  msg << svc_ctx;

  // Let us  call our parent class to check what he can do for
  // us. 
  TAO_GIOP_Client_Message_Factory::write_request_header (svc_ctx,
                                                         request_id,
                                                         response_flags,
                                                         spec,
                                                         opname,
                                                         msg);
  
  // 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_orbdebug)
        ACE_DEBUG ((LM_DEBUG,
                    "(%N | %l) Unable to handle this request \n"));
      return 0;
    }
  
  msg << opname;
  
  // The principal is not used. So send a null pointer
  static CORBA::Principal_ptr principal = 0;
  msg << principal;
  
  
  return 1;

}


CORBA::Boolean
TAO_GIOP_Client_Message_1_1::
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_orbdebug)
        ACE_DEBUG ((LM_DEBUG,
                    "(%N | %l) Unable to handle this request \n"));
      return 0;
    }
  
  return 1;
}


const size_t
TAO_GIOP_Client_Message_1_1::get_header_len (void)
{
  return TAO_GIOP_HEADER_LEN;
}

const size_t
TAO_GIOP_Client_Message_1_1::get_message_size_offset (void)
{
  return TAO_GIOP_MESSAGE_SIZE_OFFSET;
}


CORBA::Boolean 
TAO_GIOP_Client_Message_1_1::start_message (TAO_Pluggable_Message_Type t, 
                                            TAO_OutputCDR &msg)
{
  
  TAO_GIOP_Version version (this->our_major_version_,
                            this->our_minor_version_);
  
  TAO_GIOP_Message_Type type = TAO_GIOP_REQUEST;
  switch (t)
    {
    case (TAO_MESSAGE_REQUEST):
      type = TAO_GIOP_REQUEST;
      break;
    case (TAO_MESSAGE_REPLY):
      type = TAO_GIOP_REPLY;
      break;
    case (TAO_MESSAGE_CANCELREQUEST):
      type = TAO_GIOP_CANCELREQUEST;
      break;
    case (TAO_MESSAGE_LOCATEREQUEST):
      type = TAO_GIOP_LOCATEREQUEST;
      break;
    case (TAO_MESSAGE_LOCATEREPLY):
      type = TAO_GIOP_LOCATEREPLY;
      break;
    case (TAO_MESSAGE_CLOSECONNECTION):
      type = TAO_GIOP_CLOSECONNECTION;
      break;
    case (TAO_MESSAGE_MESSAGERROR):
      type = TAO_GIOP_MESSAGERROR;
      break;
    case (TAO_MESSAGE_FRAGMENT):
      type = TAO_GIOP_FRAGMENT;
      break;
    }
  
  return TAO_GIOP_Utils::start_message (version,
                                        type,
                                        msg);
}

int
TAO_GIOP_Client_Message_1_1::parse_reply (TAO_Transport * /*transport*/,
                                          TAO_Message_State_Factory &mesg_state,
                                          IOP::ServiceContextList& reply_ctx,
                                          CORBA::ULong &request_id,
                                          CORBA::ULong &reply_status)
{
  // 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::parse_reply: "
                         "request.\n"),
                        -1);

    case TAO_GIOP_CANCELREQUEST:
    case TAO_GIOP_LOCATEREQUEST:
      // Errors
    case TAO_GIOP_CLOSECONNECTION:
      // I am not sure why we are not handling this here.. by Bala
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                         "TAO (%P|%t) %N:%l TAO_GIOP::parse_reply: "
                         "wrong message.\n"),
                        -1);
        break;
    case TAO_GIOP_LOCATEREPLY:
      // Handle after the switch 
      break;
    case TAO_GIOP_REPLY:
      if ((state->cdr >> reply_ctx) == 0)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "TAO (%P|%t) TAO_GIOP_Client_Message_1_1::parse_reply, "
                        "extracting context\n"));
          return -1;
        }
      // Rest of the stuff after the switch
      break;
    case TAO_GIOP_FRAGMENT:
      // Never happens: why??
      break;
    }
  

  // Read the request id
  if (!state->cdr.read_ulong (request_id))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) : TAO_GIOP::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
  if (!state->cdr.read_ulong (reply_status))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) : TAO_GIOP::parse_reply, "
                    "extracting reply status\n"));
      return -1;
    }
  
  return 0;
}