1 /*
2 * Copyright 1999-2006 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "globus_i_wsrf_app.h"
18 #include "globus_wsrf_options.h"
19 #include "version.h"
20
21 /**
22 * @defgroup globus_wsrp_tools_programs WS-ResourceProperties Client Programs
23 */
24 /**
25 * @defgroup globus_wsrl_tools_programs WS-ResourceLifetime Client Programs
26 */
27
28 #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
29 globus_result_t
30 globus_i_wsrf_run_app(
31 globus_i_wsrf_app_t * app,
32 int argc,
33 char * argv[])
34 36 {
35 globus_result_t result;
36 globus_module_descriptor_t * failed_module;
37 int rc;
38 36 xsd_any * fault = NULL;
39
40 36 rc = globus_module_activate_array(app->module_list, &failed_module);
41
42 36 if (rc != GLOBUS_SUCCESS)
43 {
44 0 fprintf(stderr, "Error %d initializing %s\n", rc, failed_module->module_name);
45
46 0 result = GLOBUS_FAILURE;
47
48 0 goto out;
49 }
50
51 36 if (app->initialize_arg)
52 {
53 33 result = app->initialize_arg(app);
54
55 33 if (result != GLOBUS_SUCCESS)
56 {
57 0 goto deactivate_out;
58 }
59 }
60
61 36 result = globus_i_wsrf_app_parse_options(
62 argc,
63 argv,
64 app->usage,
65 app->help_footer,
66 app->options_table,
67 app->options_arg,
68 app->unknown_handler,
69 &app->epr,
70 &app->attr,
71 &app->debug);
72 36 if (result != GLOBUS_SUCCESS)
73 {
74 0 if (globus_error_match(globus_error_peek(result), NULL, GLOBUS_OPTIONS_HELP))
75 {
76 0 result = GLOBUS_SUCCESS;
77 }
78 0 goto deactivate_out;
79 }
80
81
82 36 result = app->invoke_function(
83 app,
84 &fault);
85
86 36 if (fault != NULL)
87 {
88 0 if (app->debug)
89 {
90 0 result = globus_i_wsrf_app_print_fault(fault);
91 0 printf("Error: %s\n", globus_error_print_friendly(globus_error_get(result)));
92 }
93 else
94 {
95 0 fprintf(stderr, "Error: %s\n", fault->element->local);
96 }
97 }
98 36 else if (result != GLOBUS_SUCCESS)
99 {
100 0 printf("Error: %s\n", globus_error_print_friendly(globus_error_get(result)));
101 }
102 36 deactivate_out:
103 36 globus_module_deactivate_all();
104
105 36 out:
106 36 return result;
107 }
108 /* globus_i_wsrf_app() */
109
110
111 globus_result_t
112 globus_i_wsrf_app_print_fault(
113 xsd_any * fault)
114 0 {
115 0 globus_result_t result = GLOBUS_SUCCESS;
116 globus_soap_message_handle_t stderr_handle;
117
118 0 result = globus_soap_message_handle_init_to_file(
119 &stderr_handle,
120 "stderr://",
121 O_WRONLY);
122
123 0 if (result != GLOBUS_SUCCESS)
124 {
125 0 goto out;
126 }
127 0 result = xsd_any_serialize(
128 fault->element,
129 fault,
130 stderr_handle,
131 0);
132 0 globus_soap_message_handle_destroy(stderr_handle);
133 0 out:
134
135 0 return result;
136 }
137 /* globus_i_wsrf_app_print_fault() */
138
139 globus_result_t
140 globus_i_wsrf_app_parse_options(
141 int argc,
142 char * argv[],
143 const char * usage,
144 const char * footer,
145 globus_options_entry_t * app_options_table,
146 void * app_options_arg,
147 globus_options_unknown_callback_t unknown_handler,
148 wsa_EndpointReferenceType * epr,
149 globus_soap_message_attr_t * attr,
150 globus_bool_t * debug)
151 36 {
152 globus_result_t result;
153 globus_wsrf_options_handle_t wsrf_options;
154 globus_options_handle_t options_handle;
155 char * progname;
156
157 36 progname = strrchr(argv[0], '/');
158
159 36 progname = progname ? progname + 1 : argv[0];
160
161 36 result = globus_wsrf_options_handle_init(
162 &wsrf_options,
163 argv[0],
164 &local_version,
165 usage,
166 footer);
167
168 36 if (result != GLOBUS_SUCCESS)
169 {
170 0 goto out;
171 }
172 36 result = globus_options_init(
173 &options_handle,
174 unknown_handler,
175 app_options_arg);
176 36 if (result != GLOBUS_SUCCESS)
177 {
178 0 goto destroy_wsrf_options_out;
179 }
180 36 result = globus_wsrf_options_handle_add_to_table(
181 wsrf_options,
182 options_handle);
183 36 if (result != GLOBUS_SUCCESS)
184 {
185 0 goto destroy_options_out;
186 }
187 36 if (app_options_table)
188 {
189 6 result = globus_options_add_table(
190 options_handle,
191 app_options_table,
192 app_options_arg);
193 6 if (result != GLOBUS_SUCCESS)
194 {
195 0 goto destroy_options_out;
196 }
197 }
198 36 result = globus_options_command_line_process(
199 options_handle,
200 argc,
201 argv);
202 36 if (result != GLOBUS_SUCCESS)
203 {
204 0 if (!globus_error_match(globus_error_peek(result), NULL, GLOBUS_OPTIONS_HELP))
205 {
206 0 fprintf(stderr, "%s\n",
207 globus_error_print_friendly(globus_error_peek(result)));
208 0 fprintf(stderr, "Usage: %s %s\n", progname, usage);
209 }
210 0 goto destroy_options_out;
211 }
212 36 result = globus_wsrf_options_handle_get_debug(
213 wsrf_options,
214 debug);
215 36 if (result != GLOBUS_SUCCESS)
216 {
217 0 fprintf(stderr, "Usage: %s %s\n", progname, usage);
218
219 0 goto destroy_options_out;
220 }
221 36 result = globus_wsrf_options_handle_get_attr(
222 wsrf_options,
223 attr);
224 36 if (result != GLOBUS_SUCCESS)
225 {
226 0 fprintf(stderr, "Usage: %s %s\n", progname, usage);
227
228 0 goto destroy_options_out;
229 }
230 36 result = globus_wsrf_options_handle_get_epr(
231 wsrf_options,
232 epr);
233 36 if (result != GLOBUS_SUCCESS)
234 {
235 0 fprintf(stderr, "Usage: %s %s\n", progname, usage);
236
237 0 goto destroy_attr_out;
238 }
239
240 36 destroy_attr_out:
241 36 if (result != GLOBUS_SUCCESS)
242 {
243 0 globus_soap_message_attr_destroy(*attr);
244 0 *attr = NULL;
245 }
246 36 destroy_options_out:
247 36 globus_options_destroy(options_handle);
248 36 destroy_wsrf_options_out:
249 36 globus_wsrf_options_handle_destroy(wsrf_options);
250 36 out:
251 36 return result;
252 }
253 /* globus_i_wsrf_app_parse_options() */
254
255 globus_result_t
256 globus_i_wsrf_parse_qname(
257 char * qname_string,
258 xsd_QName * qname)
259 9 {
260 int rc;
261 9 globus_result_t result = GLOBUS_SUCCESS;
262
263 9 qname->local = malloc(strlen(qname_string)+1);
264 9 if (qname->local == NULL)
265 {
266 0 result = GlobusSoapMessageErrorOutOfMemory;
267
268 0 goto out;
269 }
270 9 if (qname_string[0] == '{')
271 {
272 9 qname->Namespace = malloc(strlen(qname_string)+1);
273 9 if (qname->Namespace == NULL)
274 {
275 0 result = GlobusSoapMessageErrorOutOfMemory;
276
277 0 goto free_local_out;
278 }
279 9 rc = sscanf(qname_string, "{%[^}]}%s", qname->Namespace, qname->local);
280
281 9 if (rc != 2)
282 {
283 0 result = globus_error_put(
284 globus_error_construct_error(
285 NULL,
286 NULL,
287 GLOBUS_OPTIONS_INVALID_PARAMETER,
288 __FILE__,
289 "globus_i_wsrf_parse_qname",
290 __LINE__,
291 "Invalid QName %s",
292 qname_string));
293
294 0 goto free_ns_out;
295 }
296 }
297 else
298 {
299 0 qname->Namespace = NULL;
300 0 strcpy(qname->local, qname_string);
301 }
302
303 9 if (result != GLOBUS_SUCCESS)
304 {
305 0 free_local_out:
306 0 free(qname->local);
307 0 qname->local = NULL;
308 0 free_ns_out:
309 0 free(qname->Namespace);
310 0 qname->Namespace = NULL;
311 }
312 9 out:
313 9 return result;
314 }
315 /* globus_i_wsrf_parse_qname() */
316