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_common.h"
18 #include "globus_soap_message.h"
19 #include "globus_wsrf_resource.h"
20 #include "globus_service_engine.h"
21 #include "globus_operation_provider.h"
22 #include "globus_service_registry.h"
23 #include "globus_wsrf_core_tools.h"
24 #include "globus_wsrf_core_error.h"
25 #include "globus_notification_producer.h"
26 #include "globus_ws_addressing.h"
27 #include "version.h"
28
29 #include "wsnt_SubscribeType.h"
30 #include "wsnt_SubscribeResponseType.h"
31 #include "wsnt_GetCurrentMessageType.h"
32 #include "wsnt_GetCurrentMessageResponseType.h"
33 #include "wsnt_TopicExpression.h"
34 #include "wsnt_TopicExpressionType.h"
35
36 #include "wsrp_ResourcePropertyValueChangeNotificationType.h"
37 #include "wsrp_ResourcePropertyValueChangeNotification.h"
38
39 #include "wsr_ResourceUnknownFault.h"
40 #include "wsnt_NoCurrentMessageOnTopicFault.h"
41 #include "wsnt_SubscribeCreationFailedFault.h"
42 #include "wsnt_InvalidFilterFault.h"
43 #include "wsnt_InvalidTopicExpressionFault.h"
44 #include "wsnt_TopicNotSupportedFault.h"
45 #include "wsnt_InvalidProducerPropertiesExpressionFault.h"
46 #include "wsnt_InvalidMessageContentExpressionFault.h"
47 #include "wsnt_UnrecognizedPolicyRequestFault.h"
48 #include "wsnt_UnsupportedPolicyRequestFault.h"
49 #include "wsnt_NotifyMessageNotSupportedFault.h"
50 #include "wsnt_UnacceptableTerminationTimeFault.h"
51 #include "wsnt_TopicExpressionDialectUnknownFault.h"
52 #include "wsnt_SubscribeCreationFailedFault.h"
53
54 /* RP QName definitions */
55 #include "wsnt_TopicExpression.h"
56 #include "wsnt_FixedTopicSet.h"
57 #include "wsnt_TopicExpressionDialect.h"
58 #include "wstop_SimpleTopicExpression.h"
59 #include "wstop_TopicSet.h"
60
61 typedef enum
62 {
63 WSNT_SUBSCRIBE,
64 WSNT_GET_CURRENT_MESSAGE
65 }
66 globus_l_notification_producer_operation_t;
67
68 static
69 xsd_anyURI globus_l_notification_dialects[] =
70 {
71 "http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple",
72 "http://docs.oasis-open.org/wsn/t-1/TopicExpression/Concrete",
73 "http://docs.oasis-open.org/wsn/t-1/TopicExpression/Full",
74 NULL
75 };
76
77 typedef struct
78 {
79 char * resource_id;
80 globus_callback_handle_t handle;
81 }
82 globus_l_notification_state_t;
83
84 /* Prototypes */
85 static
86 globus_result_t
87 wsnt_NotificationProducer_init_resource(
88 const struct wsa_EndpointReferenceType_s *epr);
89
90 static
91 globus_result_t
92 wsnt_Subscribe_provider(
93 globus_service_engine_t engine,
94 globus_soap_message_handle_t handle,
95 globus_service_descriptor_t * service,
96 wsnt_SubscribeType * input,
97 wsnt_SubscribeResponseType * output,
98 xsd_any * fault);
99
100 static
101 globus_result_t
102 wsnt_GetCurrentMessage_provider(
103 globus_service_engine_t engine,
104 globus_soap_message_handle_t handle,
105 globus_service_descriptor_t * service,
106 wsnt_GetCurrentMessageType * input,
107 wsnt_GetCurrentMessageResponseType *output,
108 xsd_any * fault);
109
110 static
111 globus_bool_t
112 wsnt_l_NotificationProducer_set_TopicExpression(
113 void * arg,
114 const xsd_QName * qname,
115 void * property);
116
117 static
118 void
119 wsnt_l_NotificationProducer_get_TopicExpression(
120 void * arg,
121 const xsd_QName * qname,
122 void ** property);
123
124 static
125 globus_bool_t
126 wsnt_l_NotificationProducer_set_TopicSet(
127 void * arg,
128 const xsd_QName * qname,
129 void * property);
130
131 static
132 void
133 wsnt_l_NotificationProducer_get_TopicSet(
134 void * arg,
135 const xsd_QName * qname,
136 void ** property);
137
138 static
139 void
140 globus_l_notification_callback(
141 void * callback_arg,
142 const char * resource_id,
143 globus_notification_producer_topic_info_t
144 topic_info,
145 const wsnt_TopicExpressionType * topic);
146
147 static
148 void
149 globus_l_notification_topic_changed_callback(
150 void * callback_arg);
151
152 static
153 void
154 wsnt_l_property_changed(
155 void * arg,
156 const globus_resource_t resource,
157 globus_bool_t new_property,
158 const xsd_QName * qname,
159 void * value,
160 globus_xsd_type_info_t type_info);
161
162 static
163 int
164 wsnt_NotificationProducer_activate(void);
165
166 static
167 int
168 wsnt_NotificationProducer_deactivate(void);
169
170 static
171 globus_result_t
172 wsnt_l_result_to_fault(
173 globus_l_notification_producer_operation_t operation,
174 globus_result_t result,
175 xsd_any * fault);
176
177 static
178 void
179 globus_l_notification_state_destroy(
180 void * datum);
181
182 /* Local Variables */
183
184 static xsd_QName wsnt_Subscribe_qname =
185 {
186 "http://docs.oasis-open.org/wsn/bw-2/providers",
187 "Subscribe"
188 };
189
190 static xsd_QName wsnt_GetCurrentMessage_qname =
191 {
192 "http://docs.oasis-open.org/wsn/bw-2/providers",
193 "GetCurrentMessage"
194 };
195
196 static
197 globus_operation_provider_descriptor_t
198 wsnt_Subscribe_descriptor =
199 {
200 &wsnt_Subscribe_qname,
201 "Subscribe",
202 wsnt_Subscribe_provider,
203 wsnt_NotificationProducer_init_resource
204 };
205
206 static
207 globus_operation_provider_descriptor_t
208 wsnt_GetCurrentMessage_descriptor =
209 {
210 &wsnt_GetCurrentMessage_qname,
211 "GetCurrentMessage",
212 wsnt_GetCurrentMessage_provider,
213 NULL
214 };
215
216
217 GlobusExtensionDefineModule(globus_wsnt_NotificationProducer_provider) =
218 {
219 "globus_wsnt_NotificationProducer_provider",
220 wsnt_NotificationProducer_activate,
221 wsnt_NotificationProducer_deactivate,
222 NULL,
223 NULL,
224 &local_version
225 };
226
227 /* Implementation */
228
229 static
230 globus_result_t
231 wsnt_NotificationProducer_init_resource(
232 const struct wsa_EndpointReferenceType_s *epr)
233 240 {
234 globus_result_t result;
235 globus_l_notification_state_t * notification_state;
236 globus_resource_t resource;
237 xsd_boolean * fixed_topic_set;
238 240 xsd_anyURI_array * topic_expression_dialects = NULL;
239 xsd_anyURI * dialect;
240 xsd_QName_array * property_names;
241 int i;
242 xsd_any any;
243 wsnt_TopicExpressionType topic_expression;
244
245 240 notification_state = malloc(sizeof(globus_l_notification_state_t));
246 240 if (notification_state == NULL)
247 {
248 0 result = globus_error_put(GLOBUS_ERROR_NO_INFO);
249
250 0 goto out;
251 }
252 240 notification_state->handle = GLOBUS_HANDLE_TABLE_NO_HANDLE;
253 240 result = globus_wsrf_core_get_resource_id_from_epr(
254 epr,
255 &notification_state->resource_id);
256
257 240 if (result != GLOBUS_SUCCESS || notification_state->resource_id == NULL)
258 {
259 0 result = globus_error_put(GLOBUS_ERROR_NO_INFO);
260
261 0 goto free_notification_state_out;
262 }
263
264 240 result = globus_resource_find(
265 notification_state->resource_id,
266 &resource);
267 240 if (result != GLOBUS_SUCCESS)
268 {
269 0 goto free_notification_state_resource_id_out;
270 }
271
272 240 result = globus_resource_set_resource_specific_by_key(
273 resource,
274 "WSNT_RESOURCE",
275 notification_state,
276 globus_l_notification_state_destroy);
277 240 if (result != GLOBUS_SUCCESS)
278 {
279 0 goto finish_out;
280 }
281
282 240 result = globus_notification_producer_create(
283 notification_state->resource_id,
284 globus_l_notification_callback,
285 NULL);
286
287 240 if (result != GLOBUS_SUCCESS)
288 {
289 0 goto finish_out;
290 }
291
292 240 result = globus_resource_create_property_callback(
293 resource,
294 &wsnt_TopicExpression_qname,
295 &wsnt_TopicExpressionType_array_info,
296 wsnt_l_NotificationProducer_get_TopicExpression,
297 wsnt_l_NotificationProducer_set_TopicExpression,
298 notification_state->resource_id);
299
300 240 if (result != GLOBUS_SUCCESS)
301 {
302 0 goto destroy_notification_producer_out;
303 }
304 240 result = globus_resource_create_property_callback(
305 resource,
306 &wstop_TopicSet_qname,
307 &wstop_TopicSetType_info,
308 wsnt_l_NotificationProducer_get_TopicSet,
309 wsnt_l_NotificationProducer_set_TopicSet,
310 notification_state->resource_id);
311 240 if (result != GLOBUS_SUCCESS)
312 {
313 0 goto destroy_topic_property_out;
314 }
315
316 240 result = xsd_boolean_init(&fixed_topic_set);
317 240 if (result != GLOBUS_SUCCESS)
318 {
319 0 goto destroy_topic_set_property_out;
320 }
321 240 *fixed_topic_set = GLOBUS_FALSE;
322
323 240 result = globus_resource_create_property(
324 resource,
325 &wsnt_FixedTopicSet_qname,
326 &xsd_boolean_info,
327 fixed_topic_set);
328
329 240 if (result != GLOBUS_SUCCESS)
330 {
331 0 goto free_fixed_topic_set_out;
332 }
333 240 fixed_topic_set = NULL;
334
335 240 result = xsd_anyURI_array_init(&topic_expression_dialects);
336
337 240 if (result != GLOBUS_SUCCESS)
338 {
339 0 goto destroy_fixed_topic_set_property_out;
340 }
341
342 960 for (i = 0; globus_l_notification_dialects[i] != NULL; i++)
343 {
344 720 dialect = xsd_anyURI_array_push(topic_expression_dialects);
345 720 if (dialect == NULL)
346 {
347 0 goto destroy_topic_expression_dialects_out;
348 }
349
350 720 *dialect = globus_libc_strdup(globus_l_notification_dialects[i]);
351 }
352
353 240 result = globus_resource_create_property(
354 resource,
355 &wsnt_TopicExpressionDialect_qname,
356 &xsd_anyURI_array_info,
357 topic_expression_dialects);
358
359 240 if (result != GLOBUS_SUCCESS)
360 {
361 0 goto destroy_topic_expression_dialects_out;
362 }
363
364 240 result = globus_resource_enumerate_properties(
365 resource,
366 &property_names);
367 240 if (result != GLOBUS_SUCCESS)
368 {
369 0 goto destroy_topic_expression_dialects_property_out;
370 }
371
372 240 result = wsnt_TopicExpressionType_init_contents(
373 &topic_expression);
374
375 240 if (result != GLOBUS_SUCCESS)
376 {
377 0 goto destroy_property_names_out;
378 }
379 240 topic_expression._Dialect = topic_expression_dialects->elements[0];
380 240 topic_expression.any = &any;
381 240 result = xsd_any_init_contents(topic_expression.any);
382 240 if (result != GLOBUS_SUCCESS)
383 {
384 0 goto destroy_property_names_out;
385 }
386 240 topic_expression.any->any_info = &wstop_SimpleTopicExpression_contents_info;
387
388 1622 for (i = 0; i < property_names->length; i++)
389 {
390 1382 topic_expression.any->value = (void *) &property_names->elements[i];
391
392 1382 result = globus_notification_producer_topic_create(
393 notification_state-> resource_id,
394 &topic_expression);
395
396 1382 if (result != GLOBUS_SUCCESS)
397 {
398 0 goto destroy_property_names_out;
399 }
400 }
401
402 240 result = globus_resource_add_property_changed_callback(
403 resource,
404 wsnt_l_property_changed,
405 NULL);
406
407 240 destroy_property_names_out:
408 240 xsd_QName_array_destroy(property_names);
409
410 240 if (result != GLOBUS_SUCCESS)
411 {
412 0 destroy_topic_expression_dialects_property_out:
413 0 globus_resource_destroy_property(
414 resource,
415 &wsnt_TopicExpressionDialect_qname);
416 0 destroy_topic_expression_dialects_out:
417 0 xsd_anyURI_array_destroy(topic_expression_dialects);
418 0 destroy_fixed_topic_set_property_out:
419 0 globus_resource_destroy_property(
420 resource,
421 &wsnt_FixedTopicSet_qname);
422 0 free_fixed_topic_set_out:
423 0 xsd_boolean_destroy(fixed_topic_set);
424 0 destroy_topic_set_property_out:
425 0 globus_resource_destroy_property(
426 resource,
427 &wstop_TopicSet_qname);
428 0 destroy_topic_property_out:
429 0 globus_resource_destroy_property(
430 resource,
431 &wsnt_TopicExpression_qname);
432 0 destroy_notification_producer_out:
433 0 globus_notification_producer_destroy(
434 notification_state->resource_id);
435 }
436
437 240 finish_out:
438 240 globus_resource_finish(resource);
439 240 notification_state = NULL;
440
441 240 if (notification_state)
442 {
443 0 free_notification_state_resource_id_out:
444 0 free(notification_state->resource_id);
445 0 free_notification_state_out:
446 0 free(notification_state);
447 }
448 240 out:
449 240 return result;
450 }
451 /* wsnt_NotificationProducer_init_resource() */
452
453 static
454 globus_result_t
455 wsnt_Subscribe_provider(
456 globus_service_engine_t engine,
457 globus_soap_message_handle_t handle,
458 globus_service_descriptor_t * service,
459 wsnt_SubscribeType * input,
460 wsnt_SubscribeResponseType * output,
461 xsd_any * fault)
462 35 {
463 globus_result_t result;
464 wsa_EndpointReferenceType * epr;
465 char * id;
466
467 35 epr = globus_soap_message_handle_get_attr(
468 handle,
469 WSADDR_EPR_KEY);
470
471 35 if (epr == NULL)
472 {
473 0 result = globus_wsrf_core_create_fault(
474 fault,
475 &wsr_ResourceUnknownFault_qname);
476
477 0 goto out;
478 }
479
480 35 result = service->get_resource_id(&epr->ReferenceParameters->any, &id);
481 35 if (result != GLOBUS_SUCCESS)
482 {
483 0 result = globus_wsrf_core_create_fault(
484 fault,
485 &wsr_ResourceUnknownFault_qname);
486
487 0 goto out;
488 }
489
490 35 result = globus_notification_producer_subscribe(
491 id,
492 engine,
493 input,
494 output);
495
496 35 if (result != GLOBUS_SUCCESS)
497 {
498 6 result = wsnt_l_result_to_fault(
499 WSNT_SUBSCRIBE,
500 result,
501 fault);
502 }
503
504 35 globus_libc_free(id);
505 35 out:
506 35 return result;
507 }
508 /* wsnt_Subscribe_provider() */
509
510 static
511 globus_result_t
512 wsnt_GetCurrentMessage_provider(
513 globus_service_engine_t engine,
514 globus_soap_message_handle_t handle,
515 globus_service_descriptor_t * service,
516 wsnt_GetCurrentMessageType * input,
517 wsnt_GetCurrentMessageResponseType *output,
518 xsd_any * fault)
519 30 {
520 globus_result_t result;
521 wsa_EndpointReferenceType * epr;
522 char * id;
523 xsd_any * any;
524
525 30 epr = globus_soap_message_handle_get_attr(
526 handle,
527 WSADDR_EPR_KEY);
528
529 30 if (epr == NULL)
530 {
531 0 result = globus_wsrf_core_create_fault(
532 fault,
533 &wsr_ResourceUnknownFault_qname);
534
535 0 goto out;
536 }
537
538 30 result = service->get_resource_id(&epr->ReferenceParameters->any, &id);
539 30 if (result != GLOBUS_SUCCESS)
540 {
541 0 result = globus_wsrf_core_create_fault(
542 fault,
543 &wsr_ResourceUnknownFault_qname);
544
545 0 goto out;
546 }
547
548 30 any = xsd_any_array_push(&output->any);
549
550 30 result = globus_notification_producer_get_current_message(
551 id,
552 &input->Topic,
553 any);
554
555 30 if (result != GLOBUS_SUCCESS)
556 {
557 6 result = wsnt_l_result_to_fault(
558 WSNT_GET_CURRENT_MESSAGE,
559 result,
560 fault);
561 }
562 24 else if(any->any_info == NULL)
563 {
564 3 result = globus_wsrf_core_create_fault(
565 fault,
566 &wsnt_NoCurrentMessageOnTopicFault_qname);
567 3 xsd_any_destroy_contents(&output->any.elements[output->any.length-1]);
568 3 output->any.length--;
569 }
570
571 30 globus_libc_free(id);
572 30 out:
573 30 return result;
574 }
575 /* wsnt_GetCurrentMessage_provider() */
576
577 static
578 globus_bool_t
579 wsnt_l_NotificationProducer_set_TopicExpression(
580 void * arg,
581 const xsd_QName * qname,
582 void * property)
583 0 {
584 0 return GLOBUS_FALSE;
585 }
586 /* wsnt_l_NotificationProducer_set_TopicExpression() */
587
588 static
589 void
590 wsnt_l_NotificationProducer_get_TopicExpression(
591 void * arg,
592 const xsd_QName * qname,
593 void ** property)
594 260 {
595 260 wsnt_TopicExpressionType_array * topics = NULL;
596
597 260 globus_assert(xsd_QName_keyeq((xsd_QName *) qname, &wsnt_TopicExpression_qname));
598 260 globus_notification_producer_topic_enumerate(
599 arg,
600 &topics);
601 260 *property = topics;
602 260 }
603 /* wsnt_l_NotificationProducer_get_TopicExpression() */
604
605 static
606 globus_bool_t
607 wsnt_l_NotificationProducer_set_TopicSet(
608 void * arg,
609 const xsd_QName * qname,
610 void * property)
611 0 {
612 0 return GLOBUS_FALSE;
613 }
614 /* wsnt_l_NotificationProducer_set_TopicSet() */
615
616 static
617 void
618 wsnt_l_NotificationProducer_get_TopicSet(
619 void * arg,
620 const xsd_QName * qname,
621 void ** property)
622 7 {
623 7 wstop_TopicSetType * topics = NULL;
624
625 7 globus_assert(xsd_QName_keyeq((xsd_QName *) qname, &wstop_TopicSet_qname));
626 7 globus_notification_producer_get_topic_set(
627 arg,
628 &topics);
629 7 *property = topics;
630 7 }
631 /* wsnt_l_NotificationProducer_get_TopicSet() */
632
633 static
634 void
635 wsnt_l_property_changed(
636 void * arg,
637 const globus_resource_t resource,
638 globus_bool_t new_property,
639 const xsd_QName * qname,
640 void * value,
641 globus_xsd_type_info_t type_info)
642 785 {
643 const char * resource_id;
644 785 globus_result_t result = GLOBUS_SUCCESS;
645 wsnt_TopicExpressionType topic_expression;
646 xsd_any * message;
647 wsrp_ResourcePropertyValueChangeNotificationType *
648 785 value_changed_notification = NULL;
649 xsd_any * new_value;
650
651 785 result = globus_resource_get_id(resource, &resource_id);
652 785 if (result != GLOBUS_SUCCESS)
653 {
654 0 goto out;
655 }
656
657 785 result = wsnt_TopicExpressionType_init_contents(&topic_expression);
658 785 if (result != GLOBUS_SUCCESS)
659 {
660 0 goto out;
661 }
662
663 785 result = xsd_any_init(&topic_expression.any);
664 785 if (result != GLOBUS_SUCCESS)
665 {
666 0 goto out;
667 }
668
669 785 topic_expression.any->any_info = &wstop_SimpleTopicExpression_contents_info;
670 785 topic_expression.any->value = (xsd_QName *) qname;
671 785 topic_expression._Dialect = globus_l_notification_dialects[0];
672
673 785 if (new_property)
674 {
675 405 globus_notification_producer_topic_create(
676 resource_id,
677 &topic_expression);
678 }
679
680 785 if (value != NULL)
681 {
682 397 result = xsd_any_init(&message);
683 397 if (result != GLOBUS_SUCCESS)
684 {
685 0 goto out;
686 }
687 397 result = xsd_QName_copy(
688 &message->element,
689 &wsrp_ResourcePropertyValueChangeNotification_qname);
690 397 message->any_info =
691 &wsrp_ResourcePropertyValueChangeNotificationType_info;
692 397 result = wsrp_ResourcePropertyValueChangeNotificationType_init(
693 &value_changed_notification);
694
695 397 if (result != GLOBUS_SUCCESS)
696 {
697 0 goto destroy_message_out;
698 }
699 397 result = wsrp_NewValuesType_init(&value_changed_notification->NewValues);
700 397 if (result != GLOBUS_SUCCESS)
701 {
702 0 goto destroy_message_out;
703 }
704 397 new_value = xsd_any_array_push(
705 &value_changed_notification->NewValues->any);
706
707 397 new_value->any_info = type_info;
708 397 new_value->value = value;
709 397 new_value->element = (xsd_QName *) qname;
710
711 397 message->value = value_changed_notification;
712
713 397 result = globus_notification_producer_topic_changed(
714 resource_id,
715 &topic_expression,
716 message,
717 NULL,
718 NULL);
719 }
720 else
721 {
722 388 goto free_topic_expression_any;
723 }
724
725 397 destroy_message_out:
726 397 if (value_changed_notification != NULL)
727 {
728 397 value_changed_notification->NewValues->any.elements[0].element = NULL;
729 397 value_changed_notification->NewValues->any.elements[0].value = NULL;
730 }
731 397 xsd_any_destroy(message);
732 785 free_topic_expression_any:
733 785 topic_expression.any->any_info = NULL;
734 785 topic_expression.any->value = NULL;
735 785 xsd_any_destroy(topic_expression.any);
736 785 out:
737 return;
738 }
739 /* wsnt_l_property_changed() */
740
741 static
742 int
743 wsnt_NotificationProducer_activate(void)
744 311 {
745 311 int res = 0;
746 GlobusFuncName(wsnt_NotificationProducer_activate);
747
748 311 res = globus_module_activate(GLOBUS_NOTIFICATION_PRODUCER_MODULE);
749
750 311 if (res != GLOBUS_SUCCESS)
751 {
752 0 goto out;
753 }
754 311 res = globus_extension_registry_add(
755 GLOBUS_OPERATION_PROVIDER_REGISTRY,
756 &wsnt_Subscribe_qname,
757 GlobusExtensionMyModule(globus_wsnt_NotificationProducer_provider),
758 &wsnt_Subscribe_descriptor);
759
760 311 if (res != GLOBUS_SUCCESS)
761 {
762 0 goto deactivate_out;
763 }
764
765 311 res = globus_extension_registry_add(
766 GLOBUS_OPERATION_PROVIDER_REGISTRY,
767 &wsnt_GetCurrentMessage_qname,
768 GlobusExtensionMyModule(globus_wsnt_NotificationProducer_provider),
769 &wsnt_GetCurrentMessage_descriptor);
770
771 311 if (res != GLOBUS_SUCCESS)
772 {
773 0 goto remove_subscribe_out;
774 }
775
776 311 return res;
777
778 0 remove_subscribe_out:
779 0 globus_extension_registry_remove(
780 GLOBUS_OPERATION_PROVIDER_REGISTRY,
781 &wsnt_Subscribe_qname);
782
783 0 deactivate_out:
784 0 globus_module_deactivate(GLOBUS_NOTIFICATION_PRODUCER_MODULE);
785 0 out:
786 0 return res;
787 }
788 /* wsnt_NotificationProducer_activate() */
789
790 static
791 int
792 wsnt_NotificationProducer_deactivate(void)
793 42 {
794 GlobusFuncName(wsnt_NotificationProducer_deactivate);
795
796 42 globus_extension_registry_remove(
797 GLOBUS_OPERATION_PROVIDER_REGISTRY,
798 &wsnt_Subscribe_qname);
799
800 42 globus_extension_registry_remove(
801 GLOBUS_OPERATION_PROVIDER_REGISTRY,
802 &wsnt_GetCurrentMessage_qname);
803
804 42 return 0;
805 }
806 /* wsnt_NotificationProducer_deactivate() */
807
808 static
809 void
810 globus_l_notification_callback(
811 void * callback_arg,
812 const char * resource_id,
813 globus_notification_producer_topic_info_t
814 topic_info,
815 const wsnt_TopicExpressionType * topic)
816 1932 {
817 globus_result_t result;
818 globus_resource_t resource;
819 globus_l_notification_state_t * resource_info;
820
821 1932 result = globus_resource_find(resource_id, &resource);
822
823 1932 if (result != GLOBUS_SUCCESS)
824 {
825 0 goto out;
826 }
827 1932 result = globus_resource_get_resource_specific_by_key(
828 resource,
829 "WSNT_RESOURCE",
830 (void **) &resource_info);
831 1932 if (result != GLOBUS_SUCCESS)
832 {
833 0 goto finish_out;
834 }
835 1932 globus_assert(resource_info != NULL);
836 1932 globus_assert(resource_info->resource_id != NULL);
837
838 1932 if (resource_info->handle == GLOBUS_HANDLE_TABLE_NO_HANDLE &&
839 (topic_info == GLOBUS_NOTIFICATION_PRODUCER_TOPIC_CREATED ||
840 topic_info == GLOBUS_NOTIFICATION_PRODUCER_TOPIC_DESTROYED))
841 {
842 300 globus_callback_register_oneshot(
843 &resource_info->handle,
844 &globus_i_reltime_zero,
845 globus_l_notification_topic_changed_callback,
846 resource_info);
847 }
848 1932 finish_out:
849 1932 globus_resource_finish(resource);
850 1932 out:
851 return;
852 }
853 /* globus_l_notification_callback() */
854
855 static
856 void
857 globus_l_notification_topic_changed_callback(
858 void * callback_arg)
859 226 {
860 226 globus_l_notification_state_t * resource_info = callback_arg;
861 globus_resource_t resource;
862 globus_result_t result;
863
864 226 result = globus_resource_find(resource_info->resource_id, &resource);
865
866 226 if (result != GLOBUS_SUCCESS)
867 {
868 0 goto out;
869 }
870
871 226 globus_callback_unregister(resource_info->handle, NULL, NULL, NULL);
872 226 resource_info->handle = GLOBUS_HANDLE_TABLE_NO_HANDLE;
873
874 226 globus_resource_property_changed(
875 resource,
876 &wsnt_TopicExpression_qname);
877
878 226 globus_resource_finish(resource);
879
880 226 out:
881 return;
882 }
883 /* globus_l_notification_topic_changed_callback() */
884
885 static
886 globus_result_t
887 wsnt_l_result_to_fault(
888 globus_l_notification_producer_operation_t
889 operation,
890 globus_result_t result,
891 xsd_any * fault)
892 12 {
893 globus_object_t * error;
894 globus_module_descriptor_t * descriptor;
895 xsd_any * error_fault;
896 int rc;
897
898 12 error = globus_error_get(result);
899
900 12 if (error == NULL)
901 {
902 0 result = globus_wsrf_core_create_fault(
903 fault,
904 &wsnt_SubscribeCreationFailedFault_qname);
905
906 0 goto out;
907 }
908
909 12 descriptor = globus_error_get_source(error);
910
911 12 if (descriptor != GLOBUS_NOTIFICATION_PRODUCER_MODULE)
912 {
913 0 result = globus_wsrf_core_create_fault(
914 fault,
915 &wsnt_SubscribeCreationFailedFault_qname);
916
917 0 goto destroy_error_out;
918 }
919
920 12 rc = globus_error_get_type(error);
921
922 12 switch (rc)
923 {
924 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_NULL_PARAMETER:
925 0 result = globus_wsrf_core_create_fault(
926 fault,
927 &wsnt_SubscribeCreationFailedFault_qname);
928 0 break;
929 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_OUT_OF_MEMORY:
930 0 result = globus_wsrf_core_create_fault(
931 fault,
932 &wsnt_SubscribeCreationFailedFault_qname);
933 0 break;
934 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_UNKNOWN_RESOURCE:
935 0 result = globus_wsrf_core_create_fault(
936 fault,
937 &wsr_ResourceUnknownFault_qname);
938 0 break;
939 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_ALREADY_EXISTS:
940 0 result = globus_wsrf_core_create_fault(
941 fault,
942 &wsr_ResourceUnknownFault_qname);
943 0 break;
944 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_INVALID_FILTER:
945 0 error_fault = globus_wsrf_core_tools_get_fault(error);
946
947 0 result = xsd_any_copy_contents(fault, error_fault);
948
949 0 xsd_any_destroy(error_fault);
950 0 break;
951 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_DIALECT_UNKNOWN:
952 6 result = globus_wsrf_core_create_fault(
953 fault,
954 &wsnt_TopicExpressionDialectUnknownFault_qname);
955 6 break;
956 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_INVALID_TOPIC_EXPRESSION:
957 0 result = globus_wsrf_core_create_fault(
958 fault,
959 &wsnt_InvalidTopicExpressionFault_qname);
960 0 break;
961 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_TOPIC_NOT_SUPPORTED:
962 6 result = globus_wsrf_core_create_fault(
963 fault,
964 &wsnt_TopicNotSupportedFault_qname);
965 6 break;
966 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_PROPERTIES_EXPRESSION:
967 0 result = globus_wsrf_core_create_fault(
968 fault,
969 &wsnt_InvalidProducerPropertiesExpressionFault_qname);
970 0 break;
971 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_INVALID_MESSAGE_CONTENT:
972 0 result = globus_wsrf_core_create_fault(
973 fault,
974 &wsnt_InvalidMessageContentExpressionFault_qname);
975 0 break;
976 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_UNRECOGNIZED_POLICY_REQUEST:
977 0 result = globus_wsrf_core_create_fault(
978 fault,
979 &wsnt_UnrecognizedPolicyRequestFault_qname);
980 0 break;
981 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_UNSUPPORED_POLICY_REQUEST:
982 0 result = globus_wsrf_core_create_fault(
983 fault,
984 &wsnt_UnsupportedPolicyRequestFault_qname);
985 0 break;
986 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_NOTIFY_MESSAGE_NOT_SUPPORTED:
987 0 result = globus_wsrf_core_create_fault(
988 fault,
989 &wsnt_NotifyMessageNotSupportedFault_qname);
990 0 break;
991 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_UNACCEPTABLE_TERMINATION_TIME:
992 0 result = globus_wsrf_core_create_fault(
993 fault,
994 &wsnt_UnacceptableTerminationTimeFault_qname);
995 0 break;
996 case GLOBUS_NOTIFICATION_PRODUCER_ERROR_TYPE_SUBSCRIPTION_CREATION_FAILED:
997 0 result = globus_wsrf_core_create_fault(
998 fault,
999 &wsnt_SubscribeCreationFailedFault_qname);
1000 0 break;
1001 default:
1002 0 result = globus_wsrf_core_create_fault(
1003 fault,
1004 &wsnt_SubscribeCreationFailedFault_qname);
1005 break;
1006 }
1007
1008 12 destroy_error_out:
1009 12 globus_object_free(error);
1010 12 out:
1011 12 return result;
1012 }
1013 /* wsnt_l_result_to_fault() */
1014
1015 static
1016 void
1017 globus_l_notification_state_destroy(
1018 void * datum)
1019 150 {
1020 150 globus_l_notification_state_t * resource_info = datum;
1021
1022 150 if (resource_info->handle != GLOBUS_HANDLE_TABLE_NO_HANDLE)
1023 {
1024 74 globus_callback_unregister(
1025 resource_info->handle,
1026 NULL,
1027 NULL,
1028 NULL);
1029 74 resource_info->handle = GLOBUS_HANDLE_TABLE_NO_HANDLE;
1030 }
1031 150 free(resource_info->resource_id);
1032 150 free(resource_info);
1033 150 }