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