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 "NotificationProducerTestService_skeleton.h"
18 #include "NotificationProducerTestService_internal_skeleton.h"
19 #include "globus_wsrf_resource.h"
20 #include "globus_notification_producer.h"
21 #include "globus_ws_addressing.h"
22 #include "nptest_TopicDefinitionType.h"
23 #include "globus_wsnt_topic_utils.h"
24
25 static
26 globus_result_t
27 globus_l_producer_create_resource_id(
28 xsd_any * property,
29 char * resource_id);
30
31 globus_result_t
32 globus_l_notification_create_topic(
33 const char * resource_id,
34 nptest_TopicDefinitionType * topic);
35
36 globus_result_t
37 NotificationProducerTestService_init(
38 globus_service_descriptor_t * service_desc)
39 36 {
40 int rc;
41 36 globus_result_t result = GLOBUS_SUCCESS;
42
43 36 rc = globus_module_activate(GLOBUS_WSRF_RESOURCE_MODULE);
44
45 36 if (rc != GLOBUS_SUCCESS)
46 {
47 0 result = GLOBUS_FAILURE;
48
49 0 goto error_out;
50 }
51
52 36 rc = globus_module_activate(GLOBUS_NOTIFICATION_PRODUCER_MODULE);
53
54 36 if (rc != GLOBUS_SUCCESS)
55 {
56 0 result = GLOBUS_FAILURE;
57
58 0 goto deactivate_resource_out;
59 }
60
61 36 if (result != GLOBUS_SUCCESS)
62 {
63 0 deactivate_resource_out:
64 0 globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE);
65 }
66 36 error_out:
67 36 return result;
68 }
69 /* NotificationProducerTestService_init() */
70
71 globus_result_t
72 NotificationProducerTestService_finalize(
73 globus_service_descriptor_t * service_desc)
74 0 {
75 0 globus_module_deactivate(GLOBUS_NOTIFICATION_PRODUCER_MODULE);
76 0 globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE);
77
78 0 return GLOBUS_SUCCESS;
79 }
80 /* NotificationProducerTestService_finalize() */
81
82
83 globus_result_t
84 NotificationProducerTestPortType_GetCurrentMessage_impl(
85 globus_service_engine_t engine,
86 globus_soap_message_handle_t message,
87 globus_service_descriptor_t * descriptor,
88 wsnt_GetCurrentMessageType * GetCurrentMessage,
89 wsnt_GetCurrentMessageResponseType * GetCurrentMessageResponse,
90 xsd_any * fault)
91 0 {
92 /* implemented by provider */
93 0 return globus_error_put(GLOBUS_ERROR_NO_INFO);
94 }
95 /* NotificationProducerTestPortType_GetCurrentMessage_impl() */
96
97
98 /* these functions are the service implementation and
99 * must be implemented by the service implementer
100 */
101 globus_result_t
102 NotificationProducerTestPortType_Subscribe_impl(
103 globus_service_engine_t engine,
104 globus_soap_message_handle_t message,
105 globus_service_descriptor_t * descriptor,
106 wsnt_SubscribeType * Subscribe,
107 wsnt_SubscribeResponseType * SubscribeResponse,
108 xsd_any * fault)
109 0 {
110 /* implemented by provider */
111 0 return globus_error_put(GLOBUS_ERROR_NO_INFO);
112 }
113 /* NotificationProducerTestPortType_Subscribe_impl() */
114
115 /* these functions are the service implementation and
116 * must be implemented by the service implementer
117 */
118
119 globus_result_t
120 NotificationProducerTestPortType_GetResourceProperty_impl(
121 globus_service_engine_t engine,
122 globus_soap_message_handle_t message,
123 globus_service_descriptor_t * descriptor,
124 xsd_QName * GetResourceProperty,
125 wsrp_GetResourcePropertyResponseType * GetResourcePropertyResponse,
126 xsd_any * fault)
127 0 {
128 /* implemented by provider */
129 0 return globus_error_put(GLOBUS_ERROR_NO_INFO);
130 }
131 /* NotificationProducerTestPortType_GetResourceProperty_impl() */
132
133 /* these functions are the service implementation and
134 * must be implemented by the service implementer
135 */
136
137 globus_result_t
138 NotificationProducerTestPortType_SetResourceProperties_impl(
139 globus_service_engine_t engine,
140 globus_soap_message_handle_t message,
141 globus_service_descriptor_t * descriptor,
142 wsrp_SetResourcePropertiesType * SetResourceProperties,
143 wsrp_SetResourcePropertiesResponseType * SetResourcePropertiesResponse,
144 xsd_any * fault)
145 0 {
146 /* implemented by provider */
147 0 return globus_error_put(GLOBUS_ERROR_NO_INFO);
148 }
149 /* NotificationProducerTestPortType_SetResourceProperties_impl() */
150
151 /* these functions are the service implementation and
152 * must be implemented by the service implementer
153 */
154
155 globus_result_t
156 NotificationProducerTestPortType_Destroy_impl(
157 globus_service_engine_t engine,
158 globus_soap_message_handle_t message,
159 globus_service_descriptor_t * descriptor,
160 wsrl_DestroyType * Destroy,
161 wsrl_DestroyResponseType * DestroyResponse,
162 xsd_any * fault)
163 0 {
164 /* implemented by provider */
165 0 return globus_error_put(GLOBUS_ERROR_NO_INFO);
166 }
167 /* NotificationProducerTestPortType_Destroy_impl() */
168
169 /* these functions are the service implementation and
170 * must be implemented by the service implementer
171 */
172
173 globus_result_t
174 NotificationProducerTestPortType_SetTopicValue_impl(
175 globus_service_engine_t engine,
176 globus_soap_message_handle_t message,
177 globus_service_descriptor_t * descriptor,
178 nptest_SetTopicValueType * SetTopicValue,
179 xsd_anyType * SetTopicValueResponse,
180 xsd_any * fault)
181 30 {
182 wsa_EndpointReferenceType * epr;
183 char * resource_id;
184 globus_result_t result;
185 xsd_any tmp;
186
187 30 epr = globus_soap_message_handle_get_attr(
188 message,
189 WSADDR_EPR_KEY);
190
191 30 if (epr == NULL)
192 {
193 0 result = GLOBUS_FAILURE;
194
195 0 goto out;
196 }
197
198 30 result = descriptor->get_resource_id(
199 &epr->ReferenceParameters->any,
200 &resource_id);
201
202 30 if (result != GLOBUS_SUCCESS)
203 {
204 0 goto out;
205 }
206 30 result = xsd_any_init_contents(&tmp);
207 30 if (result != GLOBUS_SUCCESS)
208 {
209 0 goto free_resource_id_out;
210 }
211 30 tmp.value = SetTopicValue->TopicValue.value;
212 30 tmp.any_info = SetTopicValue->TopicValue.any_info;
213
214 30 result = globus_notification_producer_topic_changed(
215 resource_id,
216 &SetTopicValue->TopicExpression,
217 &tmp,
218 NULL,
219 NULL);
220
221 30 free_resource_id_out:
222 30 free(resource_id);
223
224 30 out:
225 30 return result;
226 }
227 /* NotificationProducerTestPortType_SetTopicValue_impl() */
228
229 /* these functions are the service implementation and
230 * must be implemented by the service implementer
231 */
232
233 globus_result_t
234 NotificationProducerTestPortType_DestroyTopic_impl(
235 globus_service_engine_t engine,
236 globus_soap_message_handle_t message,
237 globus_service_descriptor_t * descriptor,
238 wsnt_TopicExpressionType * DestroyTopic,
239 xsd_anyType * DestroyTopicResponse,
240 xsd_any * fault)
241 3 {
242 int i;
243 3 globus_result_t result = GLOBUS_SUCCESS;
244 wsa_EndpointReferenceType * epr;
245 char * resource_id;
246
247 3 epr = globus_soap_message_handle_get_attr(
248 message,
249 WSADDR_EPR_KEY);
250
251 3 if (epr == NULL)
252 {
253 0 result = GLOBUS_FAILURE;
254
255 0 goto out;
256 }
257
258 3 result = descriptor->get_resource_id(
259 &epr->ReferenceParameters->any,
260 &resource_id);
261
262 3 if (result != GLOBUS_SUCCESS)
263 {
264 0 goto out;
265 }
266
267 3 result = globus_notification_producer_topic_destroy(
268 resource_id,
269 DestroyTopic);
270
271 3 free(resource_id);
272
273 3 out:
274 3 return result;
275 }
276
277
278 /* these functions are the service implementation and
279 * must be implemented by the service implementer
280 */
281
282 globus_result_t
283 NotificationProducerTestPortType_CreateTopic_impl(
284 globus_service_engine_t engine,
285 globus_soap_message_handle_t message,
286 globus_service_descriptor_t * descriptor,
287 nptest_CreateTopicType * CreateTopic,
288 xsd_anyType * CreateTopicResponse,
289 xsd_any * fault)
290 57 {
291 int i;
292 57 globus_result_t result = GLOBUS_SUCCESS;
293 wsa_EndpointReferenceType * epr;
294 char * resource_id;
295
296 57 epr = globus_soap_message_handle_get_attr(
297 message,
298 WSADDR_EPR_KEY);
299
300 57 if (epr == NULL)
301 {
302 0 result = GLOBUS_FAILURE;
303
304 0 goto out;
305 }
306
307 57 result = descriptor->get_resource_id(
308 &epr->ReferenceParameters->any,
309 &resource_id);
310
311 57 if (result != GLOBUS_SUCCESS)
312 {
313 0 goto out;
314 }
315
316 114 for (i = 0; i < CreateTopic->TopicDefinition.length; i++)
317 {
318 57 result = globus_l_notification_create_topic(
319 resource_id,
320 &CreateTopic->TopicDefinition.elements[i]);
321
322 57 if (result != GLOBUS_SUCCESS)
323 {
324 0 break;
325 }
326 }
327
328 57 free(resource_id);
329
330 57 out:
331 57 return result;
332 }
333 /* NotificationProducerTestPortType_CreateTopic_impl() */
334
335 /* these functions are the service implementation and
336 * must be implemented by the service implementer
337 */
338
339 globus_result_t
340 NotificationProducerTestPortType_CreateNotificationProducerTest_impl(
341 globus_service_engine_t engine,
342 globus_soap_message_handle_t message,
343 globus_service_descriptor_t * descriptor,
344 xsd_anyType * CreateNotificationProducerTest,
345 nptest_CreateNotificationProducerTestResponseType * CreateNotificationProducerTestResponse,
346 xsd_any * fault)
347 36 {
348 globus_uuid_t uuid;
349 globus_result_t result;
350 globus_resource_t resource;
351 xsd_any * resource_reference;
352 char * endpoint;
353 int i;
354
355 36 result = globus_uuid_create(&uuid);
356
357 36 if (result != GLOBUS_SUCCESS)
358 {
359 0 goto out;
360 }
361
362 36 result = globus_resource_create(uuid.text, &resource);
363
364 36 if (result != GLOBUS_SUCCESS)
365 {
366 0 goto out;
367 }
368
369 36 result = nptest_CreateNotificationProducerTestResponseType_init_contents(
370 CreateNotificationProducerTestResponse);
371 36 if (result != GLOBUS_SUCCESS)
372 {
373 0 goto destroy_resource_out;
374 }
375
376 36 result = wsa_ReferenceParametersType_init(
377 &CreateNotificationProducerTestResponse->EndpointReference.ReferenceParameters);
378 36 if (result != GLOBUS_SUCCESS)
379 {
380 0 goto destroy_resource_out;
381 }
382
383 36 resource_reference = xsd_any_array_push(
384 &CreateNotificationProducerTestResponse->EndpointReference.ReferenceParameters->any);
385 36 if (resource_reference == GLOBUS_NULL)
386 {
387 0 result = GLOBUS_FAILURE;
388
389 0 goto destroy_resource_out;
390 }
391
392 36 result = globus_l_producer_create_resource_id(
393 resource_reference,
394 uuid.text);
395 36 if (result != GLOBUS_SUCCESS)
396 {
397 0 goto destroy_resource_out;
398 }
399
400 36 result = globus_service_engine_get_contact(engine, &endpoint);
401
402 36 CreateNotificationProducerTestResponse->EndpointReference.Address.base_value =
403 globus_common_create_string(
404 "%s/%s",
405 endpoint,
406 NOTIFICATIONPRODUCERTESTSERVICE_BASE_PATH);
407
408
409 36 result = NotificationProducerTestServiceInitResource(
410 &CreateNotificationProducerTestResponse->EndpointReference);
411 36 if (result != GLOBUS_SUCCESS)
412 {
413 0 goto destroy_resource_out;
414 }
415
416 36 globus_resource_finish(resource);
417
418 36 return GLOBUS_SUCCESS;
419
420 0 destroy_resource_out:
421 0 globus_resource_destroy(resource);
422 0 out:
423 0 return result;
424 }
425 /* NotificationProducerTestPortType_CreateNotificationProducerTest_impl() */
426
427 #define NOTIFICATION_NS \
428 "http://www.globus.org/namespaces/2007/06/NotificationProducerTest"
429
430 static
431 globus_result_t
432 globus_l_producer_create_resource_id(
433 xsd_any * property,
434 char * resource_id)
435 36 {
436 xsd_string * val;
437 globus_result_t result;
438
439 36 property->any_info = &xsd_string_info;
440 36 result = xsd_QName_init(&property->element);
441 36 if (result != GLOBUS_SUCCESS)
442 {
443 0 goto free_any_out;
444 }
445
446 36 property->element->Namespace = globus_libc_strdup(NOTIFICATION_NS);
447
448 36 if (property->element->Namespace == NULL)
449 {
450 0 result = globus_error_put(GLOBUS_ERROR_NO_INFO);
451 0 goto free_any_out;
452 }
453
454 36 property->element->local = globus_libc_strdup("ResourceID");
455 36 if (property->element->local == NULL)
456 {
457 0 result = globus_error_put(GLOBUS_ERROR_NO_INFO);
458 0 goto free_any_out;
459 }
460
461 36 result = xsd_string_init_cstr(
462 (xsd_string **) &property->value,
463 globus_libc_strdup(resource_id));
464 36 if (result != GLOBUS_SUCCESS)
465 {
466 0 goto free_any_out;
467 }
468
469 36 return GLOBUS_SUCCESS;
470
471 0 free_any_out:
472 0 xsd_any_destroy_contents(property);
473 0 out:
474
475 0 return result;
476 }
477 /* globus_l_producer_create_resource_id() */
478
479 globus_result_t
480 globus_l_notification_create_topic(
481 const char * resource_id,
482 nptest_TopicDefinitionType * topic)
483 57 {
484 globus_result_t result;
485 xsd_any tmp;
486 globus_wsnt_topic_value_t topic_value;
487 int i;
488 xsd_QName qn;
489
490 57 result = globus_wsnt_convert_topic_to_value(
491 topic->TopicExpression.any,
492 &topic_value);
493
494 57 if (result != GLOBUS_SUCCESS)
495 {
496 0 goto out;
497 }
498
499 57 result = xsd_QName_init_contents(&qn);
500 57 if (result != GLOBUS_SUCCESS)
501 {
502 0 goto destroy_topic_value_out;
503 }
504
505 201 for (i = 0; i < topic_value.num_tokens; i++)
506 {
507 144 if (topic_value.tokens[i] == GLOBUS_WSNT_TOPIC_NAMESPACE)
508 {
509 57 qn.Namespace = topic_value.token_values[i];
510 }
511 87 else if (topic_value.tokens[i] == GLOBUS_WSNT_TOPIC_PATH_NAME)
512 {
513 87 qn.local = topic_value.token_values[i];
514 }
515 }
516
517 57 if (qn.local == NULL)
518 {
519 0 result = GlobusSoapMessageErrorOutOfMemory;
520
521 0 goto out;
522 }
523
524 57 result = globus_xsd_type_registry_insert_element(
525 GLOBUS_GLOBAL_TYPE_REGISTRY,
526 &qn,
527 &topic->TopicElementTypeQName);
528 57 if (result != GLOBUS_SUCCESS)
529 {
530 0 goto out;
531 }
532
533 57 result = globus_notification_producer_topic_create(
534 resource_id,
535 &topic->TopicExpression);
536 57 if (result != GLOBUS_SUCCESS)
537 {
538 0 goto out;
539 }
540
541 57 if (topic->TopicValue != NULL)
542 {
543 0 tmp.any_info = topic->TopicValue->any_info;
544 0 tmp.value = topic->TopicValue->value;
545
546 0 result = globus_notification_producer_topic_changed(
547 resource_id,
548 &topic->TopicExpression,
549 &tmp,
550 GLOBUS_NULL,
551 GLOBUS_NULL);
552 0 if (result != GLOBUS_SUCCESS)
553 {
554 0 goto destroy_topic_out;
555 }
556 }
557
558 57 return result;
559
560 0 destroy_topic_out:
561 0 if (result != GLOBUS_SUCCESS)
562 {
563 0 globus_notification_producer_topic_destroy(
564 resource_id,
565 &topic->TopicExpression);
566 }
567 0 destroy_topic_value_out:
568 0 globus_wsnt_topic_value_destroy(&topic_value);
569
570 0 out:
571 0 return result;
572 }