1 /*
2  * Portions of this file Copyright 1999-2005 University of Chicago
3  * Portions of this file Copyright 1999-2005 The University of Southern California.
4  *
5  * This file or a portion of this file is licensed under the
6  * terms of the Globus Toolkit Public License, found at
7  * http://www.globus.org/toolkit/download/license.html.
8  * If you redistribute this file, with or without
9  * modifications, you must include this notice in the file.
10  */
11
12
13 #include "globus_common.h"
14 #include "globus_i_soap_message.h"
15 #include "globus_soap_message.h"
16 #include "globus_soap_message_markers.h"
17 #include "globus_soap_message_handle.h"
18 #include "globus_soap_message_fault.h"
19 #include "globus_xml_buffer.h"
20 #include "openssl/evp.h"
21 #include "globus_xio_buffer.h"
22 #include "math.h"
23
24 #include "libxml/xmlschemastypes.h"
25
26 #ifdef __alpha /* Tru64 Unix does not define these */
27 #ifndef INT32_MIN
28 #define INT32_MIN INT_MIN
29 #endif
30 #ifndef INT32_MAX
31 #define INT32_MAX INT_MAX
32 #endif
33 #ifndef INT64_MIN
34 #define INT64_MIN LONG_MIN
35 #endif
36 #ifndef INT64_MAX
37 #define INT64_MAX LONG_MAX
38 #endif
39 #ifndef UINT32_MAX
40 #define UINT32_MAX UINT_MAX
41 #endif
42 #ifndef UINT64_MAX
43 #define UINT64_MAX ULONG_MAX
44 #endif
45 #endif /* __alpha */
46
47 #define XSI_NS "http://www.w3.org/2001/XMLSchema-instance"
48 #define XSI_NIL "nil"
49
50 static
51 char *
52 globus_l_soap_message_my_strtok(
53     const char *                        str,
54     size_t                              str_length,
55     int *                               token_start_index,
56     int *                               token_end_index,
57     const char *                        delims)
58 510648 {
59 510648     const char *                        locator;
60 510648     const char *                        start_token;
61 510648     int                                 delim_count, 
62 510648                                         ind, 
63 510648                                         i, 
64 510648                                         between_tokens, 
65 510648                                         len;
66 510648     char *                              new_token = NULL;
67 510648     ind = 0;
68 510648     i = 0;
69 510648     between_tokens = 0;
70 510648     delim_count = strlen(delims);
71 510648     locator = str;
72     
73 2042592     for(i = 0; i < delim_count; ++i)
74     {
75 1531944         if(*locator == delims[i])
76         {
77 44             between_tokens = 1;
78         }
79     }
80
81 511396     while(between_tokens && locator && ind < str_length)
82     {
83 2332         for(i = 0; i < delim_count; ++i)
84         {
85 2288             if(*locator == delims[i])
86             {
87 748                 break;
88             }
89         }
90
91 792         if(i == delim_count)
92         {
93 44             between_tokens = 0;
94 44             break;
95         }
96
97 748         locator++;
98 748         ind++;
99     }
100
101 510648     start_token = locator;
102 510648     if(token_start_index)
103     {
104 510648         *token_start_index = ind;
105     }
106
107 11341818     while(!between_tokens && *locator && ind < str_length)
108     {
109 43324548         for(i = 0; i < delim_count; ++i)
110         {
111 32493422             if(*locator == delims[i])
112             {
113 44                 if(token_end_index)
114                 {
115 44                     *token_end_index = ind;
116                 }
117 44                 between_tokens = 1;
118 44                 break;
119             }
120         }
121
122 10831170         locator++;
123 10831170         ind++;
124     }
125
126 510648     if(ind == str_length)
127     {
128 510604         *token_end_index = -1;
129     }
130     else
131     {
132 44         ind--;
133     }
134
135 510648     len = ind + (str - start_token);
136 510648     if(len > 0)
137     {
138 510648         new_token = malloc(len+1);
139 510648         memcpy(new_token, start_token, len + 1);
140 510648         new_token[len] = '\0';
141     }
142
143 510648     return new_token;
144 }
145
146 static
147 int
148 globus_i_soap_message_split_qnames(
149     const xmlChar *                     qname_string,
150     globus_list_t **                    qnames)
151 0 {
152 0     xmlChar *                           tmpstr;
153 0     xmlChar *                           newstr;
154 0     int                                 start_token;
155 0     int                                 end_token;
156 0     char *                              token;
157
158 0     newstr = globus_libc_strdup(qname_string);
159 0     tmpstr = newstr;
160 0     token = globus_l_soap_message_my_strtok(
161         tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
162 0     tmpstr += end_token;
163         
164 0     while(1)
165     {
166 0         globus_list_insert(qnames, token);
167 0         if(end_token < 0)
168         {
169 0             break;
170         }
171
172 0         token = globus_l_soap_message_my_strtok(
173             tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
174 0         tmpstr += end_token;
175 0         if(!token)
176         {
177 0             break;
178         }
179
180 0         globus_list_insert(qnames, token);
181     }
182
183 0     globus_free(newstr);
184 0     return 0;
185 }
186
187 void
188 globus_soap_message_deserialize_push_element(
189     globus_soap_message_handle_t        handle)
190 544594 {
191 544594     GlobusFuncName(globus_soap_message_deserialize_push_element);
192 544594     GlobusSoapMessageDebugEnter();
193
194 544594     handle->next_ready++;
195
196 544594     GlobusSoapMessageDebugExit();
197 }
198
199 globus_result_t
200 globus_i_soap_message_deserialize_read(
201     globus_soap_message_handle_t        handle)
202 0 {
203 0     globus_result_t                     result = GLOBUS_SUCCESS;
204 0     GlobusFuncName(globus_i_soap_message_deserialize_next_element);
205 0     GlobusSoapMessageDebugEnter();
206
207 0     if(xmlTextReaderNodeType(handle->reader) != XML_READER_TYPE_NONE &&
208        xmlTextReaderIsEmptyElement(handle->reader))
209     {
210 0         if(handle->next_ready > 0)
211         {
212 0             handle->next_ready--;
213         }
214         else
215         {
216 0             result = GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT;
217         }
218
219 0         goto exit;
220     }
221
222 0     if(handle->next_ready > 0)
223     {
224 0 handle->next_ready--;
225     }
226     else
227     {
228 0 if(xmlTextReaderRead(handle->reader) <= 0)
229 {
230 0     result = GlobusSoapMessageErrorFailedNextNode(handle->result);
231     goto exit;
232 }
233     }
234
235 exit:
236 0     GlobusSoapMessageDebugExit();
237 0     return result;
238 }
239     
240 globus_result_t
241 globus_i_soap_message_deserialize_next_element(
242     globus_soap_message_handle_t        handle)
243 1571716 {
244 1571716     globus_result_t                     result = GLOBUS_SUCCESS;
245 1571716     char *                              idval = NULL;
246 1571716     GlobusFuncName(globus_i_soap_message_deserialize_next_element);
247 1571716     xmlReaderTypes                      type = XML_READER_TYPE_NONE;
248     
249 1571716     GlobusSoapMessageDebugEnter();
250
251 1571716     if(xmlTextReaderNodeType(handle->reader) != type &&
252        xmlTextReaderIsEmptyElement(handle->reader))
253     {
254 397         if(handle->next_ready > 0)
255         {
256 379             handle->next_ready--;
257         }
258         else
259         {
260 18             result = GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT;
261         }
262
263 18         goto exit;
264     }
265
266 3124407     while(type != XML_READER_TYPE_ELEMENT)
267     {
268 1573393         if(handle->next_ready > 0)
269         {
270 531021             handle->next_ready--;
271         }
272         else
273         {
274 1042372     if(xmlTextReaderRead(handle->reader) <= 0)
275             {
276 0                 result = GlobusSoapMessageErrorFailedNextNode(handle->result);
277 0                 goto exit;
278             }
279         }
280         
281 1573393         type = xmlTextReaderNodeType(handle->reader);
282 1573393         if(type == XML_READER_TYPE_END_ELEMENT)
283         {
284 20303             result = GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT;
285 20303             goto exit;
286         }
287 1553090         else if(type == XML_READER_TYPE_TEXT)
288         {
289 2             xmlChar *                   str = NULL;
290 2             if (handle->verbose)
291             {
292 0                 str = xmlTextReaderValue(handle->reader);
293             }
294 2             result = GlobusSoapMessageErrorFailedWithText(handle->verbose, str);
295
296 2             if (str)
297             {
298 0                 xmlFree(str);
299             }
300
301 0             goto exit;
302         }
303     }
304
305 1551014     if(type == XML_READER_TYPE_ELEMENT)
306     {
307 1551014         if(handle->callout_table)
308         {
309 0             xsd_QName               qn;
310             
311 0             qn.local = (char *)
312             xmlTextReaderConstLocalName(handle->reader);
313 0             qn.Namespace = (char *)
314             xmlTextReaderConstNamespaceUri(handle->reader);
315             
316 0             result = globus_soap_message_invoke_callouts(
317                 handle, 
318                 &qn,
319                 GLOBUS_SOAP_MESSAGE_CALLOUT_BEGIN);
320 0             if(result != GLOBUS_SUCCESS)
321             {
322 0                 result = GlobusSoapMessageErrorFailedNextNode(result);
323 0                 goto exit;
324             }
325         }
326
327 1551014         if((idval = xmlTextReaderGetAttribute(
328                 handle->reader, 
329                 "Id")) != NULL)
330         {
331 0             result = globus_soap_message_deserialize_mark(
332                 handle,
333                 idval);
334 0             if(result != GLOBUS_SUCCESS)
335             {
336 0                 result = GlobusSoapMessageErrorSettingId(
337                     result);
338 0                 goto exit;
339             }
340 0     xmlFree(idval);
341         }
342     }
343
344  exit:
345
346 1571716     GlobusSoapMessageDebugExit();
347 1571716     return result;
348 }
349
350 globus_result_t
351 globus_soap_message_deserialize_element_end(
352     globus_soap_message_handle_t        handle,
353     xsd_QName *                         qname)
354 1027037 {
355 1027037     char *                              idval = NULL;
356 1027037     globus_result_t                     result = GLOBUS_SUCCESS;
357 1027037     xmlReaderTypes                      type = XML_READER_TYPE_NONE;
358 1027037     int                                 res = 0;
359 1027037     GlobusFuncName(globus_soap_message_deserialize_element_end);
360 1027037     GlobusSoapMessageDebugEnter();
361
362 1027037     if(xmlTextReaderIsEmptyElement(handle->reader))
363     {
364 379         if (qname)
365         {
366 379             xsd_QName                   tmp;
367 379             xmlChar *                   qname_ns;
368 379             xmlChar *                   qname_local;
369
370 379             tmp.Namespace = (char *)
371                     xmlTextReaderConstNamespaceUri(handle->reader);
372 379             tmp.local = (char *)
373                     xmlTextReaderConstLocalName(handle->reader);
374 379             qname_ns = xmlTextReaderConstString(handle->reader,
375                     qname->Namespace);
376 379             qname_local = xmlTextReaderConstString(handle->reader,
377                     qname->local);
378 379             if (qname_ns != tmp.Namespace || qname_local != tmp.local)
379             {
380 0                 result = GlobusSoapMessageErrorFailedEndElement(
381                         handle->verbose,
382                         &tmp);
383 0                 goto exit;
384             }
385         }
386 379         res = xmlTextReaderRead(handle->reader);
387 379         if(res < 0)
388         {
389 0             result = GlobusSoapMessageErrorFailedNextNode(handle->result);
390 0             goto exit;
391         }
392 379         handle->next_ready++;    
393
394 379         goto exit;
395     }
396
397 2053346     while(type != XML_READER_TYPE_END_ELEMENT)
398     {
399 1026688         if(handle->next_ready > 0)
400         {
401 11446             handle->next_ready--;
402         }
403         else
404         {
405 1015242     res = xmlTextReaderRead(handle->reader);
406 1015242             if(res < 0)
407             {
408 0                 result = GlobusSoapMessageErrorFailedNextNode(handle->result);
409 0                 goto exit;
410             }
411 1015242             else if(res == 0)
412             {
413 0                 goto exit;
414             }
415         }
416
417 1026688         type = xmlTextReaderNodeType(handle->reader);
418 1026688         if(type == XML_READER_TYPE_ELEMENT)
419         {
420 0             xsd_QName                   unexpected_qn;
421
422 0             if (handle->verbose)
423             {
424 0                 unexpected_qn.Namespace = (char *)
425                         xmlTextReaderConstNamespaceUri(handle->reader);
426 0                 unexpected_qn.local = (char *)
427                         xmlTextReaderConstLocalName(handle->reader);
428             }
429 0             result = GlobusSoapMessageErrorFailedEndElement(
430                     handle->verbose,
431                     &unexpected_qn);
432
433 0             goto exit;
434         }
435 1026688         else if (type == XML_READER_TYPE_TEXT)
436         {
437 0             xmlChar *                   str = NULL;
438 0             if (handle->verbose)
439             {
440 0                 str = xmlTextReaderValue(handle->reader);
441             }
442 0             result = GlobusSoapMessageErrorFailedWithText(handle->verbose, str);
443
444 0             goto exit;
445         }
446     }
447
448 1026658     if(type == XML_READER_TYPE_END_ELEMENT)
449     {
450 1026658         xsd_QName               qn;
451         
452 1026658         if(handle->callout_table)
453         {
454 0             qn.local = (char *)
455             xmlTextReaderConstLocalName(handle->reader);
456 0             qn.Namespace = (char *)
457             xmlTextReaderConstNamespaceUri(handle->reader);
458
459 0             result = globus_soap_message_invoke_callouts(
460                 handle,
461                 &qn,
462                 GLOBUS_SOAP_MESSAGE_CALLOUT_END);
463         }
464                     
465 1026658         if((idval = xmlTextReaderGetAttribute(
466                 handle->reader, 
467                 "Id")) != NULL)
468         {
469 0             char * end_idval = 
470 0             globus_common_create_string("%s-end", idval);
471
472 0     if(handle->next_ready == 0)
473     {
474 0 result = globus_i_soap_message_deserialize_read(handle);
475 0 if(result != GLOBUS_SUCCESS &&
476    !GlobusSoapMessageStatusFailedElementCheck(result))
477 {
478 0     result = GLOBUS_SUCCESS;
479 0     goto exit;
480 }
481
482 0 globus_soap_message_deserialize_push_element(handle);
483     }
484
485 0     result = globus_soap_message_deserialize_mark(
486                 handle, end_idval);
487 0             if(result != GLOBUS_SUCCESS)
488             {
489 0                 result = GlobusSoapMessageErrorSettingId(
490                     result);
491 0                 goto exit;
492             }
493 0     xmlFree(idval);
494 0             globus_free(end_idval);
495         }
496     }
497
498  exit:
499
500 1027037     GlobusSoapMessageDebugExit();
501 1027037     return result;
502 }
503
504 globus_result_t
505 globus_soap_message_deserialize_skip(
506     globus_soap_message_handle_t        handle)
507 0 {
508 0     globus_result_t                     result = GLOBUS_SUCCESS;
509 0     GlobusFuncName(globus_soap_message_deserialize_skip);
510 0     GlobusSoapMessageDebugEnter();
511
512 0     if(xmlTextReaderSkip(handle->reader, handle->next_ready) <= 0)
513     {
514 0         result = GlobusSoapMessageErrorFailedNextNode(handle->result);
515 0         goto exit;
516     }
517
518 0     if(!handle->next_ready)
519     {
520 0         handle->next_ready++;
521     }
522
523  exit:
524
525 0     GlobusSoapMessageDebugExit();
526 0     return result;
527 }
528
529 globus_result_t
530 globus_i_soap_message_deserialize_next_content(
531     globus_soap_message_handle_t             handle)
532 1006778 {
533 1006778     globus_result_t                     result = GLOBUS_SUCCESS;
534 1006778     xmlReaderTypes                      type = XML_READER_TYPE_NONE;
535 1006778     GlobusFuncName(globus_i_soap_message_deserialize_next_content);
536 1006778     GlobusSoapMessageDebugEnter();
537
538 1006778     if(xmlTextReaderIsEmptyElement(handle->reader))
539     {
540 0         goto exit;
541     }
542
543 2013556     while(type != XML_READER_TYPE_TEXT)
544     {
545 1006778         if(handle->next_ready > 0)
546         {
547 0             handle->next_ready--;
548         }
549 1006778         else if(xmlTextReaderRead(handle->reader) <= 0)
550         {
551 0             result = GlobusSoapMessageErrorFailedNextNode(handle->result);
552 0             goto exit;
553         }
554
555 1006778         type = xmlTextReaderNodeType(handle->reader);
556 1006778         if(type == XML_READER_TYPE_END_ELEMENT)
557         {
558             /* no content in between nodes */
559 0             globus_soap_message_deserialize_push_element(handle);
560 0             goto exit;
561         }
562
563 1006778         if(type != XML_READER_TYPE_TEXT &&
564            type != XML_READER_TYPE_ATTRIBUTE)
565         {
566 0             result = GlobusSoapMessageErrorFailedContent();
567             goto exit;
568         }
569     }
570
571  exit:
572
573 1006778     GlobusSoapMessageDebugExit();
574 1006778     return result;
575 }
576         
577 globus_result_t
578 globus_i_soap_message_deserialize_next_attribute(
579     globus_soap_message_handle_t        handle)
580 0 {
581 0     globus_result_t                     result = GLOBUS_SUCCESS;
582 0     xmlReaderTypes                      type = XML_READER_TYPE_NONE;
583 0     GlobusFuncName(globus_i_soap_message_deserialize_next_attribute);
584 0     GlobusSoapMessageDebugEnter();
585
586 0     if(xmlTextReaderRead(handle->reader) <= 0)
587     {
588 0         result = GlobusSoapMessageErrorFailedNextNode(handle->result);
589 0         goto exit;
590     }
591
592 0     type = xmlTextReaderNodeType(handle->reader);
593 0     if(type != XML_READER_TYPE_ATTRIBUTE)
594     {
595 0         result = GlobusSoapMessageErrorFailedAttribute();
596         goto exit;
597     }
598
599  exit:
600
601 0     GlobusSoapMessageDebugExit();
602 0     return result;
603 }
604
605 globus_result_t
606 globus_soap_message_deserialize_envelope(
607     globus_soap_message_handle_t        handle)
608 4247 {
609 4247     xsd_QName                           local_qn;
610 4247     const xmlChar *                     local;
611 4247     const xmlChar *                     soap_env;
612 4247     globus_result_t                     result = GLOBUS_SUCCESS;
613
614 4247     GlobusFuncName(globus_soap_message_deserialize_envelope);
615 4247     GlobusSoapMessageDebugEnter();
616
617 4247     result = globus_soap_message_set_marker(
618 handle,
619 GLOBUS_SOAP_MESSAGE_MARKER_ENVELOPE);
620 4247     if(result != GLOBUS_SUCCESS)
621     {
622 0 result = GlobusSoapMessageErrorDeserializeFailed(
623     result, &soap_env_qname);
624 0 goto exit;
625     }
626     
627 4247     result = globus_i_soap_message_deserialize_next_element(handle);
628 4247     if(result != GLOBUS_SUCCESS)
629     {
630 0         result = GlobusSoapMessageErrorDeserializeFailed(
631             result, &soap_env_qname);
632 0         goto exit;
633     }
634
635 4247     soap_env = xmlTextReaderConstString(handle->reader, SOAP_ENV);
636 4247     local = xmlTextReaderConstLocalName(handle->reader);
637 4247     if(soap_env != local)
638     {
639 0         if (handle->verbose)
640         {
641 0             local_qn.Namespace = (char *)
642                 xmlTextReaderConstNamespaceUri(handle->reader);
643 0             local_qn.local = (char *) local;
644         }
645 0         result = GlobusSoapMessageErrorElementNotFound(
646                 handle->verbose,
647                 &soap_env_qname,
648                 &local_qn);
649         goto exit;
650     }
651
652  exit:
653
654 4247     GlobusSoapMessageDebugExit();
655 4247     return result;
656 }
657
658 globus_result_t
659 globus_soap_message_deserialize_envelope_end(
660     globus_soap_message_handle_t        handle)
661 4246 {
662 4246     globus_result_t                     result = GLOBUS_SUCCESS;
663 4246     GlobusFuncName(globus_soap_message_deserialize_envelope_end);
664 4246     GlobusSoapMessageDebugEnter();
665
666 4246     result = globus_soap_message_deserialize_element_end(
667             handle,
668             &soap_env_qname);
669 4246     if(result != GLOBUS_SUCCESS)
670     {
671 0         result = GlobusSoapMessageErrorDeserializeFailed(
672             result, &soap_env_qname);
673 0         goto exit;
674     }
675
676 4246     result = globus_xio_handle_cntl(
677 handle->xio_handle, globus_i_soap_message_buffer_driver,
678 GLOBUS_XIO_BUFFER_SET_READ_MARKER_AT_INDEX,
679 GLOBUS_SOAP_MESSAGE_MARKER_ENVELOPE_END,
680 xmlTextReaderReadPosition(handle->reader));
681 4246     if(result != GLOBUS_SUCCESS)
682     {
683 0 result = GlobusSoapMessageErrorWithMarker(
684     result, "Failed to set read marker: %s", 
685     GLOBUS_SOAP_MESSAGE_MARKER_ENVELOPE_END);
686 goto exit;
687     }
688    
689  exit:
690
691 4246     GlobusSoapMessageDebugExit();
692 4246     return result;
693 }
694     
695 globus_result_t
696 globus_soap_message_deserialize_header(
697     globus_soap_message_handle_t        handle)
698 4247 {
699 4247     const xmlChar *                     local;
700 4247     const xmlChar *                     soap_header;
701 4247     globus_result_t                     result = GLOBUS_SUCCESS;
702
703 4247     GlobusFuncName(globus_soap_message_deserialize_header);
704 4247     GlobusSoapMessageDebugEnter();
705
706 4247     result = globus_i_soap_message_deserialize_next_element(handle);
707 4247     if(result != GLOBUS_SUCCESS)
708     {
709 0         result = GlobusSoapMessageErrorDeserializeFailed(
710             result, &soap_header_qname);
711 0         goto exit;
712     }
713     
714 4247     soap_header = xmlTextReaderConstString(handle->reader, SOAP_HEADER);
715 4247     local = xmlTextReaderConstLocalName(handle->reader);
716 4247     if(soap_header != local)
717     {
718 0         result = GlobusSoapMessageErrorDeserializeFailed(
719             GLOBUS_SUCCESS, &soap_header_qname);
720         goto exit;
721     }
722
723  exit:
724     
725 4247     GlobusSoapMessageDebugExit();
726 4247     return result;
727 }
728
729 globus_result_t
730 globus_soap_message_deserialize_header_end(
731     globus_soap_message_handle_t        handle)
732 4247 {
733 4247     globus_result_t                     result = GLOBUS_SUCCESS;
734 4247     GlobusFuncName(globus_soap_message_deserialize_header_end);
735 4247     GlobusSoapMessageDebugEnter();
736
737 4247     result = globus_soap_message_deserialize_element_end(
738             handle,
739             &soap_header_qname);
740 4247     if(result != GLOBUS_SUCCESS)
741     {
742 0         GlobusSoapMessageErrorDeserializeFailed(
743             result, &soap_header_qname);
744 4247         goto exit;
745     }
746
747  exit:
748
749 4247     GlobusSoapMessageDebugExit();
750 4247     return result;
751 }
752
753 globus_result_t
754 globus_soap_message_add_required_header_element(
755     globus_soap_message_handle_t        handle,
756     const xsd_QName *                   qn)
757 0 {
758 0     globus_result_t                     result = GLOBUS_SUCCESS;
759 0     xsd_QName *                         value;
760 0     GlobusFuncName(globus_soap_message_add_required_header_element);
761 0     GlobusSoapMessageDebugEnter();
762
763 0     if(!handle->mustUnderstand_hash)
764     {
765 0         globus_hashtable_init(
766             &handle->mustUnderstand_hash,
767             10,
768             xsd_QName_hash,
769             xsd_QName_keyeq);
770     }
771
772 0     xsd_QName_copy(&value, qn);
773
774 0     globus_hashtable_insert(
775         &handle->mustUnderstand_hash,
776         value, value);
777
778 0     GlobusSoapMessageDebugExit();
779 0     return result;
780 }
781
782 globus_result_t
783 globus_soap_message_remove_required_header_element(
784     globus_soap_message_handle_t        handle,
785     const xsd_QName *                   qn)
786 8492 {
787 8492     xsd_QName *                         entry;
788 8492     if(handle->mustUnderstand_hash)
789     {
790 0         entry = globus_hashtable_remove(
791             &handle->mustUnderstand_hash, (void *)qn);
792 0 xsd_QName_destroy(entry);
793     }
794 8492     return GLOBUS_SUCCESS;
795 }
796
797 globus_result_t
798 globus_soap_message_check_required_headers(
799     globus_soap_message_handle_t        handle)
800 4178 {
801 4178     if(!handle->mustUnderstand_hash)
802     {
803 4178         return GLOBUS_SUCCESS;
804     }
805
806 0     if(globus_hashtable_empty(&handle->mustUnderstand_hash))
807     {
808 0         return GLOBUS_SUCCESS;
809     }
810     else
811     {
812 0         xsd_QName *                     element;
813 0         globus_result_t                 result = GLOBUS_SUCCESS;
814
815 0         element = globus_hashtable_first(&handle->mustUnderstand_hash);
816
817 0         while(element)
818         {
819 0             result = GlobusSoapMessageErrorMustUnderstand(
820                 result, element);
821 0             element = globus_hashtable_next(&handle->mustUnderstand_hash);
822         }
823         
824 0         return result;
825     }
826 }
827
828 globus_result_t
829 globus_soap_message_deserialize_body(
830     globus_soap_message_handle_t        handle)
831 4247 {
832 4247     const xmlChar *                     local;
833 4247     const xmlChar *                     soap_body;
834 4247     xsd_QName                           local_qn;
835 4247     globus_result_t                     result = GLOBUS_SUCCESS;
836
837 4247     GlobusFuncName(globus_soap_message_deserialize_body);
838 4247     GlobusSoapMessageDebugEnter();
839
840 4247     result = globus_i_soap_message_deserialize_next_element(handle);
841 4247     if(result != GLOBUS_SUCCESS)
842     {
843 0         result = GlobusSoapMessageErrorDeserializeFailed(
844             result, &soap_body_qname);
845 0         goto exit;
846     }
847
848 4247     soap_body = xmlTextReaderConstString(handle->reader, SOAP_BODY);
849 4247     local = xmlTextReaderConstLocalName(handle->reader);
850 4247     if(soap_body != local)
851     {
852 0         if (handle->verbose)
853         {
854 0             local_qn.Namespace = (char *)
855                 xmlTextReaderNamespaceUri(handle->reader);
856 0             local_qn.local = (char *) local;
857         }
858
859 0         result = GlobusSoapMessageErrorElementNotFound(
860                     handle->verbose,
861                     &soap_body_qname,
862                     &local_qn);
863         goto exit;
864     }
865         
866  exit:
867     
868 4247     GlobusSoapMessageDebugExit();
869 4247     return result;
870 }
871
872 globus_result_t
873 globus_soap_message_deserialize_fault(
874     globus_soap_message_handle_t        handle,
875     globus_soap_message_fault_t *       soap_fault_handle,
876     globus_soap_fault_callback_func_t   fault_callback,
877     xsd_any **                          fault_any,
878     void *                              user_data)
879 2124 {
880 2124     const xmlChar *                     local;
881 2124     const xmlChar *                     soap_fault;
882 2124     const xmlChar *                     element_name;
883 2124     const xmlChar *                     faultcode_name;
884 2124     const xmlChar *                     faultstring_name;
885 2124     const xmlChar *                     faultactor_name;
886 2124     const xmlChar *                     detail_name;
887 2124     globus_xml_buffer *                 detail_buffer;
888 2124     globus_result_t                     result = GLOBUS_SUCCESS;
889 2124     globus_soap_message_fault_t         fault = NULL;
890
891 2124     GlobusFuncName(globus_soap_message_deserialize_fault);
892 2124     GlobusSoapMessageDebugEnter();
893
894 2124     result = globus_i_soap_message_deserialize_next_element(handle);
895 2124     if(result != GLOBUS_SUCCESS)
896     {
897 0         result = GlobusSoapMessageErrorDeserializeFailed(
898             result, &soap_fault_qname);
899 0         goto exit;
900     }
901
902 2124     soap_fault = xmlTextReaderConstString(handle->reader, SOAP_FAULT);
903 2124     local = xmlTextReaderConstLocalName(handle->reader);
904 2124     if(soap_fault != local)
905     {
906 2055         globus_soap_message_deserialize_push_element(handle);
907 2055         goto exit;
908     }
909
910 69     globus_soap_message_fault_init(&fault);
911
912 69     faultcode_name = xmlTextReaderConstString(
913         handle->reader, SOAP_FAULTCODE);
914 69     faultactor_name = xmlTextReaderConstString(
915         handle->reader, SOAP_FAULTACTOR);
916 69     faultstring_name = xmlTextReaderConstString(
917         handle->reader, SOAP_FAULTSTRING);
918 69     detail_name = xmlTextReaderConstString(
919         handle->reader, SOAP_FAULT_DETAIL);
920
921 207     while(result == GLOBUS_SUCCESS)
922     {
923 207         result = globus_i_soap_message_deserialize_next_element(handle);
924 207         if(result != GLOBUS_SUCCESS)
925         {
926 4             if(GlobusSoapMessageStatusFailedElementCheck(result) ||
927                GlobusSoapMessageStatusFailedWithTextCheck(result))
928             {
929 4                 globus_soap_message_deserialize_push_element(handle);
930 4                 result = GLOBUS_SUCCESS;
931 4                 break;
932             }
933         
934 0             result = GlobusSoapMessageErrorDeserializeFailed(
935                 result, &soap_fault_qname);
936 0             goto exit;
937         }
938
939 203         element_name = xmlTextReaderConstLocalName(handle->reader);
940 203         if(element_name == faultcode_name)
941         {
942 69             result = globus_i_soap_message_deserialize_next_content(handle);
943 69             if(result != GLOBUS_SUCCESS)
944             {
945 0                 result = GlobusSoapMessageErrorDeserializeFailed(
946                     result, &soap_fault_qname);
947 0                 goto exit;
948             }
949
950 69             fault->faultcode = 
951             xmlTextReaderValue(handle->reader);
952         }
953 134         else if(element_name == faultstring_name)
954         {
955 69             result = globus_i_soap_message_deserialize_next_content(handle);
956 69             if(result != GLOBUS_SUCCESS)
957             {
958 0                 result = GlobusSoapMessageErrorDeserializeFailed(
959                     result, &soap_faultstring_qname);
960 0                 goto exit;
961             }
962
963 69             fault->faultstring = 
964             xmlTextReaderValue(handle->reader);
965         }
966 65         else if(element_name == faultactor_name)
967         {
968 0             result = globus_i_soap_message_deserialize_next_content(handle);
969 0             if(result != GLOBUS_SUCCESS)
970             {
971 0                 result = GlobusSoapMessageErrorDeserializeFailed(
972                     result, &soap_fault_qname);
973 0                 goto exit;
974             }
975
976 0             fault->faultactor = 
977             xmlTextReaderValue(handle->reader);
978         }
979 65         else if(element_name == detail_name)
980         {
981 65             xsd_any *                   dummy_any = NULL;
982 65             xsd_QName                   fault_qname;
983
984 65             result = globus_soap_message_deserialize_element_unknown(
985                 handle, &fault_qname);
986 65             if(result != GLOBUS_SUCCESS)
987             {
988 0                 result = GlobusSoapMessageErrorDeserializeFailed(
989                     result, &soap_fault_detail_qname);
990 0                 goto exit;
991             }
992
993 65             globus_soap_message_deserialize_push_element(handle);
994
995 65             globus_soap_message_set_marker(handle, "FAULT_DETAIL_BEGIN");
996
997 65             xsd_any_init(fault_any);
998
999 65             result = xsd_any_deserialize(
1000                 NULL, (*fault_any), handle, 0);
1001 65             if(result != GLOBUS_SUCCESS)
1002             {
1003 0                 result = GlobusSoapMessageErrorDeserializeFailed(
1004                     result, &soap_fault_detail_qname);
1005 0                 goto exit;
1006             }
1007             
1008 65             globus_soap_message_set_marker(handle, "FAULT_DETAIL_END");
1009
1010 65             xsd_any_init(&fault->detail);
1011 65             fault->detail->any_info = (&globus_xml_buffer_contents_info);
1012
1013 65             globus_xml_buffer_init(&detail_buffer);
1014 65             result = globus_soap_message_get_marked_buffers(
1015                 handle, 
1016                 "FAULT_DETAIL_BEGIN",
1017                 "FAULT_DETAIL_END",
1018                 &detail_buffer->buffer,
1019                 (size_t *)&detail_buffer->length);
1020 65             if(result != GLOBUS_SUCCESS)
1021             {
1022 0                 globus_xml_buffer_destroy(detail_buffer);
1023 0                 result = GlobusSoapMessageErrorDeserializeFailed(
1024                     result, &soap_fault_detail_qname);
1025 0                 goto exit;
1026             }
1027             
1028 65             fault->detail->value = detail_buffer;
1029
1030 65             fault_callback(handle, 
1031                            (*fault_any)->any_info->type, 
1032                            user_data, 
1033                            NULL);
1034
1035 65             do
1036             {
1037 65                 result = xsd_any_deserialize_pointer(
1038                     NULL, &dummy_any, handle, 0);
1039 65                 if(result != GLOBUS_SUCCESS)
1040                 {
1041 65                     if(GlobusSoapMessageStatusFailedElementCheck(result))
1042                     {
1043 65                         result = GLOBUS_SUCCESS;
1044 65                         goto exit;
1045                     }
1046
1047 0                     result = GlobusSoapMessageErrorDeserializeFailed(
1048                         result, &soap_fault_detail_qname);
1049 0                     goto exit;
1050                 }
1051 0                 xsd_any_destroy(dummy_any);
1052 0                 dummy_any = NULL;
1053
1054 0             } while(result == GLOBUS_SUCCESS);
1055
1056 0             break;
1057         }
1058         else
1059         {
1060 0             result = GlobusSoapMessageErrorUnexpectedElement(
1061                 &soap_fault_qname);
1062 0             goto exit;
1063         }
1064
1065 138         result = globus_soap_message_deserialize_element_end(
1066                 handle,
1067                 &soap_fault_qname);
1068 138         if(result != GLOBUS_SUCCESS)
1069         {
1070 0             result = GlobusSoapMessageErrorDeserializeFailed(
1071                 result, &soap_fault_qname);
1072             goto exit;
1073         }        
1074     }
1075     
1076  exit:
1077     
1078 2124     *soap_fault_handle = fault;
1079
1080 2124     GlobusSoapMessageDebugExit();
1081 2124     return result;
1082 }
1083
1084 globus_bool_t
1085 globus_soap_message_deserialize_element_is_nil(
1086     globus_soap_message_handle_t        handle)
1087 2834 {
1088 2834     xmlChar *                           nil_value;
1089 2834     GlobusFuncName(globus_soap_message_deserialize_element_is_nil);
1090 2834     GlobusSoapMessageDebugEnter();
1091
1092 2834     nil_value = xmlTextReaderGetAttributeNs(
1093         handle->reader, 
1094         XSI_NIL,
1095         XSI_NS);
1096 2834     if(nil_value && !(xmlStrcmp(nil_value, "true")))
1097     {
1098 0         xmlFree(nil_value);
1099 0         return GLOBUS_TRUE;
1100     }
1101     
1102 2834     if(!nil_value)
1103     {
1104 2834         xmlFree(nil_value);
1105     }
1106
1107 2834     return GLOBUS_FALSE;
1108 }    
1109         
1110 globus_result_t
1111 globus_soap_message_deserialize_element_unknown(
1112     globus_soap_message_handle_t        handle,
1113     xsd_QName  *                        qname)
1114 26431 {
1115 26431     globus_result_t                     result = GLOBUS_SUCCESS;
1116
1117 26431     GlobusFuncName(globus_soap_message_deserialize_element);
1118 26431     GlobusSoapMessageDebugEnter();
1119
1120 26431     result = globus_i_soap_message_deserialize_next_element(handle);
1121 26431     if(result != GLOBUS_SUCCESS)
1122     {
1123 4502         xsd_QName *                     q = NULL;
1124
1125 4502         if(GlobusSoapMessageStatusFailedElementCheck(result) ||
1126            GlobusSoapMessageStatusFailedWithTextCheck(result))
1127         {
1128 4502             globus_soap_message_deserialize_push_element(handle);
1129 4502             goto exit;
1130         }
1131         else
1132         {
1133 0             result = GlobusSoapMessageErrorDeserializeFailed(
1134                 result, q);
1135         }
1136 0         goto exit;
1137     }
1138
1139 21929     qname->local = xmlTextReaderLocalName(handle->reader);
1140 21929     qname->Namespace = xmlTextReaderNamespaceUri(handle->reader);
1141
1142  exit:
1143
1144 26431     GlobusSoapMessageDebugExit();
1145 26431     return result;
1146 }
1147
1148 globus_bool_t
1149 globus_soap_message_deserialize_element_is_empty(
1150     globus_soap_message_handle_t        handle)
1151 2155 {
1152 2155     return ((handle->next_ready == 0) &&
1153             xmlTextReaderIsEmptyElement(handle->reader));
1154 }
1155
1156 globus_result_t
1157 globus_soap_message_deserialize_element(
1158     globus_soap_message_handle_t        handle,
1159     const xsd_QName *                   qname)
1160 1525836 {
1161 1525836     const xmlChar *                     local;
1162 1525836     const xmlChar *                     local_ns;
1163 1525836     const xmlChar *                     element;
1164 1525836     const xmlChar *                     element_ns;
1165 1525836     xsd_QName                           local_qn;
1166 1525836     globus_result_t                     result = GLOBUS_SUCCESS;
1167
1168 1525836     GlobusFuncName(globus_soap_message_deserialize_element);
1169 1525836     GlobusSoapMessageDebugEnter();
1170
1171 1525836     result = globus_i_soap_message_deserialize_next_element(handle);
1172 1525836     if(result != GLOBUS_SUCCESS)
1173     {
1174 15752         if(GlobusSoapMessageStatusFailedElementCheck(result) ||
1175            GlobusSoapMessageStatusFailedWithTextCheck(result))
1176         {
1177 15752             if (!xmlTextReaderIsEmptyElement(handle->reader))
1178             {
1179 15734                 globus_soap_message_deserialize_push_element(handle);
1180             }
1181
1182 15734             goto exit;
1183         }
1184         else
1185         {
1186 0             result = GlobusSoapMessageErrorDeserializeFailed(
1187                 result, qname);
1188         }
1189 0         goto exit;
1190     }
1191
1192 1510084     if(qname)
1193     {
1194 1012039         element = xmlTextReaderConstString(handle->reader, qname->local);
1195 1012039         local = xmlTextReaderConstString(
1196             handle->reader, xmlTextReaderConstLocalName(handle->reader));
1197 1012039         if(element != local)
1198         {
1199 22             if (handle->verbose)
1200             {
1201 0                 local_qn.Namespace = (char *) xmlTextReaderConstString(
1202                         handle->reader,
1203                         xmlTextReaderConstNamespaceUri(handle->reader));
1204 0                 local_qn.local = (char *) local;
1205             }
1206 22             globus_soap_message_deserialize_push_element(handle);
1207
1208 22             result = GlobusSoapMessageErrorElementNotFound(
1209                     handle->verbose,
1210                     qname,
1211                     &local_qn);
1212 22             goto exit;
1213         }
1214         
1215 1012017         element_ns = xmlTextReaderConstString(
1216             handle->reader, qname->Namespace);
1217 1012017         local_ns = xmlTextReaderConstString(
1218             handle->reader, xmlTextReaderConstNamespaceUri(handle->reader));
1219 1012017         if(local_ns && element_ns != local_ns)
1220         {
1221 0             if (handle->verbose)
1222             {
1223 0                 local_qn.Namespace = (char *) local_ns;
1224 0                 local_qn.local = (char *) local;
1225             }
1226 0             result = GlobusSoapMessageErrorElementNotFound(
1227                     handle->verbose,
1228                     qname,
1229                     &local_qn);
1230             goto exit;
1231         }
1232     }
1233
1234  exit:
1235
1236 1525836     GlobusSoapMessageDebugExit();
1237 1525836     return result;
1238 }
1239
1240 globus_result_t
1241 globus_soap_message_deserialize_anyURI(
1242     globus_soap_message_handle_t        handle,
1243     xsd_anyURI *                        str)
1244 17035 {
1245 17035     const xmlChar *                     constval;
1246 17035     globus_result_t                     result = GLOBUS_SUCCESS;
1247 17035     int                                 start_token, end_token;
1248 17035     GlobusFuncName(globus_soap_message_deserialize_anyURI);
1249 17035     GlobusSoapMessageDebugEnter();
1250
1251 17035     result = globus_i_soap_message_deserialize_next_content(handle);
1252 17035     if(result != GLOBUS_SUCCESS)
1253     {
1254 0         result = GlobusSoapMessageErrorDeserializeFailed(
1255             result, &xsd_string_qname);
1256 0         goto exit;
1257     }
1258
1259 17035     constval = xmlTextReaderConstValue(handle->reader);
1260 17035     if(constval)
1261     {
1262 17035 *str = globus_l_soap_message_my_strtok(
1263     constval, strlen(constval), &start_token, &end_token, "\n\t ");
1264 17035 if (*str == NULL)
1265 {
1266 0     result = GlobusSoapMessageErrorDeserializeFailed(
1267 result, &xsd_anyURI_qname);
1268 0     goto exit;
1269 }
1270     }
1271     else
1272     {
1273 0 *str = NULL;
1274     }
1275     
1276  exit:
1277     
1278 17035     GlobusSoapMessageDebugExit();
1279 17035     return result;
1280 }
1281
1282 globus_result_t
1283 globus_soap_message_deserialize_string(
1284     globus_soap_message_handle_t        handle,
1285     xsd_string *                        str)
1286 2528 {
1287 2528     globus_result_t                     result = GLOBUS_SUCCESS;
1288 2528     GlobusFuncName(globus_soap_message_deserialize_string);
1289 2528     GlobusSoapMessageDebugEnter();
1290
1291 2528     result = globus_i_soap_message_deserialize_next_content(handle);
1292 2528     if(result != GLOBUS_SUCCESS)
1293     {
1294 0         result = GlobusSoapMessageErrorDeserializeFailed(
1295             result, &xsd_string_qname);
1296 0         goto exit;
1297     }
1298
1299 2528     *str = (xsd_string) xmlTextReaderValue(handle->reader);
1300     
1301  exit:
1302     
1303 2528     GlobusSoapMessageDebugExit();
1304 2528     return result;
1305 }
1306
1307 globus_result_t
1308 globus_soap_message_deserialize_string_attribute(
1309     globus_soap_message_handle_t        handle,
1310     const xsd_QName *                   attr_name,
1311     xsd_string *                        str)
1312 214 {
1313 214     const xmlChar *                     attr_ns;
1314 214     const xmlChar *                     local_ns;
1315 214     globus_result_t                     result = GLOBUS_SUCCESS;
1316 214     GlobusFuncName(globus_soap_message_deserialize_string_attribute);
1317 214     GlobusSoapMessageDebugEnter();
1318
1319 214     attr_ns = xmlTextReaderConstString(
1320         handle->reader, attr_name->Namespace);
1321 214     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1322
1323 214     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1324     {
1325 0         *str = xmlTextReaderGetAttributeNs(
1326             handle->reader, attr_name->local, attr_name->Namespace);
1327     }
1328     else
1329     {
1330 214         *str = xmlTextReaderGetAttribute(
1331             handle->reader, attr_name->local);
1332     }
1333 214     if(!*str)
1334     {
1335 0         result = GlobusSoapMessageErrorAttributeNotFound(
1336                 handle->verbose,
1337                 attr_name);
1338         goto exit;
1339     }
1340     
1341  exit:
1342     
1343 214     GlobusSoapMessageDebugExit();
1344 214     return result;
1345 }
1346
1347
1348 globus_result_t
1349 globus_soap_message_deserialize_string_list(
1350     globus_soap_message_handle_t        handle,
1351     xsd_string_array *                  inst)
1352 0 {
1353 0     const xmlChar *                     tmp_value = NULL;
1354 0     char *                              newstr;
1355 0     char *                              tmpstr;
1356 0     char *                              token;
1357 0     int                                 start_token, end_token;
1358 0     xsd_string *                        new_element = NULL;
1359 0     globus_result_t                     result = GLOBUS_SUCCESS;
1360 0     GlobusFuncName(globus_soap_message_deserialize_string_list);
1361 0     GlobusSoapMessageDebugEnter();
1362
1363 0     result = globus_i_soap_message_deserialize_next_content(handle);
1364 0     if(result != GLOBUS_SUCCESS)
1365     {
1366 0         result = GlobusSoapMessageErrorDeserializeFailed(
1367             result, &xsd_QName_qname);
1368 0         goto exit;
1369     }
1370     
1371 0     tmp_value = xmlTextReaderConstValue(handle->reader);
1372 0     if(!tmp_value)
1373     {
1374 0         result = GlobusSoapMessageErrorDeserializeFailed(
1375             result, &xsd_QName_qname);
1376 0         goto exit;
1377     }
1378
1379 0     newstr = globus_libc_strdup(tmp_value);
1380 0     tmpstr = newstr;
1381 0     token = globus_l_soap_message_my_strtok(
1382         tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
1383 0     tmpstr += end_token;
1384         
1385 0     while(token)
1386     {
1387 0         new_element = xsd_string_array_push(inst);
1388 0         *new_element = token;
1389
1390 0         if(end_token < 0)
1391         {
1392 0             break;
1393         }
1394
1395 0         token = globus_l_soap_message_my_strtok(
1396             tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
1397 0         tmpstr += end_token;
1398     }
1399
1400 0     globus_free(newstr);
1401
1402  exit:
1403
1404 0     GlobusSoapMessageDebugExit();
1405 0     return result;
1406 }
1407
1408 globus_result_t
1409 globus_soap_message_deserialize_string_attribute_list(
1410     globus_soap_message_handle_t        handle,
1411     const xsd_QName *                   attr_qname,
1412     xsd_string_array *                  inst)
1413 0 {
1414 0     const xmlChar *                     attr_ns = NULL;
1415 0     const xmlChar *                     local_ns = NULL;
1416 0     xmlChar *                           tmp_value = NULL;
1417 0     char *                              newstr;
1418 0     char *                              tmpstr;
1419 0     char *                              token;
1420 0     int                                 start_token, end_token;
1421 0     xsd_string *                        new_element = NULL;
1422 0     globus_result_t                     result = GLOBUS_SUCCESS;
1423 0     GlobusFuncName(globus_soap_message_deserialize_string_attribute_list);
1424 0     GlobusSoapMessageDebugEnter();
1425
1426 0     attr_ns = xmlTextReaderConstString(
1427         handle->reader, attr_qname->Namespace);
1428 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1429
1430 0     if(attr_ns != local_ns  && (attr_ns != NULL) && (*attr_ns != '\0'))
1431     {
1432 0         tmp_value = xmlTextReaderGetAttributeNs(
1433             handle->reader, attr_qname->local, attr_qname->Namespace);
1434     }
1435     else
1436     {
1437 0         tmp_value = xmlTextReaderGetAttribute(
1438             handle->reader, attr_qname->local);
1439     }
1440
1441 0     if(!tmp_value)
1442     {
1443 0         goto exit;
1444     }
1445
1446 0     if(!(*tmp_value))
1447     {
1448 0         result = GlobusSoapMessageErrorDeserializeFailed(
1449             result, &xsd_string_qname);
1450 0         goto exit;
1451     }
1452
1453 0     newstr = globus_libc_strdup(tmp_value);
1454 0     tmpstr = newstr;
1455 0     token = globus_l_soap_message_my_strtok(
1456         tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
1457 0     tmpstr += end_token;
1458         
1459 0     while(token)
1460     {
1461 0         new_element = xsd_string_array_push(inst);
1462 0         *new_element = token;
1463
1464 0         if(end_token < 0)
1465         {
1466 0             break;
1467         }
1468
1469 0         token = globus_l_soap_message_my_strtok(
1470             tmpstr, strlen(tmpstr), &start_token, &end_token, "\n\t ");
1471 0         tmpstr += end_token;
1472     }
1473
1474 0     globus_free(newstr);
1475
1476  exit:
1477
1478 0     if(tmp_value)
1479     {
1480 0 xmlFree(tmp_value);
1481     }
1482     
1483 0     GlobusSoapMessageDebugExit();
1484 0     return result;
1485 }
1486
1487 globus_result_t
1488 globus_soap_message_deserialize_duration_attribute(
1489     globus_soap_message_handle_t        handle,
1490     const xsd_QName *                   attr_name,
1491     xsd_duration *                      val)
1492 0 {
1493 0     const xmlChar *                     attr_ns;
1494 0     const xmlChar *                     local_ns;
1495 0     xmlChar *                           tmp_value;
1496 0     xmlSchemaValPtr                     schema_val = NULL;
1497 0     int                                 res;
1498 0     globus_result_t                     result = GLOBUS_SUCCESS;
1499 0     GlobusFuncName(globus_soap_message_deserialize_duration_attribute);
1500 0     GlobusSoapMessageDebugEnter();
1501
1502 0     attr_ns = xmlTextReaderConstString(
1503         handle->reader, attr_name->Namespace);
1504 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1505
1506 0     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1507     {
1508 0         tmp_value = xmlTextReaderGetAttributeNs(
1509             handle->reader, attr_name->local, attr_name->Namespace);
1510     }
1511     else
1512     {
1513 0         tmp_value = xmlTextReaderGetAttribute(
1514             handle->reader, attr_name->local);
1515     }
1516
1517 0     if(!tmp_value)
1518     {
1519 0         result = GlobusSoapMessageErrorAttributeNotFound(
1520                 handle->verbose,
1521                 attr_name);
1522 0         goto exit;
1523     }
1524
1525 0     res = xmlSchemaValidatePredefinedType(
1526         xmlSchemaGetBuiltInType(XML_SCHEMAS_DURATION),
1527         tmp_value,
1528         &schema_val);
1529 0     if(res != 0)
1530     {
1531 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1532             &xsd_duration_qname, tmp_value);
1533 0         goto exit;
1534     }
1535
1536 0     val->tm_mon = schema_val->value.date.mon - 1;
1537 0     val->tm_mday = schema_val->value.date.day;
1538 0     val->tm_sec = (int) schema_val->value.date.sec;
1539     
1540 0     xmlSchemaFreeValue(schema_val);
1541     
1542  exit:
1543
1544 0     if(tmp_value)
1545     {
1546 0         xmlFree(tmp_value);
1547     }
1548     
1549 0     GlobusSoapMessageDebugExit();
1550 0     return result;
1551 }
1552
1553 globus_result_t
1554 globus_soap_message_deserialize_dateTime_attribute(
1555     globus_soap_message_handle_t        handle,
1556     const xsd_QName *                   attr_name,
1557     xsd_dateTime *                      val)
1558 0 {
1559 0     const xmlChar *                     attr_ns;
1560 0     const xmlChar *                     local_ns;
1561 0     xmlChar *                           tmp_value = NULL;
1562 0     xmlSchemaValPtr                     schema_val = NULL;
1563 0     int                                 res;
1564 0     globus_result_t                     result = GLOBUS_SUCCESS;
1565 0     GlobusFuncName(globus_soap_message_deserialize_dateTime_attribute);
1566 0     GlobusSoapMessageDebugEnter();
1567
1568 0     attr_ns = xmlTextReaderConstString(
1569         handle->reader, attr_name->Namespace);
1570 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1571
1572 0     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1573     {
1574 0         tmp_value = xmlTextReaderGetAttributeNs(
1575             handle->reader, attr_name->local, attr_name->Namespace);
1576     }
1577     else
1578     {
1579 0         tmp_value = xmlTextReaderGetAttribute(
1580             handle->reader, attr_name->local);
1581     }
1582 0     if(!tmp_value)
1583     {
1584 0         result = GlobusSoapMessageErrorAttributeNotFound(
1585                 handle->verbose,
1586                 attr_name);
1587 0         goto exit;
1588     }
1589
1590 0     res = xmlSchemaValidatePredefinedType(
1591         xmlSchemaGetBuiltInType(XML_SCHEMAS_DATETIME),
1592         tmp_value,
1593         &schema_val);
1594 0     if(res != 0)
1595     {
1596 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1597             &xsd_dateTime_qname, tmp_value);
1598 0         goto exit;
1599     }
1600
1601 0     val->tm_year = schema_val->value.date.year - 1900;
1602 0     val->tm_mon = schema_val->value.date.mon;
1603 0     val->tm_mday = schema_val->value.date.day;
1604 0     val->tm_hour = schema_val->value.date.hour;
1605 0     val->tm_min = schema_val->value.date.min;
1606 0     val->tm_sec = schema_val->value.date.sec;
1607 0     if(schema_val->value.date.tz_flag)
1608     {
1609 0         val->tm_min += schema_val->value.date.tzo;
1610     }
1611
1612 0     xmlSchemaFreeValue(schema_val);
1613     
1614  exit:
1615
1616 0     if(tmp_value)
1617     {
1618 0         xmlFree(tmp_value);
1619     }
1620     
1621 0     GlobusSoapMessageDebugExit();
1622 0     return result;
1623 }
1624
1625 globus_result_t
1626 globus_soap_message_deserialize_date_attribute(
1627     globus_soap_message_handle_t        handle,
1628     const xsd_QName *                   attr_name,
1629     xsd_date *                          val)
1630 0 {
1631 0     const xmlChar *                     attr_ns;
1632 0     const xmlChar *                     local_ns;
1633 0     xmlChar *                           tmp_value = NULL;
1634 0     xmlSchemaValPtr                     schema_val = NULL;
1635 0     int                                 res;
1636 0     globus_result_t                     result = GLOBUS_SUCCESS;
1637 0     GlobusFuncName(globus_soap_message_deserialize_date_attribute);
1638 0     GlobusSoapMessageDebugEnter();
1639
1640 0     attr_ns = xmlTextReaderConstString(
1641         handle->reader, attr_name->Namespace);
1642 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1643
1644 0     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1645     {
1646 0         tmp_value = xmlTextReaderGetAttributeNs(
1647             handle->reader, attr_name->local, attr_name->Namespace);
1648     }
1649     else
1650     {
1651 0         tmp_value = xmlTextReaderGetAttribute(
1652             handle->reader, attr_name->local);
1653     }
1654 0     if(!tmp_value)
1655     {
1656 0         result = GlobusSoapMessageErrorAttributeNotFound(
1657                 handle->verbose,
1658                 attr_name);
1659 0         goto exit;
1660     }
1661
1662
1663 0     res = xmlSchemaValidatePredefinedType(
1664         xmlSchemaGetBuiltInType(XML_SCHEMAS_DATE),
1665         tmp_value,
1666         &schema_val);
1667 0     if(res != 0)
1668     {
1669 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1670             &xsd_date_qname, tmp_value);
1671 0         goto exit;
1672     }
1673
1674 0     val->tm_year = schema_val->value.date.year - 1900;
1675 0     val->tm_mon = schema_val->value.date.mon - 1;
1676 0     val->tm_mday = schema_val->value.date.day;
1677
1678 0     xmlSchemaFreeValue(schema_val);
1679     
1680  exit:
1681
1682 0     if(tmp_value)
1683     {
1684 0         xmlFree(tmp_value);
1685     }
1686     
1687 0     GlobusSoapMessageDebugExit();
1688 0     return result;
1689 }
1690
1691 globus_result_t
1692 globus_soap_message_deserialize_int_attribute(
1693     globus_soap_message_handle_t        handle,
1694     const xsd_QName *                   attr_name,
1695     xsd_int *                           val)
1696 19062 {
1697 19062     const xmlChar *                     attr_ns;
1698 19062     const xmlChar *                     local_ns;
1699 19062     xmlChar *                           tmp_value;
1700 19062     globus_result_t                     result = GLOBUS_SUCCESS;
1701 19062     GlobusFuncName(globus_soap_message_deserialize_int_attribute);
1702 19062     GlobusSoapMessageDebugEnter();
1703
1704 19062     attr_ns = xmlTextReaderConstString(
1705         handle->reader, attr_name->Namespace);
1706 19062     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1707
1708 19062     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1709     {
1710 19062         tmp_value = xmlTextReaderGetAttributeNs(
1711             handle->reader, attr_name->local, attr_name->Namespace);
1712     }
1713     else
1714     {
1715 0         tmp_value = xmlTextReaderGetAttribute(
1716             handle->reader, attr_name->local);
1717     }
1718 19062     if(!tmp_value)
1719     {
1720 19062         result = GlobusSoapMessageErrorAttributeNotFound(
1721                 handle->verbose,
1722                 attr_name);
1723 19062         goto exit;
1724     }
1725
1726 0     *val = strtol((const char *)tmp_value, NULL, 0);
1727 0     if(*val == INT32_MAX || *val == INT32_MIN)
1728     {
1729 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1730             &xsd_int_qname, tmp_value);
1731         goto exit;
1732     }
1733     
1734  exit:
1735
1736 19062     if(tmp_value)
1737     {
1738 0         xmlFree(tmp_value);
1739     }
1740     
1741 19062     GlobusSoapMessageDebugExit();
1742 19062     return result;
1743 }
1744
1745 globus_result_t
1746 globus_soap_message_deserialize_integer_attribute(
1747     globus_soap_message_handle_t        handle,
1748     const xsd_QName *                   attr_name,
1749     xsd_integer *                       val)
1750 0 {
1751 0     int                                 rc;
1752 0     xmlChar *                           tmp_value = NULL;
1753 0     char *                              tmp = NULL;
1754 0     char *                              tmp_start;
1755 0     char *                              tmp_end;
1756 0     globus_result_t                     result = GLOBUS_SUCCESS;
1757 0     GlobusFuncName(globus_soap_message_deserialize_integer_attribute);
1758 0     GlobusSoapMessageDebugEnter();
1759
1760 0     tmp_value = xmlTextReaderGetAttributeNs(
1761         handle->reader, attr_name->local, attr_name->Namespace);
1762 0     if(!tmp_value)
1763     {
1764 0         result = GlobusSoapMessageErrorDeserializeFailed(
1765             result, &xsd_integer_qname);
1766 0         goto exit;
1767     }
1768
1769 0     tmp = globus_libc_strdup(tmp_value);
1770 0     tmp_start = tmp;
1771
1772 0     while(*tmp_start && isspace(*tmp_start))
1773     {
1774 0         tmp_start++;
1775     }
1776 0     if (*tmp_start == '+')
1777     {
1778 0         tmp_start++;
1779     }
1780 0     if (*tmp_start != '-' && !isdigit(*tmp_start))
1781     {
1782 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1783             &xsd_integer_qname, tmp_value);
1784 0         goto exit;
1785     }
1786 0     tmp_end = tmp_start;
1787
1788 0     if (*tmp_end == '-')
1789     {
1790 0         tmp_end++;
1791     }
1792 0     while (*tmp_end && isdigit(*tmp_end))
1793     {
1794 0         tmp_end++;
1795     }
1796
1797 0     if (*tmp_end && isspace(*tmp_end))
1798     {
1799 0         *tmp_end = '\0';
1800 0         tmp_end++;
1801     }
1802 0     while (*tmp_end && isspace(*tmp_end))
1803     {
1804 0         tmp_end++;
1805     }
1806 0     if (*tmp_end)
1807     {
1808         /* garbage at end */
1809 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1810             &xsd_integer_qname, tmp_value);
1811 0         goto exit;
1812     }
1813 0     rc = BN_dec2bn(val, tmp_start);
1814 0     if (rc == 0)
1815     {
1816 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
1817             &xsd_integer_qname, tmp_value);
1818         goto exit;
1819     }
1820     
1821  exit:
1822
1823 0     if(tmp_value)
1824     {
1825 0         xmlFree(tmp_value);
1826     }
1827 0     if(tmp)
1828     {
1829 0         free(tmp);
1830     }
1831     
1832 0     GlobusSoapMessageDebugExit();
1833 0     return result;
1834 }
1835
1836 globus_result_t
1837 globus_soap_message_deserialize_long_attribute(
1838     globus_soap_message_handle_t        handle,
1839     const xsd_QName *                   attr_name,
1840     xsd_long *                          val)
1841 0 {
1842 0     const xmlChar *                     attr_ns;
1843 0     const xmlChar *                     local_ns;
1844 0     xmlChar *                           tmp_value;
1845 0     globus_result_t                     result = GLOBUS_SUCCESS;
1846 0     GlobusFuncName(globus_soap_message_deserialize_long_attribute);
1847 0     GlobusSoapMessageDebugEnter();
1848
1849 0     attr_ns = xmlTextReaderConstString(
1850         handle->reader, attr_name->Namespace);
1851 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1852
1853 0     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1854     {
1855 0         tmp_value = xmlTextReaderGetAttributeNs(
1856             handle->reader, attr_name->local, attr_name->Namespace);
1857     }
1858     else
1859     {
1860 0         tmp_value = xmlTextReaderGetAttribute(
1861             handle->reader, attr_name->local);
1862     }
1863 0     if(!tmp_value)
1864     {
1865 0         result = GlobusSoapMessageErrorAttributeNotFound(
1866                 handle->verbose,
1867                 attr_name);
1868 0         goto exit;
1869     }
1870
1871 0     *val = strtoll(tmp_value, NULL, 0);
1872 0     if(*val == INT64_MAX || *val == INT64_MIN)
1873     {
1874 0         if(errno == ERANGE)
1875         {
1876 0             result = GlobusSoapMessageErrorDeserializeContentFailed(
1877                 &xsd_long_qname, tmp_value);
1878             goto exit;
1879         }
1880     }
1881     
1882  exit:
1883     
1884 0     if(tmp_value)
1885     {
1886 0         xmlFree(tmp_value);
1887     }
1888
1889 0     GlobusSoapMessageDebugExit();
1890 0     return result;
1891 }
1892
1893 globus_result_t
1894 globus_soap_message_deserialize_float_attribute(
1895     globus_soap_message_handle_t        handle,
1896     const xsd_QName *                   attr_name,
1897     xsd_float *                         val)
1898 0 {
1899 0     const xmlChar *                     attr_ns;
1900 0     const xmlChar *                     local_ns;
1901 0     xmlChar *                           tmp_value = NULL;
1902 0     globus_result_t                     result = GLOBUS_SUCCESS;
1903 0     GlobusFuncName(globus_soap_message_deserialize_float_attribute);
1904 0     GlobusSoapMessageDebugEnter();
1905
1906 0     attr_ns = xmlTextReaderConstString(
1907         handle->reader, attr_name->Namespace);
1908 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
1909
1910 0     if(attr_ns != local_ns && (attr_ns != NULL) && (*attr_ns != '\0'))
1911     {
1912 0         tmp_value = xmlTextReaderGetAttributeNs(
1913             handle->reader, attr_name->local, attr_name->Namespace);
1914     }
1915     else
1916     {
1917 0         tmp_value = xmlTextReaderGetAttribute(
1918             handle->reader, attr_name->local);
1919     }
1920 0     if(!tmp_value)
1921     {
1922 0         result = GlobusSoapMessageErrorAttributeNotFound(
1923                 handle->verbose,
1924                 attr_name);
1925 0         goto exit;
1926     }
1927
1928 0     *val = (float) strtod(tmp_value, NULL);
1929
1930  exit:
1931     
1932 0     if(tmp_value)
1933     {
1934 0         xmlFree(tmp_value);
1935     }
1936
1937 0     GlobusSoapMessageDebugExit();
1938 0     return result;
1939 }
1940
1941 globus_result_t
1942 globus_soap_message_deserialize_base64Binary_attribute(
1943     globus_soap_message_handle_t        handle,
1944     const xsd_QName *                   attr_qname,
1945     xsd_base64Binary *                  val)
1946 0 {
1947 0     xmlChar *                           tmp_value = NULL;
1948 0     int                                 length;
1949 0     globus_result_t                     result = GLOBUS_SUCCESS;
1950     
1951 0     GlobusFuncName(globus_soap_message_deserialize_base64Binary_attribute);
1952 0     GlobusSoapMessageDebugEnter();
1953
1954 0     tmp_value = xmlTextReaderGetAttributeNs(
1955         handle->reader, attr_qname->local, attr_qname->Namespace);
1956 0     if(!tmp_value)
1957     {
1958 0         result = GlobusSoapMessageErrorDeserializeFailed(
1959             result, &xsd_float_qname);
1960 0         goto exit;
1961     }
1962
1963 0     length = strlen(tmp_value);
1964
1965 0     val->length = (int)ceil((length * 3) / 4) + 1;
1966 0     val->value = globus_malloc(val->length);
1967 0     if(!val->value)
1968     {
1969 0 result = GlobusSoapMessageErrorOutOfMemory;
1970 0 goto exit;
1971     }
1972     
1973 0     if(xmlBase64Decode(
1974         tmp_value, 
1975 (unsigned long *)&length, 
1976 val->value, 
1977 (unsigned long *)&val->length) < 0)
1978     {
1979 0 result = GlobusSoapMessageErrorDeserializeContentFailed(
1980     attr_qname, tmp_value);
1981 goto exit;
1982     }
1983
1984  exit:
1985  
1986 0     if(tmp_value)
1987     {
1988 0         xmlFree(tmp_value);
1989     }
1990
1991 0     GlobusSoapMessageDebugExit();
1992 0     return result;
1993 }    
1994
1995 globus_result_t
1996 globus_soap_message_deserialize_boolean(
1997     globus_soap_message_handle_t        handle,
1998     xsd_boolean *                       val)
1999 1 {
2000 1     const xmlChar *                     tmp_value = NULL;
2001 1     globus_result_t                     result = GLOBUS_SUCCESS;
2002     
2003 1     GlobusFuncName(globus_soap_message_deserialize_boolean);
2004 1     GlobusSoapMessageDebugEnter();
2005
2006 1     result = globus_i_soap_message_deserialize_next_content(handle);
2007 1     if(result != GLOBUS_SUCCESS)
2008     {
2009 0         result = GlobusSoapMessageErrorDeserializeFailed(
2010             result, &xsd_boolean_qname);
2011 0         goto exit;
2012     }
2013     
2014 1     tmp_value = xmlTextReaderConstValue(handle->reader);
2015 1     if(!tmp_value)
2016     {
2017 0         result = GlobusSoapMessageErrorDeserializeFailed(
2018             GLOBUS_SUCCESS, &xsd_boolean_qname);
2019 0         goto exit;
2020     }
2021
2022 1     if(!xmlStrcmp(tmp_value, "false"))
2023     {
2024 0         *val = 0;
2025     }
2026     else
2027     {
2028 1         *val = 1;
2029     }
2030
2031  exit:
2032
2033 1     GlobusSoapMessageDebugExit();
2034 1     return result;
2035 }
2036
2037 globus_result_t
2038 globus_soap_message_deserialize_boolean_attribute(
2039     globus_soap_message_handle_t        handle,
2040     const xsd_QName *                   attr_name,
2041     xsd_boolean *                       val)
2042 60 {
2043 60     const xmlChar *                     attr_ns;
2044 60     const xmlChar *                     local_ns;
2045 60     xmlChar *                           tmp_value;
2046 60     globus_result_t                     result = GLOBUS_SUCCESS;
2047     
2048 60     GlobusFuncName(globus_soap_message_deserialize_boolean_attribute);
2049 60     GlobusSoapMessageDebugEnter();
2050
2051 60     attr_ns = xmlTextReaderConstString(
2052         handle->reader, attr_name->Namespace);
2053 60     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
2054
2055 60     if(attr_ns != local_ns  && (attr_ns != NULL) && (*attr_ns != '\0'))
2056     {
2057 0         tmp_value = xmlTextReaderGetAttributeNs(
2058             handle->reader, attr_name->local, attr_name->Namespace);
2059     }
2060     else
2061     {
2062 60         tmp_value = xmlTextReaderGetAttribute(
2063             handle->reader, attr_name->local);
2064     }
2065 60     if(!tmp_value)
2066     {
2067 24         result = GlobusSoapMessageErrorAttributeNotFound(
2068                 handle->verbose,
2069                 attr_name);
2070 24         goto exit;
2071     }
2072     
2073 36     if(!xmlStrcmp(tmp_value, "false"))
2074     {
2075 12         *val = 0;
2076     }
2077     else
2078     {
2079 24         *val = 1;
2080     }
2081
2082  exit:
2083
2084 60     if(tmp_value)
2085     {
2086 36         xmlFree(tmp_value);
2087     }
2088
2089 60     GlobusSoapMessageDebugExit();
2090 60     return result;
2091 }
2092
2093 globus_result_t
2094 globus_soap_message_deserialize_dateTime(
2095     globus_soap_message_handle_t        handle,
2096     xsd_dateTime *                      val)
2097 493396 {
2098 493396     xmlSchemaValPtr                     schema_val = NULL;
2099 493396     int                                 res = 0;
2100 493396     const xmlChar *                     tmp_value;
2101 493396     globus_result_t                     result = GLOBUS_SUCCESS;
2102
2103 493396     GlobusFuncName(globus_soap_message_deserialize_dateTime);
2104 493396     GlobusSoapMessageDebugEnter();
2105
2106 493396     result = globus_i_soap_message_deserialize_next_content(handle);
2107 493396     if(result != GLOBUS_SUCCESS)
2108     {
2109 0         result = GlobusSoapMessageErrorDeserializeFailed(
2110             result, &xsd_dateTime_qname);
2111 0         goto exit;
2112     }
2113     
2114 493396     tmp_value = xmlTextReaderConstValue(handle->reader);
2115 493396     if(!tmp_value)
2116     {
2117 0         result = GlobusSoapMessageErrorDeserializeFailed(
2118             result, &xsd_dateTime_qname);
2119 0         goto exit;
2120     }
2121
2122 493396     res = xmlSchemaValidatePredefinedType(
2123         xmlSchemaGetBuiltInType(XML_SCHEMAS_DATETIME),
2124         tmp_value,
2125         &schema_val);
2126 493396     if(res != 0)
2127     {
2128 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2129             &xsd_dateTime_qname, tmp_value);
2130 0         goto exit;
2131     }
2132
2133 493396     val->tm_year = schema_val->value.date.year - 1900;
2134 493396     val->tm_mon = schema_val->value.date.mon - 1;
2135 493396     val->tm_mday = schema_val->value.date.day;
2136 493396     val->tm_hour = schema_val->value.date.hour;
2137 493396     val->tm_min = schema_val->value.date.min;
2138 493396     val->tm_sec = schema_val->value.date.sec;
2139 493396     if(schema_val->value.date.tz_flag)
2140     {
2141 493396         val->tm_min += schema_val->value.date.tzo;
2142     }
2143
2144 493396     xmlSchemaFreeValue(schema_val);
2145
2146  exit:
2147
2148 493396     GlobusSoapMessageDebugExit();
2149 493396     return result;
2150 }
2151         
2152 globus_result_t
2153 globus_soap_message_deserialize_date(
2154     globus_soap_message_handle_t        handle,
2155     xsd_date *                          val)
2156 0 {
2157 0     int                                 res = 0;
2158 0     xmlSchemaValPtr                     schema_val = NULL;
2159 0     const xmlChar *                     tmp_value;
2160 0     globus_result_t                     result = GLOBUS_SUCCESS;
2161
2162 0     GlobusFuncName(globus_soap_message_deserialize_date);
2163 0     GlobusSoapMessageDebugEnter();
2164
2165 0     result = globus_i_soap_message_deserialize_next_content(handle);
2166 0     if(result != GLOBUS_SUCCESS)
2167     {
2168 0         result = GlobusSoapMessageErrorDeserializeFailed(
2169             result, &xsd_date_qname);
2170 0         goto exit;
2171     }
2172     
2173 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2174 0     if(!tmp_value)
2175     {
2176 0         result = GlobusSoapMessageErrorDeserializeFailed(
2177             GLOBUS_SUCCESS, &xsd_date_qname);
2178 0         goto exit;
2179     }
2180
2181 0     res = xmlSchemaValidatePredefinedType(
2182         xmlSchemaGetBuiltInType(XML_SCHEMAS_DATE),
2183         tmp_value,
2184         &schema_val);
2185 0     if(res != 0)
2186     {
2187 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2188             &xsd_date_qname, tmp_value);
2189 0         goto exit;
2190     }
2191
2192 0     val->tm_year = schema_val->value.date.year - 1900;
2193 0     val->tm_mon = schema_val->value.date.mon - 1;
2194 0     val->tm_mday = schema_val->value.date.day;
2195
2196 0     xmlSchemaFreeValue(schema_val);
2197
2198  exit:
2199
2200 0     GlobusSoapMessageDebugExit();
2201 0     return result;
2202 }
2203
2204 globus_result_t
2205 globus_soap_message_deserialize_time(
2206     globus_soap_message_handle_t        handle,
2207     xsd_time *                          val)
2208 0 {
2209 0     xmlSchemaValPtr                     schema_val = NULL;
2210 0     int                                 res;
2211 0     const xmlChar *                     tmp_value;
2212 0     globus_result_t                     result = GLOBUS_SUCCESS;
2213
2214 0     GlobusFuncName(globus_soap_message_deserialize_time);
2215 0     GlobusSoapMessageDebugEnter();
2216
2217 0     result = globus_i_soap_message_deserialize_next_content(handle);
2218 0     if(result != GLOBUS_SUCCESS)
2219     {
2220 0         result = GlobusSoapMessageErrorDeserializeFailed(
2221             result, &xsd_time_qname);
2222 0         goto exit;
2223     }
2224     
2225 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2226 0     if(!tmp_value)
2227     {
2228 0         result = GlobusSoapMessageErrorDeserializeFailed(
2229             result, &xsd_time_qname);
2230 0         goto exit;
2231     }
2232
2233 0     res = xmlSchemaValidatePredefinedType(
2234         xmlSchemaGetBuiltInType(XML_SCHEMAS_TIME),
2235         tmp_value,
2236         &schema_val);
2237 0     if(res != 0)
2238     {
2239 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2240             &xsd_time_qname, tmp_value);
2241 0         goto exit;
2242     }
2243
2244 0     val->tm_hour = schema_val->value.date.hour;
2245 0     val->tm_min = schema_val->value.date.min;
2246 0     val->tm_sec = schema_val->value.date.sec;
2247
2248 0     if(schema_val->value.date.tz_flag)
2249     {
2250 0         val->tm_sec += (schema_val->value.date.tzo * 60);
2251     }
2252
2253 0     xmlSchemaFreeValue(schema_val);
2254
2255  exit:
2256
2257 0     GlobusSoapMessageDebugExit();
2258 0     return result;
2259 }
2260     
2261
2262 globus_result_t
2263 globus_soap_message_deserialize_duration(
2264     globus_soap_message_handle_t        handle,
2265     xsd_duration *                      val)
2266 0 {
2267 0     xmlSchemaValPtr                     schema_val = NULL;
2268 0     int                                 res;
2269 0     const xmlChar *                     tmp_value;
2270 0     globus_result_t                     result = GLOBUS_SUCCESS;
2271
2272 0     GlobusFuncName(globus_soap_message_deserialize_duration);
2273 0     GlobusSoapMessageDebugEnter();
2274
2275 0     result = globus_i_soap_message_deserialize_next_content(handle);
2276 0     if(result != GLOBUS_SUCCESS)
2277     {
2278 0         result = GlobusSoapMessageErrorDeserializeFailed(
2279             result, &xsd_duration_qname);
2280 0         goto exit;
2281     }
2282     
2283 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2284 0     if(!tmp_value)
2285     {
2286 0         result = GlobusSoapMessageErrorDeserializeFailed(
2287             result, &xsd_duration_qname);
2288 0         goto exit;
2289     }
2290
2291 0     res = xmlSchemaValidatePredefinedType(
2292         xmlSchemaGetBuiltInType(XML_SCHEMAS_DURATION),
2293         tmp_value,
2294         &schema_val);
2295 0     if(res != 0)
2296     {
2297 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2298             &xsd_duration_qname, tmp_value);
2299 0         goto exit;
2300     }
2301
2302 0     val->tm_mon = schema_val->value.date.mon - 1;
2303 0     val->tm_mday = schema_val->value.date.day;
2304 0     val->tm_sec = (int) schema_val->value.date.sec;
2305     
2306 0     xmlSchemaFreeValue(schema_val);
2307
2308  exit:
2309     
2310 0     GlobusSoapMessageDebugExit();
2311 0     return result;
2312 }
2313     
2314
2315 globus_result_t
2316 globus_soap_message_deserialize_float(
2317     globus_soap_message_handle_t        handle,
2318     xsd_float *                         val)
2319 0 {
2320 0     const xmlChar *                     tmp_value;
2321 0     globus_result_t                     result = GLOBUS_SUCCESS;
2322
2323 0     GlobusFuncName(globus_soap_message_deserialize_float);
2324 0     GlobusSoapMessageDebugEnter();
2325
2326 0     result = globus_i_soap_message_deserialize_next_content(handle);
2327 0     if(result != GLOBUS_SUCCESS)
2328     {
2329 0         result = GlobusSoapMessageErrorDeserializeFailed(
2330             result, &xsd_float_qname);
2331 0         goto exit;
2332     }
2333     
2334 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2335 0     if(!tmp_value)
2336     {
2337 0         result = GlobusSoapMessageErrorDeserializeFailed(
2338             result, &xsd_float_qname);
2339 0         goto exit;
2340     }
2341
2342 0     *val = (float) strtod(tmp_value, NULL);
2343
2344  exit:
2345
2346 0     GlobusSoapMessageDebugExit();
2347 0     return result;
2348 }
2349
2350 globus_result_t
2351 globus_soap_message_deserialize_double(
2352     globus_soap_message_handle_t        handle,
2353     xsd_double *                        val)
2354 0 {
2355 0     const xmlChar *                     tmp_value;
2356 0     globus_result_t                     result = GLOBUS_SUCCESS;
2357
2358 0     GlobusFuncName(globus_soap_message_deserialize_double);
2359 0     GlobusSoapMessageDebugEnter();
2360
2361 0     result = globus_i_soap_message_deserialize_next_content(handle);
2362 0     if(result != GLOBUS_SUCCESS)
2363     {
2364 0         result = GlobusSoapMessageErrorDeserializeFailed(
2365             result, &xsd_double_qname);
2366 0         goto exit;
2367     }
2368     
2369 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2370 0     if(!tmp_value)
2371     {
2372 0         result = GlobusSoapMessageErrorDeserializeFailed(
2373             result, &xsd_double_qname);
2374 0         goto exit;
2375     }
2376
2377 0     *val = strtod(tmp_value, NULL);
2378
2379  exit:
2380
2381 0     GlobusSoapMessageDebugExit();
2382 0     return result;
2383 }
2384
2385 globus_result_t
2386 globus_soap_message_deserialize_int(
2387     globus_soap_message_handle_t        handle,
2388     xsd_int *                           val)
2389 67 {
2390 67     const xmlChar *                     tmp_value;
2391 67     globus_result_t                     result = GLOBUS_SUCCESS;
2392
2393 67     GlobusFuncName(globus_soap_message_deserialize_int);
2394 67     GlobusSoapMessageDebugEnter();
2395
2396 67     result = globus_i_soap_message_deserialize_next_content(handle);
2397 67     if(result != GLOBUS_SUCCESS)
2398     {
2399 0         result = GlobusSoapMessageErrorDeserializeFailed(
2400             result, &xsd_int_qname);
2401 0         goto exit;
2402     }
2403     
2404 67     tmp_value = xmlTextReaderConstValue(handle->reader);
2405 67     if(!tmp_value)
2406     {
2407 0         result = GlobusSoapMessageErrorDeserializeFailed(
2408             result, &xsd_int_qname);
2409 0         goto exit;
2410     }
2411
2412 67     *val = strtol((const char *)tmp_value, NULL, 0);
2413 67     if(*val == INT32_MAX || *val == INT32_MIN)
2414     {
2415 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2416             &xsd_int_qname, tmp_value);
2417         goto exit;
2418     }
2419         
2420  exit:
2421
2422 67     GlobusSoapMessageDebugExit();
2423 67     return result;
2424 }
2425
2426 globus_result_t
2427 globus_soap_message_deserialize_long(
2428     globus_soap_message_handle_t        handle,
2429     xsd_long *                          val)
2430 0 {
2431 0     const xmlChar *                     tmp_value;
2432 0     globus_result_t                     result = GLOBUS_SUCCESS;
2433
2434 0     GlobusFuncName(globus_soap_message_deserialize_long);
2435 0     GlobusSoapMessageDebugEnter();
2436
2437 0     result = globus_i_soap_message_deserialize_next_content(handle);
2438 0     if(result != GLOBUS_SUCCESS)
2439     {
2440 0         result = GlobusSoapMessageErrorDeserializeFailed(
2441             result, &xsd_long_qname);
2442 0         goto exit;
2443     }
2444     
2445 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2446 0     if(!tmp_value)
2447     {
2448 0         result = GlobusSoapMessageErrorDeserializeFailed(
2449             GLOBUS_SUCCESS, &xsd_long_qname);
2450 0         goto exit;
2451     }
2452
2453 0     *val = strtoll(tmp_value, NULL, 0);
2454 0     if(*val == INT64_MAX || *val == INT64_MIN)
2455     {
2456 0         if(errno == ERANGE)
2457         {
2458 0             result = GlobusSoapMessageErrorDeserializeContentFailed(
2459                 &xsd_long_qname, tmp_value);
2460             goto exit;
2461         }
2462     }
2463
2464  exit:
2465
2466 0     GlobusSoapMessageDebugExit();
2467 0     return result;
2468 }
2469
2470
2471 globus_result_t
2472 globus_soap_message_deserialize_decimal(
2473     globus_soap_message_handle_t        handle,
2474     xsd_decimal *                       val)
2475 0 {
2476 0     GlobusFuncName(globus_soap_message_deserialize_decimal);
2477 0     GlobusSoapMessageDebugEnter();
2478
2479     /* not implemented */
2480 0     globus_panic(GLOBUS_SOAP_MESSAGE_MODULE, GLOBUS_SUCCESS,
2481                  "%s NOT IMPLEMENTED", _globus_func_name);
2482
2483 0     GlobusSoapMessageDebugExit();
2484 0     return GLOBUS_FAILURE;
2485 }
2486
2487 globus_result_t
2488 globus_soap_message_deserialize_integer(
2489     globus_soap_message_handle_t        handle,
2490     xsd_integer *                       val)
2491 0 {
2492 0     const xmlChar *                     tmp_value;
2493 0     char *                              tmp = NULL;
2494 0     char *                              tmp_start;
2495 0     char *                              tmp_end;
2496 0     int                                 rc;
2497 0     globus_result_t                     result = GLOBUS_SUCCESS;
2498     
2499 0     GlobusFuncName(globus_soap_message_deserialize_integer);
2500 0     GlobusSoapMessageDebugEnter();
2501
2502 0     result = globus_i_soap_message_deserialize_next_content(handle);
2503 0     if(result != GLOBUS_SUCCESS)
2504     {
2505 0         result = GlobusSoapMessageErrorDeserializeFailed(
2506             result, &xsd_integer_qname);
2507 0         goto exit;
2508     }
2509     
2510 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2511 0     if(!tmp_value)
2512     {
2513 0         result = GlobusSoapMessageErrorDeserializeFailed(
2514             GLOBUS_SUCCESS, &xsd_integer_qname);
2515 0         goto exit;
2516     }
2517
2518 0     tmp = globus_libc_strdup(tmp_value);
2519 0     tmp_start = tmp;
2520
2521 0     while(*tmp_start && isspace(*tmp_start))
2522     {
2523 0         tmp_start++;
2524     }
2525 0     if (*tmp_start == '+')
2526     {
2527 0         tmp_start++;
2528     }
2529 0     if (*tmp_start != '-' && !isdigit(*tmp_start))
2530     {
2531 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2532             &xsd_integer_qname, tmp_value);
2533 0         goto exit;
2534     }
2535 0     tmp_end = tmp_start;
2536
2537 0     if (*tmp_end == '-')
2538     {
2539 0         tmp_end++;
2540     }
2541 0     while (*tmp_end && isdigit(*tmp_end))
2542     {
2543 0         tmp_end++;
2544     }
2545
2546 0     if (*tmp_end && isspace(*tmp_end))
2547     {
2548 0         *tmp_end = '\0';
2549 0         tmp_end++;
2550     }
2551 0     while (*tmp_end && isspace(*tmp_end))
2552     {
2553 0         tmp_end++;
2554     }
2555 0     if (*tmp_end)
2556     {
2557         /* garbage at end */
2558 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2559             &xsd_integer_qname, tmp_value);
2560 0         goto exit;
2561     }
2562 0     rc = BN_dec2bn(val, tmp_start);
2563 0     if (rc == 0)
2564     {
2565 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2566             &xsd_integer_qname, tmp_value);
2567         goto exit;
2568     }
2569
2570  exit:
2571 0     if (tmp)
2572     {
2573 0         free(tmp);
2574     }
2575
2576 0     GlobusSoapMessageDebugExit();
2577 0     return result;
2578 }
2579     
2580 globus_result_t
2581 globus_soap_message_deserialize_byte(
2582     globus_soap_message_handle_t        handle,
2583     xsd_byte *                          val)
2584 0 {
2585 0     const xmlChar *                     tmp_value;
2586 0     short                               sval;
2587 0     globus_result_t                     result = GLOBUS_SUCCESS;
2588
2589 0     GlobusFuncName(globus_soap_message_deserialize_byte);
2590 0     GlobusSoapMessageDebugEnter();
2591
2592 0     result = globus_i_soap_message_deserialize_next_content(handle);
2593 0     if(result != GLOBUS_SUCCESS)
2594     {
2595 0         result = GlobusSoapMessageErrorDeserializeFailed(
2596             result, &xsd_byte_qname);
2597 0         goto exit;
2598     }
2599     
2600 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2601 0     if(!tmp_value)
2602     {
2603 0         result = GlobusSoapMessageErrorDeserializeFailed(
2604             result, &xsd_byte_qname);
2605 0         goto exit;
2606     }
2607
2608 0     sscanf(tmp_value, "%hd", &sval);
2609 0     *val = (char) sval;
2610
2611  exit:
2612
2613 0     GlobusSoapMessageDebugExit();
2614 0     return result;
2615 }
2616
2617 globus_result_t
2618 globus_soap_message_deserialize_unsignedByte(
2619     globus_soap_message_handle_t        handle,
2620     xsd_unsignedByte *                  val)
2621 0 {
2622 0     const xmlChar *                     tmp_value;
2623 0     unsigned short                      sval;
2624 0     globus_result_t                     result = GLOBUS_SUCCESS;
2625
2626 0     GlobusFuncName(globus_soap_message_deserialize_unsignedByte);
2627 0     GlobusSoapMessageDebugEnter();
2628
2629 0     result = globus_i_soap_message_deserialize_next_content(handle);
2630 0     if(result != GLOBUS_SUCCESS)
2631     {
2632 0         result = GlobusSoapMessageErrorDeserializeFailed(
2633             result, &xsd_unsignedByte_qname);
2634 0         goto exit;
2635     }
2636     
2637 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2638 0     if(!tmp_value)
2639     {
2640 0         result = GlobusSoapMessageErrorDeserializeFailed(
2641             GLOBUS_SUCCESS, &xsd_unsignedByte_qname);
2642 0         goto exit;
2643     }
2644
2645 0     if(sscanf(tmp_value, "%hu", &sval) == 0)
2646     {
2647 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2648             &xsd_unsignedByte_qname, tmp_value);
2649 0         goto exit;
2650     }
2651
2652 0     *val = (unsigned char) sval;
2653
2654  exit:
2655
2656 0     GlobusSoapMessageDebugExit();
2657 0     return result;
2658 }  
2659
2660 globus_result_t
2661 globus_soap_message_deserialize_unsignedLong(
2662     globus_soap_message_handle_t        handle,
2663     xsd_unsignedLong *                  val)
2664 0 {
2665 0     const xmlChar *                     tmp_value;
2666 0     globus_result_t                     result = GLOBUS_SUCCESS;
2667
2668 0     GlobusFuncName(globus_soap_message_deserialize_unsignedLong);
2669 0     GlobusSoapMessageDebugEnter();
2670
2671 0     result = globus_i_soap_message_deserialize_next_content(handle);
2672 0     if(result != GLOBUS_SUCCESS)
2673     {
2674 0         result = GlobusSoapMessageErrorDeserializeFailed(
2675             result, &xsd_unsignedLong_qname);
2676 0         goto exit;
2677     }
2678     
2679 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2680 0     if(!tmp_value)
2681     {
2682 0         result = GlobusSoapMessageErrorDeserializeFailed(
2683             GLOBUS_SUCCESS, &xsd_unsignedLong_qname);
2684 0         goto exit;
2685     }
2686
2687 0     *val = strtoull(tmp_value, NULL, 0);
2688 0     if(*val == UINT64_MAX)
2689     {
2690 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2691             &xsd_unsignedLong_qname, tmp_value);
2692         goto exit;
2693     }
2694
2695  exit:
2696     
2697 0     GlobusSoapMessageDebugExit();
2698 0     return result;
2699 }  
2700
2701 globus_result_t
2702 globus_soap_message_deserialize_unsignedInt(
2703     globus_soap_message_handle_t        handle,
2704     xsd_unsignedInt *                   val)
2705 0 {
2706 0     const xmlChar *                     tmp_value;
2707 0     globus_result_t                     result = GLOBUS_SUCCESS;
2708
2709 0     GlobusFuncName(globus_soap_message_deserialize_unsignedInt);
2710 0     GlobusSoapMessageDebugEnter();
2711
2712 0     result = globus_i_soap_message_deserialize_next_content(handle);
2713 0     if(result != GLOBUS_SUCCESS)
2714     {
2715 0         result = GlobusSoapMessageErrorDeserializeFailed(
2716             result, &xsd_unsignedInt_qname);
2717 0         goto exit;
2718     }
2719     
2720 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2721 0     if(!tmp_value)
2722     {
2723 0         result = GlobusSoapMessageErrorDeserializeFailed(
2724             GLOBUS_SUCCESS, &xsd_unsignedInt_qname);
2725 0         goto exit;
2726     }
2727
2728 0     *val = strtoul(tmp_value, NULL, 0);
2729 0     if(*val == UINT32_MAX)
2730     {
2731 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2732             &xsd_unsignedInt_qname, tmp_value);
2733         goto exit;
2734     }
2735
2736  exit:
2737
2738 0     GlobusSoapMessageDebugExit();
2739 0     return result;
2740 }  
2741     
2742
2743 globus_result_t
2744 globus_soap_message_deserialize_unsignedShort(
2745     globus_soap_message_handle_t        handle,
2746     xsd_unsignedShort *                 val)
2747 0 {
2748 0     const xmlChar *                     tmp_value;
2749 0     globus_result_t                     result = GLOBUS_SUCCESS;
2750
2751 0     GlobusFuncName(globus_soap_message_deserialize_unsignedShort);
2752 0     GlobusSoapMessageDebugEnter();
2753
2754 0     result = globus_i_soap_message_deserialize_next_content(handle);
2755 0     if(result != GLOBUS_SUCCESS)
2756     {
2757 0         result = GlobusSoapMessageErrorDeserializeFailed(
2758             result, &xsd_unsignedShort_qname);
2759 0         goto exit;
2760     }
2761     
2762 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2763 0     if(!tmp_value)
2764     {
2765 0         result = GlobusSoapMessageErrorDeserializeFailed(
2766             GLOBUS_SUCCESS, &xsd_unsignedShort_qname);
2767 0         goto exit;
2768     }
2769
2770 0     if(sscanf(tmp_value, "%hu", val) < 1)
2771     {
2772 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2773             &xsd_unsignedShort_qname, tmp_value);
2774         goto exit;
2775     }
2776
2777  exit:
2778
2779 0     GlobusSoapMessageDebugExit();
2780 0     return result;
2781 }
2782     
2783 globus_result_t
2784 globus_soap_message_deserialize_base64Binary(
2785     globus_soap_message_handle_t        handle,
2786     xsd_base64Binary *                  val)
2787 0 {
2788 0     const xmlChar *                     tmp_value;
2789 0     int                                 length = 0;
2790 0     globus_result_t                     result = GLOBUS_SUCCESS;
2791
2792 0     GlobusFuncName(globus_soap_message_deserialize_base64Binary);
2793 0     GlobusSoapMessageDebugEnter();
2794
2795 0     result = globus_i_soap_message_deserialize_next_content(handle);
2796 0     if(result != GLOBUS_SUCCESS)
2797     {
2798 0         result = GlobusSoapMessageErrorDeserializeFailed(
2799             result, &xsd_base64Binary_qname);
2800 0         goto exit;
2801     }
2802     
2803 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2804 0     if(!tmp_value)
2805     {
2806 0         result = GlobusSoapMessageErrorDeserializeFailed(
2807             GLOBUS_SUCCESS, &xsd_base64Binary_qname);
2808 0         goto exit;
2809     }
2810     
2811 0     length = strlen(tmp_value);
2812
2813 0     val->length = (int)ceil((length * 3) / 4) + 1;
2814 0     val->value = globus_malloc(val->length);
2815 0     if(!val->value)
2816     {
2817 0 result = GlobusSoapMessageErrorOutOfMemory;
2818 0 goto exit;
2819     }
2820     
2821 0     if(xmlBase64Decode(
2822 tmp_value, 
2823 (unsigned long *)&length, 
2824 val->value, 
2825 (unsigned long *)&val->length) < 0)
2826     {
2827 0 result = GlobusSoapMessageErrorDeserializeContentFailed(
2828     &xsd_base64Binary_qname, tmp_value);
2829 goto exit;
2830     }
2831
2832  exit:
2833
2834 0     GlobusSoapMessageDebugExit();
2835 0     return result;
2836 }
2837
2838 globus_result_t
2839 globus_soap_message_deserialize_hexBinary(
2840     globus_soap_message_handle_t        handle,
2841     xsd_hexBinary *                     val)
2842 0 {
2843 0     int                                 res = 0;
2844 0     xmlSchemaValPtr                     schema_val = NULL;
2845 0     const xmlChar *                     tmp_value;
2846 0     globus_result_t                     result = GLOBUS_SUCCESS;
2847
2848 0     GlobusFuncName(globus_soap_message_deserialize_hexBinary);
2849 0     GlobusSoapMessageDebugEnter();
2850
2851 0     result = globus_i_soap_message_deserialize_next_content(handle);
2852 0     if(result != GLOBUS_SUCCESS)
2853     {
2854 0         result = GlobusSoapMessageErrorDeserializeFailed(
2855             result, &xsd_hexBinary_qname);
2856 0         goto exit;
2857     }
2858     
2859 0     tmp_value = xmlTextReaderConstValue(handle->reader);
2860 0     if(!tmp_value)
2861     {
2862 0         result = GlobusSoapMessageErrorDeserializeFailed(
2863             result, &xsd_hexBinary_qname);
2864 0         goto exit;
2865     }
2866
2867 0     res = xmlSchemaValidatePredefinedType(
2868         xmlSchemaGetBuiltInType(XML_SCHEMAS_HEXBINARY),
2869         tmp_value,
2870         &schema_val);
2871 0     if(res != 0)
2872     {
2873 0         result = GlobusSoapMessageErrorDeserializeContentFailed(
2874             &xsd_hexBinary_qname, tmp_value);
2875 0         goto exit;
2876     }
2877
2878 0     val->value = globus_libc_strdup(schema_val->value.hex.str);
2879 0     val->length = schema_val->value.hex.total;
2880
2881 0     xmlSchemaFreeValue(schema_val);
2882
2883  exit:
2884
2885 0     GlobusSoapMessageDebugExit();
2886 0     return result;
2887 }
2888
2889 globus_result_t
2890 globus_soap_message_deserialize_QName(
2891     globus_soap_message_handle_t        handle,
2892     xsd_QName *                         val)
2893 493613 {
2894 493613     xmlChar *                           prefix;
2895 493613     const xmlChar *                     tmp_value;
2896 493613     char *                              token;
2897 493613     globus_result_t                     result = GLOBUS_SUCCESS;
2898 493613     int                                 start_token;
2899 493613     int                                 end_token;
2900
2901 493613     GlobusFuncName(globus_soap_message_deserialize_QName);
2902 493613     GlobusSoapMessageDebugEnter();
2903
2904 493613     result = globus_i_soap_message_deserialize_next_content(handle);
2905 493613     if(result != GLOBUS_SUCCESS)
2906     {
2907 0         result = GlobusSoapMessageErrorDeserializeFailed(
2908             result, &xsd_QName_qname);
2909 0         goto exit;
2910     }
2911     
2912 493613     tmp_value = xmlTextReaderConstValue(handle->reader);
2913 493613     if(!tmp_value)
2914     {
2915 0         result = GlobusSoapMessageErrorDeserializeFailed(
2916             result, &xsd_QName_qname);
2917 0         goto exit;
2918     }
2919 493613     token = globus_l_soap_message_my_strtok(
2920         tmp_value, strlen(tmp_value), &start_token, &end_token, "\n\t ");
2921 493613     if (token == NULL)
2922     {
2923 0         result = GlobusSoapMessageErrorDeserializeFailed(
2924             result, &xsd_QName_qname);
2925 0         goto exit;
2926     }
2927
2928 493613     val->local = xmlSplitQName2(token, &prefix);
2929 493613     if(val->local && prefix)
2930     {
2931 493613         val->Namespace = xmlTextReaderLookupNamespace(handle->reader, prefix);
2932 493613         xmlFree(prefix);
2933     }
2934 0     else if (val->local)
2935     {
2936 0         val->Namespace = NULL;
2937     }
2938     else
2939     {
2940 0         val->local = globus_libc_strdup(tmp_value);
2941     }
2942
2943 493613     free(token);
2944
2945  exit:
2946
2947 493613     GlobusSoapMessageDebugExit();
2948 493613     return result;
2949 }
2950
2951 globus_result_t
2952 globus_soap_message_deserialize_QName_attribute(
2953     globus_soap_message_handle_t        handle,
2954     const xsd_QName *                   attr_name,
2955     xsd_QName *                         val)
2956 2212 {
2957 2212     xmlChar *                           str = NULL;
2958 2212     xmlChar *                           prefix;
2959 2212     const xmlChar *                     attr_ns;
2960 2212     const xmlChar *                     local_ns;
2961 2212     globus_result_t                     result = GLOBUS_SUCCESS;
2962
2963 2212     GlobusFuncName(globus_soap_message_deserialize_QName_attribute);
2964 2212     GlobusSoapMessageDebugEnter();
2965
2966 2212     attr_ns = xmlTextReaderConstString(
2967         handle->reader, attr_name->Namespace);
2968 2212     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
2969
2970     /* is it the default or a null namespace? */
2971 2212     if((attr_ns != local_ns) && (attr_ns != NULL) && (*attr_ns != '\0'))
2972     {
2973 0         str = xmlTextReaderGetAttributeNs(
2974             handle->reader, attr_name->local, attr_name->Namespace);
2975     }
2976     else
2977     {
2978 2212         str = xmlTextReaderGetAttribute(
2979             handle->reader, attr_name->local);
2980     }
2981
2982 2212     if((str == NULL || (*str == '\0')))
2983     {
2984 2123         result = GlobusSoapMessageErrorAttributeNotFound(
2985                 handle->verbose,
2986                 attr_name);
2987 2123         goto exit;
2988     }
2989     else
2990     {
2991 89         val->local = xmlSplitQName2(str, &prefix);
2992 89         if(prefix)
2993         {
2994 89             val->Namespace = xmlTextReaderLookupNamespace(
2995                 handle->reader, prefix);
2996 89             xmlFree(prefix);
2997         }
2998         else
2999         {
3000 0             val->Namespace = NULL;
3001         }
3002     }
3003
3004  exit:
3005
3006 2212     if (str != NULL)
3007     {
3008 89         xmlFree(str);
3009     }
3010
3011 2212     GlobusSoapMessageDebugExit();
3012 2212     return result;
3013 }
3014
3015 globus_result_t
3016 globus_soap_message_deserialize_QName_list(
3017     globus_soap_message_handle_t        handle,
3018     xsd_QName_array *                   inst)
3019 0 {
3020 0     const xmlChar *                     tmp_value;
3021 0     globus_list_t *                     qnames;
3022 0     globus_list_t *                     qnlist;
3023 0     globus_result_t                     result = GLOBUS_SUCCESS;
3024 0     GlobusFuncName(globus_soap_message_deserialize_QName_list);
3025 0     GlobusSoapMessageDebugEnter();
3026
3027 0     result = globus_i_soap_message_deserialize_next_content(handle);
3028 0     if(result != GLOBUS_SUCCESS)
3029     {
3030 0         result = GlobusSoapMessageErrorDeserializeFailed(
3031             result, &xsd_QName_qname);
3032 0         goto exit;
3033     }
3034     
3035 0     tmp_value = xmlTextReaderConstValue(handle->reader);
3036 0     if(!tmp_value)
3037     {
3038 0         result = GlobusSoapMessageErrorDeserializeFailed(
3039             result, &xsd_QName_qname);
3040 0         goto exit;
3041     }
3042
3043 0     globus_i_soap_message_split_qnames(tmp_value, &qnames);
3044 0     qnlist = qnames;
3045 0     while(!globus_list_empty(qnlist))
3046     {
3047 0         char *                          str = globus_list_first(qnlist);
3048 0         xmlChar *                       prefix = NULL;
3049 0         xsd_QName *                     val;
3050
3051 0         val = xsd_QName_array_push(inst);
3052         
3053 0         val->local = xmlSplitQName2(str, &prefix);
3054 0         val->Namespace = xmlTextReaderLookupNamespace(
3055             handle->reader, prefix);
3056
3057 0         globus_free(str);
3058 0         qnlist = globus_list_rest(qnlist);
3059     }
3060     
3061 0     globus_list_destroy_all(qnames, globus_libc_free);
3062     
3063  exit:
3064
3065 0     GlobusSoapMessageDebugExit();
3066 0     return result;
3067 }
3068
3069 globus_result_t
3070 globus_soap_message_deserialize_QName_attribute_list(
3071     globus_soap_message_handle_t        handle,
3072     const xsd_QName *                   attr_qname,
3073     xsd_QName_array *                   inst)
3074 0 {
3075 0     const xmlChar *                     attr_ns = NULL;
3076 0     const xmlChar *                     local_ns = NULL;
3077 0     char *                              tmp_value;
3078 0     globus_list_t *                     qnames;
3079 0     globus_list_t *                     qnlist;
3080 0     globus_result_t                     result = GLOBUS_SUCCESS;
3081 0     GlobusFuncName(globus_soap_message_deserialize_QName_attribute_list);
3082 0     GlobusSoapMessageDebugEnter();
3083
3084 0     attr_ns = xmlTextReaderConstString(
3085         handle->reader, attr_qname->Namespace);
3086 0     local_ns = xmlTextReaderConstNamespaceUri(handle->reader);
3087
3088 0     if(attr_ns != local_ns  && (attr_ns != NULL) && (*attr_ns != '\0'))
3089     {
3090 0         tmp_value = xmlTextReaderGetAttributeNs(
3091             handle->reader, attr_qname->local, attr_qname->Namespace);
3092     }
3093     else
3094     {
3095 0         tmp_value = xmlTextReaderGetAttribute(
3096             handle->reader, attr_qname->local);
3097     }
3098
3099 0     if((!tmp_value) || !(*tmp_value))
3100     {
3101 0         result = GlobusSoapMessageErrorDeserializeFailed(
3102             result, &xsd_QName_qname);
3103 0         goto exit;
3104     }
3105
3106 0     globus_i_soap_message_split_qnames(tmp_value, &qnames);
3107 0     qnlist = qnames;
3108 0     while(!globus_list_empty(qnlist))
3109     {
3110 0         char *                          str = globus_list_first(qnlist);
3111 0         xmlChar *                       prefix = NULL;
3112 0         xsd_QName *                     val;
3113
3114 0         val = xsd_QName_array_push(inst);
3115         
3116 0         val->local = xmlSplitQName2(str, &prefix);
3117 0         val->Namespace = xmlTextReaderLookupNamespace(
3118             handle->reader, prefix);
3119
3120 0         globus_free(str);
3121 0         qnlist = globus_list_rest(qnlist);
3122     }
3123     
3124 0     globus_list_destroy_all(qnames, globus_libc_free);
3125     
3126  exit:
3127
3128 0     GlobusSoapMessageDebugExit();
3129 0     return result;
3130 }
3131
3132 globus_result_t
3133 globus_soap_message_deserialize_mark(
3134     globus_soap_message_handle_t        handle,
3135     const char *                        idval)
3136 0 {
3137 0     globus_result_t                     result = GLOBUS_SUCCESS;
3138 0     GlobusFuncName(globus_soap_message_deserialize_mark);
3139 0     GlobusSoapMessageDebugEnter();
3140
3141 0     GlobusSoapMessageDebugPrintf(
3142 GLOBUS_SOAP_MESSAGE_DEBUG_DEBUG,
3143 ("SETTING MARK: %s\n", idval));
3144
3145 0     if(handle->xio_handle)
3146     {
3147 0 result = globus_xio_handle_cntl(
3148     handle->xio_handle, globus_i_soap_message_buffer_driver,
3149     GLOBUS_XIO_BUFFER_SET_READ_MARKER_AT_INDEX,
3150     idval,
3151     xmlTextReaderReadPosition(handle->reader));
3152 0 if(result != GLOBUS_SUCCESS)
3153 {
3154 0     result = GlobusSoapMessageErrorWithMarker(
3155 result, "Failed to set read marker: %s", idval);
3156     goto exit;
3157 }
3158     }
3159
3160  exit:
3161     
3162 0     GlobusSoapMessageDebugExit();
3163 0     return result;