1 /*
2  * Portions of this file Copyright 1999-2005 University of Chicago
3  * Portions of this file Copyright 1999-2005 The University of Southern California.
4  *
5  * This file or a portion of this file is licensed under the
6  * terms of the Globus Toolkit Public License, found at
7  * http://www.globus.org/toolkit/download/license.html.
8  * If you redistribute this file, with or without
9  * modifications, you must include this notice in the file.
10  */
11
12 #include "globus_soap_message.h"
13 #include "globus_wsrf_resource.h"
14 #include "globus_service_engine.h"
15 #include "globus_operation_provider.h"
16 #include "globus_service_registry.h"
17 #include "globus_wsrf_core_tools.h"
18 #include "version.h"
19
20 #include "wsrl_DestroyType.h"
21 #include "wsrl_DestroyResponseType.h"
22
23 #define WSRL_IMMEDIATE_RESOURCE_TERMINATION 1
24
25 #include "wsrl_i_faults.h"
26
27 /**
28  * @page wsrl_ImmediateResourceTermination_provider ImmediateResourceTermination Provider
29  *
30  * <h2>Provider Usage Overview</h2>
31  * This operation provider implements the ImmediateResourceTermination portType
32  * defined in
33  * http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl .
34  * This portType consists of the @a Destroy operation and
35  * related faults.
36  *
37  * The WSRF service engine will automatically register this provider to handle
38  * the Destroy operation for services which use the port type.
39  */
40
41 GlobusExtensionDeclareModule(wsrl_ImmediateResourceTermination);
42
43 /* Prototypes */
44 static
45 globus_result_t
46 wsrl_Destroy_init_provider(
47     globus_service_engine_t             engine,
48     globus_soap_message_handle_t        handle,
49     wsrl_DestroyType *                  input);
50
51 static
52 globus_result_t
53 wsrl_Destroy_provider(
54     globus_service_engine_t             engine,
55     globus_soap_message_handle_t        handle,
56     globus_service_descriptor_t *       service,
57     wsrl_DestroyType *                  input,
58     wsrl_DestroyResponseType *          output,
59     char **                             fault_name,
60     void **                             fault);
61
62 static
63 int
64 wsrl_ImmediateResourceTermination_activate(void);
65
66 static
67 int
68 wsrl_ImmediateResourceTermination_deactivate(void);
69
70 /* Local Variables */
71 static xsd_QName wsrl_Destroy_qname =
72 {
73     "http://www.globus.org/docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl",
74     "Destroy"
75 };
76
77 static
78 globus_operation_provider_descriptor_t
79 wsrl_Destroy_descriptor =
80 {
81     &wsrl_Destroy_qname,
82     "Destroy",
83     (void *)wsrl_Destroy_init_provider,
84     (void *)wsrl_Destroy_provider,
85 };
86
87 GlobusExtensionDefineModule(wsrl_ImmediateResourceTermination) =
88 {
89     "wsrl_ImmediateResourceTermination",
90     wsrl_ImmediateResourceTermination_activate,
91     wsrl_ImmediateResourceTermination_deactivate,
92     NULL,
93     NULL,
94     &local_version
95 };
96
97 /* Implementation */
98
99 static
100 globus_result_t
101 wsrl_Destroy_init_provider(
102     globus_service_engine_t             engine,
103     globus_soap_message_handle_t        handle,
104     wsrl_DestroyType *                  input)
105 38 {
106 38     return GLOBUS_SUCCESS;
107 }
108 /* wsrp_GetResourceProperty_init_provider() */
109
110 static
111 globus_result_t
112 wsrl_Destroy_provider(
113     globus_service_engine_t             engine,
114     globus_soap_message_handle_t        handle,
115     globus_service_descriptor_t *       service,
116     wsrl_DestroyType *                  input,
117     wsrl_DestroyResponseType *          output,
118     char **                             fault_name,
119     void **                             fault)
120 38 {
121 38     globus_result_t                     result;
122 38     globus_resource_t                   resource;
123 38     globus_object_t *                   error;
124
125 38     result = globus_wsrf_core_get_resource(handle, service, &resource);
126
127 38     if (result != GLOBUS_SUCCESS || resource == NULL)
128     {
129 0         result = wsrl_l_ResourceUnknownFaultType_create(
130                 fault_name,
131                 (wsrl_ResourceUnknownFaultType **) fault);
132
133 0         goto out;
134     }
135
136 38     result = globus_resource_finish_and_destroy(resource);
137
138 38     if (result != GLOBUS_SUCCESS)
139     {
140 0         error = globus_error_get(result);
141
142 0         if (globus_error_match(error,
143                     GLOBUS_WSRF_RESOURCE_MODULE,
144                     GLOBUS_WSRF_RESOURCE_ERROR_TYPE_ALREADY_DESTROYED))
145         {
146 0             result = wsrl_l_ResourceNotDestroyedFaultType_create(
147                     fault_name,
148                     (wsrl_ResourceNotDestroyedFaultType **) fault);
149         }
150         else
151         {
152 0             result = wsrl_l_ResourceUnknownFaultType_create(
153                     fault_name,
154                     (wsrl_ResourceUnknownFaultType **) fault);
155         }
156 0         globus_object_free(error);
157
158 0         goto out;
159     }
160
161 38     return GLOBUS_SUCCESS;
162
163 out:
164 0     return result;
165 }
166 /* wsrp_GetResourceProperty_provider() */
167
168
169 static
170 int
171 wsrl_ImmediateResourceTermination_activate(void)
172 28 {
173 28     int                                 res = 0;
174 28     GlobusFuncName(wsrl_ImmediateResourceTermination_activate);
175     
176 28     res = globus_extension_registry_add(
177         GLOBUS_OPERATION_PROVIDER_REGISTRY,
178         &wsrl_Destroy_qname,
179         GlobusExtensionMyModule(wsrl_ImmediateResourceTermination),
180         &wsrl_Destroy_descriptor);
181
182 28     return res;
183 }
184 /* wsrl_ImmediateResourceTermination_activate() */
185
186 static
187 int
188 wsrl_ImmediateResourceTermination_deactivate(void)
189 0 {
190 0     GlobusFuncName(wsrl_ImmediateResourceTermination_deactivate);
191
192 0     globus_extension_registry_remove(
193         GLOBUS_OPERATION_PROVIDER_REGISTRY,
194         &wsrl_Destroy_qname);
195
196 0     return 0;
197 }