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