| 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 "globus_service_registry.h" | |
| 24 | #include "version.h" | |
| 25 | ||
| 26 | #include "wsrp_SetResourcePropertiesType.h" | |
| 27 | #include "wsrp_SetResourcePropertiesResponseType.h" | |
| 28 | ||
| 29 | #include "wsr_ResourceUnknownFault.h" | |
| 30 | #include "wsrp_SetResourcePropertyRequestFailedFault.h" | |
| 31 | #include "wsrp_InvalidModificationFault.h" | |
| 32 | #include "wsrp_InvalidResourcePropertyQNameFault.h" | |
| 33 | ||
| 34 | /** | |
| 35 | * @page wsrp_SetResourceProperties_provider SetResourceProperties Provider | |
| 36 | * | |
| 37 | * <h2>Provider Usage Overview</h2> | |
| 38 | * This operation provider implements the SetResourceProperties portType defined | |
| 39 | * in | |
| 40 | * http://docs.oasis-open.org/wsrf/rpw-2.wsdl . | |
| 41 | * This portType consists of the @a SetResourceProperties operation and | |
| 42 | * related faults. | |
| 43 | * | |
| 44 | * The WSRF service engine will automatically register this provider to handle | |
| 45 | * the SetResourceProperties operation for services which use the port type. | |
| 46 | * | |
| 47 | * <h2>Limitations</h2> | |
| 48 | * - This provider does not provide any transactional behavior when multiple | |
| 49 | * Insert, Update, or Delete elements are present in the | |
| 50 | * SetResourcePropertiesRequest element, nor does it prevent concurrent | |
| 51 | * accesses to resource property values | |
| 52 | * - This provider does not implement read-only resource properties. | |
| 53 | * - The minOccurs and maxOccurs attributes are extremely loosely enforced. | |
| 54 | * If neither are present, then a resource property may have exactly one | |
| 55 | * value. If either are present, then the resource property is effectively | |
| 56 | * unbounded. | |
| 57 | */ | |
| 58 | ||
| 59 | static | |
| 60 | int | |
| 61 | wsrp_SetResourceProperties_activate(void); | |
| 62 | ||
| 63 | static | |
| 64 | int | |
| 65 | wsrp_SetResourceProperties_deactivate(void); | |
| 66 | ||
| 67 | GlobusExtensionDefineModule(globus_wsrp_SetResourceProperties_provider) = | |
| 68 | { | |
| 69 | "globus_wsrp_SetResourceProperties_provider", | |
| 70 | wsrp_SetResourceProperties_activate, | |
| 71 | wsrp_SetResourceProperties_deactivate, | |
| 72 | NULL, | |
| 73 | NULL, | |
| 74 | &local_version | |
| 75 | }; | |
| 76 | ||
| 77 | /* Prototypes */ | |
| 78 | static | |
| 79 | globus_result_t | |
| 80 | wsrp_SetResourceProperties_provider( | |
| 81 | globus_service_engine_t engine, | |
| 82 | globus_soap_message_handle_t handle, | |
| 83 | globus_service_descriptor_t * service, | |
| 84 | wsrp_SetResourcePropertiesType * SetResourceProperties, | |
| 85 | wsrp_SetResourcePropertiesResponseType * | |
| 86 | SetResourcePropertiesResponse, | |
| 87 | xsd_any * fault); | |
| 88 | ||
| 89 | static | |
| 90 | globus_result_t | |
| 91 | wsrp_l_InsertResourceProperty( | |
| 92 | globus_resource_t resource, | |
| 93 | xsd_any_array * any, | |
| 94 | xsd_any * fault); | |
| 95 | ||
| 96 | static | |
| 97 | globus_result_t | |
| 98 | wsrp_l_UpdateResourceProperty( | |
| 99 | globus_resource_t resource, | |
| 100 | xsd_any_array * any, | |
| 101 | xsd_any * fault); | |
| 102 | ||
| 103 | static | |
| 104 | globus_result_t | |
| 105 | wsrp_l_DeleteResourceProperty( | |
| 106 | globus_resource_t resource, | |
| 107 | xsd_QName * qname, | |
| 108 | xsd_any * fault); | |
| 109 | ||
| 110 | static | |
| 111 | globus_result_t | |
| 112 | wsrp_l_check_for_uniformity( | |
| 113 | xsd_any_array * any_array, | |
| 114 | xsd_any * fault); | |
| 115 | ||
| 116 | /* Local Variables */ | |
| 117 | static xsd_QName wsrp_SetResourceProperties_qname = | |
| 118 | { | |
| 119 | "http://docs.oasis-open.org/wsrf/rpw-2/providers", | |
| 120 | "SetResourceProperties" | |
| 121 | }; | |
| 122 | ||
| 123 | static | |
| 124 | globus_operation_provider_descriptor_t | |
| 125 | wsrp_SetResourceProperties_descriptor = | |
| 126 | { | |
| 127 | &wsrp_SetResourceProperties_qname, | |
| 128 | "SetResourceProperties", | |
| 129 | (void *)wsrp_SetResourceProperties_provider | |
| 130 | }; | |
| 131 | ||
| 132 | /* Implementation */ | |
| 133 | static | |
| 134 | globus_result_t | |
| 135 | wsrp_SetResourceProperties_provider( | |
| 136 | globus_service_engine_t engine, | |
| 137 | globus_soap_message_handle_t handle, | |
| 138 | globus_service_descriptor_t * service, | |
| 139 | wsrp_SetResourcePropertiesType * SetResourceProperties, | |
| 140 | wsrp_SetResourcePropertiesResponseType * | |
| 141 | SetResourcePropertiesResponse, | |
| 142 | xsd_any * fault) | |
| 143 | 484 | { |
| 144 | globus_resource_t resource; | |
| 145 | globus_result_t result; | |
| 146 | int i; | |
| 147 | xsd_any_array * any; | |
| 148 | ||
| 149 | 484 | result = globus_wsrf_core_get_resource( |
| 150 | handle, | |
| 151 | service, | |
| 152 | &resource); | |
| 153 | ||
| 154 | 484 | if (result != GLOBUS_SUCCESS || resource == NULL) |
| 155 | { | |
| 156 | 0 | result = globus_wsrf_core_create_fault( |
| 157 | fault, | |
| 158 | &wsr_ResourceUnknownFault_qname); | |
| 159 | ||
| 160 | 0 | goto out; |
| 161 | } | |
| 162 | ||
| 163 | 818 | for (i = 0; i < SetResourceProperties->choice_value.length; i++) |
| 164 | { | |
| 165 | 490 | switch (SetResourceProperties->choice_value.elements[i].type) |
| 166 | { | |
| 167 | case wsrp_SetResourcePropertiesType_Insert: | |
| 168 | 284 | any = &SetResourceProperties->choice_value.elements[i]. |
| 169 | value.Insert.any, | |
| 170 | result = wsrp_l_check_for_uniformity(any, fault); | |
| 171 | 284 | if (result != GLOBUS_SUCCESS || fault->value != NULL) |
| 172 | { | |
| 173 | goto finish_out; | |
| 174 | } | |
| 175 | 260 | result = wsrp_l_InsertResourceProperty( |
| 176 | resource, | |
| 177 | any, | |
| 178 | fault); | |
| 179 | ||
| 180 | 260 | if (result != GLOBUS_SUCCESS || fault->value != NULL) |
| 181 | { | |
| 182 | goto finish_out; | |
| 183 | } | |
| 184 | ||
| 185 | 200 | break; |
| 186 | ||
| 187 | case wsrp_SetResourcePropertiesType_Update: | |
| 188 | 170 | any = &SetResourceProperties->choice_value.elements[i]. |
| 189 | value.Update.any, | |
| 190 | result = wsrp_l_check_for_uniformity(any, fault); | |
| 191 | 170 | if (result != GLOBUS_SUCCESS || fault->value != NULL) |
| 192 | { | |
| 193 | goto finish_out; | |
| 194 | } | |
| 195 | 146 | result = wsrp_l_UpdateResourceProperty( |
| 196 | resource, | |
| 197 | any, | |
| 198 | fault); | |
| 199 | ||
| 200 | 146 | if (result != GLOBUS_SUCCESS || fault->value != NULL) |
| 201 | { | |
| 202 | goto finish_out; | |
| 203 | } | |
| 204 | ||
| 205 | 98 | break; |
| 206 | ||
| 207 | case wsrp_SetResourcePropertiesType_Delete: | |
| 208 | 36 | result = wsrp_l_DeleteResourceProperty( |
| 209 | resource, | |
| 210 | &SetResourceProperties->choice_value.elements[i]. | |
| 211 | value.Delete._ResourceProperty, | |
| 212 | fault); | |
| 213 | ||
| 214 | 36 | if (result != GLOBUS_SUCCESS || fault->value != NULL) |
| 215 | { | |
| 216 | goto finish_out; | |
| 217 | } | |
| 218 | 36 | break; |
| 219 | ||
| 220 | case wsrp_SetResourcePropertiesType_undefined: | |
| 221 | 0 | result = globus_wsrf_core_create_fault( |
| 222 | fault, | |
| 223 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 224 | 0 | goto finish_out; |
| 225 | } | |
| 226 | } | |
| 227 | ||
| 228 | 484 | finish_out: |
| 229 | 484 | globus_resource_finish(resource); |
| 230 | 484 | out: |
| 231 | 484 | return result; |
| 232 | } | |
| 233 | /* wsrp_SetResourceProperties_provider() */ | |
| 234 | ||
| 235 | static | |
| 236 | int | |
| 237 | wsrp_SetResourceProperties_activate(void) | |
| 238 | 311 | { |
| 239 | 311 | int res = 0; |
| 240 | GlobusFuncName(wsrp_SetResourceProperties_activate); | |
| 241 | ||
| 242 | 311 | res = globus_extension_registry_add( |
| 243 | GLOBUS_OPERATION_PROVIDER_REGISTRY, | |
| 244 | &wsrp_SetResourceProperties_qname, | |
| 245 | GlobusExtensionMyModule(globus_wsrp_SetResourceProperties_provider), | |
| 246 | &wsrp_SetResourceProperties_descriptor); | |
| 247 | ||
| 248 | 311 | return res; |
| 249 | } | |
| 250 | /* wsrp_SetResourceProperties_activate()) */ | |
| 251 | ||
| 252 | static | |
| 253 | int | |
| 254 | wsrp_SetResourceProperties_deactivate(void) | |
| 255 | 42 | { |
| 256 | GlobusFuncName(wsrp_SetResourceProperties_deactivate); | |
| 257 | ||
| 258 | 42 | globus_extension_registry_remove( |
| 259 | GLOBUS_OPERATION_PROVIDER_REGISTRY, | |
| 260 | &wsrp_SetResourceProperties_qname); | |
| 261 | ||
| 262 | 42 | return 0; |
| 263 | } | |
| 264 | /* wsrp_SetResourceProperties_deactivate() */ | |
| 265 | ||
| 266 | /** | |
| 267 | * Insert a new RP element to the RP document. | |
| 268 | */ | |
| 269 | static | |
| 270 | globus_result_t | |
| 271 | wsrp_l_InsertResourceProperty( | |
| 272 | globus_resource_t resource, | |
| 273 | xsd_any_array * any, | |
| 274 | xsd_any * fault) | |
| 275 | 260 | { |
| 276 | 260 | globus_result_t result = GLOBUS_SUCCESS; |
| 277 | globus_xsd_type_info_t prop_info; | |
| 278 | globus_xsd_type_info_t array_info; | |
| 279 | void * prop_value; | |
| 280 | xsd_any * prop_any; | |
| 281 | 260 | globus_bool_t use_any = GLOBUS_FALSE; |
| 282 | int i; | |
| 283 | globus_object_t * error; | |
| 284 | 260 | void * copy_value = NULL; |
| 285 | ||
| 286 | 260 | if (any->length == 0) |
| 287 | { | |
| 288 | 0 | goto out; |
| 289 | } | |
| 290 | 260 | result = globus_resource_get_property( |
| 291 | resource, | |
| 292 | any->elements[0].element, | |
| 293 | &prop_value, | |
| 294 | &prop_info); | |
| 295 | ||
| 296 | 260 | if (result != GLOBUS_SUCCESS) |
| 297 | { | |
| 298 | /* The property QName doesn't appear to be in our RP document */ | |
| 299 | 24 | error = globus_error_get(result); |
| 300 | 24 | if (globus_error_match( |
| 301 | error, | |
| 302 | GLOBUS_WSRF_RESOURCE_MODULE, | |
| 303 | GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY)) | |
| 304 | { | |
| 305 | 24 | result = globus_wsrf_core_create_fault( |
| 306 | fault, | |
| 307 | &wsrp_InvalidResourcePropertyQNameFault_qname); | |
| 308 | } | |
| 309 | else | |
| 310 | { | |
| 311 | 0 | result = globus_wsrf_core_create_fault( |
| 312 | fault, | |
| 313 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 314 | } | |
| 315 | 24 | globus_object_free(error); |
| 316 | 24 | goto out; |
| 317 | } | |
| 318 | ||
| 319 | 236 | if (prop_info == &xsd_any_info) |
| 320 | { | |
| 321 | /* Got an any */ | |
| 322 | 60 | prop_any = prop_value; |
| 323 | ||
| 324 | 78 | if (prop_any->any_info == NULL || |
| 325 | prop_any->any_info == any->elements[0].any_info) | |
| 326 | { | |
| 327 | /* Single value info */ | |
| 328 | 30 | if (any->length > 1 || prop_any->value != NULL) |
| 329 | { | |
| 330 | /* Only a single value will fit in the any */ | |
| 331 | 12 | result = globus_wsrf_core_create_fault( |
| 332 | fault, | |
| 333 | &wsrp_InvalidModificationFault_qname); | |
| 334 | 12 | goto out; |
| 335 | } | |
| 336 | 18 | if (prop_any->element == NULL) |
| 337 | { | |
| 338 | /* The any is new, we'll need to set element and info */ | |
| 339 | 18 | prop_any->any_info = any->elements[0].any_info; |
| 340 | 18 | result = xsd_QName_copy( |
| 341 | &prop_any->element, | |
| 342 | any->elements[0].element); | |
| 343 | ||
| 344 | 18 | if (result != GLOBUS_SUCCESS) |
| 345 | { | |
| 346 | 0 | result = globus_wsrf_core_create_fault( |
| 347 | fault, | |
| 348 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 349 | ||
| 350 | 0 | goto out; |
| 351 | } | |
| 352 | } | |
| 353 | ||
| 354 | /* Copy the content of the any passed in to this function to the | |
| 355 | * any in the RP document | |
| 356 | */ | |
| 357 | 18 | result = any->elements[0].any_info->copy( |
| 358 | &prop_any->value, | |
| 359 | any->elements[0].value); | |
| 360 | 18 | if (result != GLOBUS_SUCCESS) |
| 361 | { | |
| 362 | 0 | result = globus_wsrf_core_create_fault( |
| 363 | fault, | |
| 364 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 365 | 0 | goto out; |
| 366 | } | |
| 367 | } | |
| 368 | 30 | else if (prop_any->any_info == &xsd_any_array_info || |
| 369 | prop_any->any_info == any->elements[0].any_info->array_info) | |
| 370 | { | |
| 371 | 30 | if (prop_any->element == NULL) |
| 372 | { | |
| 373 | /* New any with hint that we can stick as many as we like here | |
| 374 | */ | |
| 375 | 18 | result = xsd_QName_copy( |
| 376 | &prop_any->element, | |
| 377 | any->elements[0].element); | |
| 378 | ||
| 379 | 18 | if (result != GLOBUS_SUCCESS) |
| 380 | { | |
| 381 | 0 | result = globus_wsrf_core_create_fault( |
| 382 | fault, | |
| 383 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 384 | ||
| 385 | 0 | goto out; |
| 386 | } | |
| 387 | /* Make new array for values */ | |
| 388 | 18 | array_info = any->elements[0].any_info->array_info; |
| 389 | 18 | if (any->elements[0].any_info->array_info == NULL) |
| 390 | { | |
| 391 | /* No array info? I guess use the any one */ | |
| 392 | 6 | array_info = &xsd_any_array_info; |
| 393 | 6 | use_any = GLOBUS_TRUE; |
| 394 | } | |
| 395 | 18 | result = array_info->initialize(&prop_any->value); |
| 396 | 18 | if (result != GLOBUS_SUCCESS) |
| 397 | { | |
| 398 | 0 | xsd_QName_destroy(prop_any->element); |
| 399 | 0 | result = globus_wsrf_core_create_fault( |
| 400 | fault, | |
| 401 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 402 | ||
| 403 | 0 | goto out; |
| 404 | } | |
| 405 | 18 | prop_any->any_info = array_info; |
| 406 | } | |
| 407 | ||
| 408 | /* Add new values to the any array now */ | |
| 409 | 78 | for (i = 0; i < any->length; i++) |
| 410 | { | |
| 411 | 48 | copy_value = prop_any->any_info->push(prop_any->value); |
| 412 | ||
| 413 | 48 | if (copy_value == NULL) |
| 414 | { | |
| 415 | 0 | result = globus_wsrf_core_create_fault( |
| 416 | fault, | |
| 417 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 418 | 0 | goto out; |
| 419 | } | |
| 420 | ||
| 421 | 48 | if (!use_any) |
| 422 | { | |
| 423 | 36 | result = any->elements[i].any_info->copy_contents( |
| 424 | copy_value, | |
| 425 | any->elements[i].value); | |
| 426 | } | |
| 427 | else | |
| 428 | { | |
| 429 | 12 | xsd_any_info.copy_contents( |
| 430 | copy_value, | |
| 431 | &any->elements[i]); | |
| 432 | } | |
| 433 | 48 | if (result != GLOBUS_SUCCESS) |
| 434 | { | |
| 435 | 0 | result = globus_wsrf_core_create_fault( |
| 436 | fault, | |
| 437 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 438 | 0 | goto out; |
| 439 | } | |
| 440 | } | |
| 441 | } | |
| 442 | } | |
| 443 | 176 | else if (any->elements[0].any_info == prop_info) |
| 444 | { | |
| 445 | /* The RP element and this element have the same type. We're OK | |
| 446 | * If there's only one element in the any. | |
| 447 | */ | |
| 448 | 132 | if (any->length > 1 || prop_value != NULL) |
| 449 | { | |
| 450 | 12 | result = globus_wsrf_core_create_fault( |
| 451 | fault, | |
| 452 | &wsrp_InvalidModificationFault_qname); | |
| 453 | 12 | goto out; |
| 454 | } | |
| 455 | 120 | prop_info->copy(©_value, any->elements[0].value); |
| 456 | 120 | result = globus_resource_set_property( |
| 457 | resource, | |
| 458 | any->elements[0].element, | |
| 459 | copy_value); | |
| 460 | 120 | if (result != GLOBUS_SUCCESS) |
| 461 | { | |
| 462 | 0 | error = globus_error_get(result); |
| 463 | ||
| 464 | 0 | if (globus_error_match( |
| 465 | error, | |
| 466 | GLOBUS_WSRF_RESOURCE_MODULE, | |
| 467 | GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY)) | |
| 468 | { | |
| 469 | 0 | result = globus_wsrf_core_create_fault( |
| 470 | fault, | |
| 471 | &wsrp_InvalidResourcePropertyQNameFault_qname); | |
| 472 | } | |
| 473 | else | |
| 474 | { | |
| 475 | 0 | result = globus_wsrf_core_create_fault( |
| 476 | fault, | |
| 477 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 478 | } | |
| 479 | 0 | globus_object_free(error); |
| 480 | ||
| 481 | 0 | goto out; |
| 482 | } | |
| 483 | } | |
| 484 | 44 | else if (any->elements[0].any_info->array_info == prop_info) |
| 485 | { | |
| 486 | /* The RP element is an array of the type we have in the any, so | |
| 487 | * we'll need to add the new values to the array. | |
| 488 | */ | |
| 489 | 32 | void * array_value = prop_value; |
| 490 | ||
| 491 | 32 | if (array_value == NULL) |
| 492 | { | |
| 493 | 24 | result = prop_info->initialize(&array_value); |
| 494 | 24 | if (result != GLOBUS_SUCCESS) |
| 495 | { | |
| 496 | 0 | result = globus_wsrf_core_create_fault( |
| 497 | fault, | |
| 498 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 499 | 0 | goto out; |
| 500 | } | |
| 501 | 24 | result = globus_resource_set_property( |
| 502 | resource, | |
| 503 | any->elements[0].element, | |
| 504 | array_value); | |
| 505 | ||
| 506 | 24 | if (result != GLOBUS_SUCCESS) |
| 507 | { | |
| 508 | 0 | result = globus_wsrf_core_create_fault( |
| 509 | fault, | |
| 510 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 511 | 0 | goto out; |
| 512 | } | |
| 513 | } | |
| 514 | ||
| 515 | 94 | for (i = 0; i < any->length; i++) |
| 516 | { | |
| 517 | 62 | copy_value = |
| 518 | any->elements[i].any_info->array_info->push(array_value); | |
| 519 | 62 | any->elements[i].any_info->copy_contents( |
| 520 | copy_value, | |
| 521 | any->elements[i].value); | |
| 522 | } | |
| 523 | } | |
| 524 | else | |
| 525 | { | |
| 526 | /* The types don't match at all, we can't do anything about that */ | |
| 527 | 12 | result = globus_wsrf_core_create_fault( |
| 528 | fault, | |
| 529 | &wsrp_InvalidModificationFault_qname); | |
| 530 | 12 | goto out; |
| 531 | } | |
| 532 | 260 | out: |
| 533 | 260 | return result; |
| 534 | } | |
| 535 | /* wsrp_l_InsertResourceProperty() */ | |
| 536 | ||
| 537 | static | |
| 538 | globus_result_t | |
| 539 | wsrp_l_UpdateResourceProperty( | |
| 540 | globus_resource_t resource, | |
| 541 | xsd_any_array * any, | |
| 542 | xsd_any * fault) | |
| 543 | 146 | { |
| 544 | 146 | globus_result_t result = GLOBUS_SUCCESS; |
| 545 | globus_xsd_type_info_t prop_info; | |
| 546 | void * prop_value; | |
| 547 | xsd_any * prop_any; | |
| 548 | globus_xsd_type_info_t old_info; | |
| 549 | globus_xsd_type_info_t array_info; | |
| 550 | 146 | globus_bool_t use_any = GLOBUS_FALSE; |
| 551 | xsd_QName * old_element; | |
| 552 | void * old_value; | |
| 553 | int i; | |
| 554 | globus_object_t * error; | |
| 555 | 146 | void * copy_value = NULL; |
| 556 | ||
| 557 | 146 | if (any->length == 0) |
| 558 | { | |
| 559 | 0 | goto out; |
| 560 | } | |
| 561 | 146 | result = globus_resource_get_property( |
| 562 | resource, | |
| 563 | any->elements[0].element, | |
| 564 | &prop_value, | |
| 565 | &prop_info); | |
| 566 | ||
| 567 | 146 | if (result != GLOBUS_SUCCESS) |
| 568 | { | |
| 569 | /* The property QName doesn't appear to be in our RP document */ | |
| 570 | 24 | error = globus_error_get(result); |
| 571 | 24 | if (globus_error_match( |
| 572 | error, | |
| 573 | GLOBUS_WSRF_RESOURCE_MODULE, | |
| 574 | GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY)) | |
| 575 | { | |
| 576 | 24 | result = globus_wsrf_core_create_fault( |
| 577 | fault, | |
| 578 | &wsrp_InvalidResourcePropertyQNameFault_qname); | |
| 579 | } | |
| 580 | else | |
| 581 | { | |
| 582 | 0 | result = globus_wsrf_core_create_fault( |
| 583 | fault, | |
| 584 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 585 | } | |
| 586 | ||
| 587 | 24 | globus_object_free(error); |
| 588 | 24 | goto out; |
| 589 | } | |
| 590 | ||
| 591 | 122 | if (prop_info == &xsd_any_info) |
| 592 | { | |
| 593 | /* Got an any */ | |
| 594 | 66 | prop_any = prop_value; |
| 595 | ||
| 596 | 90 | if (prop_any->any_info == NULL || |
| 597 | prop_any->any_info == any->elements[0].any_info) | |
| 598 | { | |
| 599 | /* Single value info */ | |
| 600 | 30 | if (any->length > 1) |
| 601 | { | |
| 602 | /* Only a single value will fit in the any */ | |
| 603 | 6 | result = globus_wsrf_core_create_fault( |
| 604 | fault, | |
| 605 | &wsrp_InvalidModificationFault_qname); | |
| 606 | 6 | goto out; |
| 607 | } | |
| 608 | ||
| 609 | 24 | old_value = prop_any->value; |
| 610 | 24 | old_info = prop_any->any_info; |
| 611 | ||
| 612 | 24 | if (prop_any->element == NULL) |
| 613 | { | |
| 614 | /* The any is new, we'll need to set element and info */ | |
| 615 | 18 | prop_any->any_info = any->elements[0].any_info; |
| 616 | 18 | result = xsd_QName_copy( |
| 617 | &prop_any->element, | |
| 618 | any->elements[0].element); | |
| 619 | ||
| 620 | 18 | if (result != GLOBUS_SUCCESS) |
| 621 | { | |
| 622 | 0 | result = globus_wsrf_core_create_fault( |
| 623 | fault, | |
| 624 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 625 | ||
| 626 | 0 | goto out; |
| 627 | } | |
| 628 | } | |
| 629 | ||
| 630 | /* Copy the content of the any passed in to this function to the | |
| 631 | * any in the RP document | |
| 632 | */ | |
| 633 | 24 | result = any->elements[0].any_info->copy( |
| 634 | &prop_any->value, | |
| 635 | any->elements[0].value); | |
| 636 | 24 | if (result != GLOBUS_SUCCESS) |
| 637 | { | |
| 638 | 0 | result = globus_wsrf_core_create_fault( |
| 639 | fault, | |
| 640 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 641 | 0 | goto out; |
| 642 | } | |
| 643 | ||
| 644 | 24 | if (old_info && old_value) |
| 645 | { | |
| 646 | 6 | old_info->destroy(old_value); |
| 647 | } | |
| 648 | } | |
| 649 | 36 | else if (prop_any->any_info == &xsd_any_array_info || |
| 650 | prop_any->any_info == any->elements[0].any_info->array_info) | |
| 651 | { | |
| 652 | 36 | old_info = prop_any->any_info; |
| 653 | 36 | old_value = prop_any->value; |
| 654 | 36 | old_element = prop_any->element; |
| 655 | ||
| 656 | 36 | prop_any->value = NULL; |
| 657 | 36 | if (prop_any->element == NULL) |
| 658 | { | |
| 659 | /* New any with hint that we can stick as many as we like here | |
| 660 | */ | |
| 661 | 24 | result = xsd_QName_copy( |
| 662 | &prop_any->element, | |
| 663 | any->elements[0].element); | |
| 664 | ||
| 665 | 24 | if (result != GLOBUS_SUCCESS) |
| 666 | { | |
| 667 | 0 | result = globus_wsrf_core_create_fault( |
| 668 | fault, | |
| 669 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 670 | ||
| 671 | 0 | goto out; |
| 672 | } | |
| 673 | } | |
| 674 | ||
| 675 | /* Make new array for values */ | |
| 676 | 36 | array_info = any->elements[0].any_info->array_info; |
| 677 | 36 | if (any->elements[0].any_info->array_info == NULL) |
| 678 | { | |
| 679 | /* No array info? I guess use the any one */ | |
| 680 | 6 | array_info = &xsd_any_array_info; |
| 681 | 6 | use_any = GLOBUS_TRUE; |
| 682 | } | |
| 683 | 36 | result = array_info->initialize(&prop_any->value); |
| 684 | ||
| 685 | 36 | if (result != GLOBUS_SUCCESS) |
| 686 | { | |
| 687 | /* Restore property state */ | |
| 688 | 0 | xsd_QName_destroy(prop_any->element); |
| 689 | 0 | prop_any->value = old_value; |
| 690 | 0 | prop_any->element = old_element; |
| 691 | 0 | prop_any->any_info = old_info; |
| 692 | ||
| 693 | 0 | result = globus_wsrf_core_create_fault( |
| 694 | fault, | |
| 695 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 696 | ||
| 697 | 0 | goto out; |
| 698 | } | |
| 699 | 36 | prop_any->any_info = array_info; |
| 700 | ||
| 701 | /* Add new values to the any array now */ | |
| 702 | 90 | for (i = 0; i < any->length; i++) |
| 703 | { | |
| 704 | 54 | copy_value = prop_any->any_info->push(prop_any->value); |
| 705 | ||
| 706 | 54 | if (copy_value == NULL) |
| 707 | { | |
| 708 | /* Restore property state */ | |
| 709 | 0 | xsd_QName_destroy(prop_any->element); |
| 710 | 0 | prop_any->value = old_value; |
| 711 | 0 | prop_any->element = old_element; |
| 712 | 0 | prop_any->any_info = old_info; |
| 713 | ||
| 714 | 0 | result = globus_wsrf_core_create_fault( |
| 715 | fault, | |
| 716 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 717 | 0 | goto out; |
| 718 | } | |
| 719 | ||
| 720 | 54 | if (!use_any) |
| 721 | { | |
| 722 | 42 | result = any->elements[i].any_info->copy_contents( |
| 723 | copy_value, | |
| 724 | any->elements[i].value); | |
| 725 | } | |
| 726 | else | |
| 727 | { | |
| 728 | 12 | result = xsd_any_info.copy_contents( |
| 729 | copy_value, | |
| 730 | &any->elements[i]); | |
| 731 | } | |
| 732 | 54 | if (result != GLOBUS_SUCCESS) |
| 733 | { | |
| 734 | 0 | prop_any->any_info->destroy(prop_any->value); |
| 735 | ||
| 736 | /* Restore property state */ | |
| 737 | 0 | xsd_QName_destroy(prop_any->element); |
| 738 | 0 | prop_any->value = old_value; |
| 739 | 0 | prop_any->element = old_element; |
| 740 | 0 | prop_any->any_info = old_info; |
| 741 | ||
| 742 | 0 | result = globus_wsrf_core_create_fault( |
| 743 | fault, | |
| 744 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 745 | 0 | goto out; |
| 746 | } | |
| 747 | } | |
| 748 | 36 | if (old_info && old_value) |
| 749 | { | |
| 750 | 12 | old_info->destroy(old_value); |
| 751 | } | |
| 752 | } | |
| 753 | } | |
| 754 | 56 | else if (any->elements[0].any_info == prop_info) |
| 755 | { | |
| 756 | /* The RP element and this element have the same type. We're OK | |
| 757 | * If there's only one element in the any. | |
| 758 | */ | |
| 759 | 30 | if (any->length > 1) |
| 760 | { | |
| 761 | 6 | result = globus_wsrf_core_create_fault( |
| 762 | fault, | |
| 763 | &wsrp_InvalidModificationFault_qname); | |
| 764 | 6 | goto out; |
| 765 | } | |
| 766 | 24 | prop_info->copy(©_value, any->elements[0].value); |
| 767 | 24 | result = globus_resource_set_property( |
| 768 | resource, | |
| 769 | any->elements[0].element, | |
| 770 | copy_value); | |
| 771 | 24 | if (result != GLOBUS_SUCCESS) |
| 772 | { | |
| 773 | 0 | error = globus_error_get(result); |
| 774 | ||
| 775 | 0 | if (globus_error_match( |
| 776 | error, | |
| 777 | GLOBUS_WSRF_RESOURCE_MODULE, | |
| 778 | GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY)) | |
| 779 | { | |
| 780 | 0 | result = globus_wsrf_core_create_fault( |
| 781 | fault, | |
| 782 | &wsrp_InvalidResourcePropertyQNameFault_qname); | |
| 783 | } | |
| 784 | else | |
| 785 | { | |
| 786 | 0 | result = globus_wsrf_core_create_fault( |
| 787 | fault, | |
| 788 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 789 | } | |
| 790 | 0 | globus_object_free(error); |
| 791 | ||
| 792 | 0 | goto out; |
| 793 | } | |
| 794 | } | |
| 795 | 26 | else if (any->elements[0].any_info->array_info == prop_info) |
| 796 | { | |
| 797 | /* The RP element is an array of the type we have in the any, so | |
| 798 | * we'll need to replace the value of the array | |
| 799 | */ | |
| 800 | 14 | void * array_value = NULL; |
| 801 | ||
| 802 | 14 | result = prop_info->initialize(&array_value); |
| 803 | 14 | if (result != GLOBUS_SUCCESS) |
| 804 | { | |
| 805 | 0 | result = globus_wsrf_core_create_fault( |
| 806 | fault, | |
| 807 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 808 | 0 | goto out; |
| 809 | } | |
| 810 | 14 | result = globus_resource_set_property( |
| 811 | resource, | |
| 812 | any->elements[0].element, | |
| 813 | array_value); | |
| 814 | ||
| 815 | 14 | if (result != GLOBUS_SUCCESS) |
| 816 | { | |
| 817 | 0 | result = globus_wsrf_core_create_fault( |
| 818 | fault, | |
| 819 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 820 | 0 | goto out; |
| 821 | } | |
| 822 | ||
| 823 | 36 | for (i = 0; i < any->length; i++) |
| 824 | { | |
| 825 | 22 | copy_value = |
| 826 | any->elements[i].any_info->array_info->push(array_value); | |
| 827 | 22 | if (copy_value == NULL) |
| 828 | { | |
| 829 | 0 | result = globus_wsrf_core_create_fault( |
| 830 | fault, | |
| 831 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 832 | ||
| 833 | 0 | goto out; |
| 834 | } | |
| 835 | 22 | result = any->elements[i].any_info->copy_contents( |
| 836 | copy_value, | |
| 837 | any->elements[i].value); | |
| 838 | 22 | if (result != GLOBUS_SUCCESS) |
| 839 | { | |
| 840 | 0 | result = globus_wsrf_core_create_fault( |
| 841 | fault, | |
| 842 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 843 | ||
| 844 | 0 | goto out; |
| 845 | } | |
| 846 | } | |
| 847 | } | |
| 848 | else | |
| 849 | { | |
| 850 | /* The types don't match at all, we can't do anything about that */ | |
| 851 | 12 | result = globus_wsrf_core_create_fault( |
| 852 | fault, | |
| 853 | &wsrp_InvalidModificationFault_qname); | |
| 854 | ||
| 855 | 12 | goto out; |
| 856 | } | |
| 857 | 146 | out: |
| 858 | 146 | return result; |
| 859 | } | |
| 860 | /* wsrp_l_UpdateResourceProperty() */ | |
| 861 | ||
| 862 | static | |
| 863 | globus_result_t | |
| 864 | wsrp_l_DeleteResourceProperty( | |
| 865 | globus_resource_t resource, | |
| 866 | xsd_QName * qname, | |
| 867 | xsd_any * fault) | |
| 868 | 36 | { |
| 869 | globus_result_t result; | |
| 870 | globus_object_t * error; | |
| 871 | ||
| 872 | 36 | result = globus_resource_set_property( |
| 873 | resource, | |
| 874 | qname, | |
| 875 | NULL); | |
| 876 | ||
| 877 | 36 | if (result != GLOBUS_SUCCESS) |
| 878 | { | |
| 879 | 0 | error = globus_error_get(result); |
| 880 | ||
| 881 | 0 | if (globus_error_match( |
| 882 | error, | |
| 883 | GLOBUS_WSRF_RESOURCE_MODULE, | |
| 884 | GLOBUS_WSRF_RESOURCE_ERROR_TYPE_UNKNOWN_PROPERTY)) | |
| 885 | { | |
| 886 | 0 | result = globus_wsrf_core_create_fault( |
| 887 | fault, | |
| 888 | &wsrp_InvalidResourcePropertyQNameFault_qname); | |
| 889 | } | |
| 890 | else | |
| 891 | { | |
| 892 | 0 | result = globus_wsrf_core_create_fault( |
| 893 | fault, | |
| 894 | &wsrp_SetResourcePropertyRequestFailedFault_qname); | |
| 895 | } | |
| 896 | 0 | globus_object_free(error); |
| 897 | } | |
| 898 | ||
| 899 | 36 | return result; |
| 900 | } | |
| 901 | /* wsrp_l_DeleteResourceProperty() */ | |
| 902 | ||
| 903 | /** | |
| 904 | * Check that all elements in the any array have the same element name | |
| 905 | * and type info. | |
| 906 | * | |
| 907 | * If not, return a wsrp_InvalidModificationFault | |
| 908 | * fault in the fault_name and fault parameters. | |
| 909 | */ | |
| 910 | static | |
| 911 | globus_result_t | |
| 912 | wsrp_l_check_for_uniformity( | |
| 913 | xsd_any_array * any_array, | |
| 914 | xsd_any * fault) | |
| 915 | 454 | { |
| 916 | int i; | |
| 917 | 454 | globus_result_t result = GLOBUS_SUCCESS; |
| 918 | xsd_QName * last_element; | |
| 919 | 454 | xsd_QName * element = NULL; |
| 920 | globus_xsd_type_info_t last_type; | |
| 921 | 454 | globus_xsd_type_info_t type = NULL; |
| 922 | ||
| 923 | /* Verify that all update elements are the same */ | |
| 924 | 1018 | for (i = 0; i < any_array->length; i++) |
| 925 | { | |
| 926 | 612 | last_element = element; |
| 927 | 612 | last_type = type; |
| 928 | ||
| 929 | 612 | element = any_array->elements[i].element; |
| 930 | 612 | type = any_array->elements[i].any_info; |
| 931 | ||
| 932 | 612 | if (i != 0) |
| 933 | { | |
| 934 | 158 | if (type != last_type || !xsd_QName_keyeq(element, last_element)) |
| 935 | { | |
| 936 | 48 | result = globus_wsrf_core_create_fault( |
| 937 | fault, | |
| 938 | &wsrp_InvalidModificationFault_qname); | |
| 939 | 48 | goto out; |
| 940 | } | |
| 941 | } | |
| 942 | } | |
| 943 | 454 | out: |
| 944 | 454 | return result; |
| 945 | } |