Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / InsecureReferences / test.cpp
blobe4039ce6ef17f0177295475b29214a7ede6edf92
1 #include "tao/PortableServer/POAC.h"
2 #include "tao/ORB_Constants.h"
3 #include "ace/OS_NS_strings.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR *ior_file = ACE_TEXT("test.ior");
7 const ACE_TCHAR *iorstr = ACE_TEXT("");
9 CORBA::Short endpoint_port = 12345;
10 int verbose = 0;
11 bool as_server = true;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 for (int c = 1; c < argc; c++) {
17 if (ACE_OS::strcasecmp(argv[c], ACE_TEXT("-o")) == 0)
19 ior_file = argv[++c];
21 else if (ACE_OS::strcasecmp(argv[c], ACE_TEXT("-k")) == 0)
23 as_server = false;
24 iorstr = argv[++c];
26 else if (ACE_OS::strcasecmp(argv[c], ACE_TEXT("-p")) == 0)
28 endpoint_port = ACE_OS::atoi (argv[++c]);
30 else if (ACE_OS::strstr(argv[c], ACE_TEXT("-ORB")) == argv[c])
32 c++;
33 continue;
35 else
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-o <iorfile> "
39 "-p <port> "
40 "-v "
41 "\n",
42 argv [0]),
43 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 gen_objref (int argc, ACE_TCHAR *argv[])
52 CORBA::ORB_var orb;
53 CORBA::Object_var obj;
54 PortableServer::POA_var root_poa;
56 ACE_TCHAR **largv = new ACE_TCHAR *[argc+4];
57 ACE_TCHAR *extra[4];
58 int i = 0;
59 for (i = 0; i < argc; i++)
60 largv[i] = argv[i];
62 #ifdef ACE_USES_WCHAR
63 extra[0] = CORBA::wstring_dup (ACE_TEXT ("-ORBEndpoint"));
64 extra[1] =CORBA::wstring_alloc (100);
65 #else
66 extra[0] = CORBA::string_dup ("-ORBEndpoint");
67 extra[1] = CORBA::string_alloc (100);
68 #endif
69 ACE_OS::sprintf (extra[1],
70 ACE_TEXT ("iiop://localhost:%d"),
71 endpoint_port);
73 #ifdef ACE_USES_WCHAR
74 extra[2] = CORBA::wstring_dup (ACE_TEXT ("-ORBEndpoint"));
75 extra[3] = CORBA::wstring_alloc (100);
76 #else
77 extra[2] = CORBA::string_dup ("-ORBEndpoint");
78 extra[3] = CORBA::string_alloc (100);
79 #endif
80 ACE_OS::sprintf (extra[3],
81 ACE_TEXT ("iiop://localhost:%d"),
82 endpoint_port+10);
84 for (i = 0; i < 4; i++)
85 largv[argc++] = extra[i];
87 try
89 orb =
90 CORBA::ORB_init (argc, largv);
92 obj =
93 orb->resolve_initial_references("RootPOA");
95 root_poa =
96 PortableServer::POA::_narrow (obj.in ());
98 if (CORBA::is_nil (root_poa.in ()))
99 ACE_ERROR_RETURN ((LM_ERROR,
100 " (%P|%t) Panic: nil RootPOA\n"),
103 catch (const CORBA::Exception &ex)
105 ex._tao_print_exception("initialization error ");
106 return 1;
109 for (i = 0; i < 4; i++)
110 #ifdef ACE_USES_WCHAR
111 CORBA::wstring_free (extra[i]);
112 #else
113 CORBA::string_free (extra[i]);
114 #endif
116 delete [] largv;
118 CORBA::Object_var o = root_poa->create_reference ("IDL:JustATest:1.0");
120 CORBA::String_var ior =
121 orb->object_to_string (o.in ());
123 FILE *output_file = ACE_OS::fopen (ior_file, "w");
124 if (output_file == 0)
125 ACE_ERROR_RETURN ((LM_ERROR,
126 "Cannot open output file for writing IOR: %s",
127 ior_file),
129 ACE_OS::fprintf (output_file, "%s", ior.in ());
130 ACE_OS::fclose (output_file);
131 return 0;
135 parse_objref (int argc, ACE_TCHAR *argv[])
137 CORBA::ORB_var orb;
138 CORBA::Object_var obj;
142 orb =
143 CORBA::ORB_init (argc, argv);
145 obj = orb->string_to_object (iorstr);
147 orb->destroy ();
149 catch (const CORBA::Exception &ex)
151 ex._tao_print_exception("initialization error ");
152 return 1;
155 return 0;
159 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
161 if (parse_args (argc, argv) != 0)
162 return 1;
163 if (as_server)
164 return gen_objref(argc, argv);
165 return parse_objref(argc, argv);