Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / Security / ParticipatingApp / MessengerClient.cpp
bloba0046a31b219dc08830ec1b27ad4bc6efc634a9c
1 /* -*- C++ -*- */
3 #include "orbsvcs/SecurityC.h"
4 #include "MessengerC.h"
5 #include "ace/Get_Opt.h"
7 #if 0
8 The servers service configuration file
9 for this example is:
10 ---------------------------------------
11 # server.conf
12 dynamic SSLIOP_Factory Service_Object *
13 TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
14 "-SSLNoProtection \
15 -SSLAuthenticate SERVER_AND_CLIENT \
16 -SSLPrivateKey PEM:server_key.pem \
17 -SSLCertificate PEM:server_cert.pem"
19 static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
20 ---------------------------------------
22 The clients service configuration file
23 for this example is:
24 ---------------------------------------
25 # client.conf
26 dynamic SSLIOP_Factory Service_Object *
27 TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
28 "-SSLNoProtection \
29 -SSLAuthenticate SERVER \
30 -SSLPrivateKey PEM:client_key.pem \
31 -SSLCertificate PEM:client_cert.pem"
33 static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
34 ---------------------------------------
35 #endif
37 const ACE_TCHAR *ior = ACE_TEXT ("file://Messenger.ior");
39 int
40 parse_args (int argc, ACE_TCHAR *argv[])
42 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
43 int c;
45 while ((c = get_opts ()) != -1)
46 switch (c)
48 case 'k':
49 ior = get_opts.opt_arg ();
50 break;
52 case '?':
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-k <ior> "
57 "\n",
58 argv [0]),
59 -1);
61 // Indicates successful parsing of the command line
62 return 0;
65 int
66 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
68 try {
69 CORBA::ORB_var orb =
70 CORBA::ORB_init( argc, argv );
72 if (parse_args (argc, argv) != 0)
73 return 1;
75 CORBA::Object_var obj =
76 orb->string_to_object( ior );
78 Messenger_var messenger =
79 Messenger::_narrow( obj.in() );
81 CORBA::String_var message =
82 CORBA::string_dup( "Terminating messenger service!" );
84 messenger->send_message( "Chief of Security",
85 "New Directive",
86 message.inout() );
88 messenger->shutdown("Chief of Security");
90 Security::QOP qop =
91 Security::SecQOPIntegrityAndConfidentiality;
93 CORBA::Any want_protection;
94 want_protection <<= qop;
96 CORBA::Policy_var policy =
97 orb->create_policy (Security::SecQOPPolicy,
98 want_protection);
100 Security::EstablishTrust establish_trust;
101 establish_trust.trust_in_client = 0;
102 establish_trust.trust_in_target = 1;
104 CORBA::Any want_trust;
105 want_trust <<= establish_trust;
107 CORBA::Policy_var policy2 =
108 orb->create_policy (Security::SecEstablishTrustPolicy,
109 want_trust);
112 CORBA::PolicyList policy_list (2);
113 policy_list.length (1);
114 policy_list[0] =
115 CORBA::Policy::_duplicate (policy.in ());
116 policy_list.length (2);
117 policy_list[1] =
118 CORBA::Policy::_duplicate (policy2.in ());
121 CORBA::Object_var object =
122 obj->_set_policy_overrides (policy_list,
123 CORBA::SET_OVERRIDE);
125 Messenger_var messenger2 =
126 Messenger::_narrow( object.in() );
128 message =
129 CORBA::string_dup( "Terminating messenger service!" );
131 messenger2->send_message( "Chief of Security",
132 "New Directive",
133 message.inout() );
135 messenger2->shutdown("Chief of Security");
137 orb->destroy();
139 catch(const CORBA::Exception& ex)
141 ex._tao_print_exception("Client: main block");
142 return 1;
145 return 0;