Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / SimpleCodec / ServerInterceptor.cpp
blob76e1609844566bc673ea86b4b46a00bfe6fe4dc8
1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "tao/OctetSeqC.h"
4 #include <iostream>
6 const IOP::ServiceId service_id = 0xdeed;
7 const CORBA::Long allowed_gid[4] = { 9006, 9007, 9008 };
8 const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"};
10 ServerInterceptor::ServerInterceptor (IOP::CodecFactory_var cf)
11 : myname_ ("Server_Authentication_Interceptor")
13 std::cout << "Calling ServerInterceptor constructor." << std::endl;
15 // Set up a structure that contains information necessary to
16 // create a GIOP 1.2 CDR encapsulation Codec.
17 IOP::Encoding encoding;
18 encoding.format = IOP::ENCODING_CDR_ENCAPS;
19 encoding.major_version = 1;
20 encoding.minor_version = 2;
22 // Obtain the CDR encapsulation Codec.
23 this->codec = cf->create_codec (encoding);
26 ServerInterceptor::~ServerInterceptor ()
30 char *
31 ServerInterceptor::name ()
33 std::cout << "Calling ServerInterceptor name() method" << std::endl;
34 return CORBA::string_dup (this->myname_);
37 void
38 ServerInterceptor::destroy ()
40 std::cout << "Calling destroy()." << std::endl;
43 void
44 ServerInterceptor::receive_request_service_contexts (
45 PortableInterceptor::ServerRequestInfo_ptr)
47 std::cout << "Calling receive_request_service_contexts()." << std::endl;
50 void
51 ServerInterceptor::receive_request (
52 PortableInterceptor::ServerRequestInfo_ptr ri)
54 bool permission_granted = false;
55 std::cout << "Calling receive_request()." << std::endl;
57 if (ri->target_is_a(restricted_interfaces[0])){
58 IOP::ServiceId id = service_id;
59 // Check that the request service context can be retrieved.
60 IOP::ServiceContext_var sc =
61 ri->get_request_service_context (id);
62 // need to construct an octet seq for decoding
63 CORBA::OctetSeq ocSeq = CORBA::OctetSeq(
64 sc->context_data.length(),
65 sc->context_data.length(),
66 sc->context_data.get_buffer(),
67 false);
69 CORBA::Any gid_as_any;
70 gid_as_any = *codec->decode(ocSeq);
72 CORBA::Long gid;
73 if (gid_as_any >>= gid) {
74 for (int i=0; i<3; ++i) {
75 if ( gid == allowed_gid[i] )
77 permission_granted = true;
80 } else {
81 permission_granted = false;
82 std::cerr << "Could not extract GID from any." << std::endl;
86 if (permission_granted == true) {
87 std::cout << "Permission Granted " << std::endl;
89 else {
90 std::cout << "Permission Denied " << std::endl;
94 void
95 ServerInterceptor::send_reply (
96 PortableInterceptor::ServerRequestInfo_ptr ri)
98 ACE_UNUSED_ARG(ri);
99 std::cout << "Calling send_reply()." << std::endl;
102 void
103 ServerInterceptor::send_exception (
104 PortableInterceptor::ServerRequestInfo_ptr ri)
106 ACE_UNUSED_ARG(ri);
107 std::cout << "Calling send_exception()." << std::endl;
110 void
111 ServerInterceptor::send_other (
112 PortableInterceptor::ServerRequestInfo_ptr ri)
114 ACE_UNUSED_ARG(ri);
115 std::cout << "Calling send_other()." << std::endl;