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 "wsrp_GetMultipleResourcePropertiesType.h"
26 #include "wsrp_GetMultipleResourcePropertiesResponseType.h"
27
28 #define WSRP_GET_MULTIPLE_RESOURCE_PROPERTIES 1
29 #include "wsrp_i_faults.h"
30
31 /**
32  * @page wsrp_GetMultipleResourceProperties_provider GetMultipleResourceProperties Provider
33  *
34  * <h2>Provider Usage Overview</h2>
35  * This operation provider implements the GetMultipleResourceProperties
36 portType defined in
37  * http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl .
38  * This portType consists of the @a GetMultipleResourceProperties operation and
39  * related faults.
40  *
41  * The WSRF service engine will automatically register this provider to handle
42  * the GetMultipleResourceProperties operation for services which use the port
43  * type.
44  */
45
46 /* Prototypes */
47 static
48 globus_result_t
49 wsrp_GetMultipleResourceProperties_provider(
50     globus_service_engine_t             engine,
51     globus_soap_message_handle_t        handle,
52     globus_service_descriptor_t *       service,
53     wsrp_GetMultipleResourcePropertiesType *
54                                         input,
55     wsrp_GetMultipleResourcePropertiesResponseType * 
56                                         output,
57     char **                             fault_name,
58     void **                             fault);
59
60 static
61 int
62 wsrp_GetMultipleResourceProperties_activate(void);
63
64 static
65 int
66 wsrp_GetMultipleResourceProperties_deactivate(void);
67
68 /* Local Variables */
69 static xsd_QName wsrp_GetMultipleResourceProperties_qname =
70 {
71     "http://www.globus.org/docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl",
72     "GetMultipleResourceProperties"
73 };
74
75 static
76 globus_operation_provider_descriptor_t
77 wsrp_GetMultipleResourceProperties_descriptor =
78 {
79     &wsrp_GetMultipleResourceProperties_qname,
80     "GetMultipleResourceProperties",
81     (void *)wsrp_GetMultipleResourceProperties_provider
82 };
83
84 GlobusExtensionDefineModule(globus_wsrp_GetMultipleResourceProperties_provider) =
85 {
86     "globus_wsrp_GetMultipleResourceProperties_provider",
87     wsrp_GetMultipleResourceProperties_activate,
88     wsrp_GetMultipleResourceProperties_deactivate,
89     NULL,
90     NULL,
91     &local_version
92 };
93
94 /* Implementation */
95
96 static
97 globus_result_t
98 wsrp_GetMultipleResourceProperties_provider(
99     globus_service_engine_t             engine,
100     globus_soap_message_handle_t        handle,
101     globus_service_descriptor_t *       service,
102     wsrp_GetMultipleResourcePropertiesType *
103                                         input,
104     wsrp_GetMultipleResourcePropertiesResponseType * 
105                                         output,
106     char **                             fault_name,
107     void **                             fault)
108 2229 {
109 2229     globus_resource_t                   resource;
110 2229     void *                              property;
111 2229     xsd_any *                           value;
112 2229     globus_xsd_type_info_t              info;
113 2229     globus_result_t                     result;
114 2229     int                                 i, j;
115 2229     xsd_any *                           prop_any = NULL;
116
117 2229     result = globus_wsrf_core_get_resource(
118         handle,
119         service,
120         &resource);
121
122 2229     if (result != GLOBUS_SUCCESS || resource == NULL)
123     {
124 0         result = wsrp_l_ResourceUnknownFaultType_create(
125                 fault_name,
126                 (wsrp_ResourceUnknownFaultType **) fault);
127
128 0         goto out;
129     }
130
131 618854     for (i = 0; i < input->ResourceProperty.length; i++)
132     {
133 616625         globus_object_t *               error;
134
135 616625         result = globus_resource_get_property(
136                 resource,
137                 &input->ResourceProperty.elements[i],
138                 &property,
139                 &info);
140
141 616625         if (result != GLOBUS_SUCCESS)
142         {
143 0             error = globus_error_get(result);
144
145 0             if (globus_error_match(error,
146                         GLOBUS_WSRF_RESOURCE_MODULE,
147                         GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY))
148             {
149 0                 result = wsrp_l_InvalidResourcePropertyQNameFaultType_create(
150                         fault_name,
151                         (wsrp_InvalidResourcePropertyQNameFaultType **) fault);
152             }
153             else
154             {
155 0                 result = wsrp_l_ResourceUnknownFaultType_create(
156                         fault_name,
157                         (wsrp_ResourceUnknownFaultType **) fault);
158
159             }
160 0             globus_object_free(error);
161
162 0             goto free_array_out;
163         }
164
165 616625         if (info == &xsd_any_info)
166         {
167 10             prop_any = property;
168         }
169         
170 616625         if ((prop_any != NULL &&
171              prop_any->any_info != NULL &&
172              prop_any->value != NULL) || 
173             (prop_any == NULL && property != NULL))
174         {
175 616617             value = xsd_any_array_push(&output->any);
176 616617             if (value == NULL)
177             {
178 0                 result = globus_error_put(GLOBUS_ERROR_NO_INFO);
179
180 0                 goto free_array_out;
181             }
182 616617             value->any_info = info;
183 616617             result = xsd_QName_copy(&value->element,
184                     &input->ResourceProperty.elements[i]);
185 616617             if (result != GLOBUS_SUCCESS)
186             {
187 0                 goto free_array_out;
188             }
189
190 616617             result = info->copy(&value->value, property);
191 616617             if (result != GLOBUS_SUCCESS)
192             {
193 0                 goto free_array_out;
194             }
195         }
196     }
197 2229     globus_resource_finish(resource);
198
199 2229     return GLOBUS_SUCCESS;
200
201 free_array_out:
202 0     if (output->any.length > 0)
203     {
204 0         for (j = i-1; j >=0; j--)
205         {
206 0             info = output->any.elements[j].any_info;
207 0             info->destroy(output->any.elements[j].value);
208         }
209 0         free(output->any.elements);
210     }
211 0     output->any.length = 0;
212 0     output->any.elements = NULL;
213
214 0     globus_resource_finish(resource);
215 out:
216 0     return result;
217 }
218 /* wsrp_GetMultipleResourceProperties_provider() */
219
220 static
221 int
222 wsrp_GetMultipleResourceProperties_activate(void)
223 93 {
224 93     int                                 res = 0;
225 93     GlobusFuncName(wsrp_GetMultipleResourceProperties_activate);
226     
227 93     res = globus_extension_registry_add(
228         GLOBUS_OPERATION_PROVIDER_REGISTRY,
229         &wsrp_GetMultipleResourceProperties_qname,
230         GlobusExtensionMyModule(globus_wsrp_GetMultipleResourceProperties_provider),
231         &wsrp_GetMultipleResourceProperties_descriptor);
232
233
234 93     return res;
235 }
236 /* wsrp_GetMultipleResourceProperties_activate() */
237
238 static
239 int
240 wsrp_GetMultipleResourceProperties_deactivate(void)
241 21 {
242 21     GlobusFuncName(wsrp_GetMultipleResourceProperties_deactivate);
243
244 21     globus_extension_registry_remove(
245         GLOBUS_OPERATION_PROVIDER_REGISTRY,
246         &wsrp_GetMultipleResourceProperties_qname);
247
248 21     return 0;
249 }