| 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_wsrf_core_tools.h" | |
| 22 | #include "globus_wsrf_service_group.h" | |
| 23 | #include "globus_ws_addressing.h" | |
| 24 | ||
| 25 | #include "wssg_AddType.h" | |
| 26 | #include "wssg_AddResponseType.h" | |
| 27 | #include "wsa_EndpointReferenceType.h" | |
| 28 | #include "wsrl_TerminationTime.h" | |
| 29 | #include "wsrl_CurrentTime.h" | |
| 30 | #include "wssg_AddRefusedFaultType.h" | |
| 31 | #include "wssg_AddRefusedFault.h" | |
| 32 | #include "wsbf_DescriptionType.h" | |
| 33 | #include "wsbf_BaseFault.h" | |
| 34 | ||
| 35 | #include "version.h" | |
| 36 | ||
| 37 | /** | |
| 38 | * @defgroup wssg_ServiceGroupRegistration_provider ServiceGroupRegistration Provider | |
| 39 | * | |
| 40 | * <h2>Provider Usage Overview</h2> | |
| 41 | * This operation provider implements the ServiceGroupRegistry portType | |
| 42 | * defined in | |
| 43 | * http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-02.pdf | |
| 44 | * This portType consists of the wssg:Add operation and related faults. | |
| 45 | * | |
| 46 | * This provider is located in the | |
| 47 | * @b globus_wssg_ServiceGroupRegistration_provider extension. After this | |
| 48 | * extension is activated, the provider may be associated with a service by | |
| 49 | * adding the provider for {http://docs.oasis-open.org/wsrf/sgw-2/providers}Add | |
| 50 | * to the service. | |
| 51 | */ | |
| 52 | ||
| 53 | static | |
| 54 | globus_result_t | |
| 55 | wssg_Add_provider( | |
| 56 | globus_service_engine_t engine, | |
| 57 | globus_soap_message_handle_t message, | |
| 58 | globus_service_descriptor_t * descriptor, | |
| 59 | wssg_AddType * add, | |
| 60 | wssg_AddResponseType * add_response, | |
| 61 | xsd_any * fault); | |
| 62 | ||
| 63 | static | |
| 64 | int | |
| 65 | wssg_l_ServiceGroupRegistration_activate(void); | |
| 66 | ||
| 67 | static | |
| 68 | int | |
| 69 | wssg_l_ServiceGroupRegistration_deactivate(void); | |
| 70 | ||
| 71 | /* Local Variables */ | |
| 72 | static xsd_QName wssg_Add_provider_qname = | |
| 73 | { | |
| 74 | "http://docs.oasis-open.org/wsrf/sgw-2/providers", | |
| 75 | "Add" | |
| 76 | }; | |
| 77 | ||
| 78 | static | |
| 79 | globus_operation_provider_descriptor_t | |
| 80 | wssg_ServiceGroup_descriptor = | |
| 81 | { | |
| 82 | &wssg_Add_provider_qname, | |
| 83 | "Add", | |
| 84 | wssg_Add_provider, | |
| 85 | NULL | |
| 86 | }; | |
| 87 | ||
| 88 | GlobusExtensionDefineModule(globus_wssg_ServiceGroupRegistration_provider) = | |
| 89 | { | |
| 90 | "globus_wssg_ServiceGroupRegistration_provider", | |
| 91 | wssg_l_ServiceGroupRegistration_activate, | |
| 92 | wssg_l_ServiceGroupRegistration_deactivate, | |
| 93 | NULL, | |
| 94 | NULL, | |
| 95 | &local_version | |
| 96 | }; | |
| 97 | ||
| 98 | ||
| 99 | static | |
| 100 | globus_result_t | |
| 101 | wssg_Add_provider( | |
| 102 | globus_service_engine_t engine, | |
| 103 | globus_soap_message_handle_t message, | |
| 104 | globus_service_descriptor_t * descriptor, | |
| 105 | wssg_AddType * add, | |
| 106 | wssg_AddResponseType * add_response, | |
| 107 | xsd_any * fault) | |
| 108 | 6 | { |
| 109 | globus_result_t result; | |
| 110 | globus_resource_t resource; | |
| 111 | xsd_dateTime tm; | |
| 112 | xsd_dateTime * termination_time; | |
| 113 | xsd_dateTime * current_time; | |
| 114 | 6 | wsa_EndpointReferenceType * entry_epr = NULL; |
| 115 | wsa_EndpointReferenceType * service_group_epr; | |
| 116 | wssg_AddRefusedFaultType * add_refused; | |
| 117 | xsd_any * causal_fault; | |
| 118 | wsbf_BaseFaultType * base_fault; | |
| 119 | wsbf_DescriptionType * description; | |
| 120 | time_t now; | |
| 121 | ||
| 122 | ||
| 123 | 6 | service_group_epr = globus_soap_message_handle_get_attr( |
| 124 | message, | |
| 125 | WSADDR_EPR_KEY); | |
| 126 | ||
| 127 | 6 | if (service_group_epr == NULL) |
| 128 | { | |
| 129 | 0 | result = globus_error_put(GLOBUS_ERROR_NO_INFO); |
| 130 | ||
| 131 | 0 | goto out; |
| 132 | } | |
| 133 | ||
| 134 | 6 | result = wssg_AddResponseType_init_contents(add_response); |
| 135 | ||
| 136 | 6 | if (result != GLOBUS_SUCCESS) |
| 137 | { | |
| 138 | ||
| 139 | 0 | goto out; |
| 140 | } | |
| 141 | ||
| 142 | 6 | if (add->InitialTerminationTime) |
| 143 | { | |
| 144 | 0 | switch (add->InitialTerminationTime->type) |
| 145 | { | |
| 146 | case wssg_AbsoluteOrRelativeTimeType_duration: | |
| 147 | 0 | now = time(NULL); |
| 148 | ||
| 149 | 0 | termination_time = gmtime_r(&now, &tm); |
| 150 | ||
| 151 | 0 | if (termination_time == NULL) |
| 152 | { | |
| 153 | 0 | result = GlobusSoapMessageErrorParserFailed( |
| 154 | "InitialTerminationTime", NULL, NULL); | |
| 155 | ||
| 156 | 0 | goto out; |
| 157 | } | |
| 158 | ||
| 159 | 0 | result = globus_wsrf_core_add_duration( |
| 160 | termination_time, | |
| 161 | &add->InitialTerminationTime->value.duration); | |
| 162 | ||
| 163 | 0 | if (result != GLOBUS_SUCCESS) |
| 164 | { | |
| 165 | 0 | goto out; |
| 166 | } | |
| 167 | 0 | break; |
| 168 | ||
| 169 | case wssg_AbsoluteOrRelativeTimeType_dateTime: | |
| 170 | 0 | termination_time = &add->InitialTerminationTime->value.dateTime; |
| 171 | 0 | break; |
| 172 | ||
| 173 | default: | |
| 174 | 0 | result = GlobusSoapMessageErrorParserFailed( |
| 175 | "InitialTerminationTime", NULL, NULL); | |
| 176 | 0 | goto out; |
| 177 | } | |
| 178 | } | |
| 179 | else | |
| 180 | { | |
| 181 | 6 | termination_time = NULL; |
| 182 | } | |
| 183 | ||
| 184 | 6 | result = globus_service_group_add( |
| 185 | service_group_epr, | |
| 186 | &add->MemberEPR, | |
| 187 | &add->Content, | |
| 188 | termination_time, | |
| 189 | &entry_epr); | |
| 190 | ||
| 191 | 6 | if (result != GLOBUS_SUCCESS) |
| 192 | { | |
| 193 | 0 | result = globus_wsrf_core_create_fault(fault, |
| 194 | &wssg_AddRefusedFault_qname); | |
| 195 | ||
| 196 | 0 | if (result != GLOBUS_SUCCESS) |
| 197 | { | |
| 198 | 0 | goto out; |
| 199 | } | |
| 200 | ||
| 201 | 0 | add_refused = (wssg_AddRefusedFaultType *) fault->value; |
| 202 | ||
| 203 | 0 | result = xsd_anyType_init(&add_refused->FaultCause); |
| 204 | 0 | if (result != GLOBUS_SUCCESS) |
| 205 | { | |
| 206 | 0 | goto out; |
| 207 | } | |
| 208 | ||
| 209 | 0 | result = xsd_any_init(&causal_fault); |
| 210 | 0 | if (result != GLOBUS_SUCCESS) |
| 211 | { | |
| 212 | 0 | goto out; |
| 213 | } | |
| 214 | ||
| 215 | 0 | result = globus_wsrf_core_create_fault( |
| 216 | causal_fault, | |
| 217 | &wsbf_BaseFault_qname); | |
| 218 | ||
| 219 | 0 | if (result != GLOBUS_SUCCESS) |
| 220 | { | |
| 221 | 0 | xsd_any_destroy(causal_fault); |
| 222 | ||
| 223 | 0 | goto out; |
| 224 | } | |
| 225 | ||
| 226 | 0 | base_fault = (wsbf_BaseFaultType *) causal_fault->value; |
| 227 | 0 | description = wsbf_DescriptionType_array_push(&base_fault->Description); |
| 228 | ||
| 229 | 0 | if (description == NULL) |
| 230 | { | |
| 231 | 0 | goto out; |
| 232 | } | |
| 233 | ||
| 234 | 0 | result = xsd_string_init_contents_cstr( |
| 235 | &description->base_value, | |
| 236 | globus_error_print_friendly(globus_error_peek(result))); | |
| 237 | ||
| 238 | 0 | goto out; |
| 239 | } | |
| 240 | 6 | result = wsa_EndpointReferenceType_copy_contents( |
| 241 | &add_response->ServiceGroupEntryReference, entry_epr); | |
| 242 | ||
| 243 | 6 | if (result != GLOBUS_SUCCESS) |
| 244 | { | |
| 245 | 0 | wsa_EndpointReferenceType_destroy(entry_epr); |
| 246 | } | |
| 247 | 6 | result = globus_wsrf_core_get_resource_from_epr( |
| 248 | &add_response->ServiceGroupEntryReference, | |
| 249 | &resource); | |
| 250 | ||
| 251 | 6 | if (result != GLOBUS_SUCCESS) |
| 252 | { | |
| 253 | 0 | goto destroy_response_out; |
| 254 | } | |
| 255 | 6 | result = globus_resource_get_property( |
| 256 | resource, | |
| 257 | &wsrl_TerminationTime_qname, | |
| 258 | (void **) &termination_time, | |
| 259 | NULL); | |
| 260 | 6 | if (result != GLOBUS_SUCCESS) |
| 261 | { | |
| 262 | 0 | goto finish_resource_out; |
| 263 | } | |
| 264 | ||
| 265 | 6 | if (termination_time != NULL) |
| 266 | { | |
| 267 | 0 | result = xsd_dateTime_copy( |
| 268 | &add_response->TerminationTime, | |
| 269 | termination_time); | |
| 270 | 0 | if (result != GLOBUS_SUCCESS) |
| 271 | { | |
| 272 | 0 | goto finish_resource_out; |
| 273 | } | |
| 274 | } | |
| 275 | 6 | result = globus_resource_get_property( |
| 276 | resource, | |
| 277 | &wsrl_CurrentTime_qname, | |
| 278 | (void **) ¤t_time, | |
| 279 | NULL); | |
| 280 | 6 | if (current_time == NULL) |
| 281 | { | |
| 282 | 0 | now = time(NULL); |
| 283 | ||
| 284 | 0 | if (NULL == gmtime_r(&now, &tm)) |
| 285 | { | |
| 286 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 287 | ||
| 288 | 0 | goto finish_resource_out; |
| 289 | } | |
| 290 | 0 | current_time = &tm; |
| 291 | } | |
| 292 | 6 | if (result != GLOBUS_SUCCESS) |
| 293 | { | |
| 294 | 0 | goto finish_resource_out; |
| 295 | } | |
| 296 | 6 | result = xsd_dateTime_copy_contents( |
| 297 | &add_response->CurrentTime, | |
| 298 | current_time); | |
| 299 | ||
| 300 | 6 | finish_resource_out: |
| 301 | 6 | globus_resource_finish(resource); |
| 302 | ||
| 303 | 6 | destroy_response_out: |
| 304 | 6 | if (result != GLOBUS_SUCCESS) |
| 305 | { | |
| 306 | 0 | wssg_AddResponseType_destroy_contents(add_response); |
| 307 | } | |
| 308 | ||
| 309 | 6 | out: |
| 310 | 6 | return result; |
| 311 | } | |
| 312 | /* wssg_Add_provider() */ | |
| 313 | ||
| 314 | static | |
| 315 | int | |
| 316 | wssg_l_ServiceGroupRegistration_activate(void) | |
| 317 | 50 | { |
| 318 | 50 | int res = 0; |
| 319 | GlobusFuncName(wssg_l_ServiceGroup_activate); | |
| 320 | ||
| 321 | 50 | res = globus_module_activate(GLOBUS_WSRF_SERVICE_GROUP_MODULE); |
| 322 | 50 | if (res != GLOBUS_SUCCESS) |
| 323 | { | |
| 324 | 0 | goto out; |
| 325 | } | |
| 326 | ||
| 327 | 50 | res = globus_extension_registry_add( |
| 328 | GLOBUS_OPERATION_PROVIDER_REGISTRY, | |
| 329 | &wssg_Add_provider_qname, | |
| 330 | GlobusExtensionMyModule(globus_wssg_ServiceGroupRegistration_provider), | |
| 331 | &wssg_ServiceGroup_descriptor); | |
| 332 | ||
| 333 | 50 | if (res != GLOBUS_SUCCESS) |
| 334 | { | |
| 335 | 0 | globus_module_deactivate(GLOBUS_WSRF_SERVICE_GROUP_MODULE); |
| 336 | } | |
| 337 | 50 | out: |
| 338 | 50 | return res; |
| 339 | } | |
| 340 | /* wssg_ServiceGroupRegistration_activate() */ | |
| 341 | ||
| 342 | static | |
| 343 | int | |
| 344 | wssg_l_ServiceGroupRegistration_deactivate(void) | |
| 345 | 42 | { |
| 346 | GlobusFuncName(wssg_ServiceGroup_deactivate); | |
| 347 | ||
| 348 | 42 | globus_extension_registry_remove( |
| 349 | GLOBUS_OPERATION_PROVIDER_REGISTRY, | |
| 350 | &wssg_Add_provider_qname); | |
| 351 | ||
| 352 | 42 | globus_module_deactivate(GLOBUS_WSRF_SERVICE_GROUP_MODULE); |
| 353 | ||
| 354 | 42 | return 0; |
| 355 | } |