1 /*
2 * Copyright 1999-2006 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include "globus_common.h"
19 #include "libxml/xmlschemas.h"
20 #include "libxml/schemasInternals.h"
21 #include "libxml/uri.h"
22
23 #include "wsdl.h"
24
25 #include "globus_wsdl_template.h"
26 #include "globus_i_wsdl_parser.h"
27 #include "globus_wsdl_config.h"
28
29 #include "js/jsstddef.h"
30 #include <errno.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include "js/jstypes.h"
35 #include "js/jsarena.h"
36 #include "js/jsutil.h"
37 #include "js/jsprf.h"
38 #include "js/jsapi.h"
39 #include "js/jsatom.h"
40 #include "js/jscntxt.h"
41 #include "js/jsdbgapi.h"
42 #include "js/jsemit.h"
43 #include "js/jsfun.h"
44 #include "js/jsgc.h"
45 #include "js/jslock.h"
46 #include "js/jsobj.h"
47 #include "js/jsparse.h"
48 #include "js/jsscope.h"
49 #include "js/jsscript.h"
50
51 #include <sys/types.h>
52 #include <sys/stat.h>
53 #include <errno.h>
54
55 #ifdef WIN32
56 #define FILE_SEPARATOR "\\"
57 #else
58 #define FILE_SEPARATOR "/"
59 #endif
60
61 #define GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED (1 << 30)
62
63 size_t gStackChunkSize = 8192;
64
65 typedef struct _StreamContext StreamContext;
66 struct _StreamContext
67 {
68 FILE * error_stream;
69 FILE * out_stream;
70 StreamContext * next;
71 };
72
73 typedef struct _Template Template;
74 struct _Template
75 {
76 char * filename;
77 char * buffer;
78 size_t length;
79 };
80
81 typedef struct _PrivateContext PrivateContext;
82 struct _PrivateContext
83 {
84 StreamContext * streams;
85 globus_result_t result;
86 globus_hashtable_t nsmap;
87 int free_nsmap;
88 globus_hashtable_t templates;
89 char * outdir;
90 globus_list_t * template_paths;
91 };
92
93 static
94 void TemplateFree(
95 void * template);
96
97 static JSBool
98 LoadTemplate(
99 JSContext * ctx,
100 JSObject * obj,
101 uintN argc,
102 jsval * argv,
103 jsval * rval);
104
105 static JSBool
106 FileExists(
107 JSContext * ctx,
108 JSObject * obj,
109 uintN argc,
110 jsval * argv,
111 jsval * rval);
112
113 static JSBool
114 CreateSubDir(
115 JSContext * ctx,
116 JSObject * obj,
117 uintN argc,
118 jsval * argv,
119 jsval * rval);
120
121 static JSBool
122 URIBasePath(
123 JSContext * ctx,
124 JSObject * obj,
125 uintN argc,
126 jsval * argv,
127 jsval * rval);
128
129 static JSBool
130 NamespaceToPrefix(
131 JSContext * cx,
132 JSObject * obj,
133 uintN argc,
134 jsval * argv,
135 jsval * rval);
136
137 static JSBool
138 Debug(
139 JSContext * cx,
140 JSObject * obj,
141 uintN argc,
142 jsval * argv,
143 jsval * rval);
144
145 static JSBool
146 Abort(
147 JSContext * cx,
148 JSObject * obj,
149 uintN argc,
150 jsval * argv,
151 jsval * rval);
152
153 static JSBool
154 Print(
155 JSContext * cx,
156 JSObject * obj,
157 uintN argc,
158 jsval * argv,
159 jsval * rval);
160
161 static JSBool
162 Error(
163 JSContext * cx,
164 JSObject * obj,
165 uintN argc,
166 jsval * argv,
167 jsval * rval);
168
169 static JSBool
170 CanonicalizeString(
171 JSContext * cx,
172 JSObject * obj,
173 uintN argc,
174 jsval * argv,
175 jsval * rval);
176
177 static
178 JSBool
179 GetNamespaces(
180 JSContext * cx,
181 xmlNsPtr ns,
182 jsval * vp)
183 0 {
184 0 *vp = JSVAL_VOID;
185
186 0 if (ns != NULL)
187 {
188 jsval * nsmaps;
189 0 size_t count = 0;
190 xmlNs * tmp;
191 char * tmpstr;
192
193 0 for (tmp = ns; tmp != NULL; tmp = tmp->next)
194 {
195 0 count++;
196 }
197
198 0 nsmaps = malloc(count * sizeof(jsval));
199 0 if (nsmaps == NULL)
200 {
201 0 JS_ReportError(cx,
202 "Out of memory getting namespace list");
203 0 return JS_FALSE;
204 }
205
206 0 count = 0;
207 0 for (tmp = ns; tmp != NULL; tmp = tmp->next)
208 {
209 0 if (!tmp->prefix)
210 {
211 0 nsmaps[count++] = STRING_TO_JSVAL(JS_InternString(cx, tmpstr));
212 }
213 else
214 {
215 0 tmpstr = globus_common_create_string(
216 "%s=%s",
217 tmp->prefix,
218 tmp->href);
219 0 nsmaps[count++] = STRING_TO_JSVAL(JS_InternString(cx, tmpstr));
220 0 free(tmpstr);
221 }
222 }
223 0 *vp = OBJECT_TO_JSVAL(JS_NewArrayObject(cx, count, nsmaps));
224 }
225 0 return JS_TRUE;
226 }
227
228 #define DEF_GET_PROP(_PREFIX_) \
229 static JSBool \
230 _PREFIX_ ## Getter( \
231 JSContext * cx, \
232 JSObject * obj, \
233 jsval id, \
234 jsval * vp)
235
236 #define DEF_ENUM_PROP(_PREFIX_) \
237 static JSBool \
238 _PREFIX_ ## Enumerate( \
239 JSContext * cx, \
240 JSObject * obj, \
241 JSIterateOp enum_op, \
242 jsval * statep, \
243 jsid * idp)
244
245 #define DEF_RES_PROP(_PREFIX_) \
246 static JSBool \
247 _PREFIX_ ## Resolve( \
248 JSContext * cx, \
249 JSObject * obj, \
250 jsval id)
251
252 #define DEF_CLASS(_PREFIX_) \
253 static JSClass _PREFIX_ ## _class = \
254 { \
255 #_PREFIX_, JSCLASS_HAS_PRIVATE|JSCLASS_NEW_RESOLVE, \
256 JS_PropertyStub, JS_PropertyStub, \
257 _PREFIX_ ## Getter, JS_PropertyStub, \
258 JS_EnumerateStub, JS_ResolveStub, \
259 JS_ConvertStub, JS_FinalizeStub \
260 }; \
261 static JSObject * _PREFIX_ ## Class
262
263 #define DEF_LISTCLASS(_PREFIX_) \
264 static JSClass _PREFIX_ ## _class = \
265 { \
266 #_PREFIX_, JSCLASS_NEW_ENUMERATE|JSCLASS_HAS_PRIVATE, \
267 JS_PropertyStub, JS_PropertyStub, \
268 _PREFIX_ ## Getter, JS_PropertyStub, \
269 (JSEnumerateOp) _PREFIX_ ## Enumerate, \
270 _PREFIX_ ## Resolve, \
271 JS_ConvertStub, JS_FinalizeStub \
272 }
273
274 #define DEF_PROPS(_PREFIX_) \
275 extern JSPropertySpec _PREFIX_ ## _properties[]
276
277 #define DEF_LIST(_PREFIX_) \
278 DEF_ENUM_PROP(_PREFIX_); \
279 DEF_GET_PROP(_PREFIX_); \
280 DEF_RES_PROP(_PREFIX_); \
281 DEF_LISTCLASS(_PREFIX_)
282
283 #define DEF_OBJECT(_PREFIX_) \
284 DEF_GET_PROP(_PREFIX_); \
285 DEF_PROPS(_PREFIX_); \
286 DEF_CLASS(_PREFIX_)
287
288 DEF_OBJECT(xsdType);
289 DEF_OBJECT(xsdAttr);
290 DEF_OBJECT(xsdElement);
291 DEF_OBJECT(xsdWildcard);
292 DEF_OBJECT(xsdFacet);
293
294 DEF_OBJECT(xsdQName);
295 DEF_OBJECT(part);
296 DEF_OBJECT(operation);
297 DEF_OBJECT(binding);
298 DEF_OBJECT(portType);
299 DEF_OBJECT(message);
300 DEF_OBJECT(param);
301 DEF_OBJECT(fault);
302 DEF_OBJECT(port);
303 DEF_OBJECT(service);
304 DEF_OBJECT(bindingOperation);
305 DEF_OBJECT(bindingOperationFault);
306
307 DEF_OBJECT(soapBinding);
308 DEF_OBJECT(soapOperation);
309 DEF_OBJECT(soapBindingParam);
310 DEF_OBJECT(soapBody);
311 DEF_OBJECT(soapFault);
312 DEF_OBJECT(soapHeader);
313 DEF_OBJECT(soapAddress);
314
315 DEF_GET_PROP(xsdEnum);
316 DEF_CLASS(xsdEnum);
317
318 DEF_PROPS(xsdTypeEnum);
319 DEF_PROPS(xsdContentTypeEnum);
320 DEF_PROPS(xsdAttrEnum);
321 DEF_PROPS(operationTypeEnum);
322 DEF_PROPS(bindingType);
323 DEF_PROPS(soapOperationStyleType);
324 DEF_PROPS(soapUseType);
325
326 DEF_LIST(xsdSubTypes);
327 DEF_LIST(xsdAttrs);
328 DEF_LIST(xsdQNames);
329 DEF_LIST(parts);
330 DEF_LIST(operations);
331 DEF_LIST(faults);
332 DEF_LIST(ports);
333 DEF_LIST(bindingOperations);
334 DEF_LIST(bindingOperationFaults);
335 DEF_LIST(xsdFacets);
336
337 static void
338 internal_ErrorReporter(
339 JSContext * cx,
340 const char * message,
341 JSErrorReport * report);
342
343 static JSFunctionSpec functions_defs[] =
344 {
345 {"load", LoadTemplate, 0},
346 {"file_exists", FileExists, 0},
347 {"uri_base_path", URIBasePath, 0},
348 {"create_subdir", CreateSubDir, 0},
349 {"debug", Debug, 0},
350 {"abort", Abort, 0},
351 {"error", Error, 0},
352 {"print", Print, 0},
353 {"canonical", CanonicalizeString, 0},
354 {"NStoP", NamespaceToPrefix, 0},
355 {0}
356 };
357
358 static JSClass global_class =
359 {
360 "global", JSCLASS_NEW_RESOLVE,
361 JS_PropertyStub, JS_PropertyStub,
362 JS_PropertyStub, JS_PropertyStub,
363 JS_EnumerateStub, JS_ResolveStub,
364 JS_ConvertStub, JS_FinalizeStub
365 };
366
367 static JSClass basic_class =
368 {
369 "basic", JSCLASS_NEW_RESOLVE,
370 JS_PropertyStub, JS_PropertyStub,
371 JS_PropertyStub, JS_PropertyStub,
372 JS_EnumerateStub, JS_ResolveStub,
373 JS_ConvertStub, JS_FinalizeStub
374 };
375
376 typedef struct _ScannerData ScannerData;
377 struct _ScannerData
378 {
379 wsdlSchemaPtr schema;
380 xmlSchemaPtr xsdSchema;
381 JSContext * context;
382 JSObject * global;
383 JSObject * types;
384 JSObject * elements;
385 JSObject * local_elements;
386 JSObject * attributes;
387 JSObject * local_attributes;
388 JSObject * messages;
389 JSObject * portTypes;
390 JSObject * bindings;
391 JSObject * services;
392 globus_result_t result;
393 };
394
395 static
396 void
397 globus_i_wsdl_parser_import_scanner(
398 void * payload,
399 void * data,
400 xmlChar * name);
401
402 static
403 void
404 globus_i_wsdl_parser_type_scanner(
405 void * payload,
406 void * data,
407 xmlChar * name);
408
409 static
410 void
411 globus_i_wsdl_parser_element_scanner(
412 void * payload,
413 void * data,
414 xmlChar * name);
415
416 static
417 void
418 globus_i_wsdl_parser_attribute_scanner(
419 void * payload,
420 void * data,
421 xmlChar * name);
422
423 static
424 void
425 globus_i_wsdl_parser_message_scanner(
426 void * payload,
427 void * data,
428 xmlChar * name);
429
430 static
431 void
432 globus_i_wsdl_parser_portType_scanner(
433 void * payload,
434 void * data,
435 xmlChar * name);
436
437 static
438 void
439 globus_i_wsdl_parser_binding_scanner(
440 void * payload,
441 void * data,
442 xmlChar * name);
443
444 static
445 void
446 globus_i_wsdl_parser_service_scanner(
447 void * payload,
448 void * data,
449 xmlChar * name);
450
451 static
452 void
453 globus_i_wsdl_parser_wsdl_imports_scanner(
454 void * payload,
455 void * data,
456 xmlChar * name);
457
458 static
459 globus_result_t
460 globus_i_wsdl_js_load_schema(
461 JSContext * cx,
462 wsdlSchemaPtr schema);
463
464 static
465 globus_result_t
466 globus_i_wsdl_execute_script(
467 JSContext * ctx,
468 JSObject * glob,
469 const char * tmpl_filename,
470 const char * out_filename,
471 const char * out_dir,
472 globus_hashtable_t nsmap,
473 globus_list_t * template_paths);
474
475 static
476 JSString *
477 globus_l_wsdl_jscript_qname_string(
478 JSContext * ctx,
479 const xmlChar * href,
480 const xmlChar * local);
481
482 static
483 void
484 globus_i_wsdl_parser_classes_init(
485 JSContext * cx,
486 JSObject * glob)
487 34 {
488 34 xsdTypeClass = JS_InitClass(cx, glob, NULL, &xsdType_class, NULL, 0,
489 xsdType_properties, NULL, NULL, NULL);
490
491 34 xsdElementClass = JS_InitClass(cx, glob, NULL, &xsdElement_class, NULL, 0,
492 xsdElement_properties, NULL, NULL, NULL);
493
494 34 xsdAttrClass = JS_InitClass(cx, glob, NULL, &xsdAttr_class, NULL, 0,
495 xsdAttr_properties, NULL, NULL, NULL);
496
497 34 xsdWildcardClass = JS_InitClass(cx, glob, NULL, &xsdWildcard_class, NULL, 0,
498 xsdWildcard_properties, NULL, NULL, NULL);
499
500 34 xsdFacetClass = JS_InitClass(cx, glob, NULL, &xsdFacet_class, NULL, 0,
501 xsdFacet_properties, NULL, NULL, NULL);
502
503 34 messageClass = JS_InitClass(cx, glob, NULL, &message_class, NULL, 0,
504 message_properties, NULL, NULL, NULL);
505
506 34 portTypeClass = JS_InitClass(cx, glob, NULL, &portType_class, NULL, 0,
507 portType_properties, NULL, NULL, NULL);
508
509 34 operationClass = JS_InitClass(cx, glob, NULL, &operation_class, NULL, 0,
510 operation_properties, NULL, NULL, NULL);
511
512 34 bindingClass = JS_InitClass(cx, glob, NULL, &binding_class, NULL, 0,
513 binding_properties, NULL, NULL, NULL);
514
515 34 serviceClass = JS_InitClass(cx, glob, NULL, &service_class, NULL, 0,
516 service_properties, NULL, NULL, NULL);
517
518 34 bindingOperationClass = JS_InitClass(cx, glob, NULL,
519 &bindingOperation_class, NULL, 0,
520 bindingOperation_properties,
521 NULL, NULL, NULL);
522
523 34 soapBindingClass = JS_InitClass(cx, glob, NULL, &soapBinding_class, NULL, 0,
524 soapBinding_properties, NULL, NULL, NULL);
525
526 34 soapOperationClass = JS_InitClass(cx, glob, NULL, &soapOperation_class,
527 NULL, 0, soapOperation_properties,
528 NULL, NULL, NULL);
529
530 34 }
531
532 static JSBool
533 URIBasePath(
534 JSContext * cx,
535 JSObject * obj,
536 uintN argc,
537 jsval * argv,
538 jsval * rval)
539 32 {
540 char * uri_base_path;
541 JSString * str;
542 char * uri_string;
543 xmlURIPtr uri_handle;
544 32 JSBool res = JS_TRUE;
545 GlobusFuncName(URIBasePath);
546 32 GlobusWSDLDebugEnter();
547
548 32 if(argc < 1)
549 {
550 0 JS_ReportError(cx,
551 "Wrong number of arguments "
552 "passed to function: %s",
553 argc, 2, "load(template, outfile)");
554 0 res = JS_FALSE;
555 0 goto exit;
556 }
557
558 32 str = JS_ValueToString(cx, argv[0]);
559 32 if(!str)
560 {
561 0 JS_ReportError(cx,
562 "Failed to load template");
563 0 res = JS_FALSE;
564 0 goto exit;
565 }
566
567 32 uri_string = globus_common_create_string("%*s",
568 JS_GetStringLength(str),
569 JS_GetStringBytes(str));
570
571 32 uri_handle = xmlParseURI(uri_string);
572 32 if(!uri_handle)
573 {
574 0 JS_ReportError(cx, "Failed to parse uri: %s", uri_string);
575 0 res = JS_FALSE;
576 0 goto exit;
577 }
578
579 32 uri_base_path = uri_handle->path;
580 32 if (uri_base_path != NULL)
581 {
582 96 while((*uri_base_path) == '/')
583 {
584 32 ++uri_base_path;
585 }
586
587 32 str = JS_InternString(cx, (const char *) uri_base_path);
588 32 *rval = STRING_TO_JSVAL(str);
589 }
590 else
591 {
592 0 *rval = JSVAL_VOID;
593 }
594
595 32 exit:
596 32 GlobusWSDLDebugExit();
597 32 return res;
598 }
599
600 static JSBool
601 CreateSubDir(
602 JSContext * cx,
603 JSObject * obj,
604 uintN argc,
605 jsval * argv,
606 jsval * rval)
607 12 {
608 JSString * str;
609 char * dir_string;
610 12 JSBool res = JS_TRUE;
611 12 PrivateContext * private = NULL;
612 GlobusFuncName(CreateSubDir);
613 12 GlobusWSDLDebugEnter();
614
615 12 if(argc < 1)
616 {
617 0 JS_ReportError(cx,
618 "Wrong number of arguments "
619 "passed to function: %s",
620 argc, 2, "load(template, outfile)");
621 0 res = JS_FALSE;
622 0 goto exit;
623 }
624
625 12 private = (PrivateContext *) JS_GetContextPrivate(cx);
626
627 12 str = JS_ValueToString(cx, argv[0]);
628 12 if(!str)
629 {
630 0 JS_ReportError(cx,
631 "Failed to load template");
632 0 res = JS_FALSE;
633 0 goto exit;
634 }
635
636 12 dir_string = globus_common_create_string(
637 "%s%s%*s",
638 (private->outdir ? private->outdir : ""),
639 (private->outdir ? FILE_SEPARATOR : ""),
640 (int) JS_GetStringLength(str),
641 JS_GetStringBytes(str));
642
643 12 if(mkdir(dir_string, 00770) < 0)
644 {
645 11 if(errno != EEXIST)
646 {
647 globus_object_t * errobj;
648 char * errstr;
649
650 0 errobj = globus_error_wrap_errno_error(
651 GLOBUS_WSDL_PARSER_MODULE,
652 errno,
653 GLOBUS_WSDL_ERROR_JSRUNTIME,
654 __FILE__,
655 _globus_func_name,
656 __LINE__,
657 "Failed to create directory: %s",
658 dir_string);
659 0 errstr = globus_error_print_friendly(errobj);
660 0 globus_object_free(errobj);
661 0 JS_ReportError(cx, "subdir %s creation failed:%d:%s",
662 dir_string, errno, errstr);
663 0 globus_free(errstr);
664 0 free(dir_string);
665 0 res = JS_FALSE;
666 0 goto exit;
667 }
668 }
669
670 12 free(dir_string);
671
672 12 *rval = JSVAL_NULL;
673
674 12 exit:
675 12 GlobusWSDLDebugExit();
676 12 return res;
677 }
678
679 static JSBool
680 LoadTemplate(
681 JSContext * cx,
682 JSObject * obj,
683 uintN argc,
684 jsval * argv,
685 jsval * rval)
686 2201 {
687 2201 char * script_buffer = NULL;
688 2201 size_t script_length = 0;
689 2201 jsval result = 0;
690 2201 JSBool res = JS_TRUE;
691 2201 char * error = NULL;
692 2201 char * path = NULL;
693 JSString * str;
694 char filename[500];
695 char out_filename[500];
696 2201 FILE * out_stream = NULL;
697 2201 PrivateContext * private = NULL;
698 2201 Template * template = NULL;
699 2201 StreamContext * new_streams = NULL;
700 2201 StreamContext * tmp_streams = NULL;
701 2201 globus_list_t * paths = NULL;
702 struct stat statbuf;
703 2201 int filename_found = 0;
704 GlobusFuncName(LoadTemplate);
705 2201 GlobusWSDLDebugEnter();
706
707 2201 if(argc < 1)
708 {
709 0 JS_ReportError(cx,
710 "Wrong number of arguments "
711 "passed to function: %s",
712 argc, 2, "load(template, outfile)");
713 0 res = JS_FALSE;
714 0 goto exit;
715 }
716
717 2201 str = JS_ValueToString(cx, argv[0]);
718 2201 if(!str)
719 {
720 0 JS_ReportError(cx,
721 "Failed to load template");
722 0 res = JS_FALSE;
723 0 goto exit;
724 }
725
726 2201 private = (PrivateContext *) JS_GetContextPrivate(cx);
727 2201 paths = private->template_paths;
728
729 6527 while(paths)
730 {
731 4292 path = globus_list_first(paths);
732 4292 sprintf(filename, "%s/%*s",
733 path, (int) JS_GetStringLength(str),
734 JS_GetStringBytes(str));
735
736 4292 if(private->templates)
737 {
738 4225 template = globus_hashtable_lookup(&private->templates, filename);
739 4225 if(template)
740 {
741 1683 filename_found = 1;
742 1683 break;
743 }
744 }
745
746 2609 if(stat(filename, &statbuf))
747 {
748 2125 if(errno != ENOENT)
749 {
750 char * errstr;
751 0 result = GlobusWSDLErrorAccessingTemplateFile(errno, filename);
752 0 errstr = globus_error_print_chain(globus_error_get(result));
753
754 0 JS_ReportError(cx, errstr);
755 0 res = JS_FALSE;
756 0 goto exit;
757 }
758 }
759 else
760 {
761 484 filename_found = 1;
762 484 break;
763 }
764
765 2125 paths = globus_list_rest(paths);
766 }
767
768 2201 if(!filename_found)
769 {
770 34 sprintf(filename, "%*s", (int) JS_GetStringLength(str), JS_GetStringBytes(str));
771 34 if(private->templates)
772 {
773 0 template = globus_hashtable_lookup(&private->templates, filename);
774 }
775 }
776
777 2201 if(!template)
778 {
779 518 if(stat(filename, &statbuf))
780 {
781 char * errstr;
782 0 result = GlobusWSDLErrorAccessingTemplateFile(errno, filename);
783 0 errstr = globus_error_print_chain(globus_error_get(result));
784
785 0 JS_ReportError(cx, errstr);
786 0 res = JS_FALSE;
787 0 goto exit;
788 }
789
790 518 res = globus_wsdl_template_get_jsbuf(
791 (const char *) filename, &script_buffer, &script_length, &error,
792 '@', '$');
793 518 if(res != 0)
794 {
795 0 if(error)
796 {
797 0 JS_ReportError(cx, "%s", error);
798 0 free(error);
799 }
800 0 res = JS_FALSE;
801 0 goto exit;
802 }
803
804 518 GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_TEMPLATE,
805 ("TEMPLATE BUFFER:"
806 "\n----------------------\n"));
807 518 GlobusWSDLDebugWrite(GLOBUS_WSDL_DEBUG_TEMPLATE,
808 script_length, script_buffer);
809 518 GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_TEMPLATE,
810 ("\n----------------------\n"));
811
812 518 template = globus_malloc(sizeof(Template));
813 518 if(!template)
814 {
815 0 JS_ReportError(cx,
816 "Memory allocation failed.");
817 0 res = JS_FALSE;
818 0 goto exit;
819 }
820 518 template->filename = globus_libc_strdup(filename);
821 518 template->buffer = script_buffer;
822 518 template->length = script_length;
823
824 518 if(!private->templates)
825 {
826 34 globus_hashtable_init(&private->templates, 10,
827 globus_hashtable_string_hash,
828 globus_hashtable_string_keyeq);
829 }
830
831 518 globus_hashtable_insert(&private->templates, template->filename, template);
832 }
833 else
834 {
835 1683 script_buffer = template->buffer;
836 1683 script_length = template->length;
837 }
838
839 2201 if(argc > 1 && (argv[1] != JSVAL_NULL))
840 {
841 1936 str = JS_ValueToString(cx, argv[1]);
842 1936 if(!str)
843 {
844 0 JS_ReportError(cx,
845 "Failed to load template %s. "
846 "Second argument to load function should "
847 "be output filename but is not of type string.",
848 filename);
849 0 res = JS_FALSE;
850 0 goto exit;
851 }
852
853 1936 sprintf(out_filename, "%s%s%*s",
854 (private->outdir ? private->outdir : ""),
855 (private->outdir ? FILE_SEPARATOR : ""),
856 (int) JS_GetStringLength(str),
857 JS_GetStringBytes(str));
858
859 1936 out_stream = fopen(out_filename, "w+");
860 1936 if(!out_stream)
861 {
862 0 JS_ReportError(cx, "Failed to open output file %s for writing",
863 out_filename);
864 0 res = JS_FALSE;
865 0 goto exit;
866 }
867 }
868
869 2201 globus_assert(private && private->streams);
870
871 2201 new_streams = (StreamContext *) malloc(sizeof(StreamContext));
872 2201 if(!new_streams)
873 {
874 0 JS_ReportOutOfMemory(cx);
875 0 res = JS_FALSE;
876 0 goto exit;
877 }
878
879 2201 memset(new_streams, 0, sizeof(StreamContext));
880
881 2201 new_streams->next = private->streams;
882 2201 new_streams->error_stream = private->streams->error_stream;
883 2201 new_streams->out_stream = out_stream;
884 2201 private->streams = new_streams;
885
886 2201 JS_SetContextPrivate(cx, (void *) private);
887
888 2201 res = JS_EvaluateScript(cx, obj, script_buffer,
889 script_length, filename, 0, &result);
890 2201 if(!res)
891 {
892 0 if (JS_IsExceptionPending(cx))
893 {
894 0 res = JS_GetPendingException(cx, &result);
895
896 0 if (res && JSVAL_IS_STRING(result))
897 {
898 0 JS_ClearPendingException(cx);
899 0 JS_ReportError(cx, "Failed to evaluate script\n %s\n %s",
900 filename,
901 JS_GetStringBytes(JSVAL_TO_STRING(result)));
902 0 res = JS_FALSE;
903 0 goto exit;
904 }
905 }
906 0 JS_ReportError(cx, "Failed to evaluate script\n %s", filename);
907 0 res = JS_FALSE;
908 0 goto exit;
909 }
910 2201 private = JS_GetContextPrivate(cx);
911 2201 globus_assert(private);
912
913 2201 if(private->streams->out_stream)
914 {
915 1936 fclose(private->streams->out_stream);
916 }
917
918 2201 tmp_streams = private->streams;
919 2201 if(tmp_streams)
920 {
921 2201 private->streams = private->streams->next;
922 2201 free(tmp_streams);
923 }
924
925 2201 JS_SetContextPrivate(cx, (void *) private);
926
927 2201 exit:
928 2201 GlobusWSDLDebugExit();
929 2201 return res;
930 }
931
932 static JSBool
933 FileExists(
934 JSContext * cx,
935 JSObject * obj,
936 uintN argc,
937 jsval * argv,
938 jsval * rval)
939 1800 {
940 1800 JSBool res = JS_TRUE;
941 JSString * str;
942 char filename[500];
943 1800 PrivateContext * private = NULL;
944 struct stat statbuf;
945 GlobusFuncName(FileExists);
946 1800 GlobusWSDLDebugEnter();
947
948 1800 if(argc < 1)
949 {
950 0 JS_ReportError(cx,
951 "Wrong number of arguments "
952 "passed to function: %s",
953 argc, 2, "file_exists(filename)");
954 0 res = JS_FALSE;
955 0 goto exit;
956 }
957
958 1800 str = JS_ValueToString(cx, argv[0]);
959 1800 if(!str)
960 {
961 0 JS_ReportError(cx,
962 "Failed to load filename");
963 0 res = JS_FALSE;
964 0 goto exit;
965 }
966
967 1800 private = (PrivateContext *) JS_GetContextPrivate(cx);
968
969 1800 sprintf(filename, "%s%s%*s",
970 (private->outdir ? private->outdir : ""),
971 (private->outdir ? FILE_SEPARATOR : ""),
972 (int) JS_GetStringLength(str),
973 JS_GetStringBytes(str));
974
975 1800 if(!stat(filename, &statbuf))
976 {
977 6 *rval = BOOLEAN_TO_JSVAL(JS_TRUE);
978 }
979 else
980 {
981 1794 *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
982 }
983
984
985 1800 exit:
986 1800 GlobusWSDLDebugExit();
987 1800 return res;
988 }
989
990 static JSBool
991 CanonicalizeString(
992 JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
993 48074 {
994 uintN i, n;
995 JSString *str;
996 char *s, *news;
997
998 48074 if(argc < 1)
999 {
1000 0 JS_ReportError(cx, "function canonical called with no parameters");
1001 0 return JS_FALSE;
1002 }
1003
1004 48074 if(JSVAL_IS_NULL(argv[0]) || JSVAL_IS_VOID(argv[0]))
1005 {
1006 13 str = JS_InternString(cx, "NULL");
1007 13 *rval = STRING_TO_JSVAL(str);
1008 13 return JS_TRUE;
1009 }
1010
1011 48061 if(!JSVAL_IS_STRING(argv[0]))
1012 {
1013 0 JS_ReportError(cx, "parameter passed to canonical is not a string");
1014 0 return JS_FALSE;
1015 }
1016
1017 48061 str = JSVAL_TO_STRING(argv[0]);
1018 48061 n = JSSTRING_LENGTH(str);
1019 48061 news = (char *) JS_malloc(cx, (n + 1) * sizeof(char));
1020 48061 if(!news)
1021 {
1022 0 JS_ReportOutOfMemory(cx);
1023 0 return JS_FALSE;
1024 }
1025
1026 48061 s = JS_GetStringBytes(str);
1027 794461 for(i = 0; i < n; ++i)
1028 {
1029 746400 switch(s[i])
1030 {
1031 case '-':
1032 3 news[i] = '_';
1033 3 break;
1034 case ' ':
1035 247 news[i] = '_';
1036 247 break;
1037 default:
1038 746150 news[i] = s[i];
1039 break;
1040 }
1041 }
1042
1043 48061 news[n] = 0;
1044 48061 str = JS_InternString(cx, news);
1045 48061 JS_free(cx, news);
1046 48061 if(!str)
1047 {
1048 0 JS_ReportError(cx, "Failed to internalize string in canonical function");
1049 0 return JS_FALSE;
1050 }
1051
1052 48061 *rval = STRING_TO_JSVAL(str);
1053 48061 return JS_TRUE;
1054 }
1055
1056 static JSBool
1057 NamespaceToPrefix(JSContext *cx, JSObject *obj,
1058 uintN argc, jsval *argv, jsval *rval)
1059 34404 {
1060 globus_hashtable_t nsmap;
1061 PrivateContext * ctx;
1062 JSString * str;
1063 char * prefix;
1064
1065 34404 ctx = (PrivateContext *) JS_GetContextPrivate(cx);
1066
1067 34404 nsmap = (globus_hashtable_t) ctx->nsmap;
1068 34404 if(!nsmap)
1069 {
1070 0 str = JS_InternString(cx, "");
1071 0 if(!str)
1072 {
1073 0 JS_ReportError(cx,
1074 "Failed to access namespace mapping table in NStoP");
1075 0 return JS_FALSE;
1076 }
1077
1078 0 *rval = STRING_TO_JSVAL(str);
1079 0 return JS_TRUE;
1080 }
1081
1082 34404 str = JS_ValueToString(cx, argv[0]);
1083 34404 if (!str)
1084 {
1085 0 JS_ReportError(cx, "Parameter passed to NStoP is not a string");
1086 0 return JS_FALSE;
1087 }
1088
1089 34404 prefix = globus_wsdl_config_get_property(nsmap,
1090 (const char *)JS_GetStringBytes(str));
1091 34404 if(!prefix)
1092 {
1093 176 str = JS_InternString(cx, "");
1094 176 if(!str)
1095 {
1096 0 JS_ReportError(cx, "NStoP failed: could not internalize string");
1097 0 return JS_FALSE;
1098 }
1099
1100 176 *rval = STRING_TO_JSVAL(str);
1101 176 return JS_TRUE;
1102 }
1103
1104 34228 str = JS_InternString(cx, prefix);
1105 34228 *rval = STRING_TO_JSVAL(str);
1106 34228 return JS_TRUE;
1107 }
1108
1109
1110 static JSBool
1111 Debug(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1112 14270 {
1113 uintN i, n;
1114 JSString *str;
1115
1116 28540 for (i = n = 0; i < argc; i++) {
1117 14270 str = JS_ValueToString(cx, argv[i]);
1118 14270 if (!str)
1119 {
1120 0 JS_ReportError(
1121 cx,
1122 "Argument %d to debug function is not a string", i);
1123 0 return JS_FALSE;
1124 }
1125
1126 14270 if (GlobusDebugTrue(GLOBUS_WSDL_PARSER, 2))
1127 {
1128 0 fprintf(stdout, "%s%s", i ? " " : "", JS_GetStringBytes(str));
1129 }
1130 }
1131
1132 14270 n++;
1133 14270 return JS_TRUE;
1134 }
1135
1136 static JSBool
1137 Error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1138 0 {
1139 uintN i, n;
1140 JSString *str;
1141 char error_string[5000];
1142 0 int len = 0;
1143 PrivateContext * ctx_handle;
1144
1145 0 ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1146
1147 0 for (i = n = 0; i < argc; i++) {
1148 0 str = JS_ValueToString(cx, argv[i]);
1149 0 if (!str)
1150 {
1151 0 JS_ReportError(
1152 cx,
1153 "Argument %d to debug function is not a string", i);
1154 0 return JS_FALSE;
1155 }
1156
1157 0 len += sprintf(error_string + len,
1158 "%s%s", i ? " " : "", JS_GetStringBytes(str));
1159 }
1160
1161 0 JS_ReportError(
1162 cx, "ERROR: %s", error_string);
1163 0 return JS_FALSE;
1164 }
1165
1166 static JSBool
1167 Abort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1168 0 {
1169 0 abort();
1170 }
1171
1172 static JSBool
1173 Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1174 515357 {
1175 uintN i, n;
1176 JSString *str;
1177 PrivateContext * ctx_handle;
1178 FILE * ostream;
1179
1180 515357 ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1181 515887 if(!ctx_handle || !ctx_handle->streams || !ctx_handle->streams->out_stream)
1182 {
1183 530 ostream = stdout;
1184 }
1185 else
1186 {
1187 514827 ostream = ctx_handle->streams->out_stream;
1188 }
1189
1190 1030714 for (i = n = 0; i < argc; i++) {
1191 515357 str = JS_ValueToString(cx, argv[i]);
1192 515357 if (!str)
1193 {
1194 0 JS_ReportError(cx, "Argument %d to print function is not a string", i);
1195 0 return JS_FALSE;
1196 }
1197
1198 515357 fprintf(ostream, "%s%s", i ? " " : "", JS_GetStringBytes(str));
1199 }
1200
1201 515357 n++;
1202 515357 *rval = JSVAL_ZERO;
1203 515357 return JS_TRUE;
1204 }
1205
1206
1207 static void
1208 internal_ErrorReporter(
1209 JSContext * cx,
1210 const char * message,
1211 JSErrorReport * report)
1212 0 {
1213 char *prefix, *tmp, *linebuf;
1214 PrivateContext * ctx_handle;
1215 GlobusFuncName(internal_ErrorReporting);
1216 0 GlobusWSDLDebugEnter();
1217
1218 0 ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1219 0 if(!ctx_handle)
1220 {
1221 0 goto exit;
1222 }
1223
1224 0 if (!report) {
1225 0 ctx_handle->result = globus_error_put(
1226 globus_error_construct_error(
1227 GLOBUS_WSDL_PARSER_MODULE,
1228 (ctx_handle->result != GLOBUS_NULL)
1229 ? globus_error_get(ctx_handle->result)
1230 : NULL,
1231 GLOBUS_WSDL_ERROR_JAVASCRIPT,
1232 __FILE__,
1233 _globus_func_name,
1234 __LINE__,
1235 "%s\n",
1236 message));
1237 0 goto exit;
1238 }
1239
1240 /* Conditionally ignore reported warnings. */
1241 0 if (JSREPORT_IS_WARNING(report->flags) &&
1242 !GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1243 {
1244 0 goto exit;
1245 }
1246
1247 0 prefix = NULL;
1248 0 if (report->filename)
1249 {
1250 0 prefix = JS_smprintf("%s:", report->filename);
1251 }
1252
1253 0 if (JSREPORT_IS_WARNING(report->flags)) {
1254 0 tmp = prefix;
1255 0 prefix = JS_smprintf("%s%swarning: ",
1256 tmp ? tmp : "",
1257 JSREPORT_IS_STRICT(report->flags) ? "strict " : "");
1258 0 JS_free(cx, tmp);
1259 }
1260
1261 0 linebuf = NULL;
1262 0 if(report->linebuf)
1263 {
1264 0 linebuf = JS_smprintf("%s", report->linebuf);
1265 }
1266
1267 0 if (ctx_handle->result == NULL)
1268 {
1269 0 ctx_handle->result = globus_error_put(
1270 globus_error_construct_error(
1271 GLOBUS_WSDL_PARSER_MODULE,
1272 (ctx_handle->result != GLOBUS_NULL)
1273 ? globus_error_get(ctx_handle->result)
1274 : NULL,
1275 GLOBUS_WSDL_ERROR_JAVASCRIPT,
1276 __FILE__,
1277 _globus_func_name,
1278 __LINE__,
1279 (linebuf ? "%s%s at line:\n\t%s" : "%s%s%s"),
1280 (prefix ? prefix : ""),
1281 (message ? message : ""),
1282 (linebuf ? linebuf : "")));
1283 }
1284
1285 0 if(prefix)
1286 {
1287 0 JS_free(cx, prefix);
1288 }
1289
1290 0 if(linebuf)
1291 {
1292 0 JS_free(cx, linebuf);
1293 }
1294
1295 0 if(JSREPORT_IS_WARNING(report->flags))
1296 {
1297 globus_object_t * warn_obj;
1298 0 warn_obj = globus_error_get(ctx_handle->result);
1299
1300 0 if(GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1301 {
1302 char * warn_str;
1303
1304 0 warn_str = globus_error_print_chain(warn_obj);
1305
1306 0 GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_WARN,
1307 ("%s", warn_str));
1308
1309 0 if(warn_str)
1310 {
1311 0 globus_free(warn_str);
1312 }
1313 }
1314
1315 0 if(warn_obj)
1316 {
1317 0 globus_object_free(warn_obj);
1318 }
1319
1320 0 ctx_handle->result = GLOBUS_SUCCESS;
1321 }
1322
1323 0 exit:
1324
1325 0 GlobusWSDLDebugExit();
1326 0 }
1327
1328 static
1329 JSString *
1330 globus_l_wsdl_jscript_qname_string(
1331 JSContext * ctx,
1332 const xmlChar * href,
1333 const xmlChar * local)
1334 86018 {
1335 JSString * str;
1336 char * qname;
1337 86018 size_t href_length = 0;
1338 86018 size_t local_length = 0;
1339
1340 86018 href_length = href ? strlen((const char *) href) : 0;
1341 86018 local_length = local ? strlen((const char *) local) : 0;
1342
1343 86018 qname = malloc(href_length + local_length + 2);
1344 86018 if(href)
1345 {
1346 82904 memcpy(qname, href, href_length);
1347 82904 qname[href_length] = '#';
1348 82904 href_length++;
1349 }
1350
1351 86018 memcpy(qname + href_length, local, local_length);
1352 86018 qname[href_length + local_length] = 0;
1353
1354 86018 str = JS_InternString(ctx, qname);
1355
1356 86018 return str;
1357 }
1358
1359 globus_result_t
1360 globus_wsdl_execute(
1361 globus_list_t * schema_files,
1362 const char * tmpl_filename,
1363 const char * out_filename,
1364 const char * out_dir,
1365 globus_hashtable_t nsmap,
1366 globus_hashtable_t vars,
1367 globus_list_t * template_paths,
1368 globus_hashtable_t ignorable_namespaces,
1369 globus_hashtable_t include_namespaces,
1370 const int rt_size)
1371 34 {
1372 34 JSRuntime * rt = NULL;
1373 34 JSContext * ctx = NULL;
1374 34 JSObject * glob = NULL;
1375 34 JSObject * ignore = NULL;
1376 34 char * ignore_entry = NULL;
1377 34 JSObject * include = NULL;
1378 34 char * include_entry = NULL;
1379 char ** var_entry;
1380 34 globus_result_t result = GLOBUS_SUCCESS;
1381 34 char * sfile = NULL;
1382 34 globus_list_t * sfiles = NULL;
1383 34 globus_list_t * schemas = NULL;
1384 34 wsdlSchemaPtr schema = NULL;
1385 GlobusFuncName(globus_wsdl_execute);
1386 34 GlobusWSDLDebugEnter();
1387
1388 34 rt = JS_NewRuntime((rt_size <= 0) ? (64L * 1024L * 1024L) : rt_size);
1389 34 if(!rt)
1390 {
1391 0 result = GlobusWSDLErrorJSRuntime(GLOBUS_NULL);
1392 0 goto exit;
1393 }
1394
1395 34 ctx = JS_NewContext(rt, gStackChunkSize);
1396 34 if(!ctx)
1397 {
1398 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1399 0 goto exit;
1400 }
1401
1402 34 JS_SetErrorReporter(ctx, internal_ErrorReporter);
1403
1404 34 glob = JS_NewObject(ctx, &global_class, NULL, NULL);
1405 34 if(!glob)
1406 {
1407 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1408 0 goto exit;
1409 }
1410
1411 34 if(!JS_InitStandardClasses(ctx, glob))
1412 {
1413 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1414 0 goto exit;
1415 }
1416
1417 34 globus_i_wsdl_parser_classes_init(ctx, glob);
1418
1419 34 if(!JS_DefineFunctions(ctx, glob, functions_defs))
1420 {
1421 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1422 0 goto exit;
1423 }
1424
1425 34 sfiles = schema_files;
1426 130 while(sfiles)
1427 {
1428 62 sfile = globus_list_first(sfiles);
1429
1430 62 result = globus_i_wsdl_parse_schema(sfile, &schema);
1431 62 if(result != GLOBUS_SUCCESS)
1432 {
1433 0 result = GlobusWSDLErrorParsingSchema(result, sfile);
1434 0 goto exit;
1435 }
1436
1437 62 result = globus_list_insert(&schemas, schema);
1438 62 if(result != GLOBUS_SUCCESS)
1439 {
1440 0 result = GlobusWSDLErrorParsingSchema(result, sfile);
1441 0 goto exit;
1442 }
1443
1444 62 result = globus_i_wsdl_js_load_schema(ctx, schema);
1445 62 if(result != GLOBUS_SUCCESS)
1446 {
1447 0 result = GlobusWSDLErrorLoadingSchema(result);
1448 0 goto exit;
1449 }
1450
1451 62 sfiles = globus_list_rest(sfiles);
1452 }
1453
1454 34 var_entry = globus_hashtable_first(&vars);
1455 563 while(var_entry)
1456 {
1457 495 if(!JS_DefineProperty(
1458 ctx, glob, var_entry[0],
1459 STRING_TO_JSVAL(JS_InternString(ctx, var_entry[1])),
1460 NULL, NULL,
1461 JSPROP_PERMANENT))
1462 {
1463 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1464 0 goto exit;
1465 }
1466
1467 495 var_entry = globus_hashtable_next(&vars);
1468 }
1469
1470 34 ignore = JS_NewObject(ctx, &basic_class, NULL, glob);
1471 34 if(!ignore)
1472 {
1473 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1474 0 goto exit;
1475 }
1476
1477 34 if(!JS_DefineProperty(
1478 ctx, glob, "ignore_namespaces",
1479 OBJECT_TO_JSVAL(ignore), NULL,
1480 NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1481 {
1482 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1483 0 goto exit;
1484 }
1485
1486 34 ignore_entry = globus_hashtable_first(&ignorable_namespaces);
1487 347 while(ignore_entry)
1488 {
1489 279 if(!JS_DefineProperty(
1490 ctx, ignore, ignore_entry,
1491 STRING_TO_JSVAL(JS_InternString(ctx, ignore_entry)),
1492 NULL, NULL, JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE))
1493 {
1494 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1495 0 goto exit;
1496 }
1497
1498 279 ignore_entry = globus_hashtable_next(&ignorable_namespaces);
1499 }
1500
1501
1502 34 if(!include_namespaces)
1503 {
1504 5 if(!JS_DefineProperty(
1505 ctx, glob, "include_namespaces",
1506 JSVAL_NULL, NULL,
1507 NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1508 {
1509 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1510 0 goto exit;
1511 }
1512 }
1513 else
1514 {
1515
1516 29 include = JS_NewObject(ctx, &basic_class, NULL, glob);
1517 29 if(!include)
1518 {
1519 0 result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1520 0 goto exit;
1521 }
1522
1523 29 if(!JS_DefineProperty(
1524 ctx, glob, "include_namespaces",
1525 OBJECT_TO_JSVAL(include), NULL,
1526 NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1527 {
1528 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1529 0 goto exit;
1530 }
1531
1532 29 include_entry = globus_hashtable_first(&include_namespaces);
1533 113 while(include_entry)
1534 {
1535 55 if(!JS_DefineProperty(
1536 ctx, include, include_entry,
1537 STRING_TO_JSVAL(JS_InternString(ctx, include_entry)),
1538 NULL, NULL,
1539 JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE))
1540 {
1541 0 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1542 0 goto exit;
1543 }
1544
1545 55 include_entry = globus_hashtable_next(&include_namespaces);
1546 }
1547 }
1548
1549 34 result = globus_i_wsdl_execute_script(ctx, glob,
1550 tmpl_filename,
1551 out_filename,
1552 out_dir,
1553 nsmap,
1554 template_paths);
1555 if(result != GLOBUS_SUCCESS)
1556 {
1557 /*result = GlobusWSDLErrorExecutingScript(result, tmpl_filename);*/
1558 34 goto exit;
1559 }
1560
1561 34 exit:
1562
1563 34 if(result != GLOBUS_SUCCESS)
1564 {
1565 0 if(GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1566 {
1567 globus_object_t * error_obj;
1568 char * error_str;
1569
1570 0 error_obj = globus_error_get(result);
1571 0 if(error_obj)
1572 {
1573 0 error_str = globus_error_print_chain(
1574 error_obj);
1575
1576 0 GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_WARN,
1577 ("[DEBUG::WSDL] %s:%d: %s",
1578 _globus_func_name,
1579 __LINE__,
1580 error_str));
1581 0 globus_free(error_str);
1582
1583 0 result = globus_error_put(error_obj);
1584 }
1585 }
1586 }
1587
1588 34 if(schemas)
1589 {
1590 33 globus_list_destroy_all(schemas, (void(*)(void *))wsdlSchemaFree);
1591 }
1592
1593 34 if(ctx)
1594 {
1595 34 JS_DestroyContext(ctx);
1596 }
1597
1598 34 if(rt)
1599 {
1600 34 JS_DestroyRuntime(rt);
1601 }
1602
1603 34 GlobusWSDLDebugExit();
1604 34 return result;
1605 }
1606
1607 static
1608 globus_result_t
1609 globus_i_wsdl_js_load_schema(
1610 JSContext * cx,
1611 wsdlSchemaPtr schema)
1612 62 {
1613 62 JSObject * glob = NULL;
1614 62 JSObject * wsdl = NULL;
1615 62 JSObject * types = NULL;
1616 62 JSObject * elements = NULL;
1617 62 JSObject * local_elements = NULL;
1618 62 JSObject * attributes = NULL;
1619 62 JSObject * local_attributes = NULL;
1620 62 JSObject * messages = NULL;
1621 62 JSObject * portTypes = NULL;
1622 62 JSObject * bindings = NULL;
1623 62 JSObject * services = NULL;
1624 62 JSObject * typeEnum = NULL;
1625 62 JSObject * attrEnum = NULL;
1626 62 JSObject * contentTypeEnum = NULL;
1627 62 JSObject * operationTypeEnum = NULL;
1628 62 JSObject * bindingType = NULL;
1629 62 JSObject * soapOperationStyleType = NULL;
1630 62 JSObject * soapUseType = NULL;
1631 62 ScannerData * data = NULL;
1632 jsval val;
1633 JSString * str;
1634 62 JSBool res = JS_TRUE;
1635 62 globus_result_t result = GLOBUS_SUCCESS;
1636 GlobusFuncName(globus_i_wsdl_js_load_schema);
1637 62 GlobusWSDLDebugEnter();
1638
1639 62 glob = JS_GetGlobalObject(cx);
1640 62 if(!glob)
1641 {
1642 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1643 0 goto exit;
1644 }
1645
1646 62 res = JS_GetProperty(cx, glob, "wsdl", &val);
1647 62 if(val == JSVAL_VOID)
1648 {
1649 33 wsdl = JS_NewObject(cx, &basic_class, NULL, glob);
1650 33 if(!wsdl)
1651 {
1652 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1653 0 goto exit;
1654 }
1655
1656 33 val = OBJECT_TO_JSVAL(wsdl);
1657 33 if(!JS_DefineProperty(cx, glob, "wsdl", val, NULL, NULL,
1658 JSPROP_READONLY|JSPROP_PERMANENT))
1659 {
1660 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1661 0 goto exit;
1662 }
1663 }
1664 else
1665 {
1666 29 wsdl = JSVAL_TO_OBJECT(val);
1667 29 if(!wsdl)
1668 {
1669 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1670 0 goto exit;
1671 }
1672 }
1673
1674 62 res = JS_GetProperty(cx, wsdl, "types", &val);
1675 62 if(val == JSVAL_VOID)
1676 {
1677 33 types = JS_NewObject(cx, &basic_class, NULL, wsdl);
1678 33 if(!types)
1679 {
1680 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1681 0 goto exit;
1682 }
1683
1684 33 val = OBJECT_TO_JSVAL(types);
1685 33 if(!JS_DefineProperty(cx, wsdl, "types", val, NULL, NULL,
1686 JSPROP_READONLY|JSPROP_PERMANENT))
1687 {
1688 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1689 0 goto exit;
1690 }
1691 }
1692 else
1693 {
1694 29 types = JSVAL_TO_OBJECT(val);
1695 29 if(!types)
1696 {
1697 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1698 0 goto exit;
1699 }
1700 }
1701
1702 62 res = JS_GetProperty(cx, wsdl, "elements", &val);
1703 62 if(val == JSVAL_VOID)
1704 {
1705 33 elements = JS_NewObject(cx, &basic_class, NULL, wsdl);
1706 33 if(!elements)
1707 {
1708 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1709 0 goto exit;
1710 }
1711
1712 33 val = OBJECT_TO_JSVAL(elements);
1713 33 if(!JS_DefineProperty(cx, wsdl, "elements", val, NULL, NULL,
1714 JSPROP_READONLY|JSPROP_PERMANENT))
1715 {
1716 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1717 0 goto exit;
1718 }
1719 }
1720 else
1721 {
1722 29 elements = JSVAL_TO_OBJECT(val);
1723 29 if(!elements)
1724 {
1725 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1726 0 goto exit;
1727 }
1728 }
1729
1730 62 res = JS_GetProperty(cx, wsdl, "local_elements", &val);
1731 62 if(val == JSVAL_VOID)
1732 {
1733 33 local_elements = JS_NewObject(cx, &basic_class, NULL, wsdl);
1734 33 if(!local_elements)
1735 {
1736 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1737 0 goto exit;
1738 }
1739
1740 33 val = OBJECT_TO_JSVAL(local_elements);
1741 33 if(!JS_DefineProperty(cx, wsdl, "local_elements", val, NULL, NULL,
1742 JSPROP_READONLY|JSPROP_PERMANENT))
1743 {
1744 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1745 0 goto exit;
1746 }
1747 }
1748 else
1749 {
1750 29 local_elements = JSVAL_TO_OBJECT(val);
1751 29 if(!local_elements)
1752 {
1753 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1754 0 goto exit;
1755 }
1756 }
1757
1758 62 res = JS_GetProperty(cx, wsdl, "attributes", &val);
1759 62 if(val == JSVAL_VOID)
1760 {
1761 33 attributes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1762 33 if(!attributes)
1763 {
1764 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1765 0 goto exit;
1766 }
1767
1768 33 val = OBJECT_TO_JSVAL(attributes);
1769 33 if(!JS_DefineProperty(cx, wsdl, "attributes", val, NULL, NULL,
1770 JSPROP_READONLY|JSPROP_PERMANENT))
1771 {
1772 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1773 0 goto exit;
1774 }
1775 }
1776 else
1777 {
1778 29 attributes = JSVAL_TO_OBJECT(val);
1779 29 if(!attributes)
1780 {
1781 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1782 0 goto exit;
1783 }
1784 }
1785
1786 62 res = JS_GetProperty(cx, wsdl, "local_attributes", &val);
1787 62 if(val == JSVAL_VOID)
1788 {
1789 33 local_attributes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1790 33 if(!local_attributes)
1791 {
1792 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1793 0 goto exit;
1794 }
1795
1796 33 val = OBJECT_TO_JSVAL(local_attributes);
1797 33 if(!JS_DefineProperty(cx, wsdl, "local_attributes", val, NULL, NULL,
1798 JSPROP_READONLY|JSPROP_PERMANENT))
1799 {
1800 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1801 0 goto exit;
1802 }
1803 }
1804 else
1805 {
1806 29 local_attributes = JSVAL_TO_OBJECT(val);
1807 29 if(!local_attributes)
1808 {
1809 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1810 0 goto exit;
1811 }
1812 }
1813
1814 62 res = JS_GetProperty(cx, wsdl, "messages", &val);
1815 62 if(val == JSVAL_VOID)
1816 {
1817 33 messages = JS_NewObject(cx, &basic_class, NULL, wsdl);
1818 33 if(!messages)
1819 {
1820 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1821 0 goto exit;
1822 }
1823
1824 33 val = OBJECT_TO_JSVAL(messages);
1825 33 if(!JS_DefineProperty(cx, wsdl, "messages", val, NULL, NULL,
1826 JSPROP_READONLY|JSPROP_PERMANENT))
1827 {
1828 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1829 0 goto exit;
1830 }
1831 }
1832 else
1833 {
1834 29 messages = JSVAL_TO_OBJECT(val);
1835 29 if(!messages)
1836 {
1837 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1838 0 goto exit;
1839 }
1840 }
1841
1842 62 res = JS_GetProperty(cx, wsdl, "portTypes", &val);
1843 62 if(val == JSVAL_VOID)
1844 {
1845 33 portTypes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1846 33 if(!portTypes)
1847 {
1848 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1849 0 goto exit;
1850 }
1851
1852 33 val = OBJECT_TO_JSVAL(portTypes);
1853 33 if(!JS_DefineProperty(cx, wsdl, "portTypes", val, NULL, NULL,
1854 JSPROP_READONLY|JSPROP_PERMANENT))
1855 {
1856 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1857 0 goto exit;
1858 }
1859 }
1860 else
1861 {
1862 29 portTypes = JSVAL_TO_OBJECT(val);
1863 29 if(!portTypes)
1864 {
1865 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1866 0 goto exit;
1867 }
1868 }
1869
1870 62 res = JS_GetProperty(cx, wsdl, "bindings", &val);
1871 62 if(val == JSVAL_VOID)
1872 {
1873 33 bindings = JS_NewObject(cx, &basic_class, NULL, wsdl);
1874 33 if(!bindings)
1875 {
1876 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1877 0 goto exit;
1878 }
1879
1880 33 val = OBJECT_TO_JSVAL(bindings);
1881 33 if(!JS_DefineProperty(cx, wsdl, "bindings", val, NULL, NULL,
1882 JSPROP_READONLY|JSPROP_PERMANENT))
1883 {
1884 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1885 0 goto exit;
1886 }
1887 }
1888 else
1889 {
1890 29 bindings = JSVAL_TO_OBJECT(val);
1891 29 if(!bindings)
1892 {
1893 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1894 0 goto exit;
1895 }
1896 }
1897
1898 62 res = JS_GetProperty(cx, wsdl, "services", &val);
1899 62 if(val == JSVAL_VOID)
1900 {
1901 33 services = JS_NewObject(cx, &basic_class, NULL, wsdl);
1902 33 if(!services)
1903 {
1904 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1905 0 goto exit;
1906 }
1907
1908 33 val = OBJECT_TO_JSVAL(services);
1909 33 if(!JS_DefineProperty(cx, wsdl, "services", val, NULL, NULL,
1910 JSPROP_READONLY|JSPROP_PERMANENT))
1911 {
1912 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1913 0 goto exit;
1914 }
1915 }
1916 else
1917 {
1918 29 services = JSVAL_TO_OBJECT(val);
1919 29 if(!services)
1920 {
1921 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1922 0 goto exit;
1923 }
1924 }
1925
1926 62 data = (ScannerData *) malloc(sizeof(ScannerData));
1927 62 data->schema = schema;
1928 62 data->context = cx;
1929 62 data->global = glob;
1930 62 data->types = (void *)types;
1931 62 data->elements = (void *)elements;
1932 62 data->local_elements = (void *)local_elements;
1933 62 data->attributes = (void *)attributes;
1934 62 data->local_attributes = (void *)local_attributes;
1935 62 data->messages = (void *)messages;
1936 62 data->attributes = (void *)attributes;
1937 62 data->portTypes = (void *)portTypes;
1938 62 data->bindings = (void *)bindings;
1939 62 data->services = (void *)services;
1940 62 data->result = GLOBUS_SUCCESS;
1941
1942 62 if(schema->schemaTypes)
1943 {
1944 33 data->xsdSchema = schema->schemaTypes;
1945 33 xmlHashScan(schema->schemaTypes->schemasImports,
1946 globus_i_wsdl_parser_import_scanner, data);
1947 33 if(data->result != GLOBUS_SUCCESS)
1948 {
1949 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
1950 0 goto exit;
1951 }
1952
1953 33 data->xsdSchema = schema->schemaTypes;
1954 33 xmlHashScan(schema->schemaTypes->typeDecl,
1955 globus_i_wsdl_parser_type_scanner, data);
1956 33 if(data->result != GLOBUS_SUCCESS)
1957 {
1958 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
1959 0 goto exit;
1960 }
1961
1962 33 xmlHashScan(schema->schemaTypes->groupDecl,
1963 globus_i_wsdl_parser_type_scanner, data);
1964 33 if(data->result != GLOBUS_SUCCESS)
1965 {
1966 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
1967 0 goto exit;
1968 }
1969
1970 33 xmlHashScan(schema->schemaTypes->elemDecl,
1971 globus_i_wsdl_parser_element_scanner, data);
1972 33 if(data->result != GLOBUS_SUCCESS)
1973 {
1974 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
1975 0 goto exit;
1976 }
1977
1978 33 xmlHashScan(schema->schemaTypes->attrDecl,
1979 globus_i_wsdl_parser_attribute_scanner,
1980 data);
1981 33 if(data->result != GLOBUS_SUCCESS)
1982 {
1983 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
1984 0 goto exit;
1985 }
1986 }
1987
1988 62 typeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1989 62 if(!typeEnum)
1990 {
1991 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1992 0 goto exit;
1993 }
1994
1995 62 if(!JS_DefineProperties(cx, typeEnum, xsdTypeEnum_properties))
1996 {
1997 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1998 0 goto exit;
1999 }
2000
2001 62 val = OBJECT_TO_JSVAL(typeEnum);
2002 62 if(!JS_DefineProperty(cx, wsdl, "xsdType", val, NULL, NULL,
2003 JSPROP_READONLY|JSPROP_PERMANENT))
2004 {
2005 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2006 0 goto exit;
2007 }
2008
2009 62 attrEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2010 62 if(!attrEnum)
2011 {
2012 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2013 0 goto exit;
2014 }
2015
2016 62 if(!JS_DefineProperties(cx, attrEnum, xsdAttrEnum_properties))
2017 {
2018 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2019 0 goto exit;
2020 }
2021
2022 62 val = OBJECT_TO_JSVAL(attrEnum);
2023 62 if(!JS_DefineProperty(cx, wsdl, "xsdAttr", val, NULL, NULL,
2024 JSPROP_READONLY|JSPROP_PERMANENT))
2025 {
2026 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2027 0 goto exit;
2028 }
2029
2030 62 contentTypeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2031 62 if(!contentTypeEnum)
2032 {
2033 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2034 0 goto exit;
2035 }
2036
2037 62 if(!JS_DefineProperties(cx, contentTypeEnum,
2038 xsdContentTypeEnum_properties))
2039 {
2040 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2041 0 goto exit;
2042 }
2043
2044 62 val = OBJECT_TO_JSVAL(contentTypeEnum);
2045 62 if(!JS_SetProperty(cx, wsdl, "xsdContentType", &val))
2046 {
2047 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2048 0 goto exit;
2049 }
2050
2051 62 operationTypeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2052 62 JS_DefineProperties(cx, operationTypeEnum, operationTypeEnum_properties);
2053 62 val = OBJECT_TO_JSVAL(operationTypeEnum);
2054 62 JS_SetProperty(cx, wsdl, "operationType", &val);
2055
2056 62 bindingType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2057 62 JS_DefineProperties(cx, bindingType, bindingType_properties);
2058 62 val = OBJECT_TO_JSVAL(bindingType);
2059 62 JS_SetProperty(cx, wsdl, "bindingType", &val);
2060
2061 62 soapOperationStyleType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2062 62 JS_DefineProperties(cx, soapOperationStyleType,
2063 soapOperationStyleType_properties);
2064 62 val = OBJECT_TO_JSVAL(soapOperationStyleType);
2065 62 JS_SetProperty(cx, wsdl, "soapOperationStyleType", &val);
2066
2067 62 soapUseType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
2068 62 JS_DefineProperties(cx, soapUseType,
2069 soapUseType_properties);
2070 62 val = OBJECT_TO_JSVAL(soapUseType);
2071 62 JS_SetProperty(cx, wsdl, "soapUseType", &val);
2072
2073 62 xmlHashScan(schema->messagesDecl,
2074 globus_i_wsdl_parser_message_scanner,
2075 data);
2076 62 if(data->result != GLOBUS_SUCCESS)
2077 {
2078 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2079 0 goto exit;
2080 }
2081
2082 62 xmlHashScan(schema->portTypesDecl,
2083 globus_i_wsdl_parser_portType_scanner, data);
2084 62 if(data->result != GLOBUS_SUCCESS)
2085 {
2086 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2087 0 goto exit;
2088 }
2089
2090 62 xmlHashScan(schema->bindingsDecl,
2091 globus_i_wsdl_parser_binding_scanner,
2092 data);
2093 62 if(data->result != GLOBUS_SUCCESS)
2094 {
2095 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2096 0 goto exit;
2097 }
2098
2099 62 xmlHashScan(schema->servicesDecl,
2100 globus_i_wsdl_parser_service_scanner,
2101 data);
2102 62 if(data->result != GLOBUS_SUCCESS)
2103 {
2104 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2105 0 goto exit;
2106 }
2107
2108 62 xmlHashScan(schema->importsDecl,
2109 globus_i_wsdl_parser_wsdl_imports_scanner,
2110 data);
2111 62 if(data->result != GLOBUS_SUCCESS)
2112 {
2113 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2114 0 goto exit;
2115 }
2116
2117 62 if(!schema->targetNamespace)
2118 {
2119 20 val = JSVAL_NULL;
2120 }
2121 else
2122 {
2123 42 str = JS_InternString(cx, (const char *) schema->targetNamespace);
2124 42 if(!str)
2125 {
2126 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2127 0 goto exit;
2128 }
2129 42 val = STRING_TO_JSVAL(str);
2130 }
2131
2132 62 if(!JS_SetProperty(cx, wsdl, "targetNamespace", &val))
2133 {
2134 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2135 0 goto exit;
2136 }
2137
2138 62 exit:
2139
2140 62 GlobusWSDLDebugExit();
2141 62 return result;
2142 }
2143
2144 static
2145 globus_result_t
2146 globus_i_wsdl_js_load_imported_schema(
2147 JSContext * cx,
2148 wsdlSchemaPtr schema)
2149 230 {
2150 230 JSObject * glob = NULL;
2151 230 JSObject * wsdl = NULL;
2152 230 JSObject * types = NULL;
2153 230 JSObject * elements = NULL;
2154 230 JSObject * local_elements = NULL;
2155 230 JSObject * attributes = NULL;
2156 230 JSObject * local_attributes = NULL;
2157 230 JSObject * messages = NULL;
2158 230 JSObject * portTypes = NULL;
2159 230 JSObject * bindings = NULL;
2160 230 JSObject * services = NULL;
2161 230 ScannerData * data = NULL;
2162 jsval val;
2163 230 JSBool res = JS_TRUE;
2164 230 globus_result_t result = GLOBUS_SUCCESS;
2165 GlobusFuncName(globus_i_wsdl_js_load_imported_schema);
2166 230 GlobusWSDLDebugEnter();
2167
2168 230 glob = JS_GetGlobalObject(cx);
2169 230 if(!glob)
2170 {
2171 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2172 0 goto exit;
2173 }
2174
2175 230 res = JS_GetProperty(cx, glob, "wsdl", &val);
2176 230 globus_assert(res);
2177
2178 230 wsdl = JSVAL_TO_OBJECT(val);
2179 230 if(!wsdl)
2180 {
2181 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2182 0 goto exit;
2183 }
2184
2185 230 res = JS_GetProperty(cx, wsdl, "types", &val);
2186 230 globus_assert(res);
2187
2188 230 types = JSVAL_TO_OBJECT(val);
2189 230 if(!types)
2190 {
2191 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2192 0 goto exit;
2193 }
2194
2195 230 res = JS_GetProperty(cx, wsdl, "elements", &val);
2196 230 globus_assert(res);
2197
2198 230 elements = JSVAL_TO_OBJECT(val);
2199 230 if(!elements)
2200 {
2201 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2202 0 goto exit;
2203 }
2204
2205 230 res = JS_GetProperty(cx, wsdl, "local_elements", &val);
2206 230 globus_assert(res);
2207
2208 230 local_elements = JSVAL_TO_OBJECT(val);
2209 230 if(!local_elements)
2210 {
2211 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2212 0 goto exit;
2213 }
2214
2215 230 res = JS_GetProperty(cx, wsdl, "attributes", &val);
2216 230 globus_assert(res);
2217
2218 230 attributes = JSVAL_TO_OBJECT(val);
2219 230 if(!attributes)
2220 {
2221 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2222 0 goto exit;
2223 }
2224
2225 230 res = JS_GetProperty(cx, wsdl, "local_attributes", &val);
2226 230 globus_assert(res);
2227
2228 230 local_attributes = JSVAL_TO_OBJECT(val);
2229 230 if(!local_attributes)
2230 {
2231 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2232 0 goto exit;
2233 }
2234
2235 230 res = JS_GetProperty(cx, wsdl, "messages", &val);
2236 230 globus_assert(res);
2237
2238 230 messages = JSVAL_TO_OBJECT(val);
2239 230 if(!messages)
2240 {
2241 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2242 0 goto exit;
2243 }
2244
2245 230 res = JS_GetProperty(cx, wsdl, "portTypes", &val);
2246 230 globus_assert(res);
2247
2248 230 portTypes = JSVAL_TO_OBJECT(val);
2249 230 if(!portTypes)
2250 {
2251 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2252 0 goto exit;
2253 }
2254
2255 230 res = JS_GetProperty(cx, wsdl, "bindings", &val);
2256 230 globus_assert(res);
2257
2258 230 bindings = JSVAL_TO_OBJECT(val);
2259 230 if(!bindings)
2260 {
2261 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2262 0 goto exit;
2263 }
2264
2265 230 res = JS_GetProperty(cx, wsdl, "services", &val);
2266 230 globus_assert(res);
2267
2268 230 services = JSVAL_TO_OBJECT(val);
2269 230 if(!services)
2270 {
2271 0 result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2272 0 goto exit;
2273 }
2274
2275 230 data = (ScannerData *) malloc(sizeof(ScannerData));
2276 230 data->schema = schema;
2277 230 data->context = cx;
2278 230 data->global = glob;
2279 230 data->types = (void *)types;
2280 230 data->elements = (void *)elements;
2281 230 data->attributes = (void *)attributes;
2282 230 data->local_elements = (void *)local_elements;
2283 230 data->local_attributes = (void *)local_attributes;
2284 230 data->messages = (void *)messages;
2285 230 data->portTypes = (void *)portTypes;
2286 230 data->bindings = (void *)bindings;
2287 230 data->services = (void *)services;
2288 230 data->result = GLOBUS_SUCCESS;
2289
2290 230 if(schema->schemaTypes)
2291 {
2292 210 data->xsdSchema = schema->schemaTypes;
2293 210 xmlHashScan(schema->schemaTypes->schemasImports,
2294 globus_i_wsdl_parser_import_scanner,
2295 data);
2296 210 if(data->result != GLOBUS_SUCCESS)
2297 {
2298 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2299 0 goto exit;
2300 }
2301
2302 210 data->xsdSchema = schema->schemaTypes;
2303 210 xmlHashScan(schema->schemaTypes->typeDecl,
2304 globus_i_wsdl_parser_type_scanner, data);
2305 210 if(data->result != GLOBUS_SUCCESS)
2306 {
2307 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2308 0 goto exit;
2309 }
2310
2311 210 xmlHashScan(schema->schemaTypes->groupDecl,
2312 globus_i_wsdl_parser_type_scanner, data);
2313 210 if(data->result != GLOBUS_SUCCESS)
2314 {
2315 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2316 0 goto exit;
2317 }
2318
2319 210 xmlHashScan(schema->schemaTypes->elemDecl,
2320 globus_i_wsdl_parser_element_scanner, data);
2321 210 if(data->result != GLOBUS_SUCCESS)
2322 {
2323 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2324 0 goto exit;
2325 }
2326
2327 210 xmlHashScan(schema->schemaTypes->attrDecl,
2328 globus_i_wsdl_parser_attribute_scanner,
2329 data);
2330 210 if(data->result != GLOBUS_SUCCESS)
2331 {
2332 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2333 0 goto exit;
2334 }
2335 }
2336
2337 230 xmlHashScan(schema->messagesDecl,
2338 globus_i_wsdl_parser_message_scanner, data);
2339 230 if(data->result != GLOBUS_SUCCESS)
2340 {
2341 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2342 0 goto exit;
2343 }
2344
2345 230 xmlHashScan(schema->portTypesDecl,
2346 globus_i_wsdl_parser_portType_scanner, data);
2347 230 if(data->result != GLOBUS_SUCCESS)
2348 {
2349 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2350 0 goto exit;
2351 }
2352
2353 230 xmlHashScan(schema->bindingsDecl,
2354 globus_i_wsdl_parser_binding_scanner, data);
2355 230 if(data->result != GLOBUS_SUCCESS)
2356 {
2357 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2358 0 goto exit;
2359 }
2360
2361 230 xmlHashScan(schema->servicesDecl,
2362 globus_i_wsdl_parser_service_scanner, data);
2363 230 if(data->result != GLOBUS_SUCCESS)
2364 {
2365 0 result = GlobusWSDLErrorJSLoadSchema(data->result);
2366 0 goto exit;
2367 }
2368
2369 230 xmlHashScan(schema->importsDecl,
2370 globus_i_wsdl_parser_wsdl_imports_scanner, data);
2371
2372 230 exit:
2373
2374 230 GlobusWSDLDebugExit();
2375 230 return result;
2376 }
2377
2378 static
2379 globus_result_t
2380 globus_i_wsdl_execute_script(
2381 JSContext * ctx,
2382 JSObject * glob,
2383 const char * tmpl_filename,
2384 const char * out_filename,
2385 const char * out_dir,
2386 globus_hashtable_t nsmap,
2387 globus_list_t * template_paths)
2388 34 {
2389 PrivateContext * data;
2390 JSString * argString;
2391 jsval resval;
2392 jsval load_args[2];
2393 34 globus_result_t result = GLOBUS_SUCCESS;
2394 34 int argcount = 0;
2395
2396 GlobusFuncName(globus_i_wsdl_execute_script);
2397 34 GlobusWSDLDebugEnter();
2398
2399 34 data = (PrivateContext *) globus_malloc(sizeof(PrivateContext));
2400 34 if(!data)
2401 {
2402 0 result = GlobusWSDLErrorOutOfMemory;
2403 0 goto exit;
2404 }
2405 34 memset(data, 0, sizeof(PrivateContext));
2406 34 if(out_dir)
2407 {
2408 33 data->outdir = globus_libc_strdup(out_dir);
2409 33 if(mkdir(data->outdir, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))
2410 {
2411 33 if(errno != EEXIST)
2412 {
2413 0 result = GlobusWSDLErrorDirCreate(data->outdir);
2414 0 goto exit;
2415 }
2416 }
2417 }
2418
2419 34 data->streams = (StreamContext *) malloc(sizeof(StreamContext));
2420 34 globus_assert_string(data->streams, "Memory allocation failed.");
2421 34 memset(data->streams, 0, sizeof(StreamContext));
2422
2423 34 if(!nsmap)
2424 {
2425 0 globus_hashtable_init(&data->nsmap, 10,
2426 globus_hashtable_string_hash,
2427 globus_hashtable_string_keyeq);
2428 0 data->free_nsmap = 0;
2429 }
2430 else
2431 {
2432 34 data->nsmap = nsmap;
2433 34 data->free_nsmap = 0;
2434 }
2435
2436 34 data->template_paths = template_paths;
2437 34 JS_SetContextPrivate(ctx, (void *)data);
2438
2439 34 memset(load_args, 0, 2);
2440
2441 34 argString = JS_InternString(ctx, tmpl_filename);
2442 34 load_args[0] = STRING_TO_JSVAL(argString);
2443 34 argcount++;
2444
2445 34 if(out_filename)
2446 {
2447 0 argString = JS_InternString(ctx, out_filename);
2448 0 load_args[1] = STRING_TO_JSVAL(argString);
2449 0 argcount++;
2450 }
2451 else
2452 {
2453 34 load_args[1] = JSVAL_NULL;
2454 34 argcount++;
2455 }
2456
2457 34 if(JS_CallFunctionName(
2458 ctx, glob, "load", argcount, load_args, &resval) != JS_TRUE)
2459 {
2460 /*
2461 result = GlobusWSDLErrorTemplateLoad(data->result, tmpl_filename);
2462 data->result = result;
2463 */
2464 0 result = data->result;
2465 0 goto exit;
2466 }
2467
2468 34 exit:
2469
2470 34 data = (PrivateContext *) JS_GetContextPrivate(ctx);
2471 34 if(data)
2472 {
2473 34 if(data->streams)
2474 {
2475 34 free(data->streams);
2476 }
2477
2478 34 if(data->nsmap && data->free_nsmap)
2479 {
2480 0 globus_wsdl_config_properties_destroy(data->nsmap);
2481 }
2482
2483 34 if(data->templates)
2484 {
2485 34 globus_hashtable_destroy_all(&data->templates, TemplateFree);
2486 }
2487
2488 34 if(data->outdir)
2489 {
2490 33 free(data->outdir);
2491 }
2492
2493 34 free(data);
2494 }
2495
2496 34 GlobusWSDLDebugExit();
2497 34 return result;
2498 }
2499
2500 static
2501 JSBool
2502 xsdEnumGetter(
2503 JSContext * cx,
2504 JSObject * obj,
2505 jsval id,
2506 jsval * vp)
2507 226370 {
2508 226370 jsval res = JS_TRUE;
2509 GlobusFuncName(xsdEnumGetter);
2510 226370 GlobusWSDLDebugEnter();
2511
2512 452740 if(JSVAL_IS_INT(id))
2513 {
2514 226370 *vp = id;
2515 }
2516 else
2517 {
2518 0 res = JS_FALSE;
2519 }
2520
2521 226370 GlobusWSDLDebugExit();
2522 226370 return res;
2523 }
2524
2525 static
2526 JSBool
2527 xsdAttrsGetter(
2528 JSContext * cx,
2529 JSObject * obj,
2530 jsval id,
2531 jsval * vp)
2532 9679 {
2533 xmlSchemaAttributePtr attr;
2534 9679 JSBool res = JS_TRUE;
2535 JSObject * attrObj;
2536 9679 int i = 0;
2537 GlobusFuncName(xsdAttrsGetter);
2538 9679 GlobusWSDLDebugEnter();
2539
2540 9679 attr = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
2541 9679 globus_assert(attr);
2542
2543 9679 if(JSVAL_IS_STRING(id))
2544 {
2545 0 while(attr)
2546 {
2547 JSString * name;
2548
2549 0 name = JS_InternString(cx, (const char *) attr->name);
2550 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
2551 {
2552 0 break;
2553 }
2554
2555 0 attr = attr->next;
2556 }
2557 }
2558 19358 else if(JSVAL_IS_INT(id))
2559 {
2560 13283 for(; i < JSVAL_TO_INT(id) && attr; ++i)
2561 {
2562 3604 attr = attr->next;
2563 }
2564 9679 globus_assert(attr);
2565 }
2566 else
2567 {
2568 0 attr = (xmlSchemaAttributePtr) JSVAL_TO_PRIVATE(id);
2569 0 globus_assert(attr);
2570 }
2571
2572 9679 attrObj = JS_NewObject(cx, &xsdAttr_class, xsdAttrClass, obj);
2573 9679 globus_assert(attrObj);
2574 9679 JS_SetPrivate(cx, attrObj, (void *)attr);
2575 9679 JS_DefineProperties(cx, attrObj, xsdAttr_properties);
2576
2577 9679 *vp = OBJECT_TO_JSVAL(attrObj);
2578
2579 9679 GlobusWSDLDebugExit();
2580 9679 return res;
2581 }
2582
2583 static
2584 JSBool
2585 xsdFacetsGetter(
2586 JSContext * cx,
2587 JSObject * obj,
2588 jsval id,
2589 jsval * vp)
2590 595 {
2591 xmlSchemaFacetPtr facet;
2592 JSObject * facetObj;
2593 595 int i = 0;
2594 595 JSBool res = JS_TRUE;
2595 GlobusFuncName(xsdFacetsGetter);
2596 595 GlobusWSDLDebugEnter();
2597
2598 595 facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2599 595 globus_assert(facet);
2600
2601 595 if(JSVAL_IS_STRING(id))
2602 {
2603 0 *vp = JSVAL_ZERO;
2604 }
2605 1190 else if(JSVAL_IS_INT(id))
2606 {
2607 1980 for(; i < JSVAL_TO_INT(id) && facet; ++i)
2608 {
2609 1385 facet = facet->next;
2610 }
2611 595 globus_assert(facet);
2612 }
2613 else
2614 {
2615 0 facet = (xmlSchemaFacetPtr) JSVAL_TO_PRIVATE(id);
2616 0 globus_assert(facet);
2617 }
2618
2619 595 facetObj = JS_NewObject(cx, &xsdFacet_class, xsdFacetClass, obj);
2620 595 globus_assert(facetObj);
2621 595 JS_SetPrivate(cx, facetObj, (void *)facet);
2622 595 JS_DefineProperties(cx, facetObj, xsdFacet_properties);
2623 595 *vp = OBJECT_TO_JSVAL(facetObj);
2624
2625 595 GlobusWSDLDebugExit();
2626 595 return res;
2627 }
2628
2629 static
2630 JSBool
2631 xsdFacetsEnumerate(
2632 JSContext * cx,
2633 JSObject * obj,
2634 JSIterateOp enum_op,
2635 jsval * statep,
2636 jsid * idp)
2637 294 {
2638 294 JSBool res = JS_TRUE;
2639 xmlSchemaFacetPtr facet;
2640 int index;
2641 294 int i = 0;
2642 GlobusFuncName(xsdFacetsEnumerate);
2643 294 GlobusWSDLDebugEnter();
2644
2645 294 facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2646 294 globus_assert(facet);
2647
2648 294 switch(enum_op)
2649 {
2650 case JSENUMERATE_INIT:
2651
2652 59 *statep = INT_TO_JSVAL(0);
2653 59 break;
2654
2655 case JSENUMERATE_NEXT:
2656
2657 235 index = JSVAL_TO_INT(*statep);
2658
2659 771 for(; i < index && facet; ++i)
2660 {
2661 536 facet = facet->next;
2662 }
2663
2664 235 if(!facet)
2665 {
2666 59 *statep = JSVAL_NULL;
2667 59 *idp = JSVAL_ZERO;
2668 59 break;
2669 }
2670
2671 176 *idp = *statep;
2672 176 *statep = INT_TO_JSVAL(index + 1);
2673
2674 break;
2675
2676 case JSENUMERATE_DESTROY:
2677
2678 break;
2679 }
2680
2681 294 GlobusWSDLDebugExit();
2682 294 return res;
2683 }
2684
2685 static
2686 JSBool
2687 xsdSubTypesGetter(
2688 JSContext * cx,
2689 JSObject * obj,
2690 jsval id,
2691 jsval * vp)
2692 68652 {
2693 xmlSchemaTypePtr type;
2694 JSObject * typeObj;
2695 68652 int i = 0;
2696 68652 JSBool res = JS_TRUE;
2697 GlobusFuncName(xsdSubTypesGetter);
2698 68652 GlobusWSDLDebugEnter();
2699
2700 68652 type = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2701 68652 globus_assert(type);
2702
2703 68652 if(JSVAL_IS_STRING(id))
2704 {
2705 0 while(type)
2706 {
2707 JSString * name;
2708
2709 0 name = JS_InternString(cx, (const char *) type->name);
2710 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
2711 {
2712 0 break;
2713 }
2714
2715 0 type = type->next;
2716 }
2717 }
2718 137304 else if(JSVAL_IS_INT(id))
2719 {
2720 93571 for(; i < JSVAL_TO_INT(id) && type; ++i)
2721 {
2722 24919 type = type->next;
2723 }
2724 68652 globus_assert(type);
2725 }
2726 else
2727 {
2728 0 type = (xmlSchemaTypePtr) JSVAL_TO_PRIVATE(id);
2729 0 globus_assert(type);
2730 }
2731
2732 68652 if (type->type == XML_SCHEMA_TYPE_ELEMENT)
2733 {
2734 12914 typeObj = JS_NewObject(cx, &xsdElement_class, xsdElementClass, obj);
2735 }
2736 else
2737 {
2738 55738 typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
2739 }
2740 68652 globus_assert(typeObj);
2741 68652 JS_SetPrivate(cx, typeObj, (void *)type);
2742 68652 *vp = OBJECT_TO_JSVAL(typeObj);
2743
2744 68652 GlobusWSDLDebugExit();
2745 68652 return res;
2746 }
2747
2748 static
2749 JSBool
2750 xsdSubTypesEnumerate(
2751 JSContext * cx,
2752 JSObject * obj,
2753 JSIterateOp enum_op,
2754 jsval * statep,
2755 jsid * idp)
2756 42727 {
2757 42727 JSBool res = JS_TRUE;
2758 xmlSchemaTypePtr schemaType;
2759 int index;
2760 42727 int i = 0;
2761 GlobusFuncName(xsdSubTypesEnumerate);
2762 42727 GlobusWSDLDebugEnter();
2763
2764 42727 schemaType = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2765 42727 globus_assert(schemaType);
2766
2767 42727 switch(enum_op)
2768 {
2769 case JSENUMERATE_INIT:
2770
2771 12285 *statep = INT_TO_JSVAL(i);
2772 12285 if(idp)
2773 {
2774 0 *idp = JSVAL_ZERO;
2775 }
2776 12285 break;
2777
2778 case JSENUMERATE_NEXT:
2779
2780 30440 index = JSVAL_TO_INT(*statep);
2781 62301 for(; i < index && schemaType; ++i)
2782 {
2783 31861 schemaType = schemaType->next;
2784 }
2785
2786 30440 if(!schemaType)
2787 {
2788 12283 *statep = JSVAL_NULL;
2789 12283 *idp = JSVAL_ZERO;
2790 12283 break;
2791 }
2792
2793 18157 *idp = *statep;
2794 18157 *statep = INT_TO_JSVAL(index + 1);
2795
2796 break;
2797
2798 case JSENUMERATE_DESTROY:
2799
2800 break;
2801 }
2802
2803 42727 GlobusWSDLDebugExit();
2804 42727 return res;
2805 }
2806
2807 static
2808 JSBool
2809 xsdAttrsEnumerate(
2810 JSContext * cx,
2811 JSObject * obj,
2812 JSIterateOp enum_op,
2813 jsval * statep,
2814 jsid * idp)
2815 7569 {
2816 7569 JSBool res = JS_TRUE;
2817 xmlSchemaAttributePtr schemaAttribute;
2818 7569 int i = 0;
2819 int index;
2820 GlobusFuncName(xsdAttrsEnumerate);
2821 7569 GlobusWSDLDebugEnter();
2822
2823 7569 schemaAttribute = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
2824 7569 globus_assert(schemaAttribute);
2825
2826 7569 switch(enum_op)
2827 {
2828 case JSENUMERATE_INIT:
2829
2830 2224 *statep = INT_TO_JSVAL(0);
2831 2224 break;
2832
2833 case JSENUMERATE_NEXT:
2834
2835 5345 index = JSVAL_TO_INT(*statep);
2836 9667 for(; i < index && schemaAttribute; ++i)
2837 {
2838 4322 schemaAttribute = schemaAttribute->next;
2839 }
2840
2841 5345 if(!schemaAttribute)
2842 {
2843 2224 *statep = JSVAL_NULL;
2844 2224 *idp = JSVAL_ZERO;
2845 2224 break;
2846 }
2847
2848 3121 *idp = *statep;
2849 3121 *statep = INT_TO_JSVAL(index + 1);
2850
2851 break;
2852
2853 case JSENUMERATE_DESTROY:
2854
2855 break;
2856 }
2857
2858 7569 GlobusWSDLDebugExit();
2859 7569 return res;
2860 }
2861
2862 static
2863 JSBool
2864 xsdFacetGetter(
2865 JSContext * cx,
2866 JSObject * obj,
2867 jsval jid,
2868 jsval * vp)
2869 595 {
2870 int idval;
2871 JSString * str;
2872 xmlSchemaFacetPtr facet;
2873 595 JSBool res = JS_TRUE;
2874 GlobusFuncName(xsdFacetGetter);
2875 595 GlobusWSDLDebugEnter();
2876
2877 595 facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2878 595 globus_assert(facet);
2879
2880 595 if(!JSVAL_IS_INT(jid))
2881 {
2882 char * prop_name;
2883
2884 0 prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
2885 0 JS_ReportError(cx,
2886 "Unknown property: .%s for facet", prop_name);
2887 0 res = JS_FALSE;
2888 0 goto exit;
2889 }
2890
2891 595 idval = JSVAL_TO_INT(jid);
2892 595 switch(idval)
2893 {
2894 case type:
2895
2896 176 *vp = INT_TO_JSVAL(facet->type);
2897 176 break;
2898
2899 case value:
2900 419 str = NULL;
2901
2902 419 if(!facet->value)
2903 {
2904 0 *vp = JSVAL_VOID;
2905 0 break;
2906 }
2907
2908 419 if(facet->val != NULL && facet->val->type == XML_SCHEMAS_QNAME)
2909 {
2910 xmlChar * local;
2911 xmlChar * prefix;
2912 xmlNsPtr ns;
2913 char * qn;
2914
2915 351 local = xmlSplitQName2(facet->val->value.qname.name, &prefix);
2916
2917 351 if (local != NULL)
2918 {
2919 351 ns = xmlSearchNs(facet->node->doc, facet->node, prefix);
2920 351 qn = globus_common_create_string("%s#%s",
2921 (const char *) ns->href,
2922 local);
2923
2924 351 str = JS_InternString(cx, (const char *) qn);
2925
2926 351 xmlFree(local);
2927 351 xmlFree(prefix);
2928 }
2929 }
2930
2931 419 if (str == NULL)
2932 {
2933 68 str = JS_InternString(cx, (const char *) facet->value);
2934 }
2935 419 *vp = STRING_TO_JSVAL(str);
2936 419 break;
2937
2938 case id:
2939
2940 0 *vp = INT_TO_JSVAL(facet->id);
2941 0 break;
2942
2943 case fixed:
2944
2945 0 *vp = INT_TO_JSVAL(facet->fixed);
2946 0 break;
2947
2948 default:
2949
2950 0 *vp = JSVAL_VOID;
2951 0 JS_ReportError(cx, "Unknown property for facet with id: %d", idval);
2952 0 res = JS_FALSE;
2953 }
2954
2955 595 exit:
2956
2957 595 GlobusWSDLDebugExit();
2958 595 return res;
2959 }
2960
2961 static
2962 JSBool
2963 xsdTypeGetter(
2964 JSContext * cx,
2965 JSObject * obj,
2966 jsval jid,
2967 jsval * vp)
2968 227601 {
2969 globus_i_js_id_t idval;
2970 JSObject * subTypesObj;
2971 JSObject * attribObj;
2972 JSObject * typeObj;
2973 JSObject * wildcardObj;
2974 JSObject * facetsObj;
2975 JSString * str;
2976 xmlSchemaTypePtr xsdType;
2977 227601 JSBool res = JS_TRUE;
2978 GlobusFuncName(xsdTypeGetter);
2979 227601 GlobusWSDLDebugEnter();
2980
2981 227601 xsdType = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2982 227601 globus_assert(xsdType);
2983
2984 227601 if(!JSVAL_IS_INT(jid))
2985 {
2986 char * prop_name;
2987
2988 0 prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
2989 0 JS_ReportError(
2990 cx,
2991 "Unknown property: .%s for xsd:type", prop_name);
2992 0 res = JS_FALSE;
2993 0 goto exit;
2994 }
2995
2996 227601 idval = JSVAL_TO_INT(jid);
2997 227601 switch(idval)
2998 {
2999 case type:
3000
3001 61905 *vp = INT_TO_JSVAL(xsdType->type);
3002 61905 break;
3003
3004 case name:
3005
3006 26948 if(!xsdType->name)
3007 {
3008 0 *vp = JSVAL_VOID;
3009 0 break;
3010 }
3011
3012 26948 str = JS_InternString(cx, (const char *) xsdType->name);
3013 26948 *vp = STRING_TO_JSVAL(str);
3014 26948 break;
3015
3016 case id:
3017
3018 0 *vp = INT_TO_JSVAL(xsdType->id);
3019 0 break;
3020
3021 case subtypes:
3022
3023 48695 if(!xsdType->subtypes)
3024 {
3025 1996 *vp = JSVAL_VOID;
3026 1996 break;
3027 }
3028
3029 46699 subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
3030 46699 globus_assert(subTypesObj);
3031 46699 JS_SetPrivate(cx, subTypesObj, xsdType->subtypes);
3032
3033 46699 *vp = OBJECT_TO_JSVAL(subTypesObj);
3034 46699 break;
3035
3036 case attributes:
3037
3038 13897 if(!xsdType->attributes)
3039 {
3040 12006 *vp = JSVAL_VOID;
3041 12006 break;
3042 }
3043
3044 1891 attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
3045 1891 globus_assert(attribObj);
3046 1891 JS_SetPrivate(cx, attribObj, xsdType->attributes);
3047
3048 1891 *vp = OBJECT_TO_JSVAL(attribObj);
3049 1891 break;
3050
3051 case minOccurs:
3052
3053 1948 *vp = INT_TO_JSVAL(xsdType->minOccurs);
3054 1948 break;
3055
3056 case maxOccurs:
3057
3058 3994 *vp =
3059 (xsdType->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ?
3060 JS_GetPositiveInfinityValue(cx) :
3061 INT_TO_JSVAL(xsdType->maxOccurs);
3062 3994 break;
3063
3064 case ref:
3065
3066 4020 if(!xsdType->ref)
3067 {
3068 3856 *vp = JSVAL_VOID;
3069 3856 break;
3070 }
3071
3072 164 str = JS_InternString(cx, (const char *) xsdType->ref);
3073 164 *vp = STRING_TO_JSVAL(str);
3074 164 break;
3075
3076 case refNs:
3077
3078 84 if(!xsdType->refNs)
3079 {
3080 0 *vp = JSVAL_VOID;
3081 0 break;
3082 }
3083
3084 84 str = JS_InternString(cx, (const char *) xsdType->refNs);
3085 84 *vp = STRING_TO_JSVAL(str);
3086 84 break;
3087
3088 case refQname:
3089
3090 38 if(!xsdType->ref)
3091 {
3092 0 *vp = JSVAL_VOID;
3093 0 break;
3094 }
3095 38 else if(!xsdType->refNs)
3096 {
3097 0 str = JS_InternString(cx, (const char *) xsdType->ref);
3098 0 *vp = STRING_TO_JSVAL(str);
3099 0 break;
3100 }
3101 else
3102 {
3103 38 str = globus_l_wsdl_jscript_qname_string(
3104 cx, xsdType->refNs, xsdType->ref);
3105 38 *vp = STRING_TO_JSVAL(str);
3106 38 break;
3107 }
3108
3109 case base:
3110
3111 1123 if(!xsdType->base)
3112 {
3113 0 *vp = JSVAL_VOID;
3114 0 break;
3115 }
3116
3117 1123 if(xsdType->type == XML_SCHEMA_TYPE_UNION)
3118 {
3119 96 char * memberTypes = NULL;
3120 96 int len = 0;
3121 96 int memberTypes_length = 1;
3122 xsdQNamePtr qnames, qn;
3123
3124 96 globus_i_wsdl_split_qnames(NULL, xsdType->node, xsdType->base, &qnames);
3125 96 qn = qnames;
3126 384 while(qn)
3127 {
3128 192 len = strlen((const char *) qn->Namespace) +
3129 strlen((const char *) qn->name) + 2;
3130 192 memberTypes = realloc(memberTypes,
3131 (sizeof(char) * len) +
3132 memberTypes_length);
3133 192 sprintf(memberTypes + memberTypes_length - 1, "%s#%s ",
3134 qn->Namespace, qn->name);
3135 192 memberTypes_length += len;
3136
3137 192 qn = qn->next;
3138 }
3139
3140 96 xsdQNameFree(qnames);
3141
3142 96 str = JS_InternString(cx, memberTypes);
3143 }
3144 else
3145 {
3146 1027 str = JS_InternString(cx, (const char *) xsdType->base);
3147 }
3148
3149 1123 *vp = STRING_TO_JSVAL(str);
3150 1123 break;
3151
3152 case baseNs:
3153
3154 2014 if(!xsdType->baseNs)
3155 {
3156 0 *vp = JSVAL_VOID;
3157 0 break;
3158 }
3159
3160 2014 str = JS_InternString(cx, (const char *) xsdType->baseNs);
3161 2014 *vp = STRING_TO_JSVAL(str);
3162 2014 break;
3163
3164 case baseQName:
3165
3166 1792 if(!xsdType->base)
3167 {
3168 0 *vp = JSVAL_VOID;
3169 0 break;
3170 }
3171
3172 1792 if(!xsdType->baseNs)
3173 {
3174 0 str = JS_InternString(cx, (const char *) xsdType->base);
3175 0 *vp = STRING_TO_JSVAL(str);
3176 0 break;
3177 }
3178
3179 1792 str = globus_l_wsdl_jscript_qname_string(
3180 cx, xsdType->baseNs, xsdType->base);
3181 1792 *vp = STRING_TO_JSVAL(str);
3182 1792 break;
3183
3184 case baseType:
3185
3186 952 if(!xsdType->baseType)
3187 {
3188 0 *vp = JSVAL_VOID;
3189 0 break;
3190 }
3191
3192 952 typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
3193 952 globus_assert(typeObj);
3194 952 JS_SetPrivate(cx, typeObj, (void *)xsdType->baseType);
3195 952 JS_DefineProperties(cx, typeObj, xsdType_properties);
3196 952 *vp = OBJECT_TO_JSVAL(typeObj);
3197 952 break;
3198
3199 case targetNamespace:
3200
3201 31312 if(!xsdType->targetNamespace)
3202 {
3203 0 *vp = JSVAL_VOID;
3204 0 break;
3205 }
3206
3207 31312 str = JS_InternString(cx, (const char *) xsdType->targetNamespace);
3208 31312 *vp = STRING_TO_JSVAL(str);
3209 31312 break;
3210
3211 case qname:
3212
3213 7403 if(!xsdType->name)
3214 {
3215 0 *vp = JSVAL_VOID;
3216 0 break;
3217 }
3218 7403 else if(!xsdType->targetNamespace)
3219 {
3220 315 str = JS_InternString(cx, (const char *) xsdType->name);
3221 315 *vp = STRING_TO_JSVAL(str);
3222 315 break;
3223 }
3224 else
3225 {
3226 7088 str = globus_l_wsdl_jscript_qname_string(
3227 cx, xsdType->targetNamespace, xsdType->name);
3228 7088 *vp = STRING_TO_JSVAL(str);
3229 7088 break;
3230 }
3231
3232 case attributeWildcard:
3233
3234 13874 if(!xsdType->attributeWildcard)
3235 {
3236 10237 *vp = JSVAL_VOID;
3237 10237 break;
3238 }
3239
3240 3637 wildcardObj = JS_NewObject(cx,
3241 &xsdWildcard_class,
3242 xsdWildcardClass, obj);
3243 3637 globus_assert(wildcardObj);
3244 3637 JS_SetPrivate(cx, wildcardObj, (void *)xsdType->attributeWildcard);
3245 3637 JS_DefineProperties(cx, wildcardObj, xsdWildcard_properties);
3246 3637 *vp = OBJECT_TO_JSVAL(wildcardObj);
3247 3637 break;
3248
3249 case facets:
3250
3251 702 if(!xsdType->facets)
3252 {
3253 10 *vp = JSVAL_VOID;
3254 10 break;
3255 }
3256
3257 692 facetsObj = JS_NewObject(cx, &xsdFacets_class, NULL, obj);
3258 globus_assert(facets);
3259 692 JS_SetPrivate(cx, facetsObj, xsdType->facets);
3260
3261 692 *vp = OBJECT_TO_JSVAL(facetsObj);
3262 692 break;
3263
3264 case namedType:
3265
3266 0 if(xsdType->type != XML_SCHEMA_TYPE_ELEMENT ||
3267 !((xmlSchemaElementPtr)xsdType)->namedType)
3268 {
3269 0 *vp = JSVAL_VOID;
3270 0 break;
3271 }
3272
3273 0 str = JS_InternString(cx, (const char *) ((xmlSchemaElementPtr)xsdType)->namedType);
3274 0 *vp = STRING_TO_JSVAL(str);
3275 0 break;
3276
3277 case namedTypeNs:
3278
3279 0 if(((xmlSchemaElementPtr)xsdType)->type != XML_SCHEMA_TYPE_ELEMENT ||
3280 !((xmlSchemaElementPtr)xsdType)->namedTypeNs)
3281 {
3282 0 *vp = JSVAL_VOID;
3283 0 break;
3284 }
3285
3286 0 str = JS_InternString(cx,
3287 (const char *) ((xmlSchemaElementPtr)xsdType)->namedTypeNs);
3288 0 *vp = STRING_TO_JSVAL(str);
3289 0 break;
3290
3291 case nillable:
3292 5976 if(((xmlSchemaElementPtr)xsdType)->flags & XML_SCHEMAS_ELEM_NILLABLE)
3293 {
3294 98 *vp = JSVAL_TRUE;
3295 98 break;
3296 }
3297 else
3298 {
3299 5878 *vp = JSVAL_FALSE;
3300 }
3301 5878 break;
3302
3303 case documentation:
3304 640 *vp = JSVAL_VOID;
3305 640 if (xsdType->annot != NULL)
3306 {
3307 xmlNodePtr tmp;
3308 74 xmlBufferPtr buf = xmlBufferCreate();
3309
3310 74 tmp = xsdType->annot->content->children;
3311
3312 148 while (tmp != NULL)
3313 {
3314 74 if (strcmp((char *) tmp->name, "documentation") == 0)
3315 {
3316 74 xmlNodeDump(buf, xsdType->node->doc, tmp->children, 0, 0);
3317 74 str = JS_InternString(cx, (char *) buf->content);
3318 74 *vp = STRING_TO_JSVAL(str);
3319 74 break;
3320 }
3321 0 tmp = tmp->next;
3322 }
3323 }
3324 640 break;
3325
3326 case namespaces:
3327 0 if (xsdType->node != NULL && xsdType->node->ns != NULL)
3328 {
3329 0 res = GetNamespaces(cx, xsdType->node->ns, vp);
3330 }
3331 0 break;
3332
3333 case Namespace:
3334 284 str = NULL;
3335 284 if (xsdType->type == XML_SCHEMA_TYPE_ANY)
3336 {
3337 xmlChar * prop;
3338 270 prop = xmlGetProp(xsdType->node, (xmlChar *) "namespace");
3339
3340 270 if (prop)
3341 {
3342 224 str = JS_InternString(cx, prop);
3343 }
3344 }
3345 284 if (str)
3346 {
3347 224 *vp = STRING_TO_JSVAL(str);
3348 }
3349 else
3350 {
3351 60 *vp = JSVAL_VOID;
3352 }
3353 284 break;
3354
3355 default:
3356
3357 0 JS_ReportError(cx, "Unknown property for type with id: %d", idval);
3358 0 res = JS_FALSE;
3359 }
3360
3361 227601 exit:
3362
3363 227601 GlobusWSDLDebugExit();
3364 227601 return res;
3365 }
3366
3367 static
3368 JSBool
3369 xsdWildcardGetter(
3370 JSContext * cx,
3371 JSObject * obj,
3372 jsval jid,
3373 jsval * vp)
3374 247 {
3375 int idval;
3376 xmlSchemaWildcardPtr xsdWildcard;
3377 JSString * str;
3378 247 JSBool res = JS_TRUE;
3379 GlobusFuncName(xsdWildcardGetter);
3380 247 GlobusWSDLDebugEnter();
3381
3382 247 xsdWildcard = (xmlSchemaWildcardPtr) JS_GetPrivate(cx, obj);
3383 247 globus_assert(xsdWildcard);
3384
3385 247 if(!JSVAL_IS_INT(jid))
3386 {
3387 char * prop_name;
3388
3389 0 prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
3390 0 JS_ReportError(cx,
3391 "Unknown property: .%s for wildcard", prop_name);
3392 0 res = JS_FALSE;
3393 0 goto exit;
3394 }
3395
3396 247 idval = JSVAL_TO_INT(jid);
3397 247 switch(idval)
3398 {
3399 case type:
3400
3401 0 *vp = INT_TO_JSVAL(xsdWildcard->type);
3402 0 break;
3403
3404 case id:
3405
3406 0 *vp = INT_TO_JSVAL(xsdWildcard->id);
3407 0 break;
3408
3409 case minOccurs:
3410
3411 0 *vp = INT_TO_JSVAL(xsdWildcard->minOccurs);
3412 0 break;
3413
3414 case maxOccurs:
3415
3416 0 *vp =
3417 (xsdWildcard->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ?
3418 JS_GetPositiveInfinityValue(cx) :
3419 INT_TO_JSVAL(xsdWildcard->maxOccurs);
3420 0 break;
3421
3422 case any:
3423
3424 0 *vp = INT_TO_JSVAL(xsdWildcard->any);
3425 0 break;
3426
3427 case Namespace:
3428 247 str = NULL;
3429 247 if (xsdWildcard->nsSet)
3430 {
3431 char * tmp;
3432 0 size_t len = 0;
3433 xmlSchemaWildcardNsPtr p;
3434
3435 0 p = xsdWildcard->nsSet;
3436
3437 0 while (p != NULL)
3438 {
3439 0 len += strlen(p->value)+2;
3440 0 p = p->next;
3441 }
3442
3443 0 tmp = malloc(len);
3444 0 tmp[0] = 0;
3445
3446 0 p = xsdWildcard->nsSet;
3447
3448 0 while (p != NULL)
3449 {
3450 0 strcat(tmp, p->value);
3451 0 strcat(tmp, " ");
3452 0 p = p->next;
3453 }
3454 0 tmp[strlen(tmp)] = 0;
3455 0 str = JS_InternString(cx, tmp);
3456 }
3457 247 else if (xsdWildcard->negNsSet)
3458 {
3459 char * tmp;
3460 211 size_t len = 0;
3461 xmlSchemaWildcardNsPtr p;
3462
3463 211 p = xsdWildcard->negNsSet;
3464
3465 633 while (p != NULL)
3466 {
3467 211 len += strlen(p->value)+11;
3468 211 p = p->next;
3469 }
3470
3471 211 tmp = malloc(len);
3472 211 tmp[0] = 0;
3473
3474 211 p = xsdWildcard->nsSet;
3475
3476 422 while (p != NULL)
3477 {
3478 0 strcat(tmp, "##other{");
3479 0 strcat(tmp, p->value);
3480 0 strcat(tmp, "} ");
3481 0 p = p->next;
3482 }
3483 211 tmp[strlen(tmp)] = 0;
3484 211 str = JS_InternString(cx, tmp);
3485 }
3486 247 if (str)
3487 {
3488 211 *vp = STRING_TO_JSVAL(str);
3489 }
3490 else
3491 {
3492 36 *vp = JSVAL_VOID;
3493 }
3494 247 break;
3495
3496 default:
3497
3498 0 *vp = JSVAL_VOID;
3499 0 JS_ReportError(cx,
3500 "Unknown property for xsd "
3501 "wildcard with id: %d", idval);
3502 0 res = JS_FALSE;
3503 }
3504
3505 247 exit:
3506
3507 247 GlobusWSDLDebugExit();
3508 247 return res;
3509 }
3510
3511 static
3512 JSBool
3513 xsdAttrGetter(
3514 JSContext * cx,
3515 JSObject * obj,
3516 jsval jid,
3517 jsval * vp)
3518 83051 {
3519 int idval;
3520 xmlSchemaAttributePtr attr;
3521 83051 JSBool res = JS_TRUE;
3522 JSObject * subTypesObj;
3523 JSObject * attribObj;
3524 JSString * str;
3525 JSObject * typeObj;
3526 GlobusFuncName(xsdAttrGetter);
3527 83051 GlobusWSDLDebugEnter();
3528
3529 83051 attr = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
3530 83051 globus_assert(attr);
3531
3532 83051 if(!JSVAL_IS_INT(jid))
3533 {
3534 0 JS_ReportError(cx,
3535 "Invalid id for xsd attribute property, "
3536 "expected int not string");
3537 0 res = JS_FALSE;
3538 0 goto exit;
3539 }
3540
3541
3542 83051 idval = JSVAL_TO_INT(jid);
3543 83051 switch(idval)
3544 {
3545 case type:
3546
3547 4309 *vp = INT_TO_JSVAL(attr->type);
3548 4309 break;
3549
3550 case name:
3551
3552 13679 if(!attr->name)
3553 {
3554 0 *vp = JSVAL_VOID;
3555 0 break;
3556 }
3557
3558 13679 str = JS_InternString(cx, (const char *) attr->name);
3559 13679 *vp = STRING_TO_JSVAL(str);
3560 13679 break;
3561
3562 case id:
3563
3564 0 *vp = INT_TO_JSVAL(attr->id);
3565 0 break;
3566
3567 case ref:
3568
3569 6940 if(!attr->ref)
3570 {
3571 5945 *vp = JSVAL_VOID;
3572 5945 break;
3573 }
3574
3575 995 str = JS_InternString(cx, (const char *) attr->ref);
3576 995 *vp = STRING_TO_JSVAL(str);
3577 995 break;
3578
3579 case refNs:
3580
3581 0 if(!attr->refNs)
3582 {
3583 0 *vp = JSVAL_VOID;
3584 0 break;
3585 }
3586
3587 0 str = JS_InternString(cx, (const char *) attr->refNs);
3588 0 *vp = STRING_TO_JSVAL(str);
3589 0 break;
3590
3591 case refQname:
3592
3593 995 if(!attr->ref)
3594 {
3595 0 *vp = JSVAL_VOID;
3596 0 break;
3597 }
3598 995 else if(!attr->refNs)
3599 {
3600 0 str = JS_InternString(cx, (const char *) attr->ref);
3601 0 *vp = STRING_TO_JSVAL(str);
3602 0 break;
3603 }
3604 else
3605 {
3606 995 str = globus_l_wsdl_jscript_qname_string(
3607 cx, attr->refNs, attr->ref);
3608 995 *vp = STRING_TO_JSVAL(str);
3609 995 break;
3610 }
3611
3612 case typeName:
3613
3614 12249 if(!attr->typeName)
3615 {
3616 362 *vp = JSVAL_VOID;
3617 362 break;
3618 }
3619
3620 11887 str = JS_InternString(cx, (const char *) attr->typeName);
3621 11887 *vp = STRING_TO_JSVAL(str);
3622 11887 break;
3623
3624 case typeNs:
3625
3626 21863 if(!attr->typeNs)
3627 {
3628 154 *vp = JSVAL_VOID;
3629 154 break;
3630 }
3631
3632 21709 str = JS_InternString(cx, (const char *) attr->typeNs);
3633 21709 *vp = STRING_TO_JSVAL(str);
3634 21709 break;
3635
3636 case typeQname:
3637
3638 10648 if(!attr->typeName)
3639 {
3640 0 *vp = JSVAL_VOID;
3641 0 break;
3642 }
3643
3644 10648 if(!attr->typeNs)
3645 {
3646 0 str = JS_InternString(cx, (const char *) attr->typeNs);
3647 0 *vp = STRING_TO_JSVAL(str);
3648 0 break;
3649 }
3650
3651 10648 str = globus_l_wsdl_jscript_qname_string(
3652 cx, attr->typeNs, attr->typeName);
3653 10648 *vp = STRING_TO_JSVAL(str);
3654 10648 break;
3655
3656 case subtypes:
3657
3658 1443 if(!attr->subtypes)
3659 {
3660 0 *vp = JSVAL_VOID;
3661 0 break;
3662 }
3663
3664 1443 subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
3665 1443 globus_assert(subTypesObj);
3666 1443 JS_SetPrivate(cx, subTypesObj, attr->subtypes);
3667
3668 1443 *vp = OBJECT_TO_JSVAL(subTypesObj);
3669 1443 break;
3670
3671 case occurs:
3672
3673 4573 *vp = INT_TO_JSVAL(attr->occurs);
3674 4573 break;
3675
3676 case base:
3677
3678 0 if(!attr->base)
3679 {
3680 0 *vp = JSVAL_VOID;
3681 0 break;
3682 }
3683
3684 0 typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
3685 0 globus_assert(typeObj);
3686 0 JS_SetPrivate(cx, typeObj, (void *)attr->base);
3687 0 JS_DefineProperties(cx, typeObj, xsdType_properties);
3688 0 *vp = OBJECT_TO_JSVAL(typeObj);
3689 0 break;
3690
3691 case defValue:
3692
3693 0 if(!attr->defValue)
3694 {
3695 0 *vp = JSVAL_VOID;
3696 0 break;
3697 }
3698
3699 0 str = JS_InternString(cx, (const char *) attr->defValue);
3700 0 *vp = STRING_TO_JSVAL(str);
3701 0 break;
3702
3703 case targetNamespace:
3704
3705 5814 if(!attr->targetNamespace)
3706 {
3707 3964 str = JS_InternString(cx, (const char *) "");
3708 }
3709 else
3710 {
3711 1850 str = JS_InternString(cx, (const char *) attr->targetNamespace);
3712 }
3713
3714 5814 *vp = STRING_TO_JSVAL(str);
3715 5814 break;
3716
3717 case qname:
3718
3719 0 if(!attr->name)
3720 {
3721 0 *vp = JSVAL_VOID;
3722 0 break;
3723 }
3724 0 else if(!attr->targetNamespace)
3725 {
3726 0 str = JS_InternString(cx, (const char *) attr->name);
3727 0 *vp = STRING_TO_JSVAL(str);
3728 0 break;
3729 }
3730 else
3731 {
3732 0 str = globus_l_wsdl_jscript_qname_string(
3733 cx, attr->targetNamespace, attr->name);
3734 0 *vp = STRING_TO_JSVAL(str);
3735 0 break;
3736 }
3737
3738 case attributes:
3739
3740 341 if(attr->type != XML_SCHEMA_TYPE_ATTRIBUTEGROUP)
3741 {
3742 0 *vp = JSVAL_VOID;
3743 0 break;
3744 }
3745
3746 341 attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
3747 341 globus_assert(attribObj);
3748
3749 341 JS_SetPrivate(cx, attribObj,
3750 ((xmlSchemaAttributeGroupPtr)attr)->attributes);
3751
3752 341 *vp = OBJECT_TO_JSVAL(attribObj);
3753 341 break;
3754
3755 case Default:
3756 197 if (attr->defValue)
3757 {
3758 0 str = JS_InternString(cx, (const char *) attr->defValue);
3759 0 *vp = STRING_TO_JSVAL(str);
3760 0 break;
3761 }
3762 else
3763 {
3764 197 *vp = JSVAL_VOID;
3765 197 break;
3766 }
3767 case namespaces:
3768 0 if (attr->node != NULL && attr->node->ns != NULL)
3769 {
3770 0 res = GetNamespaces(cx, attr->node->ns, vp);
3771 }
3772 0 break;
3773 default:
3774
3775 0 *vp = JSVAL_VOID;
3776 0 JS_ReportError(cx,
3777 "Unknown property for xsd "
3778 "attribute with id: %d", idval);
3779 0 res = JS_FALSE;
3780 }
3781
3782 83051 exit:
3783
3784 83051 GlobusWSDLDebugExit();
3785 83051 return res;
3786 }
3787
3788 static
3789 JSBool
3790 xsdElementGetter(
3791 JSContext * cx,
3792 JSObject * obj,
3793 jsval jid,
3794 jsval * vp)
3795 279013 {
3796 int idval;
3797 xmlSchemaElementPtr element;
3798 JSString * str;
3799 JSObject * attribObj;
3800 279013 JSBool res = JS_TRUE;
3801 JSObject * subTypesObj;
3802
3803 GlobusFuncName(xsdElementGetter);
3804 279013 GlobusWSDLDebugEnter();
3805
3806 279013 element = (xmlSchemaElementPtr) JS_GetPrivate(cx, obj);
3807 279013 globus_assert(element);
3808
3809 279013 if(!JSVAL_IS_INT(jid))
3810 {
3811 0 char * prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
3812 0 JS_ReportError(cx,
3813 "Unknown property: .%s for element", prop_name);
3814 0 res = JS_FALSE;
3815 0 goto exit;
3816 }
3817
3818
3819 279013 idval = JSVAL_TO_INT(jid);
3820 279013 switch(idval)
3821 {
3822 case type:
3823
3824 35282 *vp = INT_TO_JSVAL(element->type);
3825 35282 break;
3826
3827 case name:
3828
3829 49607 if(!element->name)
3830 {
3831 0 *vp = JSVAL_VOID;
3832 0 break;
3833 }
3834
3835 49607 str = JS_InternString(cx, (const char *) element->name);
3836 49607 *vp = STRING_TO_JSVAL(str);
3837 49607 break;
3838
3839 case id:
3840
3841 0 *vp = INT_TO_JSVAL(element->id);
3842 0 break;
3843
3844 case subtypes:
3845
3846 41284 if(!element->subtypes)
3847 {
3848 206 *vp = JSVAL_VOID;
3849 206 break;
3850 }
3851
3852 41078 subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
3853 41078 globus_assert(subTypesObj);
3854
3855 41078 JS_SetPrivate(cx, subTypesObj, element->subtypes);
3856
3857 41078 *vp = OBJECT_TO_JSVAL(subTypesObj);
3858 41078 break;
3859
3860 case attributes:
3861
3862 0 if(!element->attributes)
3863 {
3864 0 *vp = JSVAL_VOID;
3865 0 break;
3866 }
3867
3868 0 attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
3869 0 globus_assert(attribObj);
3870
3871 0 JS_SetPrivate(cx, attribObj, element->attributes);
3872
3873 0 *vp = OBJECT_TO_JSVAL(attribObj);
3874 0 break;
3875
3876 case minOccurs:
3877
3878 5994 *vp = INT_TO_JSVAL(element->minOccurs);
3879 5994 break;
3880
3881 case maxOccurs:
3882
3883 8204 *vp =
3884 (element->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ?
3885 JS_GetPositiveInfinityValue(cx) :
3886 INT_TO_JSVAL(element->maxOccurs);
3887 8204 break;
3888
3889 case ref:
3890
3891 30618 if(!element->ref)
3892 {
3893 25581 *vp = JSVAL_VOID;
3894 25581 break;
3895 }
3896
3897 5037 str = JS_InternString(cx, (const char *) element->ref);
3898 5037 *vp = STRING_TO_JSVAL(str);
3899 5037 break;
3900
3901 case refNs:
3902
3903 0 if(!element->refNs)
3904 {
3905 0 *vp = JSVAL_VOID;
3906 0 break;
3907 }
3908
3909 0 str = JS_InternString(cx, (const char *) element->refNs);
3910 0 *vp = STRING_TO_JSVAL(str);
3911 0 break;
3912
3913 case refQname:
3914
3915 5223 if(!element->ref)
3916 {
3917 0 *vp = JSVAL_VOID;
3918 0 break;
3919 }
3920 5223 else if(!element->refNs)
3921 {
3922 0 str = JS_InternString(cx, (const char *) element->ref);
3923 0 *vp = STRING_TO_JSVAL(str);
3924 0 break;
3925 }
3926 else
3927 {
3928 5223 str = globus_l_wsdl_jscript_qname_string(
3929 cx, element->refNs, element->ref);
3930 5223 *vp = STRING_TO_JSVAL(str);
3931 5223 break;
3932 }
3933
3934 case targetNamespace:
3935
3936 21155 if(!element->targetNamespace)
3937 {
3938 0 str = JS_InternString(cx, (const char *) "");
3939 }
3940 else
3941 {
3942 21155 str = JS_InternString(cx, (const char *) element->targetNamespace);
3943 }
3944
3945 21155 *vp = STRING_TO_JSVAL(str);
3946 21155 break;
3947
3948 case namedType:
3949
3950 42585 if(!element->namedType)
3951 {
3952 8165 *vp = JSVAL_VOID;
3953 8165 break;
3954 }
3955
3956 34420 str = JS_InternString(cx, (const char *) element->namedType);
3957 34420 *vp = STRING_TO_JSVAL(str);
3958 34420 break;
3959
3960 case namedTypeNs:
3961
3962 29792 if(!element->namedTypeNs)
3963 {
3964 0 *vp = JSVAL_VOID;
3965 0 break;
3966 }
3967
3968 29792 str = JS_InternString(cx, (const char *) element->namedTypeNs);
3969 29792 *vp = STRING_TO_JSVAL(str);
3970 29792 break;
3971
3972 case substGroup:
3973
3974 0 if(!element->substGroup)
3975 {
3976 0 *vp = JSVAL_VOID;
3977 0 break;
3978 }
3979
3980 0 str = JS_InternString(cx, (const char *) element->substGroup);
3981 0 *vp = STRING_TO_JSVAL(str);
3982 0 break;
3983
3984 case substGroupNs:
3985
3986 0 if(!element->substGroupNs)
3987 {
3988 0 *vp = JSVAL_VOID;
3989 0 break;
3990 }
3991
3992 0 str = JS_InternString(cx, (const char *) element->substGroupNs);
3993 0 *vp = STRING_TO_JSVAL(str);
3994 0 break;
3995
3996 case contentType:
3997
3998 0 *vp = INT_TO_JSVAL(element->contentType);
3999 0 break;
4000
4001 case qname:
4002
4003 0 if(!element->name)
4004 {
4005 0 *vp = JSVAL_VOID;
4006 0 break;
4007 }
4008 0 else if(!element->targetNamespace)
4009 {
4010 0 str = JS_InternString(cx, (const char *) element->name);
4011 0 *vp = STRING_TO_JSVAL(str);
4012 0 break;
4013 }
4014 else
4015 {
4016 0 str = globus_l_wsdl_jscript_qname_string(
4017 cx, element->targetNamespace, element->name);
4018 0 *vp = STRING_TO_JSVAL(str);
4019 0 break;
4020 }
4021
4022 case Default:
4023 220 if (element->value)
4024 {
4025 0 str = JS_InternString(cx, (const char *) element->value);
4026 0 *vp = STRING_TO_JSVAL(str);
4027 }
4028 else
4029 {
4030 220 *vp = JSVAL_VOID;
4031 }
4032 220 break;
4033 case nillable:
4034 7871 if(element->flags & XML_SCHEMAS_ELEM_NILLABLE)
4035 {
4036 266 *vp = JSVAL_TRUE;
4037 }
4038 else
4039 {
4040 7605 *vp = JSVAL_FALSE;
4041 }
4042 7871 break;
4043 case documentation:
4044 1178 *vp = JSVAL_VOID;
4045 1178 if (element->annot != NULL)
4046 {
4047 xmlNodePtr tmp;
4048 47 xmlBufferPtr buf = xmlBufferCreate();
4049
4050 47 tmp = element->annot->content->children;
4051
4052 94 while (tmp != NULL)
4053 {
4054 47 if (strcmp((char *) tmp->name, "documentation") == 0)
4055 {
4056 47 xmlNodeDump(buf, element->node->doc, tmp->children, 0, 0);
4057 47 str = JS_InternString(cx, (char *) buf->content);
4058 47 *vp = STRING_TO_JSVAL(str);
4059 47 break;
4060 }
4061 0 tmp = tmp->next;
4062 }
4063 }
4064 1178 break;
4065
4066 case namespaces:
4067 0 if (element->node != NULL && element->node->ns != NULL)
4068 {
4069 0 res = GetNamespaces(cx, element->node->ns, vp);
4070 }
4071 0 break;
4072 default:
4073
4074 0 *vp = JSVAL_VOID;
4075 0 JS_ReportError(cx, "Unknown property with id %d for element", idval);
4076 0 res = JS_FALSE;
4077 goto exit;
4078 }
4079
4080 279013 exit:
4081
4082 279013 GlobusWSDLDebugExit();
4083 279013 return res;
4084 }
4085
4086 static
4087 JSBool
4088 messageGetter(
4089 JSContext * cx,
4090 JSObject * obj,
4091 jsval jid,
4092 jsval * vp)
4093 3873 {
4094 3873 JSBool res = JS_TRUE;
4095 int idval;
4096 3873 JSString * str = NULL;
4097 3873 JSObject * partsObj = NULL;
4098 3873 wsdlMessagePtr message = NULL;
4099 GlobusFuncName(messageGetter);
4100 3873 GlobusWSDLDebugEnter();
4101
4102 3873 message = (wsdlMessagePtr) JS_GetPrivate(cx, obj);
4103 3873 globus_assert(message);
4104
4105 3873 if(!JSVAL_IS_INT(jid))
4106 {
4107 0 JS_ReportError(cx,
4108 "Invalid id type (expected int) for "
4109 "wsdl element property");
4110 0 res = JS_FALSE;
4111 0 goto exit;
4112 }
4113
4114
4115 3873 idval = JSVAL_TO_INT(jid);
4116 3873 switch(idval)
4117 {
4118
4119 case name:
4120
4121 0 if(!message->name)
4122 {
4123 0 *vp = JSVAL_VOID;
4124 0 break;
4125 }
4126
4127 0 str = JS_InternString(cx, (const char *) message->name);
4128 0 globus_assert(str);
4129
4130 0 *vp = STRING_TO_JSVAL(str);
4131 0 break;
4132
4133 case parts:
4134
4135 3873 if(!message->parts)
4136 {
4137 42 *vp = JSVAL_VOID;
4138 42 break;
4139 }
4140
4141 3831 partsObj = JS_NewObject(cx, &parts_class, NULL, obj);
4142 3831 globus_assert(partsObj);
4143
4144 3831 JS_SetPrivate(cx, partsObj, (void *) message->parts);
4145
4146 3831 *vp = OBJECT_TO_JSVAL(partsObj);
4147 3831 break;
4148
4149 case targetNamespace:
4150
4151 0 if(!message->schema || !message->schema->targetNamespace)
4152 {
4153 0 *vp = JSVAL_VOID;
4154 0 break;
4155 }
4156
4157 0 str = JS_InternString(cx,
4158 (const char *) message->schema->targetNamespace);
4159 0 globus_assert(str);
4160
4161 0 *vp = STRING_TO_JSVAL(str);
4162 0 break;
4163
4164 default:
4165
4166 0 *vp = JSVAL_VOID;
4167 0 JS_ReportError(cx,
4168 "Unknown message property with "
4169 "id %d for element", idval);
4170 0 res = JS_FALSE;
4171 goto exit;
4172 }
4173
4174 3873 exit:
4175
4176 3873 GlobusWSDLDebugExit();
4177 3873 return res;
4178 }
4179
4180 #include "wsdlInternals.h"
4181
4182 static
4183 JSBool
4184 xsdQNamesGetter(
4185 JSContext * cx,
4186 JSObject * obj,
4187 jsval id,
4188 jsval * vp)
4189 0 {
4190 xsdQNamePtr qn;
4191 JSObject * qnObj;
4192 0 JSBool res = JS_TRUE;
4193 JSString * str;
4194 0 int i = 0;
4195 GlobusFuncName(xsdQNamesGetter);
4196 0 GlobusWSDLDebugEnter();
4197
4198 0 qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
4199 0 globus_assert(qn);
4200
4201 0 if(JSVAL_IS_STRING(id))
4202 {
4203 0 while(qn)
4204 {
4205 0 str = globus_l_wsdl_jscript_qname_string(
4206 cx, qn->Namespace, qn->name);
4207 0 *vp = STRING_TO_JSVAL(str);
4208 0 if(JS_CompareStrings(str, JSVAL_TO_STRING(id)))
4209 {
4210 0 break;
4211 }
4212
4213 0 qn = qn->next;
4214 }
4215 }
4216 0 else if(JSVAL_IS_INT(id))
4217 {
4218 for(; i < JSVAL_TO_INT(id) && type; ++i)
4219 {
4220 qn = qn->next;
4221 }
4222 0 globus_assert(qn);
4223 }
4224 else
4225 {
4226 0 qn = (xsdQNamePtr) JSVAL_TO_PRIVATE(id);
4227 0 globus_assert(qn);
4228 }
4229
4230 0 qnObj = JS_NewObject(cx, &xsdQName_class,
4231 xsdQNameClass, obj);
4232 0 globus_assert(qnObj);
4233 0 JS_SetPrivate(cx, qnObj, (void *)qn);
4234 0 JS_DefineProperties(cx, qnObj, xsdQName_properties);
4235 0 *vp = OBJECT_TO_JSVAL(qnObj);
4236
4237 0 GlobusWSDLDebugExit();
4238 0 return res;
4239 }
4240
4241 static
4242 JSBool
4243 xsdQNamesEnumerate(
4244 JSContext * cx,
4245 JSObject * obj,
4246 JSIterateOp enum_op,
4247 jsval * statep,
4248 jsid * idp)
4249 0 {
4250 0 xsdQNamePtr qn = NULL;
4251 0 JSBool res = JS_TRUE;
4252 0 int i = 0;
4253 int index;
4254 GlobusFuncName(xsdQNameEnumerate);
4255 0 GlobusWSDLDebugEnter();
4256
4257 0 qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
4258 0 globus_assert(qn);
4259
4260 0 switch(enum_op)
4261 {
4262 case JSENUMERATE_INIT:
4263
4264 0 *statep = INT_TO_JSVAL(0);
4265 0 if(idp)
4266 {
4267 0 *idp = JSVAL_ZERO;
4268 }
4269 0 break;
4270
4271 case JSENUMERATE_NEXT:
4272
4273 0 index = JSVAL_TO_INT(*statep);
4274 0 for(; i < index && qn; ++i)
4275 {
4276 0 qn = qn->next;
4277 }
4278
4279 0 if(!qn)
4280 {
4281 0 *statep = JSVAL_NULL;
4282 0 *idp = JSVAL_ZERO;
4283 0 break;
4284 }
4285
4286 0 *idp = *statep;
4287 0 *statep = INT_TO_JSVAL(index + 1);
4288
4289 break;
4290
4291 case JSENUMERATE_DESTROY:
4292
4293 break;
4294 }
4295
4296 0 GlobusWSDLDebugExit();
4297 0 return res;
4298 }
4299
4300 static
4301 JSBool
4302 xsdQNameGetter(
4303 JSContext * cx,
4304 JSObject * obj,
4305 jsval jid,
4306 jsval * vp)
4307 0 {
4308 xsdQNamePtr qn;
4309 0 JSBool res = JS_TRUE;
4310 jsval idval;
4311 JSString * str;
4312 GlobusFuncName(xsdQNameGetter);
4313 0 GlobusWSDLDebugEnter();
4314
4315 0 qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
4316 0 globus_assert(qn);
4317
4318 0 if(!JSVAL_IS_INT(jid))
4319 {
4320 0 JS_ReportError(cx,
4321 "Invalid id type (expected int) for "
4322 "wsdl xsdQName property");
4323 0 res = JS_FALSE;
4324 0 goto exit;
4325 }
4326
4327 0 idval = JSVAL_TO_INT(jid);
4328 0 switch(idval)
4329 {
4330 case name:
4331
4332 0 if(!qn->name)
4333 {
4334 0 *vp = JSVAL_VOID;
4335 0 break;
4336 }
4337
4338 0 str = JS_InternString(cx, (const char *) qn->name);
4339 0 if(!str)
4340 {
4341 0 *vp = JSVAL_VOID;
4342 0 break;
4343 }
4344
4345 0 *vp = STRING_TO_JSVAL(str);
4346 0 break;
4347
4348 case Namespace:
4349
4350 0 if(!qn->Namespace)
4351 {
4352 0 *vp = JSVAL_VOID;
4353 0 break;
4354 }
4355
4356 0 str = JS_InternString(cx, (const char *) qn->Namespace);
4357 0 if(!str)
4358 {
4359 0 *vp = JSVAL_VOID;
4360 0 break;
4361 }
4362
4363 0 *vp = STRING_TO_JSVAL(str);
4364 0 break;
4365
4366 case qname:
4367
4368 0 if(!qn->name)
4369 {
4370 0 *vp = JSVAL_VOID;
4371 0 break;
4372 }
4373 0 else if(!qn->Namespace)
4374 {
4375 0 str = JS_InternString(cx, (const char *) qn->name);
4376 0 if(!str)
4377 {
4378 0 *vp = JSVAL_VOID;
4379 0 break;
4380 }
4381
4382 0 *vp = STRING_TO_JSVAL(str);
4383 0 break;
4384 }
4385 else
4386 {
4387 0 str = globus_l_wsdl_jscript_qname_string(
4388 cx, qn->Namespace, qn->name);
4389 0 *vp = STRING_TO_JSVAL(str);
4390 0 break;
4391 }
4392
4393 default:
4394
4395 0 *vp = JSVAL_VOID;
4396 0 JS_ReportError(cx,
4397 "Unknown xsdQName property "
4398 "with id %d for element", idval);
4399 0 res = JS_FALSE;
4400 goto exit;
4401 }
4402
4403 0 exit:
4404
4405 0 GlobusWSDLDebugExit();
4406 0 return res;
4407 }
4408
4409 static
4410 JSBool
4411 portTypeGetter(
4412 JSContext * cx,
4413 JSObject * obj,
4414 jsval jid,
4415 jsval * vp)
4416 3936 {
4417 3936 JSBool res = JS_TRUE;
4418 3936 JSString * str = NULL;
4419 int idval;
4420 3936 JSObject * operationsObj = NULL;
4421 3936 JSObject * xsdQNamesObj = NULL;
4422 3936 wsdlPortTypePtr portType = NULL;
4423 GlobusFuncName(portTypeGetter);
4424 3936 GlobusWSDLDebugEnter();
4425
4426 3936 portType = (wsdlPortTypePtr) JS_GetPrivate(cx, obj);
4427 3936 globus_assert(portType);
4428
4429 3936 if(!JSVAL_IS_INT(jid))
4430 {
4431 0 JS_ReportError(cx,
4432 "Invalid id type (expected int) for "
4433 "wsdl PortType property");
4434 0 res = JS_FALSE;
4435 0 goto exit;
4436 }
4437
4438 3936 idval = JSVAL_TO_INT(jid);
4439 3936 switch(idval)
4440 {
4441 case name:
4442
4443 1971 if(!portType->name)
4444 {
4445 0 *vp = JSVAL_VOID;
4446 0 break;
4447 }
4448
4449 1971 str = JS_InternString(cx, (const char *) portType->name);
4450 1971 if(!str)
4451 {
4452 0 *vp = JSVAL_VOID;
4453 0 break;
4454 }
4455
4456 1971 *vp = STRING_TO_JSVAL(str);
4457 1971 break;
4458
4459 case operations:
4460
4461 1488 if(!portType->operations)
4462 {
4463 0 *vp = JSVAL_VOID;
4464 0 break;
4465 }
4466
4467 1488 operationsObj = JS_NewObject(cx, &operations_class, NULL, obj);
4468 1488 globus_assert(operationsObj);
4469
4470 1488 JS_SetPrivate(cx, operationsObj, (void *) portType->operations);
4471
4472 1488 *vp = OBJECT_TO_JSVAL(operationsObj);
4473 1488 break;
4474
4475 case ResourceProperties:
4476
4477 156 if(!portType->ResourceProperties)
4478 {
4479 156 *vp = JSVAL_VOID;
4480 156 break;
4481 }
4482
4483 0 xsdQNamesObj = JS_NewObject(cx, &xsdQNames_class, NULL, obj);
4484 0 globus_assert(xsdQNamesObj);
4485
4486 0 JS_SetPrivate(cx, xsdQNamesObj, (void *) portType->ResourceProperties);
4487
4488 0 *vp = OBJECT_TO_JSVAL(xsdQNamesObj);
4489 0 break;
4490
4491 case implements:
4492
4493 0 if(!portType->implements)
4494 {
4495 0 *vp = JSVAL_VOID;
4496 0 break;
4497 }
4498
4499 0 xsdQNamesObj = JS_NewObject(cx, &xsdQNames_class, NULL, obj);
4500 0 globus_assert(xsdQNamesObj);
4501
4502 0 JS_SetPrivate(cx, xsdQNamesObj, (void *) portType->implements);
4503
4504 0 *vp = OBJECT_TO_JSVAL(xsdQNamesObj);
4505 0 break;
4506
4507 case targetNamespace:
4508
4509 321 if(!portType->schema || !portType->schema->targetNamespace)
4510 {
4511 0 *vp = JSVAL_VOID;
4512 0 break;
4513 }
4514
4515 321 str = JS_InternString(cx, (const char *) portType->schema->targetNamespace);
4516 321 globus_assert(str);
4517
4518 321 *vp = STRING_TO_JSVAL(str);
4519 321 break;
4520
4521 default:
4522
4523 0 *vp = JSVAL_VOID;
4524 0 JS_ReportError(cx,
4525 "Unknown portType property "
4526 "with id %d for element", idval);
4527 0 res = JS_FALSE;
4528 goto exit;
4529 }
4530
4531 3936 exit:
4532
4533 3936 GlobusWSDLDebugExit();
4534 3936 return res;
4535 }
4536
4537 static
4538 JSBool
4539 bindingGetter(
4540 JSContext * cx,
4541 JSObject * obj,
4542 jsval jid,
4543 jsval * vp)
4544 2282 {
4545 2282 JSBool res = JS_TRUE;
4546 int idval;
4547 2282 JSString * str = NULL;
4548 2282 JSObject * portTypeObj = NULL;
4549 2282 JSObject * operationsObj = NULL;
4550 2282 JSObject * soapBindingObj = NULL;
4551 2282 wsdlBindingPtr binding = NULL;
4552 GlobusFuncName(bindingGetter);
4553 2282 GlobusWSDLDebugEnter();
4554
4555 2282 binding = (wsdlBindingPtr) JS_GetPrivate(cx, obj);
4556 2282 globus_assert(binding);
4557
4558 2282 if(!JSVAL_IS_INT(jid))
4559 {
4560 0 JS_ReportError(cx,
4561 "Invalid id type (expected int) for "
4562 "wsdl binding property");
4563 0 res = JS_FALSE;
4564 0 goto exit;
4565 }
4566
4567
4568 2282 idval = JSVAL_TO_INT(jid);
4569 2282 switch(idval)
4570 {
4571 case name:
4572
4573 0 if(!binding->name)
4574 {
4575 0 *vp = JSVAL_VOID;
4576 0 break;
4577 }
4578
4579 0 str = JS_InternString(cx, (const char *) binding->name);
4580 0 if(!str)
4581 {
4582 0 *vp = JSVAL_VOID;
4583 0 break;
4584 }
4585
4586 0 *vp = STRING_TO_JSVAL(str);
4587 0 break;
4588
4589 case type:
4590
4591 452 if(!binding->type)
4592 {
4593 0 *vp = JSVAL_VOID;
4594 0 break;
4595 }
4596
4597 452 portTypeObj = JS_NewObject(cx, &portType_class,
4598 portTypeClass, obj);
4599 452 globus_assert(portTypeObj);
4600 452 JS_SetPrivate(cx, portTypeObj, (void *)binding->type);
4601 452 JS_DefineProperties(cx, portTypeObj, portType_properties);
4602 452 *vp = OBJECT_TO_JSVAL(portTypeObj);
4603 452 break;
4604
4605 case operations:
4606
4607 1830 if(!binding->operations)
4608 {
4609 0 *vp = JSVAL_VOID;
4610 0 break;
4611 }
4612
4613 1830 operationsObj = JS_NewObject(cx, &bindingOperations_class,
4614 NULL, obj);
4615 1830 globus_assert(operationsObj);
4616 1830 JS_SetPrivate(cx, operationsObj, (void *)binding->operations);
4617
4618 1830 *vp = OBJECT_TO_JSVAL(operationsObj);
4619 1830 break;
4620
4621 case soap:
4622
4623 0 if(!binding->extension || (binding->extensionType != SOAP_BINDING))
4624 {
4625 0 *vp = JSVAL_VOID;
4626 0 break;
4627 }
4628
4629 0 soapBindingObj = JS_NewObject(cx, &soapBinding_class,
4630 soapBindingClass, obj);
4631 0 globus_assert(soapBindingObj);
4632 0 JS_SetPrivate(cx, soapBindingObj,
4633 (void *)binding->extension);
4634 0 JS_DefineProperties(cx, soapBindingObj,
4635 soapBinding_properties);
4636 0 *vp = OBJECT_TO_JSVAL(soapBindingObj);
4637 0 break;
4638
4639 case extensionType:
4640
4641 0 *vp = INT_TO_JSVAL(binding->extensionType);
4642 0 break;
4643
4644 case targetNamespace:
4645
4646 0 if(!binding->schema || !binding->schema->targetNamespace)
4647 {
4648 0 *vp = JSVAL_VOID;
4649 0 break;
4650 }
4651
4652 0 str = JS_InternString(cx, (const char *) binding->schema->targetNamespace);
4653 0 globus_assert(str);
4654
4655 0 *vp = STRING_TO_JSVAL(str);
4656 0 break;
4657
4658 default:
4659
4660 0 *vp = JSVAL_VOID;
4661 0 JS_ReportError(cx,
4662 "Unknown property for binding "
4663 "with id %d for element", idval);
4664 0 res = JS_FALSE;
4665 goto exit;
4666 }
4667
4668 2282 exit:
4669
4670 2282 GlobusWSDLDebugExit();
4671 2282 return res;
4672 }
4673
4674 static
4675 JSBool
4676 bindingOperationsGetter(
4677 JSContext * cx,
4678 JSObject * obj,
4679 jsval id,
4680 jsval * vp)
4681 1572 {
4682 1572 JSBool res = JS_TRUE;
4683 wsdlBindingOperationPtr bop;
4684 JSObject * bopObj;
4685 1572 int i = 0;
4686 GlobusFuncName(bindingOperationsGetter);
4687 1572 GlobusWSDLDebugEnter();
4688
4689 1572 bop = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4690 1572 globus_assert(bop);
4691
4692 1572 if(JSVAL_IS_STRING(id))
4693 {
4694 0 while(bop)
4695 {
4696 JSString * name;
4697
4698 0 name = JS_InternString(cx, (const char *) bop->name);
4699 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
4700 {
4701 0 break;
4702 }
4703
4704 0 bop = bop->next;
4705 }
4706 }
4707 3144 else if(JSVAL_IS_INT(id))
4708 {
4709 5991 for(; i < JSVAL_TO_INT(id) && bop; ++i)
4710 {
4711 4419 bop = bop->next;
4712 }
4713 1572 globus_assert(bop);
4714 }
4715 else
4716 {
4717 0 bop = (wsdlBindingOperationPtr) JSVAL_TO_PRIVATE(id);
4718 0 globus_assert(bop);
4719 }
4720
4721 1572 bopObj = JS_NewObject(cx, &bindingOperation_class,
4722 bindingOperationClass, obj);
4723 1572 globus_assert(bopObj);
4724 1572 JS_SetPrivate(cx, bopObj, (void *)bop);
4725 1572 JS_DefineProperties(cx, bopObj, bindingOperation_properties);
4726 1572 *vp = OBJECT_TO_JSVAL(bopObj);
4727
4728 1572 GlobusWSDLDebugExit();
4729 1572 return res;
4730 }
4731
4732 static
4733 JSBool
4734 bindingOperationsEnumerate(
4735 JSContext * cx,
4736 JSObject * obj,
4737 JSIterateOp enum_op,
4738 jsval * statep,
4739 jsid * idp)
4740 1830 {
4741 1830 JSBool res = JS_TRUE;
4742 wsdlBindingOperationPtr boperation;
4743 1830 int i = 0;
4744 int index;
4745 GlobusFuncName(bindingOperationsEnumerate);
4746 1830 GlobusWSDLDebugEnter();
4747
4748 1830 boperation = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4749 1830 globus_assert(boperation);
4750
4751 1830 switch(enum_op)
4752 {
4753 case JSENUMERATE_INIT:
4754
4755 258 *statep = INT_TO_JSVAL(i);
4756 258 break;
4757
4758 case JSENUMERATE_NEXT:
4759
4760 1572 index = JSVAL_TO_INT(*statep);
4761 6777 for(; i < index && boperation; ++i)
4762 {
4763 5205 boperation = boperation->next;
4764 }
4765
4766 1572 if(!boperation)
4767 {
4768 258 *statep = JSVAL_NULL;
4769 258 *idp = JSVAL_ZERO;
4770 258 break;
4771 }
4772
4773 1314 *idp = *statep;
4774 1314 *statep = INT_TO_JSVAL(index + 1);
4775
4776 break;
4777
4778 case JSENUMERATE_DESTROY:
4779
4780 break;
4781 }
4782
4783 1830 GlobusWSDLDebugExit();
4784 1830 return res;
4785 }
4786
4787 static
4788 JSBool
4789 bindingOperationGetter(
4790 JSContext * cx,
4791 JSObject * obj,
4792 jsval jid,
4793 jsval * vp)
4794 1314 {
4795 int idval;
4796 JSString * str;
4797 1314 JSBool res = JS_TRUE;
4798 1314 JSObject * inObj = NULL;
4799 1314 JSObject * outObj = NULL;
4800 1314 JSObject * faultsObj = NULL;
4801 1314 JSObject * soapObj = NULL;
4802 1314 wsdlBindingOperationPtr bop = NULL;
4803 GlobusFuncName(bindingOperationGetter);
4804 1314 GlobusWSDLDebugEnter();
4805
4806 1314 bop = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4807 1314 globus_assert(bop);
4808
4809 1314 if(!JSVAL_IS_INT(jid))
4810 {
4811 0 JS_ReportError(cx,
4812 "Invalid id type (expected int) "
4813 "for wsdl bindingOperation property");
4814 0 res = JS_FALSE;
4815 0 goto exit;
4816 }
4817
4818 1314 idval = JSVAL_TO_INT(jid);
4819
4820 1314 switch(idval)
4821 {
4822 case name:
4823
4824 1314 if(!bop->name)
4825 {
4826 0 *vp = JSVAL_VOID;
4827 0 break;
4828 }
4829
4830 1314 str = JS_InternString(cx, (const char *) bop->name);
4831 1314 globus_assert(str);
4832
4833 1314 *vp = STRING_TO_JSVAL(str);
4834 1314 break;
4835
4836 case input:
4837
4838 0 if(!bop->input || (bop->inputType != SOAP_BINDING))
4839 {
4840 0 *vp = JSVAL_VOID;
4841 0 break;
4842 }
4843
4844 0 inObj = JS_NewObject(cx, &soapBindingParam_class,
4845 soapBindingParamClass, obj);
4846 0 globus_assert(inObj);
4847 0 JS_SetPrivate(cx, inObj, (void *)bop->input);
4848 0 JS_DefineProperties(cx, inObj, soapBindingParam_properties);
4849 0 *vp = OBJECT_TO_JSVAL(inObj);
4850 0 break;
4851
4852 case output:
4853
4854 0 if(!bop->output || (bop->outputType != SOAP_BINDING))
4855 {
4856 0 *vp = JSVAL_VOID;
4857 0 break;
4858 }
4859
4860 0 outObj = JS_NewObject(cx, &soapBindingParam_class,
4861 soapBindingParamClass, obj);
4862 0 globus_assert(outObj);
4863 0 JS_SetPrivate(cx, outObj, (void *)bop->output);
4864 0 JS_DefineProperties(cx, outObj, soapBindingParam_properties);
4865 0 *vp = OBJECT_TO_JSVAL(outObj);
4866 0 break;
4867
4868 case inputType:
4869
4870 0 *vp = INT_TO_JSVAL(bop->inputType);
4871 0 break;
4872
4873 case outputType:
4874
4875 0 *vp = INT_TO_JSVAL(bop->outputType);
4876 0 break;
4877
4878 case faults:
4879
4880 0 if(!bop->faults)
4881 {
4882 0 *vp = JSVAL_VOID;
4883 0 break;
4884 }
4885
4886 0 faultsObj = JS_NewObject(cx, &bindingOperationFaults_class,
4887 NULL, obj);
4888 0 globus_assert(faultsObj);
4889 0 JS_SetPrivate(cx, faultsObj, (void *) bop->faults);
4890
4891 0 *vp = OBJECT_TO_JSVAL(faultsObj);
4892 0 break;
4893
4894 case soap:
4895
4896 0 if(!bop->extension || (bop->extensionType != SOAP_BINDING))
4897 {
4898 0 *vp = JSVAL_VOID;
4899 0 break;
4900 }
4901
4902 0 soapObj = JS_NewObject(cx, &soapOperation_class,
4903 soapOperationClass, obj);
4904 0 globus_assert(soapObj);
4905 0 JS_SetPrivate(cx, soapObj, (void *)bop->extension);
4906 0 JS_DefineProperties(cx, soapObj, soapOperation_properties);
4907 0 *vp = OBJECT_TO_JSVAL(soapObj);
4908 0 break;
4909
4910 default:
4911
4912 0 *vp = JSVAL_VOID;
4913 0 JS_ReportError(cx,
4914 "Unknown binding operation property "
4915 "with id %d for part", idval);
4916 0 res = JS_FALSE;
4917 goto exit;
4918 }
4919
4920 1314 exit:
4921
4922 1314 GlobusWSDLDebugExit();
4923 1314 return res;
4924 }
4925
4926 static
4927 JSBool
4928 bindingOperationFaultsGetter(
4929 JSContext * cx,
4930 JSObject * obj,
4931 jsval id,
4932 jsval * vp)
4933 0 {
4934 wsdlBindingOperationFaultPtr bopf;
4935 JSObject * bopfObj;
4936 0 JSBool res = JS_TRUE;
4937 0 int i = 0;
4938 GlobusFuncName(bindingOperationFaultsGetter);
4939 0 GlobusWSDLDebugEnter();
4940
4941 0 bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
4942 0 globus_assert(bopf);
4943
4944 0 if(JSVAL_IS_STRING(id))
4945 {
4946 0 while(bopf)
4947 {
4948 JSString * name;
4949
4950 0 name = JS_InternString(cx, (const char *) bopf->name);
4951 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
4952 {
4953 0 break;
4954 }
4955
4956 0 bopf = bopf->next;
4957 }
4958 }
4959 0 else if(JSVAL_IS_INT(id))
4960 {
4961 0 for(; i < JSVAL_TO_INT(id) && bopf; ++i)
4962 {
4963 0 bopf = bopf->next;
4964 }
4965 0 globus_assert(bopf);
4966 }
4967 else
4968 {
4969 0 bopf = (wsdlBindingOperationFaultPtr) JSVAL_TO_PRIVATE(id);
4970 0 globus_assert(bopf);
4971 }
4972
4973 0 bopfObj = JS_NewObject(cx, &bindingOperationFault_class,
4974 bindingOperationFaultClass, obj);
4975 0 globus_assert(bopfObj);
4976 0 JS_SetPrivate(cx, bopfObj, (void *)bopf);
4977 0 JS_DefineProperties(cx, bopfObj,
4978 bindingOperationFault_properties);
4979
4980 0 *vp = OBJECT_TO_JSVAL(bopfObj);
4981
4982 0 GlobusWSDLDebugExit();
4983 0 return res;
4984 }
4985
4986 static
4987 JSBool
4988 bindingOperationFaultsEnumerate(
4989 JSContext * cx,
4990 JSObject * obj,
4991 JSIterateOp enum_op,
4992 jsval * statep,
4993 jsid * idp)
4994 0 {
4995 0 JSBool res = JS_TRUE;
4996 wsdlBindingOperationFaultPtr bopf;
4997 0 int i = 0;
4998 int index;
4999 GlobusFuncName(bindingOperationFaultsEnumerate);
5000 0 GlobusWSDLDebugEnter();
5001
5002 0 bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
5003 0 globus_assert(bopf);
5004
5005 0 switch(enum_op)
5006 {
5007 case JSENUMERATE_INIT:
5008
5009 0 *statep = INT_TO_JSVAL(i);
5010 0 break;
5011
5012 case JSENUMERATE_NEXT:
5013
5014 0 index = JSVAL_TO_INT(*statep);
5015 0 for(; i < index && bopf; ++i)
5016 {
5017 0 bopf = bopf->next;
5018 }
5019
5020 0 if(!bopf)
5021 {
5022 0 *statep = JSVAL_NULL;
5023 0 *idp = JSVAL_ZERO;
5024 0 break;
5025 }
5026
5027 0 *idp = *statep;
5028 0 *statep = INT_TO_JSVAL(index + 1);
5029
5030 break;
5031
5032 case JSENUMERATE_DESTROY:
5033
5034 break;
5035 }
5036
5037 0 GlobusWSDLDebugExit();
5038 0 return res;
5039 }
5040
5041 static
5042 JSBool
5043 bindingOperationFaultGetter(
5044 JSContext * cx,
5045 JSObject * obj,
5046 jsval jid,
5047 jsval * vp)
5048 0 {
5049 int idval;
5050 0 JSString * str = NULL;
5051 0 JSBool res = JS_TRUE;
5052 0 wsdlBindingOperationFaultPtr bopf = NULL;
5053 0 JSObject * soapObj = NULL;
5054 GlobusFuncName(bindingOperationFaultGetter);
5055 0 GlobusWSDLDebugEnter();
5056
5057 0 bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
5058 0 globus_assert(bopf);
5059
5060 0 if(!JSVAL_IS_INT(jid))
5061 {
5062 0 JS_ReportError(cx,
5063 "Invalid id type (expected int) "
5064 "for wsdl bindingOperationFault property");
5065 0 res = JS_FALSE;
5066 0 goto exit;
5067 }
5068
5069 0 idval = JSVAL_TO_INT(jid);
5070
5071 0 switch(idval)
5072 {
5073 case name:
5074
5075 0 if(!bopf->name)
5076 {
5077 0 *vp = JSVAL_VOID;
5078 0 break;
5079 }
5080
5081 0 str = JS_InternString(cx, (const char *) bopf->name);
5082 0 globus_assert(str);
5083
5084 0 *vp = STRING_TO_JSVAL(str);
5085 0 break;
5086
5087 case soap:
5088
5089 0 if(!bopf->extension || (bopf->extensionType != SOAP_BINDING))
5090 {
5091 0 *vp = JSVAL_VOID;
5092 0 break;
5093 }
5094
5095 0 soapObj = JS_NewObject(cx, &soapFault_class, soapFaultClass, obj);
5096 0 globus_assert(soapObj);
5097 0 JS_SetPrivate(cx, soapObj, bopf->extension);
5098 0 JS_DefineProperties(cx, soapObj, soapFault_properties);
5099 0 *vp = OBJECT_TO_JSVAL(soapObj);
5100 0 break;
5101
5102 default:
5103
5104 0 *vp = JSVAL_VOID;
5105 0 JS_ReportError(cx, "Unknown part property with id %d for part", idval);
5106 0 res = JS_FALSE;
5107 goto exit;
5108 }
5109
5110 0 exit:
5111
5112 0 GlobusWSDLDebugExit();
5113 0 return res;
5114 }
5115
5116 static
5117 JSBool
5118 partsEnumerate(
5119 JSContext * cx,
5120 JSObject * obj,
5121 JSIterateOp enum_op,
5122 jsval * statep,
5123 jsid * idp)
5124 0 {
5125 0 JSBool res = JS_TRUE;
5126 wsdlPartPtr parts;
5127 0 int i = 0;
5128 int index;
5129 GlobusFuncName(partsEnumerate);
5130 0 GlobusWSDLDebugEnter();
5131
5132 0 parts = (wsdlPartPtr) JS_GetPrivate(cx, obj);
5133 0 globus_assert(parts);
5134
5135 0 switch(enum_op)
5136 {
5137 case JSENUMERATE_INIT:
5138
5139 0 *statep = INT_TO_JSVAL(i);
5140 0 break;
5141
5142 case JSENUMERATE_NEXT:
5143
5144 0 index = JSVAL_TO_INT(*statep);
5145 0 for(; i < index && parts; ++i)
5146 {
5147 0 parts = parts->next;
5148 }
5149
5150 0 if(!parts)
5151 {
5152 0 *statep = JSVAL_NULL;
5153 0 *idp = JSVAL_ZERO;
5154 0 break;
5155 }
5156
5157 0 *idp = *statep;
5158 0 *statep = INT_TO_JSVAL(index + 1);
5159
5160 break;
5161
5162 case JSENUMERATE_DESTROY:
5163
5164 break;
5165 }
5166
5167 0 GlobusWSDLDebugExit();
5168 0 return res;
5169 }
5170
5171 static
5172 JSBool
5173 partsGetter(
5174 JSContext * cx,
5175 JSObject * obj,
5176 jsval id,
5177 jsval * vp)
5178 2090 {
5179 2090 wsdlPartPtr part = NULL;
5180 2090 JSObject * partObj = NULL;
5181 2090 JSBool res = JS_TRUE;
5182 2090 int i = 0;
5183 GlobusFuncName(partsGetter);
5184 2090 GlobusWSDLDebugEnter();
5185
5186 2090 part = (wsdlPartPtr) JS_GetPrivate(cx, obj);
5187 2090 globus_assert(part);
5188
5189 2090 if(JSVAL_IS_STRING(id))
5190 {
5191 0 while(part)
5192 {
5193 JSString * name;
5194
5195 0 name = JS_InternString(cx, (const char *) part->name);
5196 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5197 {
5198 0 break;
5199 }
5200
5201 0 part = part->next;
5202 }
5203 }
5204 2090 else if(JSVAL_IS_INT(id))
5205 {
5206 2090 for(; i < JSVAL_TO_INT(id) && part; ++i)
5207 {
5208 0 part = part->next;
5209 }
5210 2090 globus_assert(part);
5211 }
5212
5213 2090 partObj = JS_NewObject(cx, &part_class,
5214 partClass, obj);
5215 2090 globus_assert(partObj);
5216 2090 JS_SetPrivate(cx, partObj, (void *)part);
5217 2090 JS_DefineProperties(cx, partObj, part_properties);
5218
5219 2090 *vp = OBJECT_TO_JSVAL(partObj);
5220
5221 2090 GlobusWSDLDebugExit();
5222 2090 return res;
5223 }
5224
5225 static
5226 JSBool
5227 partGetter(
5228 JSContext * cx,
5229 JSObject * obj,
5230 jsval jid,
5231 jsval * vp)
5232 2090 {
5233 int idval;
5234 2090 JSString * str = NULL;
5235 2090 JSObject * typeObj = NULL;
5236 2090 JSObject * elementObj = NULL;
5237 2090 JSBool res = JS_TRUE;
5238 2090 wsdlPartPtr part = NULL;
5239 GlobusFuncName(partGetter);
5240 2090 GlobusWSDLDebugEnter();
5241
5242 2090 part = (wsdlPartPtr) JS_GetPrivate(cx, obj);
5243 2090 globus_assert(part);
5244
5245 2090 if(!JSVAL_IS_INT(jid))
5246 {
5247 0 JS_ReportError(cx,
5248 "Invalid id type (expected int) "
5249 "for wsdl part property");
5250 0 res = JS_FALSE;
5251 0 goto exit;
5252 }
5253
5254 2090 idval = JSVAL_TO_INT(jid);
5255
5256 2090 switch(idval)
5257 {
5258 case name:
5259
5260 0 if(!part->name)
5261 {
5262 0 *vp = JSVAL_VOID;
5263 0 break;
5264 }
5265
5266 0 str = JS_InternString(cx, (const char *) part->name);
5267 0 globus_assert(str);
5268
5269 0 *vp = STRING_TO_JSVAL(str);
5270 0 break;
5271
5272 case type:
5273
5274 0 if(!part->type)
5275 {
5276 0 *vp = JSVAL_VOID;
5277 0 break;
5278 }
5279
5280 0 typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
5281 0 globus_assert(typeObj);
5282 0 JS_SetPrivate(cx, typeObj, (void *)part->type);
5283 0 JS_DefineProperties(cx, typeObj, xsdType_properties);
5284 0 *vp = OBJECT_TO_JSVAL(typeObj);
5285 0 break;
5286
5287 case element:
5288
5289 2090 if(!part->element)
5290 {
5291 0 *vp = JSVAL_VOID;
5292 0 break;
5293 }
5294
5295 2090 elementObj = JS_NewObject(cx, &xsdElement_class, xsdElementClass, obj);
5296 2090 globus_assert(elementObj);
5297 2090 JS_SetPrivate(cx, elementObj, (void *)part->element);
5298 2090 JS_DefineProperties(cx, elementObj, xsdElement_properties);
5299 2090 *vp = OBJECT_TO_JSVAL(elementObj);
5300 2090 break;
5301
5302 default:
5303
5304 0 *vp = JSVAL_VOID;
5305 0 JS_ReportError(cx, "Unknown part property with id %d for part", idval);
5306 0 res = JS_FALSE;
5307 goto exit;
5308 }
5309
5310 2090 exit:
5311
5312 2090 GlobusWSDLDebugExit();
5313 2090 return res;
5314 }
5315
5316 static
5317 JSBool
5318 operationsGetter(
5319 JSContext * cx,
5320 JSObject * obj,
5321 jsval id,
5322 jsval * vp)
5323 1153 {
5324 wsdlOperationPtr operation;
5325 JSObject * operationObj;
5326 1153 JSBool res = JS_TRUE;
5327 1153 int i = 0;
5328 GlobusFuncName(operationsGetter);
5329 1153 GlobusWSDLDebugEnter();
5330
5331 1153 operation = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5332 1153 globus_assert(operation);
5333
5334 1153 if(JSVAL_IS_STRING(id))
5335 {
5336 0 while(operation)
5337 {
5338 JSString * name;
5339
5340 0 name = JS_InternString(cx, (const char *) operation->name);
5341 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5342 {
5343 0 break;
5344 }
5345
5346 0 operation = operation->next;
5347 }
5348 }
5349 2306 else if(JSVAL_IS_INT(id))
5350 {
5351 3991 for(; i < JSVAL_TO_INT(id) && operation; ++i)
5352 {
5353 2838 operation = operation->next;
5354 }
5355 1153 globus_assert(operation);
5356 }
5357 else
5358 {
5359 0 operation = (wsdlOperationPtr) JSVAL_TO_PRIVATE(id);
5360 0 globus_assert(operation);
5361 }
5362
5363 1153 operationObj = JS_NewObject(cx, &operation_class,
5364 operationClass, obj);
5365 1153 globus_assert(operationObj);
5366 1153 JS_SetPrivate(cx, operationObj, (void *)operation);
5367 1153 JS_DefineProperties(cx, operationObj, operation_properties);
5368 1153 *vp = OBJECT_TO_JSVAL(operationObj);
5369
5370 1153 GlobusWSDLDebugExit();
5371 1153 return res;
5372 }
5373
5374 static
5375 JSBool
5376 operationsEnumerate(
5377 JSContext * cx,
5378 JSObject * obj,
5379 JSIterateOp enum_op,
5380 jsval * statep,
5381 jsid * idp)
5382 1823 {
5383 1823 JSBool res = JS_TRUE;
5384 wsdlOperationPtr operations;
5385 1823 int i = 0;
5386 int index;
5387 GlobusFuncName(operationsEnumerate);
5388 1823 GlobusWSDLDebugEnter();
5389
5390 1823 operations = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5391 1823 globus_assert(operations);
5392
5393 1823 switch(enum_op)
5394 {
5395 case JSENUMERATE_INIT:
5396
5397 335 *statep = INT_TO_JSVAL(i);
5398 335 break;
5399
5400 case JSENUMERATE_NEXT:
5401
5402 1488 index = JSVAL_TO_INT(*statep);
5403 5479 for(; i < index && operations; ++i)
5404 {
5405 3991 operations = operations->next;
5406 }
5407
5408 1488 if(!operations)
5409 {
5410 335 *statep = JSVAL_NULL;
5411 335 *idp = JSVAL_ZERO;
5412 335 break;
5413 }
5414
5415 1153 *idp = *statep;
5416 1153 *statep = INT_TO_JSVAL(index + 1);
5417
5418 break;
5419
5420 case JSENUMERATE_DESTROY:
5421
5422 break;
5423 }
5424
5425 1823 GlobusWSDLDebugExit();
5426 1823 return res;
5427 }
5428
5429 static
5430 JSBool
5431 operationGetter(
5432 JSContext * cx,
5433 JSObject * obj,
5434 jsval jid,
5435 jsval * vp)
5436 15360 {
5437 15360 JSString * str = NULL;
5438 15360 JSObject * paramObj = NULL;
5439 15360 JSObject * faultsObj = NULL;
5440 int idval;
5441 15360 JSBool res = JS_TRUE;
5442 15360 wsdlOperationPtr operation = NULL;
5443 GlobusFuncName(operationGetter);
5444 15360 GlobusWSDLDebugEnter();
5445
5446 15360 operation = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5447 15360 globus_assert(operation);
5448
5449 15360 if(!JSVAL_IS_INT(jid))
5450 {
5451 0 JS_ReportError(cx,
5452 "Invalid id type (expected int) "
5453 "for wsdl operation property");
5454 0 res = JS_FALSE;
5455 0 goto exit;
5456 }
5457
5458 15360 idval = JSVAL_TO_INT(jid);
5459
5460 15360 switch(idval)
5461 {
5462 case name:
5463
5464 6321 if(!operation->name)
5465 {
5466 0 *vp = JSVAL_VOID;
5467 0 break;
5468 }
5469
5470 6321 str = JS_InternString(cx, (const char *) operation->name);
5471 6321 globus_assert(str);
5472
5473 6321 *vp = STRING_TO_JSVAL(str);
5474 6321 break;
5475
5476 case type:
5477
5478 3270 *vp = INT_TO_JSVAL(operation->type);
5479 3270 break;
5480
5481 case input:
5482
5483 1455 if(!operation->input)
5484 {
5485 0 *vp = JSVAL_VOID;
5486 0 break;
5487 }
5488
5489 1455 paramObj = JS_NewObject(cx, &param_class, paramClass, obj);
5490 1455 globus_assert(paramObj);
5491 1455 JS_SetPrivate(cx, paramObj, (void *)operation->input);
5492 1455 JS_DefineProperties(cx, paramObj, param_properties);
5493 1455 *vp = OBJECT_TO_JSVAL(paramObj);
5494 1455 break;
5495
5496 case output:
5497
5498 3051 if(!operation->output)
5499 {
5500 0 *vp = JSVAL_VOID;
5501 0 break;
5502 }
5503
5504 3051 paramObj = JS_NewObject(cx, &param_class, paramClass, obj);
5505 3051 globus_assert(paramObj);
5506 3051 JS_SetPrivate(cx, paramObj, (void *)operation->output);
5507 3051 JS_DefineProperties(cx, paramObj, param_properties);
5508 3051 *vp = OBJECT_TO_JSVAL(paramObj);
5509 3051 break;
5510
5511 case faults:
5512
5513 1263 if(!operation->faults)
5514 {
5515 61 *vp = JSVAL_VOID;
5516 61 break;
5517 }
5518
5519 1202 faultsObj = JS_NewObject(cx, &faults_class, NULL, obj);
5520 1202 globus_assert(faultsObj);
5521
5522 1202 JS_SetPrivate(cx, faultsObj, (void *)operation->faults);
5523 1202 *vp = OBJECT_TO_JSVAL(faultsObj);
5524 1202 break;
5525
5526 default:
5527
5528 0 *vp = JSVAL_VOID;
5529 0 JS_ReportError(cx, "Unknown property with id %d for part", idval);
5530 0 res = JS_FALSE;
5531 goto exit;
5532 }
5533
5534 15360 exit:
5535
5536 15360 GlobusWSDLDebugExit();
5537 15360 return res;
5538 }
5539
5540
5541 static
5542 JSBool
5543 faultsGetter(
5544 JSContext * cx,
5545 JSObject * obj,
5546 jsval id,
5547 jsval * vp)
5548 980 {
5549 wsdlFaultPtr fault;
5550 JSObject * faultObj;
5551 980 JSBool res = JS_TRUE;
5552 980 int i = 0;
5553 GlobusFuncName(faultsGetter);
5554 980 GlobusWSDLDebugEnter();
5555
5556 980 fault = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5557 980 globus_assert(fault);
5558
5559 980 if(JSVAL_IS_STRING(id))
5560 {
5561 0 while(fault)
5562 {
5563 JSString * name;
5564
5565 0 name = JS_InternString(cx, (const char *) fault->name);
5566 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5567 {
5568 0 break;
5569 }
5570
5571 0 fault = fault->next;
5572 }
5573 }
5574 1960 else if(JSVAL_IS_INT(id))
5575 {
5576 3428 for(; i < JSVAL_TO_INT(id) && fault; ++i)
5577 {
5578 2448 fault = fault->next;
5579 }
5580 980 globus_assert(fault);
5581 }
5582 else
5583 {
5584 0 fault = (wsdlFaultPtr) JSVAL_TO_PRIVATE(id);
5585 0 globus_assert(fault);
5586 }
5587
5588 980 faultObj = JS_NewObject(cx, &fault_class,
5589 faultClass, obj);
5590 980 globus_assert(faultObj);
5591 980 JS_SetPrivate(cx, faultObj, (void *)fault);
5592 980 JS_DefineProperties(cx, faultObj, fault_properties);
5593 980 *vp = OBJECT_TO_JSVAL(faultObj);
5594
5595 980 GlobusWSDLDebugExit();
5596 980 return res;
5597 }
5598
5599 static
5600 JSBool
5601 faultsEnumerate(
5602 JSContext * cx,
5603 JSObject * obj,
5604 JSIterateOp enum_op,
5605 jsval * statep,
5606 jsid * idp)
5607 1424 {
5608 1424 JSBool res = JS_TRUE;
5609 wsdlFaultPtr faults;
5610 1424 int i = 0;
5611 int index;
5612 GlobusFuncName(faultsEnumerate);
5613 1424 GlobusWSDLDebugEnter();
5614
5615 1424 faults = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5616 1424 globus_assert(faults);
5617
5618 1424 switch(enum_op)
5619 {
5620 case JSENUMERATE_INIT:
5621
5622 222 *statep = INT_TO_JSVAL(i);
5623 222 break;
5624
5625 case JSENUMERATE_NEXT:
5626
5627 1202 index = JSVAL_TO_INT(*statep);
5628 4630 for(; i < index && faults; ++i)
5629 {
5630 3428 faults = faults->next;
5631 }
5632
5633 1202 if(!faults)
5634 {
5635 222 *statep = JSVAL_NULL;
5636 222 *idp = JSVAL_ZERO;
5637 222 break;
5638 }
5639
5640 980 *idp = *statep;
5641 980 *statep = INT_TO_JSVAL(index + 1);
5642
5643 break;
5644
5645 case JSENUMERATE_DESTROY:
5646
5647 break;
5648 }
5649
5650 1424 GlobusWSDLDebugExit();
5651 1424 return res;
5652 }
5653
5654 static
5655 JSBool
5656 faultGetter(
5657 JSContext * cx,
5658 JSObject * obj,
5659 jsval jid,
5660 jsval * vp)
5661 1262 {
5662 int idval;
5663 JSString * str;
5664 JSObject * messageObj;
5665 1262 JSBool res = JS_TRUE;
5666 1262 wsdlFaultPtr fault = NULL;
5667 GlobusFuncName(faultGetter);
5668 1262 GlobusWSDLDebugEnter();
5669
5670 1262 fault = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5671 1262 globus_assert(fault);
5672
5673 1262 if(!JSVAL_IS_INT(jid))
5674 {
5675 0 JS_ReportError(cx,
5676 "Invalid id type (expected int) "
5677 "for wsdl fault property");
5678 0 res = JS_FALSE;
5679 0 goto exit;
5680 }
5681
5682 1262 idval = JSVAL_TO_INT(jid);
5683
5684 1262 switch(idval)
5685 {
5686 case name:
5687
5688 639 if(!fault->name)
5689 {
5690 0 *vp = JSVAL_VOID;
5691 0 break;
5692 }
5693
5694 639 str = JS_InternString(cx, (const char *) fault->name);
5695 639 globus_assert(str);
5696
5697 639 *vp = STRING_TO_JSVAL(str);
5698 639 break;
5699
5700 case message:
5701
5702 623 if(!fault->message)
5703 {
5704 0 *vp = JSVAL_VOID;
5705 0 break;
5706 }
5707
5708 623 messageObj = JS_NewObject(cx, &message_class, messageClass, obj);
5709 623 globus_assert(messageObj);
5710 623 JS_SetPrivate(cx, messageObj, (void *)fault->message);
5711 623 JS_DefineProperties(cx, messageObj, message_properties);
5712 623 *vp = OBJECT_TO_JSVAL(messageObj);
5713 623 break;
5714
5715 default:
5716
5717 0 *vp = JSVAL_VOID;
5718 0 JS_ReportError(cx, "Unknown fault property with id %d for part", idval);
5719 0 res = JS_FALSE;
5720 goto exit;
5721 }
5722
5723 1262 exit:
5724
5725 1262 GlobusWSDLDebugExit();
5726 1262 return res;
5727 }
5728
5729
5730 static
5731 JSBool
5732 paramGetter(
5733 JSContext * cx,
5734 JSObject * obj,
5735 jsval jid,
5736 jsval * vp)
5737 4506 {
5738 int idval;
5739 JSString * str;
5740 JSObject * messageObj;
5741 4506 JSBool res = JS_TRUE;
5742 4506 wsdlParamPtr param = NULL;
5743 GlobusFuncName(paramGetter);
5744 4506 GlobusWSDLDebugEnter();
5745
5746 4506 param = (wsdlParamPtr) JS_GetPrivate(cx, obj);
5747 4506 globus_assert(param);
5748
5749 4506 if(!JSVAL_IS_INT(jid))
5750 {
5751 0 JS_ReportError(cx,
5752 "Invalid id type (expected int) "
5753 "for wsdl param property");
5754 0 res = JS_FALSE;
5755 0 goto exit;
5756 }
5757
5758 4506 idval = JSVAL_TO_INT(jid);
5759
5760 4506 switch(idval)
5761 {
5762 case name:
5763
5764 92 if(!param->name)
5765 {
5766 92 *vp = JSVAL_VOID;
5767 92 break;
5768 }
5769
5770 0 str = JS_InternString(cx, (const char *) param->name);
5771 0 globus_assert(str);
5772
5773 0 *vp = STRING_TO_JSVAL(str);
5774 0 break;
5775
5776 case Action:
5777
5778 1164 if(!param->Action)
5779 {
5780 92 *vp = JSVAL_VOID;
5781 92 break;
5782 }
5783
5784 1072 str = JS_InternString(cx, (const char *) param->Action);
5785 1072 globus_assert(str);
5786
5787 1072 *vp = STRING_TO_JSVAL(str);
5788 1072 break;
5789
5790 case message:
5791
5792 3250 if(!param->message)
5793 {
5794 0 *vp = JSVAL_VOID;
5795 0 break;
5796 }
5797
5798 3250 messageObj = JS_NewObject(cx, &message_class, messageClass, obj);
5799 3250 globus_assert(messageObj);
5800 3250 JS_SetPrivate(cx, messageObj, (void *)param->message);
5801 3250 JS_DefineProperties(cx, messageObj, message_properties);
5802 3250 *vp = OBJECT_TO_JSVAL(messageObj);
5803 3250 break;
5804
5805 default:
5806
5807 0 *vp = JSVAL_VOID;
5808 0 JS_ReportError(cx, "Unknown param property with id %d for part", idval);
5809 0 res = JS_FALSE;
5810 goto exit;
5811 }
5812
5813 4506 exit:
5814
5815 4506 GlobusWSDLDebugExit();
5816 4506 return res;
5817 }
5818
5819 static
5820 JSBool
5821 portsGetter(
5822 JSContext * cx,
5823 JSObject * obj,
5824 jsval id,
5825 jsval * vp)
5826 547 {
5827 wsdlPortPtr port;
5828 JSObject * portObj;
5829 547 JSBool res = JS_TRUE;
5830 547 int i = 0;
5831 GlobusFuncName(portsGetter);
5832 547 GlobusWSDLDebugEnter();
5833
5834 547 port = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5835 547 globus_assert(port);
5836
5837 547 if(JSVAL_IS_STRING(id))
5838 {
5839 0 while(port)
5840 {
5841 JSString * name;
5842
5843 0 name = JS_InternString(cx, (const char *) port->name);
5844 0 if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5845 {
5846 0 break;
5847 }
5848
5849 0 port = port->next;
5850 }
5851 }
5852 1094 else if(JSVAL_IS_INT(id))
5853 {
5854 1096 for(; i < JSVAL_TO_INT(id) && port; ++i)
5855 {
5856 549 port = port->next;
5857 }
5858 547 globus_assert(port);
5859 }
5860 else
5861 {
5862 0 port = (wsdlPortPtr) JSVAL_TO_PRIVATE(id);
5863 0 globus_assert(port);
5864 }
5865
5866 547 portObj = JS_NewObject(cx, &port_class,
5867 portClass, obj);
5868 547 globus_assert(portObj);
5869 547 JS_SetPrivate(cx, portObj, (void *)port);
5870 547 JS_DefineProperties(cx, portObj, port_properties);
5871 547 *vp = OBJECT_TO_JSVAL(portObj);
5872
5873 547 GlobusWSDLDebugExit();
5874 547 return res;
5875 }
5876
5877 static
5878 JSBool
5879 portsEnumerate(
5880 JSContext * cx,
5881 JSObject * obj,
5882 JSIterateOp enum_op,
5883 jsval * statep,
5884 jsid * idp)
5885 990 {
5886 990 JSBool res = JS_TRUE;
5887 wsdlPortPtr ports;
5888 990 int i = 0;
5889 int index;
5890 GlobusFuncName(portsEnumerate);
5891 990 GlobusWSDLDebugEnter();
5892
5893 990 ports = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5894 990 globus_assert(ports);
5895
5896 990 switch(enum_op)
5897 {
5898 case JSENUMERATE_INIT:
5899
5900 269 *statep = INT_TO_JSVAL(i);
5901 269 break;
5902
5903 case JSENUMERATE_NEXT:
5904
5905 721 index = JSVAL_TO_INT(*statep);
5906 1722 for(; i < index && ports; ++i)
5907 {
5908 1001 ports = ports->next;
5909 }
5910
5911 721 if(!ports)
5912 {
5913 269 *statep = JSVAL_NULL;
5914 269 *idp = JSVAL_ZERO;
5915 269 break;
5916 }
5917
5918 452 *idp = *statep;
5919 452 *statep = INT_TO_JSVAL(index + 1);
5920
5921 break;
5922
5923 case JSENUMERATE_DESTROY:
5924
5925 break;
5926 }
5927
5928 990 GlobusWSDLDebugExit();
5929 990 return res;
5930 }
5931
5932 static
5933 JSBool
5934 portGetter(
5935 JSContext * cx,
5936 JSObject * obj,
5937 jsval jid,
5938 jsval * vp)
5939 547 {
5940 int idval;
5941 547 JSString * str = NULL;
5942 547 JSObject * bindingObj = NULL;
5943 547 JSObject * soapObj = NULL;
5944 547 JSBool res = JS_TRUE;
5945 547 wsdlPortPtr port = NULL;
5946 GlobusFuncName(portGetter);
5947 547 GlobusWSDLDebugEnter();
5948
5949 547 port = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5950 547 globus_assert(port);
5951
5952 547 if(!JSVAL_IS_INT(jid))
5953 {
5954 0 JS_ReportError(cx,
5955 "Invalid id type (expected int) "
5956 "for wsdl port property");
5957 0 res = JS_FALSE;
5958 0 goto exit;
5959 }
5960
5961 547 idval = JSVAL_TO_INT(jid);
5962
5963 547 switch(idval)
5964 {
5965 case name:
5966
5967 0 if(!port->name)
5968 {
5969 0 *vp = JSVAL_VOID;
5970 0 break;
5971 }
5972
5973 0 str = JS_InternString(cx, (const char *) port->name);
5974 0 globus_assert(str);
5975
5976 0 *vp = STRING_TO_JSVAL(str);
5977 0 break;
5978
5979 case binding:
5980
5981 452 if(!port->binding)
5982 {
5983 0 *vp = JSVAL_VOID;
5984 0 break;
5985 }
5986
5987 452 bindingObj = JS_NewObject(cx, &binding_class, bindingClass, obj);
5988 452 globus_assert(bindingObj);
5989 452 JS_SetPrivate(cx, bindingObj, (void *)port->binding);
5990 452 JS_DefineProperties(cx, bindingObj, binding_properties);
5991
5992 452 *vp = OBJECT_TO_JSVAL(bindingObj);
5993 452 break;
5994
5995 case soap:
5996
5997 95 if(!port->extension || (port->extensionType != SOAP_BINDING))
5998 {
5999 0 *vp = JSVAL_VOID;
6000 0 break;
6001 }
6002
6003 95 soapObj = JS_NewObject(cx, &soapAddress_class, soapAddressClass, obj);
6004 95 globus_assert(soapObj);
6005 95 JS_SetPrivate(cx, soapObj, (void *)port->extension);
6006 95 JS_DefineProperties(cx, soapObj, soapAddress_properties);
6007 95 *vp = OBJECT_TO_JSVAL(soapObj);
6008 95 break;
6009
6010 default:
6011
6012 0 *vp = JSVAL_VOID;
6013 0 JS_ReportError(cx, "Unknown port property with id %d for part", idval);
6014 0 res = JS_FALSE;
6015 goto exit;
6016 }
6017
6018 547 exit:
6019
6020 547 GlobusWSDLDebugExit();
6021 547 return res;
6022 }
6023
6024 static
6025 JSBool
6026 serviceGetter(
6027 JSContext * cx,
6028 JSObject * obj,
6029 jsval jid,
6030 jsval * vp)
6031 880 {
6032 int idval;
6033 880 JSString * str = NULL;
6034 880 JSObject * portsObj = NULL;
6035 880 JSBool res = JS_TRUE;
6036 880 wsdlServicePtr service = NULL;
6037 GlobusFuncName(serviceGetter);
6038 880 GlobusWSDLDebugEnter();
6039
6040 880 service = (wsdlServicePtr) JS_GetPrivate(cx, obj);
6041 880 globus_assert(service);
6042
6043 880 if(!JSVAL_IS_INT(jid))
6044 {
6045 char * prop_name;
6046
6047 0 prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
6048 0 JS_ReportError(cx,
6049 "Invalid property access .%s on wsdl service element",
6050 prop_name);
6051 0 res = JS_FALSE;
6052 0 goto exit;
6053 }
6054
6055 880 idval = JSVAL_TO_INT(jid);
6056
6057 880 switch(idval)
6058 {
6059 case name:
6060
6061 32 if(!service->name)
6062 {
6063 0 *vp = JSVAL_VOID;
6064 0 break;
6065 }
6066
6067 32 str = JS_InternString(cx, (const char *) service->name);
6068 32 globus_assert(str);
6069
6070 32 *vp = STRING_TO_JSVAL(str);
6071 32 break;
6072
6073 case ports:
6074
6075 816 if(!service->ports)
6076 {
6077 0 *vp = JSVAL_VOID;
6078 0 break;
6079 }
6080
6081 816 portsObj = JS_NewObject(cx, &ports_class, NULL, obj);
6082 816 globus_assert(portsObj);
6083 816 JS_SetPrivate(cx, portsObj, (void *) service->ports);
6084 816 *vp = OBJECT_TO_JSVAL(portsObj);
6085 816 break;
6086
6087 case soap:
6088
6089 0 *vp = JSVAL_VOID;
6090 0 break;
6091
6092 case targetNamespace:
6093
6094 32 if(!service->schema || !service->schema->targetNamespace)
6095 {
6096 0 *vp = JSVAL_VOID;
6097 0 break;
6098 }
6099
6100 32 str = JS_InternString(cx, (const char *) service->schema->targetNamespace);
6101 32 globus_assert(str);
6102
6103 32 *vp = STRING_TO_JSVAL(str);
6104 32 break;
6105
6106 default:
6107
6108 0 *vp = JSVAL_VOID;
6109 0 JS_ReportError(cx, "Unknown service property with id %d for part", idval);
6110 0 res = JS_FALSE;
6111 goto exit;
6112 }
6113
6114 880 exit:
6115
6116 880 GlobusWSDLDebugExit();
6117 880 return res;
6118 }
6119
6120 static
6121 JSBool
6122 soapBindingGetter(
6123 JSContext * cx,
6124 JSObject * obj,
6125 jsval jid,
6126 jsval * vp)
6127 0 {
6128 0 JSString * str = NULL;
6129 int idval;
6130 0 JSBool res = JS_TRUE;
6131 0 soapBindingPtr binding = NULL;
6132 GlobusFuncName(soapBindingGetter);
6133 0 GlobusWSDLDebugEnter();
6134
6135 0 binding = (soapBindingPtr) JS_GetPrivate(cx, obj);
6136 0 globus_assert(binding);
6137
6138 0 if(!JSVAL_IS_INT(jid))
6139 {
6140 0 JS_ReportError(cx,
6141 "Invalid id type (expected int) "
6142 "for soap binding property");
6143 0 res = JS_FALSE;
6144 0 goto exit;
6145 }
6146
6147 0 idval = JSVAL_TO_INT(jid);
6148
6149 0 switch(idval)
6150 {
6151 case style:
6152
6153 0 *vp = INT_TO_JSVAL(binding->style);
6154 0 break;
6155
6156 case transport:
6157
6158 0 if(!binding->transport)
6159 {
6160 0 *vp = JSVAL_VOID;
6161 0 break;
6162 }
6163
6164 0 str = JS_InternString(cx, (const char *) binding->transport);
6165 0 globus_assert(str);
6166 0 *vp = STRING_TO_JSVAL(str);
6167 0 break;
6168
6169 default:
6170
6171 0 *vp = JSVAL_VOID;
6172 0 JS_ReportError(cx,
6173 "Unknown soap binding property "
6174 "with id %d for part", idval);
6175 0 res = JS_FALSE;
6176 goto exit;
6177 }
6178
6179 0 exit:
6180
6181 0 GlobusWSDLDebugExit();
6182 0 return res;
6183 }
6184
6185 static
6186 JSBool
6187 soapOperationGetter(
6188 JSContext * cx,
6189 JSObject * obj,
6190 jsval jid,
6191 jsval * vp)
6192 0 {
6193 0 JSString * str = NULL;
6194 int idval;
6195 0 JSBool res = JS_TRUE;
6196 0 soapOperationPtr operation = NULL;
6197 GlobusFuncName(soapOperationGetter);
6198 0 GlobusWSDLDebugEnter();
6199
6200 0 operation = (soapOperationPtr) JS_GetPrivate(cx, obj);
6201 0 globus_assert(operation);
6202
6203 0 if(!JSVAL_IS_INT(jid))
6204 {
6205 0 JS_ReportError(cx,
6206 "Invalid id type (expected int) "
6207 "for soap operation property");
6208 0 res = JS_FALSE;
6209 0 goto exit;
6210 }
6211
6212 0 idval = JSVAL_TO_INT(jid);
6213
6214 0 switch(idval)
6215 {
6216 case soapAction:
6217
6218 0 if(!operation->soapAction)
6219 {
6220 0 *vp = JSVAL_VOID;
6221 0 break;
6222 }
6223
6224 0 str = JS_InternString(cx, (const char *) operation->soapAction);
6225 0 globus_assert(str);
6226 0 *vp = STRING_TO_JSVAL(str);
6227 0 break;
6228
6229 case style:
6230
6231 0 *vp = INT_TO_JSVAL(operation->style);
6232 0 break;
6233
6234
6235 default:
6236
6237 0 *vp = JSVAL_VOID;
6238 0 JS_ReportError(cx,
6239 "Unknown soap operation property "
6240 "with id %d", idval);
6241 0 res = JS_FALSE;
6242 goto exit;
6243 }
6244
6245 0 exit:
6246
6247 0 GlobusWSDLDebugExit();
6248 0 return res;
6249 }
6250
6251 static
6252 JSBool
6253 soapHeaderGetter(
6254 JSContext * cx,
6255 JSObject * obj,
6256 jsval jid,
6257 jsval * vp)
6258 0 {
6259 0 JSString * str = NULL;
6260 int idval;
6261 0 JSBool res = JS_TRUE;
6262 0 soapHeaderPtr header = NULL;
6263 GlobusFuncName(soapHeaderGetter);
6264 0 GlobusWSDLDebugEnter();
6265
6266 0 header = (soapHeaderPtr) JS_GetPrivate(cx, obj);
6267 0 globus_assert(header);
6268
6269 0 if(!JSVAL_IS_INT(jid))
6270 {
6271 0 JS_ReportError(cx,
6272 "Invalid id type (expected int) "
6273 "for soap header property");
6274 0 res = JS_FALSE;
6275 0 goto exit;
6276 }
6277
6278 0 idval = JSVAL_TO_INT(jid);
6279
6280 0 switch(idval)
6281 {
6282 case message:
6283
6284 0 if(!header->message)
6285 {
6286 0 *vp = JSVAL_VOID;
6287 0 break;
6288 }
6289
6290 0 str = JS_InternString(cx, (const char *) header->message);
6291 0 globus_assert(str);
6292 0 *vp = STRING_TO_JSVAL(str);
6293 0 break;
6294
6295 case parts:
6296
6297 0 if(!header->parts)
6298 {
6299 0 *vp = JSVAL_VOID;
6300 0 break;
6301 }
6302
6303 0 str = JS_InternString(cx, (const char *) header->parts);
6304 0 globus_assert(str);
6305 0 *vp = STRING_TO_JSVAL(str);
6306 0 break;
6307
6308 case use:
6309
6310 0 *vp = INT_TO_JSVAL(header->use);
6311 0 break;
6312
6313 case encodingStyle:
6314
6315 0 if(!header->encodingStyle)
6316 {
6317 0 *vp = JSVAL_VOID;
6318 0 break;
6319 }
6320
6321 0 str = JS_InternString(cx, (const char *) header->encodingStyle);
6322 0 globus_assert(str);
6323 0 *vp = STRING_TO_JSVAL(str);
6324 0 break;
6325
6326 case Namespace:
6327
6328 0 if(!header->Namespace)
6329 {
6330 0 *vp = JSVAL_VOID;
6331 }
6332
6333 0 str = JS_InternString(cx, (const char *) header->Namespace);
6334 0 globus_assert(str);
6335 0 *vp = STRING_TO_JSVAL(str);
6336 0 break;
6337
6338 default:
6339
6340 0 *vp = JSVAL_VOID;
6341 0 JS_ReportError(cx,
6342 "Unknown soap header property "
6343 "with id %d", idval);
6344 0 res = JS_FALSE;
6345 goto exit;
6346 }
6347
6348 0 exit:
6349
6350 0 GlobusWSDLDebugExit();
6351 0 return res;
6352 }
6353
6354 static
6355 JSBool
6356 soapBodyGetter(
6357 JSContext * cx,
6358 JSObject * obj,
6359 jsval jid,
6360 jsval * vp)
6361 0 {
6362 0 JSString * str = NULL;
6363 int idval;
6364 0 JSBool res = JS_TRUE;
6365 0 soapBodyPtr body = NULL;
6366 GlobusFuncName(soapBodyGetter);
6367 0 GlobusWSDLDebugEnter();
6368
6369 0 body = (soapBodyPtr) JS_GetPrivate(cx, obj);
6370 0 globus_assert(body);
6371
6372 0 if(!JSVAL_IS_INT(jid))
6373 {
6374 0 JS_ReportError(cx,
6375 "Invalid id type (expected int) "
6376 "for soap body property");
6377 0 res = JS_FALSE;
6378 0 goto exit;
6379 }
6380
6381 0 idval = JSVAL_TO_INT(jid);
6382
6383 0 switch(idval)
6384 {
6385 case parts:
6386
6387 0 if(!body->parts)
6388 {
6389 0 *vp = JSVAL_VOID;
6390 0 break;
6391 }
6392
6393 0 str = JS_InternString(cx, (const char *) body->parts);
6394 0 globus_assert(str);
6395 0 *vp = STRING_TO_JSVAL(str);
6396 0 break;
6397
6398 case use:
6399
6400 0 *vp = INT_TO_JSVAL(body->use);
6401 0 break;
6402
6403 case encodingStyle:
6404
6405 0 if(!body->encodingStyle)
6406 {
6407 0 *vp = JSVAL_VOID;
6408 0 break;
6409 }
6410
6411 0 str = JS_InternString(cx, (const char *) body->encodingStyle);
6412 0 globus_assert(str);
6413 0 *vp = STRING_TO_JSVAL(str);
6414 0 break;
6415
6416 case Namespace:
6417
6418 0 if(!body->Namespace)
6419 {
6420 0 *vp = JSVAL_VOID;
6421 }
6422
6423 0 str = JS_InternString(cx, (const char *) body->Namespace);
6424 0 globus_assert(str);
6425 0 *vp = STRING_TO_JSVAL(str);
6426 0 break;
6427
6428 default:
6429
6430 0 *vp = JSVAL_VOID;
6431 0 JS_ReportError(cx,
6432 "Unknown soap body property "
6433 "with id %d", idval);
6434 0 res = JS_FALSE;
6435 goto exit;
6436 }
6437
6438 0 exit:
6439
6440 0 GlobusWSDLDebugExit();
6441 0 return res;
6442 }
6443
6444 static
6445 JSBool
6446 soapFaultGetter(
6447 JSContext * cx,
6448 JSObject * obj,
6449 jsval jid,
6450 jsval * vp)
6451 0 {
6452 0 JSString * str = NULL;
6453 int idval;
6454 0 JSBool res = JS_TRUE;
6455 0 soapFaultPtr fault = NULL;
6456 GlobusFuncName(soapFaultGetter);
6457 0 GlobusWSDLDebugEnter();
6458
6459 0 fault = (soapFaultPtr) JS_GetPrivate(cx, obj);
6460 0 globus_assert(fault);
6461
6462 0 if(!JSVAL_IS_INT(jid))
6463 {
6464 0 JS_ReportError(cx,
6465 "Invalid id type (expected int) "
6466 "for soap fault property");
6467 0 res = JS_FALSE;
6468 0 goto exit;
6469 }
6470
6471 0 idval = JSVAL_TO_INT(jid);
6472
6473 0 switch(idval)
6474 {
6475 case use:
6476
6477 0 *vp = INT_TO_JSVAL(fault->use);
6478 0 break;
6479
6480 case encodingStyle:
6481
6482 0 if(!fault->encodingStyle)
6483 {
6484 0 *vp = JSVAL_VOID;
6485 0 break;
6486 }
6487
6488 0 str = JS_InternString(cx, (const char *) fault->encodingStyle);
6489 0 globus_assert(str);
6490 0 *vp = STRING_TO_JSVAL(str);
6491 0 break;
6492
6493 case Namespace:
6494
6495 0 if(!fault->Namespace)
6496 {
6497 0 *vp = JSVAL_VOID;
6498 }
6499
6500 0 str = JS_InternString(cx, (const char *) fault->Namespace);
6501 0 globus_assert(str);
6502 0 *vp = STRING_TO_JSVAL(str);
6503 0 break;
6504
6505 default:
6506
6507 0 *vp = JSVAL_VOID;
6508 0 JS_ReportError(cx,
6509 "Unknown soap fault property "
6510 "with id %d", idval);
6511 0 res = JS_FALSE;
6512 goto exit;
6513 }
6514
6515 0 exit:
6516
6517 0 GlobusWSDLDebugExit();
6518 0 return res;
6519 }
6520
6521 static
6522 JSBool
6523 soapAddressGetter(
6524 JSContext * cx,
6525 JSObject * obj,
6526 jsval jid,
6527 jsval * vp)
6528 95 {
6529 95 JSString * str = NULL;
6530 int idval;
6531 95 JSBool res = JS_TRUE;
6532 95 soapAddressPtr address = NULL;
6533 GlobusFuncName(soapAddressGetter);
6534 95 GlobusWSDLDebugEnter();
6535
6536 95 address = (soapAddressPtr) JS_GetPrivate(cx, obj);
6537 95 globus_assert(address);
6538
6539 95 if(!JSVAL_IS_INT(jid))
6540 {
6541 0 JS_ReportError(cx,
6542 "Invalid id type (expected int) "
6543 "for soap address property");
6544 0 res = JS_FALSE;
6545 0 goto exit;
6546 }
6547
6548 95 idval = JSVAL_TO_INT(jid);
6549
6550 95 switch(idval)
6551 {
6552 case location:
6553
6554 95 if(!address->location)
6555 {
6556 0 *vp = JSVAL_VOID;
6557 0 break;
6558 }
6559
6560 95 str = JS_InternString(cx, (const char *) address->location);
6561 95 globus_assert(str);
6562 95 *vp = STRING_TO_JSVAL(str);
6563 95 break;
6564
6565 default:
6566
6567 0 *vp = JSVAL_VOID;
6568 0 JS_ReportError(cx,
6569 "Unknown soap address property "
6570 "with id %d", idval);
6571 0 res = JS_FALSE;
6572 goto exit;
6573 }
6574
6575 95 exit:
6576
6577 95 GlobusWSDLDebugExit();
6578 95 return res;
6579 }
6580
6581 static
6582 JSBool
6583 soapBindingParamGetter(
6584 JSContext * cx,
6585 JSObject * obj,
6586 jsval jid,
6587 jsval * vp)
6588 0 {
6589 0 JSObject * newObj = NULL;
6590 int idval;
6591 0 JSBool res = JS_TRUE;
6592 0 soapBindingParamPtr param = NULL;
6593 GlobusFuncName(soapBindingParamGetter);
6594 0 GlobusWSDLDebugEnter();
6595
6596 0 param = (soapBindingParamPtr) JS_GetPrivate(cx, obj);
6597 0 globus_assert(param);
6598
6599 0 if(!JSVAL_IS_INT(jid))
6600 {
6601 0 JS_ReportError(cx,
6602 "Invalid id type (expected int) "
6603 "for soap binding param property");
6604 0 res = JS_FALSE;
6605 0 goto exit;
6606 }
6607
6608 0 idval = JSVAL_TO_INT(jid);
6609
6610 0 switch(idval)
6611 {
6612 case header:
6613
6614 0 if(!param->header)
6615 {
6616 0 *vp = JSVAL_VOID;
6617 0 break;
6618 }
6619
6620 0 newObj = JS_NewObject(cx, &soapHeader_class, soapHeaderClass, obj);
6621 0 globus_assert(newObj);
6622 0 JS_SetPrivate(cx, newObj, (void *)param->header);
6623 0 JS_DefineProperties(cx, newObj, soapHeader_properties);
6624 0 *vp = OBJECT_TO_JSVAL(newObj);
6625 0 break;
6626
6627 case body:
6628
6629 0 if(!param->body)
6630 {
6631 0 *vp = JSVAL_VOID;
6632 0 break;
6633 }
6634
6635 0 newObj = JS_NewObject(cx, &soapBody_class, soapBodyClass, obj);
6636 0 globus_assert(newObj);
6637 0 JS_SetPrivate(cx, newObj, (void *)param->body);
6638 0 JS_DefineProperties(cx, newObj, soapBody_properties);
6639 0 *vp = OBJECT_TO_JSVAL(newObj);
6640 0 break;
6641
6642 case fault:
6643
6644 0 if(!param->fault)
6645 {
6646 0 *vp = JSVAL_VOID;
6647 0 break;
6648 }
6649
6650 0 newObj = JS_NewObject(cx, &soapFault_class, soapFaultClass, obj);
6651 0 globus_assert(newObj);
6652 0 JS_SetPrivate(cx, newObj, (void *)param->fault);
6653 0 JS_DefineProperties(cx, newObj, soapFault_properties);
6654 0 *vp = OBJECT_TO_JSVAL(newObj);
6655 0 break;
6656
6657 default:
6658
6659 0 *vp = JSVAL_VOID;
6660 0 JS_ReportError(cx,
6661 "Unknown soap binding property "
6662 "with id %d for part", idval);
6663 0 res = JS_FALSE;
6664 goto exit;
6665 }
6666
6667 0 exit:
6668
6669 0 GlobusWSDLDebugExit();
6670 0 return res;
6671 }
6672
6673 static
6674 void
6675 globus_i_wsdl_parser_import_scanner(
6676 void * payload,
6677 void * data,
6678 xmlChar * name)
6679 1708 {
6680 xmlSchemaImportPtr import;
6681 xmlSchemaPtr schema;
6682 ScannerData * dt;
6683 GlobusFuncName(globus_i_wsdl_parser_import_scanner);
6684 1708 GlobusWSDLDebugEnter();
6685
6686 1708 dt = (ScannerData *) data;
6687 1708 import = (xmlSchemaImportPtr) payload;
6688
6689 1708 if(dt->result != GLOBUS_SUCCESS)
6690 {
6691 0 goto exit;
6692 }
6693
6694 1708 schema = import->schema;
6695
6696 1708 if(schema)
6697 {
6698 1708 dt->xsdSchema = schema;
6699 1708 xmlHashScan(schema->schemasImports,
6700 globus_i_wsdl_parser_import_scanner, data);
6701 1708 if(dt->result != GLOBUS_SUCCESS)
6702 {
6703 0 dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6704 0 goto exit;
6705 }
6706
6707 1708 dt->xsdSchema = schema;
6708 1708 xmlHashScan(schema->typeDecl, globus_i_wsdl_parser_type_scanner, data);
6709 1708 if(dt->result != GLOBUS_SUCCESS)
6710 {
6711 0 dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6712 0 goto exit;
6713 }
6714
6715 1708 xmlHashScan(schema->groupDecl, globus_i_wsdl_parser_type_scanner, data);
6716 1708 if(dt->result != GLOBUS_SUCCESS)
6717 {
6718 0 dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6719 0 goto exit;
6720 }
6721
6722 1708 xmlHashScan(schema->elemDecl,
6723 globus_i_wsdl_parser_element_scanner,
6724 data);
6725 1708 if(dt->result != GLOBUS_SUCCESS)
6726 {
6727 0 dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6728 0 goto exit;
6729 }
6730
6731 1708 xmlHashScan(schema->attrDecl,
6732 globus_i_wsdl_parser_attribute_scanner,
6733 data);
6734 1708 if(dt->result != GLOBUS_SUCCESS)
6735 {
6736 0 dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6737 0 goto exit;
6738 }
6739 }
6740
6741 1708 exit:
6742
6743 1708 GlobusWSDLDebugExit();
6744 1708 }
6745
6746 static
6747 void
6748 globus_i_wsdl_parser_type_scanner(
6749 void * payload,
6750 void * data,
6751 xmlChar * name)
6752 35228 {
6753 xmlSchemaTypePtr xsdType;
6754 wsdlSchemaPtr schema;
6755 xmlSchemaPtr xsdSchema;
6756 JSContext * cx;
6757 jsval val;
6758 JSObject * typeObj;
6759 JSObject * types;
6760 JSObject * global;
6761 JSString * str;
6762 35228 globus_result_t result = GLOBUS_SUCCESS;
6763 GlobusFuncName(globus_i_wsdl_parser_type_scanner);
6764 35228 GlobusWSDLDebugEnter();
6765
6766 35228 xsdType = (xmlSchemaTypePtr) payload;
6767 35228 schema = ((ScannerData *)data)->schema;
6768 35228 xsdSchema = ((ScannerData *)data)->xsdSchema;
6769 35228 cx = ((ScannerData *)data)->context;
6770 35228 global = ((ScannerData *)data)->global;
6771 35228 types = ((ScannerData *)data)->types;
6772 35228 result = ((ScannerData *)data)->result;
6773
6774 35228 if(result != GLOBUS_SUCCESS)
6775 {
6776 0 goto exit;
6777 }
6778
6779 35228 if(xsdType->targetNamespace)
6780 {
6781 35213 str = globus_l_wsdl_jscript_qname_string(
6782 cx, xsdType->targetNamespace, xsdType->name);
6783 }
6784 15 else if(xsdSchema->targetNamespace)
6785 {
6786 15 xsdType->targetNamespace = xsdSchema->targetNamespace;
6787 15 str = globus_l_wsdl_jscript_qname_string(
6788 cx, xsdSchema->targetNamespace, xsdType->name);
6789 }
6790 0 else if(schema->targetNamespace)
6791 {
6792 0 xsdType->targetNamespace = schema->targetNamespace;
6793 0 str = globus_l_wsdl_jscript_qname_string(
6794 cx, schema->targetNamespace, xsdType->name);
6795 }
6796 else
6797 {
6798 0 JS_ReportError(cx,
6799 "Can't find namespace for type: %s",
6800 xsdType->name);
6801 0 result = GlobusWSDLErrorScanningTypes(
6802 GLOBUS_NULL, xsdType->name);
6803 0 goto exit;
6804 }
6805
6806 35228 typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, types);
6807 35228 globus_assert(typeObj);
6808 35228 JS_SetPrivate(cx, typeObj, (void *)xsdType);
6809 35228 JS_DefineProperties(cx, typeObj, xsdType_properties);
6810
6811 35228 val = OBJECT_TO_JSVAL(typeObj);
6812
6813 35228 if(!JS_DefineProperty(
6814 cx, types, (const char *)JS_GetStringBytes(str),
6815 val, NULL, NULL,
6816 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6817 {
6818 0 JS_ReportError(cx, "Failed to define type from parsed WSDL");
6819 0 result = GlobusWSDLErrorScanningTypes(
6820 GLOBUS_NULL, xsdType->name);
6821 0 goto exit;
6822 }
6823
6824 35228 exit:
6825
6826 35228 GlobusWSDLDebugExit();
6827 35228 ((ScannerData *)data)->result = result;
6828 35228 }
6829
6830 static
6831 void
6832 globus_i_wsdl_parser_element_scanner(
6833 void * payload,
6834 void * data,
6835 xmlChar * name)
6836 20140 {
6837 xmlSchemaElementPtr element;
6838 wsdlSchemaPtr schema;
6839 xmlSchemaPtr xsdSchema;
6840 JSContext * cx;
6841 jsval val;
6842 JSObject * elements;
6843 JSObject * local_elements;
6844 JSObject * global;
6845 JSObject * elemObj;
6846 JSString * str;
6847 20140 globus_result_t result = GLOBUS_SUCCESS;
6848 GlobusFuncName(globus_i_wsdl_parser_element_scanner);
6849 20140 GlobusWSDLDebugEnter();
6850
6851 20140 element = (xmlSchemaElementPtr) payload;
6852 20140 schema = ((ScannerData *)data)->schema;
6853 20140 xsdSchema = ((ScannerData *)data)->xsdSchema;
6854 20140 cx = ((ScannerData *)data)->context;
6855 20140 global = ((ScannerData *)data)->global;
6856 20140 elements = ((ScannerData *)data)->elements;
6857 20140 local_elements = ((ScannerData *)data)->local_elements;
6858 20140 result = ((ScannerData *)data)->result;
6859
6860 20140 if(result != GLOBUS_SUCCESS)
6861 {
6862 0 goto exit;
6863 }
6864
6865
6866 20140 if(!element->targetNamespace)
6867 {
6868 2657 if((element->flags & XML_SCHEMAS_ELEM_GLOBAL) ||
6869 (xsdSchema->flags & XML_SCHEMAS_QUALIF_ELEM))
6870 {
6871 2657 element->targetNamespace = xsdSchema->targetNamespace;
6872 }
6873 }
6874
6875 20140 str = globus_l_wsdl_jscript_qname_string(
6876 cx, element->targetNamespace, element->name);
6877
6878 20140 if(element->flags & XML_SCHEMAS_ELEM_GLOBAL)
6879 {
6880 12204 elemObj = JS_NewObject(cx, &xsdElement_class,
6881 xsdElementClass, elements);
6882 12204 globus_assert(elemObj);
6883 12204 JS_SetPrivate(cx, elemObj, (void *)element);
6884 12204 JS_DefineProperties(cx, elemObj, xsdElement_properties);
6885
6886 12204 val = OBJECT_TO_JSVAL(elemObj);
6887
6888 12204 if(!JS_DefineProperty(
6889 cx, elements, (const char *) JS_GetStringBytes(str),
6890 val, NULL, NULL,
6891 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6892 {
6893 0 JS_ReportError(cx, "Failed to define element from parsed WSDL");
6894 0 result = GlobusWSDLErrorScanningElements(
6895 GLOBUS_NULL, element->name);
6896 0 goto exit;
6897 }
6898 }
6899 else
6900 {
6901 7936 elemObj = JS_NewObject(cx, &xsdElement_class,
6902 xsdElementClass, local_elements);
6903 7936 globus_assert(elemObj);
6904 7936 JS_SetPrivate(cx, elemObj, (void *)element);
6905 7936 JS_DefineProperties(cx, elemObj, xsdElement_properties);
6906
6907 7936 val = OBJECT_TO_JSVAL(elemObj);
6908
6909 7936 if(!JS_DefineProperty(
6910 cx, local_elements, (const char *) JS_GetStringBytes(str),
6911 val, NULL, NULL,
6912 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6913 {
6914 0 JS_ReportError(cx, "Failed to define element from parsed WSDL");
6915 0 result = GlobusWSDLErrorScanningElements(
6916 GLOBUS_NULL, element->name);
6917 0 goto exit;
6918 }
6919 }
6920
6921 20140 exit:
6922
6923 20140 GlobusWSDLDebugExit();
6924 20140 ((ScannerData *)data)->result = result;
6925 20140 }
6926
6927 static
6928 void
6929 globus_i_wsdl_parser_attribute_scanner(
6930 void * payload,
6931 void * data,
6932 xmlChar * name)
6933 4866 {
6934 xmlSchemaAttributePtr attribute;
6935 wsdlSchemaPtr schema;
6936 xmlSchemaPtr xsdSchema;
6937 JSContext * cx;
6938 jsval val;
6939 JSObject * attributes;
6940 JSObject * local_attributes;
6941 JSObject * global;
6942 JSObject * attrObj;
6943 JSString * str;
6944 4866 globus_result_t result = GLOBUS_SUCCESS;
6945 GlobusFuncName(globus_i_wsdl_parser_attribute_scanner);
6946 4866 GlobusWSDLDebugEnter();
6947
6948 4866 attribute = (xmlSchemaAttributePtr) payload;
6949 4866 schema = ((ScannerData *)data)->schema;
6950 4866 xsdSchema = ((ScannerData *)data)->xsdSchema;
6951 4866 cx = ((ScannerData *)data)->context;
6952 4866 global = ((ScannerData *)data)->global;
6953 4866 attributes = ((ScannerData *)data)->attributes;
6954 4866 local_attributes = ((ScannerData *)data)->local_attributes;
6955 4866 result = ((ScannerData *)data)->result;
6956
6957 4866 if(result != GLOBUS_SUCCESS)
6958 {
6959 0 goto exit;
6960 }
6961
6962 4866 if(!attribute->targetNamespace)
6963 {
6964 3114 if((attribute->flags & XML_SCHEMAS_ATTR_GLOBAL) ||
6965 (xsdSchema->flags & XML_SCHEMAS_QUALIF_ATTR))
6966 {
6967 0 attribute->targetNamespace = xsdSchema->targetNamespace;
6968 }
6969 }
6970
6971 4866 str = globus_l_wsdl_jscript_qname_string(
6972 cx, attribute->targetNamespace, attribute->name);
6973
6974 4866 if(attribute->flags & XML_SCHEMAS_ATTR_GLOBAL)
6975 {
6976 1752 attrObj = JS_NewObject(
6977 cx, &xsdAttr_class, xsdAttrClass, attributes);
6978 1752 globus_assert(attrObj);
6979 1752 JS_SetPrivate(cx, attrObj, (void *)attribute);
6980 1752 JS_DefineProperties(cx, attrObj, xsdAttr_properties);
6981
6982 1752 val = OBJECT_TO_JSVAL(attrObj);
6983
6984 1752 JS_DefineProperty(
6985 cx, attributes, (const char *) JS_GetStringBytes(str),
6986 val, NULL, NULL,
6987 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
6988 }
6989 else
6990 {
6991 3114 attrObj = JS_NewObject(
6992 cx, &xsdAttr_class, xsdAttrClass, local_attributes);
6993 3114 globus_assert(attrObj);
6994 3114 JS_SetPrivate(cx, attrObj, (void *)attribute);
6995 3114 JS_DefineProperties(cx, attrObj, xsdAttr_properties);
6996
6997 3114 val = OBJECT_TO_JSVAL(attrObj);
6998
6999 3114 JS_DefineProperty(
7000 cx, local_attributes, (const char *) JS_GetStringBytes(str),
7001 val, NULL, NULL,
7002 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
7003 }
7004
7005 4866 exit:
7006
7007 4866 GlobusWSDLDebugExit();
7008 4866 ((ScannerData *)data)->result = result;
7009 4866 }
7010
7011 static
7012 void
7013 globus_i_wsdl_parser_message_scanner(
7014 void * payload,
7015 void * data,
7016 xmlChar * name)
7017 2189 {
7018 wsdlMessagePtr message;
7019 JSContext * cx;
7020 jsval val;
7021 JSObject * messages;
7022 JSObject * messageObj;
7023 JSObject * global;
7024 2189 globus_result_t result = GLOBUS_SUCCESS;
7025 GlobusFuncName(globus_i_wsdl_parser_message_scanner);
7026 2189 GlobusWSDLDebugEnter();
7027
7028 2189 message = (wsdlMessagePtr) payload;
7029 2189 cx = ((ScannerData *)data)->context;
7030 2189 global = ((ScannerData *)data)->global;
7031 2189 messages = ((ScannerData *)data)->messages;
7032 2189 result = ((ScannerData *)data)->result;
7033
7034 2189 if(result != GLOBUS_SUCCESS)
7035 {
7036 0 goto exit;
7037 }
7038
7039 2189 messageObj = JS_NewObject(cx, &message_class, messageClass, messages);
7040 2189 globus_assert(messageObj);
7041 2189 JS_SetPrivate(cx, messageObj, (void *)message);
7042 2189 JS_DefineProperties(cx, messageObj, message_properties);
7043
7044 2189 val = OBJECT_TO_JSVAL(messageObj);
7045
7046 2189 if(!JS_DefineProperty(cx, messages, (const char *)name, val, NULL, NULL,
7047 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
7048 {
7049 0 JS_ReportError(cx, "Failed to define message from parsed WSDL");
7050 0 result = GlobusWSDLErrorScanningMessages(GLOBUS_NULL, message->name);
7051 0 goto exit;
7052 }
7053
7054
7055 2189 exit:
7056
7057 2189 GlobusWSDLDebugExit();
7058 2189 ((ScannerData *)data)->result = result;
7059 2189 }
7060
7061 static
7062 void
7063 globus_i_wsdl_parser_portType_scanner(
7064 void * payload,
7065 void * data,
7066 xmlChar * name)
7067 540 {
7068 wsdlPortTypePtr portType;
7069 JSContext * cx;
7070 jsval val;
7071 JSObject * portTypes;
7072 JSObject * global;
7073 JSObject * portTypeObj;
7074 540 globus_result_t result = GLOBUS_SUCCESS;
7075 GlobusFuncName(globus_i_wsdl_parser_portType_scanner);
7076 540 GlobusWSDLDebugEnter();
7077
7078 540 portType = (wsdlPortTypePtr) payload;
7079 540 cx = ((ScannerData *)data)->context;
7080 540 global = ((ScannerData *)data)->global;
7081 540 portTypes = ((ScannerData *)data)->portTypes;
7082 540 result = ((ScannerData *)data)->result;
7083
7084 540 if(result != GLOBUS_SUCCESS)
7085 {
7086 0 goto exit;
7087 }
7088
7089 540 portTypeObj = JS_NewObject(cx, &portType_class, portTypeClass, portTypes);
7090 540 globus_assert(portTypeObj);
7091 540 JS_SetPrivate(cx, portTypeObj, (void *)portType);
7092 540 JS_DefineProperties(cx, portTypeObj, portType_properties);
7093
7094 540 val = OBJECT_TO_JSVAL(portTypeObj);
7095
7096 540 if(!JS_DefineProperty(cx, portTypes, (const char *)name, val, NULL, NULL,
7097 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
7098 {
7099 0 JS_ReportError(cx, "Failed to define portType from parsed WSDL");
7100 0 result = GlobusWSDLErrorScanningPortTypes(GLOBUS_NULL, portType->name);
7101 0 goto exit;
7102 }
7103
7104
7105 540 exit:
7106
7107 540 GlobusWSDLDebugExit();
7108 540 ((ScannerData *)data)->result = result;
7109 540 }
7110
7111 static
7112 void
7113 globus_i_wsdl_parser_binding_scanner(
7114 void * payload,
7115 void * data,
7116 xmlChar * name)
7117 65 {
7118 wsdlBindingPtr binding;
7119 JSContext * cx;
7120 jsval val;
7121 JSObject * bindings;
7122 JSObject * global;
7123 JSObject * bindingObj;
7124 65 globus_result_t result = GLOBUS_SUCCESS;
7125 GlobusFuncName(globus_i_wsdl_parser_binding_scanner);
7126 65 GlobusWSDLDebugEnter();
7127
7128 65 binding = (wsdlBindingPtr) payload;
7129 65 cx = ((ScannerData *)data)->context;
7130 65 global = ((ScannerData *)data)->global;
7131 65 bindings = ((ScannerData *)data)->bindings;
7132 65 result = ((ScannerData *)data)->result;
7133
7134 65 if(result != GLOBUS_SUCCESS)
7135 {
7136 0 goto exit;
7137 }
7138
7139 65 bindingObj = JS_NewObject(cx, &binding_class, bindingClass, bindings);
7140 65 globus_assert(bindingObj);
7141 65 JS_SetPrivate(cx, bindingObj, (void *)binding);
7142
7143 65 val = OBJECT_TO_JSVAL(bindingObj);
7144
7145 65 if(!JS_DefineProperty(cx, bindings, (const char *)name, val, NULL, NULL,
7146 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
7147 {
7148 0 JS_ReportError(cx, "Failed to define binding from parsed WSDL");
7149 0 result = GlobusWSDLErrorScanningBindings(GLOBUS_NULL, binding->name);
7150 0 goto exit;
7151 }
7152
7153
7154 65 exit:
7155
7156 65 GlobusWSDLDebugExit();
7157 65 ((ScannerData *)data)->result = result;
7158 65 }
7159
7160 static
7161 void
7162 globus_i_wsdl_parser_service_scanner(
7163 void * payload,
7164 void * data,
7165 xmlChar * name)
7166 20 {
7167 20 wsdlServicePtr service = NULL;
7168 20 JSContext * cx = NULL;
7169 jsval val;
7170 20 JSObject * services = NULL;
7171 20 JSObject * global = NULL;
7172 20 JSObject * serviceObj = NULL;
7173 20 globus_result_t result = GLOBUS_SUCCESS;
7174 GlobusFuncName(globus_i_wsdl_parser_service_scanner);
7175 20 GlobusWSDLDebugEnter();
7176
7177 20 service = (wsdlServicePtr) payload;
7178 20 cx = ((ScannerData *)data)->context;
7179 20 global = ((ScannerData *)data)->global;
7180 20 services = ((ScannerData *)data)->services;
7181 20 result = ((ScannerData *)data)->result;
7182
7183 20 if(result != GLOBUS_SUCCESS)
7184 {
7185 0 goto exit;
7186 }
7187
7188 20 serviceObj = JS_NewObject(cx, &service_class, serviceClass, services);
7189 20 globus_assert(serviceObj);
7190 20 JS_SetPrivate(cx, serviceObj, (void *)service);
7191 20 JS_DefineProperties(cx, serviceObj, service_properties);
7192
7193 20 val = OBJECT_TO_JSVAL(serviceObj);
7194
7195 20 if(!JS_DefineProperty(cx, services, (const char *)name, val, NULL, NULL,
7196 JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
7197 {
7198 0 JS_ReportError(cx, "Failed to define service from parsed WSDL");
7199 0 result = GlobusWSDLErrorScanningServices(GLOBUS_NULL, service->name);
7200 0 goto exit;
7201 }
7202
7203 20 exit:
7204
7205 20 GlobusWSDLDebugExit();
7206 20 ((ScannerData *)data)->result = result;
7207 20 }
7208
7209 static
7210 void
7211 globus_i_wsdl_parser_wsdl_imports_scanner(
7212 void * payload,
7213 void * data,
7214 xmlChar * name)
7215 230 {
7216 230 wsdlImportPtr import = NULL;
7217 230 JSContext * cx = NULL;
7218 230 JSObject * global = NULL;
7219 230 globus_result_t result = GLOBUS_SUCCESS;
7220 GlobusFuncName(globus_i_wsdl_parser_wsdl_imports_scanner);
7221 230 GlobusWSDLDebugEnter();
7222
7223 230 import = (wsdlImportPtr) payload;
7224 230 cx = ((ScannerData *)data)->context;
7225 230 global = ((ScannerData *)data)->global;
7226 230 result = ((ScannerData *)data)->result;
7227
7228 230 if(result != GLOBUS_SUCCESS)
7229 {
7230 0 goto exit;
7231 }
7232
7233 230 ((ScannerData *)data)->schema = import->schema;
7234 230 result = globus_i_wsdl_js_load_imported_schema(cx, import->schema);
7235 230 if(result != GLOBUS_SUCCESS)
7236 {
7237 0 JS_ReportError(cx, "Failed to load WSDL schema");
7238 0 result = GlobusWSDLErrorScanningImports(
7239 GLOBUS_NULL, import->wsdlLocation);
7240 0 goto exit;
7241 }
7242
7243 230 exit:
7244
7245 230 GlobusWSDLDebugExit();
7246 230 ((ScannerData *)data)->result = result;
7247 230 }
7248
7249 static void
7250 TemplateFree(
7251 void * template)
7252 518 {
7253 518 Template * tmpl = (Template *) template;
7254 518 if(tmpl)
7255 {
7256 518 if(tmpl->filename)
7257 {
7258 518 free(tmpl->filename);
7259 }
7260
7261 518 if(tmpl->buffer)
7262 {
7263 518 free(tmpl->buffer);
7264 }
7265
7266 518 free(tmpl);
7267 }
7268 518 }
7269
7270
7271 #define DEFINE_LIST_RESOLVER(PREFIX, PRIV) \
7272 static \
7273 JSBool \
7274 PREFIX ## Resolve(JSContext *cx, JSObject *obj, jsval id) \
7275 { \
7276 int i; \
7277 int idval; \
7278 PRIV type; \
7279 JSBool res; \
7280 \
7281 type = (PRIV) JS_GetPrivate(cx, obj); \
7282 \
7283 if (JSVAL_IS_INT(id)) \
7284 { \
7285 idval = JSVAL_TO_INT(id); \
7286 \
7287 for (i = 0; i < idval; i++) \
7288 { \
7289 if (type == NULL) \
7290 { \
7291 break; \
7292 } \
7293 type = type->next; \
7294 } \
7295 } \
7296 else if (JSVAL_IS_STRING(id)) \
7297 { \
7298 JSString * name; \
7299 i = 0; \
7300 \
7301 while (type) \
7302 { \
7303 name = JS_InternString(cx, type->name); \
7304 if(JS_CompareStrings(name, JSVAL_TO_STRING(id))) \
7305 { \
7306 break; \
7307 } \
7308 type = type->next; \
7309 i++; \
7310 } \
7311 } \
7312 else \
7313 { \
7314 type = NULL; \
7315 } \
7316 \
7317 if (type != NULL) \
7318 { \
7319 res = JS_DefineElement(cx, obj, i, NULL, NULL, NULL, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); \
7320 } \
7321 else \
7322 { \
7323 res = JS_FALSE; \
7324 } \
7325 return res; \
7326 }
7327
7328 #define DEFINE_LIST_RESOLVER_INT_ONLY(PREFIX, PRIV) \
7329 static \
7330 JSBool \
7331 PREFIX ## Resolve(JSContext *cx, JSObject *obj, jsval id) \
7332 { \
7333 int i; \
7334 int idval; \
7335 PRIV type; \
7336 JSBool res; \
7337 \
7338 type = (PRIV) JS_GetPrivate(cx, obj); \
7339 \
7340 if (JSVAL_IS_INT(id)) \
7341 { \
7342 idval = JSVAL_TO_INT(id); \
7343 \
7344 for (i = 0; i < idval; i++) \
7345 { \
7346 if (type == NULL) \
7347 { \
7348 break; \
7349 } \
7350 type = type->next; \
7351 } \
7352 } \
7353 else \
7354 { \
7355 type = NULL; \
7356 } \
7357 \
7358 if (type != NULL) \
7359 { \
7360 res = JS_DefineElement(cx, obj, i, NULL, NULL, NULL, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); \
7361 } \
7362 else \
7363 { \
7364 res = JS_FALSE; \
7365 } \
7366 return res; \
7367 }
7368
7369 86809 DEFINE_LIST_RESOLVER(xsdSubTypes, xmlSchemaTypePtr)
7370 0 DEFINE_LIST_RESOLVER(bindingOperationFaults, wsdlBindingOperationFaultPtr)
7371 2886 DEFINE_LIST_RESOLVER(bindingOperations, wsdlBindingOperationPtr)
7372 1960 DEFINE_LIST_RESOLVER(faults, wsdlFaultPtr)
7373 2306 DEFINE_LIST_RESOLVER(operations, wsdlOperationPtr)
7374 2090 DEFINE_LIST_RESOLVER(parts, wsdlPartPtr)
7375 999 DEFINE_LIST_RESOLVER(ports, wsdlPortPtr)
7376 3121 DEFINE_LIST_RESOLVER(xsdAttrs, xmlSchemaAttributePtr)
7377 771 DEFINE_LIST_RESOLVER_INT_ONLY(xsdFacets, xmlSchemaFacetPtr)