| 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 | ||
| 18 | #include "globus_soap_message.h" | |
| 19 | #include "xsd_any.h" | |
| 20 | #include "xsd_anyType.h" | |
| 21 | #include "xsd_QName.h" | |
| 22 | #include "globus_soap_message_utils.h" | |
| 23 | #include "globus_i_soap_message.h" | |
| 24 | #include "globus_i_soap_message_wildcards.h" | |
| 25 | #include "globus_xml_buffer.h" | |
| 26 | ||
| 27 | void | |
| 28 | xsd_anyType_destroy_contents( | |
| 29 | xsd_anyType * instance) | |
| 30 | 691 | { |
| 31 | GlobusFuncName(xsd_anyType_destroy_contents); | |
| 32 | 691 | GlobusSoapMessageDebugEnter(); |
| 33 | ||
| 34 | 691 | if (instance) |
| 35 | { | |
| 36 | 691 | if(instance && instance->value && instance->any_info) |
| 37 | { | |
| 38 | 291 | instance->any_info->destroy(instance->value); |
| 39 | 291 | instance->value = NULL; |
| 40 | } | |
| 41 | 691 | instance->any_info = NULL; |
| 42 | 691 | instance->registry = NULL; |
| 43 | } | |
| 44 | ||
| 45 | 691 | GlobusSoapMessageDebugExit(); |
| 46 | 691 | } |
| 47 | /* xsd_anyType_destroy_contents() */ | |
| 48 | ||
| 49 | globus_result_t | |
| 50 | xsd_anyType_copy_contents( | |
| 51 | xsd_anyType * dest, | |
| 52 | const xsd_anyType * src) | |
| 53 | 324 | { |
| 54 | 324 | globus_result_t result = GLOBUS_SUCCESS; |
| 55 | GlobusFuncName(xsd_anyType_copy_contents); | |
| 56 | 324 | GlobusSoapMessageDebugEnter(); |
| 57 | ||
| 58 | 324 | if(dest && src) |
| 59 | { | |
| 60 | 324 | dest->registry = src->registry; |
| 61 | 324 | dest->any_info = src->any_info; |
| 62 | ||
| 63 | 464 | if(src->value && src->any_info) |
| 64 | { | |
| 65 | 140 | result = src->any_info->copy(&dest->value, src->value); |
| 66 | } | |
| 67 | else | |
| 68 | { | |
| 69 | 184 | dest->value = NULL; |
| 70 | } | |
| 71 | } | |
| 72 | ||
| 73 | 324 | GlobusSoapMessageDebugExit(); |
| 74 | 324 | return result; |
| 75 | } | |
| 76 | /* xsd_anyType_copy_contents() */ | |
| 77 | ||
| 78 | globus_result_t | |
| 79 | xsd_anyType_serialize( | |
| 80 | const xsd_QName * element_qname, | |
| 81 | const xsd_anyType * anyinst, | |
| 82 | globus_soap_message_handle_t message_handle, | |
| 83 | globus_xsd_element_options_t options) | |
| 84 | 286 | { |
| 85 | 286 | globus_result_t result = GLOBUS_SUCCESS; |
| 86 | 286 | globus_bool_t skip_type_info = GLOBUS_FALSE; |
| 87 | GlobusFuncName(xsd_anyType_serialize); | |
| 88 | 286 | GlobusSoapMessageDebugEnter(); |
| 89 | ||
| 90 | 286 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 91 | { | |
| 92 | /* add begin element (always act like GLOBUS_XSD_ELEMENT_TYPE_ATTR is | |
| 93 | * set for anyType). But, if the type QName is globus_xml_buffer_qname, | |
| 94 | * we'll not actually serialize it. | |
| 95 | */ | |
| 96 | ||
| 97 | 286 | if (anyinst->any_info != NULL && |
| 98 | anyinst->any_info->type != NULL && | |
| 99 | (xsd_QName_keyeq( | |
| 100 | anyinst->any_info->type, | |
| 101 | &globus_xml_buffer_qname) || | |
| 102 | xsd_QName_keyeq( | |
| 103 | anyinst->any_info->type, | |
| 104 | &xsd_any_qname))) | |
| 105 | { | |
| 106 | 160 | skip_type_info = GLOBUS_TRUE; |
| 107 | } | |
| 108 | ||
| 109 | ||
| 110 | 286 | result = globus_soap_message_attribute_ns_set( |
| 111 | message_handle, | |
| 112 | element_qname, | |
| 113 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 114 | &options); | |
| 115 | 286 | if(result != GLOBUS_SUCCESS) |
| 116 | { | |
| 117 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 118 | result, NULL, element_qname); | |
| 119 | 0 | goto exit; |
| 120 | } | |
| 121 | ||
| 122 | 286 | result = globus_soap_message_attribute_ns_set( |
| 123 | message_handle, | |
| 124 | element_qname, | |
| 125 | xsd_QName_qname.Namespace, | |
| 126 | &options); | |
| 127 | 286 | if(result != GLOBUS_SUCCESS) |
| 128 | { | |
| 129 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 130 | result, NULL, element_qname); | |
| 131 | 0 | goto exit; |
| 132 | } | |
| 133 | ||
| 134 | 286 | result = globus_soap_message_element_ns_set( |
| 135 | message_handle, | |
| 136 | element_qname, | |
| 137 | element_qname->Namespace, | |
| 138 | &options); | |
| 139 | ||
| 140 | 286 | if(result != GLOBUS_SUCCESS) |
| 141 | { | |
| 142 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 143 | result, NULL, element_qname); | |
| 144 | 0 | goto exit; |
| 145 | } | |
| 146 | ||
| 147 | 286 | if (anyinst->any_info != NULL && |
| 148 | anyinst->any_info->type != NULL && | |
| 149 | !skip_type_info) | |
| 150 | { | |
| 151 | 0 | result = globus_soap_message_element_ns_set( |
| 152 | message_handle, | |
| 153 | element_qname, | |
| 154 | anyinst->any_info->type->Namespace, | |
| 155 | &options); | |
| 156 | ||
| 157 | 0 | if(result != GLOBUS_SUCCESS) |
| 158 | { | |
| 159 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 160 | result, NULL, element_qname); | |
| 161 | 0 | goto exit; |
| 162 | } | |
| 163 | } | |
| 164 | ||
| 165 | 286 | result = globus_soap_message_serialize_element( |
| 166 | message_handle, | |
| 167 | element_qname, | |
| 168 | options | GLOBUS_XSD_ELEMENT_TYPE_ATTR, | |
| 169 | (anyinst->any_info != NULL) | |
| 170 | ? anyinst->any_info->type | |
| 171 | : NULL); | |
| 172 | ||
| 173 | 286 | if(result != GLOBUS_SUCCESS) |
| 174 | { | |
| 175 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 176 | result, | |
| 177 | "Serialization of xsd:anyType failed", | |
| 178 | element_qname); | |
| 179 | 0 | goto exit; |
| 180 | } | |
| 181 | ||
| 182 | 286 | result = globus_soap_message_attribute_ns_add( |
| 183 | message_handle, | |
| 184 | element_qname, | |
| 185 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 186 | &options); | |
| 187 | 286 | if(result != GLOBUS_SUCCESS) |
| 188 | { | |
| 189 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 190 | result, | |
| 191 | "Serialization of xsd:anyType failed", | |
| 192 | element_qname); | |
| 193 | 0 | goto exit; |
| 194 | } | |
| 195 | ||
| 196 | 286 | result = globus_soap_message_element_ns_add( |
| 197 | message_handle, | |
| 198 | element_qname, | |
| 199 | element_qname->Namespace, | |
| 200 | &options); | |
| 201 | 286 | if(result != GLOBUS_SUCCESS) |
| 202 | { | |
| 203 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 204 | result, | |
| 205 | "Serialization of xsd:anyType failed", | |
| 206 | element_qname); | |
| 207 | 0 | goto exit; |
| 208 | } | |
| 209 | 286 | if (anyinst->any_info != NULL && |
| 210 | anyinst->any_info->type != NULL && | |
| 211 | !skip_type_info) | |
| 212 | { | |
| 213 | xsd_QName type_attr; | |
| 214 | ||
| 215 | 0 | result = globus_soap_message_element_ns_add( |
| 216 | message_handle, | |
| 217 | element_qname, | |
| 218 | anyinst->any_info->type->Namespace, | |
| 219 | &options); | |
| 220 | ||
| 221 | 0 | if(result != GLOBUS_SUCCESS) |
| 222 | { | |
| 223 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 224 | result, NULL, element_qname); | |
| 225 | 0 | goto exit; |
| 226 | } | |
| 227 | 0 | type_attr.local = "type"; |
| 228 | 0 | type_attr.Namespace = |
| 229 | "http://www.w3.org/2001/XMLSchema-instance"; | |
| 230 | 0 | result = globus_soap_message_serialize_QName_attribute( |
| 231 | message_handle, | |
| 232 | &type_attr, | |
| 233 | anyinst->any_info->contents_info | |
| 234 | ? anyinst->any_info->contents_info->type | |
| 235 | : anyinst->any_info->type); | |
| 236 | 0 | if(result != GLOBUS_SUCCESS) |
| 237 | { | |
| 238 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 239 | result, NULL, element_qname); | |
| 240 | 0 | goto exit; |
| 241 | } | |
| 242 | } | |
| 243 | ||
| 244 | 286 | result = globus_soap_message_serialize_element_begin_close( |
| 245 | message_handle, element_qname); | |
| 246 | 286 | if(result != GLOBUS_SUCCESS) |
| 247 | { | |
| 248 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 249 | result, | |
| 250 | "Serialization of xsd:anyType failed", | |
| 251 | element_qname); | |
| 252 | 0 | goto exit; |
| 253 | } | |
| 254 | } | |
| 255 | ||
| 256 | 286 | if (anyinst->any_info != NULL) |
| 257 | { | |
| 258 | /* serialize contents of type */ | |
| 259 | 160 | result = anyinst->any_info->serialize( |
| 260 | element_qname, | |
| 261 | anyinst->value, | |
| 262 | message_handle, | |
| 263 | options | GLOBUS_XSD_ELEMENT_TYPE_ATTR | |
| 264 | | GLOBUS_XSD_ELEMENT_CONTENTS_ONLY); | |
| 265 | 160 | if(result != GLOBUS_SUCCESS) |
| 266 | { | |
| 267 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 268 | result, | |
| 269 | "Serialization of xsd:any failed", | |
| 270 | element_qname); | |
| 271 | 0 | goto exit; |
| 272 | } | |
| 273 | } | |
| 274 | ||
| 275 | 286 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 276 | { | |
| 277 | 286 | result = globus_soap_message_serialize_element_end( |
| 278 | message_handle, | |
| 279 | element_qname, | |
| 280 | options, | |
| 281 | NULL); | |
| 282 | 286 | if(result != GLOBUS_SUCCESS) |
| 283 | { | |
| 284 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 285 | result, | |
| 286 | "Serialization of empty xsd:anyType failed", | |
| 287 | element_qname); | |
| 288 | 0 | goto exit; |
| 289 | } | |
| 290 | 286 | if (anyinst->any_info != NULL && |
| 291 | anyinst->any_info->type != NULL && | |
| 292 | !skip_type_info) | |
| 293 | { | |
| 294 | 0 | globus_soap_message_element_ns_remove( |
| 295 | message_handle, | |
| 296 | anyinst->any_info->type->Namespace, | |
| 297 | &options); | |
| 298 | } | |
| 299 | 286 | globus_soap_message_element_ns_remove( |
| 300 | message_handle, | |
| 301 | element_qname->Namespace, | |
| 302 | &options); | |
| 303 | ||
| 304 | 286 | if (!skip_type_info) |
| 305 | { | |
| 306 | 126 | globus_soap_message_attribute_ns_remove( |
| 307 | message_handle, | |
| 308 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 309 | &options); | |
| 310 | } | |
| 311 | } | |
| 312 | ||
| 313 | 286 | exit: |
| 314 | ||
| 315 | 286 | GlobusSoapMessageDebugExit(); |
| 316 | 286 | return result; |
| 317 | } | |
| 318 | /* xsd_anyType_serialize() */ | |
| 319 | ||
| 320 | globus_result_t | |
| 321 | xsd_anyType_deserialize( | |
| 322 | const xsd_QName * element_qname, | |
| 323 | xsd_anyType * instance, | |
| 324 | globus_soap_message_handle_t message_handle, | |
| 325 | globus_xsd_element_options_t options) | |
| 326 | 258 | { |
| 327 | 258 | globus_result_t result = GLOBUS_SUCCESS; |
| 328 | 258 | globus_bool_t empty = GLOBUS_FALSE; |
| 329 | 258 | globus_bool_t no_element = GLOBUS_FALSE; |
| 330 | GlobusFuncName(xsd_anyType_deserialize); | |
| 331 | 258 | GlobusSoapMessageDebugEnter(); |
| 332 | ||
| 333 | 258 | result = globus_soap_message_deserialize_element( |
| 334 | message_handle, element_qname); | |
| 335 | 258 | if(result != GLOBUS_SUCCESS) |
| 336 | { | |
| 337 | 0 | if(GlobusSoapMessageStatusFailedWithTextCheck(result)) |
| 338 | { | |
| 339 | 0 | no_element = GLOBUS_TRUE; |
| 340 | 0 | result = GLOBUS_SUCCESS; |
| 341 | } | |
| 342 | 0 | else if(!GlobusSoapMessageStatusCheck(result)) |
| 343 | { | |
| 344 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 345 | result, element_qname); | |
| 346 | 0 | goto exit; |
| 347 | } | |
| 348 | else | |
| 349 | { | |
| 350 | goto exit; | |
| 351 | } | |
| 352 | } | |
| 353 | ||
| 354 | 258 | if (globus_soap_message_deserialize_element_is_empty(message_handle)) |
| 355 | { | |
| 356 | 148 | empty = GLOBUS_TRUE; |
| 357 | } | |
| 358 | ||
| 359 | 258 | if (! no_element) |
| 360 | { | |
| 361 | /* Push the element back if there was one. If we are deserializing | |
| 362 | * contents only, then the element is part of the contents, otherwise, | |
| 363 | * the deserializer in the any_info will want to see the element. | |
| 364 | */ | |
| 365 | 258 | globus_soap_message_deserialize_push_element(message_handle); |
| 366 | } | |
| 367 | ||
| 368 | 258 | GlobusSoapMessageDebugPrintf( |
| 369 | GLOBUS_SOAP_MESSAGE_DEBUG_WILDCARDS, | |
| 370 | ("\n\nDeserializing xsd:anyType\n")); | |
| 371 | ||
| 372 | 258 | result = globus_i_xsd_deserialize_from_xsi_type( |
| 373 | &instance->any_info, | |
| 374 | instance->registry, | |
| 375 | message_handle); | |
| 376 | 258 | if(result != GLOBUS_SUCCESS) |
| 377 | { | |
| 378 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 379 | result, element_qname); | |
| 380 | 0 | goto exit; |
| 381 | } | |
| 382 | ||
| 383 | 258 | if(!instance->any_info) |
| 384 | { | |
| 385 | 258 | instance->any_info = (&globus_xml_buffer_info); |
| 386 | } | |
| 387 | ||
| 388 | 258 | GlobusSoapMessageDebugPrintf( |
| 389 | GLOBUS_SOAP_MESSAGE_DEBUG_WILDCARDS, | |
| 390 | ("Using any info: {%s}%s\n", | |
| 391 | instance->any_info->type->Namespace, | |
| 392 | instance->any_info->type->local)); | |
| 393 | ||
| 394 | 258 | if (!empty) |
| 395 | { | |
| 396 | 110 | result = instance->any_info->deserialize( |
| 397 | element_qname, | |
| 398 | &instance->value, | |
| 399 | message_handle, | |
| 400 | options); | |
| 401 | 110 | if(result != GLOBUS_SUCCESS) |
| 402 | { | |
| 403 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 404 | result, instance->any_info->type); | |
| 405 | 0 | goto exit; |
| 406 | } | |
| 407 | } | |
| 408 | 148 | else if (!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 409 | { | |
| 410 | 148 | result = globus_soap_message_deserialize_element_end( |
| 411 | message_handle, | |
| 412 | element_qname); | |
| 413 | } | |
| 414 | ||
| 415 | ||
| 416 | 258 | exit: |
| 417 | ||
| 418 | 258 | if(result != GLOBUS_SUCCESS) |
| 419 | { | |
| 420 | 0 | xsd_anyType_destroy_contents(instance); |
| 421 | } | |
| 422 | ||
| 423 | 258 | GlobusSoapMessageDebugExit(); |
| 424 | 258 | return result; |
| 425 | } | |
| 426 | /* xsd_anyType_deserialize() */ | |
| 427 | ||
| 428 | globus_result_t | |
| 429 | xsd_anyType_deserialize_pointer( | |
| 430 | const xsd_QName * element_qname, | |
| 431 | xsd_anyType ** ip, | |
| 432 | globus_soap_message_handle_t message_handle, | |
| 433 | globus_xsd_element_options_t options) | |
| 434 | 204 | { |
| 435 | 204 | xsd_anyType * instance = NULL; |
| 436 | 204 | globus_result_t result = GLOBUS_SUCCESS; |
| 437 | 204 | globus_bool_t empty = GLOBUS_FALSE; |
| 438 | GlobusFuncName(xsd_any_deserialize_pointer); | |
| 439 | 204 | GlobusSoapMessageDebugEnter(); |
| 440 | ||
| 441 | 204 | result = globus_soap_message_deserialize_element( |
| 442 | message_handle, element_qname); | |
| 443 | 204 | if(result != GLOBUS_SUCCESS) |
| 444 | { | |
| 445 | 114 | if(GlobusSoapMessageStatusElementNotFoundCheck(result) || |
| 446 | GlobusSoapMessageStatusFailedElementCheck(result)) | |
| 447 | { | |
| 448 | 114 | *ip = NULL; |
| 449 | 114 | result = GLOBUS_SUCCESS; |
| 450 | ||
| 451 | 114 | goto exit; |
| 452 | } | |
| 453 | ||
| 454 | 0 | if(!GlobusSoapMessageStatusCheck(result)) |
| 455 | { | |
| 456 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 457 | result, element_qname); | |
| 458 | 0 | goto exit; |
| 459 | } | |
| 460 | 0 | goto exit; |
| 461 | } | |
| 462 | ||
| 463 | 90 | if (globus_soap_message_deserialize_element_is_empty(message_handle)) |
| 464 | { | |
| 465 | 90 | empty = GLOBUS_TRUE; |
| 466 | } | |
| 467 | ||
| 468 | 90 | globus_soap_message_deserialize_push_element(message_handle); |
| 469 | ||
| 470 | 90 | GlobusSoapMessageDebugPrintf( |
| 471 | GLOBUS_SOAP_MESSAGE_DEBUG_WILDCARDS, | |
| 472 | ("\n\nDeserializing xsd:anyType\n")); | |
| 473 | ||
| 474 | 90 | result = xsd_anyType_init(&instance); |
| 475 | 90 | if(result != GLOBUS_SUCCESS) |
| 476 | { | |
| 477 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 478 | result, &xsd_anyType_qname); | |
| 479 | 0 | goto exit; |
| 480 | } | |
| 481 | ||
| 482 | 90 | result = globus_i_xsd_deserialize_from_xsi_type( |
| 483 | &instance->any_info, | |
| 484 | instance->registry, | |
| 485 | message_handle); | |
| 486 | 90 | if(result != GLOBUS_SUCCESS) |
| 487 | { | |
| 488 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 489 | result, element_qname); | |
| 490 | 0 | goto exit; |
| 491 | } | |
| 492 | ||
| 493 | ||
| 494 | 90 | if(!instance->any_info) |
| 495 | { | |
| 496 | 90 | instance->any_info = (&globus_xml_buffer_info); |
| 497 | } | |
| 498 | ||
| 499 | 90 | if (!empty) |
| 500 | { | |
| 501 | 0 | result = instance->any_info->deserialize( |
| 502 | element_qname, | |
| 503 | &instance->value, | |
| 504 | message_handle, | |
| 505 | options); | |
| 506 | 0 | if(result != GLOBUS_SUCCESS) |
| 507 | { | |
| 508 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 509 | result, instance->any_info->type); | |
| 510 | 0 | goto exit; |
| 511 | } | |
| 512 | } | |
| 513 | 90 | else if (!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 514 | { | |
| 515 | 90 | result = globus_soap_message_deserialize_element_end( |
| 516 | message_handle, | |
| 517 | element_qname); | |
| 518 | } | |
| 519 | ||
| 520 | 90 | *ip = instance; |
| 521 | ||
| 522 | 204 | exit: |
| 523 | ||
| 524 | 204 | if(result != GLOBUS_SUCCESS && instance) |
| 525 | { | |
| 526 | 0 | xsd_anyType_destroy(instance); |
| 527 | } | |
| 528 | ||
| 529 | 204 | GlobusSoapMessageDebugExit(); |
| 530 | 204 | return result; |
| 531 | } |