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_soap_message.h"
18 #include "globus_wsrf_resource.h"
19 #include "globus_service_engine.h"
20 #include "globus_operation_provider.h"
21 #include "globus_service_registry.h"
22 #include "globus_wsrf_core_tools.h"
23 #include "version.h"
24
25 #include "wsrl_DestroyType.h"
26 #include "wsrl_DestroyResponseType.h"
27
28 #include "wsr_ResourceUnknownFault.h"
29 #include "wsrl_ResourceNotDestroyedFault.h"
30
31 /**
32 * @page wsrl_ImmediateResourceTermination_provider ImmediateResourceTermination Provider
33 *
34 * <h2>Provider Usage Overview</h2>
35 * This operation provider implements the ImmediateResourceTermination portType
36 * defined in
37 * http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl .
38 * This portType consists of the @a Destroy operation and
39 * related faults.
40 *
41 * The WSRF service engine will automatically register this provider to handle
42 * the Destroy operation for services which use the port type.
43 */
44
45 /* Prototypes */
46 static
47 globus_result_t
48 wsrl_Destroy_provider(
49 globus_service_engine_t engine,
50 globus_soap_message_handle_t handle,
51 globus_service_descriptor_t * service,
52 wsrl_DestroyType * input,
53 wsrl_DestroyResponseType * output,
54 xsd_any * fault);
55
56 static
57 int
58 wsrl_ImmediateResourceTermination_activate(void);
59
60 static
61 int
62 wsrl_ImmediateResourceTermination_deactivate(void);
63
64 /* Local Variables */
65 static xsd_QName wsrl_Destroy_qname =
66 {
67 "http://docs.oasis-open.org/wsrf/rlw-2/providers",
68 "Destroy"
69 };
70
71 static
72 globus_operation_provider_descriptor_t
73 wsrl_Destroy_descriptor =
74 {
75 &wsrl_Destroy_qname,
76 "Destroy",
77 (void *)wsrl_Destroy_provider,
78 };
79
80 GlobusExtensionDefineModule(globus_wsrl_ImmediateResourceTermination_provider) =
81 {
82 "globus_wsrl_ImmediateResourceTermination_provider",
83 wsrl_ImmediateResourceTermination_activate,
84 wsrl_ImmediateResourceTermination_deactivate,
85 NULL,
86 NULL,
87 &local_version
88 };
89
90 /* Implementation */
91
92 static
93 globus_result_t
94 wsrl_Destroy_provider(
95 globus_service_engine_t engine,
96 globus_soap_message_handle_t handle,
97 globus_service_descriptor_t * service,
98 wsrl_DestroyType * input,
99 wsrl_DestroyResponseType * output,
100 xsd_any * fault)
101 253 {
102 globus_result_t result;
103 globus_result_t save_result;
104 globus_resource_t resource;
105 globus_object_t * error;
106
107 253 result = globus_wsrf_core_get_resource(handle, service, &resource);
108
109 253 if (result != GLOBUS_SUCCESS || resource == NULL)
110 {
111 0 save_result = result;
112 0 result = globus_wsrf_core_create_fault(
113 fault,
114 &wsr_ResourceUnknownFault_qname);
115 0 if (result != GLOBUS_SUCCESS)
116 {
117 0 result = save_result;
118 }
119 0 goto out;
120 }
121
122 253 result = globus_resource_destroy(resource);
123
124 253 if (result != GLOBUS_SUCCESS)
125 {
126 0 error = globus_error_get(result);
127
128 0 if (globus_error_match(error,
129 GLOBUS_WSRF_RESOURCE_MODULE,
130 GLOBUS_WSRF_RESOURCE_ERROR_TYPE_ALREADY_DESTROYED))
131 {
132 0 result = globus_wsrf_core_create_fault(
133 fault,
134 &wsrl_ResourceNotDestroyedFault_qname);
135 }
136 else
137 {
138 0 result = globus_wsrf_core_create_fault(
139 fault,
140 &wsr_ResourceUnknownFault_qname);
141 }
142 0 globus_object_free(error);
143
144 0 goto out;
145 }
146
147 253 return GLOBUS_SUCCESS;
148
149 0 out:
150 0 return result;
151 }
152 /* wsrl_Destroy_provider() */
153
154
155 static
156 int
157 wsrl_ImmediateResourceTermination_activate(void)
158 334 {
159 334 int res = 0;
160 GlobusFuncName(wsrl_ImmediateResourceTermination_activate);
161
162 334 res = globus_extension_registry_add(
163 GLOBUS_OPERATION_PROVIDER_REGISTRY,
164 &wsrl_Destroy_qname,
165 GlobusExtensionMyModule(globus_wsrl_ImmediateResourceTermination_provider),
166 &wsrl_Destroy_descriptor);
167
168 334 return res;
169 }
170 /* wsrl_ImmediateResourceTermination_activate() */
171
172 static
173 int
174 wsrl_ImmediateResourceTermination_deactivate(void)
175 63 {
176 GlobusFuncName(wsrl_ImmediateResourceTermination_deactivate);
177
178 63 globus_extension_registry_remove(
179 GLOBUS_OPERATION_PROVIDER_REGISTRY,
180 &wsrl_Destroy_qname);
181
182 63 return 0;
183 }