1 #include "client_interceptors.h"
3 #include "tao/AnyTypeCode/DynamicC.h"
4 #include "tao/AnyTypeCode/TypeCode.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/Log_Msg.h"
8 const CORBA::ULong request_ctx_id
= 0xdead;
9 //const CORBA::ULong reply_ctx_id = 0xbeef; // Never used.
11 Vault_Client_Request_Interceptor::Vault_Client_Request_Interceptor ()
12 : myname_ ("Vault_Client_Interceptor")
16 Vault_Client_Request_Interceptor::~Vault_Client_Request_Interceptor ()
21 Vault_Client_Request_Interceptor::name ()
23 return CORBA::string_dup (this->myname_
);
27 Vault_Client_Request_Interceptor::destroy ()
32 Vault_Client_Request_Interceptor::send_poll (
33 PortableInterceptor::ClientRequestInfo_ptr
)
39 Vault_Client_Request_Interceptor::send_request (
40 PortableInterceptor::ClientRequestInfo_ptr ri
)
42 CORBA::String_var op
= ri
->operation ();
44 if (ACE_OS::strcmp (op
.in (), "authenticate") == 0)
46 // Make the context to send the context to the target.
47 IOP::ServiceContext sc
;
48 sc
.context_id
= request_ctx_id
;
50 const char passwd
[] = "root123";
51 CORBA::ULong string_len
= sizeof (passwd
) + 1;
52 CORBA::Octet
*buf
= 0;
54 CORBA::Octet
[string_len
]);
55 ACE_OS::strcpy (reinterpret_cast<char *> (buf
), passwd
);
57 sc
.context_data
.replace (string_len
, string_len
, buf
, 1);
59 // Add this context to the service context list.
60 ri
->add_request_service_context (sc
, 0);
63 if (ACE_OS::strcmp (op
.in (), "update_records") == 0)
65 Dynamic::ParameterList_var paramlist
=
68 const Test_Interceptors::Secure_Vault::Record
*record
= 0;
70 CORBA::ULong i
= 0; // index -- explicitly used to avoid
71 // overloaded operator ambiguity.
72 paramlist
[i
++].argument
>>= id
;
73 paramlist
[i
].argument
>>= record
;
78 Vault_Client_Request_Interceptor::receive_reply (
79 PortableInterceptor::ClientRequestInfo_ptr ri
)
81 CORBA::String_var op
= ri
->operation ();
83 if (ACE_OS::strcmp (op
.in (), "update_records") == 0)
86 CORBA::Any_var result_any
= ri
->result ();
88 (result_any
.in ()) >>= result
;
93 Vault_Client_Request_Interceptor::receive_other (
94 PortableInterceptor::ClientRequestInfo_ptr
)
100 Vault_Client_Request_Interceptor::receive_exception (
101 PortableInterceptor::ClientRequestInfo_ptr ri
)
103 CORBA::Any_var any
= ri
->received_exception ();
105 CORBA::TypeCode_var tc
= any
->type ();
107 const char *id
= tc
->id ();
109 CORBA::String_var exception_id
=
110 ri
->received_exception_id ();
112 if (ACE_OS::strcmp (id
, exception_id
.in ()) != 0)
113 ACE_ERROR ((LM_ERROR
,
114 "Mismatched exception IDs: %s != %s\n",
116 exception_id
.in ()));
120 ////////////////////////////////// Context /////////////////////////
122 Vault_Client_Request_Context_Interceptor::Vault_Client_Request_Context_Interceptor ()
123 : myname_ ("Vault_Client_Context_Interceptor")
127 Vault_Client_Request_Context_Interceptor::~Vault_Client_Request_Context_Interceptor ()
132 Vault_Client_Request_Context_Interceptor::name ()
134 return CORBA::string_dup (this->myname_
);
138 Vault_Client_Request_Context_Interceptor::destroy ()
143 Vault_Client_Request_Context_Interceptor::send_poll (
144 PortableInterceptor::ClientRequestInfo_ptr
)
150 Vault_Client_Request_Context_Interceptor::send_request (
151 PortableInterceptor::ClientRequestInfo_ptr ri
)
153 // MAke the context to send the context to the target
154 IOP::ServiceContext sc
;
155 sc
.context_id
= request_ctx_id
;
157 const char passwd
[] = "root123";
158 CORBA::ULong string_len
= sizeof (passwd
) + 1;
159 CORBA::Octet
*buf
= 0;
160 ACE_NEW_THROW_EX (buf
,
161 CORBA::Octet
[string_len
],
162 CORBA::NO_MEMORY ());
164 ACE_OS::strcpy (reinterpret_cast<char *> (buf
), passwd
);
166 sc
.context_data
.replace (string_len
, string_len
, buf
, 1);
168 // Add this context to the service context list.
169 ri
->add_request_service_context (sc
, 0);
173 Vault_Client_Request_Context_Interceptor::receive_other (
174 PortableInterceptor::ClientRequestInfo_ptr
)
180 Vault_Client_Request_Context_Interceptor::receive_reply (
181 PortableInterceptor::ClientRequestInfo_ptr
)
186 Vault_Client_Request_Context_Interceptor::receive_exception (
187 PortableInterceptor::ClientRequestInfo_ptr ri
)
189 CORBA::Any_var any
= ri
->received_exception ();
191 CORBA::TypeCode_var tc
= any
->type ();
193 const char *id
= tc
->id ();
195 CORBA::String_var exception_id
=
196 ri
->received_exception_id ();
198 if (ACE_OS::strcmp (id
, exception_id
.in ()) != 0)
199 ACE_ERROR ((LM_ERROR
,
200 "Mismatched exception IDs %s != %s\n",
202 exception_id
.in ()));
206 ///////////////////////////////////Dynamic ////////////////////////////////////
208 Vault_Client_Request_Dynamic_Interceptor::Vault_Client_Request_Dynamic_Interceptor ()
209 : myname_ ("Vault_Client_Dynamic_Interceptor")
213 Vault_Client_Request_Dynamic_Interceptor::~Vault_Client_Request_Dynamic_Interceptor ()
218 Vault_Client_Request_Dynamic_Interceptor::name ()
220 return CORBA::string_dup (this->myname_
);
224 Vault_Client_Request_Dynamic_Interceptor::destroy ()
229 Vault_Client_Request_Dynamic_Interceptor::send_poll (
230 PortableInterceptor::ClientRequestInfo_ptr
)
236 Vault_Client_Request_Dynamic_Interceptor::send_request (
237 PortableInterceptor::ClientRequestInfo_ptr ri
)
239 CORBA::String_var op
= ri
->operation ();
241 if (ACE_OS::strcmp (op
.in (), "authenticate") == 0)
243 Dynamic::ParameterList_var paramlist
=
247 CORBA::ULong i
= 0; // index -- explicitly used to avoid
248 // overloaded operator ambiguity.
249 paramlist
[i
].argument
>>= user
;
252 if (ACE_OS::strcmp (op
.in (), "update_records") == 0)
254 Dynamic::ParameterList_var paramlist
=
257 const Test_Interceptors::Secure_Vault::Record
*record
= 0;
259 CORBA::ULong i
= 0; // index -- explicitly used to avoid
260 // overloaded operator ambiguity.
261 paramlist
[i
++].argument
>>= id
;
262 paramlist
[i
].argument
>>= record
;
267 Vault_Client_Request_Dynamic_Interceptor::receive_reply (
268 PortableInterceptor::ClientRequestInfo_ptr ri
)
270 CORBA::String_var op
= ri
->operation ();
272 if (ACE_OS::strcmp (op
.in (), "ready") == 0)
276 CORBA::Any_var result_any
= ri
->result ();
278 (result_any
.in ()) >>= result
;
281 if (ACE_OS::strcmp (op
.in (), "update_records") == 0)
285 CORBA::Any_var result_any
= ri
->result ();
287 (result_any
.in ()) >>= result
;
292 Vault_Client_Request_Dynamic_Interceptor::receive_other (
293 PortableInterceptor::ClientRequestInfo_ptr
)
299 Vault_Client_Request_Dynamic_Interceptor::receive_exception (
300 PortableInterceptor::ClientRequestInfo_ptr ri
)
302 CORBA::Any_var any
= ri
->received_exception ();
304 CORBA::TypeCode_var tc
= any
->type ();
306 const char *id
= tc
->id ();
308 CORBA::String_var exception_id
=
309 ri
->received_exception_id ();
311 if (ACE_OS::strcmp (id
, exception_id
.in ()) != 0)
312 ACE_ERROR ((LM_ERROR
,
313 "Mismatched exception IDs %s != %s\n",
315 exception_id
.in ()));
319 //////////////////////////////NOOP///////////////////////////////////////
321 Vault_Client_Request_NOOP_Interceptor::Vault_Client_Request_NOOP_Interceptor ()
322 : myname_ ("Vault_Client_NOOP_Interceptor")
326 Vault_Client_Request_NOOP_Interceptor::~Vault_Client_Request_NOOP_Interceptor ()
331 Vault_Client_Request_NOOP_Interceptor::name ()
333 return CORBA::string_dup (this->myname_
);
337 Vault_Client_Request_NOOP_Interceptor::destroy ()
342 Vault_Client_Request_NOOP_Interceptor::send_poll (
343 PortableInterceptor::ClientRequestInfo_ptr
)
349 Vault_Client_Request_NOOP_Interceptor::send_request (
350 PortableInterceptor::ClientRequestInfo_ptr
)
355 Vault_Client_Request_NOOP_Interceptor::receive_other (
356 PortableInterceptor::ClientRequestInfo_ptr
)
362 Vault_Client_Request_NOOP_Interceptor::receive_reply (
363 PortableInterceptor::ClientRequestInfo_ptr
)
368 Vault_Client_Request_NOOP_Interceptor::receive_exception (
369 PortableInterceptor::ClientRequestInfo_ptr ri
)
371 CORBA::Any_var any
= ri
->received_exception ();
373 CORBA::TypeCode_var tc
= any
->type ();
375 const char *id
= tc
->id ();
377 CORBA::String_var exception_id
=
378 ri
->received_exception_id ();
380 if (ACE_OS::strcmp (id
, exception_id
.in ()) != 0)
381 ACE_ERROR ((LM_ERROR
,
382 "Mismatched exception IDs %s != %s\n",
384 exception_id
.in ()));