Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Bug_1107_Regression / server.cpp
blob18ed207e4b121194d44749a0cc0dde282d7a995e
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "Foo_i.h"
5 #include "ace/SString.h"
7 const ACE_TCHAR *ior_output_file = 0;
8 const char *cert_file = "cacert.pem";
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "Usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
40 ACE_CString env ("SSL_CERT_FILE=");
41 env += cert_file;
42 ACE_OS::putenv (env.c_str ());
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 CORBA::Object_var obj =
48 orb->resolve_initial_references ("RootPOA");
50 if (CORBA::is_nil (obj.in ()))
51 ACE_ERROR_RETURN ((LM_ERROR,
52 "(%P|%t) ERROR: Unable to initialize the "
53 "POA.\n"),
54 1);
56 PortableServer::POA_var root_poa =
57 PortableServer::POA::_narrow (obj.in ());
59 PortableServer::POAManager_var poa_manager =
60 root_poa->the_POAManager ();
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 obj =
66 orb->resolve_initial_references ("SecurityLevel3:SecurityCurrent");
68 SecurityLevel3::SecurityCurrent_var security_current =
69 SecurityLevel3::SecurityCurrent::_narrow (obj.in ());
71 if (CORBA::is_nil (security_current.in ()))
72 ACE_ERROR_RETURN ((LM_ERROR,
73 "(%P|%t) ERROR: SecurityCurrent reference "
74 "is nil.\n"),
75 1);
77 Foo_i *server_impl = 0;
79 ACE_NEW_RETURN (server_impl,
80 Foo_i (orb.in (),
81 security_current.in ()),
82 -1);
84 PortableServer::ServantBase_var owner_transfer (server_impl);
86 Foo::Bar_var server =
87 server_impl->_this ();
89 // Sanity check on SSLIOP profile equivalence.
90 // Since the POA is reference counting the servants, this
91 // implementation must still exist when the POA is destroyed.
92 Foo_i server_impl2 (orb.in (), security_current.in ());
93 Foo::Bar_var server2 =
94 server_impl2._this ();
96 const CORBA::Boolean equivalent =
97 server->_is_equivalent (server2.in ());
99 if (equivalent)
101 ACE_ERROR ((LM_ERROR,
102 "(%P|%t) ERROR: SSLIOP profile equivalence "
103 "check failed.\n"));
106 CORBA::String_var ior =
107 orb->object_to_string (server.in ());
109 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
111 // If the ior_output_file exists, output the ior to it
112 if (ior_output_file != 0)
114 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
115 if (output_file == 0)
116 ACE_ERROR_RETURN ((LM_ERROR,
117 "Cannot open output file for writing IOR: %s",
118 ior_output_file),
120 ACE_OS::fprintf (output_file, "%s", ior.in ());
121 ACE_OS::fclose (output_file);
124 poa_manager->activate ();
126 // Clear the STDERR flags so that the first expected
127 // failed connection attempt by the client doesn't trigger an
128 // error on the scoreboard. The flag is also set in the
129 // Foo_i::baz() method since the connection has been successfully
130 // made by that time.
131 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);
132 orb->run ();
133 ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);
135 ACE_DEBUG ((LM_DEBUG,
136 "\n"
137 "Event loop finished.\n"));
139 root_poa->destroy (true, true);
141 orb->destroy ();
143 catch (const CORBA::Exception& ex)
145 ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);
146 ex._tao_print_exception ("Caught exception:");
147 return 1;
150 return 0;