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