| 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_i_soap_message.h" | |
| 19 | ||
| 20 | /** | |
| 21 | * Common serialization code for all primitive types. | |
| 22 | * @param element_qname | |
| 23 | * @param type_info | |
| 24 | * @param instance | |
| 25 | * @param type_serialize_contents | |
| 26 | * @param message_handle | |
| 27 | */ | |
| 28 | globus_result_t | |
| 29 | globus_xsd_generic_serialize( | |
| 30 | const xsd_QName * element_qname, | |
| 31 | const globus_xsd_type_info_t type_info, | |
| 32 | const void * instance, | |
| 33 | globus_soap_message_handle_t message_handle, | |
| 34 | globus_xsd_element_options_t options) | |
| 35 | 2288299 | { |
| 36 | 2288299 | globus_result_t result = GLOBUS_SUCCESS; |
| 37 | GlobusFuncName(globus_xsd_generic_serialize); | |
| 38 | 2288299 | GlobusSoapMessageDebugEnter(); |
| 39 | ||
| 40 | 2288299 | if (message_handle == NULL || type_info == NULL || (instance == NULL && !(options&GLOBUS_XSD_ELEMENT_NIL))) |
| 41 | { | |
| 42 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 43 | ||
| 44 | 0 | goto exit; |
| 45 | } | |
| 46 | 2288299 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 47 | { | |
| 48 | 2192283 | if (element_qname == NULL) |
| 49 | { | |
| 50 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 51 | ||
| 52 | 0 | goto exit; |
| 53 | } | |
| 54 | /* add begin element */ | |
| 55 | 2192283 | if(options & (GLOBUS_XSD_ELEMENT_TYPE_ATTR|GLOBUS_XSD_ELEMENT_NIL) && |
| 56 | !message_handle->c14n_subset) | |
| 57 | { | |
| 58 | 2182007 | result = globus_soap_message_attribute_ns_set( |
| 59 | message_handle, | |
| 60 | element_qname, | |
| 61 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 62 | &options); | |
| 63 | 2182007 | if(result != GLOBUS_SUCCESS) |
| 64 | { | |
| 65 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 66 | result, NULL, element_qname); | |
| 67 | 0 | goto exit; |
| 68 | } | |
| 69 | ||
| 70 | 2182007 | result = globus_soap_message_attribute_ns_set( |
| 71 | message_handle, | |
| 72 | element_qname, | |
| 73 | type_info->type->Namespace, | |
| 74 | &options); | |
| 75 | 2182007 | if(result != GLOBUS_SUCCESS) |
| 76 | { | |
| 77 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 78 | result, NULL, element_qname); | |
| 79 | 0 | goto exit; |
| 80 | } | |
| 81 | } | |
| 82 | ||
| 83 | 2192283 | result = globus_soap_message_element_ns_set( |
| 84 | message_handle, | |
| 85 | element_qname, | |
| 86 | element_qname->Namespace, | |
| 87 | &options); | |
| 88 | 2192283 | if(result != GLOBUS_SUCCESS) |
| 89 | { | |
| 90 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 91 | result, NULL, element_qname); | |
| 92 | 0 | goto exit; |
| 93 | } | |
| 94 | 2192283 | result = globus_soap_message_serialize_element( |
| 95 | message_handle, | |
| 96 | element_qname, | |
| 97 | options, | |
| 98 | type_info->type); | |
| 99 | 2192283 | if(result != GLOBUS_SUCCESS) |
| 100 | { | |
| 101 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 102 | result, NULL, element_qname); | |
| 103 | 0 | goto exit; |
| 104 | } | |
| 105 | ||
| 106 | /* serialize namespaces */ | |
| 107 | 2192283 | if(options & GLOBUS_XSD_ELEMENT_TYPE_ATTR && |
| 108 | !message_handle->c14n_subset) | |
| 109 | { | |
| 110 | 2182007 | result = globus_soap_message_attribute_ns_add( |
| 111 | message_handle, | |
| 112 | element_qname, | |
| 113 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 114 | &options); | |
| 115 | 2182007 | if(result != GLOBUS_SUCCESS) |
| 116 | { | |
| 117 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 118 | result, NULL, element_qname); | |
| 119 | 0 | goto exit; |
| 120 | } | |
| 121 | ||
| 122 | 2182007 | result = globus_soap_message_attribute_ns_add( |
| 123 | message_handle, | |
| 124 | element_qname, | |
| 125 | type_info->type->Namespace, | |
| 126 | &options); | |
| 127 | 2182007 | if(result != GLOBUS_SUCCESS) |
| 128 | { | |
| 129 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 130 | result, NULL, element_qname); | |
| 131 | 0 | goto exit; |
| 132 | } | |
| 133 | } | |
| 134 | ||
| 135 | 2192283 | result = globus_soap_message_element_ns_add( |
| 136 | message_handle, | |
| 137 | element_qname, | |
| 138 | element_qname->Namespace, | |
| 139 | &options); | |
| 140 | 2192283 | if(result != GLOBUS_SUCCESS) |
| 141 | { | |
| 142 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 143 | result, NULL, element_qname); | |
| 144 | 0 | goto exit; |
| 145 | } | |
| 146 | ||
| 147 | 2192283 | if(options & GLOBUS_XSD_ELEMENT_TYPE_ATTR && |
| 148 | !message_handle->c14n_subset) | |
| 149 | { | |
| 150 | xsd_QName type_attr; | |
| 151 | 2182007 | type_attr.local = "type"; |
| 152 | 2182007 | type_attr.Namespace = |
| 153 | "http://www.w3.org/2001/XMLSchema-instance"; | |
| 154 | 2182007 | result = globus_soap_message_serialize_QName_attribute( |
| 155 | message_handle, | |
| 156 | &type_attr, | |
| 157 | type_info->type); | |
| 158 | 2182007 | if(result != GLOBUS_SUCCESS) |
| 159 | { | |
| 160 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 161 | result, NULL, element_qname); | |
| 162 | 0 | goto exit; |
| 163 | } | |
| 164 | } | |
| 165 | ||
| 166 | 2192283 | if ((options & GLOBUS_XSD_ELEMENT_NIL) && (!instance) && |
| 167 | (!message_handle->c14n_subset)) | |
| 168 | { | |
| 169 | xsd_QName nil_attr; | |
| 170 | 12 | xsd_boolean nil_val = GLOBUS_TRUE; |
| 171 | ||
| 172 | 12 | nil_attr.Namespace = XSI_NS; |
| 173 | 12 | nil_attr.local = "nil"; |
| 174 | 12 | result = globus_soap_message_serialize_boolean_attribute( |
| 175 | message_handle, | |
| 176 | &nil_attr, | |
| 177 | &nil_val); | |
| 178 | } | |
| 179 | ||
| 180 | /* serialize attributes */ | |
| 181 | 2192283 | result = globus_soap_message_serialize_element_begin_close( |
| 182 | message_handle, element_qname); | |
| 183 | 2192283 | if(result != GLOBUS_SUCCESS) |
| 184 | { | |
| 185 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 186 | result, NULL, element_qname); | |
| 187 | 0 | goto exit; |
| 188 | } | |
| 189 | } | |
| 190 | ||
| 191 | 2288299 | if (instance != NULL) |
| 192 | { | |
| 193 | /* serialize contents of type */ | |
| 194 | 2288287 | result = type_info->contents_info->serialize( |
| 195 | NULL, instance, message_handle, 0); | |
| 196 | 2288287 | if(result != GLOBUS_SUCCESS) |
| 197 | { | |
| 198 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 199 | result, NULL, element_qname); | |
| 200 | 0 | goto exit; |
| 201 | } | |
| 202 | } | |
| 203 | ||
| 204 | 2288299 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 205 | { | |
| 206 | /* add end element */ | |
| 207 | 2192283 | result = globus_soap_message_serialize_element_end( |
| 208 | message_handle, | |
| 209 | element_qname, | |
| 210 | options, | |
| 211 | type_info->type); | |
| 212 | 2192283 | if(result != GLOBUS_SUCCESS) |
| 213 | { | |
| 214 | 0 | result = GlobusSoapMessageErrorSerializeFailed( |
| 215 | result, NULL, element_qname); | |
| 216 | 0 | goto exit; |
| 217 | } | |
| 218 | ||
| 219 | 2192283 | globus_soap_message_element_ns_remove( |
| 220 | message_handle, | |
| 221 | element_qname->Namespace, | |
| 222 | &options); | |
| 223 | ||
| 224 | 2192283 | if(options & GLOBUS_XSD_ELEMENT_TYPE_ATTR && |
| 225 | !message_handle->c14n_subset) | |
| 226 | { | |
| 227 | 2182007 | globus_soap_message_attribute_ns_remove( |
| 228 | message_handle, | |
| 229 | "http://www.w3.org/2001/XMLSchema-instance", | |
| 230 | &options); | |
| 231 | ||
| 232 | 2182007 | globus_soap_message_attribute_ns_remove( |
| 233 | message_handle, | |
| 234 | type_info->type->Namespace, | |
| 235 | &options); | |
| 236 | } | |
| 237 | } | |
| 238 | ||
| 239 | 2288299 | exit: |
| 240 | ||
| 241 | 2288299 | GlobusSoapMessageDebugExit(); |
| 242 | 2288299 | return result; |
| 243 | } | |
| 244 | /* globus_xsd_generic_serialize() */ | |
| 245 | ||
| 246 | ||
| 247 | globus_result_t | |
| 248 | globus_xsd_generic_deserialize( | |
| 249 | const xsd_QName * element_qname, | |
| 250 | const globus_xsd_type_info_t type_info, | |
| 251 | void ** instance, | |
| 252 | globus_soap_message_handle_t message_handle, | |
| 253 | globus_xsd_element_options_t options) | |
| 254 | 2736829 | { |
| 255 | 2736829 | globus_result_t result = GLOBUS_SUCCESS; |
| 256 | GlobusFuncName(globus_xsd_generic_deserialize); | |
| 257 | 2736829 | GlobusSoapMessageDebugEnter(); |
| 258 | ||
| 259 | 2736829 | if (type_info == NULL || |
| 260 | instance == NULL || | |
| 261 | message_handle == NULL) | |
| 262 | { | |
| 263 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 264 | ||
| 265 | 0 | goto exit; |
| 266 | } | |
| 267 | ||
| 268 | 2736829 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 269 | { | |
| 270 | 12147 | result = globus_soap_message_deserialize_element( |
| 271 | message_handle, element_qname); | |
| 272 | 12147 | if(result != GLOBUS_SUCCESS) |
| 273 | { | |
| 274 | 0 | goto error_exit; |
| 275 | } | |
| 276 | ||
| 277 | 12147 | result = globus_soap_message_deserialize_element_begin_close( |
| 278 | message_handle); | |
| 279 | 12147 | if(result != GLOBUS_SUCCESS) |
| 280 | { | |
| 281 | 0 | goto error_exit; |
| 282 | } | |
| 283 | } | |
| 284 | ||
| 285 | 2736829 | result = type_info->contents_info->deserialize( |
| 286 | NULL, | |
| 287 | instance, | |
| 288 | message_handle, | |
| 289 | options); | |
| 290 | 2736829 | if(result != GLOBUS_SUCCESS) |
| 291 | { | |
| 292 | 0 | goto error_exit; |
| 293 | } | |
| 294 | ||
| 295 | 2736829 | if(!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 296 | { | |
| 297 | 12147 | result = |
| 298 | globus_soap_message_deserialize_element_end( | |
| 299 | message_handle, | |
| 300 | element_qname); | |
| 301 | 12147 | if(result != GLOBUS_SUCCESS) |
| 302 | { | |
| 303 | 0 | goto error_exit; |
| 304 | } | |
| 305 | } | |
| 306 | ||
| 307 | 2736829 | goto exit; |
| 308 | ||
| 309 | 0 | error_exit: |
| 310 | ||
| 311 | 0 | if(!GlobusSoapMessageStatusCheck(result)) |
| 312 | { | |
| 313 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 314 | result, element_qname); | |
| 315 | } | |
| 316 | 2736829 | exit: |
| 317 | ||
| 318 | 2736829 | GlobusSoapMessageDebugExit(); |
| 319 | 2736829 | return result; |
| 320 | } | |
| 321 | /* globus_xsd_generic_deserialize() */ | |
| 322 | ||
| 323 | globus_result_t | |
| 324 | globus_xsd_generic_init( | |
| 325 | const globus_xsd_type_info_t type_info, | |
| 326 | void ** object) | |
| 327 | 0 | { |
| 328 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 329 | GlobusFuncName(globus_xsd_generic_init); | |
| 330 | void * instance; | |
| 331 | ||
| 332 | 0 | GlobusSoapMessageDebugEnter(); |
| 333 | ||
| 334 | 0 | instance = calloc(1, type_info->type_size); |
| 335 | 0 | if (instance == NULL) |
| 336 | { | |
| 337 | 0 | GlobusSoapMessageDebugExit(); |
| 338 | 0 | return GlobusSoapMessageErrorOutOfMemory; |
| 339 | } | |
| 340 | ||
| 341 | 0 | *object = instance; |
| 342 | 0 | GlobusSoapMessageDebugExit(); |
| 343 | 0 | return result; |
| 344 | } | |
| 345 | /* globus_xsd_generic_init() */ | |
| 346 | ||
| 347 | ||
| 348 | void | |
| 349 | globus_xsd_generic_destroy( | |
| 350 | const globus_xsd_type_info_t type_info, | |
| 351 | void * object) | |
| 352 | 0 | { |
| 353 | GlobusFuncName(globus_xsd_generic_destroy); | |
| 354 | 0 | GlobusSoapMessageDebugEnter(); |
| 355 | ||
| 356 | 0 | if(!object) |
| 357 | { | |
| 358 | 0 | goto exit; |
| 359 | } | |
| 360 | ||
| 361 | 0 | type_info->destroy_contents(object); |
| 362 | ||
| 363 | 0 | free(object); |
| 364 | 0 | exit: |
| 365 | 0 | GlobusSoapMessageDebugExit(); |
| 366 | 0 | } |
| 367 | /* globus_xsd_generic_destroy() */ | |
| 368 | ||
| 369 | globus_result_t | |
| 370 | globus_xsd_generic_copy( | |
| 371 | const globus_xsd_type_info_t type_info, | |
| 372 | void ** dest_obj, | |
| 373 | const void * src_obj) | |
| 374 | 0 | { |
| 375 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 376 | GlobusFuncName(globus_xsd_generic_copy); | |
| 377 | void * instance; | |
| 378 | 0 | GlobusSoapMessageDebugEnter(); |
| 379 | ||
| 380 | 0 | if(!src_obj) |
| 381 | { | |
| 382 | 0 | instance = NULL; |
| 383 | 0 | goto exit; |
| 384 | } | |
| 385 | ||
| 386 | 0 | instance = malloc(type_info->type_size); |
| 387 | 0 | if (instance == NULL) |
| 388 | { | |
| 389 | 0 | GlobusSoapMessageDebugExit(); |
| 390 | 0 | return GlobusSoapMessageErrorOutOfMemory; |
| 391 | } | |
| 392 | ||
| 393 | 0 | result = type_info->copy_contents(instance, src_obj); |
| 394 | 0 | if(result != GLOBUS_SUCCESS) |
| 395 | { | |
| 396 | 0 | free(instance); |
| 397 | 0 | GlobusSoapMessageDebugExit(); |
| 398 | 0 | return GlobusSoapMessageErrorOutOfMemory; |
| 399 | } | |
| 400 | ||
| 401 | 0 | exit: |
| 402 | 0 | *dest_obj = instance; |
| 403 | 0 | GlobusSoapMessageDebugExit(); |
| 404 | 0 | return result; |
| 405 | } | |
| 406 | /* globus_xsd_generic_copy() */ | |
| 407 | ||
| 408 | globus_result_t | |
| 409 | globus_xsd_generic_deserialize_pointer( | |
| 410 | const xsd_QName * element_qname, | |
| 411 | const globus_xsd_type_info_t type_info, | |
| 412 | void ** ip, | |
| 413 | globus_soap_message_handle_t message_handle, | |
| 414 | globus_xsd_element_options_t options) | |
| 415 | 2183419 | { |
| 416 | 2183419 | globus_result_t result = GLOBUS_SUCCESS; |
| 417 | GlobusFuncName(globus_xsd_generic_deserialize_pointer); | |
| 418 | 2183419 | GlobusSoapMessageDebugEnter(); |
| 419 | ||
| 420 | 2183419 | *ip = NULL; |
| 421 | ||
| 422 | 2183419 | if (!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 423 | { | |
| 424 | 2183413 | result = globus_soap_message_deserialize_element( |
| 425 | message_handle, element_qname); | |
| 426 | ||
| 427 | 2183413 | if(GlobusSoapMessageStatusElementNotFoundCheck(result) || |
| 428 | GlobusSoapMessageStatusFailedElementCheck(result) || | |
| 429 | GlobusSoapMessageStatusFailedWithTextCheck(result)) | |
| 430 | { | |
| 431 | 352 | result = GLOBUS_SUCCESS; |
| 432 | 352 | goto exit; |
| 433 | } | |
| 434 | ||
| 435 | 2183061 | if(result != GLOBUS_SUCCESS) |
| 436 | { | |
| 437 | 0 | goto error_exit; |
| 438 | } | |
| 439 | } | |
| 440 | ||
| 441 | 2183067 | if (!globus_soap_message_deserialize_element_is_nil(message_handle)) |
| 442 | { | |
| 443 | 2183043 | result = type_info->initialize(ip); |
| 444 | ||
| 445 | 2183043 | if(result != GLOBUS_SUCCESS) |
| 446 | { | |
| 447 | 0 | goto error_exit; |
| 448 | } | |
| 449 | ||
| 450 | 2183043 | result = type_info->contents_info->deserialize( |
| 451 | element_qname, ip, message_handle, options); | |
| 452 | 2183043 | if(result != GLOBUS_SUCCESS) |
| 453 | { | |
| 454 | 0 | goto error_exit; |
| 455 | } | |
| 456 | } | |
| 457 | ||
| 458 | 2183067 | if (!(options & GLOBUS_XSD_ELEMENT_CONTENTS_ONLY)) |
| 459 | { | |
| 460 | 2183061 | result = globus_soap_message_deserialize_element_end( |
| 461 | message_handle, | |
| 462 | element_qname); | |
| 463 | 2183061 | if(result != GLOBUS_SUCCESS) |
| 464 | { | |
| 465 | 0 | goto error_exit; |
| 466 | } | |
| 467 | ||
| 468 | } | |
| 469 | 2183067 | goto exit; |
| 470 | ||
| 471 | 0 | error_exit: |
| 472 | ||
| 473 | 0 | if(!GlobusSoapMessageStatusCheck(result)) |
| 474 | { | |
| 475 | 0 | result = GlobusSoapMessageErrorDeserializeFailed( |
| 476 | result, element_qname); | |
| 477 | } | |
| 478 | ||
| 479 | 2183419 | exit: |
| 480 | ||
| 481 | 2183419 | if(result != GLOBUS_SUCCESS && *ip) |
| 482 | { | |
| 483 | 0 | type_info->destroy(*ip); |
| 484 | 0 | *ip = NULL; |
| 485 | } | |
| 486 | ||
| 487 | 2183419 | GlobusSoapMessageDebugExit(); |
| 488 | 2183419 | return result; |
| 489 | } |