comparison GEMBASSY-1.0.3/gsoap/src/symbol2.c @ 2:8947fca5f715 draft default tip

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:21:44 -0400
parents 84a17b3fad1f
children
comparison
equal deleted inserted replaced
1:84a17b3fad1f 2:8947fca5f715
1 /*
2 symbol2.c
3
4 Symbol table handling, type analysis, and code generation.
5
6 --------------------------------------------------------------------------------
7 gSOAP XML Web services tools
8 Copyright (C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved.
9 This part of the software is released under one of the following licenses:
10 GPL or Genivia's license for commercial use.
11 --------------------------------------------------------------------------------
12 GPL license.
13
14 This program is free software; you can redistribute it and/or modify it under
15 the terms of the GNU General Public License as published by the Free Software
16 Foundation; either version 2 of the License, or (at your option) any later
17 version.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 PARTICULAR PURPOSE. See the GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
25 Place, Suite 330, Boston, MA 02111-1307 USA
26
27 Author contact information:
28 engelen@genivia.com / engelen@acm.org
29
30 This program is released under the GPL with the additional exemption that
31 compiling, linking, and/or using OpenSSL is allowed.
32 --------------------------------------------------------------------------------
33 A commercial use license is available from Genivia, Inc., contact@genivia.com
34 --------------------------------------------------------------------------------
35 */
36
37 #include "soapcpp2.h"
38
39 #ifdef HAVE_CONFIG_H
40 #include "soapcpp2_yacc.h"
41 #else
42 #include "soapcpp2_yacc.tab.h"
43 #endif
44
45 char *envURI = "http://schemas.xmlsoap.org/soap/envelope/";
46 char *encURI = "http://schemas.xmlsoap.org/soap/encoding/";
47 char *rpcURI = "http://www.w3.org/2003/05/soap-rpc";
48 char *xsiURI = "http://www.w3.org/2001/XMLSchema-instance";
49 char *xsdURI = "http://www.w3.org/2001/XMLSchema";
50 char *tmpURI = "http://tempuri.org";
51
52 static Symbol *symlist = (Symbol*) 0; /* pointer to linked list of symbols */
53 static Symbol *nslist = (Symbol*) 0; /* pointer to linked list of namespace prefix symbols */
54
55 static Tnode *Tptr[TYPES];
56
57 Service *services = NULL;
58
59 FILE *fout, *fhead, *fclient, *fserver, *fheader, *flib, *fmatlab, *fmheader;
60
61 int partnum = 0;
62
63 int typeNO = 1; /* unique no. assigned to all types */
64
65 static int is_anytype_flag = 0; /* anytype is used */
66 static int has_nsmap = 0;
67
68 int tagcmp(const char *s, const char *t);
69 int tagncmp(const char *s, const char *t, size_t n);
70
71 long minlen(Tnode *typ);
72 long maxlen(Tnode *typ);
73
74 int is_soap12(const char*);
75 int has_detail_string(void);
76 int has_Detail_string(void);
77
78 void needs_lang(Entry *e);
79
80 int is_mutable(Tnode *typ);
81 int is_header_or_fault(Tnode *typ);
82 int is_body(Tnode *typ);
83 int is_volatile(Tnode* typ);
84 int is_untyped(Tnode* typ);
85 int is_primclass(Tnode* typ);
86 int is_imported(Tnode* typ);
87 int is_template(Tnode* typ);
88 int is_mask(Tnode* typ);
89 int is_attachment(Tnode* typ);
90 int has_attachment(Tnode* typ);
91 int is_void(Tnode* typ);
92 int has_external(Tnode *typ);
93 int has_volatile(Tnode *typ);
94
95 int is_invisible(const char *name);
96 int is_invisible_empty(Tnode *p);
97
98 int is_eq_nons(const char *s, const char *t);
99 int is_eq(const char *s, const char *t);
100
101 int is_item(Entry *p);
102 int is_self(Entry *p);
103
104 const char *cstring(const char*);
105 const char *xstring(const char*);
106
107 /*
108 install - add new symbol
109 */
110 Symbol *
111 install(const char *name, Token token)
112 { Symbol *p;
113 p = (Symbol*)emalloc(sizeof(Symbol));
114 p->name = emalloc(strlen(name)+1);
115 strcpy(p->name, name);
116 p->token = token;
117 p->next = symlist;
118 symlist = p;
119 return p;
120 }
121
122 /*
123 lookup - search for an identifier's name. If found, return pointer to symbol table entry. Return pointer 0 if not found.
124 */
125 Symbol *
126 lookup(const char *name)
127 { Symbol *p;
128 for (p = symlist; p; p = p->next)
129 if (!strcmp(p->name, name))
130 return p;
131 return NULL;
132 }
133
134 /*
135 gensymidx - generate new symbol from base name and index
136 */
137 Symbol *
138 gensymidx(const char *base, int idx)
139 { char buf[1024];
140 Symbol *s;
141 sprintf(buf, "%s_%d", base, idx);
142 s = lookup(buf);
143 if (s)
144 return s;
145 return install(buf, ID);
146 }
147
148 /*
149 gensym - generate new symbol from base name
150 */
151 Symbol *
152 gensym(const char *base)
153 { static int num = 1;
154 return gensymidx(base, num++);
155 }
156
157 /*
158 mktable - make a new symbol table with a pointer to a previous table
159 */
160 Table *
161 mktable(Table *table)
162 { Table *p;
163 p = (Table*)emalloc(sizeof(Table));
164 p->sym = lookup("/*?*/");
165 p->list = (Entry*) 0;
166 if (table == (Table*) 0)
167 p->level = INTERNAL;
168 else p->level = table->level+1;
169 p->prev = table;
170 return p;
171 }
172
173 /*
174 mkmethod - make a new method by calling mktype
175 */
176 Tnode *
177 mkmethod(Tnode *ret, Table *args)
178 { FNinfo *fn = (FNinfo*)emalloc(sizeof(FNinfo));
179 fn->ret = ret;
180 fn->args = args;
181 return mktype(Tfun, fn, 0);
182 }
183
184 /*
185 freetable - free space by removing a table
186 */
187 void
188 freetable(Table *table)
189 { Entry *p, *q;
190 if (table == (Table*) 0)
191 return;
192 for (p = table->list; p != (Entry*) 0; p = q) {
193 q = p->next;
194 free(p);
195 }
196 free(table);
197 }
198
199 /*
200 unlinklast - unlink last entry added to table
201 */
202 Entry *
203 unlinklast(Table *table)
204 { Entry **p, *q;
205 if (table == (Table*)0)
206 return (Entry*)0;
207 for (p = &table->list; *p != (Entry*)0 && (*p)->next != (Entry*)0;
208 p = &(*p)->next);
209 q = *p;
210 *p = (Entry*)0;
211 return q;
212 }
213
214 /*
215 enter - enter a symbol in a table. Error if already in the table
216 */
217 Entry *
218 enter(Table *table, Symbol *sym)
219 { Entry *p, *q = NULL;
220 again:
221 for (p = table->list; p; q = p, p = p->next)
222 { if (p->sym == sym && p->info.typ->type != Tfun)
223 { char *s;
224 sprintf(errbuf, "Duplicate declaration of '%s' (already declared at line %d), changing conflicting identifier name to new name '%s_'. Note: this problem may be caused by importing invalid XML schemas", sym->name, p->lineno, sym->name);
225 semwarn(errbuf);
226 s = (char*)emalloc(strlen(sym->name) + 2);
227 strcpy(s, sym->name);
228 strcat(s, "_");
229 sym = lookup(s);
230 if (!sym)
231 sym = install(s, ID);
232 free(s);
233 goto again;
234 }
235 }
236 p = (Entry*)emalloc(sizeof(Entry));
237 p->sym = sym;
238 p->tag = NULL;
239 p->info.typ = NULL;
240 p->info.sto = Snone;
241 p->info.hasval = False;
242 p->info.minOccurs = 1;
243 p->info.maxOccurs = 1;
244 p->info.offset = 0;
245 p->level = table->level;
246 p->lineno = yylineno;
247 p->next = NULL;
248 if (!q)
249 table->list = p;
250 else
251 q->next = p;
252 return p;
253 }
254
255 /*
256 entry - return pointer to table entry of a symbol
257 */
258 Entry *
259 entry(Table *table, Symbol *sym)
260 { Table *t;
261 Entry *p;
262 for (t = table; t; t = t->prev)
263 for (p = t->list; p; p = p->next)
264 if (p->sym == sym)
265 return p;
266 return NULL;
267 }
268
269 /*
270 reenter - re-enter a symbol in a table.
271 */
272 Entry *
273 reenter(Table *table, Symbol *sym)
274 { Entry *p, *q = NULL;
275 for (p = table->list; p; q = p, p = p->next)
276 if (p->sym == sym)
277 break;
278 if (p && p->next)
279 { if (q)
280 q->next = p->next;
281 else
282 table->list = p->next;
283 for (q = p->next; q->next; q = q->next)
284 ;
285 q->next = p;
286 p->next = NULL;
287 }
288 return p;
289 }
290
291 /*
292 merge - append two tables if members are not duplicated
293 */
294 int
295 merge(Table *dest, Table *src)
296 { Entry *p, *q;
297 for (p = src->list; p; p = p->next)
298 { q = entry(dest, p->sym);
299 if (!q || q->info.typ != p->info.typ)
300 { q = enter(dest, p->sym);
301 q->info = p->info;
302 }
303 }
304 return 0;
305 }
306
307 Entry *
308 enumentry(Symbol *sym)
309 { Table *t;
310 Entry *p, *q;
311 for (t = enumtable; t; t = t->prev)
312 { for (p = t->list; p; p = p->next)
313 { q = entry((Table*)p->info.typ->ref, sym);
314 if (q)
315 return q;
316 }
317 }
318 return NULL;
319 }
320
321 char *get_mxClassID(Tnode*);
322 char *t_ident(Tnode*);
323 char *c_ident(Tnode*);
324 char *ident(char*);
325 char *soap_type(Tnode*);
326 char *c_storage(Storage);
327 char *c_init(Entry*);
328 char *c_type(Tnode*);
329 char *c_type_id(Tnode*, char*);
330 char *xsi_type_cond(Tnode*, int);
331 char *xsi_type(Tnode*);
332 char *xsi_type_cond_u(Tnode*, int);
333 char *xsi_type_u(Tnode*);
334 char *the_type(Tnode*);
335 char *wsdl_type(Tnode*, char*);
336 char *base_type(Tnode*, char*);
337 char *xml_tag(Tnode*);
338 char *ns_qualifiedElement(Tnode*);
339 char *ns_qualifiedAttribute(Tnode*);
340 char *ns_convert(char*);
341 char *field(Entry *p, char *ns);
342 char *field_overridden(Table *t, Entry *p, char *ns);
343 char *ns_add(Entry *p, char *ns);
344 char *ns_addx(char *tag, char *ns);
345 char *ns_add_overridden(Table *t, Entry *p, char *ns);
346 char *ns_remove(char*);
347 char *ns_remove1(char*);
348 char *ns_remove2(char*);
349 char *res_remove(char*);
350 char *ns_name(char*);
351 char *ns_cname(char*, char*);
352 char *ns_fname(char*);
353
354 int has_class(Tnode*);
355 int has_constructor(Tnode*);
356 int has_destructor(Tnode*);
357 int has_getter(Tnode*);
358 int has_setter(Tnode*);
359 int has_ns(Tnode*);
360 int has_ns_t(Tnode*);
361 int has_ns_eq(char*, char*);
362 char *strict_check(void);
363 char *ns_of(char*);
364 int eq_ns(char*, char*);
365 char *prefix_of(char*);
366 int has_offset(Tnode*);
367 int reflevel(Tnode *typ);
368 Tnode* reftype(Tnode *typ);
369 int is_response(Tnode*);
370 int is_XML(Tnode*);
371 int is_stdXML(Tnode *p);
372 Entry *get_response(Tnode*);
373 int is_primitive_or_string(Tnode*);
374 int is_primitive(Tnode*);
375 Entry *is_discriminant(Tnode*);
376 Entry *is_dynamic_array(Tnode*);
377 int is_transient(Tnode*);
378 int is_external(Tnode*);
379 int is_anyType(Tnode*);
380 int is_anyAttribute(Tnode*);
381 int is_binary(Tnode*);
382 int is_hexBinary(Tnode*);
383 int is_fixedstring(Tnode*);
384 int is_string(Tnode*);
385 int is_wstring(Tnode*);
386 int is_stdstring(Tnode*);
387 int is_stdwstring(Tnode*);
388 int is_stdstr(Tnode*);
389 int is_typedef(Tnode*);
390 int get_dimension(Tnode*);
391 char *has_soapref(Tnode*);
392 int is_document(const char*);
393 int is_literal(const char*);
394 int is_keyword(const char *);
395
396 int is_repetition(Entry*);
397 int is_choice(Entry*);
398 int is_sequence(Entry*);
399 int is_anytype(Entry*);
400
401 char *xsi_type_Tarray(Tnode*);
402 char *xsi_type_Darray(Tnode*);
403
404 void matlab_def_table(Table*);
405 void def_table(Table*);
406 void generate(Tnode *);
407 int no_of_var(Tnode*);
408 char *pointer_stuff(Tnode*);
409 void in_defs(Table*);
410 void in_defs2(Table*);
411 void in_defs3(Table*);
412 void out_defs(Table*);
413 void mark_defs(Table*);
414 void in_attach(Table*);
415 void out_attach(Table*);
416 void soap_serialize(Tnode*);
417 void soap_traverse(Tnode*);
418 void soap_default(Tnode*);
419 void soap_put(Tnode*);
420 void soap_out(Tnode*);
421 void soap_out_Darray(Tnode *);
422 void soap_get(Tnode*);
423 void soap_in(Tnode*);
424 void soap_in_Darray(Tnode *);
425 void soap_instantiate_class(Tnode *);
426 int get_Darraydims(Tnode *typ);
427 const char *nillable(Tnode *typ);
428
429 void soap_serve(Table*);
430 void generate_proto(Table*, Entry*);
431 /*
432 void generate_call(Table*, Entry*);
433 void generate_server(Table*, Entry*);
434 */
435 void generate_header(Table*);
436 void get_namespace_prefixes(void);
437 void generate_schema(Table*);
438 void gen_schema(FILE*,Table*,char*,char*,int,int,char*,char*,char*,char*);
439 void gen_type_documentation(FILE *fd, Entry *type, char *ns);
440 int gen_member_documentation(FILE *fd, Symbol *type, Entry *member, char *ns);
441 void gen_schema_elements_attributes(FILE *fd, Table *t, char *ns, char *ns1, char *encoding, char *style);
442 void gen_schema_elements(FILE *fd, Tnode *p, char *ns, char *ns1);
443 int gen_schema_element(FILE *fd, Tnode *p, Entry *q, char *ns, char *ns1);
444 void gen_schema_attributes(FILE *fd, Tnode *p, char *ns, char *ns1);
445 void gen_wsdl(FILE*,Table*,char*,char*,char*,char*,char*,char*,char*,char*);
446 void gen_nsmap(FILE*,Symbol*,char*);
447
448 void gen_proxy(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
449 void gen_object(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
450 void gen_proxy_header(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
451 void gen_proxy_code(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
452 void gen_object_header(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
453 void gen_object_code(FILE*,Table*,Symbol*,char*,char*,char*,char*,char*);
454 void gen_method(FILE *fd, Table *table, Entry *method, int server);
455 void gen_params(FILE *fd, Table *params, Entry *result, int flag);
456 void gen_args(FILE *fd, Table *params, Entry *result, int flag);
457 void gen_query_url(FILE *fd, Table *params);
458 void gen_query_form(FILE *fd, Table *params);
459 const char* gen_format(FILE *fd, Tnode *typ);
460 void gen_call_method(FILE *fd, Table *table, Entry *method, char *name);
461 void gen_serve_method(FILE *fd, Table *table, Entry *param, char *name);
462
463 void gen_data(char*,Table*,char*,char*,char*,char*,char*,char*);
464 FILE *gen_env(char*,char*,int,Table*,char*,char*,char*,char*,char*,char*,int);
465 void gen_xmlns(FILE*);
466 void gen_field(FILE*,int,Entry*,char*,char*,char*);
467 void gen_val(FILE*,int,Tnode*,char*,char*,char*);
468 void gen_atts(FILE*,int,Table*,char*);
469
470 /*
471 mktype - make a (new) type with a reference to additional information and the
472 width in bytes required to store objects of that type. A pointer to the
473 type is returned which can be compared to check if types are identical.
474 */
475 Tnode *
476 mktype(Type type, void *ref, int width)
477 { Tnode *p;
478 int t = 0;
479 if (transient != -2 || type > Ttime)
480 t = transient;
481 if (type != Tstruct && type != Tclass && type != Tunion && (type != Tenum || ref))
482 { for (p = Tptr[type]; p; p = p->next)
483 { if (p->ref == ref && p->sym == (Symbol*) 0 && p->width == width && p->transient == t)
484 { if (imported && !p->imported)
485 p->imported = imported;
486 return p; /* type alrady exists in table */
487 }
488 }
489 }
490 p = (Tnode*)emalloc(sizeof(Tnode)); /* install new type */
491 p->type = type;
492 p->ref = ref;
493 p->id = lookup("/*?*/");
494 p->base = NULL;
495 p->sym = (Symbol*)0;
496 p->response = (Entry*)0;
497 p->width = width;
498 p->generated = False;
499 p->classed = False;
500 p->wsdl = False;
501 p->next = Tptr[type];
502 p->transient = t;
503 p->imported = imported;
504 p->pattern = NULL;
505 p->minLength = MINLONG64;
506 p->maxLength = MAXLONG64;
507 p->num = typeNO++;
508 Tptr[type] = p;
509 DBGLOG(fprintf(stderr, "New type %s %s\n", c_type(p), p->imported));
510 if (type == Tpointer && ((Tnode*)ref)->imported && (((Tnode*)ref)->type == Tenum || ((Tnode*)ref)->type == Tstruct || ((Tnode*)ref)->type == Tclass))
511 p->imported = ((Tnode*)ref)->imported;
512 else if (lflag && !is_transient(p) && (type == Tenum || type == Tstruct || type == Tclass))
513 mkpointer(p);
514 return p;
515 }
516
517 Tnode *
518 mksymtype(Tnode *typ, Symbol *sym)
519 { Tnode *p;
520 p = (Tnode*)emalloc(sizeof(Tnode)); /* install new type */
521 p->type = typ->type;
522 p->ref = typ->ref;
523 if (typ->id == lookup("/*?*/"))
524 p->id = sym;
525 else
526 p->id = typ->id;
527 p->sym = sym;
528 p->response = (Entry*)0;
529 p->width = typ->width;
530 p->generated = False;
531 p->classed = True; /* copy of existing (generated) type */
532 p->wsdl = False;
533 p->next = Tptr[typ->type];
534 p->transient = transient;
535 p->imported = imported;
536 p->pattern = NULL;
537 p->minLength = MINLONG64;
538 p->maxLength = MAXLONG64;
539 p->num = typeNO++;
540 Tptr[typ->type] = p;
541 DBGLOG(fprintf(stderr, "New typedef %s %s\n", c_type(p), p->imported));
542 return p;
543 }
544
545 Tnode *
546 mktemplate(Tnode *typ, Symbol *id)
547 { Tnode *p;
548 for (p = Tptr[Ttemplate]; p; p = p->next)
549 if (p->ref == typ && p->id == id && p->transient == transient)
550 { if (imported && !p->imported)
551 p->imported = imported;
552 return p; /* type alrady exists in table */
553 }
554 p = (Tnode*)emalloc(sizeof(Tnode)); /* install new type */
555 p->type = Ttemplate;
556 p->ref = typ;
557 p->id = id;
558 p->sym = NULL;
559 p->response = (Entry*)0;
560 p->width = 0;
561 p->generated = False;
562 p->classed = False; /* copy of existing (generated) type */
563 p->wsdl = False;
564 p->next = Tptr[Ttemplate];
565 p->transient = transient;
566 p->imported = imported;
567 p->pattern = NULL;
568 p->minLength = MINLONG64;
569 p->maxLength = MAXLONG64;
570 p->num = typeNO++;
571 Tptr[Ttemplate] = p;
572 return p;
573 }
574
575 /* DO NOT REMOVE OR ALTER (SEE LICENCE AGREEMENT AND COPYING.txt) */
576 void
577 copyrightnote(FILE *fd, char *fn)
578 { fprintf(fd, "\
579 /* %s\n Generated by gSOAP "VERSION" from %s\n\
580 \n\
581 Copyright(C) 2000-2013, Robert van Engelen, Genivia Inc. All Rights Reserved.\n\
582 The generated code is released under one of the following licenses:\n\
583 GPL or Genivia's license for commercial use.\n\
584 This program is released under the GPL with the additional exemption that\n\
585 compiling, linking, and/or using OpenSSL is allowed.\n\
586 */", fn, filename);
587 }
588
589 void
590 banner(FILE *fd, const char *text)
591 { int i;
592 fprintf(fd, "\n\n/");
593 for (i = 0; i < 78; i++)
594 fputc('*', fd);
595 fprintf(fd, "\\\n *%76s*\n * %-75s*\n *%76s*\n\\", "", text, "");
596 for (i = 0; i < 78; i++)
597 fputc('*', fd);
598 fprintf(fd, "/\n");
599 }
600
601 void
602 identify(FILE *fd, char *fn)
603 { time_t t = time(NULL), *p = &t;
604 char tmp[256];
605 strftime(tmp, 256, "%Y-%m-%d %H:%M:%S GMT", gmtime(p));
606 fprintf(fd, "\n\nSOAP_SOURCE_STAMP(\"@(#) %s ver "VERSION" %s\")\n", fn, tmp);
607 }
608
609 void
610 compile(Table *table)
611 { Entry *p;
612 Tnode *typ;
613 Pragma *pragma;
614 int classflag = 0;
615 int found;
616 int filenum;
617 char *s;
618 char base[1024];
619 char soapStub[1024];
620 char soapH[1024];
621 char soapC[1024];
622 char soapClient[1024];
623 char soapServer[1024];
624 char soapClientLib[1024];
625 char soapServerLib[1024];
626 char pathsoapStub[1024];
627 char pathsoapH[1024];
628 char pathsoapC[1024];
629 char pathsoapClient[1024];
630 char pathsoapServer[1024];
631 char pathsoapClientLib[1024];
632 char pathsoapServerLib[1024];
633 char soapMatlab[1024];
634 char pathsoapMatlab[1024];
635 char soapMatlabHdr[1024];
636 char pathsoapMatlabHdr[1024];
637
638 found = 0;
639 for (p = table->list; p; p = p->next)
640 if (p->info.typ->type == Tfun && !(p->info.sto & Sextern))
641 found = 1;
642 if (!found)
643 Sflag = Cflag = Lflag = 1; /* no service operations were found */
644
645 if (*dirpath)
646 fprintf(fmsg, "Using project directory path: %s\n", dirpath);
647
648 if (namespaceid)
649 { prefix = namespaceid;
650 fprintf(fmsg, "Using code namespace: %s\n", namespaceid);
651 }
652 strcpy(base, prefix);
653 if (cflag)
654 s = ".c";
655 else
656 s = ".cpp";
657
658 strcpy(soapMatlab, base);
659 strcat(soapMatlab, "Matlab.c");
660 strcpy(pathsoapMatlab, dirpath);
661 strcat(pathsoapMatlab, soapMatlab );
662
663 strcpy(soapMatlabHdr, base);
664 strcat(soapMatlabHdr, "Matlab.h");
665 strcpy(pathsoapMatlabHdr, dirpath);
666 strcat(pathsoapMatlabHdr, soapMatlabHdr);
667
668 strcpy(soapStub, base);
669 strcat(soapStub, "Stub.h");
670 strcpy(pathsoapStub, dirpath);
671 strcat(pathsoapStub, soapStub);
672 strcpy(soapH, base);
673 strcat(soapH, "H.h");
674 strcpy(pathsoapH, dirpath);
675 strcat(pathsoapH, soapH);
676 strcpy(soapC, base);
677 if (fflag)
678 strcat(soapC, "C_nnn");
679 else
680 strcat(soapC, "C");
681 strcat(soapC, s);
682 strcpy(pathsoapC, dirpath);
683 strcat(pathsoapC, soapC);
684 strcpy(soapClient, base);
685 strcat(soapClient, "Client");
686 strcat(soapClient, s);
687 strcpy(pathsoapClient, dirpath);
688 strcat(pathsoapClient, soapClient);
689 strcpy(soapServer, base);
690 strcat(soapServer, "Server");
691 strcat(soapServer, s);
692 strcpy(pathsoapServer, dirpath);
693 strcat(pathsoapServer, soapServer);
694 strcpy(soapClientLib, base);
695 strcat(soapClientLib, "ClientLib");
696 strcat(soapClientLib, s);
697 strcpy(pathsoapClientLib, dirpath);
698 strcat(pathsoapClientLib, soapClientLib);
699 strcpy(soapServerLib, base);
700 strcat(soapServerLib, "ServerLib");
701 strcat(soapServerLib, s);
702 strcpy(pathsoapServerLib, dirpath);
703 strcat(pathsoapServerLib, soapServerLib);
704
705 if (mflag)
706 { fprintf(fmsg, "Saving %s Matlab definitions\n", pathsoapMatlab);
707 fmatlab=fopen(pathsoapMatlab, "w");
708 if (!fmatlab)
709 execerror("Cannot write to file");
710 copyrightnote(fmatlab, soapMatlab);
711 fprintf(fmatlab,"\n#include \"%s\"\n", soapMatlabHdr);
712 fprintf(fmsg, "Saving %s Matlab definitions\n", pathsoapMatlabHdr);
713 fmheader=fopen(pathsoapMatlabHdr, "w");
714 if (!fmheader)
715 execerror("Cannot write to file");
716 copyrightnote(fmheader, soapMatlabHdr);
717 fprintf(fmheader,"\n#include \"mex.h\"\n#include \"%s\"\n", soapStub);
718 }
719
720 fprintf(fmsg, "Saving %s annotated copy of the source input\n", pathsoapStub);
721 fheader=fopen(pathsoapStub, "w");
722 if (!fheader)
723 execerror("Cannot write to file");
724 copyrightnote(fheader, soapStub);
725 fprintf(fheader,"\n\n#ifndef %sStub_H\n#define %sStub_H", prefix, prefix);
726 for (pragma = pragmas; pragma; pragma = pragma->next)
727 fprintf(fheader,"\n%s", pragma->pragma);
728 if (nflag)
729 fprintf(fheader,"\n#ifndef WITH_NONAMESPACES\n#define WITH_NONAMESPACES\n#endif");
730 if (namespaceid)
731 { fprintf(fheader,"\n#ifndef WITH_NOGLOBAL\n#define WITH_NOGLOBAL\n#endif");
732 }
733 fprintf(fheader,"\n#include \"stdsoap2.h\"");
734 fprintf(fheader,"\n#if GSOAP_VERSION != %d\n# error \"GSOAP VERSION MISMATCH IN GENERATED CODE: PLEASE REINSTALL PACKAGE\"\n#endif\n", GSOAP_VERSION);
735 if (cflag)
736 fprintf(fheader,"\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
737 if (namespaceid)
738 fprintf(fheader,"\n\nnamespace %s {", namespaceid);
739
740 fprintf(fmsg, "Saving %s interface declarations\n", pathsoapH);
741 fhead=fopen(pathsoapH,"w");
742 if (!fhead)
743 execerror("Cannot write to file");
744 copyrightnote(fhead, soapH);
745 fprintf(fhead,"\n\n#ifndef %sH_H\n#define %sH_H", prefix, prefix);
746 fprintf(fhead,"\n#include \"%s\"", soapStub);
747 if (cflag)
748 fprintf(fhead,"\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
749 if (namespaceid)
750 fprintf(fhead,"\n\nnamespace %s {", namespaceid);
751 fprintf(fhead, "\n#ifndef WITH_NOIDREF");
752 if (!cflag && !namespaceid)
753 fprintf(fhead,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
754 fprintf(fhead, "\nSOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap*, const void*, int);");
755 if (!cflag && !namespaceid)
756 fprintf(fhead,"\n\n#ifdef __cplusplus\n}\n#endif");
757 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap*);");
758 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap*);");
759 fprintf(fhead, "\n#endif");
760 if (!cflag && !namespaceid)
761 fprintf(fhead,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
762 fprintf(fhead, "\nSOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*);");
763 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap*, const void*, const char*, int, int);");
764 if (!cflag && !namespaceid)
765 fprintf(fhead,"\n\n#ifdef __cplusplus\n}\n#endif");
766 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap*);");
767
768 generate_header(table);
769 generate_schema(table);
770
771 if (!Sflag && !iflag && !jflag)
772 { fprintf(fmsg, "Saving %s client calling stubs\n", pathsoapClient);
773 fclient=fopen(pathsoapClient,"w");
774 if (!fclient)
775 execerror("Cannot write to file");
776 copyrightnote(fclient, soapClient);
777 fprintf(fclient,"\n\n#if defined(__BORLANDC__)");
778 fprintf(fclient,"\n#pragma option push -w-8060");
779 fprintf(fclient,"\n#pragma option push -w-8004");
780 fprintf(fclient,"\n#endif");
781 fprintf(fclient,"\n#include \"%sH.h\"", prefix);
782 if (cflag)
783 fprintf(fclient,"\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
784 if (namespaceid)
785 fprintf(fclient,"\n\nnamespace %s {", namespaceid);
786 identify(fclient, soapClient);
787
788 if (!Lflag)
789 { flib=fopen(pathsoapClientLib,"w");
790 if (!flib)
791 execerror("Cannot write to file");
792 copyrightnote(flib, soapClientLib);
793 fprintf(fmsg, "Saving %s client stubs with serializers (use only for libs)\n", pathsoapClientLib);
794 fprintf(flib, "\n\n/** Use this file in your project build instead of the two files %s and %s. This hides the serializer functions and avoids linking problems when linking multiple clients and servers. */\n", soapC, soapClient);
795 fprintf(flib, "\n#ifndef WITH_NOGLOBAL\n#define WITH_NOGLOBAL\n#endif");
796 fprintf(flib, "\n#define SOAP_FMAC3 static");
797 fprintf(flib, "\n#include \"%s\"", soapC);
798 fprintf(flib, "\n#include \"%s\"", soapClient);
799 fprintf(flib, "\n\n/* End of %s */\n", soapClientLib);
800 fclose(flib);
801 }
802 }
803 if (!Cflag && !iflag && !jflag)
804 { fprintf(fmsg, "Saving %s server request dispatcher\n", pathsoapServer);
805 fserver=fopen(pathsoapServer,"w");
806 if (!fserver)
807 execerror("Cannot write to file");
808 copyrightnote(fserver, soapServer);
809 fprintf(fserver,"\n\n#if defined(__BORLANDC__)");
810 fprintf(fserver,"\n#pragma option push -w-8060");
811 fprintf(fserver,"\n#pragma option push -w-8004");
812 fprintf(fserver,"\n#endif");
813 fprintf(fserver,"\n#include \"%sH.h\"", prefix);
814 if (cflag)
815 fprintf(fserver,"\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
816 if (namespaceid)
817 fprintf(fserver,"\n\nnamespace %s {", namespaceid);
818 identify(fserver, soapServer);
819
820 if (!Lflag)
821 { flib = fopen(pathsoapServerLib,"w");
822 if (!flib)
823 execerror("Cannot write to file");
824 copyrightnote(flib, soapServerLib);
825 fprintf(fmsg, "Saving %s server request dispatcher with serializers (use only for libs)\n", pathsoapServerLib);
826 fprintf(flib, "\n\n/** Use this file in your project build instead of the two files %s and %s. This hides the serializer functions and avoids linking problems when linking multiple clients and servers. */\n", soapC, soapServer);
827 fprintf(flib, "\n#ifndef WITH_NOGLOBAL\n#define WITH_NOGLOBAL\n#endif");
828 fprintf(flib, "\n#define SOAP_FMAC3 static");
829 fprintf(flib, "\n#include \"%s\"", soapC);
830 fprintf(flib, "\n#include \"%s\"", soapServer);
831 fprintf(flib, "\n\n/* End of %s */\n", soapServerLib);
832 fclose(flib);
833 }
834 }
835
836 if (!iflag && !jflag)
837 soap_serve(table);
838
839 classflag = 0;
840 for (p = classtable->list; p; p = p->next)
841 { if (p->info.typ->type == Tclass && p->info.typ->transient <= 0)
842 { classflag = 1;
843 break;
844 }
845 }
846 if (classflag || Tptr[Ttemplate])
847 { if (cflag)
848 semwarn("Option -c conflicts with the use of classes");
849 }
850
851 for (filenum = 1; partnum == 0; filenum++)
852 {
853 if (fflag)
854 { char *t = strrchr(pathsoapC, '.');
855 sprintf(t-3, "%03d", filenum);
856 *t = '.';
857 fprintf(fmsg, "Saving %s serializers (part %d)\n", pathsoapC, filenum);
858 partnum = fflag; /* number of defs per file */
859 }
860 else
861 { fprintf(fmsg, "Saving %s serializers\n", pathsoapC);
862 partnum = 1;
863 }
864 fout=fopen(pathsoapC,"w");
865 if (!fout)
866 execerror("Cannot write to file");
867 copyrightnote(fout, soapC);
868 fprintf(fout,"\n\n#if defined(__BORLANDC__)");
869 fprintf(fout,"\n#pragma option push -w-8060");
870 fprintf(fout,"\n#pragma option push -w-8004");
871 fprintf(fout,"\n#endif");
872
873 fprintf(fout,"\n\n#include \"%sH.h\"", prefix);
874 if (cflag)
875 fprintf(fout,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
876 if (namespaceid)
877 fprintf(fout,"\n\nnamespace %s {", namespaceid);
878 identify(fout, soapC);
879
880 if (filenum == 1)
881 {
882
883 if (!lflag)
884 {
885 fprintf(fout,"\n\n#ifndef WITH_NOGLOBAL");
886 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_getheader(struct soap *soap)\n{\n\tsoap->part = SOAP_IN_HEADER;\n\tsoap->header = soap_in_SOAP_ENV__Header(soap, \"SOAP-ENV:Header\", soap->header, NULL);\n\tsoap->part = SOAP_END_HEADER;\n\treturn soap->header == NULL;\n}");
887 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap *soap)\n{\n\tif (soap->version && soap->header)\n\t{\tsoap->part = SOAP_IN_HEADER;\n\t\tif (soap_out_SOAP_ENV__Header(soap, \"SOAP-ENV:Header\", 0, soap->header, NULL))\n\t\t\treturn soap->error;\n\t\tsoap->part = SOAP_END_HEADER;\n\t}\n\treturn SOAP_OK;\n}");
888 if (cflag)
889 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap)\n{\n\tif (soap->version && soap->header)\n\t\tsoap_serialize_SOAP_ENV__Header(soap, soap->header);\n}");
890 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap)\n{\n\tif (soap->header == NULL)\n\t{\tif ((soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header))))\n\t\t\tsoap_default_SOAP_ENV__Header(soap, soap->header);\n\t}\n}");
891 }
892 else if ((p = entry(classtable, lookup("SOAP_ENV__Header"))) && p->info.typ->type == Tstruct)
893 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap)\n{\n\tif (soap->version && soap->header)\n\t\tsoap_serialize_SOAP_ENV__Header(soap, soap->header);\n}");
894 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap)\n{\n\tif (soap->header == NULL)\n\t{\tif ((soap->header = soap_new_SOAP_ENV__Header(soap, -1)))\n\t\t\tsoap_default_SOAP_ENV__Header(soap, soap->header);\n\t}\n}");
895 }
896 else
897 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap)\n{\n\tif (soap->version && soap->header)\n\t\tsoap->header->soap_serialize(soap);\n}");
898 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap)\n{\n\tif (soap->header == NULL)\n\t{\tif ((soap->header = soap_new_SOAP_ENV__Header(soap, -1)))\n\t\t\tsoap->header->soap_default(soap);\n\t}\n}");
899 }
900 if (cflag)
901 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap *soap)\n{\n\tif (soap->fault == NULL)\n\t{\tsoap->fault = (struct SOAP_ENV__Fault*)soap_malloc(soap, sizeof(struct SOAP_ENV__Fault));\n\t\tif (soap->fault == NULL)\n\t\t\treturn;\n\t\tsoap_default_SOAP_ENV__Fault(soap, soap->fault);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Code)\n\t{\tsoap->fault->SOAP_ENV__Code = (struct SOAP_ENV__Code*)soap_malloc(soap, sizeof(struct SOAP_ENV__Code));\n\t\tsoap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Reason)\n\t{\tsoap->fault->SOAP_ENV__Reason = (struct SOAP_ENV__Reason*)soap_malloc(soap, sizeof(struct SOAP_ENV__Reason));\n\t\tsoap_default_SOAP_ENV__Reason(soap, soap->fault->SOAP_ENV__Reason);\n\t}\n}");
902 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap *soap)\n{\n\tif (soap->fault)\n\t\tsoap_serialize_SOAP_ENV__Fault(soap, soap->fault);\n}");
903 }
904 else if ((p = entry(classtable, lookup("SOAP_ENV__Fault"))) && p->info.typ->type == Tstruct)
905 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap *soap)\n{\n\tif (soap->fault == NULL)\n\t{\tsoap->fault = soap_new_SOAP_ENV__Fault(soap, -1);\n\t\tif (soap->fault == NULL)\n\t\t\treturn;\n\t\tsoap_default_SOAP_ENV__Fault(soap, soap->fault);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Code)\n\t{\tsoap->fault->SOAP_ENV__Code = soap_new_SOAP_ENV__Code(soap, -1);\n\t\tsoap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Reason)\n\t{\tsoap->fault->SOAP_ENV__Reason = soap_new_SOAP_ENV__Reason(soap, -1);\n\t\tsoap_default_SOAP_ENV__Reason(soap, soap->fault->SOAP_ENV__Reason);\n\t}\n}");
906 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->fault)\n\t\tsoap_serialize_SOAP_ENV__Fault(soap, soap->fault);\n}");
907 }
908 else
909 { fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap *soap)\n{\n\tif (soap->fault == NULL)\n\t{\tsoap->fault = soap_new_SOAP_ENV__Fault(soap, -1);\n\t\tsoap->fault->soap_default(soap);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Code)\n\t{\tsoap->fault->SOAP_ENV__Code = soap_new_SOAP_ENV__Code(soap, -1);\n\t\tsoap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code);\n\t}\n\tif (soap->version == 2 && !soap->fault->SOAP_ENV__Reason)\n\t{\tsoap->fault->SOAP_ENV__Reason = soap_new_SOAP_ENV__Reason(soap, -1);\n\t\tsoap_default_SOAP_ENV__Reason(soap, soap->fault->SOAP_ENV__Reason);\n\t}\n}");
910 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->fault)\n\t\tsoap->fault->soap_serialize(soap);\n}");
911 }
912 if ((p = entry(classtable, lookup("SOAP_ENV__Fault"))) && p->info.typ->type == Tstruct)
913 { fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_putfault(struct soap *soap)\n{\n\tif (soap->fault)\n\t\treturn soap_put_SOAP_ENV__Fault(soap, soap->fault, \"SOAP-ENV:Fault\", NULL);\n\treturn SOAP_OK;\n}");
914 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_getfault(struct soap *soap)\n{\n\treturn (soap->fault = soap_get_SOAP_ENV__Fault(soap, NULL, \"SOAP-ENV:Fault\", NULL)) == NULL;\n}");
915 }
916 else
917 { fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_putfault(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->fault)\n\t\treturn soap->fault->soap_put(soap, \"SOAP-ENV:Fault\", NULL);\n\treturn SOAP_EOM;\n}");
918 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_getfault(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->fault)\n\t\treturn soap->fault->soap_get(soap, \"SOAP-ENV:Fault\", NULL) == NULL;\n\treturn SOAP_EOM;\n}");
919 }
920 fprintf(fhead,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultcode(struct soap *soap);");
921 fprintf(fout,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultcode(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->version == 2 && soap->fault->SOAP_ENV__Code)\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Code->SOAP_ENV__Value;\n\treturn (const char**)&soap->fault->faultcode;\n}");
922 if (cflag)
923 fprintf(fout,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultsubcode(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->version == 2)\n\t{\tif (soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode == NULL)\n\t\t{\tsoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode = (struct SOAP_ENV__Code*)soap_malloc(soap, sizeof(struct SOAP_ENV__Code));\n\t\t\tsoap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode);\n\t\t}\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value;\n\t}\n\treturn (const char**)&soap->fault->faultcode;\n}");
924 else
925 fprintf(fout,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultsubcode(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->version == 2)\n\t{\tif (soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode == NULL)\n\t\t{\tsoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode = soap_new_SOAP_ENV__Code(soap, -1);\n\t\t\tsoap_default_SOAP_ENV__Code(soap, soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode);\n\t\t}\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value;\n\t}\n\treturn (const char**)&soap->fault->faultcode;\n}");
926 fprintf(fout,"\n\nSOAP_FMAC3 const char * SOAP_FMAC4 soap_check_faultsubcode(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->version == 2)\n\t{\tif (soap->fault->SOAP_ENV__Code && soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode && soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode)\n\t\t\treturn soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value;\n\t\treturn NULL;\n\t}\n\treturn soap->fault->faultcode;\n}");
927 fprintf(fout,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultstring(struct soap *soap)\n{\n\tsoap_fault(soap);\n\tif (soap->version == 2)\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Reason->SOAP_ENV__Text;\n\treturn (const char**)&soap->fault->faultstring;\n}");
928 fprintf(fout,"\n\nSOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultdetail(struct soap *soap)\n{\n\tsoap_fault(soap);");
929 if (has_Detail_string())
930 { if (cflag)
931 fprintf(fout,"\n\tif (soap->version == 2)\n\t{\tif (soap->fault->SOAP_ENV__Detail == NULL)\n\t\t{\tsoap->fault->SOAP_ENV__Detail = (struct SOAP_ENV__Detail*)soap_malloc(soap, sizeof(struct SOAP_ENV__Detail));\n\t\t\tsoap_default_SOAP_ENV__Detail(soap, soap->fault->SOAP_ENV__Detail);\n\t\t}\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Detail->__any;\n\t}");
932 else
933 fprintf(fout,"\n\tif (soap->version == 2)\n\t{\tif (soap->fault->SOAP_ENV__Detail == NULL)\n\t\t{\tsoap->fault->SOAP_ENV__Detail = soap_new_SOAP_ENV__Detail(soap, -1);\n\t\t\tsoap_default_SOAP_ENV__Detail(soap, soap->fault->SOAP_ENV__Detail);\n\t\t}\n\t\treturn (const char**)&soap->fault->SOAP_ENV__Detail->__any;\n\t}");
934 }
935 if (has_detail_string())
936 { if (cflag)
937 fprintf(fout,"\n\tif (soap->fault->detail == NULL)\n\t{\tsoap->fault->detail = (struct SOAP_ENV__Detail*)soap_malloc(soap, sizeof(struct SOAP_ENV__Detail));\n\t\tsoap_default_SOAP_ENV__Detail(soap, soap->fault->detail);\n\t}\n\treturn (const char**)&soap->fault->detail->__any;\n}");
938 else
939 fprintf(fout,"\n\tif (soap->fault->detail == NULL)\n\t{\tsoap->fault->detail = soap_new_SOAP_ENV__Detail(soap, -1);\n\t\tsoap_default_SOAP_ENV__Detail(soap, soap->fault->detail);\n\t}\n\treturn (const char**)&soap->fault->detail->__any;\n}");
940 }
941 if (!has_detail_string() && !has_Detail_string())
942 fprintf(fout,"\n\treturn NULL;\n}");
943 fprintf(fout,"\n\nSOAP_FMAC3 const char * SOAP_FMAC4 soap_check_faultdetail(struct soap *soap)\n{\n\tsoap_fault(soap);");
944 if (has_Detail_string())
945 fprintf(fout,"\n\tif (soap->version == 2 && soap->fault->SOAP_ENV__Detail)\n\t\treturn soap->fault->SOAP_ENV__Detail->__any;");
946 if (has_detail_string())
947 fprintf(fout,"\n\tif (soap->fault->detail)\n\t\treturn soap->fault->detail->__any;");
948 fprintf(fout,"\n\treturn NULL;\n}");
949 fprintf(fout,"\n\n#endif");
950
951 fprintf(fout,"\n\n#ifndef WITH_NOIDREF");
952 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap *soap)\n{");
953 fprintf(fout,"\n\tint t;\n\tif (soap->version == 1)\n\t{\tfor (;;)\n\t\t{\tif (!soap_getelement(soap, &t))\n\t\t\t\tif (soap->error || soap_ignore_element(soap))\n\t\t\t\t\tbreak;\n\t\t}\n\t}");
954 fprintf(fout,"\n\tif (soap->error == SOAP_NO_TAG || soap->error == SOAP_EOF)");
955 fprintf(fout,"\n\t\tsoap->error = SOAP_OK;");
956 fprintf(fout,"\n\treturn soap->error;");
957 fprintf(fout,"\n}\n#endif");
958
959 if (!cflag && !namespaceid)
960 fprintf(fout,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
961 fprintf(fout,"\nSOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type)\n{\t(void)type;");
962 fprintf(fout,"\n\tif (soap_peek_element(soap))\n\t\treturn NULL;");
963 fprintf(fout,"\n#ifndef WITH_NOIDREF\n\tif (!*soap->id || !(*type = soap_lookup_type(soap, soap->id)))\n\t\t*type = soap_lookup_type(soap, soap->href);");
964 fprintf(fout,"\n\tswitch (*type)\n\t{");
965 DBGLOG(fprintf(stderr,"\n Calling in_defs( )."));
966 fflush(fout);
967 in_defs(table);
968 DBGLOG(fprintf(stderr,"\n Completed in_defs( )."));
969 fprintf(fout,"\n\tdefault:\n#else\n\t*type = 0;\n#endif");
970 fprintf(fout,"\n\t{\tconst char *t = soap->type;\n\t\tif (!*t)\n\t\t\tt = soap->tag;");
971 fflush(fout);
972 in_defs2(table);
973 fprintf(fout,"\n\t\tt = soap->tag;");
974 in_defs3(table);
975 fprintf(fout,"\n#ifndef WITH_NOIDREF\n\t}\n#endif\n\t}\n\tsoap->error = SOAP_TAG_MISMATCH;\n\treturn NULL;\n}");
976 if (!cflag && !namespaceid)
977 fprintf(fout,"\n\n#ifdef __cplusplus\n}\n#endif");
978
979 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap *soap)\n{");
980 fprintf(fout,"\n\tif (!soap_peek_element(soap))");
981 fprintf(fout,"\n\t{\tint t;");
982 fprintf(fout,"\n\t\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Unexpected element '%%s' in input (level=%%u, %%d)\\n\", soap->tag, soap->level, soap->body));");
983 fprintf(fout,"\n\t\tif (soap->mustUnderstand && !soap->other)");
984 fprintf(fout,"\n\t\t\treturn soap->error = SOAP_MUSTUNDERSTAND;");
985 fprintf(fout,"\n\t\tif (((soap->mode & SOAP_XML_STRICT) && soap->part != SOAP_IN_HEADER) || !soap_match_tag(soap, soap->tag, \"SOAP-ENV:\"))\n\t\t{\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"REJECTING element '%%s'\\n\", soap->tag));\n\t\t\treturn soap->error = SOAP_TAG_MISMATCH;\n\t\t}");
986 fprintf(fout,"\n\t\tif (!*soap->id || !soap_getelement(soap, &t))");
987 fprintf(fout,"\n\t\t{\tsoap->peeked = 0;");
988 fprintf(fout,"\n\t\t\tif (soap->fignore)\n\t\t\t\tsoap->error = soap->fignore(soap, soap->tag);\n\t\t\telse\n\t\t\t\tsoap->error = SOAP_OK;");
989 fprintf(fout,"\n\t\t\tDBGLOG(TEST, if (!soap->error) SOAP_MESSAGE(fdebug, \"IGNORING element '%%s'\\n\", soap->tag));");
990 fprintf(fout,"\n\t\t\tif (!soap->error && soap->body)");
991 fprintf(fout,"\n\t\t\t{\tsoap->level++;");
992 fprintf(fout,"\n\t\t\t\twhile (!soap_ignore_element(soap))");
993 fprintf(fout,"\n\t\t\t\t\t;");
994 fprintf(fout,"\n\t\t\t\tif (soap->error == SOAP_NO_TAG)");
995 fprintf(fout,"\n\t\t\t\t\tsoap->error = soap_element_end_in(soap, NULL);");
996 fprintf(fout,"\n\t\t\t}");
997 fprintf(fout,"\n\t\t}");
998 fprintf(fout,"\n\t}");
999 fprintf(fout,"\n\treturn soap->error;");
1000 fprintf(fout,"\n}");
1001
1002 fprintf(fout,"\n\n#ifndef WITH_NOIDREF");
1003 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap *soap)\n{\n\tint i;\n\tstruct soap_plist *pp;");
1004 fprintf(fout,"\n\tif (soap->version == 1 && soap->encodingStyle && !(soap->mode & (SOAP_XML_TREE | SOAP_XML_GRAPH)))");
1005 fprintf(fout,"\n\t\tfor (i = 0; i < SOAP_PTRHASH; i++)");
1006 fprintf(fout,"\n\t\t\tfor (pp = soap->pht[i]; pp; pp = pp->next)");
1007 fprintf(fout,"\n\t\t\t\tif (pp->mark1 == 2 || pp->mark2 == 2)");
1008 fprintf(fout,"\n\t\t\t\t\tif (soap_putelement(soap, pp->ptr, \"id\", pp->id, pp->type))\n\t\t\t\t\t\treturn soap->error;");
1009 fprintf(fout,"\n\treturn SOAP_OK;\n}\n#endif");
1010
1011 if (!cflag && !namespaceid)
1012 fprintf(fout,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
1013 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap *soap, const void *ptr, const char *tag, int id, int type)\n{\t(void)tag;");
1014 fprintf(fout,"\n\tswitch (type)\n\t{");
1015 fflush(fout);
1016 out_defs(table);
1017 fprintf(fout,"\n\t}\n\treturn SOAP_OK;\n}");
1018 if (!cflag && !namespaceid)
1019 fprintf(fout,"\n\n#ifdef __cplusplus\n}\n#endif");
1020
1021 fprintf(fout,"\n\n#ifndef WITH_NOIDREF");
1022 if (!cflag && !namespaceid)
1023 fprintf(fout,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif");
1024 if (is_anytype_flag)
1025 { fprintf(fout,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap *soap, const void *ptr, int type)\n{");
1026 fprintf(fout,"\n\t(void)soap; (void)ptr; (void)type; /* appease -Wall -Werror */");
1027 fprintf(fout,"\n\tswitch (type)\n\t{");
1028 fflush(fout);
1029 mark_defs(table);
1030 fprintf(fout,"\n\t}\n}");
1031 }
1032 else
1033 { fprintf(fout,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap *soap, const void *ptr, int type)\n{");
1034 fprintf(fout,"\n\t(void)soap; (void)ptr; (void)type; /* appease -Wall -Werror */");
1035 fprintf(fout,"\n}");
1036 }
1037 if (!cflag && !namespaceid)
1038 fprintf(fout,"\n\n#ifdef __cplusplus\n}\n#endif");
1039 fprintf(fout,"\n#endif");
1040
1041 }
1042
1043 if (!cflag)
1044 {
1045 fprintf(fhead,"\n\nSOAP_FMAC3 void * SOAP_FMAC4 %s_instantiate(struct soap*, int, const char*, const char*, size_t*);", prefix);
1046 fprintf(fout,"\n\nSOAP_FMAC3 void * SOAP_FMAC4 %s_instantiate(struct soap *soap, int t, const char *type, const char *arrayType, size_t *n)\n{\t(void)type;\n\tswitch (t)\n\t{", prefix);
1047 if (classtable)
1048 for (p = classtable->list; p; p = p->next)
1049 if ((p->info.typ->type == Tclass || p->info.typ->type == Tstruct) && !is_transient(p->info.typ))
1050 { if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1051 fprintf(fout,"\n#ifndef WITH_NOGLOBAL");
1052 fprintf(fout,"\n\tcase %s:\n\t\treturn (void*)soap_instantiate_%s(soap, -1, type, arrayType, n);", soap_type(p->info.typ), c_ident(p->info.typ));
1053 if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1054 fprintf(fout,"\n#endif");
1055 }
1056 if (typetable)
1057 for (p = typetable->list; p; p = p->next)
1058 if ((p->info.typ->type == Tclass || p->info.typ->type == Tstruct) && !is_transient(p->info.typ))
1059 { if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1060 fprintf(fout,"\n#ifndef WITH_NOGLOBAL");
1061 fprintf(fout,"\n\tcase %s:\n\t\treturn (void*)soap_instantiate_%s(soap, -1, type, arrayType, n);", soap_type(p->info.typ), c_ident(p->info.typ));
1062 if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1063 fprintf(fout,"\n#endif");
1064 }
1065 for (typ = Tptr[Ttemplate]; typ; typ = typ->next)
1066 if (typ->ref && !is_transient(typ))
1067 fprintf(fout,"\n\tcase %s:\n\t\treturn (void*)soap_instantiate_%s(soap, -1, type, arrayType, n);", soap_type(typ), c_ident(typ));
1068
1069 fprintf(fout,"\n\t}\n\treturn NULL;\n}");
1070
1071 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 %s_fdelete(struct soap_clist*);", prefix);
1072 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 %s_fdelete(struct soap_clist *p)", prefix);
1073 fprintf(fout,"\n{\tswitch (p->type)\n\t{");
1074 if (classtable)
1075 { for (p = classtable->list; p; p = p->next)
1076 if ((p->info.typ->type == Tclass || p->info.typ->type == Tstruct) && !is_transient(p->info.typ))
1077 { if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1078 fprintf(fout,"\n#ifndef WITH_NOGLOBAL");
1079 fprintf(fout,"\n\tcase %s:", soap_type(p->info.typ));
1080 fprintf(fout,"\n\t\tif (p->size < 0)\n\t\t\tSOAP_DELETE((%s*)p->ptr);\n\t\telse\n\t\t\tSOAP_DELETE_ARRAY((%s*)p->ptr);\n\t\tbreak;", c_type(p->info.typ), c_type(p->info.typ));
1081 if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1082 fprintf(fout,"\n#endif");
1083 }
1084 }
1085 if (typetable)
1086 { for (p = typetable->list; p; p = p->next)
1087 if (p->info.typ->type == Tclass || p->info.typ->type == Tstruct) /* && is_external(p->info.typ)) */
1088 { if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1089 fprintf(fout,"\n#ifndef WITH_NOGLOBAL");
1090 fprintf(fout,"\n\tcase %s:", soap_type(p->info.typ));
1091 fprintf(fout,"\n\t\tif (p->size < 0)\n\t\t\tSOAP_DELETE((%s*)p->ptr);\n\t\telse\n\t\t\tSOAP_DELETE_ARRAY((%s*)p->ptr);\n\t\tbreak;", c_type(p->info.typ), c_type(p->info.typ));
1092 if (is_header_or_fault(p->info.typ) || is_body(p->info.typ))
1093 fprintf(fout,"\n#endif");
1094 }
1095 }
1096 for (typ = Tptr[Ttemplate]; typ; typ = typ->next)
1097 { if (typ->ref && !is_transient(typ))
1098 { fprintf(fout,"\n\tcase %s:", soap_type(typ));
1099 fprintf(fout,"\n\t\tif (p->size < 0)\n\t\t\tSOAP_DELETE((%s*)p->ptr);\n\t\telse\n\t\t\tSOAP_DELETE_ARRAY((%s*)p->ptr);\n\t\tbreak;", c_type(typ), c_type(typ));
1100 }
1101 }
1102 fprintf(fout,"\n\tdefault:\treturn SOAP_ERR;");
1103 fprintf(fout,"\n\t}\n\treturn SOAP_OK;");
1104 fprintf(fout,"\n}");
1105
1106 fprintf(fhead,"\nSOAP_FMAC3 void* SOAP_FMAC4 soap_class_id_enter(struct soap*, const char*, void*, int, size_t, const char*, const char*);");
1107 if (!lflag)
1108 {
1109 fprintf(fout,"\n\nSOAP_FMAC3 void* SOAP_FMAC4 soap_class_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, const char *type, const char *arrayType)");
1110 fprintf(fout, "\n{\treturn soap_id_enter(soap, id, p, t, n, 0, type, arrayType, %s_instantiate);\n}", prefix);
1111 }
1112
1113 if (Tptr[Ttemplate])
1114 {
1115 fprintf(fhead, "\n\nSOAP_FMAC3 void* SOAP_FMAC4 soap_container_id_forward(struct soap*, const char*, void*, size_t, int, int, size_t, unsigned int);");
1116 if (!lflag)
1117 {
1118 fprintf(fout, "\n\nSOAP_FMAC3 void* SOAP_FMAC4 soap_container_id_forward(struct soap *soap, const char *href, void *p, size_t len, int st, int tt, size_t n, unsigned int k)");
1119 fprintf(fout, "\n{\treturn soap_id_forward(soap, href, p, len, st, tt, n, k, %s_container_insert);\n}", prefix);
1120 }
1121
1122 fprintf(fhead, "\n\nSOAP_FMAC3 void SOAP_FMAC4 %s_container_insert(struct soap*, int, int, void*, size_t, const void*, size_t);", prefix);
1123 if (!lflag)
1124 {
1125 fprintf(fout, "\n\nSOAP_FMAC3 void SOAP_FMAC4 %s_container_insert(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)", prefix);
1126 fprintf(fout, "\n#ifdef WIN32\n#pragma warning(push)\n#pragma warning(disable:4065)\n#endif");
1127 fprintf(fout,"\n{\n\t(void)soap; (void)st; (void)p; (void)len; (void)q; (void)n; /* appease -Wall -Werror */");
1128 fprintf(fout, "\n\tswitch (tt)\n\t{");
1129 for (typ = Tptr[Ttemplate]; typ; typ = typ->next)
1130 { if (typ->ref && !is_transient(typ))
1131 { fprintf(fout, "\n\tcase %s:", soap_type(typ));
1132 fprintf(fout, "\n\t\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Container %s_container_insert type=%%d in %%d location=%%p object=%%p len=%%lu\\n\", st, tt, p, q, (unsigned long)len));", prefix);
1133 if (!strcmp(typ->id->name, "std::vector") || !strcmp(typ->id->name, "std::deque"))
1134 fprintf(fout, "\n\t\t(*(%s)p)[len] = *(%s)q;", c_type_id(typ, "*"), c_type_id((Tnode*)typ->ref, "*"));
1135 else
1136 fprintf(fout, "\n\t\t((%s)p)->insert(((%s)p)->end(), *(%s)q);", c_type_id(typ, "*"), c_type_id(typ, "*"), c_type_id((Tnode*)typ->ref, "*"));
1137 fprintf(fout, "\n\t\tbreak;");
1138 }
1139 }
1140 fprintf(fout, "\n\tdefault:\n\t\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Could not insert type=%%d in %%d\\n\", st, tt));");
1141 fprintf(fout, "\n\t}");
1142 fprintf(fout, "\n#ifdef WIN32\n#pragma warning(pop)\n#endif");
1143 fprintf(fout, "\n}");
1144 }
1145 }
1146 }
1147 }
1148
1149 def_table(table);
1150
1151 if (namespaceid)
1152 fprintf(fout,"\n\n} // namespace %s\n", namespaceid);
1153 if (cflag)
1154 fprintf(fout,"\n\n#ifdef __cplusplus\n}\n#endif");
1155 fprintf(fout,"\n\n#if defined(__BORLANDC__)");
1156 fprintf(fout,"\n#pragma option pop");
1157 fprintf(fout,"\n#pragma option pop");
1158 fprintf(fout,"\n#endif");
1159 fprintf(fout, "\n\n/* End of %s */\n", soapC);
1160 fclose(fout);
1161 }
1162
1163 if (namespaceid)
1164 fprintf(fhead,"\n\n} // namespace %s\n", namespaceid);
1165 if (cflag)
1166 fprintf(fhead,"\n\n#ifdef __cplusplus\n}\n#endif");
1167 fprintf(fhead, "\n\n#endif");
1168 fprintf(fhead, "\n\n/* End of %s */\n", soapH);
1169 fclose(fhead);
1170
1171 if (namespaceid)
1172 fprintf(fheader,"\n\n} // namespace %s\n", namespaceid);
1173 if (cflag)
1174 fprintf(fheader,"\n\n#ifdef __cplusplus\n}\n#endif");
1175 fprintf(fheader, "\n\n#endif");
1176 fprintf(fheader, "\n\n/* End of %s */\n", soapStub);
1177 fclose(fheader);
1178
1179 if (mflag)
1180 { DBGLOG(fprintf(stderr,"\n Calling matlab_def_table( )."));
1181 matlab_def_table(table);
1182 DBGLOG(fprintf(stderr,"\n Completed matlab_def_table( )."));
1183 fclose(fmatlab);
1184 fclose(fmheader);
1185 }
1186
1187 if (!Sflag && !iflag && !jflag)
1188 { if (namespaceid)
1189 fprintf(fclient,"\n\n} // namespace %s\n", namespaceid);
1190 if (cflag)
1191 fprintf(fclient,"\n\n#ifdef __cplusplus\n}\n#endif");
1192 fprintf(fclient,"\n\n#if defined(__BORLANDC__)");
1193 fprintf(fclient,"\n#pragma option pop");
1194 fprintf(fclient,"\n#pragma option pop");
1195 fprintf(fclient,"\n#endif");
1196 fprintf(fclient, "\n\n/* End of %s */\n", soapClient);
1197 fclose(fclient);
1198 }
1199
1200 if (!Cflag && !iflag && !jflag)
1201 { if (namespaceid)
1202 fprintf(fserver,"\n\n} // namespace %s\n", namespaceid);
1203 if (cflag)
1204 fprintf(fserver,"\n\n#ifdef __cplusplus\n}\n#endif");
1205 fprintf(fserver,"\n\n#if defined(__BORLANDC__)");
1206 fprintf(fserver,"\n#pragma option pop");
1207 fprintf(fserver,"\n#pragma option pop");
1208 fprintf(fserver,"\n#endif");
1209 fprintf(fserver, "\n\n/* End of %s */\n", soapServer);
1210 fclose(fserver);
1211 }
1212 }
1213
1214 void
1215 gen_class(FILE *fd, Entry *p)
1216 { Entry *Eptr;
1217 Tnode *typ = p->info.typ;
1218 char *x;
1219 x = xsi_type(typ);
1220 if (!x || !*x)
1221 x = wsdl_type(typ, "");
1222 typ->classed = True;
1223 if (is_header_or_fault(typ) || is_body(typ))
1224 fprintf(fd, "\n\n#ifndef WITH_NOGLOBAL");
1225 if (typ->ref)
1226 { fprintf(fd, "\n\n#ifndef %s", soap_type(typ));
1227 fprintf(fd, "\n#define %s (%d)\n",soap_type(typ),typ->num);
1228 }
1229 else
1230 fprintf(fd, "\n\n");
1231 if (is_volatile(typ))
1232 fprintf(fd, "#if 0 /* volatile type: do not declare here, declared elsewhere */\n");
1233 else if (is_transient(typ) && typ->ref)
1234 fprintf(fd, "/* Transient type: */\n");
1235 else if (is_invisible(typ->id->name) && typ->ref)
1236 fprintf(fd, "/* Operation wrapper: */\n");
1237 else if (is_hexBinary(typ))
1238 fprintf(fd, "/* hexBinary schema type: */\n");
1239 else if (is_binary(typ))
1240 fprintf(fd, "/* Base64 schema type: */\n");
1241 else if (is_discriminant(typ))
1242 fprintf(fd, "/* Choice: */\n");
1243 else if (is_dynamic_array(typ))
1244 { Eptr = ((Table*)typ->ref)->list;
1245 if (has_ns(typ) || is_untyped(typ))
1246 fprintf(fd, "/* Sequence of %s schema type: */\n", x);
1247 else
1248 { if (!eflag)
1249 { sprintf(errbuf, "array '%s' is not compliant with WS-I Basic Profile 1.0a, reason: SOAP encoded array", c_type(typ));
1250 compliancewarn(errbuf);
1251 }
1252 fprintf(fd, "/* SOAP encoded array of %s schema type: */\n", x);
1253 }
1254 }
1255 else if (is_primclass(typ))
1256 fprintf(fd, "/* Primitive %s schema type: */\n", x);
1257 else if (!strcmp(typ->id->name, "SOAP_ENV__Header"))
1258 fprintf(fd, "/* SOAP Header: */\n");
1259 else if (!strcmp(typ->id->name, "SOAP_ENV__Fault"))
1260 fprintf(fd, "/* SOAP Fault: */\n");
1261 else if (!strcmp(typ->id->name, "SOAP_ENV__Code"))
1262 fprintf(fd, "/* SOAP Fault Code: */\n");
1263 else if (x && *x && typ->ref)
1264 fprintf(fd, "/* %s */\n", x);
1265 fflush(fd);
1266 if (typ->type == Tstruct)
1267 { DBGLOG(fprintf(stderr,"\nstruct %s\n", typ->id->name));
1268 if (typ->ref)
1269 { int permission = -1;
1270 fprintf(fd, "struct %s\n{", ident(typ->id->name));
1271 for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next)
1272 { if (!cflag && permission != (Eptr->info.sto & (Sprivate | Sprotected)))
1273 { if (Eptr->info.sto & Sprivate)
1274 fprintf(fd, "\nprivate:");
1275 else if (Eptr->info.sto & Sprotected)
1276 fprintf(fd, "\nprotected:");
1277 else
1278 fprintf(fd, "\npublic:");
1279 permission = (Eptr->info.sto & (Sprivate | Sprotected));
1280 }
1281 if (cflag && Eptr->info.typ->type == Tfun)
1282 continue;
1283 if (cflag && (Eptr->info.sto & Stypedef))
1284 continue;
1285 fprintf(fd, "\n\t%s", c_storage(Eptr->info.sto));
1286 /*if (Eptr->info.typ->type == Tclass && !is_external(Eptr->info.typ) && Eptr->info.typ->classed == False || (Eptr->info.typ->type == Tpointer || Eptr->info.typ->type == Treference) && Eptr->info.typ->ref && ((Tnode*)Eptr->info.typ->ref)->type == Tclass && !is_external(Eptr->info.typ->ref) && ((Tnode*)Eptr->info.typ->ref)->classed == False)
1287 fprintf(fd, "class ");
1288 */
1289 if (Eptr->sym == typ->id && Eptr->info.typ->type == Tfun) /* a hack to emit constructor in a struct, where constructor has no return value */
1290 ((FNinfo*)Eptr->info.typ->ref)->ret = mknone();
1291 fprintf(fd, "%s", c_type_id(Eptr->info.typ,Eptr->sym->name));
1292 if (Eptr->info.sto & Sconst)
1293 fprintf(fd, "%s;", c_init(Eptr));
1294 else if (Eptr->info.sto & Sconstobj)
1295 fprintf(fd, " const;");
1296 else
1297 fprintf(fd, ";");
1298 if (Eptr->info.sto & Sreturn)
1299 fprintf(fd, "\t/* SOAP 1.2 RPC return element (when namespace qualified) */");
1300 if (is_external(Eptr->info.typ))
1301 fprintf(fd, "\t/* external */");
1302 if (is_transient(Eptr->info.typ))
1303 fprintf(fd, "\t/* transient */");
1304 if (is_imported(Eptr->info.typ))
1305 fprintf(fd, "\t/* type imported from %s */", Eptr->info.typ->imported);
1306 if (Eptr->info.sto & Sattribute)
1307 { if (Eptr->info.minOccurs >= 1)
1308 fprintf(fd, "\t/* required attribute of type %s */", wsdl_type(Eptr->info.typ, ""));
1309 else
1310 fprintf(fd, "\t/* optional attribute of type %s */", wsdl_type(Eptr->info.typ, ""));
1311 }
1312 if (Eptr->info.sto & (Sconst | Sprivate | Sprotected))
1313 fprintf(fd, "\t/* not serialized */");
1314 else if (Eptr->info.sto & SmustUnderstand)
1315 fprintf(fd, "\t/* mustUnderstand */");
1316 else if (!is_dynamic_array(typ) && is_repetition(Eptr))
1317 { if (Eptr->info.maxOccurs > 1)
1318 fprintf(fd, "\t/* sequence of " SOAP_LONG_FORMAT " to " SOAP_LONG_FORMAT " elements <%s> */", Eptr->info.minOccurs, Eptr->info.maxOccurs, ns_convert(Eptr->next->sym->name));
1319 else
1320 fprintf(fd, "\t/* sequence of elements <%s> */", ns_convert(Eptr->next->sym->name));
1321 }
1322 else if (is_anytype(Eptr))
1323 fprintf(fd, "\t/* any type of element <%s> (defined below) */", ns_convert(Eptr->next->sym->name));
1324 else if (is_choice(Eptr))
1325 fprintf(fd, "\t/* union discriminant (of union defined below) */");
1326 else if (Eptr->info.typ->type != Tfun && !(Eptr->info.sto & (Sconst | Sprivate | Sprotected)) && !(Eptr->info.sto & Sattribute) && !is_transient(Eptr->info.typ) && !is_external(Eptr->info.typ) && strncmp(Eptr->sym->name, "__", 2))
1327 { if (Eptr->info.maxOccurs > 1)
1328 fprintf(fd, "\t/* sequence of " SOAP_LONG_FORMAT " to " SOAP_LONG_FORMAT " elements of type %s */", Eptr->info.minOccurs, Eptr->info.maxOccurs, wsdl_type(Eptr->info.typ, ""));
1329 else if (Eptr->info.minOccurs >= 1)
1330 fprintf(fd, "\t/* required element of type %s */", wsdl_type(Eptr->info.typ, ""));
1331 else
1332 fprintf(fd, "\t/* optional element of type %s */", wsdl_type(Eptr->info.typ, ""));
1333 }
1334 if (!is_dynamic_array(typ) && !is_primclass(typ))
1335 { if (!strncmp(Eptr->sym->name, "__size", 6))
1336 { if (!Eptr->next || Eptr->next->info.typ->type != Tpointer)
1337 { sprintf(errbuf, "Member field '%s' is not followed by a pointer member field in struct '%s'", Eptr->sym->name, typ->id->name);
1338 semwarn(errbuf);
1339 }
1340 }
1341 else if (!strncmp(Eptr->sym->name, "__type", 6))
1342 { if (!Eptr->next || ((Eptr->next->info.typ->type != Tpointer || ((Tnode*)Eptr->next->info.typ->ref)->type != Tvoid)))
1343 { sprintf(errbuf, "Member field '%s' is not followed by a void pointer or union member field in struct '%s'", Eptr->sym->name, typ->id->name);
1344 semwarn(errbuf);
1345 }
1346 }
1347 }
1348 }
1349 if (!cflag && !is_transient(typ) && !is_volatile(typ))
1350 { fprintf(fd,"\npublic:\n\tint soap_type() const { return %d; } /* = unique type id %s */", typ->num, soap_type(typ));
1351 #if 0
1352 /* ctor not allowed in unions, so keep things simple for structs */
1353 if (!has_constructor(typ))
1354 { fprintf(fd,"\n\t %s()", ident(typ->id->name));
1355 fprintf(fd, " { void soap_default_%s(struct soap*, %s); soap_default_%s(NULL, this); }", c_ident(typ), c_type_id(typ, "*"), c_ident(typ));
1356 }
1357 if (!has_destructor(typ))
1358 fprintf(fd,"\n\tvirtual ~%s() { }", ident(typ->id->name));
1359 #endif
1360 }
1361 if (!((Table*)typ->ref)->list)
1362 { if (cflag)
1363 fprintf(fd, "\n#ifdef WITH_NOEMPTYSTRUCT\n\tchar dummy;\t/* dummy member to enable compilation */\n#endif");
1364 else
1365 fprintf(fd, "\n#ifdef WITH_NOEMPTYSTRUCT\nprivate:\n\tchar dummy;\t/* dummy member to enable compilation */\n#endif");
1366 }
1367 fprintf(fd, "\n};");
1368 }
1369 else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ))
1370 { sprintf(errbuf, "struct '%s' is empty", typ->id->name);
1371 semwarn(errbuf);
1372 }
1373 }
1374 else if (typ->type == Tclass)
1375 { DBGLOG(fprintf(stderr,"\nclass %s\n", typ->id->name));
1376 if (typ->ref)
1377 { int permission = -1;
1378 fprintf(fd,"class SOAP_CMAC %s", ident(typ->id->name));
1379 if (typ->base)
1380 fprintf(fd," : public %s", ident(typ->base->name));
1381 fprintf(fd,"\n{");
1382 for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next)
1383 { if (permission != (Eptr->info.sto & (Sprivate | Sprotected)))
1384 { if (Eptr->info.sto & Sprivate)
1385 fprintf(fd, "\nprivate:");
1386 else if (Eptr->info.sto & Sprotected)
1387 fprintf(fd, "\nprotected:");
1388 else
1389 fprintf(fd, "\npublic:");
1390 permission = (Eptr->info.sto & (Sprivate | Sprotected));
1391 }
1392 fprintf(fd,"\n\t%s", c_storage(Eptr->info.sto));
1393 /* if (Eptr->info.typ->type == Tclass && !is_external(Eptr->info.typ) && Eptr->info.typ->classed == False || (Eptr->info.typ->type == Tpointer || Eptr->info.typ->type == Treference) && Eptr->info.typ->ref && ((Tnode*)Eptr->info.typ->ref)->type == Tclass && !is_external(Eptr->info.typ->ref) && ((Tnode*)Eptr->info.typ->ref)->classed == False)
1394 fprintf(fd, "class ");
1395 */
1396 fprintf(fd,"%s", c_type_id(Eptr->info.typ,Eptr->sym->name));
1397 if (Eptr->info.sto & Sconstobj)
1398 fprintf(fd, " const");
1399 if (Eptr->info.sto & Sconst)
1400 fprintf(fd, "%s;", c_init(Eptr));
1401 else if (Eptr->info.sto & Sabstract)
1402 fprintf(fd, " = 0;");
1403 else
1404 fprintf(fd, ";");
1405 if (Eptr->info.sto & Sreturn)
1406 fprintf(fd, "\t/* SOAP 1.2 RPC return element (when namespace qualified) */");
1407 if (is_external(Eptr->info.typ))
1408 fprintf(fd, "\t/* external */");
1409 if (is_transient(Eptr->info.typ))
1410 fprintf(fd, "\t/* transient */");
1411 if (is_imported(Eptr->info.typ))
1412 fprintf(fd, "\t/* type imported from %s */", Eptr->info.typ->imported);
1413 if (Eptr->info.sto & Sattribute)
1414 { if (Eptr->info.minOccurs >= 1)
1415 fprintf(fd, "\t/* required attribute */");
1416 else
1417 fprintf(fd, "\t/* optional attribute */");
1418 }
1419 if (Eptr->info.sto & (Sconst | Sprivate | Sprotected))
1420 fprintf(fd, "\t/* not serialized */");
1421 else if (Eptr->info.sto & SmustUnderstand)
1422 fprintf(fd, "\t/* mustUnderstand */");
1423 else if (!is_dynamic_array(typ) && is_repetition(Eptr))
1424 { if (Eptr->info.maxOccurs > 1)
1425 fprintf(fd, "\t/* sequence of " SOAP_LONG_FORMAT " to " SOAP_LONG_FORMAT " elements <%s> */", Eptr->info.minOccurs, Eptr->info.maxOccurs, ns_convert(Eptr->next->sym->name));
1426 else
1427 fprintf(fd, "\t/* sequence of elements <%s> */", ns_convert(Eptr->next->sym->name));
1428 }
1429 else if (is_anytype(Eptr))
1430 fprintf(fd, "\t/* any type of element <%s> (defined below) */", ns_convert(Eptr->next->sym->name));
1431 else if (is_choice(Eptr))
1432 fprintf(fd, "\t/* union discriminant (of union defined below) */");
1433 else if (Eptr->info.typ->type != Tfun && !(Eptr->info.sto & (Sconst | Sprivate | Sprotected)) && !(Eptr->info.sto & Sattribute) && !is_transient(Eptr->info.typ) && !is_external(Eptr->info.typ) && strncmp(Eptr->sym->name, "__", 2))
1434 { if (Eptr->info.maxOccurs > 1)
1435 fprintf(fd, "\t/* sequence of " SOAP_LONG_FORMAT " to " SOAP_LONG_FORMAT " elements */", Eptr->info.minOccurs, Eptr->info.maxOccurs);
1436 else if (Eptr->info.minOccurs >= 1)
1437 fprintf(fd, "\t/* required element of type %s */", wsdl_type(Eptr->info.typ, ""));
1438 else
1439 fprintf(fd, "\t/* optional element of type %s */", wsdl_type(Eptr->info.typ, ""));
1440 }
1441 if (!is_dynamic_array(typ) && !is_primclass(typ))
1442 { if (!strncmp(Eptr->sym->name, "__size", 6))
1443 { if (!Eptr->next || Eptr->next->info.typ->type != Tpointer)
1444 { sprintf(errbuf, "Member field '%s' is not followed by a pointer member field in struct '%s'", Eptr->sym->name, typ->id->name);
1445 semwarn(errbuf);
1446 }
1447 }
1448 else if (!strncmp(Eptr->sym->name, "__type", 6))
1449 { if (!Eptr->next || ((Eptr->next->info.typ->type != Tpointer || ((Tnode*)Eptr->next->info.typ->ref)->type != Tvoid)))
1450 { sprintf(errbuf, "Member field '%s' is not followed by a void pointer or union member field in struct '%s'", Eptr->sym->name, typ->id->name);
1451 semwarn(errbuf);
1452 }
1453 }
1454 }
1455 }
1456 if (!is_transient(typ) && !is_volatile(typ))
1457 { fprintf(fd,"\npublic:\n\tvirtual int soap_type() const { return %d; } /* = unique type id %s */", typ->num, soap_type(typ));
1458 fprintf(fd,"\n\tvirtual void soap_default(struct soap*);");
1459 fprintf(fd,"\n\tvirtual void soap_serialize(struct soap*) const;");
1460 if (kflag)
1461 fprintf(fd,"\n\tvirtual void soap_traverse(struct soap*, const char *s, soap_walker, soap_walker);");
1462 fprintf(fd,"\n\tvirtual int soap_put(struct soap*, const char*, const char*) const;");
1463 fprintf(fd,"\n\tvirtual int soap_out(struct soap*, const char*, int, const char*) const;");
1464 fprintf(fd,"\n\tvirtual void *soap_get(struct soap*, const char*, const char*);");
1465 fprintf(fd,"\n\tvirtual void *soap_in(struct soap*, const char*, const char*);");
1466 if (!has_constructor(typ))
1467 { fprintf(fd,"\n\t %s()", ident(typ->id->name));
1468 fprintf(fd, " { %s::soap_default(NULL); }", ident(typ->id->name));
1469 }
1470 if (!has_destructor(typ))
1471 fprintf(fd,"\n\tvirtual ~%s() { }", ident(typ->id->name));
1472 /* the use of 'friend' causes problems linking static functions. Adding these friends could enable serializing protected/private members (which is not implemented)
1473 fprintf(fd,"\n\tfriend %s *soap_instantiate_%s(struct soap*, int, const char*, const char*, size_t*);", typ->id->name, typ->id->name);
1474 fprintf(fd,"\n\tfriend %s *soap_in_%s(struct soap*, const char*, %s*, const char*);", typ->id->name, typ->id->name, typ->id->name);
1475 fprintf(fd,"\n\tfriend int soap_out_%s(struct soap*, const char*, int, const %s*, const char*);", typ->id->name, typ->id->name);
1476 */
1477 }
1478 else if (!((Table*)typ->ref)->list)
1479 fprintf(fd, "\n#ifdef WITH_NOEMPTYSTRUCT\nprivate:\n\tchar dummy;\t/* dummy member to enable compilation */\n#endif");
1480 fprintf(fd,"\n};");
1481 }
1482 else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ))
1483 { sprintf(errbuf, "class '%s' is empty", typ->id->name);
1484 semwarn(errbuf);
1485 }
1486 }
1487 else if (typ->type == Tunion)
1488 { int i = 1;
1489 if (typ->ref)
1490 { fprintf(fd, "union %s\n{", ident(typ->id->name));
1491 for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next)
1492 { fprintf(fd, "\n#define SOAP_UNION_%s_%s\t(%d)", c_ident(typ), ident(Eptr->sym->name), i);
1493 i++;
1494 fprintf(fd, "\n\t%s", c_storage(Eptr->info.sto));
1495 fprintf(fd, "%s;", c_type_id(Eptr->info.typ,Eptr->sym->name));
1496 if (Eptr->info.sto & (Sconst | Sprivate | Sprotected))
1497 fprintf(fd, "\t/* const field cannot be deserialized */");
1498 if (is_external(Eptr->info.typ))
1499 fprintf(fd, "\t/* external */");
1500 if (is_transient(Eptr->info.typ))
1501 fprintf(fd, "\t/* transient */");
1502 if (Eptr->info.sto & Sattribute)
1503 { fprintf(fd, "\t/* attribute not allowed in union */");
1504 sprintf(errbuf, "union '%s' contains attribute declarations", typ->id->name);
1505 semwarn(errbuf);
1506 }
1507 if (Eptr->info.sto & SmustUnderstand)
1508 fprintf(fd, "\t/* mustUnderstand */");
1509 }
1510 fprintf(fd, "\n};");
1511 }
1512 else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ))
1513 { sprintf(errbuf, "union '%s' is empty", typ->id->name);
1514 semwarn(errbuf);
1515 }
1516 }
1517 if (is_volatile(typ))
1518 fprintf(fd, "\n#endif");
1519 if ((typ->type == Tstruct || typ->type == Tunion) && p->sym->token == TYPE)
1520 fprintf(fd, "\ntypedef %s %s;", c_type(typ), ident(p->sym->name));
1521 if (typ->ref)
1522 fprintf(fd, "\n#endif");
1523 if (is_header_or_fault(typ) || is_body(typ))
1524 fprintf(fd, "\n\n#endif");
1525 fflush(fd);
1526 }
1527
1528 void
1529 generate_header(Table *t)
1530 { Entry *p, *q;
1531 banner(fheader, "Enumerations");
1532 fflush(fheader);
1533 if (enumtable)
1534 for (p = enumtable->list; p; p = p->next)
1535 { char *x;
1536 if (is_imported(p->info.typ) || (is_transient(p->info.typ) && !p->info.typ->ref))
1537 continue;
1538 x = xsi_type(p->info.typ);
1539 if (!x || !*x)
1540 x = wsdl_type(p->info.typ, "");
1541 fprintf(fheader, "\n\n#ifndef %s", soap_type(p->info.typ));
1542 fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num);
1543 if (is_volatile(p->info.typ))
1544 fprintf(fheader, "\n#if 0 /* volatile type: do not redeclare here */");
1545 if (is_mask(p->info.typ))
1546 fprintf(fheader, "\n/* Bitmask %s */", x);
1547 else
1548 fprintf(fheader, "\n/* %s */", x);
1549 fprintf(fheader, "\nenum %s { ", ident(p->info.typ->id->name));
1550 if ((Table*)p->info.typ->ref)
1551 { const char *c = "";
1552 for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
1553 { if (q->info.val.i <= 0x7FFFLL && q->info.val.i >= -0x8000LL)
1554 fprintf(fheader, "%s%s = " SOAP_LONG_FORMAT, c, ident(q->sym->name), q->info.val.i);
1555 else
1556 fprintf(fheader, "%s%s = " SOAP_LONG_FORMAT "LL", c, ident(q->sym->name), q->info.val.i);
1557 c = ", ";
1558 }
1559 }
1560 fprintf(fheader, " };");
1561 if (p->sym->token == TYPE)
1562 fprintf(fheader, "\ntypedef %s %s;", c_type(p->info.typ), ident(p->sym->name));
1563 if (is_volatile(p->info.typ))
1564 fprintf(fheader, "\n#endif");
1565 fprintf(fheader, "\n#endif");
1566 }
1567 banner(fheader, "Types with Custom Serializers");
1568 fflush(fheader);
1569 if (typetable)
1570 for (p = typetable->list; p; p = p->next)
1571 { if (is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_imported(p->info.typ))
1572 { fprintf(fheader, "\n#ifndef %s", soap_type(p->info.typ));
1573 fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num);
1574 fprintf(fheader, "\n%s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name));
1575 fprintf(fheader, "\n#endif");
1576 }
1577 }
1578 if (typetable)
1579 for (p = typetable->list; p; p = p->next)
1580 { if (p->info.typ->type == Tclass && is_eq(p->info.typ->sym->name, "xsd__QName") && !is_external(p->info.typ) && !is_imported(p->info.typ))
1581 { fprintf(fheader, "\n#ifndef %s", soap_type(p->info.typ));
1582 fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num);
1583 fprintf(fheader,"\n%sstd::string %s;", c_storage(p->info.sto), p->sym->name);
1584 fprintf(fheader, "\n#endif\n");
1585 }
1586 }
1587 banner(fheader, "Classes and Structs");
1588 fflush(fheader);
1589 if (classtable)
1590 for (p = classtable->list; p; p = p->next)
1591 { if (!is_imported(p->info.typ))
1592 gen_class(fheader, p);
1593 }
1594 banner(fheader, "Typedefs");
1595 fflush(fheader);
1596 if (typetable)
1597 for (p = typetable->list; p; p = p->next)
1598 { if (!is_primitive_or_string(p->info.typ) && !is_external(p->info.typ) && !is_XML(p->info.typ) && !is_transient(p->info.typ) && !has_ns_t(p->info.typ) && !is_imported(p->info.typ) && !is_template(p->info.typ))
1599 { sprintf(errbuf, "typedef '%s' is not namespace qualified: schema definition for '%s' in WSDL file output may be invalid", p->sym->name, p->sym->name);
1600 semwarn(errbuf);
1601 }
1602 if (p->info.typ->type == Tclass && is_eq(p->info.typ->sym->name, "xsd__QName") && !is_external(p->info.typ) && !is_imported(p->info.typ))
1603 continue;
1604 if (!is_external(p->info.typ) && !is_imported(p->info.typ))
1605 { fprintf(fheader, "\n#ifndef %s", soap_type(p->info.typ));
1606 fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num);
1607 fprintf(fheader,"\n%s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name));
1608 fprintf(fheader, "\n#endif\n");
1609 }
1610 }
1611 banner(fheader, "Externals");
1612 fflush(fheader);
1613 if (t)
1614 for (p = t->list; p; p = p->next)
1615 if (p->info.typ->type != Tfun || p->info.sto & Sextern)
1616 { fprintf(fheader,"\n\nextern %s", c_storage(p->info.sto));
1617 fprintf(fheader,"%s;", c_type_id(p->info.typ, p->sym->name));
1618 }
1619 fflush(fheader);
1620 }
1621
1622 void
1623 get_namespace_prefixes(void)
1624 { Symbol *p, *q;
1625 int i, n;
1626 char *s, buf[256];
1627 if (nslist)
1628 return;
1629 for (p = symlist; p; p = p->next)
1630 { if (*p->name != '~')
1631 { s = p->name;
1632 while (*s == '_')
1633 s++;
1634 n = (int)(strlen(s) - 2);
1635 for (i = 1; i < n; i++)
1636 { if (s[i] == ':'
1637 || (s[i-1] != '_' && s[i] == '_' && s[i+1] == '_' && s[i+2] && s[i+2] != '_')
1638 || (s[i-1] != '_' && (!strncmp(s+i, "___DOT", 6)
1639 || !strncmp(s+i, "___USCORE", 9)
1640 || (!strncmp(s+i, "___x", 4) && isxdigit(s[i+4]) && isxdigit(s[i+5]) && isxdigit(s[i+6]) && isxdigit(s[i+7])))))
1641 { if (s[i+1] == ':')
1642 { i++;
1643 continue;
1644 }
1645 strncpy(buf, s, i);
1646 buf[i] = '\0';
1647 if (!strcmp(buf, "SOAP_ENV") || !strcmp(buf, "SOAP_ENC") || !strcmp(buf, "xsd") || !strcmp(buf, "xsi") || !strcmp(buf, "xml") || !strcmp(buf, "std") || !strncmp(buf, "soap_", 5))
1648 goto nsnext;
1649 for (q = nslist; q; q = q->next)
1650 if (!strcmp(q->name, buf))
1651 goto nsnext;
1652 q = (Symbol*)emalloc(sizeof(Symbol));
1653 q->name = (char*)emalloc(i+1);
1654 strcpy(q->name, buf);
1655 q->name[i] = '\0';
1656 q->next = nslist;
1657 nslist = q;
1658 break;
1659 }
1660 }
1661 }
1662 nsnext:
1663 ;
1664 }
1665 q = (Symbol*)emalloc(sizeof(Symbol));
1666 q->name = "xsd";
1667 q->next = nslist;
1668 nslist = q;
1669 q = (Symbol*)emalloc(sizeof(Symbol));
1670 q->name = "xsi";
1671 q->next = nslist;
1672 nslist = q;
1673 q = (Symbol*)emalloc(sizeof(Symbol));
1674 q->name = "SOAP-ENC";
1675 q->next = nslist;
1676 nslist = q;
1677 q = (Symbol*)emalloc(sizeof(Symbol));
1678 q->name = "SOAP-ENV";
1679 q->next = nslist;
1680 nslist = q;
1681 }
1682
1683 void
1684 generate_schema(Table *t)
1685 { Entry *p;
1686 Symbol *ns;
1687 char *name = NULL;
1688 char *URL = NULL;
1689 char *executable = NULL;
1690 char *URI = NULL;
1691 char *style = NULL;
1692 char *encoding = NULL;
1693 char *protocol = NULL;
1694 char *import = NULL;
1695 Service *sp = NULL;
1696 char buf[1024];
1697 FILE *fd;
1698 int flag = 0;
1699 get_namespace_prefixes();
1700 for (ns = nslist; ns; ns = ns->next)
1701 { if (!strcmp(ns->name, "SOAP-ENV") || !strcmp(ns->name, "SOAP-ENC") || !strcmp(ns->name, "xsi") || !strcmp(ns->name, "xsd"))
1702 continue;
1703 name = NULL;
1704 URL = NULL;
1705 executable = NULL;
1706 URI = NULL;
1707 style = NULL;
1708 encoding = NULL;
1709 import = NULL;
1710 for (sp = services; sp; sp = sp->next)
1711 { if (!tagcmp(sp->ns, ns->name))
1712 { name = ns_cname(sp->name, NULL);
1713 URL = sp->URL;
1714 executable = sp->executable;
1715 URI = sp->URI;
1716 style = sp->style;
1717 encoding = sp->encoding;
1718 protocol = sp->protocol;
1719 import = sp->import;
1720 break;
1721 }
1722 }
1723 if (!URI)
1724 { URI = emalloc(strlen(tmpURI) + strlen(ns->name) + 6);
1725 sprintf(URI, "%s/%s.xsd", tmpURI, ns_convert(ns->name));
1726 }
1727 if (vflag >= 0 && is_document(style) && encoding && !*encoding)
1728 { semwarn("Cannot use document style with SOAP encoding");
1729 encoding = NULL;
1730 }
1731 if (!name)
1732 name = "Service";
1733 if (!URL)
1734 URL = "http://localhost:80";
1735 if (!import)
1736 flag = 1;
1737 if (t)
1738 { for (p = t->list; p; p = p->next)
1739 { if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns->name, p->sym->name))
1740 { if (name)
1741 fprintf(fmsg, "Using %s service name: %s\n", ns->name, name);
1742 if (protocol)
1743 fprintf(fmsg, "Using %s service protocol: %s\n", ns->name, protocol);
1744 if (style && vflag >= 0)
1745 fprintf(fmsg, "Using %s service style: %s\n", ns->name, style);
1746 else if (!eflag && vflag >= 0)
1747 fprintf(fmsg, "Using %s service style: document\n", ns->name);
1748 if (encoding && *encoding)
1749 fprintf(fmsg, "Using %s service encoding: %s\n", ns->name, encoding);
1750 else if (encoding && !*encoding && vflag >= 0)
1751 fprintf(fmsg, "Using %s service encoding: encoded\n", ns->name);
1752 else if (!eflag && vflag >= 0)
1753 fprintf(fmsg, "Using %s service encoding: literal\n", ns->name);
1754 if (URL)
1755 fprintf(fmsg, "Using %s service location: %s\n", ns->name, URL);
1756 if (executable)
1757 fprintf(fmsg, "Using %s service executable: %s\n", ns->name, executable);
1758 if (import)
1759 fprintf(fmsg, "Using %s schema import: %s\n", ns->name, import);
1760 else if (URI)
1761 fprintf(fmsg, "Using %s schema namespace: %s\n", ns->name, URI);
1762 if (sp && sp->name)
1763 sprintf(buf, "%s%s.wsdl", dirpath, ns_cname(name, NULL));
1764 else
1765 sprintf(buf, "%s%s.wsdl", dirpath, ns_cname(ns->name, NULL));
1766 if (!wflag && !import)
1767 { fprintf(fmsg, "Saving %s Web Service description\n", buf);
1768 fd = fopen(buf, "w");
1769 if (!fd)
1770 execerror("Cannot write WSDL file");
1771 gen_wsdl(fd, t, ns->name, name, URL, executable, URI, style, encoding, protocol);
1772 fclose(fd);
1773 }
1774 if (!cflag)
1775 { if (iflag || jflag)
1776 { char *sname;
1777 if (sp && sp->name)
1778 sname = sp->name;
1779 else
1780 sname = "";
1781 if (!Sflag)
1782 { char *name1 = ns_cname(sname, "Proxy");
1783 sprintf(buf, "%s%s%s.h", dirpath, prefix, name1);
1784 fprintf(fmsg, "Saving %s client proxy class\n", buf);
1785 fd = fopen(buf, "w");
1786 if (!fd)
1787 execerror("Cannot write proxy class file");
1788 sprintf(buf, "%s%s.h", prefix, name1);
1789 copyrightnote(fd, buf);
1790 gen_proxy_header(fd, t, ns, name1, URL, executable, URI, encoding);
1791 fclose(fd);
1792 sprintf(buf, "%s%s%s.cpp", dirpath, prefix, name1);
1793 fprintf(fmsg, "Saving %s client proxy class\n", buf);
1794 fd = fopen(buf, "w");
1795 if (!fd)
1796 execerror("Cannot write proxy class file");
1797 sprintf(buf, "%s%s.cpp", prefix, name1);
1798 copyrightnote(fd, buf);
1799 gen_proxy_code(fd, t, ns, name1, URL, executable, URI, encoding);
1800 fclose(fd);
1801 }
1802 if (!Cflag)
1803 { char *name1 = ns_cname(sname, "Service");
1804 sprintf(buf, "%s%s%s.h", dirpath, prefix, name1);
1805 fprintf(fmsg, "Saving %s service class\n", buf);
1806 fd = fopen(buf, "w");
1807 if (!fd)
1808 execerror("Cannot write service class file");
1809 sprintf(buf, "%s%s.h", prefix, name1);
1810 copyrightnote(fd, buf);
1811 gen_object_header(fd, t, ns, name1, URL, executable, URI, encoding);
1812 fclose(fd);
1813 sprintf(buf, "%s%s%s.cpp", dirpath, prefix, name1);
1814 fprintf(fmsg, "Saving %s service class\n", buf);
1815 fd = fopen(buf, "w");
1816 if (!fd)
1817 execerror("Cannot write service class file");
1818 sprintf(buf, "%s%s.cpp", prefix, name1);
1819 copyrightnote(fd, buf);
1820 gen_object_code(fd, t, ns, name1, URL, executable, URI, encoding);
1821 fclose(fd);
1822 }
1823 }
1824 else if (zflag == 1)
1825 { if (!Sflag && sp && sp->name)
1826 { sprintf(buf, "%s%s%s.h", dirpath, prefix, ns_cname(name, "Proxy"));
1827 fprintf(fmsg, "Saving %s simple client proxy (deprecated)\n", buf);
1828 fd = fopen(buf, "w");
1829 if (!fd)
1830 execerror("Cannot write proxy file");
1831 sprintf(buf, "%s%s.h", prefix, ns_cname(name, "Proxy"));
1832 copyrightnote(fd, buf);
1833 gen_proxy(fd, t, ns, name, URL, executable, URI, encoding);
1834 fclose(fd);
1835 }
1836 else if (!Sflag)
1837 { sprintf(buf, "%s%s.h", dirpath, ns_cname(prefix, "Proxy"));
1838 fprintf(fmsg, "Saving %s simple client proxy (deprecated)\n", buf);
1839 fd = fopen(buf, "w");
1840 if (!fd)
1841 execerror("Cannot write proxy file");
1842 sprintf(buf, "%s.h", ns_cname(prefix, "Proxy"));
1843 copyrightnote(fd, buf);
1844 gen_proxy(fd, t, ns, "Service", URL, executable, URI, encoding);
1845 fclose(fd);
1846 }
1847 if (!Cflag && sp && sp->name)
1848 { sprintf(buf, "%s%s%s.h", dirpath, prefix, ns_cname(name, "Object"));
1849 fprintf(fmsg, "Saving %s simple server object (deprecated)\n", buf);
1850 fd = fopen(buf, "w");
1851 if (!fd)
1852 execerror("Cannot write server object file");
1853 sprintf(buf, "%s%s.h", prefix, ns_cname(name, "Object"));
1854 copyrightnote(fd, buf);
1855 gen_object(fd, t, ns, name, URL, executable, URI, encoding);
1856 fclose(fd);
1857 }
1858 else if (!Cflag)
1859 { sprintf(buf, "%s%s.h", dirpath, ns_cname(prefix, "Object"));
1860 fprintf(fmsg, "Saving %s simple server object (deprecated)\n", buf);
1861 fd = fopen(buf, "w");
1862 if (!fd)
1863 execerror("Cannot write server object file");
1864 sprintf(buf, "%s.h", ns_cname(prefix, "Object"));
1865 copyrightnote(fd, buf);
1866 gen_object(fd, t, ns, "Service", URL, executable, URI, encoding);
1867 fclose(fd);
1868 }
1869 }
1870 }
1871 if (!xflag)
1872 { strcpy(buf, dirpath);
1873 if (sp && sp->name)
1874 strcat(buf, ns_fname(name));
1875 else
1876 strcat(buf, ns_fname(ns->name));
1877 strcat(buf, ".");
1878 gen_data(buf, t, ns->name, name, URL, executable, URI, encoding);
1879 }
1880 break;
1881 }
1882 }
1883 if (sp && sp->name)
1884 { has_nsmap = 1;
1885 if (nflag)
1886 sprintf(buf, "%s%s.nsmap", dirpath, prefix);
1887 else
1888 sprintf(buf, "%s%s.nsmap", dirpath, ns_cname(name, NULL));
1889 fprintf(fmsg, "Saving %s namespace mapping table\n", buf);
1890 fd = fopen(buf, "w");
1891 if (!fd)
1892 execerror("Cannot write nsmap file");
1893 fprintf(fd, "\n#include \"%sH.h\"", prefix);
1894 if (nflag)
1895 fprintf(fd, "\nSOAP_NMAC struct Namespace %s_namespaces[] =\n", prefix);
1896 else
1897 fprintf(fd, "\nSOAP_NMAC struct Namespace namespaces[] =\n");
1898 gen_nsmap(fd, ns, URI);
1899 fclose(fd);
1900
1901 if (Tflag && !Cflag)
1902 { Entry *method;
1903 char soapTester[1024];
1904 char pathsoapTester[1024];
1905 char *name1 = NULL;
1906 Tflag = 0;
1907 strcpy(soapTester, prefix);
1908 strcat(soapTester, "Tester");
1909 if (cflag)
1910 strcat(soapTester, ".c");
1911 else
1912 strcat(soapTester, ".cpp");
1913 strcpy(pathsoapTester, dirpath);
1914 strcat(pathsoapTester, soapTester);
1915 fprintf(fmsg, "Saving %s server auto-test code\n", pathsoapTester);
1916 fd = fopen(pathsoapTester,"w");
1917 if (!fd)
1918 execerror("Cannot write to file");
1919 copyrightnote(fd, soapTester);
1920 fprintf(fd, "\n/*\n Stand-alone server auto-test code:\n Takes request from standard input or over TCP/IP socket and returns\nresponse to standard output or socket\n\n Compile:\n cc soapTester.c soapServer.c soapC.c stdsoap2.c\n\n Command line usage with redirect over stdin/out:\n > ./a.out < SomeTest.req.xml\n > ./a.out 12288 < SomeTest.req.xml\n Note: 12288 = SOAP_XML_INDENT | SOAP_XML_STRICT (see codes in stdsoap2.h)\n Command line usage to start server at port 8080:\n > a.out 12288 8080\n*/\n\n#include \"");
1921 if (iflag || jflag)
1922 { char *sname;
1923 if (sp && sp->name)
1924 sname = sp->name;
1925 else
1926 sname = "";
1927 name1 = ns_cname(sname, "Service");
1928 fprintf(fd, "%s%s%s.h\"\n\n#ifndef SOAP_DEFMAIN\n# define SOAP_DEFMAIN main\t/* redefine to use your own main() */\n#endif\n\nint SOAP_DEFMAIN(int argc, char **argv)\n{\n\t%s service(argc > 1 ? atoi(argv[1]) : 0);\n\tif (argc <= 2)\n\t\treturn service.serve();\n\treturn service.run(atoi(argv[2]));\n}\n", dirpath, prefix, name1, name1);
1929 }
1930 else
1931 fprintf(fd, "%s%s.nsmap\"\n\n#ifndef SOAP_DEFMAIN\n# define SOAP_DEFMAIN main\t/* redefine to use your own main() */\n#endif\n\nint SOAP_DEFMAIN(int argc, char **argv)\n{\n\tstruct soap *soap = soap_new1(argc > 1 ? atoi(argv[1]) : 0);\n\tif (argc <= 2)\n\t\treturn %s_serve(soap);\n\tif (soap_valid_socket(soap_bind(soap, NULL, atoi(argv[2]), 100)))\n\t\twhile (soap_valid_socket(soap_accept(soap)))\n\t\t{\t%s_serve(soap);\n\t\t\tsoap_destroy(soap);\n\t\t\tsoap_end(soap);\n\t\t}\n\tsoap_free(soap);\n\treturn 0;\n}\n", dirpath, nflag?prefix:ns_cname(name, NULL), nflag?prefix:"soap", nflag?prefix:"soap");
1932 for (method = t->list; method; method = method->next)
1933 { if (method->info.typ->type == Tfun && !(method->info.sto & Sextern))
1934 { Entry *p, *q = entry(t, method->sym);
1935 Table *r;
1936 if (q)
1937 p = (Entry*)q->info.typ->ref;
1938 else
1939 { fprintf(stderr, "Internal error: no table entry\n");
1940 return;
1941 }
1942 q = entry(classtable, method->sym);
1943 r = (Table*)q->info.typ->ref;
1944 if (iflag || jflag)
1945 fprintf(fd, "\n\n/** Auto-test server operation %s */\nint %s::%s(", method->sym->name, name1, ns_cname(method->sym->name, NULL));
1946 else
1947 fprintf(fd, "\n\n/** Auto-test server operation %s */\nint %s(struct soap *soap", method->sym->name, ident(method->sym->name));
1948 gen_params(fd, r, p, !iflag && !jflag);
1949 /* single param to single param echo */
1950 if (p && r && r->list && r->list->info.typ == p->info.typ)
1951 fprintf(fd, "\n{\t/* Echo request-response parameter */\n\t*%s = *%s;\n\treturn SOAP_OK;\n}\n", ident(p->sym->name), ident(r->list->sym->name));
1952 else if (p && r && r->list && p->info.typ->type == Tpointer && r->list->info.typ == (Tnode*)p->info.typ->ref)
1953 fprintf(fd, "\n{\t/* Echo request-response parameter */\n\t*%s = %s;\n\treturn SOAP_OK;\n}\n", ident(p->sym->name), ident(r->list->sym->name));
1954 else if (p && r && r->list && p->info.typ->type == Treference && r->list->info.typ == (Tnode*)p->info.typ->ref)
1955 fprintf(fd, "\n{\t/* Echo request-response parameter */\n\t%s = %s;\n\treturn SOAP_OK;\n}\n", ident(p->sym->name), ident(r->list->sym->name));
1956 else if (p && r && r->list && p->info.typ->type == Treference && r->list->info.typ->type == Tpointer && r->list->info.typ->ref == (Tnode*)p->info.typ->ref)
1957 fprintf(fd, "\n{\t/* Echo request-response parameter */\n\t%s = *%s;\n\treturn SOAP_OK;\n}\n", ident(p->sym->name), ident(r->list->sym->name));
1958 /* params to wrapped params echo */
1959 else
1960 { fprintf(fd, "\n{\t");
1961 if (r && p && p->info.typ->ref && ((Tnode*)p->info.typ->ref)->ref && (((Tnode*)p->info.typ->ref)->type == Tstruct || ((Tnode*)p->info.typ->ref)->type == Tclass))
1962 { const char *s, *a;
1963 int d = 1;
1964 s = ident(p->sym->name);
1965 if (p->info.typ->type == Treference)
1966 a = ".";
1967 else
1968 a = "->";
1969 for (p = ((Table*)((Tnode*)p->info.typ->ref)->ref)->list, q = r->list; p && q; p = p->next, q = q->next)
1970 { if (p->info.typ == q->info.typ)
1971 fprintf(fd, "\n\t%s%s%s = %s;", s, a, ident(p->sym->name), ident(q->sym->name));
1972 else if (q->info.typ->type == Tpointer && p->info.typ == (Tnode*)q->info.typ->ref)
1973 fprintf(fd, "\n\t%s%s%s = *%s;", s, a, ident(p->sym->name), ident(q->sym->name));
1974 else
1975 d = 0;
1976 }
1977 if (!d)
1978 fprintf(fd, "\n\t/* Return incomplete response with default data values */");
1979 }
1980 fprintf(fd, "\n\treturn SOAP_OK;\n}\n");
1981 }
1982 fflush(fd);
1983 }
1984 }
1985 fclose(fd);
1986 }
1987 }
1988 }
1989 if (!wflag && !import)
1990 { sprintf(buf, "%s%s.xsd", dirpath, ns_cname(ns->name, NULL));
1991 fprintf(fmsg, "Saving %s XML schema\n", buf);
1992 fd = fopen(buf, "w");
1993 if (!fd)
1994 execerror("Cannot write schema file");
1995 fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1996 if (t)
1997 for (p = t->list; p; p = p->next)
1998 if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns->name, p->sym->name))
1999 { gen_schema(fd, t, ns->name, ns->name, 0, 1, URL, URI, style, encoding);
2000 break;
2001 }
2002 if (!t || !p)
2003 gen_schema(fd, t, ns->name, ns->name, 0, 0, URL, URI, style, encoding);
2004 fclose(fd);
2005 }
2006 }
2007 if (!has_nsmap && flag)
2008 { if (Tflag && !Cflag && !iflag && !jflag)
2009 fprintf(fmsg, "Warning: cannot save soapTester, need directive //gsoap service name\n");
2010 for (ns = nslist; ns; ns = ns->next)
2011 if (strcmp(ns->name, "SOAP-ENV") && strcmp(ns->name, "SOAP-ENC") && strcmp(ns->name, "xsi") && strcmp(ns->name, "xsd"))
2012 break;
2013 if (nflag)
2014 sprintf(buf, "%s%s.nsmap", dirpath, prefix);
2015 else if (ns && ns->name)
2016 sprintf(buf, "%s%s.nsmap", dirpath, ns_cname(ns->name, NULL));
2017 else
2018 sprintf(buf, "%ssoap.nsmap", dirpath);
2019 fprintf(fmsg, "Saving %s namespace mapping table\n", buf);
2020 fd = fopen(buf, "w");
2021 if (!fd)
2022 execerror("Cannot write nsmap file");
2023 fprintf(fd, "\n#include \"%sH.h\"", prefix);
2024 if (nflag)
2025 fprintf(fd, "\nSOAP_NMAC struct Namespace %s_namespaces[] =\n", prefix);
2026 else
2027 fprintf(fd, "\nSOAP_NMAC struct Namespace namespaces[] =\n");
2028 gen_nsmap(fd, ns, URI);
2029 fclose(fd);
2030 }
2031 }
2032
2033 int
2034 chkhdr(char *part)
2035 { Entry *p;
2036 p = entry(classtable, lookup("SOAP_ENV__Header"));
2037 if (p)
2038 for (p = ((Table*)p->info.typ->ref)->list; p; p = p->next)
2039 if (has_ns_eq(NULL, p->sym->name) && (!strcmp(part, p->sym->name) || is_eq_nons(part, p->sym->name)))
2040 return 1;
2041 sprintf(errbuf, "Cannot define method-header-part in WSDL: SOAP_ENV__Header \"%s\" member field is not qualified", part);
2042 semwarn(errbuf);
2043 return 0;
2044 }
2045
2046 void
2047 gen_wsdl(FILE *fd, Table *t, char *ns, char *name, char *URL, char *executable, char *URI, char *style, char *encoding, char *protocol)
2048 { Entry *p, *q, *r;
2049 Symbol *s;
2050 Service *sp, *sp2;
2051 Method *m;
2052 const char *mimein = NULL, *mimeout = NULL;
2053 int prot, mask = 0x0; /* 0x1 = SOAP, 0x2 = GET, 0x4 = PUT, 0x8 = POST */
2054 char *action, *comment, *method_style = NULL, *method_encoding = NULL, *method_response_encoding = NULL;
2055 char *portname;
2056 char *binding;
2057 fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
2058 for (sp = services; sp; sp = sp->next)
2059 if (!tagcmp(sp->ns, ns))
2060 break;
2061 if (sp && sp->definitions)
2062 fprintf(fd, "<definitions name=\"%s\"\n", sp->definitions);
2063 else
2064 fprintf(fd, "<definitions name=\"%s\"\n", name);
2065 if (sp && sp->WSDL)
2066 fprintf(fd, " targetNamespace=\"%s\"\n xmlns:tns=\"%s\"", sp->WSDL, sp->WSDL);
2067 else
2068 fprintf(fd, " targetNamespace=\"%s/%s.wsdl\"\n xmlns:tns=\"%s/%s.wsdl\"", URI, name, URI, name);
2069 if (sp && sp->binding)
2070 binding = ns_cname(sp->binding, NULL);
2071 else
2072 binding = name;
2073 if (sp && sp->portname)
2074 portname = ns_cname(sp->portname, NULL);
2075 else
2076 portname = name;
2077 for (s = nslist; s; s = s->next)
2078 { for (sp2 = services; sp2; sp2 = sp2->next)
2079 if (!tagcmp(sp2->ns, s->name) && sp2->URI)
2080 break;
2081 if (sp2)
2082 fprintf(fd, "\n xmlns:%s=\"%s\"", ns_convert(s->name), sp2->URI);
2083 else if (!strcmp(s->name, "SOAP-ENV"))
2084 fprintf(fd, "\n xmlns:SOAP-ENV=\"%s\"", envURI);
2085 else if (!strcmp(s->name, "SOAP-ENC"))
2086 fprintf(fd, "\n xmlns:SOAP-ENC=\"%s\"", encURI);
2087 else if (!strcmp(s->name, "xsi"))
2088 fprintf(fd, "\n xmlns:xsi=\"%s\"", xsiURI);
2089 else if (!strcmp(s->name, "xsd"))
2090 fprintf(fd, "\n xmlns:xsd=\"%s\"", xsdURI);
2091 else
2092 fprintf(fd, "\n xmlns:%s=\"%s/%s.xsd\"", ns_convert(s->name), tmpURI, ns_convert(s->name));
2093 }
2094 if (is_soap12(encoding))
2095 fprintf(fd, "\n xmlns:SOAP=\"http://schemas.xmlsoap.org/wsdl/soap12/\"");
2096 else
2097 fprintf(fd, "\n xmlns:SOAP=\"http://schemas.xmlsoap.org/wsdl/soap/\"");
2098 fprintf(fd, "\n xmlns:HTTP=\"http://schemas.xmlsoap.org/wsdl/http/\"");
2099 fprintf(fd, "\n xmlns:MIME=\"http://schemas.xmlsoap.org/wsdl/mime/\"");
2100 fprintf(fd, "\n xmlns:DIME=\"http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/\"");
2101 fprintf(fd, "\n xmlns:WSDL=\"http://schemas.xmlsoap.org/wsdl/\"");
2102 fprintf(fd, "\n xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n\n");
2103 fprintf(fd, "<types>\n\n");
2104 for (s = nslist; s; s = s->next)
2105 gen_schema(fd, t, ns, s->name, !strcmp(s->name, ns), 1, URL, URI, style, encoding);
2106 fprintf(fd, "</types>\n\n");
2107 fflush(fd);
2108 if (t)
2109 { for (p = t->list; p; p = p->next)
2110 { if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns, p->sym->name))
2111 { mimein = NULL;
2112 mimeout = NULL;
2113 comment = NULL;
2114 method_style = style;
2115 method_encoding = encoding;
2116 method_response_encoding = NULL;
2117 if (sp)
2118 { for (m = sp->list; m; m = m->next)
2119 { if (is_eq_nons(m->name, p->sym->name))
2120 { if (m->mess&MIMEIN)
2121 mimein = m->part;
2122 if (m->mess&MIMEOUT)
2123 mimeout = m->part;
2124 if (m->mess == ENCODING)
2125 method_encoding = m->part;
2126 else if (m->mess == RESPONSE_ENCODING)
2127 method_response_encoding = m->part;
2128 else if (m->mess == STYLE)
2129 method_style = m->part;
2130 else if (m->mess == COMMENT)
2131 comment = m->part;
2132 }
2133 }
2134 }
2135 if (!method_response_encoding)
2136 method_response_encoding = method_encoding;
2137 if (get_response(p->info.typ))
2138 fprintf(fd, "<message name=\"%sRequest\">\n", ns_remove(p->sym->name));
2139 else
2140 fprintf(fd, "<message name=\"%s\">\n", ns_remove(p->sym->name));
2141 fflush(fd);
2142 if (is_document(method_style))
2143 { if (is_invisible(p->sym->name))
2144 { q = entry(classtable, p->sym);
2145 if (q)
2146 { q = ((Table*)q->info.typ->ref)->list;
2147 if (q)
2148 { if (is_invisible(q->sym->name))
2149 { r = entry(classtable, q->sym);
2150 if (r)
2151 { r = ((Table*)r->info.typ->ref)->list;
2152 if (r)
2153 { fprintf(fd, " <part name=\"Body\" element=\"%s\"", ns_add(r, ns));
2154 if (gen_member_documentation(fd, p->sym, r, ns))
2155 fprintf(fd, " </part>\n");
2156 }
2157 }
2158 }
2159 else
2160 { fprintf(fd, " <part name=\"Body\" element=\"%s\"", ns_add(q, ns));
2161 if (gen_member_documentation(fd, p->sym, q, ns))
2162 fprintf(fd, " </part>\n");
2163 }
2164 }
2165 }
2166 }
2167 else
2168 { fprintf(fd, " <part name=\"Body\" element=\"%s\"", ns_add(p, ns));
2169 if (gen_member_documentation(fd, p->sym, p, ns))
2170 fprintf(fd, " </part>\n");
2171 }
2172 }
2173 else
2174 { q = entry(classtable, p->sym);
2175 if (q)
2176 { for (q = ((Table*)q->info.typ->ref)->list; q; q = q->next)
2177 { if (!is_transient(q->info.typ) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun && !is_repetition(q) && !is_anytype(q))
2178 { if (is_literal(method_encoding))
2179 { fprintf(fd, " <part name=\"%s\" element=\"%s\"", ns_remove(q->sym->name), ns_add(q, ns));
2180 if (gen_member_documentation(fd, p->sym, q, ns))
2181 fprintf(fd, " </part>\n");
2182 }
2183 else if (is_XML(q->info.typ) || is_stdXML(q->info.typ))
2184 fprintf(fd, " <part name=\"Body\" type=\"xsd:anyType\"/>\n");
2185 else
2186 { fprintf(fd, " <part name=\"%s\" type=\"%s\"", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns));
2187 if (gen_member_documentation(fd, p->sym, q, ns))
2188 fprintf(fd, " </part>\n");
2189 }
2190 }
2191 }
2192 }
2193 }
2194 if (mimein)
2195 fprintf(fd, " <part name=\"Attachments\" type=\"xsd:base64Binary\"/>\n");
2196 fprintf(fd, "</message>\n\n");
2197 fflush(fd);
2198 q = (Entry*)p->info.typ->ref;
2199 for (r = t->list; r; r = r->next)
2200 if (r != p && r->info.typ->type == Tfun && !(r->info.sto & Sextern) && q == (Entry*)r->info.typ->ref)
2201 q = NULL;
2202 if (q && is_transient(q->info.typ))
2203 ;
2204 else if (q && !is_response(q->info.typ))
2205 { fprintf(fd, "<message name=\"%sResponse\">\n", ns_remove(p->sym->name));
2206 if (is_document(method_style))
2207 fprintf(fd, " <part name=\"Body\" element=\"%sResponse\"/>\n", ns_add(p, ns));
2208 else if (is_literal(method_response_encoding))
2209 { fprintf(fd, " <part name=\"%s\" element=\"%s\"", ns_remove(q->sym->name), ns_add(q, ns));
2210 if (gen_member_documentation(fd, p->sym, q, ns))
2211 fprintf(fd, " </part>\n");
2212 }
2213 else if (is_XML((Tnode*)q->info.typ->ref) || is_stdXML((Tnode*)q->info.typ->ref))
2214 fprintf(fd, " <part name=\"Body\" type=\"xsd:anyType\"/>\n");
2215 else
2216 { fprintf(fd, " <part name=\"%s\" type=\"%s\"", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns));
2217 if (gen_member_documentation(fd, p->sym, q, ns))
2218 fprintf(fd, " </part>\n");
2219 }
2220 if (mimeout)
2221 fprintf(fd, " <part name=\"Attachments\" type=\"xsd:base64Binary\"/>\n");
2222 fprintf(fd, "</message>\n\n");
2223 }
2224 else if (q && q->info.typ->wsdl == False)
2225 { q->info.typ->wsdl = True;
2226 fprintf(fd, "<message name=\"%s\">\n", ns_remove(((Tnode*)q->info.typ->ref)->id->name));
2227 if (is_document(method_style))
2228 { if (has_ns_eq(NULL, ((Entry*)p->info.typ->ref)->sym->name))
2229 fprintf(fd, " <part name=\"Body\" element=\"%s\"/>\n", ns_convert(((Entry*)p->info.typ->ref)->sym->name));
2230 else if (is_invisible(((Tnode*)q->info.typ->ref)->id->name))
2231 { r = ((Table*)((Tnode*)q->info.typ->ref)->ref)->list;
2232 if (r)
2233 { fprintf(fd, " <part name=\"Body\" element=\"%s\"", ns_add(r, ns));
2234 if (gen_member_documentation(fd, p->sym, r, ns))
2235 fprintf(fd, " </part>\n");
2236 }
2237 }
2238 else
2239 { fprintf(fd, " <part name=\"Body\" element=\"%s\"", ns_convert(((Tnode*)q->info.typ->ref)->id->name));
2240 if (gen_member_documentation(fd, p->sym, q, ns))
2241 fprintf(fd, " </part>\n");
2242 }
2243 }
2244 else
2245 { if (((Tnode*)q->info.typ->ref)->ref)
2246 { for (q = ((Table*)((Tnode*)q->info.typ->ref)->ref)->list; q; q = q->next)
2247 { if (!is_transient(q->info.typ) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun && !is_repetition(q) && !is_anytype(q))
2248 { if (is_literal(method_response_encoding))
2249 { fprintf(fd, " <part name=\"%s\" element=\"%s\"", ns_remove(q->sym->name), ns_add(q, ns));
2250 if (gen_member_documentation(fd, p->sym, q, ns))
2251 fprintf(fd, " </part>\n");
2252 }
2253 else if (is_XML(q->info.typ) || is_stdXML(q->info.typ))
2254 fprintf(fd, " <part name=\"Body\" type=\"xsd:anyType\"/>\n");
2255 else
2256 { fprintf(fd, " <part name=\"%s\" type=\"%s\"", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns));
2257 if (gen_member_documentation(fd, p->sym, q, ns))
2258 fprintf(fd, " </part>\n");
2259 }
2260 }
2261 }
2262 }
2263 }
2264 if (mimeout)
2265 fprintf(fd, " <part name=\"Attachments\" type=\"xsd:base64Binary\"/>\n");
2266 fprintf(fd, "</message>\n\n");
2267 }
2268 fflush(fd);
2269 }
2270 }
2271 if (custom_header)
2272 { Table *r;
2273 fprintf(fd, "<message name=\"%sHeader\">\n", name);
2274 r = (Table*)entry(classtable, lookup("SOAP_ENV__Header"))->info.typ->ref;
2275 if (r)
2276 { for (q = r->list; q; q = q->next)
2277 { if (!is_transient(q->info.typ) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun && !is_repetition(q) && !is_anytype(q))
2278 fprintf(fd, " <part name=\"%s\" element=\"%s\"/>\n", ns_remove(q->sym->name), ns_add(q, ns));
2279 }
2280 }
2281 fprintf(fd, "</message>\n\n");
2282 }
2283 if (custom_fault)
2284 { Table *r;
2285 fprintf(fd, "<message name=\"%sFault\">\n", name);
2286 r = (Table*)entry(classtable, lookup("SOAP_ENV__Detail"))->info.typ->ref;
2287 if (r)
2288 for (q = r->list; q; q = q->next)
2289 if (!is_transient(q->info.typ) && !is_repetition(q) && !is_anytype(q) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun && has_ns_eq(NULL, q->sym->name))
2290 { fprintf(fd, " <part name=\"%s\" element=\"%s\"", ns_remove(q->sym->name), ns_add(q, ns));
2291 if (gen_member_documentation(fd, q->sym, q, ns))
2292 fprintf(fd, " </part>\n");
2293 }
2294 fprintf(fd, "</message>\n\n");
2295 }
2296 if (sp)
2297 { for (m = sp->list; m; m = m->next)
2298 { if (m->mess&FAULT && m->part)
2299 { Method *m2;
2300 int flag = 0;
2301 for (m2 = sp->list; m2 && m2 != m; m2 = m2->next)
2302 if (m2->mess&FAULT && !strcmp(m2->part, m->part))
2303 flag = 1;
2304 if (!flag)
2305 { if (typetable)
2306 for (p = typetable->list; p; p = p->next)
2307 if ((m->mess&FAULT) && is_eq(m->part, p->info.typ->sym->name))
2308 break;
2309 if (!p && classtable)
2310 for (p = classtable->list; p; p = p->next)
2311 if ((m->mess&FAULT) && is_eq(m->part, p->info.typ->id->name))
2312 break;
2313 if (p)
2314 { fprintf(fd, "<message name=\"%sFault\">\n", ns_remove(m->part));
2315 fprintf(fd, " <part name=\"Fault\" element=\"%s\"/>\n", ns_convert(m->part));
2316 fprintf(fd, "</message>\n\n");
2317 flag = 0;
2318 if (custom_fault)
2319 { Table *r;
2320 r = (Table*)entry(classtable, lookup("SOAP_ENV__Detail"))->info.typ->ref;
2321 if (r)
2322 for (q = r->list; q; q = q->next)
2323 if (!is_transient(q->info.typ) && !is_repetition(q) && !is_anytype(q) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun && (!strcmp(q->sym->name, m->part) || !strcmp(q->sym->name + 1, m->part)))
2324 { flag = 1;
2325 break;
2326 }
2327 }
2328 if (!flag)
2329 { sprintf(errbuf, "//gsoap %s method-fault %s %s directive does not refer to a member of struct SOAP_ENV__Detail: suggest to define struct SOAP_ENV__Detail with member %s", sp->ns, m->name, m->part, m->part);
2330 semwarn(errbuf);
2331 }
2332 }
2333 else
2334 { sprintf(errbuf, "//gsoap %s method-fault %s %s directive does not refer to struct/class or typedef: should globablly define fault %s as type (typedef or struct/class)", sp->ns, m->name, m->part, m->part);
2335 semwarn(errbuf);
2336 }
2337 }
2338 }
2339 }
2340 }
2341 fflush(fd);
2342 if (sp && sp->porttype)
2343 fprintf(fd, "<portType name=\"%s\">\n", sp->porttype);
2344 else
2345 fprintf(fd, "<portType name=\"%s\">\n", ns_cname(name, "PortType"));
2346 if (protocol)
2347 { if (strncmp(protocol, "SOAP", 4))
2348 { if (strstr(protocol, "GET"))
2349 mask = 0x2;
2350 else if (strstr(protocol, "PUT"))
2351 mask = 0x4;
2352 else /* POST */
2353 mask = 0x8;
2354 }
2355 else
2356 mask = 0x1;
2357 }
2358 for (p = t->list; p; p = p->next)
2359 { if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns, p->sym->name))
2360 { comment = NULL;
2361 if (sp)
2362 { for (m = sp->list; m; m = m->next)
2363 { if (m->mess == COMMENT && is_eq_nons(m->name, p->sym->name))
2364 comment = m->part;
2365 else if (m->mess == PROTOCOL)
2366 { if (strncmp(m->part, "SOAP", 4))
2367 { if (strstr(m->part, "GET"))
2368 mask |= 0x2;
2369 else if (strstr(m->part, "PUT"))
2370 mask |= 0x4;
2371 else /* POST */
2372 mask |= 0x8;
2373 }
2374 else
2375 mask |= 0x1;
2376 }
2377 }
2378 }
2379 if (!mask)
2380 { if (vflag < 0)
2381 mask = 0x8; /* -0 option: use POST */
2382 else
2383 mask = 0x1;
2384 }
2385 fprintf(fd, " <operation name=\"%s\">\n", ns_remove(p->sym->name));
2386 if (comment)
2387 fprintf(fd, " <documentation>%s</documentation>\n", comment);
2388 else
2389 fprintf(fd, " <documentation>Service definition of function %s</documentation>\n", p->sym->name);
2390 if (get_response(p->info.typ))
2391 fprintf(fd, " <input message=\"tns:%sRequest\"/>\n", ns_remove(p->sym->name));
2392 else
2393 fprintf(fd, " <input message=\"tns:%s\"/>\n", ns_remove(p->sym->name));
2394 q = (Entry*)p->info.typ->ref;
2395 if (q && is_transient(q->info.typ))
2396 ;
2397 else if (q && !is_response(q->info.typ))
2398 fprintf(fd, " <output message=\"tns:%sResponse\"/>\n", ns_remove(p->sym->name));
2399 else if (q)
2400 fprintf(fd, " <output message=\"tns:%s\"/>\n", ns_remove(((Tnode*)q->info.typ->ref)->id->name));
2401 if (sp)
2402 for (m = sp->list; m; m = m->next)
2403 if ((m->mess&FAULT) && is_eq_nons(m->name, p->sym->name))
2404 fprintf(fd, " <fault name=\"%s\" message=\"tns:%sFault\"/>\n", ns_remove(m->part), ns_remove(m->part));
2405 fprintf(fd, " </operation>\n");
2406 }
2407 }
2408 fprintf(fd, "</portType>\n\n");
2409 for (prot = 0x1; prot <= 0x8; prot <<= 1)
2410 { if ((prot & mask))
2411 { const char *v = "", *b = "";
2412 switch (prot)
2413 { case 0x1: v = ""; b = "SOAP"; break;
2414 case 0x2: v = "GET"; b = "HTTP"; break;
2415 case 0x4: v = "PUT"; b = "HTTP"; break;
2416 case 0x8: v = "POST"; b = "HTTP"; break;
2417 }
2418 fprintf(fd, "<binding name=\"%s%s\" ", binding, v);
2419 if (prot == 0x1)
2420 { if (is_document(style))
2421 { if (sp && sp->porttype)
2422 fprintf(fd, "type=\"tns:%s\">\n <SOAP:binding style=\"document\"", sp->porttype);
2423 else
2424 fprintf(fd, "type=\"tns:%s\">\n <SOAP:binding style=\"document\"", ns_cname(name, "PortType"));
2425 }
2426 else
2427 { if (sp && sp->porttype)
2428 fprintf(fd, "type=\"tns:%s\">\n <SOAP:binding style=\"rpc\"", sp->porttype);
2429 else
2430 fprintf(fd, "type=\"tns:%s\">\n <SOAP:binding style=\"rpc\"", ns_cname(name, "PortType"));
2431 }
2432 if (sp && sp->transport)
2433 fprintf(fd, " transport=\"%s\"/>\n", sp->transport);
2434 else
2435 fprintf(fd, " transport=\"http://schemas.xmlsoap.org/soap/http\"/>\n");
2436 }
2437 else
2438 { if (sp && sp->porttype)
2439 fprintf(fd, "type=\"tns:%s\">\n <HTTP:binding verb=\"%s\"/>\n", sp->porttype, v);
2440 else
2441 fprintf(fd, "type=\"tns:%s\">\n <HTTP:binding verb=\"%s\"/>\n", ns_cname(name, "PortType"), v);
2442 }
2443 fflush(fd);
2444 for (p = t->list; p; p = p->next)
2445 { if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns, p->sym->name))
2446 { action = "";
2447 mimein = NULL;
2448 mimeout = NULL;
2449 method_style = style;
2450 method_encoding = encoding;
2451 method_response_encoding = NULL;
2452 if (sp)
2453 { int v = 0x1;
2454 if (sp->protocol)
2455 { if (strncmp(sp->protocol, "SOAP", 4))
2456 { if (strstr(sp->protocol, "GET"))
2457 v = 0x2;
2458 else if (strstr(sp->protocol, "PUT"))
2459 v = 0x4;
2460 else /* POST */
2461 v = 0x8;
2462 }
2463 }
2464 for (m = sp->list; m; m = m->next)
2465 { if (is_eq_nons(m->name, p->sym->name))
2466 { if (m->mess&MIMEIN)
2467 mimein = m->part;
2468 if (m->mess&MIMEOUT)
2469 mimeout = m->part;
2470 if (m->mess == ENCODING)
2471 method_encoding = m->part;
2472 else if (m->mess == RESPONSE_ENCODING)
2473 method_response_encoding = m->part;
2474 else if (m->mess == STYLE)
2475 method_style = m->part;
2476 else if (m->mess == ACTION || m->mess == REQUEST_ACTION)
2477 action = m->part;
2478 else if (m->mess == RESPONSE_ACTION)
2479 action = m->part;
2480 else if (m->mess == PROTOCOL)
2481 { if (strncmp(m->part, "SOAP", 4))
2482 { if (strstr(m->part, "GET"))
2483 v = 0x2;
2484 else if (strstr(m->part, "PUT"))
2485 v = 0x4;
2486 else /* POST */
2487 v = 0x8;
2488 }
2489 else
2490 v = 0x1;
2491 }
2492 }
2493 }
2494 if (vflag < 0)
2495 v = 0x8;
2496 if (prot != v)
2497 continue;
2498 }
2499 if (!method_response_encoding)
2500 method_response_encoding = method_encoding;
2501 fprintf(fd, " <operation name=\"%s\">\n", ns_remove(p->sym->name));
2502 if (prot == 0x1)
2503 { if (is_document(style))
2504 { if (is_document(method_style))
2505 { if (is_soap12(encoding) && !*action)
2506 fprintf(fd, " <SOAP:operation/>\n");
2507 else if (*action == '"')
2508 fprintf(fd, " <SOAP:operation soapAction=%s/>\n", action);
2509 else
2510 fprintf(fd, " <SOAP:operation soapAction=\"%s\"/>\n", action);
2511 }
2512 else if (is_soap12(encoding) && !*action)
2513 fprintf(fd, " <SOAP:operation style=\"rpc\"/>\n");
2514 else if (*action == '"')
2515 fprintf(fd, " <SOAP:operation style=\"rpc\" soapAction=%s/>\n", action);
2516 else
2517 fprintf(fd, " <SOAP:operation style=\"rpc\" soapAction=\"%s\"/>\n", action);
2518 }
2519 else
2520 { if (is_document(method_style))
2521 { if (is_soap12(encoding) && !*action)
2522 fprintf(fd, " <SOAP:operation style=\"document\"/>\n");
2523 else if (*action == '"')
2524 fprintf(fd, " <SOAP:operation style=\"document\" soapAction=%s/>\n", action);
2525 else
2526 fprintf(fd, " <SOAP:operation style=\"document\" soapAction=\"%s\"/>\n", action);
2527 }
2528 else if (is_soap12(encoding) && !*action)
2529 fprintf(fd, " <SOAP:operation style=\"rpc\"/>\n");
2530 else if (*action == '"')
2531 fprintf(fd, " <SOAP:operation style=\"rpc\" soapAction=%s/>\n", action);
2532 else
2533 fprintf(fd, " <SOAP:operation style=\"rpc\" soapAction=\"%s\"/>\n", action);
2534 }
2535 }
2536 else
2537 { if (!*action)
2538 fprintf(fd, " <HTTP:operation/>\n");
2539 else if (*action == '"')
2540 fprintf(fd, " <HTTP:operation location=%s/>\n", action);
2541 else
2542 fprintf(fd, " <HTTP:operation location=\"%s\"/>\n", action);
2543 }
2544 fprintf(fd, " <input>\n");
2545 q = entry(classtable, p->sym);
2546 if (prot == 0x1)
2547 { if (mimein)
2548 fprintf(fd, " <MIME:multipartRelated>\n <MIME:part>\n");
2549 if (is_literal(method_encoding) || (q && (q = (((Table*)q->info.typ->ref)->list)) && q && is_XML(q->info.typ)))
2550 { if (is_document(method_style))
2551 fprintf(fd, " <SOAP:body parts=\"Body\" use=\"literal\"/>\n");
2552 else
2553 fprintf(fd, " <SOAP:body parts=\"Body\" use=\"literal\" namespace=\"%s\"/>\n", URI);
2554 }
2555 else
2556 { if (encoding && *encoding)
2557 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, encoding);
2558 else if (method_encoding && *method_encoding)
2559 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, method_encoding);
2560 else
2561 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, encURI);
2562 if (!eflag)
2563 { sprintf(errbuf, "operation '%s' is not compliant with WS-I Basic Profile 1.0a, reason: uses SOAP encoding", p->sym->name);
2564 compliancewarn(errbuf);
2565 }
2566 }
2567 if (custom_header)
2568 { m = NULL;
2569 if (sp)
2570 { for (m = sp->list; m; m = m->next)
2571 if (is_eq_nons(m->name, p->sym->name) && (m->mess&HDRIN))
2572 { if (chkhdr(m->part))
2573 fprintf(fd, " <SOAP:header use=\"literal\" message=\"tns:%sHeader\" part=\"%s\"/>\n", name, ns_remove(m->part));
2574 }
2575 }
2576 }
2577 if (mimein)
2578 { if (sp)
2579 { for (m = sp->list; m; m = m->next)
2580 { if (is_eq_nons(m->name, p->sym->name) && (m->mess&MIMEIN))
2581 fprintf(fd, " </MIME:part>\n <MIME:part>\n <MIME:content part=\"Attachments\" type=\"%s\"/>\n", m->part);
2582 }
2583 }
2584 fprintf(fd, " </MIME:part>\n </MIME:multipartRelated>\n");
2585 }
2586 }
2587 else if (prot == 0x2)
2588 fprintf(fd, " <HTTP:urlEncoded/>\n");
2589 else
2590 { if (mimein)
2591 fprintf(fd, " <MIME:content type=\"%s\"/>\n", mimein);
2592 else if (!q || is_document(method_style))
2593 fprintf(fd, " <MIME:mimeXml part=\"Body\"/>\n");
2594 else
2595 fprintf(fd, " <MIME:mimeXml part=\"%s\"/>\n", ns_remove(q->sym->name));
2596 }
2597 fprintf(fd, " </input>\n");
2598
2599 q = (Entry*)p->info.typ->ref;
2600 if (!q || !q->info.typ->ref)
2601 { fprintf(fd, " </operation>\n");
2602 continue;
2603 }
2604 if (prot != 0x4)
2605 { fprintf(fd, " <output>\n");
2606 if (prot == 0x1)
2607 { if (mimeout)
2608 fprintf(fd, " <MIME:multipartRelated>\n <MIME:part>\n");
2609 if (is_literal(method_response_encoding) || is_XML((Tnode*)q->info.typ->ref))
2610 { if (is_document(method_style))
2611 fprintf(fd, " <SOAP:body parts=\"Body\" use=\"literal\"/>\n");
2612 else
2613 fprintf(fd, " <SOAP:body parts=\"Body\" use=\"literal\" namespace=\"%s\"/>\n", URI);
2614 }
2615 else if (encoding && *encoding)
2616 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, encoding);
2617 else if (method_response_encoding && *method_response_encoding)
2618 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, method_response_encoding);
2619 else
2620 fprintf(fd, " <SOAP:body use=\"encoded\" namespace=\"%s\" encodingStyle=\"%s\"/>\n", URI, encURI);
2621 if (custom_header)
2622 { if (sp)
2623 for (m = sp->list; m; m = m->next)
2624 if (is_eq_nons(m->name, p->sym->name) && (m->mess&HDROUT))
2625 { if (chkhdr(m->part))
2626 fprintf(fd, " <SOAP:header use=\"literal\" message=\"tns:%sHeader\" part=\"%s\"/>\n", name, ns_remove(m->part));
2627 }
2628 }
2629 if (mimeout)
2630 { if (sp)
2631 { for (m = sp->list; m; m = m->next)
2632 { if (is_eq_nons(m->name, p->sym->name) && (m->mess&MIMEOUT))
2633 fprintf(fd, " </MIME:part>\n <MIME:part>\n <MIME:content part=\"Attachments\" type=\"%s\"/>\n", m->part);
2634 }
2635 }
2636 fprintf(fd, " </MIME:part>\n </MIME:multipartRelated>\n");
2637 }
2638 }
2639 else
2640 { q = (Entry*)p->info.typ->ref;
2641 if (is_document(method_style))
2642 fprintf(fd, " <MIME:mimeXml part=\"Body\"/>\n");
2643 else if (q && !is_transient(q->info.typ) && !is_response(q->info.typ) && is_literal(method_response_encoding))
2644 fprintf(fd, " <MIME:mimeXml part=\"%s\"/>\n", ns_remove(q->sym->name));
2645 else
2646 fprintf(fd, " <MIME:mimeXml part=\"Body\"/>\n");
2647 }
2648 fprintf(fd, " </output>\n");
2649 }
2650 if (sp)
2651 for (m = sp->list; m; m = m->next)
2652 if ((m->mess&FAULT) && is_eq_nons(m->name, p->sym->name))
2653 fprintf(fd, " <fault name=\"%s\">\n <SOAP:fault name=\"%s\" use=\"literal\"/>\n </fault>\n", ns_remove(m->part), ns_remove(m->part));
2654 fprintf(fd, " </operation>\n");
2655 fflush(fd);
2656 }
2657 }
2658 fprintf(fd, "</binding>\n\n");
2659 }
2660 }
2661 }
2662 fprintf(fd, "<service name=\"%s\">\n", name);
2663 if (sp && sp->documentation)
2664 fprintf(fd, " <documentation>%s</documentation>\n", sp->documentation);
2665 else
2666 fprintf(fd, " <documentation>gSOAP "VERSION" generated service definition</documentation>\n");
2667 if (executable)
2668 fprintf(fd, " <port name=\"%s\" binding=\"tns:%s\">\n <SOAP:address location=\"%s/%s\"/>\n </port>", portname, binding, URL, executable);
2669 for (prot = 0x1; prot <= 0x8; prot <<= 1)
2670 { if ((prot & mask))
2671 { const char *s, *t, *v = "", *b = "";
2672 switch (prot)
2673 { case 0x1: v = ""; b = "SOAP"; break;
2674 case 0x2: v = "GET"; b = "HTTP"; break;
2675 case 0x4: v = "PUT"; b = "HTTP"; break;
2676 case 0x8: v = "POST"; b = "HTTP"; break;
2677 }
2678 fprintf(fd, " <port name=\"%s%s\" binding=\"tns:%s%s\">\n", portname, v, binding, v);
2679 for (s = URL; s; s = t)
2680 { int n;
2681 t = strchr(s, ' ');
2682 if (t)
2683 { n = (int)(t - s);
2684 t++;
2685 }
2686 else
2687 n = (int)strlen(s);
2688 fprintf(fd, " <%s:address location=\"%.*s\"/>\n", b, n, s);
2689 }
2690 fprintf(fd, " </port>\n");
2691 }
2692 }
2693 fprintf(fd, "</service>\n\n</definitions>\n");
2694 }
2695
2696 char *
2697 default_value(Entry *e, const char *a)
2698 { Entry *q;
2699 static char buf[1024];
2700 buf[0] = '\0';
2701 if (e->info.hasval)
2702 switch (e->info.typ->type)
2703 { case Tchar:
2704 case Twchar:
2705 case Tuchar:
2706 case Tshort:
2707 case Tushort:
2708 case Tint:
2709 case Tuint:
2710 case Tlong:
2711 case Tllong:
2712 case Tulong:
2713 case Tullong:
2714 sprintf(buf, " %s=\"" SOAP_LONG_FORMAT "\"", a, e->info.val.i);
2715 break;
2716 case Tfloat:
2717 case Tdouble:
2718 case Tldouble:
2719 sprintf(buf, " %s=\"%g\"", a, e->info.val.r);
2720 break;
2721 case Ttime:
2722 break; /* should get value? */
2723 case Tenum:
2724 for (q = ((Table*)e->info.typ->ref)->list; q; q = q->next)
2725 if (q->info.val.i == e->info.val.i)
2726 { sprintf(buf, " %s=\"%s\"", a, ns_convert(q->sym->name));
2727 break;
2728 }
2729 break;
2730 default:
2731 if (e->info.val.s && strlen(e->info.val.s) < sizeof(buf)-12)
2732 sprintf(buf, " %s=\"%s\"", a, xstring(e->info.val.s));
2733 break;
2734 }
2735 return buf;
2736 }
2737
2738 const char *
2739 nillable(Tnode *typ)
2740 { if (typ->type == Tpointer)
2741 return "true";
2742 return "false";
2743 }
2744
2745 void
2746 gen_schema(FILE *fd, Table *t, char *ns1, char *ns, int all, int wsdl, char *URL, char *URI, char *style, char *encoding)
2747 { int i, d;
2748 char cbuf[4];
2749 Entry *p, *q, *r;
2750 Tnode *n;
2751 Symbol *s;
2752 Service *sp, *sp2;
2753 Method *m;
2754 int flag;
2755 if (!strcmp(ns, "SOAP-ENV") || !strcmp(ns, "SOAP-ENC") || !strcmp(ns, "xsi") || !strcmp(ns, "xsd"))
2756 return;
2757 for (sp = services; sp; sp = sp->next)
2758 if (!tagcmp(sp->ns, ns) && sp->URI)
2759 break;
2760 if (sp && sp->import)
2761 return;
2762 fprintf(fd, " <schema ");
2763 if (sp)
2764 fprintf(fd, "targetNamespace=\"%s\"", sp->URI);
2765 else
2766 fprintf(fd, "targetNamespace=\"%s/%s.xsd\"", tmpURI, ns_convert(ns));
2767 for (s = nslist; s; s = s->next)
2768 { for (sp2 = services; sp2; sp2 = sp2->next)
2769 if (!tagcmp(sp2->ns, s->name) && sp2->URI)
2770 break;
2771 if (sp2)
2772 fprintf(fd, "\n xmlns:%s=\"%s\"", ns_convert(s->name), sp2->URI);
2773 else if (!strcmp(s->name, "SOAP-ENV"))
2774 fprintf(fd, "\n xmlns:SOAP-ENV=\"%s\"", envURI);
2775 else if (!strcmp(s->name, "SOAP-ENC"))
2776 fprintf(fd, "\n xmlns:SOAP-ENC=\"%s\"", encURI);
2777 else if (!strcmp(s->name, "xsi"))
2778 fprintf(fd, "\n xmlns:xsi=\"%s\"", xsiURI);
2779 else if (!strcmp(s->name, "xsd"))
2780 fprintf(fd, "\n xmlns:xsd=\"%s\"", xsdURI);
2781 else
2782 fprintf(fd, "\n xmlns:%s=\"%s/%s.xsd\"", ns_convert(s->name), tmpURI, ns_convert(s->name));
2783 }
2784 fprintf(fd, "\n xmlns=\"%s\"\n", xsdURI);
2785 if (sp && (sp->elementForm || sp->attributeForm))
2786 fprintf(fd, " elementFormDefault=\"%s\"\n attributeFormDefault=\"%s\">\n", sp->elementForm?sp->elementForm:"unqualified", sp->attributeForm?sp->attributeForm:"unqualified");
2787 else if (style && !strcmp(style, "document"))
2788 fprintf(fd, " elementFormDefault=\"qualified\"\n attributeFormDefault=\"unqualified\">\n");
2789 else
2790 fprintf(fd, " elementFormDefault=\"unqualified\"\n attributeFormDefault=\"unqualified\">\n");
2791 fflush(fd);
2792 flag = 0;
2793 for (s = nslist; s; s = s->next)
2794 { for (sp2 = services; sp2; sp2 = sp2->next)
2795 if (sp2 != sp && !tagcmp(sp2->ns, s->name) && sp2->URI)
2796 break;
2797 if (sp2)
2798 { fprintf(fd, " <import namespace=\"%s\"", sp2->URI);
2799 if (sp2->import)
2800 fprintf(fd, " schemaLocation=\"%s\"", sp2->import);
2801 fprintf(fd, "/>\n");
2802 if (!strcmp(sp2->URI, encURI))
2803 flag = 1;
2804 }
2805 }
2806 if (!flag)
2807 fprintf(fd, " <import namespace=\"%s\"/>", encURI);
2808 fprintf(fd, "\n");
2809 fflush(fd);
2810 if (typetable)
2811 { for (p = typetable->list; p; p = p->next)
2812 { if (p->info.typ->type != Ttemplate && !is_transient(p->info.typ) && !is_invisible(p->sym->name) && (!is_external(p->info.typ) || is_volatile(p->info.typ)) && ((has_ns_eq(ns, p->sym->name))))
2813 { /* typedefs that are used for SOAP Fault details */
2814 m = NULL;
2815 if (p->info.typ->type != Tstruct && p->info.typ->type != Tclass)
2816 { for (sp2 = services; sp2 && !m; sp2 = sp2->next)
2817 { for (m = sp2->list; m; m = m->next)
2818 { if ((m->mess&FAULT) && m->part && is_eq(m->part, p->sym->name))
2819 break;
2820 }
2821 }
2822 }
2823 if (m)
2824 { if (!uflag)
2825 fprintf(fd, " <!-- fault element -->\n");
2826 fprintf(fd, " <element name=\"%s\" type=\"%s\">\n", ns_remove(p->sym->name), base_type(p->info.typ, ns1));
2827 gen_type_documentation(fd, p, ns);
2828 fprintf(fd, " </element>\n");
2829 continue;
2830 }
2831 if (is_primitive_or_string(p->info.typ) || (p->info.typ->type == Tpointer && is_primitive_or_string((Tnode*)p->info.typ->ref)))
2832 { fprintf(fd, " <simpleType name=\"%s\">", ns_remove(p->sym->name));
2833 gen_type_documentation(fd, p, ns);
2834 fprintf(fd, " <restriction base=\"%s\">\n", base_type(p->info.typ, ns1));
2835 if (p->info.typ->pattern)
2836 fprintf(fd, " <pattern value=\"%s\"/>\n", p->info.typ->pattern);
2837 if (is_primitive(p->info.typ) || (p->info.typ->type == Tpointer && is_primitive((Tnode*)p->info.typ->ref) && !is_string(p->info.typ) && !is_wstring(p->info.typ)))
2838 { if (p->info.typ->minLength != MINLONG64)
2839 fprintf(fd, " <minInclusive value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->minLength);
2840 if (p->info.typ->maxLength != MAXLONG64)
2841 fprintf(fd, " <maxInclusive value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->maxLength);
2842 }
2843 else
2844 { if (p->info.typ->maxLength > 0 && p->info.typ->minLength == p->info.typ->maxLength)
2845 fprintf(fd, " <length value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->minLength);
2846 else
2847 { if (p->info.typ->minLength > 0)
2848 fprintf(fd, " <minLength value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->minLength);
2849 if (p->info.typ->maxLength != MAXLONG64)
2850 fprintf(fd, " <maxLength value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->maxLength);
2851 }
2852 }
2853 fprintf(fd, " </restriction>\n </simpleType>\n");
2854 }
2855 else
2856 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
2857 gen_type_documentation(fd, p, ns);
2858 fprintf(fd, " <complexContent>\n <restriction base=\"%s\">\n", base_type(p->info.typ, ns1));
2859 fprintf(fd, " </restriction>\n </complexContent>\n </complexType>\n");
2860 }
2861 }
2862 }
2863 }
2864 fflush(fd);
2865 if (enumtable)
2866 { for (p = enumtable->list; p; p = p->next)
2867 { if (!is_transient(p->info.typ) && !is_invisible(p->sym->name) && ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name)))
2868 { if (is_mask(p->info.typ))
2869 { fprintf(fd, " <simpleType name=\"%s\">", wsdl_type(p->info.typ, NULL));
2870 gen_type_documentation(fd, p, ns);
2871 fprintf(fd, " <list>\n");
2872 q = p;
2873 if ((Table*)p->info.typ->ref)
2874 { for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
2875 if (!has_ns_eq(NULL, ns_remove1(((Table*)p->info.typ->ref)->list->sym->name)))
2876 break;
2877 }
2878 if (q)
2879 fprintf(fd, " <restriction base=\"xsd:string\">\n");
2880 else
2881 fprintf(fd, " <restriction base=\"xsd:QName\">\n");
2882 if ((Table*)p->info.typ->ref)
2883 { for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
2884 { fprintf(fd, " <enumeration value=\"%s\"", ns_remove2(q->sym->name));
2885 if (gen_member_documentation(fd, p->sym, q, ns))
2886 fprintf(fd, " </enumeration>");
2887 if (!uflag)
2888 fprintf(fd, " <!-- = " SOAP_LONG_FORMAT " -->", q->info.val.i);
2889 fprintf(fd, "\n");
2890 }
2891 }
2892 fprintf(fd, " </restriction>\n </list>\n </simpleType>\n");
2893 }
2894 else
2895 { fprintf(fd, " <simpleType name=\"%s\">", wsdl_type(p->info.typ, NULL));
2896 gen_type_documentation(fd, p, ns);
2897 q = p;
2898 if ((Table*)p->info.typ->ref)
2899 { for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
2900 if (!has_ns_eq(NULL, ns_remove1(((Table*)p->info.typ->ref)->list->sym->name)))
2901 break;
2902 }
2903 if (q)
2904 fprintf(fd, " <restriction base=\"xsd:string\">\n");
2905 else
2906 fprintf(fd, " <restriction base=\"xsd:QName\">\n");
2907 if ((Table*)p->info.typ->ref)
2908 { for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
2909 { fprintf(fd, " <enumeration value=\"%s\"", ns_remove2(q->sym->name));
2910 if (gen_member_documentation(fd, p->sym, q, ns))
2911 fprintf(fd, " </enumeration>");
2912 if (!uflag)
2913 fprintf(fd, " <!-- = " SOAP_LONG_FORMAT " -->", q->info.val.i);
2914 fprintf(fd, "\n");
2915 }
2916 }
2917 fprintf(fd, " </restriction>\n </simpleType>\n");
2918 }
2919 }
2920 }
2921 }
2922 fflush(fd);
2923 if (classtable)
2924 { for (p = classtable->list; p; p = p->next)
2925 { if (is_transient(p->info.typ) || is_invisible(p->sym->name))
2926 continue;
2927 for (q = t->list; q; q = q->next)
2928 if (q->info.typ->type == Tfun && !(q->info.sto & Sextern) && p == get_response(q->info.typ))
2929 break;
2930 /* omit the auto-generated and user-defined response struct/class (when necessary) */
2931 if (!q)
2932 for (q = t->list; q; q = q->next)
2933 if (q->info.typ->type == Tfun && !(q->info.sto & Sextern) && !has_ns_eq(NULL, ((Entry*)q->info.typ->ref)->sym->name))
2934 { r = entry(t, q->sym);
2935 if (r && r->info.typ->ref && is_response(((Entry*)r->info.typ->ref)->info.typ) && p->info.typ == (Tnode*)((Entry*)r->info.typ->ref)->info.typ->ref)
2936 break;
2937 }
2938 if (q)
2939 continue;
2940 /* classes that are used for SOAP Fault details */
2941 m = NULL;
2942 for (sp2 = services; sp2 && !m; sp2 = sp2->next)
2943 for (m = sp2->list; m; m = m->next)
2944 if ((m->mess&FAULT) && m->part && is_eq(m->part, p->sym->name))
2945 break;
2946 if (m)
2947 { if ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name))
2948 { if (!uflag)
2949 fprintf(fd, " <!-- fault element and type -->\n");
2950 fprintf(fd, " <element name=\"%s\" type=\"%s\">\n", ns_remove(p->sym->name), base_type(p->info.typ, ns1));
2951 gen_type_documentation(fd, p, ns);
2952 fprintf(fd, " </element>\n");
2953 }
2954 }
2955 if (p->info.typ->ref && is_binary(p->info.typ))
2956 { if ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name))
2957 { if (is_attachment(p->info.typ))
2958 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
2959 gen_type_documentation(fd, p, ns);
2960 fprintf(fd, " <simpleContent>\n <extension base=\"xsd:base64Binary\">\n");
2961 if (!eflag)
2962 fprintf(fd, " <attribute name=\"href\" type=\"xsd:anyURI\" use=\"optional\"/>\n");
2963 gen_schema_attributes(fd, p->info.typ, ns, ns1);
2964 fprintf(fd, " </extension>\n </simpleContent>\n </complexType>\n");
2965 }
2966 else
2967 { fprintf(fd, " <simpleType name=\"%s\">", ns_remove(p->sym->name));
2968 gen_type_documentation(fd, p, ns);
2969 fprintf(fd, " <restriction base=\"xsd:base64Binary\">\n");
2970 if (p->info.typ->maxLength > 0 && p->info.typ->minLength == p->info.typ->maxLength)
2971 fprintf(fd, " <length value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->minLength);
2972 else
2973 { if (p->info.typ->minLength > 0)
2974 fprintf(fd, " <minLength value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->minLength);
2975 if (p->info.typ->maxLength != MAXLONG64)
2976 fprintf(fd, " <maxLength value=\"" SOAP_LONG_FORMAT "\"/>\n", p->info.typ->maxLength);
2977 }
2978 fprintf(fd, " </restriction>\n </simpleType>\n");
2979 }
2980 }
2981 }
2982 else if (p->info.typ->ref && !is_transient(p->info.typ) && is_primclass(p->info.typ))
2983 { if ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name))
2984 { q = ((Table*)p->info.typ->ref)->list;
2985 if (q && strncmp(q->sym->name, "xsd__anyType", 12))
2986 { if (is_string(q->info.typ) || is_wstring(q->info.typ) || is_stdstring(q->info.typ) || is_stdwstring(q->info.typ))
2987 { fprintf(fd, " <complexType name=\"%s\" mixed=\"true\">", ns_remove(p->sym->name));
2988 gen_type_documentation(fd, p, ns);
2989 fprintf(fd, " <simpleContent>\n <extension base=\"%s\">\n", wsdl_type(q->info.typ, ns1));
2990 gen_schema_attributes(fd, p->info.typ, ns, ns1);
2991 fprintf(fd, " </extension>\n </simpleContent>\n </complexType>\n");
2992 }
2993 else if (is_primitive(q->info.typ))
2994 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
2995 gen_type_documentation(fd, p, ns);
2996 fprintf(fd, " <simpleContent>\n <extension base=\"%s\">\n", wsdl_type(q->info.typ, ns1));
2997 gen_schema_attributes(fd, p->info.typ, ns, ns1);
2998 fprintf(fd, " </extension>\n </simpleContent>\n </complexType>\n");
2999 }
3000 else
3001 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3002 gen_type_documentation(fd, p, ns);
3003 fprintf(fd, " <complexContent>\n <extension base=\"%s\">\n", wsdl_type(q->info.typ, ns1));
3004 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3005 fprintf(fd, " </extension>\n </complexContent>\n </complexType>\n");
3006 }
3007 }
3008 }
3009 }
3010 else if (p->info.typ->ref && !is_transient(p->info.typ))
3011 { q = ((Table*)p->info.typ->ref)->list;
3012 if (entry(t, p->sym) && (!q || !is_XML(q->info.typ)))
3013 ;
3014 else if (is_dynamic_array(p->info.typ))
3015 { if (eflag || (!has_ns(p->info.typ) && !is_untyped(p->info.typ)))
3016 { if (all)
3017 { d = get_Darraydims(p->info.typ)-1;
3018 for (i = 0; i < d; i++)
3019 cbuf[i] = ',';
3020 cbuf[i] = '\0';
3021 if (q->info.maxOccurs == 1)
3022 fprintf(fd, " <complexType name=\"%s\">\n <complexContent>\n <restriction base=\"SOAP-ENC:Array\">\n <sequence>\n <element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\" nillable=\"%s\"/>\n </sequence>\n <attribute ref=\"SOAP-ENC:arrayType\" WSDL:arrayType=\"%s[%s]\"/>\n </restriction>\n </complexContent>\n </complexType>\n", wsdl_type(p->info.typ, NULL), q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1), nillable((Tnode*)q->info.typ->ref), wsdl_type(q->info.typ, ns1), cbuf);
3023 else
3024 fprintf(fd, " <complexType name=\"%s\">\n <complexContent>\n <restriction base=\"SOAP-ENC:Array\">\n <sequence>\n <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"%s\"/>\n </sequence>\n <attribute ref=\"SOAP-ENC:arrayType\" WSDL:arrayType=\"%s[%s]\"/>\n </restriction>\n </complexContent>\n </complexType>\n", wsdl_type(p->info.typ, NULL), q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1), q->info.minOccurs, q->info.maxOccurs, nillable((Tnode*)q->info.typ->ref), wsdl_type(q->info.typ, ns1), cbuf);
3025 }
3026 }
3027 else if (p->info.typ->ref && ((Table*)p->info.typ->ref)->prev && !is_transient(entry(classtable, ((Table*)p->info.typ->ref)->prev->sym)->info.typ) && strncmp(((Table*)p->info.typ->ref)->prev->sym->name, "xsd__anyType", 12))
3028 { if (q->info.maxOccurs == 1)
3029 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3030 gen_type_documentation(fd, p, ns);
3031 fprintf(fd, " <complexContent>\n <extension base=\"%s\">\n <sequence>\n", ns_convert(((Table*)p->info.typ->ref)->prev->sym->name));
3032 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\" nillable=\"true\"/>\n", q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1));
3033 fprintf(fd, " </sequence>\n </extension>\n </complexContent>\n");
3034 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3035 fprintf(fd, " </complexType>\n");
3036 }
3037 else
3038 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3039 gen_type_documentation(fd, p, ns);
3040 fprintf(fd, " <complexContent>\n <extension base=\"%s\">\n <sequence>\n", ns_convert(((Table*)p->info.typ->ref)->prev->sym->name));
3041 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"%s\"/>\n", q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1), q->info.minOccurs, q->info.maxOccurs, nillable((Tnode*)q->info.typ->ref));
3042 fprintf(fd, " </sequence>\n </extension>\n </complexContent>\n");
3043 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3044 fprintf(fd, " </complexType>\n");
3045 }
3046 }
3047 else
3048 { if (q->info.maxOccurs == 1)
3049 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3050 gen_type_documentation(fd, p, ns);
3051 fprintf(fd, " <sequence>\n <element name=\"%s\" type=\"%s\" minOccurs=\"0\" maxOccurs=\"unbounded\" nillable=\"%s\"/>\n </sequence>\n </complexType>\n", q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1), nillable((Tnode*)q->info.typ->ref));
3052 }
3053 else
3054 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3055 gen_type_documentation(fd, p, ns);
3056 fprintf(fd, " <sequence>\n <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"%s\"/>\n </sequence>\n </complexType>\n", q->sym->name[5]?ns_remove(q->sym->name+5):"item", wsdl_type(q->info.typ, ns1), q->info.minOccurs, q->info.maxOccurs, nillable((Tnode*)q->info.typ->ref));
3057 }
3058 }
3059 }
3060 else if (is_discriminant(p->info.typ) && ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name)))
3061 { if (p->info.typ->ref)
3062 { fprintf(fd, " <complexType name=\"%s\">\n", ns_remove(p->sym->name));
3063 gen_schema_elements(fd, p->info.typ, ns, ns1);
3064 fprintf(fd, " </complexType>\n");
3065 }
3066 }
3067 else if (p->info.typ->type == Tstruct && ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name)))
3068 { if (p->info.typ->ref)
3069 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3070 gen_type_documentation(fd, p, ns);
3071 fprintf(fd, " <sequence>\n");
3072 gen_schema_elements(fd, p->info.typ, ns, ns1);
3073 fprintf(fd, " </sequence>\n");
3074 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3075 fprintf(fd, " </complexType>\n");
3076 }
3077 }
3078 else if (p->info.typ->type == Tclass && ((!has_ns(p->info.typ) && all) || has_ns_eq(ns, p->sym->name)))
3079 { if (p->info.typ->ref)
3080 { if (((Table*)p->info.typ->ref)->prev && !is_transient(entry(classtable, ((Table*)p->info.typ->ref)->prev->sym)->info.typ) && strncmp(((Table*)p->info.typ->ref)->prev->sym->name, "xsd__anyType", 12))
3081 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3082 gen_type_documentation(fd, p, ns);
3083 fprintf(fd, " <complexContent>\n <extension base=\"%s\">\n <sequence>\n", ns_convert(((Table*)p->info.typ->ref)->prev->sym->name));
3084 gen_schema_elements(fd, p->info.typ, ns, ns1);
3085 fprintf(fd, " </sequence>\n </extension>\n </complexContent>\n");
3086 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3087 fprintf(fd, " </complexType>\n");
3088 }
3089 else
3090 { fprintf(fd, " <complexType name=\"%s\">", ns_remove(p->sym->name));
3091 gen_type_documentation(fd, p, ns);
3092 fprintf(fd, " <sequence>\n");
3093 gen_schema_elements(fd, p->info.typ, ns, ns1);
3094 fprintf(fd, " </sequence>\n");
3095 gen_schema_attributes(fd, p->info.typ, ns, ns1);
3096 fprintf(fd, " </complexType>\n");
3097 }
3098 }
3099 }
3100 }
3101 }
3102 }
3103 fflush(fd);
3104 for (n = Tptr[Tarray]; n; n = n->next)
3105 { if (is_transient(n) || is_fixedstring(n))
3106 continue;
3107 if (1 /* wsdl */)
3108 fprintf(fd, " <complexType name=\"%s\">\n <complexContent>\n <restriction base=\"SOAP-ENC:Array\">\n <attribute ref=\"SOAP-ENC:arrayType\" WSDL:arrayType=\"%s[]\"/>\n </restriction>\n </complexContent>\n </complexType>\n", c_ident(n), wsdl_type((Tnode*)n->ref, ns1));
3109 else
3110 fprintf(fd, " <complexType name=\"%s\">\n <complexContent>\n <restriction base=\"SOAP-ENC:Array\">\n <element name=\"item\" type=\"%s\" maxOccurs=\"unbounded\"/>\n </restriction>\n </complexContent>\n </complexType>\n", c_ident(n), xsi_type((Tnode*)n->ref));
3111 fflush(fd);
3112 }
3113 gen_schema_elements_attributes(fd, t, ns, ns1, style, encoding);
3114 fprintf(fd, " </schema>\n\n");
3115 }
3116
3117 void
3118 gen_schema_elements(FILE *fd, Tnode *p, char *ns, char *ns1)
3119 { Entry *q;
3120 for (q = ((Table*)p->ref)->list; q; q = q->next)
3121 if (gen_schema_element(fd, p, q, ns, ns1))
3122 q = q->next;
3123 }
3124
3125 int
3126 gen_schema_element(FILE *fd, Tnode *p, Entry *q, char *ns, char *ns1)
3127 { char *s, *t;
3128 if (is_transient(q->info.typ) || (q->info.sto & Sattribute) || q->info.typ->type == Tfun || q->info.typ->type == Tunion)
3129 return 0;
3130 if (is_repetition(q))
3131 { if (is_sequence(q->next))
3132 { fprintf(fd, " <sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\n");
3133 if (q->next->info.typ->ref)
3134 gen_schema_elements(fd, (Tnode*)q->next->info.typ->ref, ns, ns1);
3135 fprintf(fd, " </sequence>\n");
3136 return 1;
3137 }
3138 t = ns_convert(q->next->sym->name);
3139 if (*t == '-')
3140 fprintf(fd, " <any processContents=\"lax\" minOccurs=\"0\" maxOccurs=\"unbounded\"/><!-- %s -->\n", q->next->sym->name);
3141 else if ((s = strchr(t+1, ':')) && (!strchr(q->next->sym->name+1, ':') || !has_ns_eq(ns, q->next->sym->name)))
3142 { if (((Tnode*)q->next->info.typ->ref)->type == Tpointer)
3143 if (q->info.maxOccurs == 1)
3144 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"", t, q->info.minOccurs);
3145 else
3146 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3147 else if (q->info.maxOccurs == 1)
3148 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"", t, q->info.minOccurs);
3149 else
3150 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3151 if (gen_member_documentation(fd, p->id, q, ns))
3152 fprintf(fd, " </element>\n");
3153 }
3154 else
3155 { const char *form = "";
3156 if (!s)
3157 { s = t;
3158 if (*s == ':')
3159 { s++;
3160 form = " form=\"unqualified\"";
3161 }
3162 }
3163 else
3164 { s++;
3165 form = " form=\"qualified\"";
3166 }
3167 if (((Tnode*)q->next->info.typ->ref)->type == Tpointer)
3168 if (q->info.maxOccurs == 1)
3169 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\" nillable=\"true\"%s", s, wsdl_type((Tnode*)q->next->info.typ->ref, ns1), q->info.minOccurs, form);
3170 else
3171 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"true\"%s", s, wsdl_type((Tnode*)q->next->info.typ->ref, ns1), q->info.minOccurs, q->info.maxOccurs, form);
3172 else if (q->info.maxOccurs == 1)
3173 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"%s", s, wsdl_type((Tnode*)q->next->info.typ->ref, ns1), q->info.minOccurs, form);
3174 else
3175 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"%s", s, wsdl_type((Tnode*)q->next->info.typ->ref, ns1), q->info.minOccurs, q->info.maxOccurs, form);
3176 if (gen_member_documentation(fd, p->id, q, ns))
3177 fprintf(fd, " </element>\n");
3178 }
3179 return 1;
3180 }
3181 else if (q->info.typ->type == Ttemplate || (q->info.typ->type == Tpointer && ((Tnode*)q->info.typ->ref)->type == Ttemplate) || (q->info.typ->type == Treference && ((Tnode*)q->info.typ->ref)->type == Ttemplate))
3182 { t = ns_convert(q->sym->name);
3183 if (*t == '-')
3184 fprintf(fd, " <any processContents=\"lax\" minOccurs=\"0\" maxOccurs=\"unbounded\"/><!-- %s -->\n", q->sym->name);
3185 else if ((s = strchr(t+1, ':')) && (!strchr(q->sym->name+1, ':') || !has_ns_eq(ns, q->sym->name)))
3186 { if (((Tnode*)q->info.typ->ref)->type == Tpointer)
3187 if (q->info.maxOccurs == 1)
3188 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"", t, q->info.minOccurs);
3189 else
3190 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3191 else if (q->info.maxOccurs == 1)
3192 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"", t, q->info.minOccurs);
3193 else
3194 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3195 if (gen_member_documentation(fd, p->id, q, ns))
3196 fprintf(fd, " </element>\n");
3197 }
3198 else
3199 { const char *form = "";
3200 if (!s)
3201 { s = t;
3202 if (*s == ':')
3203 { s++;
3204 form = " form=\"unqualified\"";
3205 }
3206 }
3207 else
3208 { s++;
3209 form = " form=\"qualified\"";
3210 }
3211 if (((Tnode*)q->info.typ->ref)->type == Tpointer)
3212 if (q->info.maxOccurs == 1)
3213 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\" nillable=\"true\"%s", s, wsdl_type((Tnode*)q->info.typ->ref, ns1), q->info.minOccurs, form);
3214 else
3215 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"true\"%s", s, wsdl_type((Tnode*)q->info.typ->ref, ns1), q->info.minOccurs, q->info.maxOccurs, form);
3216 else if (q->info.maxOccurs == 1)
3217 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"unbounded\"%s", s, wsdl_type((Tnode*)q->info.typ->ref, ns1), q->info.minOccurs, form);
3218 else
3219 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"%s", s, wsdl_type((Tnode*)q->info.typ->ref, ns1), q->info.minOccurs, q->info.maxOccurs, form);
3220 if (gen_member_documentation(fd, p->id, q, ns))
3221 fprintf(fd, " </element>\n");
3222 }
3223 }
3224 else if (is_anytype(q)) /* ... maybe need to show all possible types rather than xsd:anyType */
3225 { fprintf(fd, " <element name=\"%s\" type=\"xsd:anyType\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"true\"/>\n", ns_convert(q->next->sym->name), q->info.minOccurs, q->info.maxOccurs);
3226 return 1;
3227 }
3228 else if (is_choice(q))
3229 { if (q->info.minOccurs == 0)
3230 fprintf(fd, " <choice minOccurs=\"0\" maxOccurs=\"1\">\n");
3231 else
3232 fprintf(fd, " <choice>\n");
3233 if (q->next->info.typ->ref)
3234 gen_schema_elements(fd, q->next->info.typ, ns, ns1);
3235 fprintf(fd, " </choice>\n");
3236 return 1;
3237 }
3238 else if (is_sequence(q))
3239 { if (q->info.minOccurs == 0)
3240 fprintf(fd, " <sequence minOccurs=\"0\" maxOccurs=\"1\">\n");
3241 else
3242 fprintf(fd, " <sequence>\n");
3243 if (q->info.typ->type == Tpointer)
3244 gen_schema_elements(fd, (Tnode*)q->info.typ->ref, ns, ns1);
3245 else if (q->info.typ->ref)
3246 gen_schema_elements(fd, q->info.typ, ns, ns1);
3247 fprintf(fd, " </sequence>\n");
3248 return 0;
3249 }
3250 else
3251 { t = ns_convert(q->sym->name);
3252 if (*t == '-')
3253 fprintf(fd, " <any processContents=\"lax\" minOccurs=\"0\" maxOccurs=\"1\"/><!-- %s -->\n", q->sym->name);
3254 else if ((s = strchr(t+1, ':')) && (!strchr(q->sym->name+1, ':') || !has_ns_eq(ns, q->sym->name)))
3255 { if (q->info.typ->type == Tpointer || q->info.typ->type == Tarray || is_dynamic_array(q->info.typ))
3256 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3257 else
3258 fprintf(fd, " <element ref=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"", t, q->info.minOccurs, q->info.maxOccurs);
3259 if (gen_member_documentation(fd, p->id, q, ns))
3260 fprintf(fd, " </element>\n");
3261 }
3262 else
3263 { const char *form = "";
3264 if (!s)
3265 { s = t;
3266 if (*s == ':')
3267 { s++;
3268 form = " form=\"unqualified\"";
3269 }
3270 }
3271 else
3272 { s++;
3273 form = " form=\"qualified\"";
3274 }
3275 if (q->info.typ->type == Tpointer || q->info.typ->type == Tarray || is_dynamic_array(q->info.typ))
3276 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\" nillable=\"true\"%s%s", s, wsdl_type(q->info.typ, ns1), q->info.minOccurs, q->info.maxOccurs, default_value(q, "default"), form);
3277 else
3278 fprintf(fd, " <element name=\"%s\" type=\"%s\" minOccurs=\"" SOAP_LONG_FORMAT "\" maxOccurs=\"" SOAP_LONG_FORMAT "\"%s%s", s, wsdl_type(q->info.typ, ns1), q->info.minOccurs, q->info.maxOccurs, default_value(q, "default"), form);
3279 if (gen_member_documentation(fd, p->id, q, ns))
3280 fprintf(fd, " </element>\n");
3281 }
3282 }
3283 fflush(fd);
3284 return 0;
3285 }
3286
3287 void
3288 gen_schema_elements_attributes(FILE *fd, Table *t, char *ns, char *ns1, char *style, char *encoding)
3289 { Entry *p, *q, *e;
3290 Table *r;
3291 Service *sp;
3292 Method *m;
3293 char *method_style, *method_encoding, *method_response_encoding;
3294 int all = !strcmp(ns, ns1);
3295 r = mktable(NULL);
3296 for (p = classtable->list; p; p = p->next)
3297 { if (!p->info.typ->ref || /* is_invisible(p->info.typ->id->name) || */ is_transient(p->info.typ) || is_primclass(p->info.typ) || is_dynamic_array(p->info.typ))
3298 continue;
3299 for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
3300 { if (!is_repetition(q) && !is_anytype(q) && (!strchr(q->sym->name+1, ':') || !eq_ns(p->sym->name, q->sym->name)) && has_ns_eq(ns, q->sym->name) && !is_transient(q->info.typ) && q->info.typ->type != Tfun)
3301 { Service *sp2;
3302 Method *m;
3303 m = NULL;
3304 for (sp2 = services; sp2 && !m; sp2 = sp2->next)
3305 for (m = sp2->list; m; m = m->next)
3306 if ((m->mess&FAULT) && m->part && is_eq(m->part, q->sym->name))
3307 break;
3308 if (m)
3309 continue; /* already generated element for fault */
3310 e = entry(r, q->sym);
3311 if (e)
3312 { if ((e->info.sto & Sattribute) != (q->info.sto & Sattribute) || reftype(e->info.typ) != reftype(q->info.typ))
3313 { sprintf(errbuf, "Field '%s' of type '%s' at line %d has a type that does not correspond to the required unique type '%s' defined for elements '<%s>' in the WSDL namespace based on literal encoding: use SOAP RPC encoding or rename or use a namespace qualifier", q->sym->name, c_type(q->info.typ), q->lineno, c_type(e->info.typ), ns_convert(q->sym->name));
3314 semwarn(errbuf);
3315 }
3316 }
3317 else
3318 { if (q->info.sto & Sattribute)
3319 fprintf(fd, " <attribute name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3320 else
3321 fprintf(fd, " <element name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3322 e = enter(r, q->sym);
3323 e->info = q->info;
3324 }
3325 }
3326 }
3327 }
3328 if (t && all)
3329 { for (p = t->list; p; p = p->next)
3330 { if (p->info.typ->type == Tfun && !is_invisible(p->sym->name) && !(p->info.sto & Sextern) && has_ns_eq(ns, p->sym->name))
3331 { method_encoding = encoding;
3332 method_response_encoding = NULL;
3333 method_style = style;
3334 for (sp = services; sp; sp = sp->next)
3335 { if (!tagcmp(sp->ns, ns))
3336 { for (m = sp->list; m; m = m->next)
3337 { if (is_eq_nons(m->name, p->sym->name))
3338 { if (m->mess == ENCODING)
3339 method_encoding = m->part;
3340 else if (m->mess == RESPONSE_ENCODING)
3341 method_response_encoding = m->part;
3342 else if (m->mess == STYLE)
3343 method_style = m->part;
3344 }
3345 }
3346 }
3347 }
3348 if (!eflag)
3349 { if (!method_response_encoding)
3350 method_response_encoding = method_encoding;
3351 q = entry(classtable, p->sym);
3352 if (q)
3353 { if (is_document(method_style))
3354 { if (!uflag)
3355 fprintf(fd, " <!-- operation request element -->\n");
3356 fprintf(fd, " <element name=\"%s\">\n <complexType>\n <sequence>\n", ns_remove(p->sym->name));
3357 gen_schema_elements(fd, q->info.typ, ns, ns1);
3358 fprintf(fd, " </sequence>\n");
3359 gen_schema_attributes(fd, q->info.typ, ns, ns1);
3360 fprintf(fd, " </complexType>\n </element>\n");
3361 }
3362 else if (is_literal(method_encoding))
3363 { for (q = ((Table*)q->info.typ->ref)->list; q; q = q->next)
3364 { if (!is_repetition(q) && !is_anytype(q) && !has_ns_eq(NULL, q->sym->name) && !is_transient(q->info.typ) && q->info.typ->type != Tfun && !(q->info.sto & Sattribute))
3365 { e = entry(r, q->sym);
3366 if (e)
3367 { if ((e->info.sto & Sattribute) != (q->info.sto & Sattribute)|| reftype(e->info.typ) != reftype(q->info.typ))
3368 { sprintf(errbuf, "Parameter '%s' of type '%s' at line %d has a type that does not correspond to the required unique type '%s' defined for elements '<%s>' in the WSDL namespace based on literal encoding: use SOAP RPC encoding or rename or use a namespace qualifier", q->sym->name, c_type(q->info.typ), q->lineno, c_type(e->info.typ), ns_convert(q->sym->name));
3369 semwarn(errbuf);
3370 }
3371 }
3372 else
3373 { if (!uflag)
3374 fprintf(fd, " <!-- operation request element -->\n");
3375 fprintf(fd, " <element name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3376 e = enter(r, q->sym);
3377 e->info = q->info;
3378 }
3379 }
3380 }
3381 }
3382 q = (Entry*)p->info.typ->ref;
3383 for (e = t->list; e; e = e->next)
3384 if (e != p && e->info.typ->type == Tfun && !(e->info.sto & Sextern) && q == (Entry*)e->info.typ->ref)
3385 q = NULL;
3386 if (q && !is_transient(q->info.typ))
3387 { if (!is_response(q->info.typ))
3388 { if (is_document(method_style))
3389 { if (!uflag)
3390 fprintf(fd, " <!-- operation response element -->\n");
3391 fprintf(fd, " <element name=\"%sResponse\">\n <complexType>\n", ns_remove(p->sym->name));
3392 fprintf(fd, " <sequence>\n");
3393 gen_schema_element(fd, p->info.typ, q, ns, ns1);
3394 fprintf(fd, " </sequence>\n");
3395 fprintf(fd, " </complexType>\n </element>\n");
3396 }
3397 else if (is_literal(method_response_encoding))
3398 { e = entry(r, q->sym);
3399 if (e)
3400 { if ((e->info.sto & Sattribute) != (q->info.sto & Sattribute)|| reftype(e->info.typ) != reftype(q->info.typ))
3401 { sprintf(errbuf, "Qualified member field '%s' has a type that does not correspond to the unique type '%s' defined for elements '<%s>'", q->sym->name, c_type(q->info.typ), ns_convert(q->sym->name));
3402 semwarn(errbuf);
3403 }
3404 }
3405 else
3406 { if (!uflag)
3407 fprintf(fd, " <!-- operation response element -->\n");
3408 fprintf(fd, " <element name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3409 e = enter(r, q->sym);
3410 e->info = q->info;
3411 }
3412 }
3413 }
3414 else if (((Tnode*)q->info.typ->ref)->ref)
3415 { if (is_document(method_style))
3416 { if (!has_ns_eq(NULL, q->sym->name))
3417 { e = entry(r, ((Tnode*)q->info.typ->ref)->id);
3418 if (!e)
3419 { if (!uflag)
3420 fprintf(fd, " <!-- operation response element -->\n");
3421 fprintf(fd, " <element name=\"%s\">\n <complexType>\n", ns_remove(((Tnode*)q->info.typ->ref)->id->name));
3422 fprintf(fd, " <sequence>\n");
3423 gen_schema_elements(fd, (Tnode*)q->info.typ->ref, ns, ns1);
3424 fprintf(fd, " </sequence>\n");
3425 gen_schema_attributes(fd, (Tnode*)q->info.typ->ref, ns, ns1);
3426 fprintf(fd, " </complexType>\n </element>\n");
3427 e = enter(r, ((Tnode*)q->info.typ->ref)->id);
3428 e->info = q->info;
3429 }
3430 }
3431 }
3432 else if (is_literal(method_response_encoding))
3433 { for (q = ((Table*)((Tnode*)q->info.typ->ref)->ref)->list; q; q = q->next)
3434 { if (!is_repetition(q) && !is_anytype(q) && !has_ns_eq(NULL, q->sym->name) && !is_transient(q->info.typ) && q->info.typ->type != Tfun && !(q->info.sto & Sattribute))
3435 { e = entry(r, q->sym);
3436 if (e)
3437 { if ((e->info.sto & Sattribute) != (q->info.sto & Sattribute)|| reftype(e->info.typ) != reftype(q->info.typ))
3438 { sprintf(errbuf, "Qualified member field '%s' has a type that does not correspond to the unique type '%s' defined for elements '<%s>'", q->sym->name, c_type(q->info.typ), ns_convert(q->sym->name));
3439 semwarn(errbuf);
3440 }
3441 }
3442 else
3443 { if (!uflag)
3444 fprintf(fd, " <!-- operation response element -->\n");
3445 fprintf(fd, " <element name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3446 e = enter(r, q->sym);
3447 e->info = q->info;
3448 }
3449 }
3450 }
3451 }
3452 }
3453 }
3454 }
3455 }
3456 }
3457 }
3458 }
3459 if (t)
3460 { for (p = t->list; p; p = p->next)
3461 { if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && !eflag)
3462 { q = (Entry*)p->info.typ->ref;
3463 if (q && !is_transient(q->info.typ))
3464 { if (is_response(q->info.typ))
3465 { if (has_ns_eq(ns, q->sym->name))
3466 { e = entry(r, q->sym);
3467 if (!e)
3468 { if (!uflag)
3469 fprintf(fd, " <!-- operation response element -->\n");
3470 fprintf(fd, " <element name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns1));
3471 e = enter(r, q->sym);
3472 e->info = q->info;
3473 }
3474 }
3475 }
3476 }
3477 }
3478 }
3479 }
3480 freetable(r);
3481 }
3482
3483 void
3484 gen_schema_attributes(FILE *fd, Tnode *p, char *ns, char *ns1)
3485 { Entry *q;
3486 char *t, *s, *r;
3487 for (q = ((Table*)p->ref)->list; q; q = q->next)
3488 { if (q->info.sto & Sattribute)
3489 { r = default_value(q, "default");
3490 t = ns_convert(q->sym->name);
3491 if (*t == '-' || is_anyAttribute(q->info.typ))
3492 fprintf(fd, " <anyAttribute processContents=\"lax\"/><!-- %s -->\n", q->sym->name);
3493 else if ((s = strchr(t+1, ':')) && (!strchr(q->sym->name+1, ':') || !has_ns_eq(ns, q->sym->name)))
3494 { if (r && *r)
3495 fprintf(fd, " <attribute ref=\"%s\" use=\"default\"%s/>\n", t, r);
3496 else if (q->info.typ->type != Tpointer || q->info.minOccurs)
3497 fprintf(fd, " <attribute ref=\"%s\" use=\"required\"/>\n", t);
3498 else if (q->info.maxOccurs == 0)
3499 fprintf(fd, " <attribute ref=\"%s\" use=\"prohibited\"/>\n", t);
3500 else
3501 fprintf(fd, " <attribute ref=\"%s\" use=\"optional\"/>\n", t);
3502 }
3503 else
3504 { const char *form = "";
3505 if (!s)
3506 { s = t;
3507 if (*s == ':')
3508 { s++;
3509 form = " form=\"unqualified\"";
3510 }
3511 }
3512 else
3513 { s++;
3514 form = " form=\"qualified\"";
3515 }
3516 if (r && *r)
3517 fprintf(fd, " <attribute name=\"%s\" type=\"%s\" use=\"default\"%s%s", s, wsdl_type(q->info.typ, ns1), r, form);
3518 else if ((q->info.typ->type != Tpointer && !is_stdstring(q->info.typ) && !is_stdwstring(q->info.typ)) || q->info.minOccurs)
3519 fprintf(fd, " <attribute name=\"%s\" type=\"%s\" use=\"required\"%s", s, wsdl_type(q->info.typ, ns1), form);
3520 else if (q->info.maxOccurs == 0)
3521 fprintf(fd, " <attribute name=\"%s\" type=\"%s\" use=\"prohibited\"", s, wsdl_type(q->info.typ, ns1));
3522 else
3523 fprintf(fd, " <attribute name=\"%s\" type=\"%s\" use=\"optional\"%s", s, wsdl_type(q->info.typ, ns1), form);
3524 if (gen_member_documentation(fd, p->id, q, ns))
3525 fprintf(fd, " </attribute>\n");
3526 }
3527 fflush(fd);
3528 }
3529 }
3530 }
3531
3532 void
3533 gen_type_documentation(FILE *fd, Entry *type, char *ns)
3534 { Service *sp;
3535 Data *d;
3536 if (!type->sym)
3537 { fprintf(fd, "\n");
3538 return;
3539 }
3540 for (sp = services; sp; sp = sp->next)
3541 { if (!tagcmp(sp->ns, ns))
3542 { for (d = sp->data; d; d = d->next)
3543 { if (!strstr(d->name, "::") && is_eq_nons(d->name, type->sym->name))
3544 { fprintf(fd, "\n <annotation>\n <documentation>%s</documentation>\n </annotation>\n", d->text);
3545 return;
3546 }
3547 }
3548 }
3549 }
3550 if (!uflag)
3551 fprintf(fd, "<!-- %s -->\n", type->sym->name);
3552 fprintf(fd, "\n");
3553 }
3554
3555 int
3556 gen_member_documentation(FILE *fd, Symbol *type, Entry *member, char *ns)
3557 { Service *sp;
3558 Data *d;
3559 char *t;
3560 if (!type || !member->sym)
3561 { fprintf(fd, "/>\n");
3562 return 0;
3563 }
3564 t = ns_remove(type->name);
3565 for (sp = services; sp; sp = sp->next)
3566 { if (!tagcmp(sp->ns, ns))
3567 { for (d = sp->data; d; d = d->next)
3568 { char *s = strstr(d->name, "::");
3569 if (s && !strncmp(t, d->name, s-d->name) && !strcmp(s + 2, member->sym->name))
3570 { fprintf(fd, ">\n <annotation>\n <documentation>%s</documentation>\n </annotation>\n", d->text);
3571 return 1;
3572 }
3573 }
3574 }
3575 }
3576 fprintf(fd, "/>");
3577 if (!uflag)
3578 fprintf(fd, "<!-- %s::%s -->", type->name, member->sym->name);
3579 fprintf(fd, "\n");
3580 return 0;
3581 }
3582
3583 void
3584 gen_nsmap(FILE *fd, Symbol *ns, char *URI)
3585 { Symbol *ns1;
3586 Service *sp;
3587 fprintf(fd, "{\n");
3588 for (ns1 = nslist; ns1; ns1 = ns1->next)
3589 { for (sp = services; sp; sp = sp->next)
3590 if (!tagcmp(sp->ns, ns1->name) && sp->URI)
3591 break;
3592 if (sp)
3593 { if (!strcmp(ns1->name, "SOAP-ENV"))
3594 { if (vflag < 0)
3595 fprintf(fd, "\t{\"SOAP-ENV\", NULL, NULL, NULL},\n");
3596 else
3597 fprintf(fd, "\t{\"%s\", \"%s\", \"%s\", NULL},\n", ns_convert(ns1->name), sp->URI, sp->URI2 ? sp->URI2 : envURI);
3598 }
3599 else if (!strcmp(ns1->name, "SOAP-ENC"))
3600 { if (vflag < 0)
3601 fprintf(fd, "\t{\"SOAP-ENC\", NULL, NULL, NULL},\n");
3602 else
3603 fprintf(fd, "\t{\"%s\", \"%s\", \"%s\", NULL},\n", ns_convert(ns1->name), sp->URI, sp->URI2 ? sp->URI2 : encURI);
3604 }
3605 else if (sp->URI2)
3606 fprintf(fd, "\t{\"%s\", \"%s\", \"%s\", NULL},\n", ns_convert(ns1->name), sp->URI, sp->URI2);
3607 else
3608 fprintf(fd, "\t{\"%s\", \"%s\", NULL, NULL},\n", ns_convert(ns1->name), sp->URI);
3609 }
3610 else if (!strcmp(ns1->name, "SOAP-ENV"))
3611 { if (vflag < 0)
3612 fprintf(fd, "\t{\"SOAP-ENV\", NULL, NULL, NULL},\n");
3613 else if (is_soap12(NULL))
3614 fprintf(fd, "\t{\"SOAP-ENV\", \"%s\", \"http://schemas.xmlsoap.org/soap/envelope/\", NULL},\n", envURI);
3615 else
3616 fprintf(fd, "\t{\"SOAP-ENV\", \"%s\", \"http://www.w3.org/*/soap-envelope\", NULL},\n", envURI);
3617 }
3618 else if (!strcmp(ns1->name, "SOAP-ENC"))
3619 { if (vflag < 0)
3620 fprintf(fd, "\t{\"SOAP-ENC\", NULL, NULL, NULL},\n");
3621 else if (is_soap12(NULL))
3622 fprintf(fd, "\t{\"SOAP-ENC\", \"%s\", \"http://schemas.xmlsoap.org/soap/encoding/\", NULL},\n", encURI);
3623 else
3624 fprintf(fd, "\t{\"SOAP-ENC\", \"%s\", \"http://www.w3.org/*/soap-encoding\", NULL},\n", encURI);
3625 }
3626 else if (!strcmp(ns1->name, "xsi"))
3627 fprintf(fd, "\t{\"xsi\", \"%s\", \"http://www.w3.org/*/XMLSchema-instance\", NULL},\n", xsiURI);
3628 else if (!strcmp(ns1->name, "xsd"))
3629 fprintf(fd, "\t{\"xsd\", \"%s\", \"http://www.w3.org/*/XMLSchema\", NULL},\n", xsdURI);
3630 else
3631 fprintf(fd, "\t{\"%s\", \"%s/%s.xsd\", NULL, NULL},\n", ns_convert(ns1->name), tmpURI, ns_convert(ns1->name));
3632 }
3633 fprintf(fd, "\t{NULL, NULL, NULL, NULL}\n};\n");
3634 }
3635
3636 void
3637 gen_proxy(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
3638 { Entry *p, *q, *r;
3639 Table *t, *output;
3640 Service *sp;
3641 int flag;
3642 char *name1;
3643 name1 = ns_cname(name, NULL);
3644 for (sp = services; sp; sp = sp->next)
3645 if (!tagcmp(sp->ns, ns->name))
3646 break;
3647 fprintf(fd, "\n\n#ifndef %s%sProxy_H\n#define %s%sProxy_H\n#include \"%sH.h\"", prefix, name1, prefix, name1, prefix);
3648 if (nflag)
3649 fprintf(fd, "\nextern SOAP_NMAC struct Namespace %s_namespaces[];", prefix);
3650 if (namespaceid)
3651 fprintf(fd,"\n\nnamespace %s {", namespaceid);
3652 fprintf(fd, "\nclass %s\n{ public:\n\t/// Runtime engine context allocated in constructor\n\tstruct soap *soap;\n\t/// Endpoint URL of service '%s' (change as needed)\n\tconst char *endpoint;\n\t/// Constructor allocates soap engine context, sets default endpoint URL, and sets namespace mapping table\n", name1, name);
3653 if (nflag)
3654 fprintf(fd, "\t%s() { soap = soap_new(); if (soap) soap->namespaces = %s_namespaces; endpoint = \"%s\"; };\n", name1, prefix, URL);
3655 else
3656 { fprintf(fd, "\t%s()\n\t{ soap = soap_new(); endpoint = \"%s\"; if (soap && !soap->namespaces) { static const struct Namespace namespaces[] = \n", name1, URL);
3657 gen_nsmap(fd, ns, URI);
3658 fprintf(fd, "\tsoap->namespaces = namespaces; } };\n");
3659 }
3660 fprintf(fd, "\t/// Destructor frees deserialized data and soap engine context\n\tvirtual ~%s() { if (soap) { soap_destroy(soap); soap_end(soap); soap_free(soap); } };\n", name1);
3661 fflush(fd);
3662 for (r = table->list; r; r = r->next)
3663 if (r->info.typ->type == Tfun && !(r->info.sto & Sextern) && has_ns_eq(ns->name, r->sym->name))
3664 { p = entry(table, r->sym);
3665 if (p)
3666 q = (Entry*)p->info.typ->ref;
3667 else
3668 { fprintf(stderr, "Internal error: no table entry\n");
3669 return;
3670 }
3671 p = entry(classtable, r->sym);
3672 if (!p)
3673 { fprintf(stderr, "Internal error: no parameter table entry\n");
3674 return;
3675 }
3676 output = (Table*)p->info.typ->ref;
3677 /*
3678 if ((s = strstr(r->sym->name, "__")))
3679 s += 2;
3680 else
3681 s = r->sym->name;
3682 fprintf(fd, "\tvirtual int %s(", s);
3683 */
3684 fprintf(fd, "\t/// Invoke '%s' of service '%s' and return error code (or SOAP_OK)\n", ns_remove(r->sym->name), name);
3685 fprintf(fd, "\tvirtual int %s(", ident(r->sym->name));
3686 flag = 0;
3687 for (t = output; t; t = t->prev)
3688 { p = t->list;
3689 if (p)
3690 { fprintf(fd, "%s%s", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name));
3691 for (p = p->next; p; p = p->next)
3692 fprintf(fd, ", %s%s", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name));
3693 flag = 1;
3694 }
3695 }
3696 if (is_transient(q->info.typ))
3697 fprintf(fd,") { return soap ? soap_send_%s(soap, endpoint, NULL", ident(r->sym->name));
3698 else if (flag)
3699 fprintf(fd,", %s%s) { return soap ? soap_call_%s(soap, endpoint, NULL", c_storage(q->info.sto), c_type_id(q->info.typ, q->sym->name), ident(r->sym->name));
3700 else
3701 fprintf(fd,"%s%s) { return soap ? soap_call_%s(soap, endpoint, NULL", c_storage(q->info.sto), c_type_id(q->info.typ, q->sym->name), ident(r->sym->name));
3702 /* the action is now handled by the soap_call/soap_send operation when we pass NULL */
3703 #if 0
3704 m = NULL;
3705 if (sp && (s = strstr(r->sym->name, "__")))
3706 for (m = sp->list; m; m = m->next)
3707 if (m->part && m->mess == ACTION && !strcmp(m->name, s+2))
3708 { if (*m->part == '"')
3709 fprintf(fd, "%s", m->part);
3710 else
3711 fprintf(fd, "\"%s\"", m->part);
3712 break;
3713 }
3714 if (!m)
3715 fprintf(fd, "NULL");
3716 #endif
3717 for (t = output; t; t = t->prev)
3718 for (p = t->list; p; p = p->next)
3719 fprintf(fd, ", %s", ident(p->sym->name));
3720 if (is_transient(q->info.typ))
3721 fprintf(fd,") : SOAP_EOM; };\n");
3722 else
3723 fprintf(fd,", %s) : SOAP_EOM; };\n", ident(q->sym->name));
3724 fflush(fd);
3725 }
3726 fprintf(fd, "};");
3727 if (namespaceid)
3728 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
3729 fprintf(fd, "\n#endif\n");
3730 }
3731
3732 void
3733 gen_object(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
3734 { char *name1;
3735 Entry *method;
3736 name1 = ns_cname(name, NULL);
3737 fprintf(fd, "\n\n#ifndef %s%sObject_H\n#define %s%sObject_H\n#include \"%sH.h\"", prefix, name1, prefix, name1, prefix);
3738 banner(fd, "Service Object");
3739 if (namespaceid)
3740 fprintf(fd,"\n\nnamespace %s {", namespaceid);
3741 fprintf(fd, "\nclass %sService : public soap\n{ public:", name1);
3742 fprintf(fd, "\n\t%sService()\n\t{ static const struct Namespace namespaces[] =\n", name1);
3743 gen_nsmap(fd, ns, URI);
3744 fprintf(fd, "\n\tthis->namespaces = namespaces; };");
3745 fprintf(fd, "\n\tvirtual ~%sService() { };", name1);
3746 fprintf(fd, "\n\t/// Bind service to port (returns master socket or SOAP_INVALID_SOCKET)");
3747 fprintf(fd, "\n\tvirtual\tSOAP_SOCKET bind(const char *host, int port, int backlog) { return soap_bind(this, host, port, backlog); };");
3748 fprintf(fd, "\n\t/// Accept next request (returns socket or SOAP_INVALID_SOCKET)");
3749 fprintf(fd, "\n\tvirtual\tSOAP_SOCKET accept() { return soap_accept(this); };");
3750 fprintf(fd, "\n#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)");
3751 fprintf(fd, "\n\t/// Then accept SSL handshake, when SSL is used");
3752 fprintf(fd, "\n\tvirtual\tint ssl_accept() { return soap_ssl_accept(this); };");
3753 fprintf(fd, "\n#endif");
3754 fprintf(fd, "\n\t/// Serve this request (returns error code or SOAP_OK)");
3755 if (nflag)
3756 fprintf(fd, "\n\tvirtual\tint serve() { return %s_serve(this); };", prefix);
3757 else
3758 fprintf(fd, "\n\tvirtual\tint serve() { return soap_serve(this); };");
3759 fprintf(fd, "\n};");
3760 banner(fd, "Service Operations (you should define these globally)");
3761 for (method = table->list; method; method = method->next)
3762 { if (method->info.typ->type == Tfun && !(method->info.sto & Sextern))
3763 { Entry *p, *q=entry(table, method->sym);
3764 Table *output;
3765 if (q)
3766 p = (Entry*)q->info.typ->ref;
3767 else
3768 { fprintf(stderr, "Internal error: no table entry\n");
3769 return;
3770 }
3771 q = entry(classtable, method->sym);
3772 output = (Table*)q->info.typ->ref;
3773 fprintf(fd, "\n\nSOAP_FMAC5 int SOAP_FMAC6 %s(struct soap*", ident(method->sym->name));
3774 gen_params(fd, output, p, 1);
3775 fprintf(fd, ";");
3776 }
3777 }
3778 if (namespaceid)
3779 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
3780 fprintf(fd, "\n\n#endif\n");
3781 }
3782
3783 void
3784 gen_proxy_header(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
3785 { Entry *p, *method;
3786 Table *t;
3787 fprintf(fd, "\n\n#ifndef %s%s_H\n#define %s%s_H\n#include \"%sH.h\"", prefix, name, prefix, name, prefix);
3788 if (namespaceid)
3789 fprintf(fd,"\n\nnamespace %s {", namespaceid);
3790 if (iflag)
3791 fprintf(fd, "\n\nclass SOAP_CMAC %s : public soap\n{ public:", name);
3792 else
3793 fprintf(fd, "\n\nclass SOAP_CMAC %s\n{ public:", name);
3794 if (!iflag)
3795 fprintf(fd, "\n\tstruct soap *soap;\n\tbool own;");
3796 fprintf(fd, "\n\t/// Endpoint URL of service '%s' (change as needed)", name);
3797 fprintf(fd, "\n\tconst char *soap_endpoint;");
3798 fprintf(fd, "\n\t/// Constructor");
3799 fprintf(fd, "\n\t%s();", name);
3800 if (iflag)
3801 { fprintf(fd, "\n\t/// Construct from another engine state");
3802 fprintf(fd, "\n\t%s(const struct soap&);", name);
3803 }
3804 else
3805 { fprintf(fd, "\n\t/// Constructor to use/share an engine state");
3806 fprintf(fd, "\n\t%s(struct soap*);", name);
3807 }
3808 fprintf(fd, "\n\t/// Constructor with endpoint URL");
3809 fprintf(fd, "\n\t%s(const char *url);", name);
3810 fprintf(fd, "\n\t/// Constructor with engine input+output mode control");
3811 fprintf(fd, "\n\t%s(soap_mode iomode);", name);
3812 fprintf(fd, "\n\t/// Constructor with URL and input+output mode control");
3813 fprintf(fd, "\n\t%s(const char *url, soap_mode iomode);", name);
3814 fprintf(fd, "\n\t/// Constructor with engine input and output mode control");
3815 fprintf(fd, "\n\t%s(soap_mode imode, soap_mode omode);", name);
3816 fprintf(fd, "\n\t/// Destructor frees deserialized data");
3817 fprintf(fd, "\n\tvirtual\t~%s();", name);
3818 fprintf(fd, "\n\t/// Initializer used by constructors");
3819 fprintf(fd, "\n\tvirtual\tvoid %s_init(soap_mode imode, soap_mode omode);", name);
3820 fprintf(fd, "\n\t/// Delete all deserialized data (with soap_destroy and soap_end)");
3821 fprintf(fd, "\n\tvirtual\tvoid destroy();");
3822 fprintf(fd, "\n\t/// Delete all deserialized data and reset to default");
3823 fprintf(fd, "\n\tvirtual\tvoid reset();");
3824 fprintf(fd, "\n\t/// Disables and removes SOAP Header from message");
3825 fprintf(fd, "\n\tvirtual\tvoid soap_noheader();");
3826 if (!namespaceid)
3827 {
3828 p = entry(classtable, lookup("SOAP_ENV__Header"));
3829 if (p)
3830 { t = (Table*)p->info.typ->ref;
3831 if (t && t->list && !is_void(t->list->info.typ))
3832 { fprintf(fd, "\n\t/// Put SOAP Header in message");
3833 fprintf(fd, "\n\tvirtual\tvoid soap_header(");
3834 gen_params(fd, t, NULL, 0);
3835 fprintf(fd, ";");
3836 }
3837 }
3838 }
3839 fprintf(fd, "\n\t/// Get SOAP Header structure (NULL when absent)");
3840 fprintf(fd, "\n\tvirtual\tconst SOAP_ENV__Header *soap_header();");
3841 fprintf(fd, "\n\t/// Get SOAP Fault structure (NULL when absent)");
3842 fprintf(fd, "\n\tvirtual\tconst SOAP_ENV__Fault *soap_fault();");
3843 fprintf(fd, "\n\t/// Get SOAP Fault string (NULL when absent)");
3844 fprintf(fd, "\n\tvirtual\tconst char *soap_fault_string();");
3845 fprintf(fd, "\n\t/// Get SOAP Fault detail as string (NULL when absent)");
3846 fprintf(fd, "\n\tvirtual\tconst char *soap_fault_detail();");
3847 fprintf(fd, "\n\t/// Close connection (normally automatic, except for send_X ops)");
3848 fprintf(fd, "\n\tvirtual\tint soap_close_socket();");
3849 fprintf(fd, "\n\t/// Force close connection (can kill a thread blocked on IO)");
3850 fprintf(fd, "\n\tvirtual\tint soap_force_close_socket();");
3851 fprintf(fd, "\n\t/// Print fault");
3852 fprintf(fd, "\n\tvirtual\tvoid soap_print_fault(FILE*);");
3853 fprintf(fd, "\n#ifndef WITH_LEAN\n\t/// Print fault to stream");
3854 fprintf(fd, "\n#ifndef WITH_COMPAT");
3855 fprintf(fd, "\n\tvirtual\tvoid soap_stream_fault(std::ostream&);");
3856 fprintf(fd, "\n#endif\n");
3857 fprintf(fd, "\n\t/// Put fault into buffer");
3858 fprintf(fd, "\n\tvirtual\tchar *soap_sprint_fault(char *buf, size_t len);\n#endif");
3859 for (method = table->list; method; method = method->next)
3860 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && has_ns_eq(ns->name, method->sym->name))
3861 gen_method(fd, table, method, 0);
3862 fprintf(fd, "\n};");
3863 if (namespaceid)
3864 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
3865 fprintf(fd, "\n#endif\n");
3866 }
3867
3868 void
3869 gen_proxy_code(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
3870 { Entry *p, *method, *param;
3871 Table *t;
3872 char *soap;
3873 if (iflag)
3874 soap = "this";
3875 else
3876 soap = "this->soap";
3877 fprintf(fd, "\n\n#include \"%s%s.h\"", prefix, name);
3878 if (namespaceid)
3879 fprintf(fd,"\n\nnamespace %s {", namespaceid);
3880 if (iflag)
3881 { fprintf(fd, "\n\n%s::%s()\n{\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, name, name);
3882 fprintf(fd, "\n\n%s::%s(const struct soap &_soap) : soap(_soap)\n{ }", name, name);
3883 fprintf(fd, "\n\n%s::%s(const char *url)\n{\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n\tsoap_endpoint = url;\n}", name, name, name);
3884 fprintf(fd, "\n\n%s::%s(soap_mode iomode)\n{\t%s_init(iomode, iomode);\n}", name, name, name);
3885 fprintf(fd, "\n\n%s::%s(const char *url, soap_mode iomode)\n{\t%s_init(iomode, iomode);\n\tsoap_endpoint = url;\n}", name, name, name);
3886 fprintf(fd, "\n\n%s::%s(soap_mode imode, soap_mode omode)\n{\t%s_init(imode, omode);\n}", name, name, name);
3887 fprintf(fd, "\n\n%s::~%s()\n{ }", name, name);
3888 }
3889 else
3890 { fprintf(fd, "\n\n%s::%s()\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, name, name);
3891 fprintf(fd, "\n\n%s::%s(struct soap *_soap)\n{\tthis->soap = _soap;\n\tthis->own = false;\n\t%s_init(_soap->imode, _soap->omode);\n}", name, name, name);
3892 fprintf(fd, "\n\n%s::%s(const char *url)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n\tsoap_endpoint = url;\n}", name, name, name);
3893 fprintf(fd, "\n\n%s::%s(soap_mode iomode)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(iomode, iomode);\n}", name, name, name);
3894 fprintf(fd, "\n\n%s::%s(const char *url, soap_mode iomode)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(iomode, iomode);\n\tsoap_endpoint = url;\n}", name, name, name);
3895 fprintf(fd, "\n\n%s::%s(soap_mode imode, soap_mode omode)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(imode, omode);\n}", name, name, name);
3896 fprintf(fd, "\n\n%s::~%s()\n{\tif (this->own)\n\t\tsoap_free(this->soap);\n}", name, name);
3897 }
3898 fprintf(fd, "\n\nvoid %s::%s_init(soap_mode imode, soap_mode omode)\n{\tsoap_imode(%s, imode);\n\tsoap_omode(%s, omode);\n\tsoap_endpoint = NULL;\n\tstatic const struct Namespace namespaces[] =\n", name, name, soap, soap);
3899 gen_nsmap(fd, ns, URI);
3900 fprintf(fd, "\tsoap_set_namespaces(%s, namespaces);\n}", soap);
3901 fprintf(fd, "\n\nvoid %s::destroy()\n{\tsoap_destroy(%s);\n\tsoap_end(%s);\n}", name, soap, soap);
3902 fprintf(fd, "\n\nvoid %s::reset()\n{\tdestroy();\n\tsoap_done(%s);\n\tsoap_initialize(%s);\n\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, soap, soap, name);
3903 fprintf(fd, "\n\nvoid %s::soap_noheader()\n{\t%s->header = NULL;\n}", name, soap);
3904 if (!namespaceid)
3905 {
3906 p = entry(classtable, lookup("SOAP_ENV__Header"));
3907 if (p)
3908 { t = (Table*)p->info.typ->ref;
3909 if (t && t->list && !is_void(t->list->info.typ))
3910 { fprintf(fd, "\n\nvoid %s::soap_header(", name);
3911 gen_params(fd, t, NULL, 0);
3912 fprintf(fd, "\n{\t::soap_header(%s);", soap);
3913 for (param = t->list; param; param = param->next)
3914 { if (namespaceid)
3915 fprintf(fd, "\n\t((%s::SOAP_ENV__Header*)%s->header)->%s = %s;", namespaceid, soap, ident(param->sym->name), ident(param->sym->name));
3916 else
3917 fprintf(fd, "\n\t%s->header->%s = %s;", soap, ident(param->sym->name), ident(param->sym->name));
3918 }
3919 fprintf(fd, "\n}");
3920 }
3921 }
3922 }
3923 fprintf(fd, "\n\nconst SOAP_ENV__Header *%s::soap_header()\n{\treturn %s->header;\n}", name, soap);
3924 fprintf(fd, "\n\nconst SOAP_ENV__Fault *%s::soap_fault()\n{\treturn %s->fault;\n}", name, soap);
3925 fprintf(fd, "\n\nconst char *%s::soap_fault_string()\n{\treturn *soap_faultstring(%s);\n}", name, soap);
3926 fprintf(fd, "\n\nconst char *%s::soap_fault_detail()\n{\treturn *soap_faultdetail(%s);\n}", name, soap);
3927 fprintf(fd, "\n\nint %s::soap_close_socket()\n{\treturn soap_closesock(%s);\n}", name, soap);
3928 fprintf(fd, "\n\nint %s::soap_force_close_socket()\n{\treturn soap_force_closesock(%s);\n}", name, soap);
3929 fprintf(fd, "\n\nvoid %s::soap_print_fault(FILE *fd)\n{\t::soap_print_fault(%s, fd);\n}", name, soap);
3930 fprintf(fd, "\n\n#ifndef WITH_LEAN\n#ifndef WITH_COMPAT\nvoid %s::soap_stream_fault(std::ostream& os)\n{\t::soap_stream_fault(%s, os);\n}\n#endif", name, soap);
3931 fprintf(fd, "\n\nchar *%s::soap_sprint_fault(char *buf, size_t len)\n{\treturn ::soap_sprint_fault(%s, buf, len);\n}\n#endif", name, soap);
3932 for (method = table->list; method; method = method->next)
3933 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && !is_imported(method->info.typ) && has_ns_eq(ns->name, method->sym->name))
3934 gen_call_method(fd, table, method, name);
3935 if (namespaceid)
3936 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
3937 fprintf(fd,"\n/* End of client proxy code */\n");
3938 }
3939
3940 void
3941 gen_object_header(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
3942 { Entry *p, *method;
3943 Table *t;
3944 fprintf(fd, "\n\n#ifndef %s%s_H\n#define %s%s_H\n#include \"%sH.h\"", prefix, name, prefix, name, prefix);
3945 if (namespaceid)
3946 fprintf(fd,"\n\nnamespace %s {", namespaceid);
3947 if (iflag)
3948 fprintf(fd, "\nclass SOAP_CMAC %s : public soap\n{ public:", name);
3949 else
3950 { fprintf(fd, "\nclass SOAP_CMAC %s\n{ public:", name);
3951 fprintf(fd, "\n\tstruct soap *soap;\n\tbool own;");
3952 }
3953 fprintf(fd, "\n\t/// Constructor");
3954 fprintf(fd, "\n\t%s();", name);
3955 if (iflag)
3956 { fprintf(fd, "\n\t/// Construct from another engine state");
3957 fprintf(fd, "\n\t%s(const struct soap&);", name);
3958 }
3959 else
3960 { fprintf(fd, "\n\t/// Constructor to use/share an engine state");
3961 fprintf(fd, "\n\t%s(struct soap*);", name);
3962 }
3963 fprintf(fd, "\n\t/// Constructor with engine input+output mode control");
3964 fprintf(fd, "\n\t%s(soap_mode iomode);", name);
3965 fprintf(fd, "\n\t/// Constructor with engine input and output mode control");
3966 fprintf(fd, "\n\t%s(soap_mode imode, soap_mode omode);", name);
3967 fprintf(fd, "\n\t/// Destructor, also frees all deserialized data");
3968 fprintf(fd, "\n\tvirtual ~%s();", name);
3969 fprintf(fd, "\n\t/// Delete all deserialized data (with soap_destroy and soap_end)");
3970 fprintf(fd, "\n\tvirtual\tvoid destroy();");
3971 fprintf(fd, "\n\t/// Delete all deserialized data and reset to defaults");
3972 fprintf(fd, "\n\tvirtual\tvoid reset();");
3973 fprintf(fd, "\n\t/// Initializer used by constructor");
3974 fprintf(fd, "\n\tvirtual\tvoid %s_init(soap_mode imode, soap_mode omode);", name);
3975 fprintf(fd, "\n\t/// Create a copy");
3976 fprintf(fd, "\n\tvirtual\t%s *copy() SOAP_PURE_VIRTUAL;", name);
3977 fprintf(fd, "\n\t/// Close connection (normally automatic)");
3978 fprintf(fd, "\n\tvirtual\tint soap_close_socket();");
3979 fprintf(fd, "\n\t/// Force close connection (can kill a thread blocked on IO)");
3980 fprintf(fd, "\n\tvirtual\tint soap_force_close_socket();");
3981 fprintf(fd, "\n\t/// Return sender-related fault to sender");
3982 fprintf(fd, "\n\tvirtual\tint soap_senderfault(const char *string, const char *detailXML);");
3983 fprintf(fd, "\n\t/// Return sender-related fault with SOAP 1.2 subcode to sender");
3984 fprintf(fd, "\n\tvirtual\tint soap_senderfault(const char *subcodeQName, const char *string, const char *detailXML);");
3985 fprintf(fd, "\n\t/// Return receiver-related fault to sender");
3986 fprintf(fd, "\n\tvirtual\tint soap_receiverfault(const char *string, const char *detailXML);");
3987 fprintf(fd, "\n\t/// Return receiver-related fault with SOAP 1.2 subcode to sender");
3988 fprintf(fd, "\n\tvirtual\tint soap_receiverfault(const char *subcodeQName, const char *string, const char *detailXML);");
3989 fprintf(fd, "\n\t/// Print fault");
3990 fprintf(fd, "\n\tvirtual\tvoid soap_print_fault(FILE*);");
3991 fprintf(fd, "\n#ifndef WITH_LEAN\n\t/// Print fault to stream");
3992 fprintf(fd, "\n#ifndef WITH_COMPAT");
3993 fprintf(fd, "\n\tvirtual\tvoid soap_stream_fault(std::ostream&);");
3994 fprintf(fd, "\n#endif");
3995 fprintf(fd, "\n\t/// Put fault into buffer");
3996 fprintf(fd, "\n\tvirtual\tchar *soap_sprint_fault(char *buf, size_t len);\n#endif");
3997 fprintf(fd, "\n\t/// Disables and removes SOAP Header from message");
3998 fprintf(fd, "\n\tvirtual\tvoid soap_noheader();");
3999 if (!namespaceid)
4000 {
4001 p = entry(classtable, lookup("SOAP_ENV__Header"));
4002 if (p)
4003 { t = (Table*)p->info.typ->ref;
4004 if (t && t->list && !is_void(t->list->info.typ))
4005 { fprintf(fd, "\n\t/// Put SOAP Header in message");
4006 fprintf(fd, "\n\tvirtual\tvoid soap_header(");
4007 gen_params(fd, t, NULL, 0);
4008 fprintf(fd, ";");
4009 }
4010 }
4011 }
4012 fprintf(fd, "\n\t/// Get SOAP Header structure (NULL when absent)");
4013 fprintf(fd, "\n\tvirtual\tconst SOAP_ENV__Header *soap_header();");
4014 fprintf(fd, "\n\t/// Run simple single-thread iterative service on port until a connection error occurs (returns error code or SOAP_OK), use this->bind_flag = SO_REUSEADDR to rebind for a rerun");
4015 fprintf(fd, "\n\tvirtual\tint run(int port);");
4016 fprintf(fd, "\n\t/// Bind service to port (returns master socket or SOAP_INVALID_SOCKET)");
4017 fprintf(fd, "\n\tvirtual\tSOAP_SOCKET bind(const char *host, int port, int backlog);");
4018 fprintf(fd, "\n\t/// Accept next request (returns socket or SOAP_INVALID_SOCKET)");
4019 fprintf(fd, "\n\tvirtual\tSOAP_SOCKET accept();");
4020 fprintf(fd, "\n#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)");
4021 fprintf(fd, "\n\t/// Then accept SSL handshake, when SSL is used");
4022 fprintf(fd, "\n\tvirtual\tint ssl_accept();");
4023 fprintf(fd, "\n#endif");
4024 fprintf(fd, "\n\t/// Serve this request (returns error code or SOAP_OK)");
4025 fprintf(fd, "\n\tvirtual\tint serve();");
4026 fprintf(fd, "\n\t/// Used by serve() to dispatch a request (returns error code or SOAP_OK)");
4027 fprintf(fd, "\n\tvirtual\tint dispatch();");
4028 fprintf(fd, "\n\n\t///\n\t/// Service operations (you should define these):\n\t/// Note: compile with -DWITH_PURE_VIRTUAL for pure virtual methods\n\t///");
4029 for (method = table->list; method; method = method->next)
4030 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && has_ns_eq(ns->name, method->sym->name))
4031 gen_method(fd, table, method, 1);
4032 fprintf(fd, "\n};");
4033 if (namespaceid)
4034 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
4035 fprintf(fd, "\n#endif\n");
4036 }
4037
4038 void
4039 gen_method(FILE *fd, Table *table, Entry *method, int server)
4040 { Table *params;
4041 Entry *result, *p;
4042 char *soap;
4043 if (iflag)
4044 soap = "this";
4045 else
4046 soap = "this->soap";
4047 result = (Entry*)method->info.typ->ref;
4048 p = entry(classtable, method->sym);
4049 if (!p)
4050 execerror("no table entry");
4051 params = (Table*)p->info.typ->ref;
4052 if (server || !is_transient(result->info.typ))
4053 { if (is_transient(result->info.typ))
4054 fprintf(fd, "\n\n\t/// Web service one-way operation '%s' (return error code, SOAP_OK (no response), or send_%s_empty_response())", ns_remove(method->sym->name), ns_remove(method->sym->name));
4055 else
4056 fprintf(fd, "\n\n\t/// Web service operation '%s' (returns error code or SOAP_OK)", ns_remove(method->sym->name));
4057 fprintf(fd, "\n\tvirtual\tint %s(", ns_cname(method->sym->name, NULL));
4058 gen_params(fd, params, result, 0);
4059 if (!server)
4060 { fprintf(fd, " { return this->%s(NULL, NULL", ns_cname(method->sym->name, NULL));
4061 gen_args(fd, params, result, 1);
4062 fprintf(fd, "; }");
4063 fprintf(fd, "\n\tvirtual\tint %s(const char *endpoint, const char *soap_action", ns_cname(method->sym->name, NULL));
4064 gen_params(fd, params, result, 1);
4065 }
4066 if (server)
4067 fprintf(fd, " SOAP_PURE_VIRTUAL;");
4068 else
4069 fprintf(fd, ";");
4070 if (is_transient(result->info.typ))
4071 fprintf(fd, "\n\tvirtual\tint send_%s_empty_response(int httpcode) { return soap_send_empty_response(%s, httpcode); }", ns_cname(method->sym->name, NULL), soap);
4072 }
4073 else
4074 { fprintf(fd, "\n\n\t/// Web service one-way send operation 'send_%s' (returns error code or SOAP_OK)", ns_remove(method->sym->name));
4075 fprintf(fd, "\n\tvirtual\tint send_%s(", ns_cname(method->sym->name, NULL));
4076 gen_params(fd, params, result, 0);
4077 fprintf(fd, " { return this->send_%s(NULL, NULL", ns_cname(method->sym->name, NULL));
4078 gen_args(fd, params, result, 1);
4079 fprintf(fd, "; }");
4080 fprintf(fd, "\n\tvirtual\tint send_%s(const char *endpoint, const char *soap_action", ns_cname(method->sym->name, NULL));
4081 gen_params(fd, params, result, 1);
4082 fprintf(fd, ";\n\t/// Web service one-way receive operation 'recv_%s' (returns error code or SOAP_OK)", ns_remove(method->sym->name));
4083 fprintf(fd, ";\n\tvirtual\tint recv_%s(", ns_cname(method->sym->name, NULL));
4084 fprintf(fd, "struct %s&);", ident(method->sym->name));
4085 fprintf(fd, "\n\t/// Web service receive of HTTP Accept acknowledgment for one-way send operation 'send_%s' (returns error code or SOAP_OK)", ns_remove(method->sym->name));
4086 fprintf(fd, "\n\tvirtual\tint recv_%s_empty_response() { return soap_recv_empty_response(%s); }", ns_cname(method->sym->name, NULL), soap);
4087 fprintf(fd, "\n\t/// Web service one-way synchronous send operation '%s' with HTTP Accept/OK response receive (returns error code or SOAP_OK)", ns_remove(method->sym->name));
4088 fprintf(fd, "\n\tvirtual\tint %s(", ns_cname(method->sym->name, NULL));
4089 gen_params(fd, params, result, 0);
4090 fprintf(fd, " { return this->%s(NULL, NULL", ns_cname(method->sym->name, NULL));
4091 gen_args(fd, params, result, 1);
4092 fprintf(fd, "; }");
4093 fprintf(fd, "\n\tvirtual\tint %s(const char *endpoint, const char *soap_action", ns_cname(method->sym->name, NULL));
4094 gen_params(fd, params, result, 1);
4095 fprintf(fd, " { if (this->send_%s(endpoint, soap_action", ns_cname(method->sym->name, NULL));
4096 gen_args(fd, params, result, 1);
4097 fprintf(fd, " || soap_recv_empty_response(%s)) return %s->error; return SOAP_OK; }", soap, soap);
4098 }
4099 }
4100
4101 void
4102 gen_params(FILE *fd, Table *params, Entry *result, int flag)
4103 { Entry *param;
4104 for (param = params->list; param; param = param->next)
4105 fprintf(fd, "%s%s%s", flag || param != params->list ? ", " : "", c_storage(param->info.sto), c_type_id(param->info.typ, param->sym->name));
4106 if (!result || is_transient(result->info.typ))
4107 fprintf(fd, ")");
4108 else
4109 fprintf(fd, "%s%s%s)", flag || params->list ? ", " : "", c_storage(result->info.sto), c_type_id(result->info.typ, result->sym->name));
4110 }
4111
4112 void
4113 gen_args(FILE *fd, Table *params, Entry *result, int flag)
4114 { Entry *param;
4115 for (param = params->list; param; param = param->next)
4116 fprintf(fd, "%s%s", flag || param != params->list ? ", " : "", param->sym->name);
4117 if (!result || is_transient(result->info.typ))
4118 fprintf(fd, ")");
4119 else
4120 fprintf(fd, "%s%s)", flag || params->list ? ", " : "", result->sym->name);
4121 }
4122
4123 void
4124 gen_query_url(FILE *fd, Table *params)
4125 { Entry *param;
4126 int flag = 0;
4127 fprintf(fd, "\n\tif (\n#ifdef HAVE_SNPRINTF\n\tsoap_snprintf(soap->msgbuf, sizeof(soap->msgbuf),\n#else\n\tsprintf(soap->msgbuf,\n#endif\n\t\t\"%%s?");
4128 for (param = params->list; param; param = param->next)
4129 if (!is_transient(param->info.typ) && is_primitive_or_string(param->info.typ))
4130 fprintf(fd, "%s%s=%s", flag++ ? "&" : "", ns_remove(param->sym->name), gen_format(fd, param->info.typ));
4131 fprintf(fd, "\", soap_endpoint");
4132 for (param = params->list; param; param = param->next)
4133 { if (!is_transient(param->info.typ) && is_primitive_or_string(param->info.typ))
4134 { if (is_stdstring(param->info.typ))
4135 fprintf(fd, ", soap_encode_url_string(soap, %s.c_str())", ident(param->sym->name));
4136 else if (is_string(param->info.typ))
4137 fprintf(fd, ", soap_encode_url_string(soap, %s)", ident(param->sym->name));
4138 else if (is_primitive(param->info.typ))
4139 fprintf(fd, ", %s", ident(param->sym->name));
4140 }
4141 }
4142 fprintf(fd, ") < 0)\n\t{\tsoap->error = SOAP_EOM;\n\t\treturn soap_closesock(soap);\n\t}");
4143 }
4144
4145 void
4146 gen_query_form(FILE *fd, Table *params)
4147 { Entry *param;
4148 int flag = 0;
4149 fprintf(fd, "\n\tif (");
4150 for (param = params->list; param; param = param->next)
4151 { if (!is_transient(param->info.typ) && is_primitive_or_string(param->info.typ))
4152 { fprintf(fd, "soap_send(soap, \"%s%s=\")", flag++ ? "&" : "", ns_remove(param->sym->name));
4153 if (is_stdstring(param->info.typ))
4154 fprintf(fd, " || soap_send(soap, soap_encode_url_string(soap, %s.c_str()))\n\t || ", ident(param->sym->name));
4155 else if (is_string(param->info.typ))
4156 fprintf(fd, " || soap_send(soap_encode_url_string(soap, %s))\n\t || ", ident(param->sym->name));
4157 else if (is_primitive(param->info.typ))
4158 fprintf(fd, " || soap_send(soap, soap_%s2s(soap, %s))\n\t || ", c_ident(param->info.typ), ident(param->sym->name));
4159 }
4160 }
4161 }
4162
4163 const char*
4164 gen_format(FILE *fd, Tnode *typ)
4165 { if (is_string(typ) || is_stdstring(typ))
4166 return "%s";
4167 switch (typ->type)
4168 { case Tchar: return "%hhd";
4169 case Tshort: return "%hd";
4170 case Tint: return "%d";
4171 case Tlong: return "%ld";
4172 case Tllong: return SOAP_LONG_FORMAT;
4173 case Tfloat: return "%.9G";
4174 case Tdouble: return "%.17lG";
4175 case Tuchar: return "%hhu";
4176 case Tushort: return "%hu";
4177 case Tuint: return "%u";
4178 case Tulong: return "%lu";
4179 case Tullong: return SOAP_ULONG_FORMAT;
4180 default: return "";
4181 }
4182 }
4183
4184 void
4185 gen_call_method(FILE *fd, Table *table, Entry *method, char *name)
4186 { Service *sp;
4187 Method *m;
4188 int soap = (vflag >= 0);
4189 int version = vflag;
4190 int get = 0;
4191 int put = 0;
4192 int post = 0;
4193 int mime = 0;
4194 const char *style, *encoding;
4195 const char *xtag, *xtyp;
4196 const char *action = NULL, *method_encoding = NULL, *method_response_encoding = NULL;
4197 Table *params;
4198 Entry *param, *result, *p, *response = NULL;
4199 result = (Entry*)method->info.typ->ref;
4200 p = entry(classtable, method->sym);
4201 if (!p)
4202 execerror("no table entry");
4203 params = (Table*)p->info.typ->ref;
4204 if (!is_response(result->info.typ) && !is_XML(result->info.typ))
4205 response = get_response(method->info.typ);
4206 if (name)
4207 { if (!is_transient(result->info.typ))
4208 fprintf(fd, "\n\nint %s::%s(const char *endpoint, const char *soap_action", name, ns_cname(method->sym->name, NULL));
4209 else
4210 fprintf(fd, "\n\nint %s::send_%s(const char *endpoint, const char *soap_action", name, ns_cname(method->sym->name, NULL));
4211 gen_params(fd, params, result, 1);
4212 }
4213 else if (!is_transient(result->info.typ))
4214 { fprintf(fheader, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_call_%s(struct soap *soap, const char *soap_endpoint, const char *soap_action", ident(method->sym->name));
4215 gen_params(fheader, params, result, 1);
4216 fprintf(fd, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_call_%s(struct soap *soap, const char *soap_endpoint, const char *soap_action", ident(method->sym->name));
4217 gen_params(fd, params, result, 1);
4218 }
4219 else
4220 { fprintf(fheader, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_send_%s(struct soap *soap, const char *soap_endpoint, const char *soap_action", ident(method->sym->name));
4221 gen_params(fheader, params, result, 1);
4222 fprintf(fd, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_send_%s(struct soap *soap, const char *soap_endpoint, const char *soap_action", ident(method->sym->name));
4223 gen_params(fd, params, result, 1);
4224 }
4225 if (name)
4226 { if (iflag)
4227 fprintf(fd, "\n{\tstruct soap *soap = this;\n");
4228 else
4229 fprintf(fd, "\n{\tstruct soap *soap = this->soap;\n");
4230 }
4231 else
4232 { fprintf(fheader, ";");
4233 fprintf(fd, "\n{");
4234 }
4235 for (sp = services; sp; sp = sp->next)
4236 { if (has_ns_eq(sp->ns, method->sym->name))
4237 { style = sp->style;
4238 encoding = sp->encoding;
4239 method_encoding = encoding;
4240 method_response_encoding = NULL;
4241 if (sp->protocol)
4242 { if (strstr(sp->protocol, "GET"))
4243 get = 1;
4244 else if (strstr(sp->protocol, "POST"))
4245 post = 1;
4246 else if (strstr(sp->protocol, "PUT"))
4247 put = 1;
4248 if (strncmp(sp->protocol, "SOAP", 4))
4249 soap = 0;
4250 else if (strlen(sp->protocol) > 6)
4251 version = sp->protocol[6] - '0';
4252 }
4253 for (m = sp->list; m; m = m->next)
4254 { if (is_eq_nons(m->name, method->sym->name))
4255 { if (m->mess == ACTION || m->mess == REQUEST_ACTION)
4256 action = m->part;
4257 else if (m->mess == ENCODING)
4258 method_encoding = m->part;
4259 else if (m->mess == RESPONSE_ENCODING)
4260 method_response_encoding = m->part;
4261 else if (m->mess == PROTOCOL)
4262 { if (strstr(m->part, "GET"))
4263 get = 1;
4264 else if (strstr(m->part, "POST"))
4265 post = 1;
4266 else if (strstr(m->part, "PUT"))
4267 put = 1;
4268 if (strncmp(m->part, "SOAP", 4))
4269 soap = 0;
4270 else if (strlen(m->part) > 6)
4271 version = m->part[6] - '0';
4272 }
4273 else if (m->mess&MIMEIN && !strcmp(m->part, "application/x-www-form-urlencoded"))
4274 mime = 1;
4275 }
4276 }
4277 break;
4278 }
4279 }
4280 if (!get && !mime)
4281 fprintf(fd, "\tstruct %s soap_tmp_%s;", ident(method->sym->name), ident(method->sym->name));
4282 if (response)
4283 fprintf(fd, "\n\tstruct %s *soap_tmp_%s;", c_ident(response->info.typ), c_ident(response->info.typ));
4284 if (name)
4285 fprintf(fd, "\n\tif (endpoint)\n\t\tsoap_endpoint = endpoint;");
4286 if (sp && sp->URL)
4287 fprintf(fd, "\n\tif (soap_endpoint == NULL)\n\t\tsoap_endpoint = \"%s\";", sp->URL);
4288 if (action)
4289 { fprintf(fd, "\n\tif (soap_action == NULL)\n\t\tsoap_action = ");
4290 if (*action == '"')
4291 fprintf(fd, "%s;", action);
4292 else
4293 fprintf(fd, "\"%s\";", action);
4294 }
4295 if (!method_response_encoding)
4296 method_response_encoding = method_encoding;
4297 if (!get && !mime)
4298 { fprintf(fd, "\n\tsoap_begin(soap);");
4299 if (soap && sp && sp->URI && method_encoding)
4300 { if (is_literal(method_encoding))
4301 fprintf(fd, "\n\tsoap->encodingStyle = NULL;");
4302 else if (method_encoding)
4303 fprintf(fd, "\n\tsoap->encodingStyle = \"%s\";", method_encoding);
4304 }
4305 else if (!soap || !eflag)
4306 fprintf(fd, "\n\tsoap->encodingStyle = NULL;");
4307 for (param = params->list; param; param = param->next)
4308 { if (param->info.typ->type == Tarray)
4309 fprintf(fd, "\n\tmemcpy(soap_tmp_%s.%s, %s, sizeof(%s));", ident(method->sym->name), ident(param->sym->name), ident(param->sym->name), c_type(param->info.typ));
4310 else
4311 fprintf(fd, "\n\tsoap_tmp_%s.%s = %s;", ident(method->sym->name), ident(param->sym->name), ident(param->sym->name));
4312 }
4313 if (!soap)
4314 fprintf(fd, "\n\tsoap_set_version(soap, 0); /* no SOAP */");
4315 else if (version)
4316 fprintf(fd, "\n\tsoap_set_version(soap, %d); /* SOAP1.%d */", version, version);
4317 if (soap)
4318 fprintf(fd, "\n\tsoap_serializeheader(soap);");
4319 fprintf(fd, "\n\tsoap_serialize_%s(soap, &soap_tmp_%s);", ident(method->sym->name), ident(method->sym->name));
4320 fprintf(fd, "\n\tif (soap_begin_count(soap))\n\t\treturn soap->error;");
4321 fprintf(fd, "\n\tif (soap->mode & SOAP_IO_LENGTH)");
4322 fprintf(fd, "\n\t{\tif (soap_envelope_begin_out(soap)");
4323 if (soap)
4324 { fprintf(fd, "\n\t\t || soap_putheader(soap)");
4325 fprintf(fd, "\n\t\t || soap_body_begin_out(soap)");
4326 }
4327 fprintf(fd, "\n\t\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", ident(method->sym->name), ident(method->sym->name), ns_convert(method->sym->name));
4328 if (soap)
4329 fprintf(fd, "\n\t\t || soap_body_end_out(soap)");
4330 fprintf(fd, "\n\t\t || soap_envelope_end_out(soap))");
4331 fprintf(fd, "\n\t\t\t return soap->error;");
4332 fprintf(fd, "\n\t}");
4333 fprintf(fd, "\n\tif (soap_end_count(soap))\n\t\treturn soap->error;");
4334 if (soap)
4335 fprintf(fd, "\n\tif (soap_connect(soap, soap_url(soap, soap_endpoint, NULL), soap_action)");
4336 else
4337 { fprintf(fd, "\n\tsoap->http_content = \"text/xml\";");
4338 if (put)
4339 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_PUT, soap_url(soap, soap_endpoint, soap_action), soap_action)");
4340 else
4341 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_POST_FILE, soap_url(soap, soap_endpoint, soap_action), soap_action)");
4342 }
4343 fprintf(fd, "\n\t || soap_envelope_begin_out(soap)");
4344 if (soap)
4345 { fprintf(fd, "\n\t || soap_putheader(soap)");
4346 fprintf(fd, "\n\t || soap_body_begin_out(soap)");
4347 }
4348 fprintf(fd, "\n\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", ident(method->sym->name), ident(method->sym->name), ns_convert(method->sym->name));
4349 if (soap)
4350 fprintf(fd, "\n\t || soap_body_end_out(soap)");
4351 fprintf(fd, "\n\t || soap_envelope_end_out(soap)");
4352 fprintf(fd, "\n\t || soap_end_send(soap))");
4353 fprintf(fd, "\n\t\treturn soap_closesock(soap);");
4354 }
4355 else if (get)
4356 { if (params->list)
4357 { gen_query_url(fd, params);
4358 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_GET, soap->msgbuf, soap_action))");
4359 }
4360 else if (soap)
4361 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_GET, soap_url(soap, soap_endpoint, NULL), soap_action))");
4362 else
4363 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_GET, soap_url(soap, soap_endpoint, soap_action), soap_action))");
4364 fprintf(fd, "\n\t\treturn soap_closesock(soap);");
4365 }
4366 else if (mime)
4367 { fprintf(fd, "\n\tsoap->http_content = \"application/x-www-form-urlencoded\";");
4368 if (post)
4369 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_POST_FILE, soap_url(soap, soap_endpoint, soap_action), soap_action))");
4370 else if (put)
4371 fprintf(fd, "\n\tif (soap_connect_command(soap, SOAP_PUT, soap_url(soap, soap_endpoint, soap_action), soap_action))");
4372 fprintf(fd, "\n\t\treturn soap_closesock(soap);");
4373 gen_query_form(fd, params);
4374 fprintf(fd, "soap_end_send(soap))\n\t\treturn soap_closesock(soap);");
4375 }
4376 if (is_transient(result->info.typ))
4377 { fprintf(fd, "\n\treturn SOAP_OK;\n}");
4378 if (name)
4379 { fprintf(fd, "\n\nint %s::recv_%s(", name, ns_cname(method->sym->name, NULL));
4380 fprintf(fd, "struct %s& tmp)", ident(method->sym->name));
4381 if (iflag)
4382 fprintf(fd, "\n{\tstruct soap *soap = this;\n");
4383 else
4384 fprintf(fd, "\n{\tstruct soap *soap = this->soap;\n");
4385 fprintf(fd, "\n\tstruct %s *%s = &tmp;", ident(method->sym->name), ident(result->sym->name));
4386 }
4387 else
4388 { fprintf(fheader, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_recv_%s(struct soap *soap, ", ident(method->sym->name));
4389 fprintf(fd, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_recv_%s(struct soap *soap, ", ident(method->sym->name));
4390 fprintf(fheader, "struct %s *%s);\n", ident(method->sym->name), ident(result->sym->name));
4391 fprintf(fd, "struct %s *%s)\n{", ident(method->sym->name), ident(result->sym->name));
4392 }
4393 fprintf(fd, "\n\tsoap_default_%s(soap, %s);", ident(method->sym->name), ident(result->sym->name));
4394 fprintf(fd, "\n\tsoap_begin(soap);");
4395 }
4396 else if (result->info.typ->type == Tarray)
4397 fprintf(fd, "\n\tsoap_default_%s(soap, %s);", c_ident(result->info.typ), ident(result->sym->name));
4398 else if (result->info.typ->type == Treference && ((Tnode*)result->info.typ->ref)->type == Tclass && !is_external((Tnode*)result->info.typ->ref) && !is_volatile((Tnode*)result->info.typ->ref))
4399 fprintf(fd, "\n\tif (!&%s)\n\t\treturn soap_closesock(soap);\n\t%s.soap_default(soap);", ident(result->sym->name), ident(result->sym->name));
4400 else if (((Tnode*)result->info.typ->ref)->type == Tclass && !is_external((Tnode*)result->info.typ->ref) && !is_volatile((Tnode*)result->info.typ->ref))
4401 fprintf(fd, "\n\tif (!%s)\n\t\treturn soap_closesock(soap);\n\t%s->soap_default(soap);", ident(result->sym->name), ident(result->sym->name));
4402 else if (result->info.typ->type == Treference && ((Tnode*)result->info.typ->ref)->type == Tpointer)
4403 fprintf(fd, "\n\t%s = NULL;", ident(result->sym->name));
4404 else if (((Tnode*)result->info.typ->ref)->type == Tpointer)
4405 fprintf(fd, "\n\tif (!%s)\n\t\treturn soap_closesock(soap);\n\t*%s = NULL;", ident(result->sym->name), ident(result->sym->name));
4406 else if (result->info.typ->type == Treference)
4407 fprintf(fd, "\n\tif (!&%s)\n\t\treturn soap_closesock(soap);\n\tsoap_default_%s(soap, &%s);", ident(result->sym->name), c_ident((Tnode*)result->info.typ->ref), ident(result->sym->name));
4408 else if (!is_void(result->info.typ))
4409 fprintf(fd, "\n\tif (!%s)\n\t\treturn soap_closesock(soap);\n\tsoap_default_%s(soap, %s);", ident(result->sym->name), c_ident((Tnode*)result->info.typ->ref), ident(result->sym->name));
4410 fprintf(fd,"\n\tif (soap_begin_recv(soap)");
4411 fprintf(fd,"\n\t || soap_envelope_begin_in(soap)");
4412 fprintf(fd,"\n\t || soap_recv_header(soap)");
4413 fprintf(fd,"\n\t || soap_body_begin_in(soap))");
4414 fprintf(fd,"\n\t\treturn soap_closesock(soap);");
4415 if (is_transient(result->info.typ))
4416 { fprintf(fd,"\n\tsoap_get_%s(soap, %s, \"%s\", NULL);", ident(method->sym->name), ident(result->sym->name), ns_convert(method->sym->name));
4417 fprintf(fd,"\n\tif (soap->error == SOAP_TAG_MISMATCH && soap->level == 2)\n\t\tsoap->error = SOAP_OK;");
4418 fprintf(fd,"\n\tif (soap->error");
4419 fprintf(fd,"\n\t || soap_body_end_in(soap)");
4420 fprintf(fd,"\n\t || soap_envelope_end_in(soap)");
4421 fprintf(fd,"\n\t || soap_end_recv(soap))");
4422 fprintf(fd,"\n\t\treturn soap_closesock(soap);");
4423 fprintf(fd,"\n\treturn soap_closesock(soap);\n}");
4424 fflush(fd);
4425 return;
4426 }
4427 /* With RPC encoded responses, try to parse the fault first */
4428 if (!is_literal(method_response_encoding))
4429 { fprintf(fd,"\n\tif (soap_recv_fault(soap, 1))\n\t\treturn soap->error;");
4430 xtag = xtyp = "";
4431 }
4432 else if (has_ns_eq(NULL, result->sym->name))
4433 { if (response)
4434 xtag = xml_tag(response->info.typ);
4435 else
4436 xtag = ns_convert(result->sym->name);
4437 xtyp = xsi_type(result->info.typ);
4438 }
4439 else
4440 { if (response)
4441 xtag = xml_tag(response->info.typ);
4442 else
4443 xtag = xml_tag(result->info.typ);
4444 xtyp = "";
4445 }
4446 if (response)
4447 { fprintf(fd,"\n\tsoap_tmp_%s = soap_get_%s(soap, NULL, \"%s\", \"%s\");", c_ident(response->info.typ), c_ident(response->info.typ), xtag, xtyp);
4448 fprintf(fd,"\n\tif (!soap_tmp_%s || soap->error)\n\t\treturn soap_recv_fault(soap, 0);", c_ident(response->info.typ));
4449 }
4450 else if ((result->info.typ->type == Treference || result->info.typ->type == Tpointer) && !is_invisible_empty(result->info.typ->ref))
4451 { if (result->info.typ->type == Treference && ((Tnode *) result->info.typ->ref)->type == Tclass && !is_external((Tnode*)result->info.typ->ref) && !is_volatile((Tnode*)result->info.typ->ref) && !is_dynamic_array((Tnode*)result->info.typ->ref))
4452 fprintf(fd,"\n\t%s.soap_get(soap, \"%s\", \"%s\");", ident(result->sym->name), xtag, xtyp);
4453 else if (result->info.typ->type == Tpointer && ((Tnode *) result->info.typ->ref)->type == Tclass && !is_external((Tnode*)result->info.typ->ref) && !is_volatile((Tnode*)result->info.typ->ref) && !is_dynamic_array((Tnode*)result->info.typ->ref))
4454 fprintf(fd,"\n\t%s->soap_get(soap, \"%s\", \"%s\");", ident(result->sym->name), xtag, xtyp);
4455 else if (result->info.typ->type == Treference && ((Tnode *) result->info.typ->ref)->type == Tstruct && !is_external((Tnode*)result->info.typ->ref) && !is_volatile((Tnode*)result->info.typ->ref) && !is_dynamic_array((Tnode*)result->info.typ->ref))
4456 { fprintf(fd,"\n\tsoap_get_%s(soap, &%s, \"%s\", \"%s\");", c_ident((Tnode*)result->info.typ->ref), ident(result->sym->name), xtag, xtyp);
4457 }
4458 else if (result->info.typ->type == Tpointer && ((Tnode *) result->info.typ->ref)->type == Tstruct && !is_dynamic_array((Tnode*)result->info.typ->ref))
4459 {
4460 fprintf(fd,"\n\tsoap_get_%s(soap, %s, \"%s\", \"%s\");", c_ident((Tnode*)result->info.typ->ref), ident(result->sym->name), xtag, xtyp);
4461 }
4462 else if (result->info.typ->type == Tpointer && is_XML((Tnode*)result->info.typ->ref) && is_string((Tnode*)result->info.typ->ref))
4463 { fprintf(fd,"\n\tsoap_inliteral(soap, NULL, %s);", ident(result->sym->name));
4464 }
4465 else if (result->info.typ->type == Treference && is_XML((Tnode*)result->info.typ->ref) && is_string((Tnode*)result->info.typ->ref))
4466 { fprintf(fd,"\n\tsoap_inliteral(soap, NULL, &%s);", ident(result->sym->name));
4467 }
4468 else if (result->info.typ->type == Tpointer && is_XML((Tnode*)result->info.typ->ref) && is_wstring((Tnode*)result->info.typ->ref))
4469 { fprintf(fd,"\n\tsoap_inwliteral(soap, NULL, %s);", ident(result->sym->name));
4470 }
4471 else if (result->info.typ->type == Treference && is_XML((Tnode*)result->info.typ->ref) && is_wstring((Tnode*)result->info.typ->ref))
4472 { fprintf(fd,"\n\tsoap_inwliteral(soap, NULL, &%s);", ident(result->sym->name));
4473 }
4474 else if (result->info.typ->type == Treference)
4475 { fprintf(fd,"\n\tsoap_get_%s(soap, &%s, \"%s\", \"%s\");", c_ident(result->info.typ), ident(result->sym->name), xtag, xtyp);
4476 }
4477 else
4478 { fprintf(fd,"\n\tsoap_get_%s(soap, %s, \"%s\", \"%s\");", c_ident(result->info.typ), ident(result->sym->name), xtag, xtyp);
4479 }
4480 fprintf(fd,"\n\tif (soap->error)\n\t\treturn soap_recv_fault(soap, 0);");
4481 }
4482 fflush(fd);
4483 fprintf(fd,"\n\tif (soap_body_end_in(soap)");
4484 fprintf(fd,"\n\t || soap_envelope_end_in(soap)");
4485 fprintf(fd,"\n\t || soap_end_recv(soap))");
4486 fprintf(fd,"\n\t\treturn soap_closesock(soap);");
4487 if (response)
4488 { if (result->info.typ->type == Tarray)
4489 fprintf(fd,"\n\tmemcpy(%s, soap_tmp_%s->%s, sizeof(%s));", ident(result->sym->name), c_ident(response->info.typ), ident(result->sym->name), ident(result->sym->name));
4490 else if (result->info.typ->type == Treference)
4491 fprintf(fd,"\n\t%s = soap_tmp_%s->%s;", ident(result->sym->name), c_ident(response->info.typ), ident(result->sym->name));
4492 else if (!is_external((Tnode*)result->info.typ->ref))
4493 { fprintf(fd,"\n\tif (%s && soap_tmp_%s->%s)", ident(result->sym->name), c_ident(response->info.typ), ident(result->sym->name));
4494 fprintf(fd,"\n\t\t*%s = *soap_tmp_%s->%s;", ident(result->sym->name), c_ident(response->info.typ), ident(result->sym->name));
4495 }
4496 }
4497 fprintf(fd,"\n\treturn soap_closesock(soap);");
4498 fprintf(fd ,"\n}");
4499 fflush(fd);
4500 }
4501
4502 void
4503 gen_serve_method(FILE *fd, Table *table, Entry *param, char *name)
4504 { Service *sp = NULL;
4505 char *style, *encoding;
4506 Entry *result, *p, *q, *pin, *pout, *response = NULL;
4507 Table *input;
4508 char *xtag;
4509 Method *m;
4510 char *method_encoding = NULL, *method_response_encoding = NULL;
4511 result = (Entry*)param->info.typ->ref;
4512 p = entry(classtable, param->sym);
4513 if (!p)
4514 execerror("no table entry");
4515 if (!is_response(result->info.typ) && !is_XML(result->info.typ))
4516 response = get_response(param->info.typ);
4517 q = entry(table, param->sym);
4518 if (!q)
4519 execerror("no table entry");
4520 pout = (Entry*)q->info.typ->ref;
4521 if (name)
4522 { if (iflag)
4523 fprintf(fd, "\n\nstatic int serve_%s(%s *soap)\n{", ident(param->sym->name), name);
4524 else
4525 fprintf(fd, "\n\nstatic int serve_%s(%s *service)\n{\tstruct soap *soap = service->soap;\n", ident(param->sym->name), name);
4526 }
4527 else
4528 { fprintf(fheader, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_serve_%s(struct soap*);", ident(param->sym->name));
4529 fprintf(fd, "\n\nSOAP_FMAC5 int SOAP_FMAC6 soap_serve_%s(struct soap *soap)\n{", ident(param->sym->name));
4530 }
4531 fprintf(fd, "\tstruct %s soap_tmp_%s;", ident(param->sym->name), ident(param->sym->name));
4532 for (sp = services; sp; sp = sp->next)
4533 if (has_ns_eq(sp->ns, param->sym->name))
4534 { style = sp->style;
4535 encoding = sp->encoding;
4536 method_encoding = encoding;
4537 method_response_encoding = NULL;
4538 for (m = sp->list; m; m = m->next)
4539 { if (is_eq_nons(m->name, param->sym->name))
4540 { if (m->mess == ENCODING)
4541 method_encoding = m->part;
4542 else if (m->mess == RESPONSE_ENCODING)
4543 method_response_encoding = m->part;
4544 }
4545 }
4546 break;
4547 }
4548 if (!method_response_encoding)
4549 method_response_encoding = method_encoding;
4550 fflush(fd);
4551 if (!is_transient(pout->info.typ))
4552 { if (pout->info.typ->type == Tarray && response)
4553 { fprintf(fd,"\n\tstruct %s soap_tmp_%s;", c_ident(response->info.typ), c_ident(response->info.typ));
4554 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", c_ident(response->info.typ), c_ident(response->info.typ));
4555 }
4556 else if (pout->info.typ->type == Tpointer && !is_stdstring(pout->info.typ) && !is_stdwstring(pout->info.typ) && response)
4557 { fprintf(fd,"\n\tstruct %s soap_tmp_%s;", c_ident(response->info.typ), c_ident(response->info.typ));
4558 fprintf(fd,"\n\t%s soap_tmp_%s;", c_type((Tnode*)pout->info.typ->ref), c_ident((Tnode*)pout->info.typ->ref));
4559 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", c_ident(response->info.typ), c_ident(response->info.typ));
4560 if (((Tnode*)pout->info.typ->ref)->type == Tclass && !is_external((Tnode*)pout->info.typ->ref) && !is_volatile((Tnode*)pout->info.typ->ref) && !is_typedef((Tnode*)pout->info.typ->ref))
4561 fprintf(fd,"\n\tsoap_tmp_%s.soap_default(soap);", c_ident((Tnode*)pout->info.typ->ref));
4562 else if (((Tnode*)pout->info.typ->ref)->type == Tpointer)
4563 fprintf(fd,"\n\tsoap_tmp_%s = NULL;", c_ident((Tnode*)pout->info.typ->ref));
4564 else
4565 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", c_ident((Tnode*)pout->info.typ->ref), c_ident((Tnode*)pout->info.typ->ref));
4566 fprintf(fd,"\n\tsoap_tmp_%s.%s = &soap_tmp_%s;", c_ident(response->info.typ), ident(pout->sym->name), c_ident((Tnode*)pout->info.typ->ref));
4567 }
4568 else if (response)
4569 { fprintf(fd,"\n\tstruct %s soap_tmp_%s;", c_ident(response->info.typ), c_ident(response->info.typ));
4570 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", c_ident(response->info.typ), c_ident(response->info.typ));
4571 }
4572 else if (((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && (is_external((Tnode*)pout->info.typ->ref) || is_volatile((Tnode*)pout->info.typ->ref) || is_typedef((Tnode*)pout->info.typ->ref)) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4573 { fprintf(fd, "\n\t%s %s;", c_type((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4574 fprintf(fd,"\n\tsoap_default_%s(soap, &%s);", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4575 }
4576 else if (((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4577 { fprintf(fd, "\n\t%s %s;", c_type((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4578 fprintf(fd,"\n\t%s.soap_default(soap);", ident(pout->sym->name));
4579 }
4580 else if (((Tnode *)pout->info.typ->ref)->type == Tstruct && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4581 { fprintf(fd, "\n\t%s %s;", c_type((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4582 fprintf(fd,"\n\tsoap_default_%s(soap, &%s);", c_ident((Tnode *)pout->info.typ->ref), ident(pout->sym->name));
4583 }
4584 else
4585 { fprintf(fd,"\n\t%s soap_tmp_%s;", c_type((Tnode*)pout->info.typ->ref), c_ident((Tnode*)pout->info.typ->ref));
4586 if (is_string((Tnode*)pout->info.typ->ref) || is_wstring((Tnode*)pout->info.typ->ref))
4587 fprintf(fd,"\n\tsoap_tmp_%s = NULL;", c_ident((Tnode*)pout->info.typ->ref));
4588 else
4589 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", c_ident((Tnode*)pout->info.typ->ref), c_ident((Tnode*)pout->info.typ->ref));
4590 }
4591 }
4592 fprintf(fd,"\n\tsoap_default_%s(soap, &soap_tmp_%s);", ident(param->sym->name), ident(param->sym->name));
4593 fflush(fd);
4594 q = entry(classtable, param->sym);
4595 if (!is_invisible_empty(q->info.typ))
4596 { fprintf(fd,"\n\tif (!soap_get_%s(soap, &soap_tmp_%s, \"%s\", NULL))", ident(param->sym->name), ident(param->sym->name), ns_convert(param->sym->name));
4597 fprintf(fd,"\n\t\treturn soap->error;");
4598 }
4599 fprintf(fd,"\n\tif (soap_body_end_in(soap)");
4600 fprintf(fd,"\n\t || soap_envelope_end_in(soap)");
4601 fprintf(fd,"\n\t || soap_end_recv(soap))\n\t\treturn soap->error;");
4602 if (name)
4603 { if (iflag)
4604 fprintf(fd, "\n\tsoap->error = soap->%s(", ns_cname(param->sym->name, NULL));
4605 else
4606 fprintf(fd, "\n\tsoap->error = service->%s(", ns_cname(param->sym->name, NULL));
4607 }
4608 else
4609 fprintf(fd, "\n\tsoap->error = %s(soap", ident(param->sym->name));
4610 fflush(fd);
4611 input = (Table*) q->info.typ->ref;
4612 for (pin = input->list; pin; pin = pin->next)
4613 fprintf(fd, "%ssoap_tmp_%s.%s", !name || pin != input->list ? ", " : "", ident(param->sym->name), ident(pin->sym->name));
4614 if (is_transient(pout->info.typ))
4615 fprintf(fd, ");");
4616 else
4617 { if (!name || input->list)
4618 fprintf(fd, ", ");
4619 if (response)
4620 fprintf(fd, "soap_tmp_%s.%s);", c_ident(response->info.typ), ident(pout->sym->name));
4621 else if (pout->info.typ->type == Treference && (((Tnode*)pout->info.typ->ref)->type == Tstruct || ((Tnode*)pout->info.typ->ref)->type == Tclass) && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4622 fprintf(fd, "%s);", ident(pout->sym->name));
4623 else if ((((Tnode*)pout->info.typ->ref)->type == Tstruct || ((Tnode*)pout->info.typ->ref)->type == Tclass) && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4624 fprintf(fd, "&%s);", ident(pout->sym->name));
4625 else if(pout->info.typ->type == Treference)
4626 fprintf(fd, "soap_tmp_%s);", c_ident((Tnode*)pout->info.typ->ref));
4627 else
4628 fprintf(fd, "&soap_tmp_%s);", c_ident((Tnode*)pout->info.typ->ref));
4629 }
4630 fprintf(fd,"\n\tif (soap->error)\n\t\treturn soap->error;");
4631 if (!is_transient(pout->info.typ))
4632 { if (sp && sp->URI && method_response_encoding)
4633 { if (is_literal(method_response_encoding))
4634 fprintf(fd, "\n\tsoap->encodingStyle = NULL;");
4635 else if (sp->encoding)
4636 fprintf(fd, "\n\tsoap->encodingStyle = \"%s\";", sp->encoding);
4637 else if (method_response_encoding)
4638 fprintf(fd, "\n\tsoap->encodingStyle = \"%s\";", method_response_encoding);
4639 else if (!eflag)
4640 fprintf(fd, "\n\tsoap->encodingStyle = NULL;");
4641 }
4642 else if (!eflag)
4643 fprintf(fd, "\n\tsoap->encodingStyle = NULL;");
4644 fprintf(fd,"\n\tsoap_serializeheader(soap);");
4645 if (pout->info.typ->type == Tarray && response)
4646 fprintf(fd, "\n\tsoap_serialize_%s(soap, &soap_tmp_%s);", c_ident(response->info.typ), c_ident(response->info.typ));
4647 else if (response)
4648 fprintf(fd, "\n\tsoap_serialize_%s(soap, &soap_tmp_%s);", c_ident(response->info.typ), c_ident(response->info.typ));
4649 else if (((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && (is_external((Tnode*)pout->info.typ->ref) || is_volatile((Tnode*)pout->info.typ->ref) || is_typedef((Tnode*)pout->info.typ->ref)) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4650 fprintf(fd, "\n\tsoap_serialize_%s(soap, &%s);", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4651 else if(((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4652 fprintf(fd, "\n\t%s.soap_serialize(soap);", ident(pout->sym->name));
4653 else if(((Tnode *)pout->info.typ->ref)->type == Tstruct && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4654 fprintf(fd, "\n\tsoap_serialize_%s(soap, &%s);", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name));
4655 else if (!is_XML((Tnode*)pout->info.typ->ref))
4656 fprintf(fd, "\n\tsoap_serialize_%s(soap, &soap_tmp_%s);", c_ident((Tnode*)pout->info.typ->ref), c_ident((Tnode*)pout->info.typ->ref));
4657 if (has_ns_eq(NULL, pout->sym->name))
4658 xtag = ns_convert(pout->sym->name);
4659 else
4660 xtag = xml_tag(pout->info.typ);
4661 fprintf(fd, "\n\tif (soap_begin_count(soap))\n\t\treturn soap->error;");
4662 fprintf(fd, "\n\tif (soap->mode & SOAP_IO_LENGTH)");
4663 fprintf(fd, "\n\t{\tif (soap_envelope_begin_out(soap)");
4664 fprintf(fd,"\n\t\t || soap_putheader(soap)");
4665 fprintf(fd,"\n\t\t || soap_body_begin_out(soap)");
4666 if (response)
4667 fprintf(fd,"\n\t\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", c_ident(response->info.typ), c_ident(response->info.typ), xml_tag(response->info.typ));
4668 else if (((Tnode*)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && (is_external((Tnode*)pout->info.typ->ref) || is_volatile((Tnode*)pout->info.typ->ref) || is_typedef((Tnode*)pout->info.typ->ref)) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4669 fprintf(fd, "\n\t\t || soap_put_%s(soap, &%s, \"%s\", NULL)", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name), ns_convert(pout->sym->name));
4670 else if (((Tnode*)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4671 fprintf(fd, "\n\t\t || %s.soap_put(soap, \"%s\", \"\")", ident(pout->sym->name), xtag);
4672 else if (((Tnode*)pout->info.typ->ref)->type == Tstruct && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4673 fprintf(fd, "\n\t\t || soap_put_%s(soap, &%s, \"%s\", NULL)", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name), xtag);
4674 else if (is_XML((Tnode*)pout->info.typ->ref) && is_string((Tnode*)pout->info.typ->ref))
4675 fprintf(fd,"\n\t\t || soap_outliteral(soap, \"%s\", &soap_tmp_%s, NULL)", ns_convert(pout->sym->name), c_ident((Tnode*)pout->info.typ->ref));
4676 else if (is_XML((Tnode*)pout->info.typ->ref) && is_wstring((Tnode*)pout->info.typ->ref))
4677 fprintf(fd,"\n\t\t || soap_outwliteral(soap, \"%s\", &soap_tmp_%s, NULL)", ns_convert(pout->sym->name), c_ident((Tnode*)pout->info.typ->ref));
4678 else
4679 fprintf(fd,"\n\t\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", c_ident(pout->info.typ), c_ident((Tnode*)pout->info.typ->ref), ns_convert(pout->sym->name));
4680 fprintf(fd,"\n\t\t || soap_body_end_out(soap)");
4681 fprintf(fd,"\n\t\t || soap_envelope_end_out(soap))");
4682 fprintf(fd,"\n\t\t\t return soap->error;");
4683 fprintf(fd,"\n\t};");
4684 fprintf(fd,"\n\tif (soap_end_count(soap)");
4685 fprintf(fd,"\n\t || soap_response(soap, SOAP_OK)");
4686 fprintf(fd,"\n\t || soap_envelope_begin_out(soap)");
4687 fprintf(fd,"\n\t || soap_putheader(soap)");
4688 fprintf(fd,"\n\t || soap_body_begin_out(soap)");
4689 if (response)
4690 fprintf(fd,"\n\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", c_ident(response->info.typ), c_ident(response->info.typ), xml_tag(response->info.typ));
4691 else if (((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && (is_external((Tnode*)pout->info.typ->ref) || is_volatile((Tnode*)pout->info.typ->ref) || is_typedef((Tnode*)pout->info.typ->ref)) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4692 fprintf(fd, "\n\t || soap_put_%s(soap, &%s, \"%s\", NULL)", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name), ns_convert(pout->sym->name));
4693 else if(((Tnode *)pout->info.typ->ref)->type == Tclass && !is_stdstring((Tnode*)pout->info.typ->ref) && !is_stdwstring((Tnode*)pout->info.typ->ref) && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4694 fprintf(fd, "\n\t || %s.soap_put(soap, \"%s\", \"\")", ident(pout->sym->name), xtag);
4695 else if(((Tnode *)pout->info.typ->ref)->type == Tstruct && !is_dynamic_array((Tnode*)pout->info.typ->ref))
4696 fprintf(fd, "\n\t || soap_put_%s(soap, &%s, \"%s\", NULL)", c_ident((Tnode*)pout->info.typ->ref), ident(pout->sym->name), xtag);
4697 else if (is_XML((Tnode*)pout->info.typ->ref) && is_string((Tnode*)pout->info.typ->ref))
4698 fprintf(fd,"\n\t || soap_outliteral(soap, \"%s\", &soap_tmp_%s, NULL)", ns_convert(pout->sym->name), c_ident((Tnode*)pout->info.typ->ref));
4699 else if (is_XML((Tnode*)pout->info.typ->ref) && is_wstring((Tnode*)pout->info.typ->ref))
4700 fprintf(fd,"\n\t || soap_outwliteral(soap, \"%s\", &soap_tmp_%s, NULL)", ns_convert(pout->sym->name), c_ident((Tnode*)pout->info.typ->ref));
4701 else
4702 fprintf(fd,"\n\t || soap_put_%s(soap, &soap_tmp_%s, \"%s\", NULL)", c_ident(pout->info.typ), c_ident((Tnode*)pout->info.typ->ref), ns_convert(pout->sym->name));
4703 fprintf(fd,"\n\t || soap_body_end_out(soap)");
4704 fprintf(fd,"\n\t || soap_envelope_end_out(soap)");
4705 fprintf(fd,"\n\t || soap_end_send(soap))");
4706 fprintf(fd, "\n\t\treturn soap->error;");
4707 }
4708 fprintf(fd,"\n\treturn soap_closesock(soap);");
4709 fprintf(fd,"\n}");
4710 fflush(fd);
4711 }
4712
4713 void
4714 gen_object_code(FILE *fd, Table *table, Symbol *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
4715 { Entry *p, *method, *catch_method, *param;
4716 Table *t;
4717 char *soap, *catch_action;
4718 if (iflag)
4719 soap = "this";
4720 else
4721 soap = "this->soap";
4722 fprintf(fd, "\n\n#include \"%s%s.h\"", prefix, name);
4723 if (namespaceid)
4724 fprintf(fd,"\n\nnamespace %s {", namespaceid);
4725 if (iflag)
4726 { fprintf(fd, "\n\n%s::%s()\n{\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, name, name);
4727 fprintf(fd, "\n\n%s::%s(const struct soap &_soap) : soap(_soap)\n{ }", name, name);
4728 fprintf(fd, "\n\n%s::%s(soap_mode iomode)\n{\t%s_init(iomode, iomode);\n}", name, name, name);
4729 fprintf(fd, "\n\n%s::%s(soap_mode imode, soap_mode omode)\n{\t%s_init(imode, omode);\n}", name, name, name);
4730 fprintf(fd, "\n\n%s::~%s()\n{ }", name, name);
4731 }
4732 else
4733 { fprintf(fd, "\n\n%s::%s()\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, name, name);
4734 fprintf(fd, "\n\n%s::%s(struct soap *_soap)\n{\tthis->soap = _soap;\n\tthis->own = false;\n\t%s_init(_soap->imode, _soap->omode);\n}", name, name, name);
4735 fprintf(fd, "\n\n%s::%s(soap_mode iomode)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(iomode, iomode);\n}", name, name, name);
4736 fprintf(fd, "\n\n%s::%s(soap_mode imode, soap_mode omode)\n{\tthis->soap = soap_new();\n\tthis->own = true;\n\t%s_init(imode, omode);\n}", name, name, name);
4737 fprintf(fd, "\n\n%s::~%s()\n{\tif (this->own)\n\t\tsoap_free(this->soap);\n}", name, name);
4738 }
4739 fprintf(fd, "\n\nvoid %s::%s_init(soap_mode imode, soap_mode omode)\n{\tsoap_imode(%s, imode);\n\tsoap_omode(%s, omode);\n\tstatic const struct Namespace namespaces[] =\n", name, name, soap, soap);
4740 gen_nsmap(fd, ns, URI);
4741 fprintf(fd, "\tsoap_set_namespaces(%s, namespaces);\n}", soap);
4742 fprintf(fd, "\n\nvoid %s::destroy()\n{\tsoap_destroy(%s);\n\tsoap_end(%s);\n}", name, soap, soap);
4743 fprintf(fd, "\n\nvoid %s::reset()\n{\tdestroy();\n\tsoap_done(%s);\n\tsoap_initialize(%s);\n\t%s_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);\n}", name, soap, soap, name);
4744 if (iflag)
4745 fprintf(fd, "\n\n#ifndef WITH_PURE_VIRTUAL\n%s *%s::copy()\n{\t%s *dup = SOAP_NEW_COPY(%s(*(struct soap*)%s));\n\treturn dup;\n}\n#endif", name, name, name, name, soap);
4746 else
4747 fprintf(fd, "\n\n#ifndef WITH_PURE_VIRTUAL\n%s *%s::copy()\n{\t%s *dup = SOAP_NEW_COPY(%s);\n\tif (dup)\n\t\tsoap_copy_context(dup->soap, this->soap);\n\treturn dup;\n}\n#endif", name, name, name, name);
4748 fprintf(fd, "\n\nint %s::soap_close_socket()\n{\treturn soap_closesock(%s);\n}", name, soap);
4749 fprintf(fd, "\n\nint %s::soap_force_close_socket()\n{\treturn soap_force_closesock(%s);\n}", name, soap);
4750 fprintf(fd, "\n\nint %s::soap_senderfault(const char *string, const char *detailXML)\n{\treturn ::soap_sender_fault(%s, string, detailXML);\n}", name, soap);
4751 fprintf(fd, "\n\nint %s::soap_senderfault(const char *subcodeQName, const char *string, const char *detailXML)\n{\treturn ::soap_sender_fault_subcode(%s, subcodeQName, string, detailXML);\n}", name, soap);
4752 fprintf(fd, "\n\nint %s::soap_receiverfault(const char *string, const char *detailXML)\n{\treturn ::soap_receiver_fault(%s, string, detailXML);\n}", name, soap);
4753 fprintf(fd, "\n\nint %s::soap_receiverfault(const char *subcodeQName, const char *string, const char *detailXML)\n{\treturn ::soap_receiver_fault_subcode(%s, subcodeQName, string, detailXML);\n}", name, soap);
4754 fprintf(fd, "\n\nvoid %s::soap_print_fault(FILE *fd)\n{\t::soap_print_fault(%s, fd);\n}", name, soap);
4755 fprintf(fd, "\n\n#ifndef WITH_LEAN\n#ifndef WITH_COMPAT\nvoid %s::soap_stream_fault(std::ostream& os)\n{\t::soap_stream_fault(%s, os);\n}\n#endif", name, soap);
4756 fprintf(fd, "\n\nchar *%s::soap_sprint_fault(char *buf, size_t len)\n{\treturn ::soap_sprint_fault(%s, buf, len);\n}\n#endif", name, soap);
4757 fprintf(fd, "\n\nvoid %s::soap_noheader()\n{\t%s->header = NULL;\n}", name, soap);
4758 if (!namespaceid)
4759 {
4760 p = entry(classtable, lookup("SOAP_ENV__Header"));
4761 if (p)
4762 { t = (Table*)p->info.typ->ref;
4763 if (t && t->list && !is_void(t->list->info.typ))
4764 { fprintf(fd, "\n\nvoid %s::soap_header(", name);
4765 gen_params(fd, t, NULL, 0);
4766 fprintf(fd, "\n{\t::soap_header(%s);", soap);
4767 for (param = t->list; param; param = param->next)
4768 { if (namespaceid)
4769 fprintf(fd, "\n\t((%s::SOAP_ENV__Header*)%s->header)->%s = %s;", namespaceid, soap, ident(param->sym->name), ident(param->sym->name));
4770 else
4771 fprintf(fd, "\n\t%s->header->%s = %s;", soap, ident(param->sym->name), ident(param->sym->name));
4772 }
4773 fprintf(fd, "\n}");
4774 }
4775 }
4776 }
4777 fprintf(fd, "\n\nconst SOAP_ENV__Header *%s::soap_header()\n{\treturn %s->header;\n}", name, soap);
4778 fprintf(fd, "\n\nint %s::run(int port)\n{\tif (soap_valid_socket(%s->master) || soap_valid_socket(bind(NULL, port, 100)))\n\t{\tfor (;;)\n\t\t{\tif (!soap_valid_socket(accept()) || serve())\n\t\t\t\treturn %s->error;\n\t\t\tsoap_destroy(%s);\n\t\t\tsoap_end(%s);\n\t\t}\n\t}\n\telse\n\t\treturn %s->error;\n\treturn SOAP_OK;\n}", name, soap, soap, soap, soap, soap);
4779 fprintf(fd, "\n\nSOAP_SOCKET %s::bind(const char *host, int port, int backlog)\n{\treturn soap_bind(%s, host, port, backlog);\n}", name, soap);
4780 fprintf(fd, "\n\nSOAP_SOCKET %s::accept()\n{\treturn soap_accept(%s);\n}", name, soap);
4781 fprintf(fd, "\n\n#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)");
4782 fprintf(fd, "\nint %s::ssl_accept()\n{\treturn soap_ssl_accept(%s);\n}", name, soap);
4783 fprintf(fd, "\n#endif");
4784 fprintf(fd, "\n\nint %s::serve()", name);
4785 fprintf(fd, "\n{\n#ifndef WITH_FASTCGI\n\tunsigned int k = %s->max_keep_alive;\n#endif\n\tdo\n\t{", soap);
4786 fprintf(fd,"\n\n#ifndef WITH_FASTCGI\n\t\tif (%s->max_keep_alive > 0 && !--k)\n\t\t\t%s->keep_alive = 0;\n#endif", soap, soap);
4787 fprintf(fd,"\n\n\t\tif (soap_begin_serve(%s))\n\t\t{\tif (%s->error >= SOAP_STOP)\n\t\t\t\tcontinue;\n\t\t\treturn %s->error;\n\t\t}", soap, soap, soap);
4788 fprintf(fd,"\n\t\tif (dispatch() || (%s->fserveloop && %s->fserveloop(%s)))\n\t\t{\n#ifdef WITH_FASTCGI\n\t\t\tsoap_send_fault(%s);\n#else\n\t\t\treturn soap_send_fault(%s);\n#endif\n\t\t}", soap, soap, soap, soap, soap);
4789 fprintf(fd,"\n\n#ifdef WITH_FASTCGI\n\t\tsoap_destroy(%s);\n\t\tsoap_end(%s);\n\t} while (1);\n#else\n\t} while (%s->keep_alive);\n#endif", soap, soap, soap);
4790 fprintf(fd, "\n\treturn SOAP_OK;");
4791 fprintf(fd, "\n}\n");
4792 for (method = table->list; method; method = method->next)
4793 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && has_ns_eq(ns->name, method->sym->name))
4794 fprintf(fd, "\nstatic int serve_%s(%s*);", ident(method->sym->name), name);
4795 fprintf(fd, "\n\nint %s::dispatch()\n{", name);
4796 if (!iflag)
4797 fprintf(fd, "\t%s_init(this->soap->imode, this->soap->omode);\n", name);
4798 fprintf(fd, "\tsoap_peek_element(%s);", soap);
4799 catch_method = NULL;
4800 catch_action = NULL;
4801 for (method = table->list; method; method = method->next)
4802 { char *action = NULL;
4803 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && has_ns_eq(ns->name, method->sym->name))
4804 { if (aflag)
4805 { Service *sp;
4806 for (sp = services; sp; sp = sp->next)
4807 { if (has_ns_eq(sp->ns, method->sym->name))
4808 { Method *m;
4809 for (m = sp->list; m; m = m->next)
4810 { if (is_eq_nons(m->name, method->sym->name))
4811 { if (m->mess == ACTION || m->mess == REQUEST_ACTION)
4812 action = m->part;
4813 }
4814 }
4815 }
4816 }
4817 }
4818 if (is_invisible(method->sym->name))
4819 { Entry *param = entry(classtable, method->sym);
4820 if (param)
4821 param = ((Table*)param->info.typ->ref)->list;
4822 if (action)
4823 { if (*action == '"')
4824 { fprintf(fd, "\n\tif (");
4825 if (param && !Aflag)
4826 fprintf(fd, "(!%s->action && !soap_match_tag(%s, %s->tag, \"%s\")) || ", soap, soap, soap, ns_convert(param->sym->name));
4827 else
4828 { catch_method = method;
4829 catch_action = action;
4830 }
4831 fprintf(fd, "(%s->action && !strcmp(%s->action, %s))", soap, soap, action);
4832 }
4833 else
4834 { fprintf(fd, "\n\tif (");
4835 if (param && !Aflag)
4836 fprintf(fd, "(!%s->action && !soap_match_tag(%s, %s->tag, \"%s\")) || ", soap, soap, soap, ns_convert(param->sym->name));
4837 else
4838 { catch_method = method;
4839 catch_action = action;
4840 }
4841 fprintf(fd, "(%s->action && !strcmp(%s->action, \"%s\"))", soap, soap, action);
4842 }
4843 fprintf(fd, ")\n\t\treturn serve_%s(this);", ident(method->sym->name));
4844 }
4845 else
4846 { if (Aflag)
4847 compliancewarn("Option -A requires a SOAPAction where none is defined");
4848 if (param)
4849 { fprintf(fd, "\n\tif (!soap_match_tag(%s, %s->tag, \"%s\")", soap, soap, ns_convert(param->sym->name));
4850 fprintf(fd, ")\n\t\treturn serve_%s(this);", ident(method->sym->name));
4851 }
4852 else
4853 { catch_method = method;
4854 catch_action = action;
4855 }
4856 }
4857 }
4858 else
4859 { if (action)
4860 { if (*action == '"')
4861 { fprintf(fd, "\n\tif (");
4862 if (!Aflag)
4863 fprintf(fd, "(!%s->action && !soap_match_tag(%s, %s->tag, \"%s\")) || ", soap, soap, soap, ns_convert(method->sym->name));
4864 fprintf(fd, "(%s->action && !strcmp(%s->action, %s))", soap, soap, action);
4865 }
4866 else
4867 { fprintf(fd, "\n\tif (");
4868 if (!Aflag)
4869 fprintf(fd, "(!%s->action && !soap_match_tag(%s, %s->tag, \"%s\")) || ", soap, soap, soap, ns_convert(method->sym->name));
4870 fprintf(fd, "(%s->action && !strcmp(%s->action, \"%s\"))", soap, soap, action);
4871 }
4872 }
4873 else
4874 { if (Aflag)
4875 compliancewarn("Option -A requires a SOAPAction where none is defined");
4876 fprintf(fd, "\n\tif (!soap_match_tag(%s, %s->tag, \"%s\")", soap, soap, ns_convert(method->sym->name));
4877 }
4878 fprintf(fd, ")\n\t\treturn serve_%s(this);", ident(method->sym->name));
4879 }
4880 }
4881 }
4882 if (catch_method)
4883 { if (Aflag && catch_action)
4884 { if (*catch_action == '"')
4885 { fprintf(fd, "\n\tif (");
4886 fprintf(fd, "(%s->action && !strcmp(%s->action, %s))", soap, soap, catch_action);
4887 fprintf(fd, ")\n\t\treturn serve_%s(this);", ident(catch_method->sym->name));
4888 }
4889 else
4890 { fprintf(fd, "\n\tif (");
4891 fprintf(fd, "(%s->action && !strcmp(%s->action, \"%s\"))", soap, soap, catch_action);
4892 fprintf(fd, ")\n\t\treturn serve_%s(this);", ident(catch_method->sym->name));
4893 }
4894 fprintf(fd,"\n\treturn %s->error = SOAP_NO_METHOD;", soap);
4895 }
4896 fprintf(fd, "\n\treturn serve_%s(this);\n}", ident(catch_method->sym->name));
4897 }
4898 else
4899 fprintf(fd, "\n\treturn %s->error = SOAP_NO_METHOD;\n}", soap);
4900 for (method = table->list; method; method = method->next)
4901 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && !is_imported(method->info.typ) && has_ns_eq(ns->name, method->sym->name))
4902 gen_serve_method(fd, table, method, name);
4903 if (namespaceid)
4904 fprintf(fd,"\n\n} // namespace %s\n", namespaceid);
4905 fprintf(fd,"\n/* End of server object code */\n");
4906 }
4907
4908 void
4909 gen_response_begin(FILE *fd, int n, char *s)
4910 { if (!is_invisible(s))
4911 { fprintf(fd, "%*s<%sResponse", n, "", s);
4912 if (vflag < 0)
4913 gen_xmlns(fd);
4914 fprintf(fd, ">\n");
4915 }
4916 }
4917
4918 void
4919 gen_response_end(FILE *fd, int n, char *s)
4920 { if (!is_invisible(s))
4921 fprintf(fd, "%*s</%sResponse>\n", n, "", s);
4922 }
4923
4924 void
4925 gen_element_begin(FILE *fd, int n, char *s, char *t)
4926 { if (!is_invisible(s))
4927 { if (tflag && t && *t)
4928 fprintf(fd, "%*s<%s xsi:type=\"%s\"", n, "", s, t);
4929 else
4930 fprintf(fd, "%*s<%s", n, "", s);
4931 }
4932 }
4933
4934 void
4935 gen_element_end(FILE *fd, int n, char *s)
4936 { if (!is_invisible(s))
4937 fprintf(fd, "%*s</%s>\n", n, "", s);
4938 else
4939 fprintf(fd, "\n");
4940 }
4941
4942 void
4943 gen_data(char *buf, Table *t, char *ns, char *name, char *URL, char *executable, char *URI, char *encoding)
4944 { Entry *p, *q, *r;
4945 FILE *fd;
4946 char *method_encoding = NULL;
4947 char *method_response_encoding = NULL;
4948 if (t)
4949 { for (p = t->list; p; p = p->next)
4950 if (p->info.typ->type == Tfun && !(p->info.sto & Sextern) && has_ns_eq(ns, p->sym->name))
4951 { int get = 0, soap = 1, mime = 0;
4952 Service *sp;
4953 Method *m;
4954 char *nse = ns_qualifiedElement(p->info.typ);
4955 char *nsa = ns_qualifiedAttribute(p->info.typ);
4956 method_encoding = encoding;
4957 method_response_encoding = NULL;
4958 for (sp = services; sp; sp = sp->next)
4959 { if (!tagcmp(sp->ns, ns))
4960 { for (m = sp->list; m; m = m->next)
4961 { if (is_eq_nons(m->name, p->sym->name))
4962 { if (m->mess == ENCODING)
4963 method_encoding = m->part;
4964 else if (m->mess == RESPONSE_ENCODING)
4965 method_response_encoding = m->part;
4966 else if (m->mess&MIMEIN && !strcmp(m->part, "application/x-www-form-urlencoded"))
4967 mime = 1;
4968 else if (m->mess == PROTOCOL)
4969 { if (strncmp(m->part, "SOAP", 4))
4970 soap = 0;
4971 if (strstr(m->part, "GET"))
4972 get = 1;
4973 }
4974 }
4975 }
4976 }
4977 }
4978 if (!method_response_encoding)
4979 method_response_encoding = method_encoding;
4980 /* request */
4981 if (!get && !mime)
4982 { fd = gen_env(buf, ns_remove(p->sym->name), 0, t, ns, name, URL, executable, URI, method_encoding, soap);
4983 if (!fd)
4984 return;
4985 q = entry(classtable, p->sym);
4986 if (yflag)
4987 { fprintf(fd, "%*s<!-- %s(...", 2, "", ident(p->sym->name));
4988 if (q)
4989 { Table *r = (Table*)q->info.typ->ref;
4990 while (r)
4991 { Entry *e;
4992 for (e = r->list; e; e = e->next)
4993 fprintf(fd, ", %s", c_type_id(e->info.typ, e->sym->name));
4994 r = r->prev;
4995 }
4996 }
4997 fprintf(fd, ", ...) -->\n");
4998 }
4999 gen_element_begin(fd, 2, ns_convert(p->sym->name), NULL);
5000 if (q)
5001 { if (!is_invisible(p->sym->name))
5002 { if (soap && vflag < 0)
5003 gen_xmlns(fd);
5004 gen_atts(fd, 2, (Table*)q->info.typ->ref, nsa);
5005 fprintf(fd, "\n");
5006 }
5007 for (q = ((Table*)q->info.typ->ref)->list; q; q = q->next)
5008 gen_field(fd, 3, q, nse, nsa, method_encoding);
5009 }
5010 gen_element_end(fd, 2, ns_convert(p->sym->name));
5011 if (soap && vflag >= 0)
5012 fprintf(fd, " </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>\n");
5013 fclose(fd);
5014 }
5015 /* response */
5016 q = (Entry*)p->info.typ->ref;
5017 if (!mime && q && !is_transient(q->info.typ))
5018 { fd = gen_env(buf, ns_remove(p->sym->name), 1, t, ns, name, URL, executable, URI, method_response_encoding, soap);
5019 if (!fd)
5020 return;
5021 if (q && !is_response(q->info.typ))
5022 { if (is_XML((Tnode*)q->info.typ->ref))
5023 { gen_response_begin(fd, 2, ns_convert(p->sym->name));
5024 gen_response_end(fd, 2, ns_convert(p->sym->name));
5025 }
5026 else
5027 { gen_response_begin(fd, 2, ns_convert(p->sym->name));
5028 gen_field(fd, 3, q, nse, nsa, method_response_encoding);
5029 gen_response_end(fd, 2, ns_convert(p->sym->name));
5030 }
5031 }
5032 else if (q && q->info.typ->ref && ((Tnode*)q->info.typ->ref)->ref)
5033 { char *xtag;
5034 nse = ns_qualifiedElement((Tnode*)q->info.typ->ref);
5035 nsa = ns_qualifiedAttribute((Tnode*)q->info.typ->ref);
5036 if (has_ns_eq(NULL, q->sym->name))
5037 xtag = q->sym->name;
5038 else
5039 xtag = ((Tnode*)q->info.typ->ref)->id->name;
5040 if (yflag)
5041 fprintf(fd, "%*s<!-- %s(..., %s) -->\n", 2, "", ident(p->sym->name), c_type_id(q->info.typ, q->sym->name));
5042 gen_element_begin(fd, 2, ns_addx(xtag, nse), NULL);
5043 if (!is_invisible(xtag))
5044 { if (soap && vflag < 0)
5045 gen_xmlns(fd);
5046 gen_atts(fd, 2, ((Tnode*)q->info.typ->ref)->ref, nsa);
5047 fprintf(fd, "\n");
5048 }
5049 for (r = ((Table*)((Tnode*)q->info.typ->ref)->ref)->list; r; r = r->next)
5050 gen_field(fd, 3, r, nse, nsa, method_response_encoding);
5051 gen_element_end(fd, 2, ns_addx(xtag, nse));
5052 }
5053 fflush(fd);
5054 if (soap && vflag >= 0)
5055 fprintf(fd, " </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>\n");
5056 fclose(fd);
5057 }
5058 }
5059 }
5060 }
5061
5062 void
5063 gen_field(FILE *fd, int n, Entry *p, char *nse, char *nsa, char *encoding)
5064 { Entry *q;
5065 char tmp[32];
5066 LONG64 i;
5067 int d;
5068 if (!(p->info.sto & (Sattribute | Sconst | Sprivate | Sprotected)) && !is_transient(p->info.typ) && p->info.typ->type != Tfun && strncmp(p->sym->name, "__size", 6) && strncmp(p->sym->name, "__type", 6) && !is_choice(p))
5069 { if (is_soap12(encoding) && (p->info.sto & Sreturn) && (nse || has_ns_eq(NULL, p->sym->name)) && !is_literal(encoding))
5070 fprintf(fd, "%*s<SOAP-RPC:result xmlns:SOAP-RPC=\"%s\">%s</SOAP-RPC:result>\n", n, "", rpcURI, ns_add(p, nse));
5071 if (is_XML(p->info.typ))
5072 { if (yflag)
5073 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5074 gen_element_begin(fd, n, ns_add(p, nse), NULL);
5075 if (!is_invisible(p->sym->name))
5076 fprintf(fd, ">");
5077 else
5078 fprintf(fd, "%*s<!-- extensibility element(s) -->\n", n, "");
5079 gen_element_end(fd, n, ns_add(p, nse));
5080 }
5081 else
5082 { if (!is_string(p->info.typ) && n >= 10 && p->info.minOccurs <= 0)
5083 { /* Do not generate nil, since some tools don't accept it:
5084 if (!is_invisible(p->sym->name))
5085 { gen_element_begin(fd, n, ns_add(p->sym->name, nse), NULL);
5086 fprintf(fd, " xsi:nil=\"true\"/>");
5087 }
5088 */
5089 return;
5090 }
5091 else if (n >= 20)
5092 { fprintf(fd, "%*s<!-- WARNING max depth exceeded: schema appears to incorrectly define infinitely large documents in recursion over mandatory elements with minOccurs>0 -->\n", n, "");
5093 return;
5094 }
5095 else if (is_fixedstring(p->info.typ))
5096 { if (yflag)
5097 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5098 gen_element_begin(fd, n, ns_add(p, nse), xsi_type(p->info.typ));
5099 fprintf(fd, ">");
5100 fflush(fd);
5101 if (p->info.hasval)
5102 fprintf(fd, "%s", xstring(p->info.val.s));
5103 else
5104 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5105 }
5106 else if (p->info.typ->type == Tarray)
5107 { i = ((Tnode*) p->info.typ->ref)->width;
5108 if (i)
5109 { i = p->info.typ->width / i;
5110 if (i > 4)
5111 i = 2;
5112 }
5113 if (yflag)
5114 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5115 gen_element_begin(fd, n, ns_add(p, nse), "SOAP-ENC:Array");
5116 fprintf(fd, " SOAP-ENC:arrayType=\"%s[" SOAP_LONG_FORMAT "]\">", xsi_type_Tarray(p->info.typ), i);
5117 fflush(fd);
5118 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5119 }
5120 else if (is_dynamic_array(p->info.typ) && !is_binary(p->info.typ))
5121 { if (!eflag && (has_ns(p->info.typ) || is_untyped(p->info.typ)))
5122 { if (yflag)
5123 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5124 gen_element_begin(fd, n, ns_add(p, nse), xsi_type(p->info.typ));
5125 gen_atts(fd, n, (Table*)p->info.typ->ref, nsa);
5126 }
5127 else
5128 { d = get_Darraydims(p->info.typ);
5129 if (d)
5130 { for (i = 0; i < d-1; i++)
5131 { tmp[2*i] = ',';
5132 tmp[2*i+1] = '1';
5133 }
5134 tmp[2*d-2] = '\0';
5135 }
5136 else
5137 *tmp = '\0';
5138 if (yflag)
5139 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5140 gen_element_begin(fd, n, ns_add(p, nse), "SOAP-ENC:Array");
5141 if (((Table*)p->info.typ->ref)->list->info.minOccurs > 0)
5142 fprintf(fd, " SOAP-ENC:arrayType=\"%s[" SOAP_LONG_FORMAT "%s]\">", wsdl_type(((Table*)p->info.typ->ref)->list->info.typ, ""), ((Table*)p->info.typ->ref)->list->info.minOccurs, tmp);
5143 else
5144 fprintf(fd, " SOAP-ENC:arrayType=\"%s[1%s]\">", wsdl_type(((Table*)p->info.typ->ref)->list->info.typ, ""), tmp);
5145 }
5146 fflush(fd);
5147 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5148 }
5149 else if ((p->info.typ->type == Tpointer || p->info.typ->type == Treference) && is_dynamic_array((Tnode*)p->info.typ->ref) && !is_binary((Tnode*)p->info.typ->ref))
5150 { if (!eflag && (has_ns((Tnode*)p->info.typ->ref) || is_untyped((Tnode*)p->info.typ->ref)))
5151 { if (yflag)
5152 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5153 gen_element_begin(fd, n, ns_add(p, nse), xsi_type((Tnode*)p->info.typ->ref));
5154 gen_atts(fd, n, (Table*)((Tnode*)p->info.typ->ref)->ref, nsa);
5155 }
5156 else
5157 { d = get_Darraydims((Tnode*)p->info.typ->ref);
5158 if (d)
5159 { for (i = 0; i < d-1; i++)
5160 { tmp[2*i] = ',';
5161 tmp[2*i+1] = '1';
5162 }
5163 tmp[2*d-2] = '\0';
5164 }
5165 else
5166 *tmp = '\0';
5167 if (yflag)
5168 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5169 gen_element_begin(fd, n, ns_add(p, nse), "SOAP-ENC:Array");
5170 if ((((Tnode*)p->info.typ->ref)->type == Tstruct || ((Tnode*)p->info.typ->ref)->type == Tclass) && ((Table*)((Tnode*)p->info.typ->ref)->ref)->list->info.minOccurs > 0)
5171 fprintf(fd, " SOAP-ENC:arrayType=\"%s[" SOAP_LONG_FORMAT "%s]\">", wsdl_type(((Table*)((Tnode*)p->info.typ->ref)->ref)->list->info.typ, ""), ((Table*)((Tnode*)p->info.typ->ref)->ref)->list->info.minOccurs, tmp);
5172 else
5173 fprintf(fd, " SOAP-ENC:arrayType=\"%s[1%s]\">", wsdl_type(((Table*)((Tnode*)p->info.typ->ref)->ref)->list->info.typ, ""), tmp);
5174 }
5175 fflush(fd);
5176 gen_val(fd, n, (Tnode*)p->info.typ->ref, nse, nsa, encoding);
5177 }
5178 else if (p->info.typ->type == Tstruct || p->info.typ->type == Tclass)
5179 { /*
5180 if (!is_primclass(p->info.typ))
5181 { char *nse1 = ns_qualifiedElement(p->info.typ);
5182 char *nsa1 = ns_qualifiedAttribute(p->info.typ);
5183 if (nse1)
5184 nse = nse1;
5185 if (nsa1)
5186 nsa = nsa1;
5187 }
5188 */
5189 if (!is_invisible(p->sym->name))
5190 { if (yflag)
5191 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5192 gen_element_begin(fd, n, ns_add(p, nse), xsi_type_u(p->info.typ));
5193 gen_atts(fd, n, (Table*)p->info.typ->ref, nsa);
5194 }
5195 else if (is_anyType(p->info.typ))
5196 fprintf(fd, "%*s<!-- extensibility element(s) -->\n", n, "");
5197 }
5198 else if ((p->info.typ->type == Tpointer || p->info.typ->type == Treference)
5199 && (((Tnode*)p->info.typ->ref)->type == Tstruct || ((Tnode*)p->info.typ->ref)->type == Tclass))
5200 { /*
5201 if (!is_primclass(p->info.typ->ref))
5202 { char *nse1 = ns_qualifiedElement(p->info.typ->ref);
5203 char *nsa1 = ns_qualifiedAttribute(p->info.typ->ref);
5204 if (nse1)
5205 nse = nse1;
5206 if (nsa1)
5207 nsa = nsa1;
5208 }
5209 */
5210 if (!is_invisible(p->sym->name))
5211 { if (yflag)
5212 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5213 gen_element_begin(fd, n, ns_add(p, nse), xsi_type_u(p->info.typ));
5214 gen_atts(fd, n, (Table*)((Tnode*)p->info.typ->ref)->ref, nsa);
5215 }
5216 else if (is_anyType(p->info.typ))
5217 fprintf(fd, "%*s<!-- extensibility element(s) -->\n", n, "");
5218 }
5219 else if (p->info.typ->type != Tunion)
5220 { if (!is_invisible(p->sym->name))
5221 { if (yflag)
5222 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5223 gen_element_begin(fd, n, ns_add(p, nse), xsi_type_u(p->info.typ));
5224 if (p->info.typ->type == Ttemplate)
5225 { if (((Tnode*)p->info.typ->ref)->type == Tpointer
5226 && (((Tnode*)((Tnode*)p->info.typ->ref)->ref)->type == Tclass
5227 || ((Tnode*)((Tnode*)p->info.typ->ref)->ref)->type == Tstruct))
5228 gen_atts(fd, n, (Table*)((Tnode*)((Tnode*)p->info.typ->ref)->ref)->ref, nsa);
5229 else if (((Tnode*)p->info.typ->ref)->type == Tclass
5230 || ((Tnode*)p->info.typ->ref)->type == Tstruct)
5231 gen_atts(fd, n, (Table*)((Tnode*)p->info.typ->ref)->ref, nsa);
5232 else
5233 fprintf(fd, ">");
5234 }
5235 else
5236 fprintf(fd, ">");
5237 }
5238 }
5239 switch (p->info.typ->type)
5240 { case Tchar:
5241 case Tshort:
5242 case Tint:
5243 case Tlong:
5244 case Tllong:
5245 case Tuchar:
5246 case Tushort:
5247 case Tuint:
5248 case Tulong:
5249 case Tullong:
5250 if (p->info.hasval)
5251 fprintf(fd, SOAP_LONG_FORMAT, p->info.val.i);
5252 else
5253 fprintf(fd, "0");
5254 break;
5255 case Tfloat:
5256 case Tdouble:
5257 case Tldouble:
5258 if (p->info.hasval)
5259 fprintf(fd, "%g", p->info.val.r);
5260 else
5261 fprintf(fd, "0.0");
5262 break;
5263 case Ttime:
5264 { char tmp[256];
5265 time_t t = time(NULL), *p = &t;
5266 strftime(tmp, 256, "%Y-%m-%dT%H:%M:%SZ", gmtime(p));
5267 fprintf(fd, "%s", tmp);
5268 }
5269 break;
5270 case Tenum:
5271 if (p->info.hasval && p->info.typ->ref)
5272 { for (q = ((Table*)p->info.typ->ref)->list; q; q = q->next)
5273 if (p->info.val.i == q->info.val.i)
5274 { fprintf(fd, "%s", ns_remove2(q->sym->name));
5275 break;
5276 }
5277 }
5278 else
5279 gen_val(fd, n+1, p->info.typ, nse, nsa, encoding);
5280 break;
5281 case Tpointer:
5282 case Treference:
5283 if (is_string(p->info.typ) || is_wstring(p->info.typ))
5284 { if (p->info.hasval)
5285 fprintf(fd, "%s", xstring(p->info.val.s));
5286 else
5287 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5288 }
5289 else
5290 gen_val(fd, n, (Tnode*)p->info.typ->ref, nse, nsa, encoding);
5291 break;
5292 case Tclass:
5293 if (is_stdstr(p->info.typ))
5294 { if (p->info.hasval)
5295 fprintf(fd, "%s", xstring(p->info.val.s));
5296 else
5297 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5298 break;
5299 }
5300 case Tstruct:
5301 if (!is_dynamic_array(p->info.typ))
5302 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5303 break;
5304 case Tunion:
5305 gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5306 break;
5307 case Ttemplate:
5308 i = p->info.maxOccurs;
5309 if (i <= 1 || i > 4)
5310 i = p->info.minOccurs;
5311 if (i <= 1)
5312 i = 2;
5313 do
5314 { /* a bit of a hack, I don't like the copy of the code above */
5315 { gen_val(fd, n, p->info.typ, nse, nsa, encoding);
5316 if (i > 1)
5317 { gen_element_end(fd, 0, ns_add(p, nse));
5318 if (!is_invisible(p->sym->name))
5319 { if (yflag)
5320 fprintf(fd, "%*s<!-- %s -->\n", n, "", c_type_id(p->info.typ, p->sym->name));
5321 gen_element_begin(fd, n, ns_add(p, nse), xsi_type_u(p->info.typ));
5322 if (p->info.typ->type == Ttemplate)
5323 { if (((Tnode*)p->info.typ->ref)->type == Tpointer
5324 && (((Tnode*)((Tnode*)p->info.typ->ref)->ref)->type == Tclass
5325 || ((Tnode*)((Tnode*)p->info.typ->ref)->ref)->type == Tstruct))
5326 gen_atts(fd, n, (Table*)((Tnode*)((Tnode*)p->info.typ->ref)->ref)->ref, nsa);
5327 else if (((Tnode*)p->info.typ->ref)->type == Tclass
5328 || ((Tnode*)p->info.typ->ref)->type == Tstruct)
5329 gen_atts(fd, n, (Table*)((Tnode*)p->info.typ->ref)->ref, nsa);
5330 else
5331 fprintf(fd, ">");
5332 }
5333 else
5334 fprintf(fd, ">");
5335 }
5336 }
5337 fflush(fd);
5338 }
5339 } while (--i);
5340 break;
5341 default:
5342 break;
5343 }
5344 if (p->info.typ->type != Tunion)
5345 gen_element_end(fd, 0, ns_add(p, nse));
5346 fflush(fd);
5347 }
5348 }
5349 }
5350
5351 void
5352 gen_atts(FILE *fd, int n, Table *t, char *nsa)
5353 { static unsigned long idnum = 0;
5354 Entry *q, *r;
5355 Tnode *p;
5356 int i;
5357 for (; t; t = t->prev)
5358 {
5359 for (q = t->list; q; q = q->next)
5360 { if (q->info.sto & Sattribute && !is_invisible(q->sym->name) && q->info.maxOccurs != 0)
5361 { fprintf(fd, " %s=\"", ns_add(q, nsa));
5362 if ((q->info.typ->type == Tpointer || q->info.typ->type == Treference) && !is_string(q->info.typ))
5363 p = (Tnode*)q->info.typ->ref;
5364 else
5365 p = q->info.typ;
5366 if (is_eq(q->sym->name, "id"))
5367 fprintf(fd, "%lu", ++idnum); /* id="#" should be unique */
5368 else
5369 switch (p->type)
5370 { case Tchar:
5371 case Tshort:
5372 case Tint:
5373 case Tuchar:
5374 case Tushort:
5375 case Tuint:
5376 case Tlong:
5377 case Tulong:
5378 case Tllong:
5379 case Tullong:
5380 if (q->info.hasval)
5381 fprintf(fd, SOAP_LONG_FORMAT, q->info.val.i);
5382 else
5383 fprintf(fd, "0");
5384 break;
5385 case Tfloat:
5386 case Tdouble:
5387 case Tldouble:
5388 if (q->info.hasval)
5389 fprintf(fd, "%g", q->info.val.r);
5390 else
5391 fprintf(fd, "0.0");
5392 break;
5393 case Ttime:
5394 { char tmp[256];
5395 time_t T = time(NULL);
5396 strftime(tmp, 256, "%Y-%m-%dT%H:%M:%SZ", gmtime(&T));
5397 fprintf(fd, "%s", tmp);
5398 }
5399 break;
5400 case Tenum:
5401 if (q->info.hasval && p->ref)
5402 { for (r = ((Table*)p->ref)->list; r; r = r->next)
5403 { if (r->info.val.i == q->info.val.i)
5404 { fprintf(fd, "%s", ns_remove2(r->sym->name));
5405 break;
5406 }
5407 }
5408 }
5409 else if (p->ref)
5410 fprintf(fd, "%s", ns_remove2((((Table*)p->ref)->list)->sym->name));
5411 else
5412 fprintf(fd, "0");
5413 break;
5414 case Tpointer:
5415 case Treference:
5416 if (is_string(p))
5417 { if (q->info.hasval)
5418 fprintf(fd, "%s", xstring(q->info.val.s));
5419 else if (q->info.typ->minLength > 0 && q->info.typ->minLength < 10000)
5420 for (i = 0; i < (int)q->info.typ->minLength; i++)
5421 fprintf(fd, "X");
5422 }
5423 break;
5424 case Tclass:
5425 if (is_stdstr(p))
5426 { if (q->info.hasval)
5427 fprintf(fd, "%s", xstring(q->info.val.s));
5428 else if (q->info.typ->minLength > 0 && q->info.typ->minLength < 10000)
5429 for (i = 0; i < (int)q->info.typ->minLength; i++)
5430 fprintf(fd, "X");
5431 }
5432 break;
5433 default:
5434 break;
5435 }
5436 if (yflag)
5437 fprintf(fd, " // %s //", c_type_id(q->info.typ, q->sym->name));
5438 fprintf(fd, "\"");
5439 }
5440 }
5441 }
5442 fprintf(fd, ">");
5443 fflush(fd);
5444 }
5445
5446 void
5447 gen_val(FILE *fd, int n, Tnode *p, char *nse, char *nsa, char *encoding)
5448 { Entry *q;
5449 LONG64 i;
5450 if (!is_transient(p) && p->type != Tfun && !is_XML(p))
5451 { if (is_fixedstring(p))
5452 { for (i = 0; i < p->width / ((Tnode*)p->ref)->width - 1; i++)
5453 fprintf(fd, "X");
5454 }
5455 else if (p->type == Tarray)
5456 { i = ((Tnode*) p->ref)->width;
5457 if (i)
5458 { i = p->width / i;
5459 if (i > 4)
5460 i = 2;
5461 fprintf(fd, "\n");
5462 for (; i > 0; i--)
5463 { fprintf(fd, "%*s<item>", n+1, "");
5464 gen_val(fd, n+1, (Tnode*)p->ref, nse, nsa, encoding);
5465 fprintf(fd, "</item>\n");
5466 }
5467 fprintf(fd, "%*s", n, "");
5468 }
5469 }
5470 else if (is_dynamic_array(p))
5471 { if (!is_binary(p))
5472 { Table *t;
5473 fprintf(fd, "\n");
5474 for (t = (Table*)p->ref; t && !t->list; t = t->prev)
5475 ;
5476 if (t)
5477 gen_field(fd, n+1, t->list, nse, nsa, encoding);
5478 fprintf(fd, "%*s", n, "");
5479 }
5480 }
5481 switch (p->type)
5482 { case Tchar:
5483 case Tshort:
5484 case Tint:
5485 case Tlong:
5486 case Tllong:
5487 case Tuchar:
5488 case Tushort:
5489 case Tuint:
5490 case Tulong:
5491 case Tullong:
5492 fprintf(fd, "0");
5493 break;
5494 case Tfloat:
5495 case Tdouble:
5496 case Tldouble:
5497 fprintf(fd, "0.0");
5498 break;
5499 case Ttime:
5500 { char tmp[256];
5501 time_t T = time(NULL);
5502 strftime(tmp, 256, "%Y-%m-%dT%H:%M:%SZ", gmtime(&T));
5503 fprintf(fd, "%s", tmp);
5504 }
5505 break;
5506 case Tenum:
5507 if (p->ref && (q = ((Table*)p->ref)->list))
5508 fprintf(fd, "%s", ns_remove2(q->sym->name));
5509 else
5510 fprintf(fd, "0");
5511 break;
5512 case Tpointer:
5513 case Treference:
5514 if (is_string(p) || is_wstring(p))
5515 { if (p->minLength > 0 && p->minLength < 10000)
5516 for (i = 0; i < (int)p->minLength; i++)
5517 fprintf(fd, "X");
5518 }
5519 else
5520 gen_val(fd, n, (Tnode*)p->ref, nse, nsa, encoding);
5521 break;
5522 case Tclass:
5523 case Tstruct:
5524 nse = ns_qualifiedElement(p);
5525 nsa = ns_qualifiedAttribute(p);
5526 if (is_stdstr(p))
5527 { if (p->minLength > 0 && p->minLength < 10000)
5528 for (i = 0; i < (int)p->minLength; i++)
5529 fprintf(fd, "X");
5530 }
5531 else if (is_primclass(p))
5532 { Table *t;
5533 for (t = (Table*)p->ref; t; t = t->prev)
5534 { Entry *r = entry(classtable, t->sym);
5535 r = t->list;
5536 if (r && is_item(r))
5537 { gen_val(fd, n, r->info.typ, nse, nsa, encoding);
5538 return;
5539 }
5540 }
5541 }
5542 else if (!is_dynamic_array(p) && p->ref)
5543 { Table *t;
5544 fprintf(fd, "\n");
5545 for (t = (Table*)p->ref; t; t = t->prev)
5546 { for (q = t->list; q; q = q->next)
5547 { if (is_repetition(q))
5548 { i = q->info.maxOccurs;
5549 if (i <= 1 || i > 4)
5550 i = q->info.minOccurs;
5551 if (i <= 1)
5552 i = 2;
5553 do
5554 gen_field(fd, n+1, q->next, nse, nsa, encoding);
5555 while (--i);
5556 q = q->next;
5557 }
5558 else
5559 gen_field(fd, n+1, q, nse, nsa, encoding);
5560 }
5561 }
5562 fprintf(fd, "%*s", n, "");
5563 }
5564 break;
5565 case Tunion:
5566 if (((Table*)p->ref)->list)
5567 gen_field(fd, n, ((Table*)p->ref)->list, nse, nsa, encoding);
5568 break;
5569 case Ttemplate:
5570 gen_val(fd, n, (Tnode*)p->ref, nse, nsa, encoding);
5571 break;
5572 default:
5573 break;
5574 }
5575 }
5576 }
5577
5578 void
5579 gen_header(FILE *fd, char *method, int response, char *encoding)
5580 { if (custom_header)
5581 { Service *sp;
5582 Method *m = NULL;
5583 Entry *q;
5584 Table *r;
5585 if (yflag)
5586 { if (cflag)
5587 fprintf(fd, " <!-- struct SOAP_ENV__Header -->\n");
5588 else
5589 fprintf(fd, " <!-- SOAP_ENV__Header *soap::header -->\n");
5590 }
5591 fprintf(fd, " <SOAP-ENV:Header>\n");
5592 q = entry(classtable, lookup("SOAP_ENV__Header"));
5593 if (q)
5594 { r = (Table*)q->info.typ->ref;
5595 if (r)
5596 { for (q = r->list; q; q = q->next)
5597 { if (!is_transient(q->info.typ) && !(q->info.sto & Sattribute) && q->info.typ->type != Tfun)
5598 { for (sp = services; sp; sp = sp->next)
5599 for (m = sp->list; m; m = m->next)
5600 if (is_eq(m->name, method) && (!strcmp(m->part, q->sym->name) || is_eq_nons(m->part, q->sym->name)) && ((!response && (m->mess&HDRIN)) || (response && (m->mess&HDROUT))))
5601 { gen_field(fd, 2, q, NULL, NULL, encoding);
5602 break;
5603 }
5604 }
5605 }
5606 fprintf(fd, " </SOAP-ENV:Header>\n");
5607 }
5608 }
5609 }
5610 }
5611
5612 FILE *
5613 gen_env(char *buf, char *method, int response, Table *t, char *ns, char *name, char *URL, char *executable, char *URI, char *encoding, int soap)
5614 { char tmp[1024];
5615 FILE *fd;
5616 strcpy(tmp, buf);
5617 if (!soap)
5618 strcat(tmp, "REST.");
5619 #ifdef __vms
5620 if (!response)
5621 { sprintf(strrchr(tmp, '.'), "_%s_req.xml", method);
5622 fprintf(fmsg, "Saving %s sample SOAP/XML request\n", tmp);
5623 }
5624 else
5625 { sprintf(strrchr(tmp, '.'), "_%s_res.xml", method);
5626 fprintf(fmsg, "Saving %s sample SOAP/XML response\n", tmp);
5627 }
5628 #else
5629 strcpy(strrchr(tmp, '.')+1, method);
5630 if (!response)
5631 { strcat(tmp, ".req.xml");
5632 fprintf(fmsg, "Saving %s sample SOAP/XML request\n", tmp);
5633 }
5634 else
5635 { strcat(tmp, ".res.xml");
5636 fprintf(fmsg, "Saving %s sample SOAP/XML response\n", tmp);
5637 }
5638 #endif
5639 fd = fopen(tmp, "w");
5640 if (!fd)
5641 execerror("Cannot write XML file");
5642 fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
5643 if (soap && vflag >= 0)
5644 { fprintf(fd, "<SOAP-ENV:Envelope");
5645 gen_xmlns(fd);
5646 fprintf(fd, ">\n");
5647 gen_header(fd, method, response, encoding);
5648 fprintf(fd, " <SOAP-ENV:Body");
5649 if (eflag && !encoding)
5650 fprintf(fd, " SOAP-ENV:encodingStyle=\"%s\"", encURI);
5651 else if (encoding && !*encoding)
5652 fprintf(fd, " SOAP-ENV:encodingStyle=\"%s\"", encURI);
5653 else if (encoding && strcmp(encoding, "literal"))
5654 fprintf(fd, " SOAP-ENV:encodingStyle=\"%s\"", encoding);
5655 fprintf(fd, ">\n");
5656 }
5657 return fd;
5658 }
5659
5660 void
5661 gen_xmlns(FILE *fd)
5662 { Symbol *s;
5663 Service *sp = NULL;
5664 for (s = nslist; s; s = s->next)
5665 { for (sp = services; sp; sp = sp->next)
5666 if (!tagcmp(sp->ns, s->name) && sp->URI)
5667 break;
5668 if (sp)
5669 fprintf(fd, "\n xmlns:%s=\"%s\"", ns_convert(s->name), sp->URI);
5670 else if (!strcmp(s->name, "SOAP-ENV"))
5671 { if (vflag >= 0)
5672 fprintf(fd, "\n xmlns:SOAP-ENV=\"%s\"", envURI);
5673 }
5674 else if (!strcmp(s->name, "SOAP-ENC"))
5675 { if (vflag >= 0)
5676 fprintf(fd, "\n xmlns:SOAP-ENC=\"%s\"", encURI);
5677 }
5678 else if (!strcmp(s->name, "xsi"))
5679 fprintf(fd, "\n xmlns:xsi=\"%s\"", xsiURI);
5680 else if (!strcmp(s->name, "xsd"))
5681 fprintf(fd, "\n xmlns:xsd=\"%s\"", xsdURI);
5682 else
5683 fprintf(fd, "\n xmlns:%s=\"%s/%s.xsd\"", ns_convert(s->name), tmpURI, ns_convert(s->name));
5684 }
5685 }
5686
5687 char *
5688 emalloc(size_t n)
5689 { char *p;
5690 if ((p = (char*)malloc(n)) == NULL)
5691 execerror("out of memory");
5692 return p;
5693 }
5694
5695 void
5696 soap_serve(Table *table)
5697 { Entry *method, *catch_method = NULL;
5698 char *catch_action = NULL;
5699 if (!Cflag)
5700 {
5701 fprintf(fserver,"\n\n");
5702 if (!cflag && !namespaceid)
5703 fprintf(fserver,"extern \"C\" ");
5704 fprintf(fserver,"SOAP_FMAC5 int SOAP_FMAC6 %s_serve(struct soap *soap)", nflag?prefix:"soap");
5705
5706 fprintf(fserver,"\n{\n#ifndef WITH_FASTCGI\n\tunsigned int k = soap->max_keep_alive;\n#endif\n\tdo\n\t{");
5707 fprintf(fserver,"\n#ifndef WITH_FASTCGI\n\t\tif (soap->max_keep_alive > 0 && !--k)\n\t\t\tsoap->keep_alive = 0;\n#endif");
5708 fprintf(fserver,"\n\t\tif (soap_begin_serve(soap))\n\t\t{\tif (soap->error >= SOAP_STOP)\n\t\t\t\tcontinue;\n\t\t\treturn soap->error;\n\t\t}");
5709 if (namespaceid)
5710 fprintf(fserver,"\n\t\tif (%s::%s_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap)))\n\t\t{\n#ifdef WITH_FASTCGI\n\t\t\tsoap_send_fault(soap);\n#else\n\t\t\treturn soap_send_fault(soap);\n#endif\n\t\t}", namespaceid, nflag?prefix:"soap");
5711 else
5712 fprintf(fserver,"\n\t\tif (%s_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap)))\n\t\t{\n#ifdef WITH_FASTCGI\n\t\t\tsoap_send_fault(soap);\n#else\n\t\t\treturn soap_send_fault(soap);\n#endif\n\t\t}", nflag?prefix:"soap");
5713 fprintf(fserver,"\n\n#ifdef WITH_FASTCGI\n\t\tsoap_destroy(soap);\n\t\tsoap_end(soap);\n\t} while (1);\n#else\n\t} while (soap->keep_alive);\n#endif");
5714
5715 fprintf(fserver,"\n\treturn SOAP_OK;");
5716 fprintf(fserver,"\n}");
5717
5718 fprintf(fserver,"\n\n#ifndef WITH_NOSERVEREQUEST\n");
5719 if (!cflag && !namespaceid)
5720 fprintf(fserver,"extern \"C\" ");
5721 fprintf(fserver,"SOAP_FMAC5 int SOAP_FMAC6 %s_serve_request(struct soap *soap)\n{", nflag?prefix:"soap");
5722 fprintf(fserver, "\n\tsoap_peek_element(soap);");
5723 for (method = table->list; method; method = method->next)
5724 { char *action = NULL;
5725 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern))
5726 { if (aflag)
5727 { Service *sp;
5728 for (sp = services; sp; sp = sp->next)
5729 { if (has_ns_eq(sp->ns, method->sym->name))
5730 { Method *m;
5731 for (m = sp->list; m; m = m->next)
5732 { if (is_eq_nons(m->name, method->sym->name))
5733 { if (m->mess == ACTION || m->mess == REQUEST_ACTION)
5734 action = m->part;
5735 }
5736 }
5737 }
5738 }
5739 }
5740 if (is_invisible(method->sym->name))
5741 { Entry *param = entry(classtable, method->sym);
5742 if (param)
5743 param = ((Table*)param->info.typ->ref)->list;
5744 if (action)
5745 { if (*action == '"')
5746 { fprintf(fserver, "\n\tif (");
5747 if (param && !Aflag)
5748 fprintf(fserver, "(soap->action == NULL && !soap_match_tag(soap, soap->tag, \"%s\")) || ", ns_convert(param->sym->name));
5749 else
5750 { catch_method = method;
5751 catch_action = action;
5752 }
5753 fprintf(fserver, "(soap->action && !strcmp(soap->action, %s))", action);
5754 }
5755 else
5756 { fprintf(fserver, "\n\tif (");
5757 if (param && !Aflag)
5758 fprintf(fserver, "(soap->action == NULL && !soap_match_tag(soap, soap->tag, \"%s\")) || ", ns_convert(param->sym->name));
5759 else
5760 { catch_method = method;
5761 catch_action = action;
5762 }
5763 fprintf(fserver, "(soap->action && !strcmp(soap->action, \"%s\"))", action);
5764 }
5765 fprintf(fserver, ")\n\t\treturn soap_serve_%s(soap);", ident(method->sym->name));
5766 }
5767 else
5768 { if (Aflag)
5769 compliancewarn("Option -A requires a SOAPAction where none is defined");
5770 if (param)
5771 { fprintf(fserver, "\n\tif (!soap_match_tag(soap, soap->tag, \"%s\")", ns_convert(param->sym->name));
5772 fprintf(fserver, ")\n\t\treturn soap_serve_%s(soap);", ident(method->sym->name));
5773 }
5774 else
5775 { catch_method = method;
5776 catch_action = action;
5777 }
5778 }
5779 }
5780 else
5781 { if (action)
5782 { if (*action == '"')
5783 { fprintf(fserver, "\n\tif (");
5784 if (!Aflag)
5785 fprintf(fserver, "(soap->action == NULL && !soap_match_tag(soap, soap->tag, \"%s\")) || ", ns_convert(method->sym->name));
5786 fprintf(fserver, "(soap->action && !strcmp(soap->action, %s))", action);
5787 }
5788 else
5789 { fprintf(fserver, "\n\tif (");
5790 if (!Aflag)
5791 fprintf(fserver, "(soap->action == NULL && !soap_match_tag(soap, soap->tag, \"%s\")) || ", ns_convert(method->sym->name));
5792 fprintf(fserver, "(soap->action && !strcmp(soap->action, \"%s\"))", action);
5793 }
5794 }
5795 else
5796 { if (Aflag)
5797 compliancewarn("Option -A requires a SOAPAction where none is defined");
5798 fprintf(fserver, "\n\tif (!soap_match_tag(soap, soap->tag, \"%s\")", ns_convert(method->sym->name));
5799 }
5800 fprintf(fserver, ")\n\t\treturn soap_serve_%s(soap);", ident(method->sym->name));
5801 }
5802 }
5803 }
5804 if (catch_method)
5805 { if (Aflag && catch_action)
5806 { if (*catch_action == '"')
5807 { fprintf(fserver, "\n\tif (");
5808 fprintf(fserver, "(soap->action && !strcmp(soap->action, %s))", catch_action);
5809 fprintf(fserver, ")\n\t\treturn soap_serve_%s(soap);", ident(catch_method->sym->name));
5810 }
5811 else
5812 { fprintf(fserver, "\n\tif (");
5813 fprintf(fserver, "(soap->action && !strcmp(soap->action, \"%s\"))", catch_action);
5814 fprintf(fserver, ")\n\t\treturn soap_serve_%s(soap);", ident(catch_method->sym->name));
5815 }
5816 fprintf(fserver,"\n\treturn soap->error = SOAP_NO_METHOD;");
5817 }
5818 else
5819 fprintf(fserver, "\n\treturn soap_serve_%s(soap);", ident(catch_method->sym->name));
5820 }
5821 else
5822 fprintf(fserver,"\n\treturn soap->error = SOAP_NO_METHOD;");
5823
5824 fprintf(fserver,"\n}\n#endif");
5825
5826 banner(fheader, "Server-Side Operations");
5827 for (method = table->list; method; method = method->next)
5828 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern))
5829 generate_proto(table, method);
5830
5831 banner(fheader, "Server-Side Skeletons to Invoke Service Operations");
5832 fprintf(fheader, "\n");
5833 if (!cflag && !namespaceid)
5834 fprintf(fheader,"extern \"C\" ");
5835 fprintf(fheader, "SOAP_FMAC5 int SOAP_FMAC6 %s_serve(struct soap*);", nflag?prefix:"soap");
5836 fprintf(fheader, "\n\n");
5837 if (!cflag && !namespaceid)
5838 fprintf(fheader,"extern \"C\" ");
5839 fprintf(fheader, "SOAP_FMAC5 int SOAP_FMAC6 %s_serve_request(struct soap*);", nflag?prefix:"soap");
5840 for (method = table->list; method; method = method->next)
5841 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && !is_imported(method->info.typ))
5842 gen_serve_method(fserver, table, method, NULL);
5843
5844 }
5845
5846 if (!Sflag)
5847 { banner(fheader, "Client-Side Call Stubs");
5848 for (method = table->list; method; method = method->next)
5849 if (method->info.typ->type == Tfun && !(method->info.sto & Sextern) && !is_imported(method->info.typ))
5850 gen_call_method(fclient, table, method, NULL);
5851 }
5852
5853 }
5854
5855 void
5856 generate_proto(Table *table, Entry *param)
5857 { Entry *q, *pout;
5858 Table *output;
5859 q = entry(table, param->sym);
5860 if (q)
5861 pout = (Entry*)q->info.typ->ref;
5862 else
5863 { fprintf(stderr, "Internal error: no table entry\n");
5864 return;
5865 }
5866 q = entry(classtable, param->sym);
5867 output = (Table*)q->info.typ->ref;
5868 fprintf(fheader, "\n\nSOAP_FMAC5 int SOAP_FMAC6 %s(struct soap*", ident(param->sym->name));
5869 gen_params(fheader, output, pout, 1);
5870 fprintf(fheader, ";");
5871 }
5872
5873 int
5874 tagcmp(const char *s, const char *t)
5875 { size_t i, n;
5876 n = strlen(s);
5877 for (i = 0; i < n; i++)
5878 { int c = t[i];
5879 if (c == '_' && s[i] != '_')
5880 c = '-';
5881 if (s[i] > c)
5882 return 1;
5883 if (s[i] < c)
5884 return -1;
5885 }
5886 return -(t[i] != 0);
5887 }
5888
5889 int
5890 tagncmp(const char *s, const char *t, size_t n)
5891 { size_t i;
5892 for (i = 0; i < n; i++)
5893 { int c = t[i];
5894 if (c == '_' && s[i] != '_')
5895 c = '-';
5896 if (s[i] > c)
5897 return 1;
5898 if (s[i] < c)
5899 return -1;
5900 }
5901 return 0;
5902 }
5903
5904 int
5905 is_qname(Tnode *p)
5906 { if (p->sym && is_string(p) && (is_eq(p->sym->name, "xsd__QName") || is_eq(p->sym->name, "QName")))
5907 return 1;
5908 return p->id && is_string(p) && (is_eq(p->id->name, "xsd__QName") || is_eq(p->id->name, "QName"));
5909 }
5910
5911 int
5912 is_stdqname(Tnode *p)
5913 { if (p->sym && p->type == Tclass && is_volatile(p) && (is_eq(p->sym->name, "xsd__QName") || is_eq(p->sym->name, "QName")))
5914 return 1;
5915 return p->id && p->type == Tclass && is_volatile(p) && (is_eq(p->id->name, "xsd__QName") || is_eq(p->id->name, "QName"));
5916 }
5917
5918 int
5919 is_XML(Tnode *p)
5920 { return (p->sym && (is_string(p) || is_wstring(p)) && is_eq(p->sym->name, "XML")) || ((p->type == Tpointer || p->type == Treference) && is_XML((Tnode*)p->ref));
5921 }
5922
5923 int
5924 is_stdXML(Tnode *p)
5925 { return p->sym && (is_stdstring(p) || is_stdwstring(p)) && is_eq(p->sym->name, "XML");
5926 }
5927
5928 int
5929 is_response(Tnode *p)
5930 { return (p->type == Tpointer || p->type == Treference)
5931 && p->ref
5932 && has_ns((Tnode*)p->ref)
5933 && ((((Tnode*)p->ref)->type == Tstruct || ((Tnode*)p->ref)->type == Tclass) && !is_primclass((Tnode*)p->ref) && !is_dynamic_array((Tnode*)p->ref) && !is_stdstring((Tnode*)p->ref) && !is_stdwstring((Tnode*)p->ref));
5934 }
5935
5936 Entry*
5937 get_response(Tnode *p)
5938 { if (p->type == Tfun)
5939 return p->response;
5940 return 0;
5941 }
5942
5943 int
5944 is_unmatched(Symbol *sym)
5945 { return sym->name[0] == '_'
5946 && sym->name[1] != '_'
5947 && strncmp(sym->name, "_DOT", 4)
5948 && strncmp(sym->name, "_USCORE", 7)
5949 && (strncmp(sym->name, "_x", 2) || !isxdigit(sym->name[2]) || !isxdigit(sym->name[3]) || !isxdigit(sym->name[4]) || !isxdigit(sym->name[5]));
5950 }
5951
5952 int
5953 is_invisible(const char *name)
5954 { return name[0] == '-' || (name[0] == '_' && name[1] == '_' && strncmp(name, "__ptr", 5));
5955 }
5956
5957 int
5958 is_invisible_empty(Tnode *p)
5959 { if (p->type == Tstruct || p->type == Tclass)
5960 if (is_invisible(p->id->name))
5961 if (!p->ref || !((Table*)p->ref)->list)
5962 return 1;
5963 return 0;
5964 }
5965
5966 int
5967 is_element(Tnode *typ)
5968 { if (is_XML(typ) || is_stdXML(typ) || is_qname(typ) || is_stdqname(typ))
5969 return 0;
5970 if (typ->sym)
5971 return is_unmatched(typ->sym);
5972 if (typ->type == Tstruct || typ->type == Tclass)
5973 return is_unmatched(typ->id);
5974 return 0;
5975 }
5976
5977 int
5978 is_untyped(Tnode *typ)
5979 { Tnode *p;
5980 if (typ->sym)
5981 return is_unmatched(typ->sym);
5982 if (typ->type == Tpointer || typ->type == Treference || typ->type == Tarray)
5983 return is_untyped((Tnode*)typ->ref);
5984 if (typ->type == Tstruct || typ->type == Tclass)
5985 { if (is_dynamic_array(typ) && !has_ns(typ) && !is_binary(typ))
5986 { p = (Tnode*)((Table*)typ->ref)->list->info.typ->ref;
5987 return is_untyped(p);
5988 }
5989 else
5990 return is_unmatched(typ->id);
5991 }
5992 return 0;
5993 }
5994
5995 int
5996 is_primclass(Tnode *typ)
5997 { Table *t;
5998 if (typ->type == Tstruct || typ->type == Tclass)
5999 { if (!is_dynamic_array(typ))
6000 { t = (Table*)typ->ref;
6001 while (t)
6002 { if (t->list && is_item(t->list))
6003 break;
6004 t = t->prev;
6005 }
6006 if (!t)
6007 return 0;
6008 t = (Table*)typ->ref;
6009 while (t)
6010 { Entry *p;
6011 for (p = t->list; p; p = p->next)
6012 if (!is_item(p))
6013 if (p->info.typ->type != Tfun && !is_transient(p->info.typ) && p->info.sto != Sattribute && p->info.sto != Sprivate && p->info.sto != Sprotected)
6014 return 0;
6015 t = t->prev;
6016 }
6017 return 1;
6018 }
6019 }
6020 else if (typ->type == Tpointer || typ->type == Treference)
6021 return is_primclass((Tnode*)typ->ref);
6022 return 0;
6023 }
6024
6025 int
6026 is_mask(Tnode *typ)
6027 { return (typ->type == Tenum && typ->width == 8);
6028 }
6029
6030 int
6031 is_void(Tnode *typ)
6032 { if (!typ)
6033 return 1;
6034 if (typ->type == Tvoid)
6035 return 1;
6036 if (typ->type == Tpointer)
6037 return is_void((Tnode*)typ->ref);
6038 if (typ->type == Treference)
6039 return is_void((Tnode*)typ->ref);
6040 if (typ->type == Tarray)
6041 return is_void((Tnode*)typ->ref);
6042 if (typ->type == Ttemplate)
6043 return is_void((Tnode*)typ->ref);
6044 return 0;
6045 }
6046
6047 int
6048 is_transient(Tnode *typ)
6049 { if (!typ)
6050 return 1;
6051 if (typ->type == Tstruct && typ->id == lookup("soap"))
6052 return 1;
6053 if (is_external(typ) || is_volatile(typ))
6054 return 0;
6055 if (typ->transient > 0)
6056 return 1;
6057 switch (typ->type)
6058 { case Tpointer:
6059 case Treference:
6060 case Tarray:
6061 case Ttemplate:
6062 return is_transient((Tnode*)typ->ref);
6063 case Tnone:
6064 case Tvoid:
6065 return 1;
6066 default:
6067 break;
6068 }
6069 return 0;
6070 }
6071
6072 int
6073 is_imported(Tnode* typ)
6074 { return typ->imported != NULL;
6075 }
6076
6077 int
6078 is_external(Tnode* typ)
6079 { return typ->transient == -1;
6080 }
6081
6082 int
6083 is_anyType(Tnode* typ)
6084 { if (typ->type == Tpointer)
6085 return is_anyType((Tnode*)typ->ref);
6086 return is_external(typ) && typ->type == Tstruct && !strcmp(typ->id->name, "soap_dom_element");
6087 }
6088
6089 int
6090 is_anyAttribute(Tnode* typ)
6091 { if (typ->type == Tpointer)
6092 return is_anyAttribute((Tnode*)typ->ref);
6093 return is_external(typ) && typ->type == Tstruct && !strcmp(typ->id->name, "soap_dom_attribute");
6094 }
6095
6096 int
6097 is_volatile(Tnode* typ)
6098 { return typ->transient == -2;
6099 }
6100
6101 int
6102 is_template(Tnode *p)
6103 { if (p->type == Tpointer)
6104 return is_template((Tnode*)p->ref);
6105 return p->type == Ttemplate;
6106 }
6107
6108 int
6109 is_repetition(Entry *p)
6110 { if (p)
6111 return p->next && p->next->info.typ->type == Tpointer && (p->info.typ->type == Tint || p->info.typ->type == Tuint) && ((p->info.sto & Sspecial) || !strncmp(p->sym->name, "__size", 6));
6112 return 0;
6113 }
6114
6115 int
6116 is_item(Entry *p)
6117 { if (p)
6118 return !strcmp(p->sym->name, "__item");
6119 return 0;
6120 }
6121
6122 int
6123 is_self(Entry *p)
6124 { if (p)
6125 return !strcmp(p->sym->name, "__self");
6126 return 0;
6127 }
6128
6129 int
6130 is_choice(Entry *p)
6131 { if (p)
6132 if (p->next && p->next->info.typ->type == Tunion && p->info.typ->type == Tint && ((p->info.sto & Sspecial) || !strncmp(p->sym->name, "__union", 7)))
6133 return 1;
6134 return 0;
6135 }
6136
6137 int
6138 is_sequence(Entry *p)
6139 { if (p)
6140 { Tnode *q = p->info.typ;
6141 if (q->type == Tpointer)
6142 q = (Tnode*)q->ref;
6143 if (q->type == Tstruct && is_invisible(p->sym->name) && is_invisible(q->id->name) && !is_transient(q))
6144 return 1;
6145 }
6146 return 0;
6147 }
6148
6149
6150 int
6151 is_anytype(Entry *p)
6152 { if (p)
6153 if (p->next && p->next->info.typ->type == Tpointer && ((Tnode*)p->next->info.typ->ref)->type == Tvoid && p->info.typ->type == Tint && !strncmp(p->sym->name, "__type", 6))
6154 { is_anytype_flag = 1;
6155 return 1;
6156 }
6157 return 0;
6158 }
6159
6160 int
6161 is_keyword(const char *name)
6162 { Symbol *s = lookup(name);
6163 if (s)
6164 return s->token != ID;
6165 return 0;
6166 }
6167
6168
6169 int
6170 has_ptr(Tnode *typ)
6171 { Tnode *p;
6172 if (typ->type == Tpointer || typ->type == Treference)
6173 return 0;
6174 for (p = Tptr[Tpointer]; p; p = p->next)
6175 if ((Tnode*)p->ref == typ && p->transient != 1)
6176 return 1;
6177 return 0;
6178 }
6179
6180 int
6181 has_detail_string(void)
6182 { Entry *p = entry(classtable, lookup("SOAP_ENV__Fault"));
6183 if (p && p->info.typ->ref && (p->info.typ->type == Tstruct || p->info.typ->type == Tclass))
6184 { Entry *e = entry((Table*)p->info.typ->ref, lookup("detail"));
6185 if (e && e->info.typ->ref && e->info.typ->type == Tpointer && ((Tnode*)e->info.typ->ref)->type == Tstruct)
6186 { Entry *e2 = entry((Table*)((Tnode*)e->info.typ->ref)->ref, lookup("__any"));
6187 return e2 && is_string(e2->info.typ);
6188 }
6189 }
6190 return 0;
6191 }
6192
6193 int
6194 has_Detail_string(void)
6195 { Entry *p = entry(classtable, lookup("SOAP_ENV__Fault"));
6196 if (p && p->info.typ->ref && (p->info.typ->type == Tstruct || p->info.typ->type == Tclass))
6197 { Entry *e = entry((Table*)p->info.typ->ref, lookup("SOAP_ENV__Detail"));
6198 if (e && e->info.typ->ref && e->info.typ->type == Tpointer && ((Tnode*)e->info.typ->ref)->type == Tstruct)
6199 { Entry *e2 = entry((Table*)((Tnode*)e->info.typ->ref)->ref, lookup("__any"));
6200 return e2 && is_string(e2->info.typ);
6201 }
6202 }
6203 return 0;
6204 }
6205
6206 int
6207 has_class(Tnode *typ)
6208 { Entry *p;
6209 if (typ->type == Tstruct && typ->ref)
6210 { for (p = ((Table*)typ->ref)->list; p; p = p->next)
6211 { if (p->info.sto & Stypedef)
6212 continue;
6213 if (p->info.typ->type == Tclass || p->info.typ->type == Ttemplate)
6214 return 1;
6215 if (p->info.typ->type == Tstruct && has_class(p->info.typ))
6216 return 1;
6217 }
6218 }
6219 return 0;
6220 }
6221
6222 int
6223 has_external(Tnode *typ)
6224 { Entry *p;
6225 if ((typ->type == Tstruct || typ->type == Tclass) && typ->ref)
6226 { for (p = ((Table*)typ->ref)->list; p; p = p->next)
6227 { if (p->info.typ->type == Tstruct || p->info.typ->type == Tclass)
6228 { if (is_external(p->info.typ) || has_external(p->info.typ))
6229 return 1;
6230 }
6231 }
6232 }
6233 return 0;
6234 }
6235
6236 int
6237 has_volatile(Tnode *typ)
6238 { Entry *p;
6239 if ((typ->type == Tstruct || typ->type == Tclass) && typ->ref)
6240 { for (p = ((Table*)typ->ref)->list; p; p = p->next)
6241 { if (p->info.typ->type == Tstruct || p->info.typ->type == Tclass)
6242 { if (is_volatile(p->info.typ) || has_volatile(p->info.typ))
6243 if (!is_stdstr(p->info.typ))
6244 return 1;
6245 }
6246 }
6247 }
6248 return 0;
6249 }
6250
6251 int
6252 has_ns(Tnode *typ)
6253 { if (typ->type == Tstruct || typ->type == Tclass || typ->type == Tenum)
6254 return has_ns_eq(NULL, typ->id->name);
6255 return 0;
6256 }
6257
6258 int
6259 has_ns_t(Tnode *typ)
6260 { char *s;
6261 if (typ->sym)
6262 { s = strstr(typ->sym->name + 1, "__");
6263 if (!s)
6264 { s = strchr(typ->sym->name, ':');
6265 if (s && s[1] == ':')
6266 s = NULL;
6267 }
6268 return s && s[1] && s[2] && (s[2] != '_'
6269 || (s[2] == '_' && s[3] == 'x' && isxdigit(s[4]) && isxdigit(s[5]) && isxdigit(s[6]) && isxdigit(s[7]))
6270 || !strncmp(s+2, "_DOT", 4)
6271 || !strncmp(s+2, "_USCORE", 7));
6272 }
6273 return has_ns(typ);
6274 }
6275
6276 /* needs_lang adds xml:lang attribute to matching struct/class member name
6277 we should use an annotation for soapcpp2's input this in the future instead
6278 of a hard-coded member name */
6279 void
6280 needs_lang(Entry *e)
6281 { if (!strcmp(e->sym->name, "SOAP_ENV__Text"))
6282 fprintf(fout, "\n\tif (soap->lang)\n\t\tsoap_set_attr(soap, \"xml:lang\", soap->lang, 1);");
6283 }
6284
6285 int
6286 is_eq_nons(const char *s, const char *t)
6287 { size_t n, m;
6288 char *r;
6289 while (*s == '_' || *s == ':')
6290 s++;
6291 while (*t == '_' || *t == ':')
6292 t++;
6293 if (!*s || !*t)
6294 return 0;
6295 r = strstr(t, "__");
6296 if (r)
6297 t = r + 2;
6298 n = strlen(s) - 1;
6299 m = strlen(t) - 1;
6300 #ifdef SOAP_OLD_DIRECTIVE_NAME_MATCHING
6301 while (n > 0 && s[n] == '_')
6302 n--;
6303 while (m > 0 && t[m] == '_')
6304 m--;
6305 #endif
6306 if (n != m)
6307 return 0;
6308 return !strncmp(s, t, n + 1);
6309 }
6310
6311 int
6312 is_eq(const char *s, const char *t)
6313 { size_t n, m;
6314 while (*s == '_' || *s == ':')
6315 s++;
6316 while (*t == '_' || *t == ':')
6317 t++;
6318 if (!*s || !*t)
6319 return 0;
6320 for (n = strlen(s) - 1; n && s[n] == '_'; n--)
6321 ;
6322 for (m = strlen(t) - 1; m && t[m] == '_'; m--)
6323 ;
6324 if (n != m)
6325 return 0;
6326 return !strncmp(s, t, n + 1);
6327 }
6328
6329 int
6330 has_ns_eq(char *ns, char *s)
6331 { size_t n;
6332 while (*s == '_' || *s == ':')
6333 s++;
6334 if (!ns)
6335 { char *t = strstr(s + 1, "__");
6336 if (!t
6337 || (t[2] == 'x' && isxdigit(t[3]) && isxdigit(t[4]) && isxdigit(t[5]) && isxdigit(t[6]))
6338 || !strncmp(t+2, "DOT", 3)
6339 || !strncmp(t+2, "USCORE", 6))
6340 { t = strchr(s, ':');
6341 if (t && t[1] == ':')
6342 t = NULL;
6343 }
6344 return t && t[1] && t[2] && t[2] != '_';
6345 }
6346 if ((n = strlen(ns)) < strlen(s))
6347 return ((s[n] == '_' && s[n+1] == '_') || (s[n] == ':' && s[n+1] != ':')) && !tagncmp(ns, s, n);
6348 return 0;
6349 }
6350
6351 char *
6352 strict_check(void)
6353 { if (sflag)
6354 return "";
6355 return "(soap->mode & SOAP_XML_STRICT) && ";
6356 }
6357
6358 char *
6359 ns_of(char *name)
6360 { Service *sp;
6361 for (sp = services; sp; sp = sp->next)
6362 if (has_ns_eq(sp->ns, name))
6363 break;
6364 if (sp)
6365 return sp->URI;
6366 return NULL;
6367 }
6368
6369 int
6370 eq_ns(char *s, char *t)
6371 { return ns_of(s) == ns_of(t);
6372 }
6373
6374 char *
6375 prefix_of(char *s)
6376 { char *t;
6377 while (*s == '_' || *s == ':')
6378 s++;
6379 t = strstr(s + 1, "__");
6380 if (!t)
6381 { t = strchr(s, ':');
6382 if (t && t[1] == ':')
6383 t = NULL;
6384 }
6385 if (t && t[1] && t[2] && t[2] != '_')
6386 { char *r = (char*)emalloc(t - s + 1);
6387 strncpy(r, s, t - s);
6388 r[t - s] = '\0';
6389 return r;
6390 }
6391 return s;
6392 }
6393
6394 char *
6395 ns_add_overridden(Table *t, Entry *p, char *ns)
6396 { Entry *q;
6397 Symbol *s = t->sym;
6398 if (s)
6399 { do
6400 { for (q = t->list; q; q = q->next)
6401 if (!strcmp(q->sym->name, p->sym->name))
6402 return ns_add(p, ns ? prefix_of(t->sym->name) : NULL);
6403 } while ((t = t->prev) != NULL);
6404 }
6405 return ns_add(p, ns);
6406 }
6407
6408
6409 char *
6410 c_ident(Tnode *typ)
6411 { if (typ->sym && strcmp(typ->sym->name, "/*?*/"))
6412 return res_remove(typ->sym->name);
6413 return t_ident(typ);
6414 }
6415
6416 char *
6417 soap_type(Tnode *typ)
6418 { char *s, *t = c_ident(typ);
6419 if (namespaceid)
6420 { s = (char*)emalloc(strlen(t) + strlen(namespaceid) + 12);
6421 strcpy(s, "SOAP_TYPE_");
6422 strcat(s, namespaceid);
6423 strcat(s, "_");
6424 }
6425 else
6426 { s = (char*)emalloc(strlen(t) + 11);
6427 strcpy(s, "SOAP_TYPE_");
6428 }
6429 strcat(s, t);
6430 return s;
6431 }
6432
6433 char *
6434 ident(char *name)
6435 { char *s = strrchr(name, ':');
6436 if (s && *(s+1) && *(s-1) != ':')
6437 return s+1;
6438 return name;
6439 }
6440
6441 /*t_ident gives the name of a type in identifier format*/
6442 char *
6443 t_ident(Tnode *typ)
6444 { char *p, *q;
6445 switch(typ->type)
6446 {
6447 case Tnone:
6448 return "";
6449 case Tvoid:
6450 return "void";
6451 case Tchar:
6452 return "byte";
6453 case Twchar:
6454 return "wchar";
6455 case Tshort:
6456 return "short";
6457 case Tint:
6458 return "int";
6459 case Tlong:
6460 return "long";
6461 case Tllong:
6462 return "LONG64";
6463 case Tfloat:
6464 return "float";
6465 case Tdouble:
6466 return "double";
6467 case Tldouble:
6468 return "decimal";
6469 case Tuchar:
6470 return "unsignedByte";
6471 case Tushort:
6472 return "unsignedShort";
6473 case Tuint:
6474 return "unsignedInt";
6475 case Tulong:
6476 return "unsignedLong";
6477 case Tullong:
6478 return "unsignedLONG64";
6479 case Ttime:
6480 return "time";
6481 case Tstruct:
6482 case Tclass:
6483 case Tunion:
6484 case Tenum:
6485 if ((Table*)typ->ref == booltable)
6486 return "bool";
6487 return res_remove(typ->id->name);
6488 case Treference:
6489 return c_ident((Tnode*)typ->ref);
6490 case Tpointer:
6491 if (is_string(typ))
6492 return "string";
6493 if (is_wstring(typ))
6494 return "wstring";
6495 p=(char*) emalloc((10+strlen(q = c_ident((Tnode*)typ->ref)))*sizeof(char));
6496 strcpy(p,"PointerTo");
6497 strcat(p,q);
6498 return p;
6499 case Tarray:
6500 p=(char*) emalloc((16+strlen(c_ident((Tnode*)typ->ref)))*sizeof(char));
6501 if (((Tnode*)typ->ref)->width)
6502 sprintf(p, "Array%dOf%s",typ->width / ((Tnode*) typ->ref)->width,c_ident(typ->ref));
6503 else
6504 sprintf(p, "ArrayOf%s", c_ident((Tnode*)typ->ref));
6505 return p;
6506 case Ttemplate:
6507 if (typ->ref)
6508 { p=(char*) emalloc((11+strlen(res_remove(typ->id->name))+strlen(q = c_ident((Tnode*)typ->ref)))*sizeof(char));
6509 strcpy(p, res_remove(typ->id->name));
6510 strcat(p, "TemplateOf");
6511 strcat(p, q);
6512 return p;
6513 }
6514 case Tfun:
6515 return "Function";
6516 }
6517 return "anyType";
6518 }
6519
6520 void
6521 utf8(char **t, long c)
6522 { if (c < 0x0080)
6523 *(*t)++ = (char)c;
6524 else
6525 { if (c < 0x0800)
6526 *(*t)++ = (char)(0xC0 | ((c >> 6) & 0x1F));
6527 else
6528 { if (c < 0x010000)
6529 *(*t)++ = (char)(0xE0 | ((c >> 12) & 0x0F));
6530 else
6531 { if (c < 0x200000)
6532 *(*t)++ = (char)(0xF0 | ((c >> 18) & 0x07));
6533 else
6534 { if (c < 0x04000000)
6535 *(*t)++ = (char)(0xF8 | ((c >> 24) & 0x03));
6536 else
6537 { *(*t)++ = (char)(0xFC | ((c >> 30) & 0x01));
6538 *(*t)++ = (char)(0x80 | ((c >> 24) & 0x3F));
6539 }
6540 *(*t)++ = (char)(0x80 | ((c >> 18) & 0x3F));
6541 }
6542 *(*t)++ = (char)(0x80 | ((c >> 12) & 0x3F));
6543 }
6544 *(*t)++ = (char)(0x80 | ((c >> 6) & 0x3F));
6545 }
6546 *(*t)++ = (char)(0x80 | (c & 0x3F));
6547 }
6548 *(*t) = '\0';
6549 }
6550
6551 char *
6552 ns_convert(char *tag)
6553 { char *t, *s;
6554 size_t i, n;
6555 if (*tag == '_')
6556 { if (!strncmp(tag, "__ptr", 5))
6557 { if (tag[5])
6558 tag += 5;
6559 else
6560 tag = "item";
6561 }
6562 else if (strncmp(tag, "_DOT", 4)
6563 && strncmp(tag, "_USCORE", 7)
6564 && (strncmp(tag, "_x", 2) || !isxdigit(tag[2]) || !isxdigit(tag[3]) || !isxdigit(tag[4]) || !isxdigit(tag[5])))
6565 tag++; /* skip leading _ */
6566 }
6567 for (n = strlen(tag); n > 0; n--)
6568 { if (tag[n-1] != '_')
6569 break;
6570 }
6571 s = t = (char*)emalloc(n+1);
6572 for (i = 0; i < n; i++)
6573 { if (tag[i] == '_')
6574 { if (tag[i+1] == '_' && !(tag[i+2] == 'x' && isxdigit(tag[i+3]) && isxdigit(tag[i+4]) && isxdigit(tag[i+5]) && isxdigit(tag[i+6])))
6575 break;
6576 else if (!strncmp(tag+i, "_DOT", 4))
6577 { *s++ = '.';
6578 i += 3;
6579 }
6580 else if (!strncmp(tag+i, "_USCORE", 7))
6581 { *s++ = '_';
6582 i += 6;
6583 }
6584 else if (!strncmp(tag+i, "_x", 2) && isxdigit(tag[i+2]) && isxdigit(tag[i+3]) && isxdigit(tag[i+4]) && isxdigit(tag[i+5]))
6585 { char d[5];
6586 strncpy(d, tag+i+2, 4);
6587 d[4] = '\0';
6588 utf8(&s, strtoul(d, NULL, 16));
6589 i += 5;
6590 }
6591 else
6592 *s++ = '-';
6593 }
6594 else if (tag[i] == ':' && tag[i+1] == ':')
6595 break;
6596 else
6597 *s++ = tag[i];
6598 }
6599 if (i < n)
6600 { *s++ = ':';
6601 for (i += 2; i < n; i++)
6602 { if (tag[i] == '_')
6603 { if (!strncmp(tag+i, "_DOT", 4))
6604 { *s++ = '.';
6605 i += 3;
6606 }
6607 else if (!strncmp(tag+i, "_USCORE", 7))
6608 { *s++ = '_';
6609 i += 6;
6610 }
6611 else if (!strncmp(tag+i, "_x", 2) && isxdigit(tag[i+2]) && isxdigit(tag[i+3]) && isxdigit(tag[i+4]) && isxdigit(tag[i+5]))
6612 { char d[5];
6613 strncpy(d, tag+i+2, 4);
6614 d[4] = '\0';
6615 utf8(&s, strtoul(d, NULL, 16));
6616 i += 5;
6617 }
6618 else
6619 *s++ = '-';
6620 }
6621 else
6622 *s++ = tag[i];
6623 }
6624 }
6625 *s = '\0';
6626 return t;
6627 }
6628
6629 char *
6630 res_remove(char *tag)
6631 { char *s, *t;
6632 if (!(s = strchr(tag, ':')))
6633 return tag;
6634 if (s[1] != ':')
6635 tag = s + 1;
6636 if (!strchr(tag, ':'))
6637 return tag;
6638 s = emalloc(strlen(tag) + 1);
6639 strcpy(s, tag);
6640 while ((t = strchr(s, ':')))
6641 *t = '_';
6642 return s;
6643 }
6644
6645 char *
6646 ns_qualifiedElement(Tnode *typ)
6647 { Service *sp;
6648 char *s = NULL;
6649 if (typ->sym)
6650 s = prefix_of(typ->sym->name);
6651 if (!s && typ->id)
6652 s = prefix_of(typ->id->name);
6653 if (!s)
6654 return NULL;
6655 for (sp = services; sp; sp = sp->next)
6656 { if (sp->elementForm && !tagcmp(sp->ns, s))
6657 { if (!strcmp(sp->elementForm, "qualified"))
6658 return s;
6659 return NULL;
6660 }
6661 }
6662 for (sp = services; sp; sp = sp->next)
6663 if (!tagcmp(sp->ns, s))
6664 if (sp->style && !strcmp(sp->style, "document"))
6665 return s;
6666 return NULL;
6667 }
6668
6669 char *
6670 ns_qualifiedAttribute(Tnode *typ)
6671 { Service *sp;
6672 char *s = NULL;
6673 if (typ->sym)
6674 s = prefix_of(typ->sym->name);
6675 if (!s && typ->id)
6676 s = prefix_of(typ->id->name);
6677 if (!s)
6678 return NULL;
6679 for (sp = services; sp; sp = sp->next)
6680 { if (sp->attributeForm && !tagcmp(sp->ns, s))
6681 { if (!strcmp(sp->attributeForm, "qualified"))
6682 return s;
6683 return NULL;
6684 }
6685 }
6686 return NULL;
6687 }
6688
6689 char *
6690 field(Entry *p, char *ns)
6691 { char *r, *s;
6692 if (is_self(p))
6693 return "tag";
6694 r = ns_add(p, ns);
6695 s = emalloc(strlen(r) + 3);
6696 strcpy(s, "\"");
6697 strcat(s, r);
6698 strcat(s, "\"");
6699 return s;
6700 }
6701
6702 char *
6703 field_overridden(Table *t, Entry *p, char *ns)
6704 { char *r, *s;
6705 if (is_self(p))
6706 return "tag";
6707 r = ns_add_overridden(t, p, ns);
6708 s = emalloc(strlen(r) + 3);
6709 strcpy(s, "\"");
6710 strcat(s, r);
6711 strcat(s, "\"");
6712 return s;
6713 }
6714
6715 char *
6716 ns_add(Entry *p, char *ns)
6717 { if (p->tag)
6718 return ns_addx(p->tag, ns);
6719 return ns_addx(p->sym->name, ns);
6720 }
6721
6722 char *
6723 ns_addx(char *tag, char *ns)
6724 { char *n, *t, *s = ns_convert(tag);
6725 if (*s == ':')
6726 return s+1;
6727 if (!ns || *s == '-' || (t = strchr(s, ':')))
6728 return s;
6729 n = ns_convert(ns);
6730 t = emalloc(strlen(n) + strlen(s) + 2);
6731 strcpy(t, n);
6732 strcat(t, ":");
6733 strcat(t, s);
6734 return t;
6735 }
6736
6737 char *
6738 ns_name(char *tag)
6739 { char *t, *r, *s = tag;
6740 if (*s)
6741 { for (r = s+strlen(s)-1; r > s; r--)
6742 if (*r != '_')
6743 break;
6744 for (t = s + 1; t < r; t++)
6745 { if (t[0] == '_' && t[1] == '_')
6746 { s = t + 2;
6747 t++;
6748 }
6749 else if (t[0] == ':' && t[1] != ':')
6750 { s = t + 1;
6751 t++;
6752 }
6753 }
6754 }
6755 return s;
6756 }
6757
6758 char *
6759 ns_cname(char *tag, char *suffix)
6760 { char *s, *t;
6761 size_t i, n;
6762 if (!tag)
6763 return NULL;
6764 t = ns_name(tag);
6765 n = strlen(t);
6766 if (suffix)
6767 s = emalloc(n + strlen(suffix) + 2);
6768 else
6769 s = emalloc(n + 2);
6770 for (i = 0; i < n; i++)
6771 { if (!isalnum(t[i]))
6772 s[i] = '_';
6773 else
6774 s[i] = t[i];
6775 }
6776 s[i] = '\0';
6777 if (suffix)
6778 strcat(s, suffix);
6779 if (is_keyword(t))
6780 strcat(s, "_");
6781 return s;
6782 }
6783
6784 char *
6785 ns_fname(char *tag)
6786 { char *s;
6787 size_t i;
6788 s = emalloc(strlen(tag) + 1);
6789 strcpy(s, tag);
6790 for (i = 0; s[i]; i++)
6791 if (!isalnum(s[i]))
6792 s[i] = '_';
6793 return s;
6794 }
6795
6796 char *
6797 ns_remove(char *tag)
6798 { return ns_convert(ns_name(tag));
6799 }
6800
6801 char *
6802 ns_remove1(char *tag)
6803 { char *t, *s = tag;
6804 int n = 2;
6805 /* handle 'enum_xx__yy' generated by wsdl2h
6806 if (!strncmp(s, "enum_", 5))
6807 n = 1;
6808 */
6809 if (*s)
6810 { for (t = s + 1; *t && n; t++)
6811 if (t[0] == '_' && t[1] == '_')
6812 { s = t + 2;
6813 t++;
6814 n--;
6815 }
6816 if (n || (s[0] == '_' && s[1] != 'x' && strncmp(s, "_USCORE", 7)) || !*s)
6817 s = tag;
6818 }
6819 return s;
6820 }
6821
6822 char *
6823 ns_remove2(char *tag)
6824 { return ns_convert(ns_remove1(tag));
6825 }
6826
6827 char *
6828 xsi_type_cond(Tnode *typ, int flag)
6829 { if (flag)
6830 return xsi_type(typ);
6831 return "";
6832 }
6833
6834 char *
6835 xsi_type_cond_u(Tnode *typ, int flag)
6836 { if (flag)
6837 return xsi_type_u(typ);
6838 return "";
6839 }
6840
6841 char *
6842 xsi_type_u(Tnode *typ)
6843 { Service *sp;
6844 char *s = NULL;
6845 if (tflag)
6846 return xsi_type(typ);
6847 if (typ->sym)
6848 s = prefix_of(typ->sym->name);
6849 if (!s && typ->id)
6850 s = prefix_of(typ->id->name);
6851 if (!s)
6852 return "";
6853 s = xsi_type(typ);
6854 for (sp = services; sp; sp = sp->next)
6855 if (sp->xsi_type && has_ns_eq(sp->ns, s))
6856 return s;
6857 return "";
6858 }
6859
6860 char *
6861 xsi_type(Tnode *typ)
6862 { if (!typ)
6863 return "NULL";
6864 if (is_dynamic_array(typ) && !has_ns(typ))
6865 return xsi_type_Darray(typ);
6866 if (typ->type == Tarray)
6867 return xsi_type_Tarray(typ);
6868 if (is_untyped(typ))
6869 return "";
6870 if (typ->sym)
6871 { if (!strncmp(typ->sym->name, "SOAP_ENV__", 10))
6872 return "";
6873 if (is_XML(typ))
6874 return "xsd:anyType";
6875 if (typ->type != Ttemplate)
6876 return ns_convert(typ->sym->name);
6877 }
6878 if (is_string(typ) || is_wstring(typ) || is_stdstring(typ) || is_stdwstring(typ))
6879 return "xsd:string";
6880 switch(typ->type){
6881 case Tchar:
6882 return "xsd:byte";
6883 case Twchar:
6884 return "wchar";
6885 case Tshort:
6886 return "xsd:short";
6887 case Tint:
6888 return "xsd:int";
6889 case Tlong:
6890 case Tllong:
6891 return "xsd:long";
6892 case Tfloat:
6893 return "xsd:float";
6894 case Tdouble:
6895 return "xsd:double";
6896 case Tldouble:
6897 return "xsd:decimal";
6898 case Tuchar:
6899 return "xsd:unsignedByte";
6900 case Tushort:
6901 return "xsd:unsignedShort";
6902 case Tuint:
6903 return "xsd:unsignedInt";
6904 case Tulong:
6905 case Tullong:
6906 return "xsd:unsignedLong";
6907 case Ttime:
6908 return "xsd:dateTime";
6909 case Tpointer:
6910 case Treference:
6911 return xsi_type((Tnode*)typ->ref);
6912 case Tenum:
6913 if ((Table*)typ->ref == booltable)
6914 return "xsd:boolean";
6915 case Tstruct:
6916 case Tclass:
6917 if (!strncmp(typ->id->name, "SOAP_ENV__", 10))
6918 return "";
6919 return ns_convert(typ->id->name);
6920 case Ttemplate:
6921 if ((Tnode*)typ->ref)
6922 return xsi_type((Tnode*)typ->ref);
6923 break;
6924 default:
6925 break;
6926 }
6927 return "";
6928 }
6929
6930 char *
6931 xml_tag(Tnode *typ)
6932 { if (!typ)
6933 return "NULL";
6934 if (typ->type == Tpointer || typ->type == Treference)
6935 return xml_tag((Tnode*)typ->ref);
6936 if (typ->sym)
6937 return ns_convert(typ->sym->name);
6938 return the_type(typ);
6939 }
6940
6941 char *
6942 wsdl_type(Tnode *typ, char *ns)
6943 { if (!typ)
6944 return "NULL";
6945 if ((is_qname(typ) || is_stdqname(typ)) && ns)
6946 return "xsd:QName";
6947 if (typ->sym)
6948 { if (is_XML(typ))
6949 return "xsd:anyType";
6950 else if (ns)
6951 return ns_convert(typ->sym->name);
6952 else
6953 return ns_remove(typ->sym->name);
6954 }
6955 return base_type(typ, ns);
6956 }
6957
6958 char *
6959 base_type(Tnode *typ, char *ns)
6960 { int d;
6961 char *s, *t;
6962 if (is_string(typ) || is_wstring(typ) || is_stdstring(typ) || is_stdwstring(typ))
6963 { if (ns)
6964 return "xsd:string";
6965 return "string";
6966 }
6967 if (is_dynamic_array(typ) && !is_binary(typ) && !has_ns(typ) && !is_untyped(typ))
6968 { s = ns_remove(wsdl_type(((Table*)typ->ref)->list->info.typ, NULL));
6969 if (ns && *ns)
6970 { t = (char*)emalloc(strlen(s)+strlen(ns_convert(ns))+13);
6971 strcpy(t, ns_convert(ns));
6972 strcat(t, ":");
6973 strcat(t, "ArrayOf");
6974 }
6975 else
6976 { t = (char*)emalloc(strlen(s)+12);
6977 strcpy(t, "ArrayOf");
6978 }
6979 strcat(t, s);
6980 d = get_Darraydims(typ);
6981 if (d)
6982 sprintf(t+strlen(t), "%dD", d);
6983 return t;
6984 }
6985 switch (typ->type){
6986 case Tchar :
6987 if (ns)
6988 return "xsd:byte";
6989 return "byte";
6990 case Twchar :
6991 if (ns)
6992 return "xsd:wchar";
6993 return "wchar";
6994 case Tshort :
6995 if (ns)
6996 return "xsd:short";
6997 return "short";
6998 case Tint :
6999 if (ns)
7000 return "xsd:int";
7001 return "int";
7002 case Tlong :
7003 case Tllong :
7004 if (ns)
7005 return "xsd:long";
7006 return "long";
7007 case Tfloat:
7008 if (ns)
7009 return "xsd:float";
7010 return "float";
7011 case Tdouble:
7012 if (ns)
7013 return "xsd:double";
7014 return "double";
7015 case Tldouble:
7016 if (ns)
7017 return "xsd:decimal";
7018 return "decimal";
7019 case Tuchar:
7020 if (ns)
7021 return "xsd:unsignedByte";
7022 return "unsignedByte";
7023 case Tushort:
7024 if (ns)
7025 return "xsd:unsignedShort";
7026 return "unsignedShort";
7027 case Tuint:
7028 if (ns)
7029 return "xsd:unsignedInt";
7030 return "unsignedInt";
7031 case Tulong:
7032 case Tullong:
7033 if (ns)
7034 return "xsd:unsignedLong";
7035 return "unsignedLong";
7036 case Ttime:
7037 if (ns)
7038 return "xsd:dateTime";
7039 return "dateTime";
7040 case Tpointer:
7041 case Treference:
7042 return wsdl_type((Tnode*)typ->ref, ns);
7043 case Tarray:
7044 if (is_fixedstring(typ))
7045 { if (typ->sym)
7046 { if (ns)
7047 return ns_convert(typ->sym->name);
7048 return ns_remove(typ->sym->name);
7049 }
7050 if (ns)
7051 return "xsd:string";
7052 return "string";
7053 }
7054 if (ns && *ns)
7055 { s = (char*)emalloc((strlen(ns_convert(ns))+strlen(c_ident(typ))+2)*sizeof(char));
7056 strcpy(s, ns_convert(ns));
7057 strcat(s, ":");
7058 strcat(s, c_ident(typ));
7059 return s;
7060 }
7061 else
7062 return c_ident(typ);
7063 case Tenum:
7064 if ((Table*)typ->ref == booltable)
7065 { if (ns)
7066 return "xsd:boolean";
7067 return "boolean";
7068 }
7069 case Tstruct:
7070 case Tclass:
7071 if (!has_ns(typ) && ns && *ns)
7072 { s = (char*)emalloc((strlen(ns_convert(ns))+strlen(typ->id->name)+2)*sizeof(char));
7073 strcpy(s, ns_convert(ns));
7074 strcat(s, ":");
7075 strcat(s, ns_convert(typ->id->name));
7076 return s;
7077 }
7078 else if (ns)
7079 return ns_convert(typ->id->name);
7080 else
7081 return ns_remove(typ->id->name);
7082 case Tunion:
7083 if (ns)
7084 return "xsd:choice";
7085 return "choice";
7086 case Ttemplate:
7087 if ((Tnode*)typ->ref)
7088 return wsdl_type((Tnode*)typ->ref, ns);
7089 break;
7090 default:
7091 break;
7092 }
7093 return "";
7094 }
7095
7096 char *
7097 the_type(Tnode *typ)
7098 { if (!typ)
7099 return "NULL";
7100 if (typ->type == Tarray || (is_dynamic_array(typ) && (eflag || (!has_ns(typ) && !is_untyped(typ)))))
7101 return "SOAP-ENC:Array";
7102 if (is_string(typ) || is_wstring(typ) || is_stdstring(typ) || is_stdwstring(typ))
7103 return "string";
7104 switch (typ->type)
7105 {
7106 case Tchar:
7107 return "byte";
7108 case Twchar:
7109 return "wchar";
7110 case Tshort:
7111 return "short";
7112 case Tint :
7113 return "int";
7114 case Tlong :
7115 case Tllong :
7116 return "long";
7117 case Tfloat:
7118 return "float";
7119 case Tdouble:
7120 return "double";
7121 case Tldouble:
7122 return "decimal";
7123 case Tuchar:
7124 return "unsignedByte";
7125 case Tushort:
7126 return "unsignedShort";
7127 case Tuint:
7128 return "unsignedInt";
7129 case Tulong:
7130 case Tullong:
7131 return "unsignedLong";
7132 case Ttime:
7133 return "dateTime";
7134 case Tpointer:
7135 case Treference:
7136 return the_type((Tnode*)typ->ref);
7137 case Tarray:
7138 return "SOAP-ENC:Array";
7139 case Tenum:
7140 if ((Table*)typ->ref == booltable)
7141 return "boolean";
7142 case Tstruct:
7143 case Tclass:
7144 return ns_convert(typ->id->name);
7145 default:
7146 break;
7147 }
7148 return "";
7149 }
7150
7151 /* c_type returns the type to be used in parameter declaration*/
7152 char *
7153 c_type(Tnode *typ)
7154 {
7155 char *p, *q, tempBuf[10];
7156 Tnode *temp;
7157 if (typ==0)
7158 return "NULL";
7159 switch(typ->type){
7160 case Tnone:
7161 return "";
7162 case Tvoid:
7163 return "void";
7164 case Tchar:
7165 return "char";
7166 case Twchar:
7167 return "wchar_t";
7168 case Tshort:
7169 return "short";
7170 case Tint :
7171 return "int";
7172 case Tlong :
7173 return "long";
7174 case Tllong :
7175 return "LONG64";
7176 case Tfloat:
7177 return "float";
7178 case Tdouble:
7179 return "double";
7180 case Tldouble:
7181 return "long double";
7182 case Tuchar:
7183 return "unsigned char";
7184 case Tushort:
7185 return "unsigned short";
7186 case Tuint:
7187 return "unsigned int";
7188 case Tulong:
7189 return "unsigned long";
7190 case Tullong:
7191 return "ULONG64";
7192 case Ttime:
7193 return "time_t";
7194 case Tstruct:
7195 p = (char*) emalloc((8+strlen(ident(typ->id->name))) *sizeof(char));
7196 strcpy(p, "struct ");
7197 strcat(p, ident(typ->id->name));
7198 break;
7199 case Tclass:
7200 p = ident(typ->id->name);
7201 break;
7202 case Tunion: p=(char*) emalloc((7+strlen(ident(typ->id->name))) *sizeof(char));
7203 strcpy(p, "union ");
7204 strcat(p, ident(typ->id->name));
7205 break;
7206 case Tenum:
7207 if ((Table*)typ->ref == booltable)
7208 return "bool";
7209 p=(char*) emalloc((6+strlen(ident(typ->id->name))) *sizeof(char));
7210 strcpy(p, "enum ");
7211 strcat(p, ident(typ->id->name));
7212 break;
7213 case Tpointer:
7214 p = c_type_id((Tnode*)typ->ref, "*");
7215 break;
7216 case Treference:
7217 p = c_type_id((Tnode*)typ->ref, "&");
7218 break;
7219 case Tarray:
7220 temp = typ;
7221 while(((Tnode*) (typ->ref))->type==Tarray){
7222 typ = (Tnode*)typ->ref;
7223 }
7224 p=(char*) emalloc((12+strlen(q = c_type((Tnode*)typ->ref))) *sizeof(char));
7225 if (((Tnode*)typ->ref)->type == Tpointer)
7226 sprintf(p,"%s",c_type((Tnode*)typ->ref));
7227 else
7228 strcpy(p, q);
7229 typ = temp;
7230 while(typ->type==Tarray){
7231 if (((Tnode*) typ->ref)->width)
7232 { sprintf(tempBuf,"[%d]",(typ->width / ((Tnode*) typ->ref)->width));
7233 strcat(p,tempBuf);
7234 }
7235 typ = (Tnode*)typ->ref;
7236 }
7237 break;
7238 case Ttemplate:
7239 if (typ->ref)
7240 { p=(char*)emalloc((strlen(q = c_type((Tnode*)typ->ref))+strlen(ident(typ->id->name))+4) *sizeof(char));
7241 strcpy(p, ident(typ->id->name));
7242 strcat(p, "<");
7243 strcat(p, q);
7244 strcat(p, " >");
7245 break;
7246 }
7247 default:
7248 return "UnknownType";
7249 }
7250 return p;
7251 }
7252
7253 char *
7254 c_storage(Storage sto)
7255 { char *p;
7256 static char buf[256];
7257 if (sto & Sconst)
7258 { p = c_storage(sto & ~Sconst);
7259 strcat(p, "const ");
7260 return p;
7261 }
7262 if (sto & Sconstptr)
7263 { p = c_storage(sto & ~Sconstptr);
7264 strcat(p, "const ");
7265 return p;
7266 }
7267 if (sto & Sauto)
7268 { p = c_storage(sto & ~Sauto);
7269 strcat(p, "auto ");
7270 return p;
7271 }
7272 if (sto & Sregister)
7273 { p = c_storage(sto & ~Sregister);
7274 strcat(p, "register ");
7275 return p;
7276 }
7277 if (sto & Sstatic)
7278 { p = c_storage(sto & ~Sstatic);
7279 strcat(p, "static ");
7280 return p;
7281 }
7282 if (sto & Sexplicit)
7283 { p = c_storage(sto & ~Sexplicit);
7284 strcat(p, "explicit ");
7285 return p;
7286 }
7287 if (sto & Sextern)
7288 { p = c_storage(sto & ~Sextern);
7289 return p;
7290 }
7291 if (sto & Stypedef)
7292 { p = c_storage(sto & ~Stypedef);
7293 strcat(p, "typedef ");
7294 return p;
7295 }
7296 if (sto & Svirtual)
7297 { p = c_storage(sto & ~Svirtual);
7298 strcat(p, "virtual ");
7299 return p;
7300 }
7301 if (sto & Sfriend)
7302 { p = c_storage(sto & ~Sfriend);
7303 strcat(p, "friend ");
7304 return p;
7305 }
7306 if (sto & Sinline)
7307 { p = c_storage(sto & ~Sinline);
7308 strcat(p, "inline ");
7309 return p;
7310 }
7311 buf[0]= '\0';
7312 return buf;
7313 }
7314
7315 char *
7316 c_init(Entry *e)
7317 { static char buf[1024];
7318 buf[0] = '\0';
7319 if (e && e->info.hasval)
7320 { switch (e->info.typ->type)
7321 { case Tchar:
7322 case Twchar:
7323 case Tuchar:
7324 case Tshort:
7325 case Tushort:
7326 case Tint:
7327 case Tuint:
7328 case Ttime:
7329 sprintf(buf, " = " SOAP_LONG_FORMAT, e->info.val.i);
7330 break;
7331 case Tlong:
7332 sprintf(buf, " = " SOAP_LONG_FORMAT "L", e->info.val.i);
7333 break;
7334 case Tulong:
7335 sprintf(buf, " = " SOAP_LONG_FORMAT "UL", e->info.val.i);
7336 break;
7337 case Tllong:
7338 sprintf(buf, " = " SOAP_LONG_FORMAT "LL", e->info.val.i);
7339 break;
7340 case Tullong:
7341 sprintf(buf, " = " SOAP_LONG_FORMAT "ULL", e->info.val.i);
7342 break;
7343 case Tfloat:
7344 case Tdouble:
7345 sprintf(buf, " = %g", e->info.val.r);
7346 break;
7347 case Tldouble:
7348 sprintf(buf, " = %gL", e->info.val.r);
7349 break;
7350 case Tenum:
7351 if (e->info.val.i <= 0x7FFFLL && e->info.val.i >= -0x8000LL)
7352 sprintf(buf, " = (%s)" SOAP_LONG_FORMAT, c_type(e->info.typ), e->info.val.i);
7353 else
7354 sprintf(buf, " = (%s)" SOAP_LONG_FORMAT "LL", c_type(e->info.typ), e->info.val.i);
7355 break;
7356 default:
7357 if (is_stdstring(e->info.typ) && e->info.val.s && strlen(e->info.val.s) < sizeof(buf)-6)
7358 sprintf(buf, " = \"%s\"", cstring(e->info.val.s));
7359 else if (is_stdwstring(e->info.typ) && e->info.val.s && strlen(e->info.val.s) < sizeof(buf)-6)
7360 sprintf(buf, " = L\"%s\"", cstring(e->info.val.s));
7361 else if (is_wstring(e->info.typ) && e->info.val.s && strlen(e->info.val.s) < sizeof(buf)-6)
7362 sprintf(buf, " = (wchar_t*)L\"%s\"", cstring(e->info.val.s));
7363 else if (e->info.val.s && strlen(e->info.val.s) < sizeof(buf)-6)
7364 sprintf(buf, " = (char*)\"%s\"", cstring(e->info.val.s));
7365 else if (e->info.typ->type == Tpointer)
7366 sprintf(buf, " = NULL");
7367 break;
7368 }
7369 }
7370 return buf;
7371 }
7372
7373 /* c_type_id returns the type to be used in parameter declaration */
7374 char *
7375 c_type_id(Tnode *typ, char *name)
7376 {
7377 char *id,*p,*q,tempBuf[10];
7378 Tnode *temp;
7379 Entry *e;
7380 if (!typ)
7381 return "NULL";
7382 id = ident(name);
7383 switch(typ->type)
7384 {
7385 case Tnone:
7386 p = id;
7387 break;
7388 case Tvoid:
7389 p = (char*)emalloc(6+strlen(id));
7390 strcpy(p, "void ");
7391 strcat(p, id);
7392 break;
7393 case Tchar:
7394 p = (char*)emalloc(6+strlen(id));
7395 strcpy(p, "char ");
7396 strcat(p, id);
7397 break;
7398 case Twchar:
7399 p = (char*)emalloc(9+strlen(id));
7400 strcpy(p, "wchar_t ");
7401 strcat(p, id);
7402 break;
7403 case Tshort:
7404 p = (char*)emalloc(7+strlen(id));
7405 strcpy(p, "short ");
7406 strcat(p, id);
7407 break;
7408 case Tint :
7409 p = (char*)emalloc(5+strlen(id));
7410 strcpy(p, "int ");
7411 strcat(p, id);
7412 break;
7413 case Tlong :
7414 p = (char*)emalloc(6+strlen(id));
7415 strcpy(p, "long ");
7416 strcat(p, id);
7417 break;
7418 case Tllong :
7419 p = (char*)emalloc(8+strlen(id));
7420 strcpy(p, "LONG64 ");
7421 strcat(p, id);
7422 break;
7423 case Tfloat:
7424 p = (char*)emalloc(7+strlen(id));
7425 strcpy(p, "float ");
7426 strcat(p, id);
7427 break;
7428 case Tdouble:
7429 p = (char*)emalloc(8+strlen(id));
7430 strcpy(p, "double ");
7431 strcat(p, id);
7432 break;
7433 case Tldouble:
7434 p = (char*)emalloc(13+strlen(id));
7435 strcpy(p, "long double ");
7436 strcat(p, id);
7437 break;
7438 case Tuchar:
7439 p = (char*)emalloc(15+strlen(id));
7440 strcpy(p, "unsigned char ");
7441 strcat(p, id);
7442 break;
7443 case Tushort:
7444 p = (char*)emalloc(16+strlen(id));
7445 strcpy(p, "unsigned short ");
7446 strcat(p, id);
7447 break;
7448 case Tuint:
7449 p = (char*)emalloc(14+strlen(id));
7450 strcpy(p, "unsigned int ");
7451 strcat(p, id);
7452 break;
7453 case Tulong:
7454 p = (char*)emalloc(15+strlen(id));
7455 strcpy(p, "unsigned long ");
7456 strcat(p, id);
7457 break;
7458 case Tullong:
7459 p = (char*)emalloc(9+strlen(id));
7460 strcpy(p, "ULONG64 ");
7461 strcat(p, id);
7462 break;
7463 case Ttime:
7464 p = (char*)emalloc(8+strlen(id));
7465 strcpy(p, "time_t ");
7466 strcat(p, id);
7467 break;
7468 case Tstruct:
7469 p=(char*) emalloc((9+strlen(ident(typ->id->name))+strlen(id)) *sizeof(char));
7470 strcpy(p, "struct ");
7471 strcat(p, ident(typ->id->name));
7472 strcat(p, " ");
7473 strcat(p, id);
7474 break;
7475 case Tclass:
7476 if (!typ->classed && !is_imported(typ))
7477 { p=(char*) emalloc((8+strlen(ident(typ->id->name))+strlen(id)) *sizeof(char));
7478 strcpy(p, "class ");
7479 strcat(p, ident(typ->id->name));
7480 typ->classed = True;
7481 }
7482 else
7483 { p=(char*) emalloc((2+strlen(ident(typ->id->name))+strlen(id)) *sizeof(char));
7484 strcpy(p, ident(typ->id->name));
7485 }
7486 strcat(p, " ");
7487 strcat(p, id);
7488 break;
7489 case Tunion:
7490 p=(char*) emalloc((8+strlen(ident(typ->id->name))+strlen(id)) *sizeof(char));
7491 strcpy(p, "union ");
7492 strcat(p, ident(typ->id->name));
7493 strcat(p, " ");
7494 strcat(p, id);
7495 break;
7496 case Tenum:
7497 if ((Table*)typ->ref == booltable)
7498 { p = (char*)emalloc((strlen(id)+6)*sizeof(char));
7499 strcpy(p, "bool ");
7500 strcat(p, id);
7501 return p;
7502 }
7503 p=(char*) emalloc((7+strlen(ident(typ->id->name))+strlen(id)) *sizeof(char));
7504 strcpy(p, "enum ");
7505 strcat(p, ident(typ->id->name));
7506 strcat(p, " ");
7507 strcat(p, id);
7508 break;
7509 case Tpointer:
7510 p = (char*)emalloc(strlen(id)+2);
7511 strcpy(p+1, id);
7512 p[0] = '*';
7513 p = c_type_id((Tnode*)typ->ref, p);
7514 break;
7515 case Treference:
7516 p = (char*)emalloc(strlen(id)+2);
7517 strcpy(p+1, id);
7518 p[0] = '&';
7519 p = c_type_id((Tnode*)typ->ref, p);
7520 break;
7521 case Tarray:
7522 temp = typ;
7523 while(((Tnode*) (typ->ref))->type==Tarray){
7524 typ = (Tnode*)typ->ref;
7525 }
7526 p=(char*) emalloc((12+strlen(q = c_type_id((Tnode*)typ->ref, id))) *sizeof(char));
7527 strcpy(p, q);
7528 typ = temp;
7529 while(typ->type==Tarray){
7530 if (((Tnode*) typ->ref)->width)
7531 { sprintf(tempBuf,"[%d]",(typ->width / ((Tnode*) typ->ref)->width));
7532 strcat(p,tempBuf);
7533 }
7534 typ = (Tnode*)typ->ref;
7535 }
7536 /*if(((Tnode*) (typ->ref))->type==Tarray){
7537 sprintf(p,"%s [%d]",c_type((Tnode*)typ->ref),(typ->width / ((Tnode*) typ->ref)->width));
7538 }else
7539 sprintf(p,"%s a[%d]",c_type((Tnode*)typ->ref),(typ->width /((Tnode*) typ->ref)->width));*/
7540 break;
7541 case Tfun:
7542 if (strncmp(id, "operator ", 9))
7543 q = c_type_id(((FNinfo*)typ->ref)->ret, id);
7544 else
7545 q = id;
7546 p = (char*)emalloc(1024);
7547 strcpy(p, q);
7548 strcat(p, "(");
7549 for (e = ((FNinfo*)typ->ref)->args->list; e; e = e->next)
7550 { strcat(p, c_storage(e->info.sto));
7551 if (e->info.typ->type != Tvoid)
7552 { strcat(p, c_type_id(e->info.typ, e->sym->name));
7553 strcat(p, c_init(e));
7554 }
7555 else
7556 strcat(p, "void");
7557 if (e->next)
7558 strcat(p, ", ");
7559 }
7560 strcat(p, ")");
7561 break;
7562 case Ttemplate:
7563 if (typ->ref)
7564 { p=(char*)emalloc((strlen(q = c_type((Tnode*)typ->ref))+strlen(ident(typ->id->name))+strlen(id)+4) *sizeof(char));
7565 strcpy(p, ident(typ->id->name));
7566 strcat(p, "<");
7567 strcat(p, q);
7568 strcat(p, " >");
7569 strcat(p, id);
7570 break;
7571 }
7572 default:
7573 return "UnknownType";
7574 }
7575 return p;
7576 }
7577
7578 char *
7579 xsi_type_Tarray(Tnode *typ)
7580 { Tnode *t;
7581 int cardinality;
7582 char *p, *s;
7583 t = (Tnode*)typ->ref;
7584 if (is_fixedstring(typ))
7585 { if (typ->sym)
7586 return ns_convert(typ->sym->name);
7587 return "xsd:string";
7588 }
7589 cardinality = 1;
7590 while (t->type == Tarray || (is_dynamic_array(t) && !has_ns(t) && !is_untyped(typ)))
7591 { if( t->type == Tarray)
7592 t = (Tnode*)t->ref;
7593 else
7594 t = (Tnode*)((Table*)t->ref)->list->info.typ->ref;
7595 cardinality++;
7596 }
7597 s = xsi_type(t);
7598 if (!*s)
7599 s = wsdl_type(t, "");
7600 p = (char*)emalloc(strlen(s)+cardinality+3);
7601 strcpy(p, s);
7602 if (cardinality > 1)
7603 { strcat(p, "[");
7604 for (; cardinality > 2; cardinality--)
7605 strcat(p, ",");
7606 strcat(p, "]");
7607 }
7608 return p;
7609 }
7610
7611 char *
7612 xsi_type_Darray(Tnode *typ)
7613 { Tnode *t;
7614 Entry *q;
7615 int cardinality;
7616 char *p, *s;
7617 if (!typ->ref)
7618 return "";
7619 q = ((Table*)typ->ref)->list;
7620 while (q && q->info.typ->type == Tfun)
7621 q = q->next;
7622 t = (Tnode*)q->info.typ->ref;
7623 cardinality = 1;
7624 while (t->type == Tarray || (is_dynamic_array(t) && !has_ns(t) && !is_untyped(typ)))
7625 { if (t->type == Tarray)
7626 t = (Tnode*)t->ref;
7627 else
7628 { q = ((Table*)t->ref)->list;
7629 while (q && q->info.typ->type == Tfun)
7630 q = q->next;
7631 t = (Tnode*)q->info.typ->ref;
7632 }
7633 cardinality++;
7634 }
7635 s = xsi_type(t);
7636 if (!*s)
7637 s = wsdl_type(t, "");
7638 p = (char*)emalloc(strlen(s)+cardinality*2+1);
7639 strcpy(p, s);
7640 if (cardinality > 1)
7641 { strcat(p, "[");
7642 for (; cardinality > 2; cardinality--)
7643 strcat(p, ",");
7644 strcat(p, "]");
7645 }
7646 return p;
7647 }
7648
7649 void
7650 generate(Tnode *typ)
7651 {
7652 if (kflag && is_XML(typ))
7653 { soap_traverse(typ);
7654 return;
7655 }
7656 if (is_transient(typ) || typ->type == Twchar || is_XML(typ) || is_void(typ))
7657 return;
7658
7659 if (lflag && typ->type == Tint && !typ->sym)
7660 { fprintf(fhead,"\n\n#ifndef %s",soap_type(typ));
7661 fprintf(fhead,"\n#define %s (%d)",soap_type(typ),typ->num);
7662 fprintf(fhead,"\n#endif");
7663 fprintf(fhead,"\n\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_int(struct soap*, int*);");
7664 fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_int(struct soap*, const char*, int, const int*, const char*);");
7665 fprintf(fhead,"\nSOAP_FMAC1 int* SOAP_FMAC2 soap_in_int(struct soap*, const char*, int*, const char*);");
7666 return; /* do not generate int serializers in libs */
7667 }
7668 else if (is_imported(typ) && (typ->type != Tint || typ->sym))
7669 return;
7670 if (is_typedef(typ) && is_element(typ))
7671 fprintf(fhead,"\n\n/* %s is a typedef element/attribute synonym for %s */", c_ident(typ), t_ident(typ));
7672 if (is_primitive(typ) || is_string(typ) || is_wstring(typ))
7673 { if (!Qflag && is_external(typ) && namespaceid)
7674 { char *id = namespaceid;
7675 fprintf(fhead,"\n\n}");
7676 fprintf(fout,"\n\n}");
7677 namespaceid = NULL;
7678 fprintf(fhead,"\n\n#ifndef %s",soap_type(typ));
7679 fprintf(fhead,"\n#define %s (%d)",soap_type(typ),typ->num);
7680 fprintf(fhead,"\n#endif");
7681 namespaceid = id;
7682 }
7683 fprintf(fhead,"\n\n#ifndef %s",soap_type(typ));
7684 fprintf(fhead,"\n#define %s (%d)",soap_type(typ),typ->num);
7685 fprintf(fhead,"\n#endif");
7686 fflush(fhead);
7687 soap_default(typ);
7688 soap_serialize(typ);
7689 if (kflag)
7690 soap_traverse(typ);
7691 soap_out(typ);
7692 soap_in(typ);
7693 if (!Qflag && is_external(typ) && namespaceid)
7694 { fprintf(fhead,"\n\nnamespace %s {", namespaceid);
7695 fprintf(fout,"\n\nnamespace %s {", namespaceid);
7696 }
7697 soap_put(typ);
7698 soap_get(typ);
7699 return;
7700 }
7701 switch(typ->type)
7702 {
7703 case Ttemplate:
7704 case Tenum:
7705 case Tpointer:
7706 case Tarray:
7707 case Tstruct:
7708 case Tclass:
7709 case Tunion:
7710 if (is_header_or_fault(typ) || is_body(typ))
7711 { fprintf(fhead,"\n\n#ifndef WITH_NOGLOBAL");
7712 fprintf(fout,"\n\n#ifndef WITH_NOGLOBAL");
7713 }
7714 if (!Qflag && is_external(typ) && namespaceid)
7715 { char *id = namespaceid;
7716 fprintf(fhead,"\n\n}");
7717 fprintf(fout,"\n\n}");
7718 namespaceid = NULL;
7719 fprintf(fhead,"\n\n#ifndef %s",soap_type(typ));
7720 fprintf(fhead,"\n#define %s (%d)",soap_type(typ),typ->num);
7721 fprintf(fhead,"\n#endif");
7722 namespaceid = id;
7723 }
7724 fprintf(fhead,"\n\n#ifndef %s",soap_type(typ));
7725 fprintf(fhead,"\n#define %s (%d)",soap_type(typ),typ->num);
7726 fprintf(fhead,"\n#endif");
7727 fflush(fhead);
7728 soap_default(typ);
7729 soap_serialize(typ);
7730 if (kflag)
7731 soap_traverse(typ);
7732 soap_out(typ);
7733 soap_in(typ);
7734 if (!Qflag && is_external(typ) && namespaceid)
7735 { fprintf(fhead,"\n\nnamespace %s {", namespaceid);
7736 fprintf(fout,"\n\nnamespace %s {", namespaceid);
7737 }
7738 soap_put(typ);
7739 soap_get(typ);
7740 if (typ->type == Tstruct || typ->type == Tclass || typ->type == Ttemplate)
7741 soap_instantiate_class(typ);
7742 if (is_header_or_fault(typ) || is_body(typ))
7743 { fprintf(fhead,"\n\n#endif");
7744 fprintf(fout,"\n\n#endif");
7745 }
7746 break;
7747 default:
7748 break;
7749 }
7750 }
7751
7752 void
7753 matlab_gen_sparseStruct(void)
7754 {
7755 fprintf(fmheader,"\nstruct soapSparseArray{\n");
7756 fprintf(fmheader," int *ir;\n");
7757 fprintf(fmheader," int *jc;\n");
7758 fprintf(fmheader," double *pr;\n");
7759 fprintf(fmheader," int num_columns;\n");
7760 fprintf(fmheader," int num_rows;\n");
7761 fprintf(fmheader," int nzmax;\n");
7762 fprintf(fmheader,"};\n");
7763 }
7764
7765 void
7766 matlab_c_to_mx_sparse(void)
7767 {
7768 fprintf(fmheader,"\nmxArray* c_to_mx_soapSparseArray(struct soapSparseArray);\n");
7769 fprintf(fmatlab,"\nmxArray* c_to_mx_soapSparseArray(struct soapSparseArray a)\n");
7770 fprintf(fmatlab,"{\n");
7771 fprintf(fmatlab," mxArray *b;\n");
7772 fprintf(fmatlab," b = mxCreateSparse(a.num_rows, a.num_columns, a.nzmax, mxREAL);\n");
7773 fprintf(fmatlab," mxSetIr(b,a.ir);\n");
7774 fprintf(fmatlab," mxSetJc(b,a.jc);\n");
7775 fprintf(fmatlab," mxSetPr(b,a.pr);\n");
7776 fprintf(fmatlab," return b;\n");
7777 fprintf(fmatlab,"}\n");
7778 }
7779
7780 void
7781 matlab_mx_to_c_sparse(void)
7782 {
7783 fprintf(fmheader,"\nmxArray* mx_to_c_soapSparseArray(const mxArray *, struct soapSparseArray *);\n");
7784 fprintf(fmatlab,"\nmxArray* mx_to_c_soapSparseArray(const mxArray *a, struct soapSparseArray *b)\n");
7785 fprintf(fmatlab,"{\n");
7786 fprintf(fmatlab," if(!mxIsSparse(a))\n");
7787 fprintf(fmatlab," {\n");
7788 fprintf(fmatlab," mexErrMsgTxt(\"Input should be a sparse array.\");\n");
7789 fprintf(fmatlab," }\n");
7790
7791 fprintf(fmatlab," /* Get the starting positions of the data in the sparse array. */ \n");
7792 fprintf(fmatlab," b->pr = mxGetPr(a);\n");
7793 fprintf(fmatlab," b->ir = mxGetIr(a);\n");
7794 fprintf(fmatlab," b->jc = mxGetJc(a);\n");
7795 fprintf(fmatlab," b->num_columns = mxGetN(a);\n");
7796 fprintf(fmatlab," b->num_rows = mxGetM(a);\n");
7797 fprintf(fmatlab," b->nzmax = mxGetNzmax(a);\n");
7798 fprintf(fmatlab,"}\n");
7799 }
7800
7801 void
7802 matlab_mx_to_c_dynamicArray(Tnode* typ)
7803 {
7804 int d;
7805 Entry *p;
7806
7807 p = is_dynamic_array(typ);
7808
7809 fprintf(fmatlab,"{\n");
7810 fprintf(fmatlab,"\tint i, numdims;\n");
7811 fprintf(fmatlab,"\tconst int *dims;\n");
7812 fprintf(fmatlab,"\tdouble *temp;\n");
7813 fprintf(fmatlab,"\tint size = 1;\n");
7814 fprintf(fmatlab,"\tint ret;\n");
7815 fprintf(fmatlab,"\tnumdims = mxGetNumberOfDimensions(a);\n");
7816 fprintf(fmatlab,"\tdims = mxGetDimensions(a);\n");
7817
7818 d = get_Darraydims(typ);
7819 fprintf(fmatlab,"\tif (numdims != %d)\n", d);
7820 fprintf(fmatlab,"\t\tmexErrMsgTxt(\"Incompatible array specifications in C and mx.\");\n");
7821
7822 /*
7823 fprintf(fmatlab,"\tfor(i=0;i<numdims; i++) {\n");
7824 fprintf(fmatlab,"\t b->__size[i] = dims[i];\n");
7825 fprintf(fmatlab,"\t}\n");
7826 */
7827
7828 if((((Tnode *)p->info.typ->ref)->type != Tchar) && (((Tnode *)p->info.typ->ref)->type != Tuchar))
7829 {
7830 fprintf(fmatlab,"\ttemp = (double*)mxGetPr(a);\n");
7831 fprintf(fmatlab,"\tif (!temp)\n\t\tmexErrMsgTxt(\"mx_to_c_ArrayOfdouble: Pointer to data is NULL\");\n");
7832 }
7833
7834 fprintf(fmatlab,"\tfor (i = 0; i < numdims; i++) {\n");
7835 fprintf(fmatlab,"\t\tif (b->__size[i] < dims[i])\n");
7836 fprintf(fmatlab,"\t\t\tmexErrMsgTxt(\"Incompatible array dimensions in C and mx.\");\n");
7837 fprintf(fmatlab,"\t\tsize *= dims[i];\n");
7838 fprintf(fmatlab,"\t}\n");
7839
7840 if((((Tnode *)p->info.typ->ref)->type != Tchar) && (((Tnode *)p->info.typ->ref)->type != Tuchar))
7841 {
7842 fprintf(fmatlab,"\tfor (i = 0; i < size; i++)\n");
7843 fprintf(fmatlab,"\t\tb->__ptr[i] = (%s)*temp++;\n", c_type((Tnode*)p->info.typ->ref));
7844 }
7845 else
7846 {
7847 fprintf(fmatlab,"\tret = mxGetString(a, b->__ptr, size + 1);\n");
7848 fprintf(fmatlab,"\tmexPrintf(\"ret = %%d, b->__ptr = %%s, size = %%d\", ret, b->__ptr, size);\n");
7849 }
7850 fprintf(fmatlab,"\n}\n");
7851
7852 fflush(fmatlab);
7853 }
7854
7855
7856 void
7857 matlab_c_to_mx_dynamicArray(Tnode* typ)
7858 {
7859 int d,i;
7860 Entry *p;
7861
7862 p = is_dynamic_array(typ);
7863
7864 fprintf(fmatlab,"{\n");
7865 fprintf(fmatlab,"\tmxArray *out;\n");
7866 fprintf(fmatlab,"\t%s;\n",c_type_id((Tnode*)p->info.typ->ref,"*temp"));
7867 d = get_Darraydims(typ);
7868 fprintf(fmatlab,"\tint i;\n");
7869
7870 fprintf(fmatlab,"\tint ndim = %d, dims[%d] = {", d, d);
7871 for (i = 0; i < d; i++)
7872 {
7873 if(i==0)
7874 fprintf(fmatlab,"a.__size[%d]",i);
7875 else
7876 fprintf(fmatlab,", a.__size[%d]",i);
7877 }
7878 fprintf(fmatlab,"};\n");
7879
7880 fprintf(fmatlab,"\tint size = ");
7881 for (i = 0; i < d; i++)
7882 {
7883 if(i==0)
7884 fprintf(fmatlab,"dims[%d]",i);
7885 else
7886 fprintf(fmatlab,"*dims[%d]",i);
7887 }
7888 fprintf(fmatlab,";\n");
7889 if((((Tnode *)p->info.typ->ref)->type != Tchar) && (((Tnode *)p->info.typ->ref)->type != Tuchar))
7890 {
7891 fprintf(fmatlab,"\tout = mxCreateNumericArray(ndim, dims, %s, mxREAL);\n",get_mxClassID((Tnode*)p->info.typ->ref));
7892 fprintf(fmatlab,"\tif (!out)\n\t\tmexErrMsgTxt(\"Could not create mxArray.\");\n");
7893 fprintf(fmatlab,"\ttemp = (%s) mxGetPr(out);\n",c_type_id((Tnode*)p->info.typ->ref,"*"));
7894 fprintf(fmatlab,"\tif (!temp)\n\t\tmexErrMsgTxt(\"matlab_array_c_to_mx: Pointer to data is NULL\");\n");
7895
7896 fprintf(fmatlab,"\tfor (i = 0; i < size; i++)\n");
7897 fprintf(fmatlab,"\t\t*temp++ = a.__ptr[i];\n");
7898 }
7899 else
7900 {
7901 fprintf(fmatlab,"\tout = mxCreateString(a.__ptr);\n");
7902 fprintf(fmatlab,"\tif (!out)\n\t\tmexErrMsgTxt(\"Could not create mxArray.\");\n");
7903 }
7904 fprintf(fmatlab,"\treturn out;\n}\n");
7905 fflush(fmatlab);
7906 }
7907
7908 char*
7909 get_mxClassID(Tnode* typ)
7910 {
7911
7912 switch(typ->type)
7913 {
7914 case Tdouble:
7915 return "mxDOUBLE_CLASS";
7916 case Tfloat:
7917 return "mxSINGLE_CLASS";
7918 case Tshort:
7919 return "mxINT16_CLASS";
7920 case Tushort:
7921 return "mxUINT16_CLASS";
7922 case Tint:
7923 return "mxINT32_CLASS";
7924 case Tuint:
7925 return "mxUINT32_CLASS";
7926 case Tlong:
7927 return "mxINT32_CLASS";
7928 case Tulong:
7929 return "mxUINT32_CLASS";
7930 case Tllong:
7931 return "mxINT64_CLASS";
7932 case Tullong:
7933 return "mxUINT64_CLASS";
7934 case Tchar:
7935 return "mxCHAR_CLASS";
7936 case Tuchar:
7937 return "mxCHAR_CLASS";
7938 default:
7939 return "";
7940 };
7941 }
7942
7943 /*Function not in use.*/
7944 void
7945 matlab_array_c_to_mx(Tnode* typ)
7946 {
7947 Tnode* temp;
7948 int d,i;
7949
7950 fprintf(fmatlab,"{\n\tint rows, r, cols, c;\n");
7951 fprintf(fmatlab,"\tmxArray* out;\n");
7952 fprintf(fmatlab,"\tdouble* temp;\n");
7953 d = get_dimension(typ);
7954 fprintf(fmatlab,"\tint ndim = %d, dims[%d] = {",d,d);
7955 temp=typ;
7956 for(i=0;i<d; i++)
7957 {
7958 if(i==0)
7959 fprintf(fmatlab,"%d",temp->width / ((Tnode*) temp->ref)->width);
7960 else
7961 fprintf(fmatlab,",%d",temp->width / ((Tnode*) temp->ref)->width);
7962 temp=(Tnode*)typ->ref;
7963 }
7964 fprintf(fmatlab,"};\n");
7965
7966 fprintf(fmatlab,"\tout = mxCreateNumericArray(ndim, dims, mxDOUBLE_CLASS, mxREAL);\n");
7967 fprintf(fmatlab,"\ttemp = (double *) mxGetPr(out);\n");
7968 fprintf(fmatlab,"\tif (!out)\n\t\tmexErrMsgTxt(\"Could not create mxArray.\");\n");
7969 fprintf(fmatlab,"\tif (!temp)\n\t\tmexErrMsgTxt(\"matlab_array_c_to_mx: Pointer to data is NULL\");\n");
7970 fprintf(fmatlab,"\trows = mxGetM(out);\n");
7971 fprintf(fmatlab,"\tif (!rows)\n\t\tmexErrMsgTxt(\"matlab_array_c_to_mx: Data has zero rows\");\n");
7972 fprintf(fmatlab,"\tcols = mxGetN(out);\n");
7973 fprintf(fmatlab,"\tif (!cols)\n\t\tmexErrMsgTxt(\"matlab_array_c_to_mx: Data has zero columns\");\n");
7974 fprintf(fmatlab,"\tfor (c = 0; c < cols; c++)\n");
7975 fprintf(fmatlab,"\t\tfor (r = 0; r < rows; r++)\n");
7976 fprintf(fmatlab,"\t\t\t*temp++ = z->a[r][c];\n");
7977 fprintf(fmatlab,"\treturn out;\n}\n");
7978 fflush(fmatlab);
7979 }
7980
7981
7982 void matlab_c_to_mx_pointer(Tnode* typ)
7983 {
7984 if (!typ->ref)
7985 return;
7986
7987 fprintf(fmheader,"\nmxArray* c_to_mx_%s(%s);\n",c_ident(typ),c_type_id(typ, ""));
7988 fprintf(fmatlab,"\nmxArray* c_to_mx_%s(%s)\n",c_ident(typ),c_type_id(typ, "a"));
7989 fprintf(fmatlab,"{\n");
7990 fprintf(fmatlab,"\tmxArray *fout;\n");
7991 fprintf(fmatlab,"\tfout = c_to_mx_%s(*a);\n",c_ident((Tnode*)typ->ref));
7992 fprintf(fmatlab,"\treturn fout;\n");
7993 fprintf(fmatlab,"}\n");
7994 }
7995
7996 void matlab_mx_to_c_pointer(Tnode* typ)
7997 {
7998 if (!typ->ref)
7999 return;
8000 fprintf(fmheader,"\nvoid mx_to_c_%s(const mxArray*,%s);\n",c_ident(typ),c_type_id(typ, "*"));
8001 fprintf(fmatlab,"\nvoid mx_to_c_%s(const mxArray* a,%s)\n",c_ident(typ),c_type_id(typ, "*b"));
8002 fprintf(fmatlab,"{\n\tmx_to_c_%s(a,*b);\n",c_ident((Tnode*)typ->ref));
8003 fprintf(fmatlab,"\n}\n");
8004 }
8005
8006 void func2(Tnode* typ)
8007 {
8008 Table *table,*t;
8009 Entry *p;
8010
8011 fprintf(fmatlab,"\tif(!mxIsStruct(a))\n\t\tmexErrMsgTxt(\"Input must be a structure.\");\n");
8012
8013 table=(Table*)typ->ref;
8014 for (t = table; t != (Table *) 0; t = t->prev) {
8015 for (p = t->list; p != (Entry*) 0; p = p->next) {
8016 if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
8017 {
8018 fprintf(fmatlab,"\t{mxArray *tmp = mxGetField(a,0,\"%s\");\n",ident(p->sym->name));
8019 fprintf(fmatlab,"\tif (!tmp) {\n");
8020 fprintf(fmatlab,"\t\tmexErrMsgTxt(\"Above member field is empty!\");\n\t}\n");
8021 fprintf(fmatlab,"\tmx_to_c_%s(tmp,&(b->%s));}\n",c_ident(p->info.typ),ident(p->sym->name));
8022 }
8023 }
8024 }
8025 }
8026
8027 void
8028 matlab_mx_to_c_struct(Tnode* typ)
8029 {
8030 if (!typ->ref)
8031 return;
8032
8033
8034 if (is_dynamic_array(typ))
8035 {
8036 fprintf(fmheader,"\nvoid mx_to_c_%s(const mxArray*, %s);\n",c_ident(typ),c_type_id(typ, "*"));
8037 fprintf(fmatlab,"\nvoid mx_to_c_%s(const mxArray* a, %s)\n",c_ident(typ),c_type_id(typ, "*b"));
8038 matlab_mx_to_c_dynamicArray(typ);
8039 return;
8040 }
8041 else if(strstr(c_type_id(typ, ""),"soapSparseArray"))
8042 {
8043 return;
8044 }
8045
8046 fprintf(fmheader,"\nvoid mx_to_c_%s(const mxArray*, %s);\n",c_ident(typ),c_type_id(typ, "*"));
8047 fprintf(fmatlab,"\nvoid mx_to_c_%s(const mxArray* a, %s)\n",c_ident(typ),c_type_id(typ, "*b"));
8048 fprintf(fmatlab,"{\n");
8049
8050 func2(typ);
8051 fprintf(fmatlab,"\n}\n");
8052
8053 return;
8054 }
8055
8056
8057
8058 void
8059 matlab_c_to_mx_struct(Tnode* typ)
8060 {
8061 Table *table,*t;
8062 Entry *p;
8063 int number_of_fields=0;
8064
8065 if (!typ->ref)
8066 return;
8067
8068 if (is_dynamic_array(typ))
8069 {
8070 fprintf(fmheader,"\nmxArray* c_to_mx_%s(%s);\n",c_ident(typ),c_type_id(typ, ""));
8071 fprintf(fmatlab,"\nmxArray* c_to_mx_%s(%s)\n",c_ident(typ),c_type_id(typ, "a"));
8072 matlab_c_to_mx_dynamicArray(typ);
8073 return;
8074 }
8075 else if(strstr(c_type_id(typ, ""),"soapSparseArray"))
8076 {
8077 return;
8078 }
8079
8080 fprintf(fmheader,"\nmxArray* c_to_mx_%s(%s);\n",c_ident(typ),c_type_id(typ, ""));
8081 fprintf(fmatlab,"\nmxArray* c_to_mx_%s(%s)\n",c_ident(typ),c_type_id(typ, "a"));
8082 table=(Table*)typ->ref;
8083 fprintf(fmatlab,"{\n\tconst char* fnames[] = {");
8084 for (t = table; t != (Table *) 0; t = t->prev) {
8085 for (p = t->list; p != (Entry*) 0; p = p->next) {
8086 if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
8087 {
8088 if(number_of_fields)
8089 fprintf(fmatlab,",\"%s\"",ident(p->sym->name));
8090 else
8091 fprintf(fmatlab,"\"%s\"",ident(p->sym->name));
8092 number_of_fields++;
8093 }
8094 }
8095 }
8096 fprintf(fmatlab,"}; /* pointers to member field names */\n");
8097
8098 fprintf(fmatlab,"\tint rows = 1, cols = 1;\n\tint index = 0;\n\tint number_of_fields = %d;\n\tmxArray *struct_array_ptr;\n",number_of_fields);
8099 fprintf(fmatlab,"\t/* Create a 1x1 struct matrix for output */\n");
8100 fprintf(fmatlab,"\tstruct_array_ptr = mxCreateStructMatrix(rows, cols, number_of_fields, fnames);\n\tmexPrintf(\"6\");\n\tif(struct_array_ptr == NULL) {\n\t\tmexPrintf(\"COULDNT CREATE A MATRIX\");}\n\tmexPrintf(\"7\");\n");
8101
8102
8103 for (t = table; t != (Table *) 0; t = t->prev) {
8104 for (p = t->list; p != (Entry*) 0; p = p->next) {
8105 if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
8106 {
8107 fprintf(fmatlab,"\t{mxArray *fout = c_to_mx_%s(a.%s);\n",c_ident(p->info.typ), ident(p->sym->name));
8108 fprintf(fmatlab,"\tmxSetField(struct_array_ptr, index,\"%s\" , fout);}\n", ident(p->sym->name));
8109 }
8110 }
8111 }
8112 fprintf(fmatlab,"\treturn struct_array_ptr;\n}\n");
8113 return;
8114 }
8115
8116 void
8117 matlab_c_to_mx_primitive(Tnode *typ)
8118 {
8119 fprintf(fmheader,"\nmxArray* c_to_mx_%s(%s);",c_ident(typ),c_type_id(typ, ""));
8120 fprintf(fmatlab,"\nmxArray* c_to_mx_%s(%s)\n",c_ident(typ),c_type_id(typ, "a"));
8121
8122 fprintf(fmatlab,"{\n\tmxArray *fout;\n");
8123 if((typ->type == Tchar) || (typ->type == Tuchar))
8124 {
8125 fprintf(fmatlab,"\tchar buf[2];\n");
8126 fprintf(fmatlab,"\tbuf[0] = a;\n");
8127 fprintf(fmatlab,"\tbuf[1] = \'\\0\';\n");
8128 fprintf(fmatlab,"\tfout = mxCreateString(buf);\n");
8129 fprintf(fmatlab,"\tif (!fout)\n");
8130 fprintf(fmatlab,"\t\tmexErrMsgTxt(\"Could not create mxArray.\");\n");
8131 }
8132 else
8133 {
8134 fprintf(fmatlab,"\tint ndim = 1, dims[1] = {1};\n");
8135 fprintf(fmatlab,"\tfout = mxCreateNumericArray(ndim, dims, %s, mxREAL);\n",get_mxClassID(typ));
8136 fprintf(fmatlab,"\t%s = (%s)mxGetPr(fout);\n",c_type_id(typ,"*temp"),c_type_id(typ,"*"));
8137 fprintf(fmatlab,"\tif (!fout)\n");
8138 fprintf(fmatlab,"\t\tmexErrMsgTxt(\"Could not create mxArray.\");\n");
8139 fprintf(fmatlab,"\tif (!temp) \n");
8140 fprintf(fmatlab,"\t\tmexErrMsgTxt(\"matlab_array_c_to_mx: Pointer to data is NULL\");\n");
8141 fprintf(fmatlab,"\t*temp++= a;\n");
8142 }
8143 fprintf(fmatlab,"\treturn fout;\n}\n");
8144 }
8145
8146 void
8147 matlab_mx_to_c_primitive(Tnode *typ)
8148 {
8149 fprintf(fmheader, "\nvoid mx_to_c_%s(const mxArray *, %s);\n",c_ident(typ),c_type_id(typ, "*"));
8150 fprintf(fmatlab, "\nvoid mx_to_c_%s(const mxArray *a, %s)\n",c_ident(typ),c_type_id(typ, "*b"));
8151 if((typ->type == Tchar) || (typ->type == Tuchar))
8152 {
8153 fprintf(fmatlab,"{\n\tint ret;\n");
8154 fprintf(fmatlab,"\tchar buf[2];\n");
8155 fprintf(fmatlab,"\tret = mxGetString(a, buf, 2);\n");
8156 fprintf(fmatlab,"\tmexPrintf(\"ret = %%d, buf = %%s\", ret, buf);\n");
8157 fprintf(fmatlab,"\t*b = buf[0];\n");
8158 }
8159 else
8160 {
8161 fprintf(fmatlab,"{\n\tdouble* data = (double*)mxGetData(a);\n");
8162 fprintf(fmatlab,"\t*b = (%s)*data;\n",c_type(typ));
8163 }
8164 fprintf(fmatlab,"\n}\n");
8165 }
8166
8167 void
8168 matlab_out_generate(Tnode *typ)
8169 {
8170
8171 if (is_transient(typ) || typ->type == Twchar || is_XML(typ))
8172 return;
8173
8174 /*
8175 typeNO++;
8176 if (typeNO>=1024)
8177 execerror("Too many user-defined data types");
8178 */
8179
8180 if(is_primitive(typ))
8181 {
8182 matlab_c_to_mx_primitive(typ);
8183 matlab_mx_to_c_primitive(typ);
8184 return;
8185 }
8186
8187 switch(typ->type)
8188 {
8189 case Tstruct:
8190 matlab_c_to_mx_struct(typ);
8191 matlab_mx_to_c_struct(typ);
8192 break;
8193 case Tpointer:
8194 matlab_c_to_mx_pointer(typ);
8195 matlab_mx_to_c_pointer(typ);
8196 break;
8197 case Tarray:
8198 break;
8199 default:break;
8200 }
8201 }
8202
8203 /*his function is called first it first generates all routines
8204 and then in the second pass calls all routines to generate
8205 matlab_out for the table*/
8206
8207 void
8208 func1(Table *table, Entry *param)
8209 { Entry *q,*pout,*response=NULL;
8210 q=entry(table, param->sym);
8211 if (q)
8212 pout = (Entry*)q->info.typ->ref;
8213 else
8214 { fprintf(stderr, "Internal error: no table entry\n");
8215 return;
8216 }
8217 q=entry(classtable, param->sym);
8218 if (!is_response(pout->info.typ))
8219 { response = get_response(param->info.typ);
8220 }
8221 fprintf(fmheader,"\n\toutside loop struct %s soap_tmp_%s;",param->sym->name,param->sym->name);
8222 if (!is_response(pout->info.typ) && response)
8223 { fprintf(fmheader,"\n\tif..inside loop struct %s *soap_tmp_%s;",c_ident(response->info.typ), c_ident(response->info.typ));
8224 }
8225 fflush(fmheader);
8226 }
8227
8228 void
8229 matlab_def_table(Table *table)
8230 {
8231 Entry *q,*pout,*e,*response=NULL;
8232 int i;
8233 Tnode *p;
8234
8235 /* for (q1 = table->list; q1 != (Entry*) 0; q1 = q1->next)
8236 if (q1->info.typ->type==Tfun)
8237 func1(table, q1);
8238 */
8239
8240 /* Sparse matrix code will be present by default */
8241 matlab_gen_sparseStruct();
8242 matlab_c_to_mx_sparse();
8243 matlab_mx_to_c_sparse();
8244
8245 for(i=0;i<TYPES;i++)
8246 for(p=Tptr[i];p!=(Tnode*) 0;p=p->next)
8247 {
8248 /* This is generated for everything declared in the ".h" file. To make
8249 sure that it doesnt get generated for functions do a comparison with
8250 p->sym->name, so that its not generated for functions.
8251 */
8252 if(is_XML(p))
8253 continue;
8254 if(strstr(c_ident(p),"SOAP_ENV_") != NULL)
8255 continue;
8256 for(q = table->list; q != (Entry*) 0; q = q->next)
8257 {
8258 if(strcmp(c_ident(p),q->sym->name) == 0)
8259 break;
8260 e=entry(table, q->sym);
8261 if (e)
8262 pout = (Entry*)e->info.typ->ref;
8263 else
8264 { fprintf(stderr, "Internal error: no table entry\n");
8265 return;
8266 }
8267 if (!is_response(pout->info.typ))
8268 { response = get_response(q->info.typ);
8269 }
8270 if (!is_response(pout->info.typ) && response)
8271 {
8272 if(strcmp(c_ident(p),c_ident(response->info.typ)) == 0)
8273 break;
8274 }
8275 }
8276 if(q == (Entry*) 0)
8277 matlab_out_generate(p);
8278 }
8279 }
8280
8281 void
8282 def_table(Table *table)
8283 { int i;
8284 Tnode *p;
8285 for (i = 0; i < TYPES; i++)
8286 { for (p = Tptr[i]; p; p = p->next)
8287 { if (!p->generated && !is_transient(p) && p->type != Twchar && !is_void(p))
8288 { p->generated = True;
8289 generate(p);
8290 if (fflag)
8291 if (--partnum == 0)
8292 return;
8293 }
8294 }
8295 }
8296 }
8297
8298
8299 int
8300 no_of_var(Tnode *typ)
8301 {
8302 Entry *p;
8303 Table *t;
8304 int i=0;
8305 if(typ->type==Tstruct || typ->type==Tclass)
8306 {
8307 t=(Table*)typ->ref;
8308 for (p = t->list; p != (Entry*) 0; p = p->next) {
8309 if(p->info.typ->type==Tpointer)
8310 i++;
8311 }
8312 }
8313 if((((Tnode *)(typ->ref))->type==Tstruct) ||
8314 (((Tnode *)(typ->ref))->type==Tclass) )
8315 {
8316 t=(Table*)((Tnode*)(typ->ref))->ref;
8317 for (p = t->list; p != (Entry*) 0; p = p->next) {
8318 if(p->info.typ->type==Tpointer)
8319 i++;
8320 }
8321 }
8322 return i;
8323 }
8324
8325 void
8326 in_defs(Table *table)
8327 { int i;
8328 Tnode *p;
8329 for (i = 0; i < TYPES; i++)
8330 { for (p = Tptr[i]; p; p = p->next)
8331 { if (!is_element(p) && !is_transient(p) && p->type != Twchar && p->type != Tfun && p->type != Treference && p->type != Tunion && !is_XML(p) && !is_header_or_fault(p) && !is_body(p) && !is_template(p))
8332 { char *s = xsi_type(p);
8333 if (!*s)
8334 s = wsdl_type(p, "");
8335 if (*s == '-')
8336 continue;
8337 if (is_string(p))
8338 fprintf(fout,"\n\tcase %s:\n\t{\tchar **s;\n\t\ts = soap_in_%s(soap, NULL, NULL, \"%s\");\n\t\treturn s ? *s : NULL;\n\t}", soap_type(p), c_ident(p), s);
8339 else if (is_wstring(p))
8340 fprintf(fout,"\n\tcase %s:\n\t{\twchar_t **s;\n\t\ts = soap_in_%s(soap, NULL, NULL, \"%s\");\n\t\treturn s ? *s : NULL;\n\t}", soap_type(p), c_ident(p), s);
8341 else
8342 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_in_%s(soap, NULL, NULL, \"%s\");", soap_type(p), c_ident(p), s);
8343 }
8344 }
8345 }
8346 }
8347
8348 void
8349 in_defs2(Table *table)
8350 { int i, j;
8351 Tnode *p;
8352 char *s;
8353 for (i = 0; i < TYPES; i++)
8354 { /* make sure (wrapper) classes are checked first */
8355 if (i == 0)
8356 j = Tclass;
8357 else if (i == Tclass)
8358 continue;
8359 else
8360 j = i;
8361 for (p = Tptr[j]; p; p = p->next)
8362 { if (!is_element(p) && !is_transient(p) && !is_template(p) && p->type != Twchar && p->type != Tfun && p->type != Treference && p->type != Tunion && !is_XML(p) && !is_header_or_fault(p) && !is_body(p))
8363 { s = xsi_type(p);
8364 if (!*s)
8365 s = wsdl_type(p, "");
8366 if (*s == '-')
8367 continue;
8368 if (*s)
8369 { if (is_dynamic_array(p) && !is_binary(p) && !has_ns(p) && !is_untyped(p))
8370 fprintf(fout,"\n\t\tif (*soap->arrayType && !soap_match_array(soap, \"%s\"))\n\t\t{\t*type = %s;\n\t\t\treturn soap_in_%s(soap, NULL, NULL, NULL);\n\t\t}", s, soap_type(p), c_ident(p));
8371 else if (is_string(p))
8372 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\tchar **s;\n\t\t\t*type = %s;\n\t\t\ts = soap_in_%s(soap, NULL, NULL, NULL);\n\t\t\treturn s ? *s : NULL;\n\t\t}", s, soap_type(p), c_ident(p));
8373 else if (is_wstring(p))
8374 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\twchar_t **s;\n\t\t\t*type = %s;\n\t\t\ts = soap_in_%s(soap, NULL, NULL, NULL);\n\t\t\treturn s ? *s : NULL;\n\t\t}", s, soap_type(p), c_ident(p));
8375 else if (p->type != Tpointer)
8376 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\t*type = %s;\n\t\t\treturn soap_in_%s(soap, NULL, NULL, NULL);\n\t\t}", s, soap_type(p), c_ident(p));
8377 }
8378 }
8379 }
8380 }
8381 }
8382
8383 void
8384 in_defs3(Table *table)
8385 { int i;
8386 Tnode *p;
8387 char *s;
8388 for (i = 0; i < TYPES; i++)
8389 { for (p = Tptr[i]; p; p = p->next)
8390 { if (is_element(p) && !is_transient(p) && !is_template(p) && p->type != Twchar && p->type != Tfun && p->type != Treference && p->type != Tunion && !is_XML(p) && !is_header_or_fault(p) && !is_body(p))
8391 { s = xsi_type(p);
8392 if (!*s)
8393 s = wsdl_type(p, "");
8394 if (*s == '-')
8395 continue;
8396 if (*s)
8397 { if (is_dynamic_array(p) && !is_binary(p) && !has_ns(p) && !is_untyped(p))
8398 fprintf(fout,"\n\t\tif (*soap->arrayType && !soap_match_array(soap, \"%s\"))\n\t\t{\t*type = %s;\n\t\t\treturn soap_in_%s(soap, NULL, NULL, NULL);\n\t\t}", s, soap_type(p), c_ident(p));
8399 else if (is_string(p))
8400 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\tchar **s;\n\t\t\t*type = %s;\n\t\t\ts = soap_in_%s(soap, NULL, NULL, NULL);\n\t\t\treturn s ? *s : NULL;\n\t\t}", s, soap_type(p), c_ident(p));
8401 else if (is_wstring(p))
8402 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\twchar_t **s;\n\t\t\t*type = %s;\n\t\t\ts = soap_in_%s(soap, NULL, NULL, NULL);\n\t\t\treturn s ? *s : NULL;\n\t\t}", s, soap_type(p), c_ident(p));
8403 else if (p->type != Tpointer)
8404 fprintf(fout,"\n\t\tif (!soap_match_tag(soap, t, \"%s\"))\n\t\t{\t*type = %s;\n\t\t\treturn soap_in_%s(soap, NULL, NULL, NULL);\n\t\t}", s, soap_type(p), c_ident(p));
8405 }
8406 }
8407 }
8408 }
8409 }
8410
8411 void
8412 out_defs(Table *table)
8413 { int i;
8414 char *s;
8415 Tnode *p;
8416 for (i = 0; i < TYPES; i++)
8417 { for (p = Tptr[i]; p; p = p->next)
8418 { if (is_transient(p) || is_template(p) || is_XML(p) || is_header_or_fault(p) || is_body(p))
8419 continue;
8420 if (is_element(p))
8421 { s = wsdl_type(p, "");
8422 if (*s == '-')
8423 continue;
8424 if (p->type == Tarray)
8425 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, \"%s\", id, (%s)ptr, NULL);", soap_type(p),c_ident(p),s,c_type_id((Tnode*)p->ref, "(*)"));
8426 else if(p->type == Tclass && !is_external(p) && !is_volatile(p) && !is_typedef(p))
8427 fprintf(fout,"\n\tcase %s:\n\t\treturn ((%s)ptr)->soap_out(soap, \"%s\", id, NULL);", soap_type(p), c_type_id(p, "*"),s);
8428 else if (is_string(p))
8429 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_string(soap, \"%s\", id, (char*const*)&ptr, NULL);", soap_type(p),s);
8430 else if (is_wstring(p))
8431 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_wstring(soap, \"%s\", id, (wchar_t*const*)&ptr, NULL);", soap_type(p),s);
8432 else if (p->type == Tpointer)
8433 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, \"%s\", id, (%s)ptr, NULL);", soap_type(p),c_ident(p),s,c_type_id(p, "const*"));
8434 else if(p->type != Tnone && p->type != Ttemplate && p->type != Twchar && !is_void(p) && p->type != Tfun && p->type != Treference && p->type != Tunion)
8435 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, \"%s\", id, (const %s)ptr, NULL);", soap_type(p),c_ident(p),s,c_type_id(p, "*"));
8436 }
8437 else
8438 { s = xsi_type(p);
8439 if (!*s)
8440 s = wsdl_type(p, "");
8441 if (*s == '-')
8442 continue;
8443 if (p->type == Tarray)
8444 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, tag, id, (%s)ptr, \"%s\");", soap_type(p), c_ident(p),c_type_id((Tnode*)p->ref, "(*)"), s);
8445 else if(p->type == Tclass && !is_external(p) && !is_volatile(p) && !is_typedef(p))
8446 fprintf(fout,"\n\tcase %s:\n\t\treturn ((%s)ptr)->soap_out(soap, tag, id, \"%s\");", soap_type(p), c_type_id(p, "*"), s);
8447 else if (is_string(p))
8448 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_string(soap, tag, id, (char*const*)&ptr, \"%s\");", soap_type(p), s);
8449 else if (is_wstring(p))
8450 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_wstring(soap, tag, id, (wchar_t*const*)&ptr, \"%s\");", soap_type(p), s);
8451 else if (p->type == Tpointer)
8452 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, tag, id, (%s)ptr, \"%s\");", soap_type(p), c_ident(p),c_type_id(p, "const*"), s);
8453 else if(p->type != Tnone && p->type != Ttemplate && p->type != Twchar && !is_void(p) && p->type != Tfun && p->type != Treference && p->type != Tunion)
8454 fprintf(fout,"\n\tcase %s:\n\t\treturn soap_out_%s(soap, tag, id, (const %s)ptr, \"%s\");", soap_type(p), c_ident(p),c_type_id(p, "*"), s);
8455 }
8456 }
8457 }
8458 }
8459
8460 void
8461 mark_defs(Table *table)
8462 { int i;
8463 Tnode *p;
8464 for (i = 0; i < TYPES; i++)
8465 { for (p = Tptr[i]; p; p = p->next)
8466 { if (is_transient(p) || is_template(p) || is_XML(p) || is_header_or_fault(p) || is_body(p) || is_void(p))
8467 continue;
8468 if (p->type == Tarray)
8469 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_%s(soap, (%s)ptr);\n\t\tbreak;", soap_type(p), c_ident(p),c_type_id((Tnode*)p->ref, "(*)"));
8470 else if(p->type == Tclass && !is_external(p) && !is_volatile(p) && !is_typedef(p))
8471 fprintf(fout,"\n\tcase %s:\n\t\t((%s)ptr)->soap_serialize(soap);\n\t\tbreak;", soap_type(p), c_type_id(p, "*"));
8472 else if (is_string(p))
8473 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_string(soap, (char*const*)&ptr);\n\t\tbreak;", soap_type(p));
8474 else if (is_wstring(p))
8475 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_wstring(soap, (wchar_t*const*)&ptr);\n\t\tbreak;", soap_type(p));
8476 else if (p->type == Tpointer)
8477 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_%s(soap, (%s)ptr);\n\t\tbreak;", soap_type(p), c_ident(p),c_type_id(p, "const*"));
8478 else if(p->type == Ttemplate && p->ref)
8479 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_%s(soap, (const %s)ptr);\n\t\tbreak;", soap_type(p), c_ident(p),c_type_id(p, "*"));
8480 else if(!is_primitive(p) && p->type != Tnone && p->type != Ttemplate && !is_void(p) && p->type != Tfun && p->type != Treference && p->type != Tunion)
8481 fprintf(fout,"\n\tcase %s:\n\t\tsoap_serialize_%s(soap, (const %s)ptr);\n\t\tbreak;", soap_type(p), c_ident(p),c_type_id(p, "*"));
8482 }
8483 }
8484 }
8485
8486 void
8487 in_attach(Table *table)
8488 { int i;
8489 Tnode *p;
8490 for (i = 0; i < TYPES; i++)
8491 { for (p = Tptr[i]; p; p = p->next)
8492 { if (is_attachment(p))
8493 { if (p->type == Tclass)
8494 fprintf(fout,"\n\t\tcase %s:\n\t\t{\t%s a;\n\t\t\ta = (%s)soap_class_id_enter(soap, soap->dime.id, NULL, %s, sizeof(%s), NULL, NULL);\n\t\t\tif (a)\n\t\t\t{\ta->__ptr = (unsigned char*)soap->dime.ptr;\n\t\t\t\ta->__size = soap->dime.size;\n\t\t\t\ta->id = (char*)soap->dime.id;\n\t\t\t\ta->type = (char*)soap->dime.type;\n\t\t\t\ta->options = (char*)soap->dime.options;\n\t\t\t}\n\t\t\telse\n\t\t\t\treturn soap->error;\n\t\t\tbreak;\n\t\t}", soap_type(p), c_type_id(p, "*"), c_type_id(p, "*"), soap_type(p), c_type(p));
8495 else
8496 fprintf(fout,"\n\t\tcase %s:\n\t\t{\t%s a;\n\t\t\ta = (%s)soap_id_enter(soap, soap->dime.id, NULL, %s, sizeof(%s), 0, NULL, NULL, NULL);\n\t\t\tif (!a)\n\t\t\t\treturn soap->error;\n\t\t\ta->__ptr = (unsigned char*)soap->dime.ptr;\n\t\t\ta->__size = soap->dime.size;\n\t\t\ta->id = (char*)soap->dime.id;\n\t\t\ta->type = (char*)soap->dime.type;\n\t\t\ta->options = (char*)soap->dime.options;\n\t\t\tbreak;\n\t\t}", soap_type(p), c_type_id(p, "*"), c_type_id(p, "*"), soap_type(p), c_type(p));
8497 }
8498 else if (is_binary(p) && !is_transient(p))
8499 { if (p->type == Tclass)
8500 fprintf(fout,"\n\t\tcase %s:\n\t\t{\t%s a;\n\t\t\ta = (%s)soap_class_id_enter(soap, soap->dime.id, NULL, %s, sizeof(%s), NULL, NULL);\n\t\t\tif (!a)\n\t\t\t\treturn soap->error;\n\t\t\ta->__ptr = (unsigned char*)soap->dime.ptr;\n\t\t\ta->__size = soap->dime.size;\n\t\t\tbreak;\n\t\t}", soap_type(p), c_type_id(p, "*"), c_type_id(p, "*"), soap_type(p), c_type(p));
8501 else
8502 fprintf(fout,"\n\t\tcase %s:\n\t\t{\t%s a;\n\t\t\ta = (%s)soap_id_enter(soap, soap->dime.id, NULL, %s, sizeof(%s), 0, NULL, NULL, NULL);\n\t\t\tif (!a)\n\t\t\t\treturn soap->error;\n\t\t\ta->__ptr = (unsigned char*)soap->dime.ptr;\n\t\t\ta->__size = soap->dime.size;\n\t\t\tbreak;\n\t\t}", soap_type(p), c_type_id(p, "*"), c_type_id(p, "*"), soap_type(p), c_type(p));
8503 }
8504 }
8505 }
8506 }
8507
8508 void
8509 soap_instantiate_class(Tnode *typ)
8510 { Table *Tptr;
8511 Entry *Eptr;
8512 int derclass = 0, flag = 0;
8513 char *s;
8514
8515 if (cflag)
8516 return;
8517
8518 if (typ->type != Tclass || !typ->sym || !is_eq(typ->sym->name, "xsd__QName") || is_imported(typ))
8519 if (is_typedef(typ) && !is_external(typ))
8520 { fprintf(fhead, "\n\n#define soap_instantiate_%s soap_instantiate_%s\n", c_ident(typ), t_ident(typ));
8521 fprintf(fhead, "\n\n#define soap_copy_%s soap_copy_%s", c_ident(typ), t_ident(typ));
8522 return;
8523 }
8524
8525 fprintf(fhead,"\nSOAP_FMAC1 %s * SOAP_FMAC2 soap_instantiate_%s(struct soap*, int, const char*, const char*, size_t*);", c_type(typ), c_ident(typ));
8526
8527 fprintf(fhead, "\n\ninline %s * soap_new_%s(struct soap *soap, int n = -1) { return soap_instantiate_%s(soap, n, NULL, NULL, NULL); }", c_type(typ), c_ident(typ), c_ident(typ));
8528
8529 if (typ->type == Tclass || typ->type == Tstruct)
8530 { fprintf(fhead, "\n\ninline %s * soap_new_req_%s(struct soap *soap", c_type(typ), c_ident(typ));
8531 if (!is_dynamic_array(typ))
8532 { for (Tptr = (Table*)typ->ref, derclass = 0; Tptr; Tptr = Tptr->prev, derclass++)
8533 { for (Eptr = Tptr->list; Eptr; Eptr = Eptr->next)
8534 { if (Eptr->info.sto & (Stypedef | Sstatic))
8535 continue;
8536 if (is_repetition(Eptr) || is_anytype(Eptr))
8537 flag = 2;
8538 if ((Eptr->info.minOccurs > 0 || flag) && !(Eptr->info.sto & (Sprivate | Sprotected)) && Eptr->info.typ->type != Tfun && strcmp(Eptr->sym->name, "soap"))
8539 { if (flag)
8540 flag--;
8541 if (Eptr->info.typ->type == Tclass || Eptr->info.typ->type == Tstruct || Eptr->info.typ->type == Tunion || Eptr->info.typ->type == Ttemplate)
8542 fprintf(fhead, ", %s& %s", c_type(Eptr->info.typ), ident(Eptr->sym->name));
8543 else
8544 fprintf(fhead, ", %s", c_type_id(Eptr->info.typ, Eptr->sym->name));
8545 if (derclass)
8546 fprintf(fhead, "%d", derclass);
8547 }
8548 }
8549 }
8550 }
8551 fprintf(fhead, ") { %s = soap_instantiate_%s(soap, -1, NULL, NULL, NULL); if (_p) { ", c_type_id(typ, "*_p"), c_ident(typ));
8552 if (!is_external(typ))
8553 { if (typ->type == Tclass && !is_volatile(typ))
8554 fprintf(fhead, "_p->soap_default(soap); ");
8555 else
8556 fprintf(fhead, "soap_default_%s(soap, _p); ", c_ident(typ));
8557 }
8558 flag = 0;
8559 if (!is_dynamic_array(typ))
8560 { for (Tptr = (Table*)typ->ref, derclass = 0; Tptr; Tptr = Tptr->prev, derclass++)
8561 { for (Eptr = Tptr->list; Eptr; Eptr = Eptr->next)
8562 { if (Eptr->info.sto & (Stypedef | Sstatic))
8563 continue;
8564 if (is_repetition(Eptr) || is_anytype(Eptr))
8565 flag = 2;
8566 if ((Eptr->info.minOccurs > 0 || flag) && !(Eptr->info.sto & (Sprivate | Sprotected)) && Eptr->info.typ->type != Tfun && strcmp(Eptr->sym->name, "soap"))
8567 { if (flag)
8568 flag--;
8569 if (typ->type == Tclass)
8570 fprintf(fhead, "_p->%s::%s = %s", ident(Tptr->sym->name), ident(Eptr->sym->name), ident(Eptr->sym->name));
8571 else
8572 fprintf(fhead, "_p->%s = %s", ident(Eptr->sym->name), ident(Eptr->sym->name));
8573 if (derclass)
8574 fprintf(fhead, "%d; ", derclass);
8575 else
8576 fprintf(fhead, "; ");
8577 }
8578 }
8579 }
8580 }
8581 fprintf(fhead, "} return _p; }");
8582 fprintf(fhead, "\n\ninline %s * soap_new_set_%s(struct soap *soap", c_type(typ), c_ident(typ));
8583 for (Tptr = (Table*)typ->ref, derclass = 0; Tptr; Tptr = Tptr->prev, derclass++)
8584 { for (Eptr = Tptr->list; Eptr; Eptr = Eptr->next)
8585 { if (Eptr->info.sto & (Stypedef | Sstatic))
8586 continue;
8587 if (!(Eptr->info.sto & (Sprivate | Sprotected)) && Eptr->info.typ->type != Tfun && strcmp(Eptr->sym->name, "soap"))
8588 { if (Eptr->info.typ->type == Tclass || Eptr->info.typ->type == Tstruct || Eptr->info.typ->type == Tunion || Eptr->info.typ->type == Ttemplate)
8589 fprintf(fhead, ", %s& %s", c_type(Eptr->info.typ), ident(Eptr->sym->name));
8590 else
8591 fprintf(fhead, ", %s", c_type_id(Eptr->info.typ, Eptr->sym->name));
8592 if (derclass)
8593 fprintf(fhead, "%d", derclass);
8594 }
8595 }
8596 }
8597 fprintf(fhead, ") { %s = soap_instantiate_%s(soap, -1, NULL, NULL, NULL); if (_p) { ", c_type_id(typ, "*_p"), c_ident(typ));
8598 if (!is_external(typ))
8599 { if (typ->type == Tclass && !is_volatile(typ))
8600 fprintf(fhead, "_p->soap_default(soap); ");
8601 else
8602 fprintf(fhead, "soap_default_%s(soap, _p); ", c_ident(typ));
8603 }
8604 for (Tptr = (Table*)typ->ref, derclass = 0; Tptr; Tptr = Tptr->prev, derclass++)
8605 { for (Eptr = Tptr->list; Eptr; Eptr = Eptr->next)
8606 { if (Eptr->info.sto & (Stypedef | Sstatic))
8607 continue;
8608 if (!(Eptr->info.sto & (Sprivate | Sprotected)) && Eptr->info.typ->type != Tfun && strcmp(Eptr->sym->name, "soap"))
8609 { if (typ->type == Tclass)
8610 fprintf(fhead, "_p->%s::%s = %s", ident(Tptr->sym->name), ident(Eptr->sym->name), ident(Eptr->sym->name));
8611 else if (Eptr->info.typ->type == Tarray)
8612 fprintf(fhead, "memcpy(_p->%s, %s, sizeof(%s))", ident(Eptr->sym->name), ident(Eptr->sym->name), c_type(Eptr->info.typ));
8613 else
8614 fprintf(fhead, "_p->%s = %s", ident(Eptr->sym->name), ident(Eptr->sym->name));
8615 if (derclass)
8616 fprintf(fhead, "%d; ", derclass);
8617 else
8618 fprintf(fhead, "; ");
8619 }
8620 }
8621 }
8622 fprintf(fhead, "} return _p; }");
8623 }
8624
8625 fprintf(fhead, "\n\ninline void soap_delete_%s(struct soap *soap, %s) { soap_delete(soap, p); }", c_ident(typ), c_type_id(typ, "*p"));
8626
8627 /* extern "C" causes C++ namespace linking issues */
8628 /* fprintf(fhead,"\n#ifdef __cplusplus\nextern \"C\" {\n#endif"); */
8629 fprintf(fhead,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_copy_%s(struct soap*, int, int, void*, size_t, const void*, size_t);", c_ident(typ));
8630 /* fprintf(fhead,"\n#ifdef __cplusplus\n}\n#endif"); */
8631
8632 fprintf(fout,"\n\nSOAP_FMAC1 %s * SOAP_FMAC2 soap_instantiate_%s(struct soap *soap, int n, const char *type, const char *arrayType, size_t *size)", c_type(typ), c_ident(typ));
8633 fprintf(fout,"\n{");
8634 fprintf(fout,"\n\t(void)type; (void)arrayType; /* appease -Wall -Werror */");
8635 fprintf(fout, "\n\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"soap_instantiate_%s(%%d, %%s, %%s)\\n\", n, type?type:\"\", arrayType?arrayType:\"\"));", c_ident(typ));
8636
8637 fprintf(fout,"\n\tstruct soap_clist *cp = soap_link(soap, NULL, %s, n, %s_fdelete);", soap_type(typ), prefix);
8638 fprintf(fout,"\n\tif (!cp)\n\t\treturn NULL;");
8639 for (Eptr = classtable->list; Eptr; Eptr = Eptr->next)
8640 {
8641 Tptr = ((Table *) Eptr->info.typ->ref);
8642 if(Tptr == ((Table *) typ->ref)){
8643 continue;
8644 }
8645
8646 derclass = 0;
8647 while(Tptr)
8648 {
8649 if(Tptr == (Table*)typ->ref){
8650 derclass = 1;
8651 }
8652
8653 Tptr = Tptr->prev;
8654 }
8655
8656 if(derclass == 1 && !is_transient(Eptr->info.typ)){
8657 if (is_dynamic_array(Eptr->info.typ) && !is_binary(Eptr->info.typ) && !has_ns(Eptr->info.typ) && !is_untyped(Eptr->info.typ))
8658 fprintf(fout,"\n\tif (arrayType && !soap_match_tag(soap, arrayType, \"%s\"))", xsi_type(Eptr->info.typ));
8659 else
8660 fprintf(fout,"\n\tif (type && !soap_match_tag(soap, type, \"%s\"))", the_type(Eptr->info.typ));
8661 fprintf(fout,"\n\t{\tcp->type = %s;", soap_type(Eptr->info.typ));
8662 fprintf(fout,"\n\t\tif (n < 0)");
8663 fprintf(fout,"\n\t\t{\tcp->ptr = (void*)SOAP_NEW(%s);", c_type(Eptr->info.typ));
8664 fprintf(fout,"\n\t\t\tif (size)\n\t\t\t\t*size = sizeof(%s);", c_type(Eptr->info.typ));
8665 if ((s = has_soapref(Eptr->info.typ)))
8666 fprintf(fout,"\n\t\t\t((%s*)cp->ptr)->%s = soap;", c_type(Eptr->info.typ), s);
8667 fprintf(fout,"\n\t\t}\n\t\telse");
8668 fprintf(fout,"\n\t\t{\tcp->ptr = (void*)SOAP_NEW_ARRAY(%s, n);", c_type(Eptr->info.typ));
8669 fprintf(fout,"\n\t\t\tif (size)\n\t\t\t\t*size = n * sizeof(%s);", c_type(Eptr->info.typ));
8670 if (s)
8671 fprintf(fout,"\n\t\t\tif (cp->ptr)\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\t((%s*)cp->ptr)[i].%s = soap;", c_type(Eptr->info.typ), s);
8672 fprintf(fout,"\n\t\t}");
8673 fprintf(fout,"\n\t\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Instantiated location=%%p\\n\", cp->ptr));");
8674 fprintf(fout,"\n\t\tif (!cp->ptr)\n\t\t\tsoap->error = SOAP_EOM;");
8675 fprintf(fout,"\n\t\treturn (%s*)cp->ptr;", c_type(Eptr->info.typ));
8676 fprintf(fout,"\n\t}");
8677
8678 derclass = 0;
8679 }
8680 }
8681
8682 fprintf(fout,"\n\tif (n < 0)");
8683 fprintf(fout,"\n\t{\tcp->ptr = (void*)SOAP_NEW(%s);", c_type(typ));
8684 fprintf(fout,"\n\t\tif (size)\n\t\t\t*size = sizeof(%s);", c_type(typ));
8685 if ((s = has_soapref(typ)))
8686 fprintf(fout,"\n\t\t((%s*)cp->ptr)->%s = soap;", c_type(typ), s);
8687 fprintf(fout,"\n\t}\n\telse");
8688 fprintf(fout,"\n\t{\tcp->ptr = (void*)SOAP_NEW_ARRAY(%s, n);", c_type(typ));
8689 fprintf(fout,"\n\t\tif (size)\n\t\t\t*size = n * sizeof(%s);", c_type(typ));
8690 if (s)
8691 fprintf(fout,"\n\t\tif (cp->ptr)\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t((%s*)cp->ptr)[i].%s = soap;", c_type(typ), s);
8692 fprintf(fout,"\n\t}");
8693 fprintf(fout,"\n\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Instantiated location=%%p\\n\", cp->ptr));");
8694 fprintf(fout,"\n\tif (!cp->ptr)\n\t\tsoap->error = SOAP_EOM;");
8695 fprintf(fout,"\n\treturn (%s*)cp->ptr;", c_type(typ));
8696
8697 fprintf(fout,"\n}");
8698
8699 /* fprintf(fout,"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif"); */
8700 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_copy_%s(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)", c_ident(typ));
8701 fprintf(fout,"\n{\n\t(void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */");
8702 fprintf(fout,"\n\tDBGLOG(TEST, SOAP_MESSAGE(fdebug, \"Copying %s %%p -> %%p\\n\", q, p));", c_type(typ));
8703 fprintf(fout,"\n\t*(%s*)p = *(%s*)q;\n}", c_type(typ), c_type(typ));
8704 /* fprintf(fout,"\n#ifdef __cplusplus\n}\n#endif"); */
8705 }
8706
8707 int
8708 get_dimension(Tnode *typ)
8709 { if (((Tnode*)typ->ref)->width)
8710 return typ->width / ((Tnode*) typ->ref)->width;
8711 return 0;
8712 }
8713
8714
8715 void
8716 soap_serialize(Tnode *typ)
8717 { int d;
8718 Table *table,*t;
8719 Entry *p;
8720 Tnode* temp;
8721 int cardinality;
8722 const char *self;
8723
8724 if (is_primitive(typ))
8725 return;
8726
8727 if (is_typedef(typ) && is_element(typ) && !is_external(typ))
8728 { if (typ->type == Tclass && !is_stdstring(typ) && !is_stdwstring(typ) && !is_volatile(typ))
8729 fprintf(fhead, "\n\n#define soap_serialize_%s(soap, a) (a)->soap_serialize(soap)\n",c_ident(typ));
8730 else
8731 fprintf(fhead, "\n\n#define soap_serialize_%s soap_serialize_%s\n", c_ident(typ), t_ident(typ));
8732 return;
8733 }
8734
8735 if (is_typedef(typ) && !is_external(typ))
8736 { if (is_imported(typ))
8737 { fprintf(fhead, "\n\n#define soap_serialize_%s(soap, a) soap_serialize_%s(soap, a)\n", c_ident(typ), t_ident(typ));
8738 return;
8739 }
8740 if (typ->type == Tclass && !is_stdstring(typ) && !is_stdwstring(typ) && !is_volatile(typ))
8741 { fprintf(fhead, "\n\n#define soap_serialize_%s(soap, a) (a)->soap_serialize(soap)\n",c_ident(typ));
8742 return;
8743 }
8744 /* enabling this will not allow multi-ref detection of these typedef types
8745 else if (typ->type == Tclass && is_eq(typ->sym->name, "xsd__QName"))
8746 { fprintf(fhead, "\n\n#define soap_serialize_%s(soap, a) soap_serialize_std__string(soap, a)\n", c_ident(typ));
8747 return;
8748 }
8749 else if (typ->type != Tclass)
8750 { fprintf(fhead, "\n\n#define soap_serialize_%s(soap, a) soap_serialize_%s(soap, a)\n", c_ident(typ), t_ident(typ));
8751 return;
8752 }
8753 */
8754 }
8755
8756 if ((p = is_dynamic_array(typ)))
8757 { if (typ->type == Tclass && !is_typedef(typ) && !is_volatile(typ))
8758 { if (is_external(typ))
8759 return;
8760 fprintf(fout,"\n\nvoid %s::soap_serialize(struct soap *soap) const\n{\n#ifndef WITH_NOIDREF",c_ident(typ));
8761 if (is_binary(typ))
8762 { if (is_attachment(typ))
8763 { fprintf(fout,"\n\tif (this->__ptr && !soap_array_reference(soap, this, (struct soap_array*)&this->__ptr, 1, %s))", soap_type(typ));
8764 fprintf(fout,"\n\t\tif (this->id || this->type)\n\t\t\tsoap->mode |= SOAP_ENC_DIME;");
8765 }
8766 else
8767 fprintf(fout,"\n\tif (this->__ptr)\n\t\tsoap_array_reference(soap, this, (struct soap_array*)&this->%s, 1, %s);", ident(p->sym->name), soap_type(typ));
8768 fprintf(fout,"\n#endif\n}");
8769 fflush(fout);
8770 return;
8771 }
8772 else
8773 {
8774 d = get_Darraydims(typ);
8775 if (d)
8776 { fprintf(fout,"\n\tif (this->%s && !soap_array_reference(soap, this, (struct soap_array*)&this->%s, %d, %s))", ident(p->sym->name), ident(p->sym->name), d, soap_type(typ));
8777 fprintf(fout,"\n\t\tfor (int i = 0; i < soap_size(this->__size, %d); i++)", d);
8778 }
8779 else
8780 { fprintf(fout,"\n\tif (this->%s && !soap_array_reference(soap, this, (struct soap_array*)&this->%s, 1, %s))", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
8781 fprintf(fout,"\n\t\tfor (int i = 0; i < this->__size; i++)");
8782 }
8783 fprintf(fout,"\n\t\t{");
8784 if (has_ptr((Tnode*)p->info.typ->ref))
8785 fprintf(fout,"\tsoap_embedded(soap, this->%s + i, %s);", ident(p->sym->name), soap_type((Tnode*)p->info.typ->ref));
8786 if (((Tnode*)p->info.typ->ref)->type == Tclass && !is_XML((Tnode*)p->info.typ->ref) && !is_external(p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
8787 fprintf(fout,"\n\t\t\tthis->%s[i].soap_serialize(soap);", ident(p->sym->name));
8788 else if (!is_XML((Tnode*)p->info.typ->ref) &&!is_primitive((Tnode*)p->info.typ->ref))
8789 fprintf(fout,"\n\t\t\tsoap_serialize_%s(soap, this->%s + i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
8790 fprintf(fout,"\n\t\t}\n#endif\n}");
8791 return;
8792 }
8793 }
8794 else
8795 { if (is_external(typ))
8796 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "const*"));
8797 return;
8798 }
8799 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "const*"));
8800 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, %s)\n{\n#ifndef WITH_NOIDREF",c_ident(typ),c_type_id(typ, "const*a"));
8801 if (is_binary(typ))
8802 { if (is_attachment(typ))
8803 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, 1, %s))", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
8804 fprintf(fout,"\n\t\tif (a->id || a->type)\n\t\t\tsoap->mode |= SOAP_ENC_DIME;");
8805 }
8806 else
8807 fprintf(fout,"\n\tif (a->%s)\n\t\tsoap_array_reference(soap, a, (struct soap_array*)&a->%s, 1, %s);", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
8808 fprintf(fout,"\n#endif\n}");
8809 fflush(fout);
8810 return;
8811 }
8812 else
8813 {
8814 fprintf(fout,"\n\tint i;");
8815 d = get_Darraydims(typ);
8816 if (d)
8817 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, %d, %s))", ident(p->sym->name), ident(p->sym->name), d, soap_type(typ));
8818 fprintf(fout,"\n\t\tfor (i = 0; i < soap_size(a->__size, %d); i++)", d);
8819 }
8820 else
8821 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, 1, %s))", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
8822 fprintf(fout,"\n\t\tfor (i = 0; i < a->__size; i++)");
8823 }
8824 fprintf(fout,"\n\t\t{");
8825 if (has_ptr((Tnode*)p->info.typ->ref))
8826 fprintf(fout,"\tsoap_embedded(soap, a->%s + i, %s);", ident(p->sym->name), soap_type((Tnode*)p->info.typ->ref));
8827 if (((Tnode*)p->info.typ->ref)->type == Tclass && !is_XML((Tnode*)p->info.typ->ref) && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
8828 fprintf(fout,"\n\t\t\ta->%s[i].soap_serialize(soap);", ident(p->sym->name));
8829 else if (!is_XML((Tnode*)p->info.typ->ref) && !is_primitive((Tnode*)p->info.typ->ref))
8830 fprintf(fout,"\n\t\t\tsoap_serialize_%s(soap, a->%s + i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
8831 fprintf(fout,"\n\t\t}\n#endif\n}");
8832 fflush(fout);
8833 return;
8834 }
8835 }
8836 }
8837 if (is_stdstring(typ) || is_stdwstring(typ))
8838 { fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
8839 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, const %s)\n{\t(void)soap; (void)a; /* appease -Wall -Werror */\n}",c_ident(typ),c_type_id(typ, "*a"));
8840 return;
8841 }
8842 switch(typ->type)
8843 {
8844 case Tclass:
8845 if (!is_volatile(typ))
8846 {
8847 if (is_external(typ))
8848 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
8849 return;
8850 }
8851 table=(Table*)typ->ref;
8852 if (!table)
8853 return;
8854 if (!is_typedef(typ))
8855 { self = "this";
8856 fprintf(fout,"\n\nvoid %s::soap_serialize(struct soap *soap) const\n{\n#ifndef WITH_NOIDREF", ident(typ->id->name));
8857 }
8858 else
8859 { self = "p";
8860 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
8861 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, const %s)\n{\n#ifndef WITH_NOIDREF", c_ident(typ), c_type_id(typ, "*p"));
8862 }
8863 fprintf(fout, "\n\t(void)soap; /* appease -Wall -Werror */");
8864 for (p = table->list; p; p = p->next)
8865 {
8866 if (p->info.sto & (Sconst | Sprivate | Sprotected))
8867 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
8868 else if (is_transient(p->info.typ))
8869 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
8870 else if (p->info.sto & Sattribute)
8871 ;
8872 else if (is_repetition(p))
8873 {
8874 if (!is_XML(p->next->info.typ))
8875 {
8876 fprintf(fout,"\n\tif (%s->%s::%s)", self, ident(table->sym->name), ident(p->next->sym->name));
8877 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < %s->%s::%s; i++)\n\t\t{", self, ident(table->sym->name), ident(p->sym->name));
8878 if (!is_invisible(p->next->sym->name))
8879 if (has_ptr((Tnode*)p->next->info.typ->ref))
8880 fprintf(fout,"\n\t\t\tsoap_embedded(soap, %s->%s::%s + i, %s);", self, ident(table->sym->name), ident(p->next->sym->name), soap_type((Tnode*)p->next->info.typ->ref));
8881 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
8882 fprintf(fout,"\n\t\t\t%s->%s::%s[i].soap_serialize(soap);", self, ident(table->sym->name), ident(p->next->sym->name));
8883 else if (!is_primitive((Tnode*)p->next->info.typ->ref))
8884 fprintf(fout,"\n\t\t\tsoap_serialize_%s(soap, %s->%s::%s + i);", c_ident((Tnode*)p->next->info.typ->ref), self, ident(table->sym->name), ident(p->next->sym->name));
8885 fprintf(fout,"\n\t\t}\n\t}");
8886 }
8887 p = p->next;
8888 }
8889 else if (is_anytype(p))
8890 { fprintf(fout,"\n\tsoap_markelement(soap, %s->%s, %s->%s);", self, ident(p->next->sym->name), self, ident(p->sym->name));
8891 p = p->next;
8892 }
8893 else if (is_choice(p))
8894 { fprintf(fout,"\n\tsoap_serialize_%s(soap, %s->%s::%s, &%s->%s::%s);", c_ident(p->next->info.typ), self, ident(table->sym->name), ident(p->sym->name), self, ident(table->sym->name), ident(p->next->sym->name));
8895 p = p->next;
8896 }
8897 else if(p->info.typ->type==Tarray)
8898 {
8899 if (has_ptr(p->info.typ))
8900 fprintf(fout,"\n\tsoap_embedded(soap, %s->%s::%s, %s);", self, ident(table->sym->name), ident(p->sym->name), soap_type(p->info.typ));
8901 fprintf(fout,"\n\tsoap_serialize_%s(soap, %s->%s::%s);", c_ident(p->info.typ), self, ident(table->sym->name), ident(p->sym->name));
8902 }
8903 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
8904 {
8905 if (has_ptr(p->info.typ))
8906 fprintf(fout,"\n\tsoap_embedded(soap, &%s->%s::%s, %s);", self, ident(table->sym->name), ident(p->sym->name), soap_type(p->info.typ));
8907 fprintf(fout,"\n\t%s->%s::%s.soap_serialize(soap);", self, ident(table->sym->name), ident(p->sym->name));
8908 }
8909 else if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
8910 {
8911 if (!is_template(p->info.typ))
8912 if (has_ptr(p->info.typ))
8913 fprintf(fout,"\n\tsoap_embedded(soap, &%s->%s::%s, %s);", self, ident(table->sym->name), ident(p->sym->name), soap_type(p->info.typ));
8914 if (!is_primitive(p->info.typ))
8915 fprintf(fout,"\n\tsoap_serialize_%s(soap, &%s->%s::%s);", c_ident(p->info.typ), self, ident(table->sym->name), ident(p->sym->name));
8916 }
8917 }
8918 t = table->prev;
8919 if (t)
8920 fprintf(fout,"\n\t%s->%s::soap_serialize(soap);", self, ident(t->sym->name));
8921 fprintf(fout,"\n#endif\n}");
8922 break;
8923 }
8924 case Tstruct:
8925
8926 if (is_external(typ) && !is_volatile(typ))
8927 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
8928 return;
8929 }
8930 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
8931 if (!typ->ref)
8932 return;
8933 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, const %s)\n{\n#ifndef WITH_NOIDREF",c_ident(typ),c_type_id(typ, "*a"));
8934 /* DYNAMIC ARRAY */
8935
8936 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
8937 table=(Table*)typ->ref;
8938 for (t = table; t; t = t->prev)
8939 { for (p = t->list; p; p = p->next)
8940 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
8941 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
8942 else if (is_transient(p->info.typ))
8943 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
8944 else if (p->info.sto & Sattribute)
8945 ;
8946 else if (is_repetition(p))
8947 {
8948 if (!is_XML(p->next->info.typ)) {
8949 fprintf(fout,"\n\tif (a->%s)", ident(p->next->sym->name));
8950 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < a->%s; i++)\n\t\t{", ident(p->sym->name));
8951 if (!is_invisible(p->next->sym->name))
8952 if (has_ptr((Tnode*)p->next->info.typ->ref))
8953 fprintf(fout,"\n\t\t\tsoap_embedded(soap, a->%s + i, %s);", ident(p->next->sym->name), soap_type((Tnode*)p->next->info.typ->ref));
8954 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
8955 fprintf(fout,"\n\t\t\ta->%s[i].soap_serialize(soap);", ident(p->next->sym->name));
8956 else if (!is_primitive((Tnode*)p->next->info.typ->ref))
8957 fprintf(fout,"\n\t\t\tsoap_serialize_%s(soap, a->%s + i);", c_ident((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name));
8958 fprintf(fout,"\n\t\t}\n\t}");
8959 }
8960 p = p->next;
8961 }
8962 else if (is_anytype(p))
8963 { fprintf(fout,"\n\tsoap_markelement(soap, a->%s, a->%s);", ident(p->next->sym->name), ident(p->sym->name));
8964 p = p->next;
8965 }
8966 else if (is_choice(p))
8967 { fprintf(fout,"\n\tsoap_serialize_%s(soap, a->%s, &a->%s);", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name));
8968 p = p->next;
8969 }
8970 else if(p->info.typ->type==Tarray)
8971 {
8972 if (has_ptr(p->info.typ))
8973 fprintf(fout,"\n\tsoap_embedded(soap, a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
8974 fprintf(fout,"\n\tsoap_serialize_%s(soap, a->%s);", c_ident(p->info.typ), ident(p->sym->name));
8975 }
8976 else if(p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
8977 {
8978 if (has_ptr(p->info.typ))
8979 fprintf(fout,"\n\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
8980 fprintf(fout,"\n\ta->%s.soap_serialize(soap);", ident(p->sym->name));
8981 }
8982 else if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
8983 {
8984 if (!is_template(p->info.typ))
8985 if (has_ptr(p->info.typ))
8986 fprintf(fout,"\n\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
8987 if (!is_primitive(p->info.typ))
8988 fprintf(fout,"\n\tsoap_serialize_%s(soap, &a->%s);", c_ident(p->info.typ), ident(p->sym->name));
8989 }
8990 }
8991 }
8992 fprintf(fout,"\n#endif\n}");
8993 break;
8994
8995 case Tunion:
8996 if (is_external(typ) && !is_volatile(typ))
8997 { fprintf(fhead, "\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, int, const %s);", c_ident(typ), c_type_id(typ, "*"));
8998 return;
8999 }
9000 table=(Table*)typ->ref;
9001 fprintf(fhead, "\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, int, const %s);", c_ident(typ), c_type_id(typ, "*"));
9002 fprintf(fout, "\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, int choice, const %s)\n{\n#ifndef WITH_NOIDREF", c_ident(typ), c_type_id(typ, "*a"));
9003 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9004 fprintf(fout, "\n\tswitch (choice)\n\t{");
9005 for (t = table; t; t = t->prev)
9006 { for (p = t->list; p; p = p->next)
9007 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
9008 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
9009 else if (is_transient(p->info.typ))
9010 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9011 else if (p->info.sto & Sattribute)
9012 ;
9013 else if (is_repetition(p))
9014 ;
9015 else if (is_anytype(p))
9016 ;
9017 else if (p->info.typ->type==Tarray)
9018 {
9019 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9020 if (has_ptr(p->info.typ))
9021 fprintf(fout,"\n\t\tsoap_embedded(soap, a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9022 fprintf(fout,"\n\t\tsoap_serialize_%s(soap, a->%s);", c_ident(p->info.typ), ident(p->sym->name));
9023 fprintf(fout, "\n\t\tbreak;");
9024 }
9025 else if(p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
9026 {
9027 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9028 if (has_ptr(p->info.typ))
9029 fprintf(fout,"\n\t\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9030 fprintf(fout,"\n\t\ta->%s.soap_serialize(soap);", ident(p->sym->name));
9031 fprintf(fout, "\n\t\tbreak;");
9032 }
9033 else if (p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_XML(p->info.typ))
9034 {
9035 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9036 if (has_ptr(p->info.typ))
9037 fprintf(fout,"\n\t\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9038 if (!is_primitive(p->info.typ))
9039 fprintf(fout,"\n\t\tsoap_serialize_%s(soap, &a->%s);", c_ident(p->info.typ), ident(p->sym->name));
9040 fprintf(fout, "\n\t\tbreak;");
9041 }
9042 }
9043 }
9044 fprintf(fout,"\n\tdefault:\n\t\tbreak;\n\t}\n#endif\n}");
9045 break;
9046 case Tpointer:
9047 if (((Tnode*)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
9048 { if (is_external(typ))
9049 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const*"));
9050 return;
9051 }
9052 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const*"));
9053 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, %s)\n{\n#ifndef WITH_NOIDREF", c_ident(typ),c_type_id(typ, "const*a"));
9054 p = is_dynamic_array((Tnode*)typ->ref);
9055 if (p)
9056 { d = get_Darraydims((Tnode*)typ->ref);
9057 if (d)
9058 fprintf(fout,"\n\tif (*a)");
9059 else
9060 fprintf(fout,"\n\tif (*a)");
9061 }
9062 else
9063 fprintf(fout,"\n\tif (!soap_reference(soap, *a, %s))", soap_type((Tnode*)typ->ref));
9064 fprintf(fout,"\n\t\t(*a)->soap_serialize(soap);\n#endif\n}");
9065 break;
9066 }
9067 else
9068 {
9069 if (is_external(typ))
9070 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const*"));
9071 return;
9072 }
9073 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const*"));
9074 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, %s)\n{\n#ifndef WITH_NOIDREF", c_ident(typ),c_type_id(typ, "const*a"));
9075 if (is_string(typ) || is_wstring(typ))
9076 fprintf(fout,"\n\tsoap_reference(soap, *a, %s);", soap_type(typ));
9077 else if (is_primitive((Tnode*)typ->ref))
9078 fprintf(fout,"\n\tsoap_reference(soap, *a, %s);", soap_type((Tnode*)typ->ref));
9079 else if ((p = is_dynamic_array((Tnode*)typ->ref)) != NULL)
9080 { d = get_Darraydims((Tnode*)typ->ref);
9081 if (d)
9082 fprintf(fout,"\n\tif (*a)");
9083 else
9084 fprintf(fout,"\n\tif (*a)");
9085 fprintf(fout,"\n\t\tsoap_serialize_%s(soap, *a);", c_ident((Tnode*)typ->ref));
9086 }
9087 else
9088 { fprintf(fout,"\n\tif (!soap_reference(soap, *a, %s))", soap_type((Tnode*)typ->ref));
9089 fprintf(fout,"\n\t\tsoap_serialize_%s(soap, *a);", c_ident((Tnode*)typ->ref));
9090 }
9091 fprintf(fout,"\n#endif\n}");
9092 break;
9093 }
9094 case Tarray:
9095 if (is_external(typ))
9096 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const"));
9097 return;
9098 }
9099 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, %s);", c_ident(typ),c_type_id(typ, "const"));
9100 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, %s)\n{\n#ifndef WITH_NOIDREF", c_ident(typ),c_type_id(typ, "const a"));
9101 if (is_primitive((Tnode*)typ->ref))
9102 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9103 else
9104 { fprintf(fout,"\n\tint i;");
9105 fprintf(fout,"\n\tfor(i = 0; i < %d; i++)", get_dimension(typ));
9106
9107 temp=(Tnode*)typ->ref;;
9108 cardinality = 1;
9109 while(temp->type==Tarray)
9110 {
9111 temp=(Tnode*)temp->ref;
9112 cardinality++;
9113 }
9114 fprintf(fout,"\n\t{");
9115 if (has_ptr((Tnode*)typ->ref))
9116 {
9117 fprintf(fout,"\tsoap_embedded(soap, a");
9118 if(cardinality > 1)
9119 fprintf(fout,"[i]");
9120 else
9121 fprintf(fout,"+i");
9122 fprintf(fout,", %s);", soap_type((Tnode*)typ->ref));
9123 }
9124 if (((Tnode *)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
9125 { fprintf(fout,"\n\ta[i].soap_serialize(soap)");
9126 }
9127 else if (!is_primitive((Tnode*)typ->ref))
9128 { fprintf(fout,"\n\tsoap_serialize_%s(soap, a",c_ident((Tnode*)typ->ref));
9129 if(cardinality > 1){
9130 fprintf(fout,"[i])");
9131 }else {
9132 fprintf(fout,"+i)");
9133 }
9134 }
9135 fprintf(fout,";\n\t}");
9136 }
9137 fprintf(fout,"\n#endif\n}");
9138 break;
9139 case Ttemplate:
9140 if (is_external(typ))
9141 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
9142 return;
9143 }
9144 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap*, const %s);",c_ident(typ),c_type_id(typ, "*"));
9145 temp = (Tnode*)typ->ref;
9146 if (!temp)
9147 return;
9148 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_serialize_%s(struct soap *soap, const %s)\n{\n#ifndef WITH_NOIDREF",c_ident(typ),c_type_id(typ, "*a"));
9149 if (!is_primitive(temp) && !is_XML(temp) && temp->type != Tfun && !is_void(temp))
9150 { fprintf(fout, "\n\tfor (%s::const_iterator i = a->begin(); i != a->end(); ++i)", c_type(typ));
9151 if (temp->type==Tclass && !is_external(temp) && !is_volatile(temp) && !is_typedef(temp))
9152 fprintf(fout,"\n\t\t(*i).soap_serialize(soap);");
9153 else
9154 fprintf(fout,"\n\t\tsoap_serialize_%s(soap, &(*i));", c_ident(temp));
9155 }
9156 fprintf(fout, "\n#endif\n}");
9157 default: break;
9158 }
9159 }
9160
9161 void
9162 soap_default(Tnode* typ)
9163 { int i, d;
9164 Table *table,*t;
9165 Entry *p;
9166 Tnode *temp;
9167 char *s;
9168 int cardinality;
9169
9170 if (typ->type == Tpointer && !is_string(typ))
9171 return;
9172
9173 if (typ->type != Tclass || !(typ->sym && (is_stdstring(typ) || is_stdwstring(typ)) && is_eq(typ->sym->name, "xsd__QName")) || is_external(typ) || is_imported(typ))
9174 { if (is_typedef(typ) && !is_external(typ))
9175 { if (typ->type == Tclass && !is_stdstring(typ) && !is_stdwstring(typ) && !is_volatile(typ))
9176 fprintf(fhead, "\n\n#define soap_default_%s(soap, a) (a)->%s::soap_default(soap)\n", c_ident(typ), t_ident(typ));
9177 else if (typ->type == Tclass && is_eq(typ->sym->name, "xsd__QName"))
9178 fprintf(fhead, "\n\n#define soap_default_%s(soap, a) soap_default_std__string(soap, a)\n", c_ident(typ));
9179 else
9180 fprintf(fhead, "\n\n#define soap_default_%s(soap, a) soap_default_%s(soap, a)\n", c_ident(typ), t_ident(typ));
9181 return;
9182 }
9183 }
9184 p = is_dynamic_array(typ);
9185 if (p)
9186 { if (typ->type == Tclass && !is_volatile(typ))
9187 { if (is_external(typ))
9188 return;
9189 fprintf(fout,"\n\nvoid %s::soap_default(struct soap *soap)\n{", c_ident(typ));
9190 if ((s = has_soapref(typ)))
9191 fprintf(fout,"\n\tthis->%s = soap;", s);
9192 else
9193 fprintf(fout,"\n\t(void)soap; /* appease -Wall -Werror */");
9194 d = get_Darraydims(typ);
9195 if (d)
9196 { fprintf(fout,"\n\tthis->%s = NULL;", ident(p->sym->name));
9197 for (i = 0; i < d; i++)
9198 { fprintf(fout,"\n\tthis->__size[%d] = 0;", i);
9199 if (has_offset(typ) && (((Table*)typ->ref)->list->next->next->info.sto & Sconst) == 0)
9200 fprintf(fout, "\n\tthis->__offset[%d] = 0;", i);
9201 }
9202 }
9203 else
9204 { fprintf(fout,"\n\tthis->__size = 0;\n\tthis->%s = NULL;", ident(p->sym->name));
9205 if (has_offset(typ) && (((Table*)typ->ref)->list->next->next->info.sto & Sconst) == 0)
9206 fprintf(fout, "\n\tthis->__offset = 0;");
9207 }
9208 if (is_attachment(typ))
9209 fprintf(fout,"\n\tthis->id = NULL;\n\tthis->type = NULL;\n\tthis->options = NULL;");
9210 fprintf(fout,"\n}");
9211 }
9212 else
9213 { if (is_external(typ))
9214 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9215 return;
9216 }
9217 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9218 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{\t(void)soap;", c_ident(typ),c_type_id(typ, "*a"));
9219 if ((s = has_soapref(typ)))
9220 fprintf(fout,"\n\ta->%s = soap;", s);
9221 else
9222 fprintf(fout,"\n\t(void)soap; /* appease -Wall -Werror */");
9223 d = get_Darraydims(typ);
9224 if (d)
9225 { fprintf(fout,"\n\ta->%s = NULL;", ident(p->sym->name));
9226 for (i = 0; i < d; i++)
9227 { fprintf(fout,"\n\ta->__size[%d] = 0;", i);
9228 if (has_offset(typ) && (((Table*)typ->ref)->list->next->next->info.sto & Sconst) == 0)
9229 fprintf(fout, "\n\ta->__offset[%d] = 0;", i);
9230 }
9231 }
9232 else
9233 { fprintf(fout,"\n\ta->__size = 0;\n\ta->%s = NULL;", ident(p->sym->name));
9234 if (has_offset(typ) && (((Table*)typ->ref)->list->next->next->info.sto & Sconst) == 0)
9235 fprintf(fout, "\n\ta->__offset = 0;");
9236 }
9237 if (is_attachment(typ))
9238 fprintf(fout,"\n\ta->id = NULL;\n\ta->type = NULL;\n\ta->options = NULL;");
9239 fprintf(fout,"\n}");
9240 }
9241 fflush(fout);
9242 return;
9243 }
9244 if (is_primitive(typ) || is_string(typ))
9245 { if (is_external(typ))
9246 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9247 return;
9248 }
9249 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9250 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{\n\t(void)soap; /* appease -Wall -Werror */\n#ifdef SOAP_DEFAULT_%s\n\t*a = SOAP_DEFAULT_%s;\n#else\n\t*a = (%s)0;\n#endif\n}",c_ident(typ),c_type_id(typ, "*a"), c_ident(typ), c_ident(typ), c_type(typ));
9251 return;
9252 }
9253 if (is_fixedstring(typ))
9254 { fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, char[]);",c_ident(typ));
9255 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, char a[])\n{\n\t(void)soap; /* appease -Wall -Werror */\n\ta[0] = '\\0';\n}",c_ident(typ));
9256 return;
9257 }
9258 if (is_stdstring(typ) || is_stdwstring(typ))
9259 { fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9260 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{\n\t(void)soap; /* appease -Wall -Werror */\n\tp->erase();\n}",c_ident(typ),c_type_id(typ, "*p"));
9261 return;
9262 }
9263 switch(typ->type)
9264 {
9265 case Tclass:
9266 /* CLASS */
9267 if (!is_volatile(typ))
9268 {
9269 if (is_external(typ))
9270 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9271 return;
9272 }
9273 table=(Table*)typ->ref;
9274 fprintf(fout,"\n\nvoid %s::soap_default(struct soap *soap)\n{", ident(typ->id->name));
9275 if ((s = has_soapref(typ)))
9276 fprintf(fout,"\n\tthis->%s = soap;", s);
9277 else
9278 fprintf(fout, "\n\t(void)soap; /* appease -Wall -Werror */");
9279
9280 fflush(fout);
9281 if (table)
9282 {
9283 t = table->prev;
9284 if (t)
9285 fprintf(fout,"\n\tthis->%s::soap_default(soap);", ident(t->sym->name));
9286 for (p = table->list; p; p = p->next)
9287 { if (p->info.typ->type == Tfun)
9288 continue;
9289 if (p->info.sto & Sconst)
9290 fprintf(fout, "\n\t/* const %s skipped */", ident(p->sym->name));
9291 else if (is_choice(p))
9292 { fprintf(fout, "\n\tthis->%s::%s = 0;", ident(table->sym->name), ident(p->sym->name));
9293 p = p->next;
9294 }
9295 else if (is_repetition(p) || is_anytype(p))
9296 { fprintf(fout, "\n\tthis->%s::%s = 0;\n\tthis->%s::%s = NULL;", ident(table->sym->name), ident(p->sym->name), ident(table->sym->name), ident(p->next->sym->name));
9297 p = p->next;
9298 }
9299 else
9300 {
9301 if (is_fixedstring(p->info.typ))
9302 { if (p->info.hasval)
9303 fprintf(fout,"\n\tstrcpy(this->%s::%s, \"%s\");", ident(table->sym->name), ident(p->sym->name), cstring(p->info.val.s));
9304 else
9305 fprintf(fout,"\n\tthis->%s::%s[0] = '\\0';", ident(table->sym->name), ident(p->sym->name));
9306 }
9307 else if (p->info.typ->type == Tarray){
9308 fprintf(fout,"\n\tsoap_default_%s(soap, this->%s::%s);", c_ident(p->info.typ), ident(table->sym->name), ident(p->sym->name));
9309 }
9310 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ) && !is_transient(p->info.typ))
9311 fprintf(fout,"\n\tthis->%s::%s.%s::soap_default(soap);", ident(table->sym->name), ident(p->sym->name), c_ident(p->info.typ));
9312 else if (p->info.hasval)
9313 { if (p->info.typ->type == Tpointer && is_stdstring((Tnode*)p->info.typ->ref))
9314 fprintf(fout,"\n\tstatic std::string soap_tmp_%s(\"%s\");\n\tthis->%s::%s = &soap_tmp_%s;", ident(p->sym->name), p->info.val.s, ident(table->sym->name), ident(p->sym->name), ident(p->sym->name));
9315 else
9316 fprintf(fout,"\n\tthis->%s::%s%s;", ident(table->sym->name), ident(p->sym->name), c_init(p));
9317 }
9318 else if (is_transient(p->info.typ) || is_void(p->info.typ))
9319 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9320 else if (p->info.typ->type == Tpointer && (!is_string(p->info.typ) || is_XML(p->info.typ)))
9321 fprintf(fout,"\n\tthis->%s::%s = NULL;", ident(table->sym->name), ident(p->sym->name));
9322 else if (p->info.sto & (Sprivate | Sprotected))
9323 { if (p->info.typ->type == Tpointer)
9324 fprintf(fout,"\n\tthis->%s::%s = NULL;", ident(table->sym->name), ident(p->sym->name));
9325 else if (p->info.typ->type >= Tchar && p->info.typ->type < Tenum)
9326 fprintf(fout,"\n\tthis->%s::%s = 0;", ident(table->sym->name), ident(p->sym->name));
9327 else if (p->info.typ->type == Tenum)
9328 fprintf(fout,"\n\tthis->%s::%s = (%s)0;", ident(table->sym->name), ident(p->sym->name), c_type(p->info.typ));
9329 else
9330 fprintf(fout, "\n\t/* private/protected %s skipped */", ident(p->sym->name));
9331 }
9332 else
9333 fprintf(fout,"\n\tsoap_default_%s(soap, &this->%s::%s);", c_ident(p->info.typ), ident(table->sym->name), ident(p->sym->name));
9334 }
9335 }
9336 }
9337 fprintf(fout,"\n}");
9338 fflush(fout);
9339 break;
9340 }
9341
9342 case Tstruct:
9343 table=(Table*)typ->ref;
9344
9345 if (is_external(typ) && !is_volatile(typ))
9346 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9347 return;
9348 }
9349 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9350 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{", c_ident(typ),c_type_id(typ, "*a"));
9351 fflush(fout);
9352 if ((s = has_soapref(typ)))
9353 fprintf(fout,"\n\ta->%s = soap;", s);
9354 else
9355 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9356 if (table)
9357 {
9358 for (t = table; t; t = t->prev)
9359 { for (p = t->list; p; p = p->next)
9360 { if (p->info.typ->type == Tfun)
9361 continue;
9362 if (p->info.sto & Sconst)
9363 fprintf(fout, "\n\t/* const %s skipped */", ident(p->sym->name));
9364 else if (p->info.sto & (Sprivate | Sprotected))
9365 fprintf(fout, "\n\t/* private/protected %s skipped */", ident(p->sym->name));
9366 else if (is_choice(p))
9367 { fprintf(fout, "\n\ta->%s = 0;", ident(p->sym->name));
9368 p = p->next;
9369 }
9370 else if (is_repetition(p) || is_anytype(p))
9371 { fprintf(fout, "\n\ta->%s = 0;\n\ta->%s = NULL;", ident(p->sym->name), ident(p->next->sym->name));
9372 p = p->next;
9373 }
9374 else
9375 {
9376 if (is_fixedstring(p->info.typ))
9377 { if (p->info.hasval)
9378 fprintf(fout,"\n\tstrcpy(a->%s, \"%s\");", ident(p->sym->name), cstring(p->info.val.s));
9379 else
9380 fprintf(fout,"\n\ta->%s[0] = '\\0';", ident(p->sym->name));
9381 }
9382 else if (p->info.typ->type==Tarray)
9383 fprintf(fout,"\n\tsoap_default_%s(soap, a->%s);", c_ident(p->info.typ), ident(p->sym->name));
9384 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ) && !is_transient(p->info.typ))
9385 fprintf(fout,"\n\ta->%s.%s::soap_default(soap);", ident(p->sym->name), c_ident(p->info.typ));
9386 else if (p->info.hasval)
9387 { if (p->info.typ->type == Tpointer && is_stdstring((Tnode*)p->info.typ->ref))
9388 fprintf(fout,"\n\tstatic std::string soap_tmp_%s(\"%s\");\n\ta->%s = &soap_tmp_%s;", ident(p->sym->name), p->info.val.s, ident(p->sym->name), ident(p->sym->name));
9389 else
9390 fprintf(fout,"\n\ta->%s%s;", ident(p->sym->name), c_init(p));
9391 }
9392 else if (is_transient(p->info.typ) || is_void(p->info.typ))
9393 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9394 else if (p->info.typ->type == Tpointer && (!is_string(p->info.typ) || is_XML(p->info.typ)))
9395 fprintf(fout,"\n\ta->%s = NULL;", ident(p->sym->name));
9396 else
9397 fprintf(fout,"\n\tsoap_default_%s(soap, &a->%s);", c_ident(p->info.typ), ident(p->sym->name));
9398 }
9399 }
9400 }
9401 }
9402 fprintf(fout,"\n}");
9403 fflush(fout);
9404 break;
9405 case Tarray:
9406 if (is_external(typ))
9407 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type(typ));
9408 return;
9409 }
9410 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type(typ));
9411 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{", c_ident(typ),c_type_id(typ, "a"));
9412 fprintf(fout,"\n\tint i;");
9413 fprintf(fout,"\n\t(void)soap; /* appease -Wall -Werror */");
9414 fprintf(fout,"\n\tfor (i = 0; i < %d; i++)",get_dimension(typ));
9415 temp = (Tnode*)typ->ref;
9416 cardinality = 1;
9417 while(temp->type==Tarray)
9418 {
9419 temp=(Tnode*)temp->ref;
9420 cardinality++;
9421 }
9422 if (((Tnode *)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref))
9423 {
9424 if (cardinality>1)
9425 fprintf(fout,"a[i].%s::soap_default(soap)", t_ident((Tnode*)typ->ref));
9426 else
9427 fprintf(fout,"(a+i)->soap_default(soap)");
9428 }
9429 else if (((Tnode*)typ->ref)->type == Tpointer)
9430 fprintf(fout,"\n\ta[i] = NULL");
9431 else
9432 {
9433 fprintf(fout,"\n\tsoap_default_%s(soap, a",c_ident((Tnode*)typ->ref));
9434 if (cardinality>1)
9435 fprintf(fout,"[i])");
9436 else
9437 fprintf(fout,"+i)");
9438 }
9439 fprintf(fout,";\n}");
9440 break;
9441
9442 case Ttemplate:
9443 if (is_external(typ))
9444 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9445 return;
9446 }
9447 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap*, %s);",c_ident(typ),c_type_id(typ, "*"));
9448 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_default_%s(struct soap *soap, %s)\n{",c_ident(typ),c_type_id(typ, "*p"));
9449 fprintf(fout,"\n\tp->clear();");
9450 fprintf(fout,"\n}");
9451 fflush(fout);
9452 break;
9453 default :break;
9454 }
9455 }
9456
9457 void
9458 soap_traverse(Tnode* typ)
9459 { int d;
9460 Table *table,*t;
9461 Entry *p;
9462 Tnode* temp;
9463 int cardinality;
9464 if (is_primitive_or_string(typ) || is_fixedstring(typ))
9465 { fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9466 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{\t(void)soap; (void)q; /* appease -Wall -Werror */",c_ident(typ),c_type_id(typ, "*a"));
9467 fprintf(fout,"\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9468 fprintf(fout,"\n\tif (q) q(soap, (void*)a, %s, s, \"%s\");\n}", soap_type(typ), c_type(typ));
9469 return;
9470 }
9471 if (typ->type != Tclass || !(typ->sym && (is_stdstring(typ) || is_stdwstring(typ)) && is_eq(typ->sym->name, "xsd__QName")) || is_external(typ) || is_imported(typ))
9472 if (is_typedef(typ) && !is_external(typ))
9473 { if (typ->type == Tclass && !is_stdstring(typ) && !is_stdwstring(typ) && !is_volatile(typ))
9474 fprintf(fhead, "\n\n#define soap_traverse_%s(soap, a, s, p, q) (a)->soap_traverse(soap, s, p, q)\n",c_ident(typ));
9475 else if (typ->type == Tclass && is_eq(typ->sym->name, "xsd__QName"))
9476 fprintf(fhead, "\n\n#define soap_traverse_%s(soap, a, s, p, q) soap_traverse_std__string(soap, a, s, p, q)\n", c_ident(typ));
9477 else
9478 fprintf(fhead, "\n\n#define soap_traverse_%s(soap, a, s, p, q) soap_traverse_%s(soap, a, s, p, q)\n", c_ident(typ), t_ident(typ));
9479 return;
9480 }
9481 if (is_XML(typ))
9482 { fprintf(fhead, "\n\n#define soap_traverse_%s(soap, a, s, p, q) soap_traverse_%s(soap, a, s, p, q)\n", c_ident(typ), t_ident(typ));
9483 return;
9484 }
9485 if ((p = is_dynamic_array(typ)))
9486 { if (typ->type == Tclass && !is_volatile(typ))
9487 { if (is_external(typ))
9488 return;
9489 fprintf(fout,"\n\nvoid %s::soap_traverse(struct soap *soap, const char *s, soap_walker p, soap_walker q)\n{",c_ident(typ));
9490 if (is_binary(typ))
9491 { fprintf(fout,"\n\tif (this->%s && !soap_array_reference(soap, this, (struct soap_array*)&this->%s, 1, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
9492 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9493 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this->%s, 0, \"%s\", NULL);", ident(p->sym->name), p->sym->name);
9494 if (is_attachment(typ))
9495 { fprintf(fout,"\n\t\tif (this->id || this->type)\n\t\t\tsoap->mode |= SOAP_ENC_DIME;\n}");
9496 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this->id, SOAP_TYPE_string, \"id\", NULL);");
9497 fprintf(fout,"\n\t\tif (q) q(soap, (void*)this->id, SOAP_TYPE_string, \"id\", NULL);");
9498 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this->type, SOAP_TYPE_string, \"type\", NULL);");
9499 fprintf(fout,"\n\t\tif (q) q(soap, (void*)this->type, SOAP_TYPE_string, \"type\", NULL);");
9500 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this->options, 0, \"options\", NULL);");
9501 fprintf(fout,"\n\t\tif (q) q(soap, (void*)this->options, 0, \"options\", NULL);");
9502 }
9503 fprintf(fout,"\n\t\tif (q) q(soap, (void*)this->%s, 0, \"%s\", NULL);", ident(p->sym->name), p->sym->name);
9504 fprintf(fout,"\n\t\tif (q) q(soap, (void*)this, %s, s, \"%s\");\n\t}\n}", soap_type(typ), c_type(typ));
9505 fflush(fout);
9506 return;
9507 }
9508 else
9509 {
9510 d = get_Darraydims(typ);
9511 if (d)
9512 { fprintf(fout,"\n\tif (this->%s && !soap_array_reference(soap, this, (struct soap_array*)&this->%s, %d, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), d, soap_type(typ));
9513 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9514 fprintf(fout,"\n\t\tfor (int i = 0; i < soap_size(this->__size, %d); i++)", d);
9515 }
9516 else
9517 { fprintf(fout,"\n\tif (this->%s && !soap_array_reference(soap, this, (struct soap_array*)&this->%s, 1, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
9518 fprintf(fout,"\n\t\tif (p) p(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9519 fprintf(fout,"\n\t\tfor (int i = 0; i < this->__size; i++)");
9520 }
9521 fprintf(fout,"\n\t\t{");
9522 if (has_ptr((Tnode*)p->info.typ->ref))
9523 fprintf(fout,"\tsoap_embedded(soap, this->%s + i, %s);", ident(p->sym->name), soap_type((Tnode*)p->info.typ->ref));
9524 if (((Tnode*)p->info.typ->ref)->type == Tclass && !is_external(p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
9525 fprintf(fout,"\n\t\t\tthis->%s[i].soap_traverse(soap, \"%s\", p, q);", ident(p->sym->name), p->sym->name);
9526 else
9527 fprintf(fout,"\n\t\t\tsoap_traverse_%s(soap, this->%s + i, \"%s\", p, q);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), ident(p->sym->name));
9528 fprintf(fout,"\n\t\t}\n\t\tif (q) q(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9529 fprintf(fout,"\n\t}\n}");
9530 return;
9531 }
9532 }
9533 else
9534 { if (is_external(typ))
9535 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9536 return;
9537 }
9538 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9539 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{",c_ident(typ),c_type_id(typ, "*a"));
9540 if (is_binary(typ))
9541 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, 1, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
9542 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9543 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a->%s, 0, \"%s\", NULL);", ident(p->sym->name), p->sym->name);
9544 if (is_attachment(typ))
9545 { fprintf(fout,"\n\t\tif (a->id || a->type)\n\t\t\tsoap->mode |= SOAP_ENC_DIME;\n}");
9546 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a->id, SOAP_TYPE_string, \"id\", NULL);");
9547 fprintf(fout,"\n\t\tif (q) q(soap, (void*)a->id, SOAP_TYPE_string, \"id\", NULL);");
9548 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a->type, SOAP_TYPE_string, \"type\", NULL);");
9549 fprintf(fout,"\n\t\tif (q) q(soap, (void*)a->type, SOAP_TYPE_string, \"type\", NULL);");
9550 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a->options, 0, \"options\", NULL);");
9551 fprintf(fout,"\n\t\tif (q) q(soap, (void*)a->options, 0, \"options\", NULL);");
9552 }
9553 fprintf(fout,"\n\t\tif (q) q(soap, (void*)a->%s, 0, \"%s\", NULL);", ident(p->sym->name), p->sym->name);
9554 fprintf(fout,"\n\t\tif (q) q(soap, (void*)a, %s, s, \"%s\");\n\t}\n}", soap_type(typ), c_type(typ));
9555 fflush(fout);
9556 return;
9557 }
9558 else
9559 {
9560 fprintf(fout,"\n\tint i;");
9561 d = get_Darraydims(typ);
9562 if (d)
9563 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, %d, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), d, soap_type(typ));
9564 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9565 fprintf(fout,"\n\t\tfor (i = 0; i < soap_size(a->__size, %d); i++)", d);
9566 }
9567 else
9568 { fprintf(fout,"\n\tif (a->%s && !soap_array_reference(soap, a, (struct soap_array*)&a->%s, 1, %s))\n\t{", ident(p->sym->name), ident(p->sym->name), soap_type(typ));
9569 fprintf(fout,"\n\t\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9570 fprintf(fout,"\n\t\tfor (i = 0; i < a->__size; i++)");
9571 }
9572 fprintf(fout,"\n\t\t{");
9573 if (has_ptr((Tnode*)p->info.typ->ref))
9574 fprintf(fout,"\tsoap_embedded(soap, a->%s + i, %s);", ident(p->sym->name), soap_type((Tnode*)p->info.typ->ref));
9575 if (((Tnode*)p->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
9576 fprintf(fout,"\n\t\t\ta->%s[i].soap_traverse(soap, \"%s\", p, q);", ident(p->sym->name), p->sym->name);
9577 else
9578 fprintf(fout,"\n\t\t\tsoap_traverse_%s(soap, a->%s + i, \"%s\", p, q);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), p->sym->name);
9579 fprintf(fout,"\n\t\t}\n\t\tif (q) q(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9580 fprintf(fout,"\n\t}\n}");
9581 fflush(fout);
9582 return;
9583 }
9584 }
9585 }
9586 switch(typ->type)
9587 {
9588 case Tclass:
9589 if (!is_volatile(typ))
9590 {
9591 if (is_external(typ))
9592 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9593 return;
9594 }
9595 table=(Table*)typ->ref;
9596 fprintf(fout,"\n\nvoid %s::soap_traverse(struct soap *soap, const char *s, soap_walker p, soap_walker q)\n{", ident(typ->id->name));
9597 fprintf(fout, "\n\t(void)soap; /* appease -Wall -Werror */");
9598 fprintf(fout,"\n\tif (p) p(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9599 for (t = table; t; t = t->prev)
9600 {
9601 for (p = t->list; p; p = p->next) {
9602 if (p->info.sto & (Sconst | Sprivate | Sprotected))
9603 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
9604 else if (is_transient(p->info.typ))
9605 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9606 else if (p->info.sto & Sattribute)
9607 ;
9608 else if (is_repetition(p))
9609 {
9610 fprintf(fout,"\n\tif (this->%s::%s)", ident(t->sym->name), ident(p->next->sym->name));
9611 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < this->%s::%s; i++)\n\t\t{", ident(t->sym->name), ident(p->sym->name));
9612 if (!is_invisible(p->next->sym->name))
9613 if (has_ptr((Tnode*)p->next->info.typ->ref))
9614 fprintf(fout,"\n\t\t\tsoap_embedded(soap, this->%s::%s + i, %s);", ident(t->sym->name), ident(p->next->sym->name), soap_type((Tnode*)p->next->info.typ->ref));
9615 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
9616 fprintf(fout,"\n\t\t\tthis->%s::%s[i].soap_traverse(soap, \"%s\", p, q);", ident(t->sym->name), ident(p->next->sym->name), p->next->sym->name);
9617 else
9618 fprintf(fout,"\n\t\t\tsoap_traverse_%s(soap, this->%s::%s + i, \"%s\", p, q);", c_ident((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name), p->next->sym->name);
9619 fprintf(fout,"\n\t\t}\n\t}");
9620 p = p->next;
9621 }
9622 else if (is_anytype(p))
9623 { p = p->next;
9624 }
9625 else if (is_choice(p))
9626 { fprintf(fout,"\n\tsoap_traverse_%s(soap, this->%s::%s, &this->%s::%s, \"%s\", p, q);", c_ident(p->next->info.typ), ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name), p->next->sym->name);
9627 p = p->next;
9628 }
9629 else if(p->info.typ->type==Tarray)
9630 {
9631 if (has_ptr(p->info.typ))
9632 fprintf(fout,"\n\tsoap_embedded(soap, this->%s::%s, %s);", ident(t->sym->name), ident(p->sym->name), soap_type(p->info.typ));
9633 fprintf(fout,"\n\tsoap_traverse_%s(soap, this->%s::%s, \"%s\", p, q);", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), p->sym->name);
9634 }
9635 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
9636 {
9637 if (has_ptr(p->info.typ))
9638 fprintf(fout,"\n\tsoap_embedded(soap, &this->%s::%s, %s);", ident(t->sym->name), ident(p->sym->name), soap_type(p->info.typ));
9639 fprintf(fout,"\n\tthis->%s::%s.soap_traverse(soap, \"%s\", p, q);", ident(t->sym->name), ident(p->sym->name), p->sym->name);
9640 }
9641 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
9642 {
9643 if (!is_template(p->info.typ))
9644 if (has_ptr(p->info.typ))
9645 fprintf(fout,"\n\tsoap_embedded(soap, &this->%s::%s, %s);", ident(t->sym->name), ident(p->sym->name), soap_type(p->info.typ));
9646 fprintf(fout,"\n\tsoap_traverse_%s(soap, &this->%s::%s, \"%s\", p, q);", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), p->sym->name);
9647 }
9648 }
9649 }
9650 fprintf(fout,"\n\tif (q) q(soap, (void*)this, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9651 fprintf(fout,"\n}");
9652 break;
9653 }
9654 case Tstruct:
9655 if (is_external(typ) && !is_volatile(typ))
9656 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9657 return;
9658 }
9659 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9660 if (!typ->ref)
9661 return;
9662 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{",c_ident(typ),c_type_id(typ, "*a"));
9663 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9664 fprintf(fout,"\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9665 table=(Table*)typ->ref;
9666 for (t = table; t; t = t->prev)
9667 { for (p = t->list; p; p = p->next)
9668 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
9669 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
9670 else if (is_transient(p->info.typ))
9671 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9672 else if (p->info.sto & Sattribute)
9673 ;
9674 else if (is_repetition(p))
9675 {
9676 fprintf(fout,"\n\tif (a->%s)", ident(p->next->sym->name));
9677 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < a->%s; i++)\n\t\t{", ident(p->sym->name));
9678 if (!is_invisible(p->next->sym->name))
9679 if (has_ptr((Tnode*)p->next->info.typ->ref))
9680 fprintf(fout,"\n\t\t\tsoap_embedded(soap, a->%s + i, %s);", ident(p->next->sym->name), soap_type((Tnode*)p->next->info.typ->ref));
9681 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
9682 fprintf(fout,"\n\t\t\ta->%s[i].soap_traverse(soap, \"%s\", p, q);", ident(p->next->sym->name), p->next->sym->name);
9683 else
9684 fprintf(fout,"\n\t\t\tsoap_traverse_%s(soap, a->%s + i, \"%s\", p, q);", c_ident((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name), p->next->sym->name);
9685 fprintf(fout,"\n\t\t}\n\t}");
9686 p = p->next;
9687 }
9688 else if (is_anytype(p))
9689 { p = p->next;
9690 }
9691 else if (is_choice(p))
9692 { fprintf(fout,"\n\tsoap_traverse_%s(soap, a->%s, &a->%s, \"%s\", p, q);", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name), p->next->sym->name);
9693 p = p->next;
9694 }
9695 else if(p->info.typ->type==Tarray)
9696 {
9697 if (has_ptr(p->info.typ))
9698 fprintf(fout,"\n\tsoap_embedded(soap, a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9699 fprintf(fout,"\n\tsoap_traverse_%s(soap, a->%s, \"%s\", p, q);", c_ident(p->info.typ), ident(p->sym->name), p->sym->name);
9700 }
9701 else if(p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
9702 {
9703 if (has_ptr(p->info.typ))
9704 fprintf(fout,"\n\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9705 fprintf(fout,"\n\ta->%s.soap_traverse(soap, \"%s\", p, q);", ident(p->sym->name), p->sym->name);
9706 }
9707 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
9708 {
9709 if (!is_template(p->info.typ))
9710 if (has_ptr(p->info.typ))
9711 fprintf(fout,"\n\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9712 fprintf(fout,"\n\tsoap_traverse_%s(soap, &a->%s, \"%s\", p, q);", c_ident(p->info.typ), ident(p->sym->name), p->sym->name);
9713 }
9714 }
9715 }
9716 fprintf(fout,"\n\tif (q) q(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9717 fprintf(fout,"\n}");
9718 break;
9719 case Tunion:
9720 if (is_external(typ) && !is_volatile(typ))
9721 { fprintf(fhead, "\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, int, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ), c_type_id(typ, "*"));
9722 return;
9723 }
9724 table=(Table*)typ->ref;
9725 fprintf(fhead, "\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, int, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ), c_type_id(typ, "*"));
9726 fprintf(fout, "\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, int choice, %s, const char *s, soap_walker p, soap_walker q)\n{", c_ident(typ), c_type_id(typ, "*a"));
9727 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9728 fprintf(fout, "\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9729 fprintf(fout, "\n\tswitch (choice)\n\t{");
9730 for (t = table; t; t = t->prev)
9731 { for (p = t->list; p; p = p->next)
9732 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
9733 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
9734 else if (is_transient(p->info.typ))
9735 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
9736 else if (p->info.sto & Sattribute)
9737 ;
9738 else if (is_repetition(p))
9739 ;
9740 else if (is_anytype(p))
9741 ;
9742 else if (p->info.typ->type==Tarray)
9743 {
9744 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9745 if (has_ptr(p->info.typ))
9746 fprintf(fout,"\n\t\tsoap_embedded(soap, a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9747 fprintf(fout,"\n\t\tsoap_traverse_%s(soap, a->%s, \"%s\", p, q);", c_ident(p->info.typ), ident(p->sym->name), p->sym->name);
9748 fprintf(fout, "\n\t\tbreak;");
9749 }
9750 else if(p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
9751 {
9752 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9753 if (has_ptr(p->info.typ))
9754 fprintf(fout,"\n\t\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9755 fprintf(fout,"\n\t\ta->%s.soap_traverse(soap, \"%s\", p, q);", ident(p->sym->name), p->sym->name);
9756 fprintf(fout, "\n\t\tbreak;");
9757 }
9758 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
9759 {
9760 fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
9761 if (has_ptr(p->info.typ))
9762 fprintf(fout,"\n\t\tsoap_embedded(soap, &a->%s, %s);", ident(p->sym->name), soap_type(p->info.typ));
9763 fprintf(fout,"\n\t\tsoap_traverse_%s(soap, &a->%s, \"%s\", p, q);", c_ident(p->info.typ), ident(p->sym->name), p->sym->name);
9764 fprintf(fout, "\n\t\tbreak;");
9765 }
9766 }
9767 }
9768 fprintf(fout,"\n\tdefault:\n\t\tbreak;\n\t}");
9769 fprintf(fout,"\n\tif (q) q(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9770 fprintf(fout,"\n}");
9771 break;
9772 case Tpointer:
9773 if (((Tnode*)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
9774 { if (is_external(typ))
9775 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type_id(typ, "*"));
9776 return;
9777 }
9778 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type_id(typ, "*"));
9779 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{", c_ident(typ),c_type_id(typ, "*a"));
9780 p = is_dynamic_array((Tnode*)typ->ref);
9781 if (p)
9782 { d = get_Darraydims((Tnode*)typ->ref);
9783 if (d)
9784 fprintf(fout,"\n\tif (*a)");
9785 else
9786 fprintf(fout,"\n\tif (*a)");
9787 }
9788 else
9789 fprintf(fout,"\n\tif (!soap_reference(soap, *a, %s))", soap_type((Tnode*)typ->ref));
9790 fprintf(fout,"\n\t\t(*a)->soap_traverse(soap, s, p, q);\n}");
9791 break;
9792 }
9793 else
9794 {
9795 if (is_external(typ))
9796 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type_id(typ, "*"));
9797 return;
9798 }
9799 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type_id(typ, "*"));
9800 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{", c_ident(typ),c_type_id(typ, "*a"));
9801 if (is_primitive((Tnode*)typ->ref))
9802 { fprintf(fout,"\n\tif (!soap_reference(soap, *a, %s))\n\t{", soap_type(typ));
9803 fprintf(fout,"\n\t\tif (p) p(soap, (void*)*a, %s, s, \"%s\");", soap_type(typ->ref), c_type(typ->ref));
9804 fprintf(fout,"\n\t\tif (q) q(soap, (void*)*a, %s, s, \"%s\");\n\t}\n}", soap_type(typ->ref), c_type(typ->ref));
9805 }
9806 else if ((p = is_dynamic_array((Tnode*)typ->ref)) != NULL)
9807 { d = get_Darraydims((Tnode*)typ->ref);
9808 if (d)
9809 fprintf(fout,"\n\tif (*a)");
9810 else
9811 fprintf(fout,"\n\tif (*a)");
9812 fprintf(fout,"\n\t\tsoap_traverse_%s(soap, *a, s, p, q);\n}", c_ident((Tnode*)typ->ref));
9813 }
9814 else
9815 { fprintf(fout,"\n\tif (!soap_reference(soap, *a, %s))", soap_type((Tnode*)typ->ref));
9816 fprintf(fout,"\n\t\tsoap_traverse_%s(soap, *a, s, p, q);\n}", c_ident((Tnode*)typ->ref));
9817 }
9818 break;
9819 }
9820 case Tarray:
9821 if (is_external(typ))
9822 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type(typ));
9823 return;
9824 }
9825 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);", c_ident(typ),c_type(typ));
9826 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)", c_ident(typ),c_type_id(typ, "a"));
9827 if (is_primitive((Tnode*)typ->ref))
9828 { fprintf(fout, "\n{");
9829 fprintf(fout, "\n\t(void)soap; (void)a; /* appease -Wall -Werror */");
9830 fprintf(fout,"\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9831 }
9832 else
9833 { fprintf(fout,"\n{\tint i;");
9834 fprintf(fout,"\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9835 fprintf(fout,"\n\tfor(i = 0; i < %d; i++)", get_dimension(typ));
9836
9837 temp=(Tnode*)typ->ref;;
9838 cardinality = 1;
9839 while(temp->type==Tarray)
9840 {
9841 temp=(Tnode*)temp->ref;
9842 cardinality++;
9843 }
9844 fprintf(fout,"\n\t{");
9845 if (has_ptr((Tnode*)typ->ref))
9846 {
9847 fprintf(fout,"\tsoap_embedded(soap, a");
9848 if(cardinality > 1)
9849 fprintf(fout,"[i]");
9850 else
9851 fprintf(fout,"+i");
9852 fprintf(fout,", %s);", soap_type((Tnode*)typ->ref));
9853 }
9854 if (((Tnode *)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
9855 { fprintf(fout,"\n\ta[i].soap_traverse(soap, s, p, q)");
9856 }
9857 else if (!is_primitive((Tnode*)typ->ref))
9858 { fprintf(fout,"\n\tsoap_traverse_%s(soap, a",c_ident((Tnode*)typ->ref));
9859 if(cardinality > 1)
9860 fprintf(fout,"[i], s, p, q)");
9861 else
9862 fprintf(fout,"+i, s, p, q)");
9863 }
9864 fprintf(fout,";\n\t}");
9865 }
9866 fprintf(fout,"\n\tif (q) q(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9867 fprintf(fout,"\n}");
9868 break;
9869 case Ttemplate:
9870 if (is_external(typ))
9871 { fprintf(fhead,"\nSOAP_FMAC1 void SOAP_FMAC2 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9872 return;
9873 }
9874 fprintf(fhead,"\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap*, %s, const char *s, soap_walker p, soap_walker q);",c_ident(typ),c_type_id(typ, "*"));
9875 temp = (Tnode*)typ->ref;
9876 if (!temp)
9877 return;
9878 fprintf(fout,"\n\nSOAP_FMAC3 void SOAP_FMAC4 soap_traverse_%s(struct soap *soap, %s, const char *s, soap_walker p, soap_walker q)\n{",c_ident(typ),c_type_id(typ, "*a"));
9879 if (!is_primitive(temp) && temp->type != Tfun && !is_void(temp))
9880 { fprintf(fout, "\n\tif (p) p(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9881 fprintf(fout, "\n\tfor (%s::iterator i = a->begin(); i != a->end(); ++i)", c_type(typ));
9882 if (temp->type==Tclass && !is_external(temp) && !is_volatile(temp) && !is_typedef(temp))
9883 fprintf(fout,"\n\t\t(*i).soap_traverse(soap, s, p, q);");
9884 else
9885 fprintf(fout,"\n\t\tsoap_traverse_%s(soap, &(*i), s, p, q);", c_ident(temp));
9886 fprintf(fout, "\n\tif (q) q(soap, (void*)a, %s, s, \"%s\");", soap_type(typ), c_type(typ));
9887 }
9888 fprintf(fout, "\n}");
9889 default: break;
9890 }
9891 }
9892
9893 void
9894 soap_put(Tnode *typ)
9895 { int d;
9896 Entry *p;
9897 char *ci = c_ident(typ);
9898 char *ct = c_type(typ);
9899 char *ctp = c_type_id(typ, "*");
9900 char *ctpa = c_type_id(typ, "*a");
9901 char *ctc = c_type_id(typ, "const");
9902 char *ctca = c_type_id(typ, "const a");
9903 char *ctcp = c_type_id(typ, "const*");
9904 char *ctcpa = c_type_id(typ, "const*a");
9905
9906 if (typ->type == Ttemplate || typ->type == Tunion)
9907 return;
9908
9909 if (is_typedef(typ) && is_element(typ))
9910 { fprintf(fhead, "\n\n#define soap_put_%s soap_put_%s\n", c_ident(typ), t_ident(typ));
9911 return;
9912 }
9913
9914 if (typ->type == Tarray)
9915 { fprintf(fhead,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap*, %s, const char*, const char*);", ci,ctc);
9916 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap *soap, %s, const char *tag, const char *type)\n{", ci,ctca);
9917 }
9918 else if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ) && !is_typedef(typ))
9919 fprintf(fout,"\n\nint %s::soap_put(struct soap *soap, const char *tag, const char *type) const\n{", ct);
9920 else if (typ->type == Tpointer)
9921 { fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap*, %s, const char*, const char*);", ci,ctcp);
9922 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap *soap, %s, const char *tag, const char *type)\n{", ci,ctcpa);
9923 }
9924 else
9925 { fprintf(fhead,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap*, const %s, const char*, const char*);", ci,ctp);
9926 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_put_%s(struct soap *soap, const %s, const char *tag, const char *type)\n{", ci,ctpa);
9927 }
9928 fflush(fout);
9929 fprintf(fout,"\n\tregister int id = ");
9930 if (is_invisible(typ->id->name))
9931 fprintf(fout,"0;");
9932 else if ((p = is_dynamic_array(typ)) != NULL)
9933 { d = get_Darraydims(typ);
9934 if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ) && !is_typedef(typ))
9935 { if (d)
9936 fprintf(fout,"soap_embed(soap, (void*)this, (struct soap_array*)&this->%s, %d, tag, %s);", ident(p->sym->name), d, soap_type(typ));
9937 else
9938 fprintf(fout,"soap_embed(soap, (void*)this, (struct soap_array*)&this->%s, 1, tag, %s);", ident(p->sym->name), soap_type(typ));
9939 }
9940 else if (d)
9941 fprintf(fout,"soap_embed(soap, (void*)a, (struct soap_array*)&a->%s, %d, tag, %s);", ident(p->sym->name), d, soap_type(typ));
9942 else
9943 fprintf(fout,"soap_embed(soap, (void*)a, (struct soap_array*)&a->%s, 1, tag, %s);", ident(p->sym->name), soap_type(typ));
9944 }
9945 else if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ) && !is_typedef(typ))
9946 fprintf(fout,"soap_embed(soap, (void*)this, NULL, 0, tag, %s);", soap_type(typ));
9947 else
9948 fprintf(fout,"soap_embed(soap, (void*)a, NULL, 0, tag, %s);", soap_type(typ));
9949 if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ) && !is_typedef(typ))
9950 fprintf(fout,"\n\tif (this->soap_out(soap, tag?tag:\"%s\", id, type))\n\t\treturn soap->error;", xml_tag(typ));
9951 else
9952 fprintf(fout,"\n\tif (soap_out_%s(soap, tag?tag:\"%s\", id, a, type))\n\t\treturn soap->error;", ci, xml_tag(typ));
9953 if (!is_invisible(typ->id->name))
9954 fprintf(fout,"\n\treturn soap_putindependent(soap);\n}");
9955 else
9956 fprintf(fout,"\n\treturn SOAP_OK;\n}");
9957 #if 0
9958 /* some compilers cannot handle this inlined function */
9959 if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ))
9960 fprintf(fhead, "\n\ninline int soap_write_%s(struct soap *soap, %s) { if (p->soap_put(soap, \"%s\", NULL) || soap_end_send(soap)) return soap->error; return SOAP_OK; }\n", c_ident(typ), c_type_id(typ, "*p"), xml_tag(typ));
9961 else if (typ->type != Treference)
9962 fprintf(fhead, "\n\ninline int soap_write_%s(struct soap *soap, %s) { if (soap_begin_send(soap) || soap_put_%s(soap, p, \"%s\", NULL) || soap_end_send(soap)) return soap->error; return SOAP_OK; }\n", c_ident(typ), c_type_id(typ, "*p"), c_ident(typ), xml_tag(typ));
9963 #endif
9964 if (typ->type == Tclass && !is_external(typ) && !is_volatile(typ))
9965 fprintf(fhead, "\n\n#ifndef soap_write_%s\n#define soap_write_%s(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || ((data)->soap_serialize(soap),0) || (data)->soap_put(soap, \"%s\", NULL) || soap_end_send(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), xml_tag(typ));
9966 else if (is_primitive(typ))
9967 { if ((!is_external(typ) || Qflag) && namespaceid)
9968 fprintf(fhead, "\n\n#ifndef soap_write_%s\n#define soap_write_%s(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (%s::soap_serialize_%s(soap, data),0) || %s::soap_put_%s(soap, data, \"%s\", NULL) || soap_end_send(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), namespaceid, c_ident(typ), namespaceid, c_ident(typ), xml_tag(typ));
9969 else
9970 fprintf(fhead, "\n\n#ifndef soap_write_%s\n#define soap_write_%s(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_%s(soap, data),0) || soap_put_%s(soap, data, \"%s\", NULL) || soap_end_send(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), c_ident(typ), c_ident(typ), xml_tag(typ));
9971 }
9972 else if (typ->type != Treference)
9973 { if (((!is_external(typ) && !is_volatile(typ)) || Qflag) && namespaceid)
9974 fprintf(fhead, "\n\n#ifndef soap_write_%s\n#define soap_write_%s(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (%s::soap_serialize_%s(soap, data),0) || %s::soap_put_%s(soap, data, \"%s\", NULL) || soap_end_send(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), namespaceid, c_ident(typ), namespaceid, c_ident(typ), xml_tag(typ));
9975 else
9976 fprintf(fhead, "\n\n#ifndef soap_write_%s\n#define soap_write_%s(soap, data) ( soap_free_temp(soap), soap_begin_send(soap) || (soap_serialize_%s(soap, data),0) || soap_put_%s(soap, data, \"%s\", NULL) || soap_end_send(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), c_ident(typ), c_ident(typ), xml_tag(typ));
9977 }
9978 fflush(fout);
9979 }
9980
9981 Entry *
9982 is_dynamic_array(Tnode *typ)
9983 { Entry *p;
9984 Table *t;
9985 if ((typ->type == Tstruct || typ->type == Tclass) && typ->ref)
9986 { for (t = (Table*)typ->ref; t; t = t->prev)
9987 { p = t->list;
9988 while (p && p->info.typ->type == Tfun)
9989 p = p->next;
9990 if (p && p->info.typ->type == Tpointer && !strncmp(ident(p->sym->name), "__ptr", 5))
9991 if (p->next && (p->next->info.typ->type == Tint || p->next->info.typ->type == Tulong || (p->next->info.typ->type == Tarray && (((Tnode*)p->next->info.typ->ref)->type == Tint || ((Tnode*)p->next->info.typ->ref)->type == Tuint))) && !strcmp(ident(p->next->sym->name), "__size"))
9992 return p;
9993 }
9994 }
9995 return 0;
9996 }
9997
9998 Entry *
9999 is_discriminant(Tnode *typ)
10000 { Entry *p;
10001 Table *t;
10002 if ((typ->type == Tstruct || typ->type == Tclass) && typ->ref)
10003 { t = (Table*)typ->ref;
10004 /* only if this struct/class has a union and is not derived */
10005 if (t && !t->prev)
10006 { p = t->list;
10007 if (p && p->info.typ->type == Tint && ((p->info.sto & Sspecial) || !strncmp(ident(p->sym->name), "__union", 7)))
10008 if (p->next && p->next->info.typ->type == Tunion)
10009 { Entry *q;
10010 for (q = p->next->next; q; q = q->next)
10011 { if (q->info.typ->type != Tfun
10012 && !is_void(q->info.typ)
10013 && !is_transient(q->info.typ))
10014 return NULL;
10015 }
10016 return p;
10017 }
10018 }
10019 }
10020 return NULL;
10021 }
10022
10023 int
10024 get_Darraydims(Tnode *typ)
10025 { Entry *p;
10026 Table *t;
10027 if ((typ->type == Tstruct || typ->type == Tclass) && typ->ref)
10028 { for (t = (Table*)typ->ref; t; t = t->prev)
10029 { p = t->list;
10030 while (p && p->info.typ->type == Tfun)
10031 p = p->next;
10032 if (p && p->info.typ->type == Tpointer && !strncmp(ident(p->sym->name), "__ptr", 5))
10033 if (p->next && p->next->info.typ->type == Tarray && (((Tnode*)p->next->info.typ->ref)->type == Tint || ((Tnode*)p->next->info.typ->ref)->type == Tuint) && !strcmp(ident(p->next->sym->name), "__size"))
10034 return get_dimension(p->next->info.typ);
10035 }
10036 }
10037 return 0;
10038 }
10039
10040 int
10041 has_offset(Tnode *typ)
10042 { Entry *p;
10043 Table *t;
10044 if (typ->type == Tstruct || typ->type == Tclass)
10045 { for (t = (Table*)typ->ref; t; t = t->prev)
10046 { for (p = t->list; p; p = p->next)
10047 { if ((p->info.typ->type == Tint || (p->info.typ->type == Tarray && ((Tnode*)p->info.typ->ref)->type == Tint)) && !strcmp(ident(p->sym->name), "__offset"))
10048 return 1;
10049 }
10050 }
10051 }
10052 return 0;
10053 }
10054
10055 int
10056 is_boolean(Tnode *typ)
10057 { if (typ->type == Tenum)
10058 { if ((Table*)typ->ref == booltable)
10059 return 1;
10060 else
10061 { size_t n = strlen(ident(typ->id->name));
10062 return n >= 7 && is_eq(ident(typ->id->name) + n - 7, "boolean");
10063 }
10064 }
10065 return 0;
10066 }
10067
10068 int
10069 is_hexBinary(Tnode *typ)
10070 { Entry *p;
10071 Table *t;
10072 size_t n = strlen(ident(typ->id->name));
10073 if ((typ->type == Tstruct || typ->type == Tclass) && n >= 9 && is_eq(ident(typ->id->name) + n - 9, "hexBinary"))
10074 { for (t = (Table*)typ->ref; t; t = t->prev)
10075 { p = t->list;
10076 while (p && p->info.typ->type == Tfun)
10077 p = p->next;
10078 if (p && p->info.typ->type == Tpointer && ((Tnode*)p->info.typ->ref)->type == Tuchar && !strcmp(ident(p->sym->name), "__ptr"))
10079 { p = p->next;
10080 return p && (p->info.typ->type == Tint || p->info.typ->type == Tuint) && !strcmp(ident(p->sym->name), "__size");
10081 }
10082 }
10083 }
10084 return 0;
10085 }
10086
10087 int
10088 is_binary(Tnode *typ)
10089 { Entry *p;
10090 Table *t;
10091 if (!has_ns(typ) && !is_element(typ))
10092 return 0;
10093 if (typ->type == Tstruct || typ->type == Tclass)
10094 { for (t = (Table*)typ->ref; t; t = t->prev)
10095 { p = t->list;
10096 while (p && p->info.typ->type == Tfun)
10097 p = p->next;
10098 if (p && p->info.typ->type == Tpointer && ((Tnode*)p->info.typ->ref)->type == Tuchar && !strcmp(ident(p->sym->name), "__ptr"))
10099 { p = p->next;
10100 return p && (p->info.typ->type == Tint || p->info.typ->type == Tuint) && !strcmp(ident(p->sym->name), "__size");
10101 }
10102 }
10103 }
10104 return 0;
10105 }
10106
10107 int
10108 is_attachment(Tnode *typ)
10109 { Entry *p;
10110 Table *t;
10111 if (!is_binary(typ) || is_transient(typ))
10112 return 0;
10113 for (t = (Table*)typ->ref; t; t = t->prev)
10114 { for (p = t->list; p; p = p->next)
10115 { if (is_string(p->info.typ) && !strcmp(p->sym->name, "id"))
10116 { p = p->next;
10117 if (!p || !is_string(p->info.typ) || strcmp(p->sym->name, "type"))
10118 break;
10119 p = p->next;
10120 if (!p || !is_string(p->info.typ) || strcmp(p->sym->name, "options"))
10121 break;
10122 return 1;
10123 }
10124 }
10125 }
10126 return 0;
10127 }
10128
10129 int
10130 has_attachment(Tnode *typ)
10131 { if (is_attachment(typ))
10132 return 1;
10133 if (typ->type == Tstruct || typ->type == Tclass)
10134 { Entry *p;
10135 Table *t;
10136 for (t = (Table*)typ->ref; t; t = t->prev)
10137 { for (p = t->list; p; p = p->next)
10138 if (has_attachment(p->info.typ))
10139 return 1;
10140 }
10141 }
10142 return 0;
10143 }
10144
10145 int
10146 is_mutable(Tnode *typ)
10147 { return is_header_or_fault(typ);
10148 }
10149
10150 int
10151 is_header_or_fault(Tnode *typ)
10152 { if (typ->type == Tpointer || typ->type == Treference)
10153 return is_header_or_fault((Tnode*)typ->ref);
10154 return (typ->type == Tstruct || typ->type == Tclass) && (!strcmp(ident(typ->id->name), "SOAP_ENV__Header") || !strcmp(ident(typ->id->name), "SOAP_ENV__Fault") || !strcmp(ident(typ->id->name), "SOAP_ENV__Code") || !strcmp(ident(typ->id->name), "SOAP_ENV__Detail") || !strcmp(ident(typ->id->name), "SOAP_ENV__Reason"));
10155 }
10156
10157 int
10158 is_body(Tnode *typ)
10159 { if (typ->type == Tpointer || typ->type == Treference)
10160 return is_body((Tnode*)typ->ref);
10161 return (typ->type == Tstruct || typ->type == Tclass) && !strcmp(ident(typ->id->name), "SOAP_ENV__Body");
10162 }
10163
10164 long
10165 minlen(Tnode *typ)
10166 { if (typ->minLength < 0 || (typ->maxLength >> 31) != 0)
10167 return 0;
10168 return (long)typ->minLength;
10169 }
10170
10171 long
10172 maxlen(Tnode *typ)
10173 { if (typ->maxLength < 0 || (typ->maxLength >> 31) != 0)
10174 return -1;
10175 return (long)typ->maxLength;
10176 }
10177
10178 int
10179 is_soap12(const char *enc)
10180 { return !strcmp(envURI, "http://www.w3.org/2003/05/soap-envelope") || (enc && !strcmp(enc, "http://www.w3.org/2003/05/soap-encoding"));
10181 }
10182
10183 int
10184 is_document(const char *style)
10185 { return vflag < 0 || (!eflag && !style) || (style && !strcmp(style, "document"));
10186 }
10187
10188 int
10189 is_literal(const char *encoding)
10190 { return vflag < 0 || (!eflag && !encoding) || (encoding && !strcmp(encoding, "literal"));
10191 }
10192
10193 char *
10194 has_soapref(Tnode *typ)
10195 { Entry *p;
10196 Table *t;
10197 if (typ->type == Tstruct || typ->type == Tclass)
10198 { for (t = (Table*)typ->ref; t; t = t->prev)
10199 { for (p = t->list; p; p = p->next)
10200 if (p->info.typ->type == Tpointer && ((Tnode*)p->info.typ->ref)->type == Tstruct && ((Tnode*)p->info.typ->ref)->id == lookup("soap"))
10201 return ident(p->sym->name);
10202 }
10203 }
10204 return NULL;
10205 }
10206
10207 int
10208 has_constructor(Tnode *typ)
10209 { Entry *p, *q;
10210 Table *t;
10211 if (typ->type == Tclass || typ->type == Tstruct)
10212 for (t = (Table*)typ->ref; t; t = t->prev)
10213 for (p = t->list; p; p = p->next)
10214 if (p->info.typ->type == Tfun && !strcmp(p->sym->name, typ->id->name) && ((FNinfo *)p->info.typ->ref)->ret->type == Tnone)
10215 { q = ((FNinfo*)p->info.typ->ref)->args->list;
10216 if (!q)
10217 return 1;
10218 }
10219 return 0;
10220 }
10221
10222 int
10223 has_destructor(Tnode *typ)
10224 { Entry *p;
10225 Table *t;
10226 if (typ->type == Tclass || typ->type == Tstruct)
10227 for (t = (Table*)typ->ref; t; t = t->prev)
10228 for (p = t->list; p; p = p->next)
10229 if (p->info.typ->type == Tfun && *p->sym->name == '~')
10230 return 1;
10231 return 0;
10232 }
10233
10234 int
10235 has_getter(Tnode *typ)
10236 { Entry *p, *q;
10237 Table *t;
10238 if (typ->type == Tclass)
10239 for (t = (Table*)typ->ref; t; t = t->prev)
10240 for (p = t->list; p; p = p->next)
10241 if (p->info.typ->type == Tfun && !strcmp(p->sym->name, "get") && ((FNinfo *)p->info.typ->ref)->ret->type == Tint)
10242 { q = ((FNinfo*)p->info.typ->ref)->args->list;
10243 if (q && q->info.typ->type == Tpointer && ((Tnode*)q->info.typ->ref)->type == Tstruct && ((Tnode*)q->info.typ->ref)->id == lookup("soap"))
10244 return 1;
10245 }
10246 return 0;
10247 }
10248
10249 int
10250 has_setter(Tnode *typ)
10251 { Entry *p, *q;
10252 Table *t;
10253 if (typ->type == Tclass)
10254 for (t = (Table*)typ->ref; t; t = t->prev)
10255 for (p = t->list; p; p = p->next)
10256 if (p->info.typ->type == Tfun && !strcmp(p->sym->name, "set") && ((FNinfo *)p->info.typ->ref)->ret->type == Tint)
10257 { q = ((FNinfo*)p->info.typ->ref)->args->list;
10258 if (q && q->info.typ->type == Tpointer && ((Tnode*)q->info.typ->ref)->type == Tstruct && ((Tnode*)q->info.typ->ref)->id == lookup("soap"))
10259 return 1;
10260 }
10261 return 0;
10262 }
10263
10264 int
10265 is_primitive_or_string(Tnode *typ)
10266 { return is_primitive(typ) || is_string(typ) || is_wstring(typ) || is_stdstring(typ) || is_stdwstring(typ) || is_qname(typ) || is_stdqname(typ);
10267 }
10268
10269 int
10270 is_primitive(Tnode *typ)
10271 { return typ->type <= Tenum;
10272 }
10273
10274 int
10275 is_string(Tnode *typ)
10276 { return typ->type == Tpointer && ((Tnode*)typ->ref)->type == Tchar && !((Tnode*)typ->ref)->sym;
10277 }
10278
10279 int
10280 is_fixedstring(Tnode *typ)
10281 { return bflag && typ->type == Tarray && ((Tnode*)typ->ref)->type == Tchar;
10282 }
10283
10284 int
10285 is_wstring(Tnode *typ)
10286 { return typ->type == Tpointer && ((Tnode*)typ->ref)->type == Twchar && !((Tnode*)typ->ref)->sym;
10287 }
10288
10289 int
10290 is_stdstring(Tnode *typ)
10291 { return typ->type == Tclass && typ->id == lookup("std::string");
10292 }
10293
10294 int
10295 is_stdwstring(Tnode *typ)
10296 { return typ->type == Tclass && typ->id == lookup("std::wstring");
10297 }
10298
10299 int
10300 is_stdstr(Tnode *typ)
10301 { if (typ->type == Tpointer)
10302 return is_stdstring((Tnode*)typ->ref) || is_stdwstring((Tnode*)typ->ref);
10303 return is_stdstring(typ) || is_stdwstring(typ);
10304 }
10305
10306 int
10307 is_typedef(Tnode *typ)
10308 { return typ->sym && !is_transient(typ);
10309 }
10310
10311 int
10312 reflevel(Tnode *typ)
10313 { int level;
10314 for (level = 0; typ->type == Tpointer; level++)
10315 typ = (Tnode*)typ->ref;
10316 return level;
10317 }
10318
10319 Tnode *
10320 reftype(Tnode *typ)
10321 { while ((typ->type == Tpointer && !is_string(typ) && !is_wstring(typ)) || typ->type == Treference)
10322 typ = (Tnode*)typ->ref;
10323 return typ;
10324 }
10325
10326 void
10327 soap_set_attr(Entry *p, char *obj, char *name, char *tag)
10328 { Tnode *typ = p->info.typ;
10329 int flag = (p->info.minOccurs == 0);
10330 if (is_external(typ) && !is_anyAttribute(typ))
10331 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, %s->%s), 1);", tag, c_ident(typ), obj, name);
10332 else if (is_qname(typ))
10333 fprintf(fout, "\n\tif (%s->%s)\n\t\tsoap_set_attr(soap, \"%s\", soap_QName2s(soap, %s->%s), 1);", obj, name, tag, obj, name);
10334 else if (is_string(typ))
10335 fprintf(fout, "\n\tif (%s->%s)\n\t\tsoap_set_attr(soap, \"%s\", %s->%s, 1);", obj, name, tag, obj, name);
10336 else if (is_wstring(typ))
10337 fprintf(fout, "\n\tif (%s->%s)\n\t\tsoap_set_attr(soap, \"%s\", soap_wchar2s(soap, %s->%s), 2);", obj, name, tag, obj, name);
10338 else if (is_stdqname(typ))
10339 fprintf(fout, "\n\tif (!%s->%s.empty())\n\t\tsoap_set_attr(soap, \"%s\", soap_QName2s(soap, %s->%s.c_str()), 1);", obj, name, tag, obj, name);
10340 else if (is_stdstring(typ))
10341 { if (flag)
10342 fprintf(fout, "\n\tif (!%s->%s.empty())", obj, name);
10343 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", %s->%s.c_str(), 1);", tag, obj, name);
10344 }
10345 else if (is_stdwstring(typ))
10346 { if (flag)
10347 fprintf(fout, "\n\tif (!%s->%s.empty())", obj, name);
10348 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", soap_wchar2s(soap, %s->%s.c_str()), 2);", tag, obj, name);
10349 }
10350 else if (typ->type == Tllong || typ->type == Tullong)
10351 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, %s->%s), 1);", tag, c_type(typ), obj, name);
10352 else if (typ->type == Tenum)
10353 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, %s->%s), 1);", tag, c_ident(typ), obj, name);
10354 else if (typ->type == Tpointer)
10355 { Tnode *ptr = (Tnode*)typ->ref;
10356 fprintf(fout, "\n\tif (%s->%s)", obj, name);
10357 if (is_external(ptr) && !is_anyAttribute(ptr))
10358 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, *%s->%s), 1);", tag, c_ident(ptr), obj, name);
10359 else if (is_qname(ptr))
10360 fprintf(fout, "\n\t\tif (*%s->%s)\n\t\t\tsoap_set_attr(soap, \"%s\", soap_QName2s(soap, *%s->%s), 1);", obj, name, tag, obj, name);
10361 else if (is_string(ptr))
10362 fprintf(fout, "\n\t\tif (*%s->%s)\n\t\t\tsoap_set_attr(soap, \"%s\", *%s->%s, 1);", obj, name, tag, obj, name);
10363 else if (ptr->type == Tllong || ptr->type == Tullong)
10364 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, *%s->%s), 1);", tag, c_type(ptr), obj, name);
10365 else if (ptr->type == Tenum)
10366 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, *%s->%s), 1);", tag, c_ident(ptr), obj, name);
10367 else if (is_stdqname(ptr))
10368 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_QName2s(soap, %s->%s->c_str()), 1);", tag, obj, name);
10369 else if (is_stdstring(ptr))
10370 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", %s->%s->c_str(), 1);", tag, obj, name);
10371 else if (is_stdwstring(ptr))
10372 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_wchar2s(soap, %s->%s->c_str()), 2);", tag, obj, name);
10373 else if (is_primitive(ptr))
10374 fprintf(fout, "\n\t\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, *%s->%s), 1);", tag, the_type(ptr), obj, name);
10375 else if (is_hexBinary(ptr))
10376 fprintf(fout, "\n\t\tif (%s->%s->__ptr)\n\t\t\tsoap_set_attr(soap, \"%s\", soap_s2hex(soap, %s->%s->__ptr, NULL, %s->%s->__size), 1);", obj, name, tag, obj, name, obj, name);
10377 else if (is_binary(ptr))
10378 fprintf(fout, "\n\t\tif (%s->%s->__ptr)\n\t\t\tsoap_set_attr(soap, \"%s\", soap_s2base64(soap, %s->%s->__ptr, NULL, %s->%s->__size), 1);", obj, name, tag, obj, name, obj, name);
10379 else if (is_anyAttribute(ptr))
10380 fprintf(fout, "\n\t\tif (soap_out_%s(soap, \"%s\", -1, %s->%s, \"%s\"))\n\t\t\treturn soap->error;", c_ident(ptr), tag, obj, name, xsi_type_u(ptr));
10381 else
10382 { sprintf(errbuf, "Field '%s' cannot be serialized as an XML attribute", name);
10383 semwarn(errbuf);
10384 }
10385 }
10386 else if (is_primitive(typ))
10387 fprintf(fout, "\n\tsoap_set_attr(soap, \"%s\", soap_%s2s(soap, %s->%s), 1);", tag, the_type(typ), obj, name);
10388 else if (is_hexBinary(typ))
10389 fprintf(fout, "\n\tif (%s->%s.__ptr)\n\t\tsoap_set_attr(soap, \"%s\", soap_s2hex(soap, %s->%s.__ptr, NULL, %s->%s.__size), 1);", obj, name, tag, obj, name, obj, name);
10390 else if (is_binary(typ))
10391 fprintf(fout, "\n\tif (%s->%s.__ptr)\n\t\tsoap_set_attr(soap, \"%s\", soap_s2base64(soap, %s->%s.__ptr, NULL, %s->%s.__size), 1);", obj, name, tag, obj, name, obj, name);
10392 else if (is_anyAttribute(typ))
10393 fprintf(fout, "\n\tif (soap_out_%s(soap, \"%s\", -1, &%s->%s, \"%s\"))\n\t\treturn soap->error;", c_ident(typ), tag, obj, name, xsi_type_u(typ));
10394 else
10395 { sprintf(errbuf, "Field '%s' cannot be serialized as an XML attribute", name);
10396 semwarn(errbuf);
10397 }
10398 }
10399
10400 void
10401 soap_attr_value(Entry *p, char *obj, char *name, char *tag)
10402 { int flag = 0;
10403 Tnode *typ = p->info.typ;
10404 if (p->info.maxOccurs == 0)
10405 flag = 2; /* prohibited */
10406 else if (p->info.minOccurs >= 1 && !p->info.hasval)
10407 flag = 1; /* required */
10408 if (is_external(typ) && !is_anyAttribute(typ))
10409 fprintf(fout, "\n\tif (soap_s2%s(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s))\n\t\treturn NULL;", c_ident(typ), tag, flag, obj, name);
10410 else if (typ->type == Tllong || typ->type == Tullong)
10411 fprintf(fout, "\n\tif (soap_s2%s(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s))\n\t\treturn NULL;", c_type(typ), tag, flag, obj, name);
10412 else if (typ->type == Tenum)
10413 fprintf(fout, "\n\tif (soap_s2%s(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s))\n\t\treturn NULL;", c_ident(typ), tag, flag, obj, name);
10414 else if (is_qname(typ))
10415 fprintf(fout, "\n\tif (soap_s2QName(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s, %ld, %ld))\n\t\treturn NULL;", tag, flag, obj, name, minlen(typ), maxlen(typ));
10416 else if (is_string(typ))
10417 fprintf(fout, "\n\tif (soap_s2string(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s, %ld, %ld))\n\t\treturn NULL;", tag, flag, obj, name, minlen(typ), maxlen(typ));
10418 else if (is_wstring(typ))
10419 fprintf(fout, "\n\tif (soap_s2wchar(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s, %ld, %ld))\n\t\treturn NULL;", tag, flag, obj, name, minlen(typ), maxlen(typ));
10420 else if (is_stdqname(typ))
10421 fprintf(fout, "\n\t{\tconst char *t = soap_attr_value(soap, \"%s\", %d);\n\t\tif (t)\n\t\t{\tchar *s;\n\t\t\tif (soap_s2QName(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\t%s->%s.assign(s);\n\t\t}\n\t\telse if (soap->error)\n\t\t\treturn NULL;\n\t}", tag, flag, minlen(typ), maxlen(typ), obj, name);
10422 else if (is_stdstring(typ))
10423 fprintf(fout, "\n\t{\tconst char *t = soap_attr_value(soap, \"%s\", %d);\n\t\tif (t)\n\t\t{\tchar *s;\n\t\t\tif (soap_s2string(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\t%s->%s.assign(s);\n\t\t}\n\t\telse if (soap->error)\n\t\t\treturn NULL;\n\t}", tag, flag, minlen(typ), maxlen(typ), obj, name);
10424 else if (is_stdwstring(typ))
10425 fprintf(fout, "\n\t{\tconst char *t = soap_attr_value(soap, \"%s\", %d);\n\t\tif (t)\n\t\t{\twchar_t *s;\n\t\t\tif (soap_s2wchar(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\t%s->%s.assign(s);\n\t\t}\n\t\telse if (soap->error)\n\t\t\treturn NULL;\n\t}", tag, flag, minlen(typ), maxlen(typ), obj, name);
10426 else if (typ->type == Tpointer)
10427 { Tnode *ptr = (Tnode*)typ->ref;
10428 if (!is_anyAttribute(ptr))
10429 fprintf(fout, "\n\t{\tconst char *t = soap_attr_value(soap, \"%s\", %d);\n\t\tif (t)\n\t\t{", tag, flag);
10430 if (!is_stdstring(ptr))
10431 fprintf(fout, "\n\t\t\tif (!(%s->%s = (%s)soap_malloc(soap, sizeof(%s))))\n\t\t\t{\tsoap->error = SOAP_EOM;\n\t\t\t\treturn NULL;\n\t\t\t}", obj, name, c_type(typ), c_type(ptr));
10432 if (is_external(ptr) && !is_anyAttribute(ptr))
10433 fprintf(fout, "\n\t\t\tif (soap_s2%s(soap, t, %s->%s))\n\t\t\t\treturn NULL;", c_ident(ptr), obj, name);
10434 else if (ptr->type == Tllong || ptr->type == Tullong)
10435 fprintf(fout, "\n\t\t\tif (soap_s2%s(soap, t, %s->%s))\n\t\t\treturn NULL;", c_type(ptr), obj, name);
10436 else if (ptr->type == Tenum)
10437 fprintf(fout, "\n\t\t\tif (soap_s2%s(soap, t, %s->%s))\n\t\t\treturn NULL;", c_ident(ptr), obj, name);
10438 else if (is_qname(ptr))
10439 fprintf(fout, "\n\t\t\tif (soap_s2QName(soap, t, %s->%s, %ld, %ld))\n\t\t\t\treturn NULL;", obj, name, minlen(ptr), maxlen(ptr));
10440 else if (is_string(ptr))
10441 fprintf(fout, "\n\t\t\tif (soap_s2string(soap, t, %s->%s, %ld, %ld))\n\t\t\t\treturn NULL;", obj, name, minlen(ptr), maxlen(ptr));
10442 else if (is_stdqname(ptr))
10443 fprintf(fout, "\n\t\t\tchar *s = NULL;\n\t\t\tif (soap_s2QName(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\tif (s)\n\t\t\t{\t%s->%s = soap_new_std__string(soap, -1);\n\t\t\t\t%s->%s->assign(s);\n\t\t\t}", minlen(ptr), maxlen(ptr), obj, name, obj, name);
10444 else if (is_stdstring(ptr))
10445 fprintf(fout, "\n\t\t\tchar *s = NULL;\n\t\t\tif (soap_s2string(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\tif (s)\n\t\t\t{\t%s->%s = soap_new_std__string(soap, -1);\n\t\t\t\t%s->%s->assign(s);\n\t\t\t}", minlen(ptr), maxlen(ptr), obj, name, obj, name);
10446 else if (is_stdwstring(ptr))
10447 fprintf(fout, "\n\t\t\twchar_t *s = NULL;\n\t\t\tif (soap_s2wchar(soap, t, &s, %ld, %ld))\n\t\t\t\treturn NULL;\n\t\t\tif (s)\n\t\t\t{\t%s->%s = soap_new_std__wstring(soap, -1);\n\t\t\t\t%s->%s->assign(s);\n\t\t\t}", minlen(ptr), maxlen(ptr), obj, name, obj, name);
10448 else if (is_hexBinary(ptr))
10449 fprintf(fout, "\n\t\t\tif (!(%s->%s->__ptr = (unsigned char*)soap_hex2s(soap, soap_attr_value(soap, \"%s\", %d), NULL, 0, &%s->%s->__size)))\n\t\t\t\treturn NULL;", obj, name, tag, flag, obj, name);
10450 else if (is_binary(ptr))
10451 fprintf(fout, "\n\t\t\tif (!(%s->%s->__ptr = (unsigned char*)soap_base642s(soap, soap_attr_value(soap, \"%s\", %d), NULL, 0, &%s->%s->__size)))\n\t\t\t\treturn NULL;", obj, name, tag, flag, obj, name);
10452 else if (is_anyAttribute(ptr))
10453 fprintf(fout, "\n\t\t\t%s->%s = soap_in_%s(soap, \"%s\", %s->%s, \"%s\");", obj, name, c_ident(ptr), tag, obj, name, xsi_type(ptr));
10454 else
10455 fprintf(fout, "\n\t\t\tif (soap_s2%s(soap, t, %s->%s))\n\t\t\t\treturn NULL;", the_type(ptr), obj, name);
10456 if (!is_anyAttribute(ptr))
10457 fprintf(fout, "\n\t\t}\n\t\telse if (soap->error)\n\t\t\treturn NULL;\n\t}");
10458 }
10459 else if (is_hexBinary(typ))
10460 fprintf(fout, "\n\tif (!(%s->%s.__ptr = (unsigned char*)soap_hex2s(soap, soap_attr_value(soap, \"%s\", %d), NULL, 0, &%s->%s.__size)))\n\t\treturn NULL;", obj, name, tag, flag, obj, name);
10461 else if (is_binary(typ))
10462 fprintf(fout, "\n\tif (!(%s->%s.__ptr = (unsigned char*)soap_base642s(soap, soap_attr_value(soap, \"%s\", %d), NULL, 0, &%s->%s.__size)))\n\t\treturn NULL;", obj, name, tag, flag, obj, name);
10463 else if (is_anyAttribute(typ))
10464 fprintf(fout, "\n\tsoap_in_%s(soap, \"%s\", &%s->%s, \"%s\");", c_ident(typ), tag, obj, name, xsi_type(typ));
10465 else if (is_primitive(typ))
10466 fprintf(fout, "\n\tif (soap_s2%s(soap, soap_attr_value(soap, \"%s\", %d), &%s->%s))\n\t\treturn NULL;", the_type(typ), tag, flag, obj, name);
10467 if (typ->type == Tpointer)
10468 { if (!is_string(typ) && !is_wstring(typ) && !is_stdstr(typ->ref))
10469 { Tnode *ptr = (Tnode*)typ->ref;
10470 if (ptr->type <= Tenum)
10471 { if (ptr->minLength != MINLONG64 && (ptr->minLength > 0 || ptr->type < Tuchar || ptr->type > Tullong))
10472 fprintf(fout,"\n\tif (%s->%s && *%s->%s < " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", obj, name, obj, name, ptr->minLength);
10473 if (ptr->maxLength != MAXLONG64)
10474 fprintf(fout,"\n\tif (%s->%s && *%s->%s > " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", obj, name, obj, name, ptr->maxLength);
10475 }
10476 }
10477 }
10478 else if (typ->type <= Tenum)
10479 { if (typ->minLength != MINLONG64 && (typ->minLength > 0 || typ->type < Tuchar || typ->type > Tullong))
10480 fprintf(fout,"\n\tif (%s->%s < " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", obj, name, typ->minLength);
10481 if (typ->maxLength != MAXLONG64)
10482 fprintf(fout,"\n\tif (%s->%s > " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", obj, name, typ->maxLength);
10483 }
10484 }
10485
10486 char *
10487 ptr_cast(Table *t, char *name)
10488 { char *s = emalloc(strlen(t->sym->name) + strlen(name) + 6);
10489 sprintf(s, "((%s*)%s)", t->sym->name, name);
10490 return s;
10491 }
10492
10493 void
10494 soap_out(Tnode *typ)
10495 { Table *table,*t;
10496 Entry *p = NULL;
10497 int cardinality,i,j,d;
10498 Tnode *n;
10499 char *nse = ns_qualifiedElement(typ);
10500 char *nsa = ns_qualifiedAttribute(typ);
10501
10502 if (is_dynamic_array(typ))
10503 { soap_out_Darray(typ);
10504 return;
10505 }
10506
10507 if (is_external(typ))
10508 fprintf(fhead, "\n\nSOAP_FMAC3S const char* SOAP_FMAC4S soap_%s2s(struct soap*, %s);", c_ident(typ), c_type(typ));
10509
10510 if (is_typedef(typ) && is_element(typ) && !is_external(typ))
10511 { fprintf(fhead, "\n\n#define soap_out_%s soap_out_%s\n", c_ident(typ), t_ident(typ));
10512 return;
10513 }
10514
10515 if (is_primitive(typ) && typ->type != Tenum)
10516 { if (is_external(typ))
10517 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ), c_type_id(typ, "*"));
10518 return;
10519 }
10520 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ), c_type_id(typ, "*"));
10521 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)\n{\t(void)soap; (void)type; (void)tag; (void)id;", c_ident(typ), c_type_id(typ, "*a"));
10522 if (typ->type == Tllong || typ->type == Tullong)
10523 fprintf(fout,"\n\treturn soap_out%s(soap, tag, id, a, type, %s);\n}", c_type(typ), soap_type(typ));
10524 else
10525 fprintf(fout,"\n\treturn soap_out%s(soap, tag, id, a, type, %s);\n}", the_type(typ), soap_type(typ));
10526 return;
10527 }
10528 if (is_fixedstring(typ))
10529 { fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const char[], const char*);", c_ident(typ));
10530 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const char a[], const char *type)\n{", c_ident(typ));
10531 fprintf(fout,"\n\treturn soap_outstring(soap, tag, id, (char*const*)&a, type, %s);\n}", soap_type(typ));
10532 return;
10533 }
10534 if (is_string(typ))
10535 { if (is_external(typ))
10536 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, char*const*, const char*);", c_ident(typ));
10537 return;
10538 }
10539 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, char*const*, const char*);", c_ident(typ));
10540 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, char *const*a, const char *type)\n{", c_ident(typ));
10541 fprintf(fout,"\n\treturn soap_outstring(soap, tag, id, a, type, %s);\n}", soap_type(typ));
10542 return;
10543 }
10544 if (is_wstring(typ))
10545 { if (is_external(typ))
10546 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, wchar_t*const*, const char*);", c_ident(typ));
10547 return;
10548 }
10549 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, wchar_t*const*, const char*);", c_ident(typ));
10550 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, wchar_t *const*a, const char *type)\n{", c_ident(typ));
10551 fprintf(fout,"\n\treturn soap_outwstring(soap, tag, id, a, type, %s);\n}", soap_type(typ));
10552 return;
10553 }
10554 if (is_stdstring(typ))
10555 { if (is_external(typ))
10556 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const std::string*, const char*);", c_ident(typ));
10557 return;
10558 }
10559 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const std::string*, const char*);", c_ident(typ));
10560 if (is_stdXML(typ))
10561 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const std::string *s, const char *type)\n{\n\tconst char *t = s->c_str();\n\treturn soap_outliteral(soap, tag, (char*const*)&t, type);\n}", c_ident(typ));
10562 else
10563 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const std::string *s, const char *type)\n{\n\tif ((soap->mode & SOAP_C_NILSTRING) && s->empty())\n\t\treturn soap_element_null(soap, tag, id, type);\n\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, s, %s), type) || soap_string_out(soap, s->c_str(), 0) || soap_element_end_out(soap, tag))\n\t\treturn soap->error;\n\treturn SOAP_OK;\n}", c_ident(typ), soap_type(typ));
10564 return;
10565 }
10566 if (is_stdwstring(typ))
10567 { if (is_external(typ))
10568 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const std::wstring*, const char*);", c_ident(typ));
10569 return;
10570 }
10571 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const std::wstring*, const char*);", c_ident(typ));
10572 if (is_stdXML(typ))
10573 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const std::wstring *s, const char *type)\n{\n\tconst wchar_t *t = s->c_str();\n\treturn soap_outwliteral(soap, tag, (wchar_t*const*)&t, type);\n}", c_ident(typ));
10574 else
10575 fprintf(fout,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const std::wstring *s, const char *type)\n{\n\tif ((soap->mode & SOAP_C_NILSTRING) && s->empty())\n\t\treturn soap_element_null(soap, tag, id, type);\n\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, s, %s), type) || soap_wstring_out(soap, s->c_str(), 0) || soap_element_end_out(soap, tag))\n\t\treturn soap->error;\n\treturn SOAP_OK;\n}", c_ident(typ), soap_type(typ));
10576 return;
10577 }
10578 switch(typ->type)
10579 { case Tstruct:
10580 if (is_external(typ))
10581 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
10582 return;
10583 }
10584 table=(Table*)typ->ref;
10585 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
10586 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)\n{", c_ident(typ),c_type_id(typ, "*a"));
10587 for (t = table; t; t = t->prev)
10588 { for (p = t->list; p; p = p->next)
10589 { if (is_repetition(p))
10590 p = p->next;
10591 else if (p->info.sto & Sattribute)
10592 soap_set_attr(p, "a", ident(p->sym->name), ns_add(p, nsa));
10593 else if (is_qname(p->info.typ))
10594 fprintf(fout,"\n\tconst char *soap_tmp_%s = soap_QName2s(soap, a->%s);", ident(p->sym->name), ident(p->sym->name));
10595 else if (is_stdqname(p->info.typ))
10596 fprintf(fout,"\n\tstd::string soap_tmp_%s(soap_QName2s(soap, a->%s.c_str()));", ident(p->sym->name), ident(p->sym->name));
10597 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10598 fprintf(fout,"\n\tconst char *soap_tmp_%s = a->%s ? soap_QName2s(soap, *a->%s) : NULL;", ident(p->sym->name), ident(p->sym->name), ident(p->sym->name));
10599 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10600 fprintf(fout,"\n\tstd::string soap_temp_%s(a->%s ? soap_QName2s(soap, a->%s->c_str()) : \"\"), *soap_tmp_%s = a->%s ? &soap_temp_%s : NULL;", ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name));
10601 }
10602 }
10603 fprintf(fout,"\n\t(void)soap; (void)tag; (void)id; (void)type;");
10604 if (is_primclass(typ))
10605 {
10606 for (table = (Table*)typ->ref; table; table = table->prev)
10607 { p = table->list;
10608 if (p && is_item(p))
10609 break;
10610 }
10611 if ((p->info.sto & SmustUnderstand) && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && !is_transient(p->info.typ) && !is_void(p->info.typ) && p->info.typ->type != Tfun)
10612 fprintf(fout, "\n\tsoap->mustUnderstand = 1;");
10613 if(p->info.typ->type==Tarray)
10614 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, a->%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10615 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10616 fprintf(fout,"\n\treturn a->%s.soap_out(soap, tag, id, \"%s\");", ident(p->sym->name), xsi_type_u(typ));
10617 else if (is_qname(p->info.typ))
10618 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)&soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10619 else if (is_stdqname(p->info.typ))
10620 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10621 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10622 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)soap_tmp_%s, \"%s\");", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type_u(typ));
10623 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10624 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10625 else if (is_XML(p->info.typ) && is_string(p->info.typ))
10626 fprintf(fout,"\n\treturn soap_outliteral(soap, tag, &a->%s, NULL);", ident(p->sym->name));
10627 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10628 fprintf(fout,"\n\treturn soap_outwliteral(soap, tag, &a->%s, NULL);", ident(p->sym->name));
10629 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10630 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &a->%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10631 else
10632 fprintf(fout,"\n\treturn SOAP_OK;");
10633 fprintf(fout,"\n}");
10634 }
10635 else
10636 { if (!is_invisible(typ->id->name))
10637 fprintf(fout,"\n\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, %s), type))\n\t\treturn soap->error;", soap_type(typ));
10638 fflush(fout);
10639 for (t = table; t; t = t->prev)
10640 { for (p = t->list; p; p = p->next)
10641 { if (p->info.sto & Sreturn)
10642 { if (nse || has_ns_eq(NULL, p->sym->name))
10643 { if (p->info.typ->type == Tpointer)
10644 fprintf(fout,"\n\tif (a->%s)\n\t\tsoap_element_result(soap, \"%s\");", ident(p->sym->name), ns_add(p, nse));
10645 else
10646 fprintf(fout,"\n\tsoap_element_result(soap, \"%s\");", ns_add(p, nse));
10647 }
10648 }
10649 if ((p->info.sto & SmustUnderstand) && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !is_transient(p->info.typ) && !is_void(p->info.typ) && p->info.typ->type != Tfun)
10650 fprintf(fout, "\n\tsoap->mustUnderstand = 1;");
10651 needs_lang(p);
10652 if (p->info.sto & (Sconst | Sprivate | Sprotected))
10653 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
10654 else if (is_transient(p->info.typ))
10655 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
10656 else if (p->info.sto & Sattribute)
10657 ;
10658 else if (is_repetition(p))
10659 { fprintf(fout,"\n\tif (a->%s)", ident(p->next->sym->name));
10660 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < a->%s; i++)", ident(p->sym->name));
10661 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
10662 fprintf(fout,"\n\t\t\tif (a->%s[i].soap_out(soap, \"%s\", -1, \"%s\"))\n\t\t\t\treturn soap->error;", ident(p->next->sym->name), ns_add(p->next, nse),xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10663 else if (is_qname((Tnode*)p->next->info.typ->ref))
10664 fprintf(fout,"\n\t\t{\tconst char *soap_tmp_%s = soap_QName2s(soap, a->%s[i]);\n\t\t\tif (soap_out_%s(soap, \"%s\", -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\t\t\treturn soap->error;\n\t\t}", ident(p->next->sym->name), ident(p->next->sym->name), c_ident((Tnode*)p->next->info.typ->ref), ns_add(p->next, nse), ident(p->next->sym->name), xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10665 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
10666 fprintf(fout,"\n\t\t\tsoap_outliteral(soap, \"%s\", a->%s + i, NULL);", ns_add(p->next, nse), ident(p->next->sym->name));
10667 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
10668 fprintf(fout,"\n\t\t\tsoap_outwliteral(soap, \"%s\", a->%s + i, NULL);", ns_add(p->next, nse), ident(p->next->sym->name));
10669 else
10670 fprintf(fout,"\n\t\t\tif (soap_out_%s(soap, \"%s\", -1, a->%s + i, \"%s\"))\n\t\t\t\treturn soap->error;", c_ident((Tnode*)p->next->info.typ->ref), ns_add(p->next, nse), ident(p->next->sym->name), xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10671 fprintf(fout,"\n\t}");
10672 p = p->next;
10673 }
10674 else if (is_anytype(p) && is_invisible(p->next->sym->name))
10675 { fprintf(fout,"\n\tif (soap_putelement(soap, a->%s, tag, -1, a->%s))\n\t\treturn soap->error;", ident(p->next->sym->name), ident(p->sym->name));
10676 p = p->next;
10677 }
10678 else if (is_anytype(p))
10679 { fprintf(fout,"\n\tif (soap_putelement(soap, a->%s, \"%s\", -1, a->%s))\n\t\treturn soap->error;", ident(p->next->sym->name), ns_add(p->next, nse), ident(p->sym->name));
10680 p = p->next;
10681 }
10682 else if (is_choice(p))
10683 { fprintf(fout,"\n\tif (soap_out_%s(soap, a->%s, &a->%s))\n\t\treturn soap->error;", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name));
10684 p = p->next;
10685 }
10686 else if (p->info.typ->type==Tarray)
10687 fprintf(fout,"\n\tsoap_out_%s(soap, %s, -1, a->%s, \"%s\");", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10688 else if (p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10689 fprintf(fout,"\n\tif (a->%s.soap_out(soap, %s, -1, \"%s\"))\n\t\treturn soap->error;", ident(p->sym->name), field(p, nse), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10690 else if (is_qname(p->info.typ))
10691 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10692 else if (is_stdqname(p->info.typ))
10693 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10694 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10695 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident((Tnode*)p->info.typ->ref), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10696 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10697 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10698 else if (is_XML(p->info.typ) && is_string(p->info.typ))
10699 fprintf(fout,"\n\tsoap_outliteral(soap, %s, &a->%s, NULL);", field(p, nse), ident(p->sym->name));
10700 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10701 fprintf(fout,"\n\tsoap_outwliteral(soap, %s, &a->%s, NULL);", field(p, nse), ident(p->sym->name));
10702 else if (p->info.typ->type == Tpointer && !is_void(p->info.typ) && p->info.minOccurs > 0)
10703 fprintf(fout,"\n\tif (a->%s)\n\t{\tif (soap_out_%s(soap, %s, -1, &a->%s, \"%s\"))\n\t\t\treturn soap->error;\n\t}\n\telse if (soap_element_nil(soap, %s))\n\t\treturn soap->error;", ident(p->sym->name), c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)), field(p, nse));
10704 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10705 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &a->%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10706 }
10707 }
10708 if (!is_invisible(typ->id->name))
10709 fprintf(fout,"\n\treturn soap_element_end_out(soap, tag);\n}");
10710 else
10711 fprintf(fout,"\n\treturn SOAP_OK;\n}");
10712 }
10713 fflush(fout);
10714 break;
10715
10716 case Tclass:
10717 if (is_external(typ))
10718 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
10719 return;
10720 }
10721 table=(Table*)typ->ref;
10722 if (!is_volatile(typ) && !is_typedef(typ))
10723 {
10724 if (is_external(typ))
10725 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
10726 return;
10727 }
10728 fprintf(fout,"\n\nint %s::soap_out(struct soap *soap, const char *tag, int id, const char *type) const", ident(typ->id->name));
10729 fprintf(fout,"\n{\n\treturn soap_out_%s(soap, tag, id, this, type);\n}", c_ident(typ));
10730 }
10731 fprintf(fhead,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ), c_type_id(typ, "*"));
10732 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)\n{", c_ident(typ), c_type_id(typ, "*a"));
10733 fflush(fout);
10734 if (has_setter(typ))
10735 fprintf(fout, "\n\t((%s)a)->set(soap);", c_type_id(typ, "*"));
10736 for (t = table; t; t = t->prev)
10737 { Entry *e = entry(classtable, t->sym);
10738 char *nsa1 = e ? ns_qualifiedAttribute(e->info.typ) : nsa;
10739 for (p = t->list; p; p = p->next)
10740 { if (is_repetition(p))
10741 p = p->next;
10742 else if (p->info.sto & Sattribute)
10743 soap_set_attr(p, ptr_cast(t, "a"), ident(p->sym->name), ns_add(p, nsa1));
10744 else if (is_qname(p->info.typ))
10745 fprintf(fout,"\n\tconst char *soap_tmp_%s = soap_QName2s(soap, a->%s);", ident(p->sym->name), ident(p->sym->name));
10746 else if (is_stdqname(p->info.typ))
10747 fprintf(fout,"\n\tstd::string soap_tmp_%s(soap_QName2s(soap, a->%s.c_str()));", ident(p->sym->name), ident(p->sym->name));
10748 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10749 fprintf(fout,"\n\tconst char *soap_tmp_%s = a->%s ? soap_QName2s(soap, *a->%s) : NULL;", ident(p->sym->name), ident(p->sym->name), ident(p->sym->name));
10750 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10751 fprintf(fout,"\n\tstd::string soap_temp_%s(a->%s ? soap_QName2s(soap, a->%s->c_str()) : \"\"), *soap_tmp_%s = a->%s ? &soap_temp_%s : NULL;", ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name), ident(p->sym->name));
10752 }
10753 }
10754 if (is_primclass(typ))
10755 {
10756 for (t = table; t; t = t->prev)
10757 { p = t->list;
10758 if (p && is_item(p))
10759 break;
10760 }
10761 if ((p->info.sto & SmustUnderstand) && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && !is_transient(p->info.typ) && !is_void(p->info.typ) && p->info.typ->type != Tfun)
10762 fprintf(fout, "\n\tsoap->mustUnderstand = 1;");
10763 if (table->prev)
10764 {
10765 if (is_XML(p->info.typ) && is_string(p->info.typ))
10766 fprintf(fout,"\n\treturn soap_outliteral(soap, tag, &(a->%s::%s), \"%s\");", ident(t->sym->name), ident(p->sym->name), xsi_type(typ));
10767 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10768 fprintf(fout,"\n\treturn soap_outwliteral(soap, tag, &(a->%s::%s), \"%s\");", ident(t->sym->name), ident(p->sym->name), xsi_type(typ));
10769 else if(p->info.typ->type==Tarray)
10770 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, a->%s::%s, \"%s\");", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), xsi_type(typ));
10771 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10772 fprintf(fout,"\n\treturn (a->%s::%s).soap_out(soap, tag, id, \"%s\");", ident(t->sym->name), ident(p->sym->name), xsi_type(typ));
10773 else if (is_qname(p->info.typ))
10774 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)&soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type(typ));
10775 else if (is_stdqname(p->info.typ))
10776 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type(typ));
10777 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10778 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)&soap_tmp_%s, \"%s\");", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type_u(typ));
10779 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10780 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10781 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10782 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &(a->%s::%s), \"%s\");", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), xsi_type(typ));
10783 else
10784 fprintf(fout,"\n\treturn SOAP_OK;");
10785 }
10786 else
10787 { if (is_XML(p->info.typ) && is_string(p->info.typ))
10788 fprintf(fout,"\n\treturn soap_outliteral(soap, tag, &(a->%s::%s), NULL);", ident(t->sym->name), ident(p->sym->name));
10789 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10790 fprintf(fout,"\n\treturn soap_outwliteral(soap, tag, &(a->%s::%s), NULL);", ident(t->sym->name), ident(p->sym->name));
10791 else if(p->info.typ->type==Tarray)
10792 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, a->%s::%s, \"%s\");", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), xsi_type_u(typ));
10793 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10794 fprintf(fout,"\n\treturn (a->%s::%s).soap_out(soap, tag, id, \"%s\");", ident(t->sym->name), ident(p->sym->name), xsi_type_u(typ));
10795 else if (is_qname(p->info.typ))
10796 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)&soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10797 else if (is_stdqname(p->info.typ))
10798 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident(p->info.typ), ident(p->sym->name), xsi_type_u(typ));
10799 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10800 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, (char*const*)&soap_tmp_%s, \"%s\");", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type_u(typ));
10801 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10802 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &soap_tmp_%s, \"%s\");", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type_u(typ));
10803 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10804 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, &a->%s::%s, \"%s\");", c_ident(p->info.typ), ident(t->sym->name), ident(p->sym->name), xsi_type_u(typ));
10805 else
10806 fprintf(fout,"\n\treturn SOAP_OK;");
10807 }
10808 fprintf(fout,"\n}");
10809 }
10810 else
10811 { if (!is_invisible(typ->id->name))
10812 { if (table && table->prev)
10813 fprintf(fout,"\n\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, %s), \"%s\"))\n\t\treturn soap->error;", soap_type(typ), xsi_type(typ));
10814 else
10815 fprintf(fout,"\n\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, %s), type))\n\t\treturn soap->error;", soap_type(typ));
10816 }
10817 fflush(fout);
10818
10819 i=0;
10820 /* Get the depth of the inheritance hierarchy */
10821 for (t = table; t; t = t->prev)
10822 i++;
10823
10824 /* Call routines to output the member data of the class */
10825 /* Data members of the Base Classes are outputed first
10826 followed by the data members of the Derived classes.
10827 Overridden data members are output twice once for the base class
10828 they are defined in and once for the derived class that overwrites
10829 them */
10830
10831 for (; i > 0; i--)
10832 { Entry *e;
10833 char *nse1;
10834 t = table;
10835 for (j = 0; j< i-1; j++)
10836 t = t->prev;
10837 e = entry(classtable, t->sym);
10838 nse1 = e ? ns_qualifiedElement(e->info.typ) : nse;
10839 for (p = t->list; p != (Entry*) 0; p = p->next)
10840 { if (p->info.sto & Sreturn)
10841 { if (nse1 || has_ns_eq(NULL, p->sym->name))
10842 { if (p->info.typ->type == Tpointer)
10843 fprintf(fout,"\n\tif (a->%s)\n\t\tsoap_element_result(soap, \"%s\");", ident(p->sym->name), ns_add(p, nse1));
10844 else
10845 fprintf(fout,"\n\tsoap_element_result(soap, \"%s\");", ns_add(p, nse1));
10846 }
10847 }
10848 if ((p->info.sto & SmustUnderstand) && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && !is_transient(p->info.typ) && !is_void(p->info.typ) && p->info.typ->type != Tfun)
10849 fprintf(fout, "\n\tsoap->mustUnderstand = 1;");
10850 needs_lang(p);
10851 if (is_item(p))
10852 ;
10853 else if (p->info.sto & (Sconst | Sprivate | Sprotected))
10854 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
10855 else if (is_transient(p->info.typ))
10856 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
10857 else if (p->info.sto & Sattribute)
10858 ;
10859 else if (is_repetition(p))
10860 { fprintf(fout,"\n\tif (a->%s::%s)", ident(t->sym->name), ident(p->next->sym->name));
10861 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < a->%s::%s; i++)", ident(t->sym->name), ident(p->sym->name));
10862 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
10863 fprintf(fout,"\n\t\t\tif (a->%s::%s[i].soap_out(soap, %s, -1, \"%s\"))\n\t\t\t\treturn soap->error;", ident(t->sym->name), ident(p->next->sym->name), field_overridden(t, p->next, nse1),xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10864 else if (is_qname((Tnode*)p->next->info.typ->ref))
10865 fprintf(fout,"\n\t\t{\tconst char *soap_tmp_%s = soap_QName2s(soap, a->%s[i]);\n\t\t\tif (soap_out_%s(soap, %s, -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\t\t\treturn soap->error;\n\t\t}", ident(p->next->sym->name), ident(p->next->sym->name), c_ident((Tnode*)p->next->info.typ->ref), field_overridden(t, p->next, nse1), ident(p->next->sym->name), xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10866 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
10867 fprintf(fout,"\n\t\t\tsoap_outliteral(soap, %s, a->%s::%s + i, NULL);", field_overridden(t, p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
10868 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
10869 fprintf(fout,"\n\t\t\tsoap_outwliteral(soap, %s, a->%s::%s + i, NULL);", field_overridden(t, p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
10870 else
10871 fprintf(fout,"\n\t\t\tif (soap_out_%s(soap, %s, -1, a->%s::%s + i, \"%s\"))\n\t\t\t\treturn soap->error;", c_ident((Tnode*)p->next->info.typ->ref), field_overridden(t, p->next, nse1), ident(t->sym->name), ident(p->next->sym->name), xsi_type_cond_u((Tnode*)p->next->info.typ->ref, !has_ns_eq(NULL, p->next->sym->name)));
10872 fprintf(fout,"\n\t}");
10873 p = p->next;
10874 }
10875 else if (is_anytype(p) && is_invisible(p->next->sym->name))
10876 { fprintf(fout,"\n\tif (soap_putelement(soap, a->%s::%s, tag, -1, a->%s::%s))\n\t\treturn soap->error;", ident(t->sym->name), ident(p->next->sym->name), ident(t->sym->name), ident(p->sym->name));
10877 p = p->next;
10878 }
10879 else if (is_anytype(p))
10880 { fprintf(fout,"\n\tif (soap_putelement(soap, a->%s::%s, %s, -1, a->%s::%s))\n\t\treturn soap->error;", ident(t->sym->name), ident(p->next->sym->name), field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name));
10881 p = p->next;
10882 }
10883 else if (is_choice(p))
10884 { fprintf(fout,"\n\tif (soap_out_%s(soap, a->%s::%s, &a->%s::%s))\n\t\treturn soap->error;", c_ident(p->next->info.typ), ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name));
10885 p = p->next;
10886 }
10887 else if (p->info.typ->type==Tarray)
10888 fprintf(fout,"\n\tsoap_out_%s(soap, %s, -1, a->%s::%s, \"%s\");", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10889 else if (p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10890 fprintf(fout,"\n\tif ((a->%s::%s).soap_out(soap, %s, -1, \"%s\"))\n\t\treturn soap->error;", ident(t->sym->name), ident(p->sym->name), field_overridden(t, p, nse1),xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10891 else if (is_qname(p->info.typ))
10892 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10893 else if (is_stdqname(p->info.typ))
10894 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10895 else if (p->info.typ->type == Tpointer && is_qname((Tnode*)p->info.typ->ref))
10896 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, (char*const*)&soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident((Tnode*)p->info.typ->ref), field_overridden(t, p, nse1), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10897 else if (p->info.typ->type == Tpointer && is_stdqname((Tnode*)p->info.typ->ref))
10898 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &soap_tmp_%s, \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ), field_overridden(t, p, nse1), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10899 else if (is_XML(p->info.typ) && is_string(p->info.typ))
10900 fprintf(fout,"\n\tsoap_outliteral(soap, %s, &(a->%s::%s), NULL);", field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name));
10901 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10902 fprintf(fout,"\n\tsoap_outwliteral(soap, %s, &(a->%s::%s), NULL);", field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name));
10903 else if (p->info.typ->type == Tpointer && !is_void(p->info.typ) && p->info.minOccurs > 0)
10904 fprintf(fout,"\n\tif (a->%s::%s)\n\t{\tif (soap_out_%s(soap, %s, -1, &a->%s::%s, \"%s\"))\n\t\t\treturn soap->error;\n\t}\n\telse if (soap_element_nil(soap, %s))\n\t\treturn soap->error;", ident(t->sym->name), ident(p->sym->name), c_ident(p->info.typ), field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)), field_overridden(t, p, nse1));
10905 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10906 fprintf(fout,"\n\tif (soap_out_%s(soap, %s, -1, &(a->%s::%s), \"%s\"))\n\t\treturn soap->error;", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10907 fflush(fout);
10908 }
10909 }
10910 if (!is_invisible(typ->id->name))
10911 fprintf(fout,"\n\treturn soap_element_end_out(soap, tag);\n}");
10912 else
10913 fprintf(fout,"\n\treturn SOAP_OK;\n}");
10914 }
10915 fflush(fout);
10916 break;
10917
10918 case Tunion:
10919 if (is_external(typ))
10920 { fprintf(fhead, "\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, int, const %s);", c_ident(typ), c_type_id(typ, "*"));
10921 return;
10922 }
10923 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, int, const %s);", c_ident(typ), c_type_id(typ, "*"));
10924 fprintf(fout, "\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, int choice, const %s)\n{", c_ident(typ), c_type_id(typ, "*a"));
10925 table = (Table*)typ->ref;
10926 fprintf(fout, "\n\tswitch (choice)\n\t{");
10927 for (p = table->list; p; p = p->next)
10928 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
10929 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
10930 else if (is_transient(p->info.typ))
10931 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
10932 else if (p->info.sto & Sattribute)
10933 ;
10934 else if (is_repetition(p))
10935 ;
10936 else if (is_anytype(p))
10937 ;
10938 else if (p->info.typ->type == Tarray)
10939 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10940 fprintf(fout, "\n\t\treturn soap_out_%s(soap, \"%s\", -1, a->%s, \"%s\");", c_ident(p->info.typ), ns_add(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10941 }
10942 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
10943 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10944 fprintf(fout, "\n\t\treturn a->%s.soap_out(soap, \"%s\", -1, \"%s\");", ident(p->sym->name), ns_add(p, nse), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10945 }
10946 else if (is_qname(p->info.typ) || is_stdqname(p->info.typ))
10947 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10948 fprintf(fout,"\n\t{\tconst char *soap_tmp_%s = soap_QName2s(soap, a->%s);", ident(p->sym->name), ident(p->sym->name));
10949 fprintf(fout,"\n\t\treturn soap_out_%s(soap, \"%s\", -1, (char*const*)&soap_tmp_%s, \"%s\");\n\t}", c_ident(p->info.typ),ns_add(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10950 }
10951 else if (is_XML(p->info.typ) && is_string(p->info.typ))
10952 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10953 fprintf(fout,"\n\t\treturn soap_outliteral(soap, \"%s\", &a->%s, NULL);", ns_add(p, nse), ident(p->sym->name));
10954 }
10955 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
10956 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10957 fprintf(fout,"\n\t\treturn soap_outwliteral(soap, \"%s\", &a->%s, NULL);", ns_add(p, nse), ident(p->sym->name));
10958 }
10959 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
10960 { fprintf(fout, "\n\tcase SOAP_UNION_%s_%s:", c_ident(typ), ident(p->sym->name));
10961 fprintf(fout,"\n\t\treturn soap_out_%s(soap, \"%s\", -1, &a->%s, \"%s\");", c_ident(p->info.typ),ns_add(p, nse), ident(p->sym->name), xsi_type_cond_u(p->info.typ, !has_ns_eq(NULL, p->sym->name)));
10962 }
10963 }
10964 fprintf(fout, "\n\tdefault:\n\t\tbreak;\n\t}\n\treturn SOAP_OK;\n}");
10965 fflush(fout);
10966 break;
10967
10968 case Tpointer:
10969 if (is_external(typ))
10970 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char *, int, %s, const char *);", c_ident(typ),c_type_id(typ, "const*"));
10971 return;
10972 }
10973 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char *, int, %s, const char *);", c_ident(typ),c_type_id(typ, "const*"));
10974 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, %s, const char *type)\n{", c_ident(typ),c_type_id(typ, "const*a"));
10975 if (is_template(typ))
10976 { fprintf(fout,"\n\tif (!*a)");
10977 fprintf(fout,"\n\t\treturn soap_element_null(soap, tag, id, type);");
10978 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, *a, type);", c_ident((Tnode*)typ->ref));
10979 }
10980 else
10981 { p = is_dynamic_array((Tnode*)typ->ref);
10982 if (p)
10983 { d = get_Darraydims((Tnode*)typ->ref);
10984 if (d)
10985 fprintf(fout,"\n\tid = soap_element_id(soap, tag, id, *a, (struct soap_array*)&(*a)->%s, %d, type, %s);", ident(p->sym->name), d, soap_type((Tnode*)typ->ref));
10986 else
10987 fprintf(fout,"\n\tid = soap_element_id(soap, tag, id, *a, (struct soap_array*)&(*a)->%s, 1, type, %s);", ident(p->sym->name), soap_type((Tnode*)typ->ref));
10988 }
10989 else
10990 fprintf(fout,"\n\tid = soap_element_id(soap, tag, id, *a, NULL, 0, type, %s);", soap_type((Tnode*)typ->ref));
10991 fprintf(fout,"\n\tif (id < 0)\n\t\treturn soap->error;");
10992 if (((Tnode *) typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
10993 fprintf(fout,"\n\treturn (*a)->soap_out(soap, tag, id, type);");
10994 else
10995 fprintf(fout,"\n\treturn soap_out_%s(soap, tag, id, *a, type);",c_ident((Tnode*)typ->ref));
10996 }
10997 fprintf(fout,"\n}");
10998 break;
10999
11000 case Tarray:
11001 if (is_external(typ))
11002 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, %s, const char*);", c_ident(typ),c_type_id(typ, "const"));
11003 return;
11004 }
11005 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, %s, const char*);", c_ident(typ),c_type_id(typ, "const"));
11006 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, %s, const char *type)\n{", c_ident(typ),c_type_id(typ, "const a"));
11007 fprintf(fout,"\n\tint i;");
11008 fprintf(fout,"\n\tsoap_array_begin_out(soap, tag, soap_embedded_id(soap, id, a, %s), \"%s[%d]\", 0);", soap_type(typ), xsi_type_Tarray(typ), get_dimension(typ));
11009 n=(Tnode*)typ->ref;
11010 cardinality = 1;
11011 while(n->type==Tarray)
11012 {
11013 n=(Tnode*)n->ref;
11014 cardinality++;
11015 }
11016
11017 fprintf(fout,"\n\tfor (i = 0; i < %d; i++)\n\t{",get_dimension(typ));
11018 if (((Tnode *)typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
11019 { if(cardinality>1)
11020 fprintf(fout,"\n\t\ta[i].soap_out(soap, \"item\", -1, \"%s\")", xsi_type_u((Tnode*)typ->ref));
11021 else fprintf(fout,"\n\t\t(a+i)->soap_out(soap, \"item\", -1, \"%s\")", xsi_type_u((Tnode*)typ->ref));
11022 }
11023 else
11024 { if(((Tnode *)typ->ref)->type != Tarray)
11025 { if(((Tnode *)typ->ref)->type == Tpointer)
11026 fprintf(fout,"\n\t\tsoap->position = 1;\n\t\tsoap->positions[0] = i;\n\t\tsoap_out_%s(soap, \"item\", -1, a", c_ident((Tnode*)typ->ref));
11027 else
11028 fprintf(fout,"\n\t\tsoap_out_%s(soap, \"item\", -1, a",c_ident((Tnode*)typ->ref));
11029 }
11030 else
11031 fprintf(fout,"\n\t\tsoap_out_%s(soap, \"item\", -1, a",c_ident((Tnode*)typ->ref));
11032 if(cardinality>1)
11033 fprintf(fout,"[i], \"%s\")", xsi_type_u((Tnode*)typ->ref));
11034 else
11035 fprintf(fout,"+i, \"%s\")", xsi_type_u((Tnode*)typ->ref));
11036 }
11037 if(((Tnode *)typ->ref)->type == Tpointer)
11038 fprintf(fout,";\n\t}\n\tsoap->position = 0;\n\treturn soap_element_end_out(soap, tag);\n}");
11039 else
11040 fprintf(fout,";\n\t}\n\treturn soap_element_end_out(soap, tag);\n}");
11041 break;
11042
11043 case Tenum:
11044 if (is_external(typ))
11045 { fprintf(fhead, "\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ), c_type_id(typ, "*"));
11046 return;
11047 }
11048 fprintf(fhead, "\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ), c_type_id(typ, "*"));
11049 if (!is_typedef(typ))
11050 { fprintf(fout, "\n\nstatic const struct soap_code_map soap_codes_%s[] =\n{", c_ident(typ));
11051 for (t = (Table*)typ->ref; t; t = t->prev)
11052 { for (p = t->list; p; p = p->next)
11053 fprintf(fout, "\t{ (long)%s, \"%s\" },\n", ident(p->sym->name), ns_remove2(p->sym->name));
11054 }
11055 fprintf(fout, "\t{ 0, NULL }\n");
11056 fprintf(fout, "};");
11057 }
11058 fprintf(fhead, "\n\nSOAP_FMAC3S const char* SOAP_FMAC4S soap_%s2s(struct soap*, %s);", c_ident(typ), c_type(typ));
11059 fprintf(fout, "\n\nSOAP_FMAC3S const char* SOAP_FMAC4S soap_%s2s(struct soap *soap, %s)", c_ident(typ), c_type_id(typ, "n"));
11060 if (is_typedef(typ))
11061 fprintf(fout, "\n{\treturn soap_%s2s(soap, n);\n}", t_ident(typ));
11062 else if (is_boolean(typ))
11063 fprintf(fout, "\n{\n\t(void)soap; /* appease -Wall -Werror */\nreturn soap_code_str(soap_codes_%s, n!=0);\n}", c_ident(typ));
11064 else if (!is_mask(typ))
11065 { fprintf(fout, "\n{\tconst char *s = soap_code_str(soap_codes_%s, (long)n);", c_ident(typ));
11066 fprintf(fout, "\n\tif (s)\n\t\treturn s;");
11067 fprintf(fout, "\n\treturn soap_long2s(soap, (long)n);");
11068 fprintf(fout, "\n}");
11069 }
11070 else
11071 fprintf(fout, "\n{\n\treturn soap_code_list(soap, soap_codes_%s, (long)n);\n}", c_ident(typ));
11072 fprintf(fout, "\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)", c_ident(typ), c_type_id(typ, "*a"));
11073 fprintf(fout, "\n{\tif (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, %s), type)", soap_type(typ));
11074 fprintf(fout, " || soap_send(soap, soap_%s2s(soap, *a)))\n\t\treturn soap->error;", c_ident(typ));
11075 fprintf(fout, "\n\treturn soap_element_end_out(soap, tag);\n}");
11076 break;
11077 case Ttemplate:
11078 if (is_external(typ))
11079 { fprintf(fhead,"\nSOAP_FMAC1 int SOAP_FMAC2 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
11080 return;
11081 }
11082 if (is_typedef(typ))
11083 { fprintf(fhead, "\n\n#define soap_out_%s soap_out_%s\n", c_ident(typ), t_ident(typ));
11084 return;
11085 }
11086 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
11087 n = typ->ref;
11088 if (!n)
11089 return;
11090 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)\n{", c_ident(typ),c_type_id(typ, "*a"));
11091
11092 fprintf(fout, "\n\tfor (%s::const_iterator i = a->begin(); i != a->end(); ++i)\n\t{", c_type(typ));
11093 if (n->type==Tarray)
11094 fprintf(fout,"\n\t\tif (soap_out_%s(soap, tag, id, *i, \"%s\"))", c_ident(n), xsi_type_u(typ));
11095 else if (n->type==Tclass && !is_external(n) && !is_volatile(n) && !is_typedef(n))
11096 fprintf(fout,"\n\t\tif ((*i).soap_out(soap, tag, id, \"%s\"))", xsi_type_u(typ));
11097 else if (is_qname(n))
11098 fprintf(fout,"\n\t\tconst char *soap_tmp = soap_QName2s(soap, *i);\n\t\tif (soap_out_%s(soap, tag, id, (char*const*)&soap_tmp, \"%s\"))", c_ident(n), xsi_type_u(typ));
11099 else if (is_stdqname(n))
11100 fprintf(fout,"\n\t\tstd::string soap_tmp(soap_QName2s(soap, (*i).c_str()));\n\t\tif (soap_out_%s(soap, tag, id, &soap_tmp, \"%s\"))", c_ident(n), xsi_type_u(typ));
11101 else if (is_XML(n) && is_string(n))
11102 fprintf(fout,"\n\t\tif (soap_outliteral(soap, tag, &(*i), NULL))");
11103 else if (is_XML(n) && is_wstring(n))
11104 fprintf(fout,"\n\t\tif (soap_outwliteral(soap, tag, &(*i), NULL))");
11105 else if (n->type == Tenum && (Table*)n->ref == booltable)
11106 fprintf(fout,"\n\t\tbool b = (*i);\n\t\tif (soap_out_%s(soap, tag, id, &b, \"%s\"))", c_ident(n), xsi_type_u(typ));
11107 else
11108 fprintf(fout,"\n\t\tif (soap_out_%s(soap, tag, id, &(*i), \"%s\"))", c_ident(n), xsi_type_u(typ));
11109 fprintf(fout, "\n\t\t\treturn soap->error;");
11110 fprintf(fout, "\n\t}\n\treturn SOAP_OK;\n}");
11111 break;
11112 default: break;
11113 }
11114 }
11115
11116 void
11117 soap_out_Darray(Tnode *typ)
11118 { int i, j, d = 0;
11119 Table *t, *table;
11120 Entry *p;
11121 char *nse = ns_qualifiedElement(typ);
11122 char *nsa = ns_qualifiedAttribute(typ);
11123 char *item;
11124
11125 table=(Table*)typ->ref;
11126 fprintf(fhead,"\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap*, const char*, int, const %s, const char*);", c_ident(typ),c_type_id(typ, "*"));
11127 if (is_external(typ))
11128 return;
11129 if (typ->type == Tclass && !is_volatile(typ) && !is_typedef(typ))
11130 { fprintf(fout,"\n\nint %s::soap_out(struct soap *soap, const char *tag, int id, const char *type) const", c_type(typ));
11131 fprintf(fout,"\n{\treturn soap_out_%s(soap, tag, id, this, type);\n}", c_ident(typ));
11132 }
11133 fflush(fout);
11134 fprintf(fout,"\n\nSOAP_FMAC3 int SOAP_FMAC4 soap_out_%s(struct soap *soap, const char *tag, int id, const %s, const char *type)\n{", c_ident(typ),c_type_id(typ, "*a"));
11135 if (has_setter(typ))
11136 fprintf(fout, "\n\t((%s)a)->set(soap);", c_type_id(typ, "*"));
11137 if (!is_binary(typ))
11138 { d = get_Darraydims(typ);
11139 if (d)
11140 fprintf(fout,"\n\tint i, n = soap_size(a->__size, %d);", d);
11141 else
11142 fprintf(fout,"\n\tint i, n = a->__size;");
11143 }
11144 if (typ->type == Tclass)
11145 { for (t = table; t; t = t->prev)
11146 { for (p = t->list; p; p = p->next)
11147 { if (p->info.sto & Sattribute)
11148 soap_set_attr(p, ptr_cast(t, "a"), ident(p->sym->name), ns_add(p, nsa));
11149 }
11150 }
11151 }
11152 else
11153 { for (t = table; t; t = t->prev)
11154 { for (p = t->list; p; p = p->next)
11155 { if (p->info.sto & Sattribute)
11156 soap_set_attr(p, "a", ident(p->sym->name), ns_add(p, nsa));
11157 }
11158 }
11159 }
11160 p = is_dynamic_array(typ);
11161 if (p->sym->name[5])
11162 item = ns_addx(p->sym->name + 5, nse);
11163 else
11164 item = ns_addx("item", nse);
11165 if (!has_ns(typ) && !is_untyped(typ) && !is_binary(typ))
11166 { if (is_untyped(p->info.typ))
11167 { if (has_offset(typ))
11168 if (d)
11169 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsizesoffsets(soap, \"%s\", a->__size, a->__offset, %d) : NULL;", ident(p->sym->name), wsdl_type(p->info.typ, "xsd"), d);
11170 else
11171 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsize(soap, \"%s\", n + a->__offset) : NULL;", ident(p->sym->name), wsdl_type(p->info.typ, "xsd"));
11172 else if (d)
11173 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsizes(soap, \"%s\", a->__size, %d) : NULL;", ident(p->sym->name), wsdl_type(p->info.typ, "xsd"), d);
11174 else
11175 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsize(soap, \"%s\", n) : NULL;", ident(p->sym->name), wsdl_type(p->info.typ, "xsd"));
11176 }
11177 else
11178 { if (has_offset(typ))
11179 if (d)
11180 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsizesoffsets(soap, \"%s\", a->__size, a->__offset, %d) : NULL;", ident(p->sym->name), xsi_type(typ), d);
11181 else
11182 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsize(soap, \"%s\", n + a->__offset) : NULL;", ident(p->sym->name), xsi_type(typ));
11183 else if (d)
11184 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsizes(soap, \"%s\", a->__size, %d) : NULL;", ident(p->sym->name), xsi_type(typ),d);
11185 else
11186 fprintf(fout,"\n\tchar *t = a->%s ? soap_putsize(soap, \"%s\", a->__size) : NULL;", ident(p->sym->name), xsi_type(typ));
11187 }
11188 }
11189 if (d)
11190 fprintf(fout,"\n\tid = soap_element_id(soap, tag, id, a, (struct soap_array*)&a->%s, %d, type, %s);", ident(p->sym->name), d, soap_type(typ));
11191 else if (is_attachment(typ))
11192 { fprintf(fout,"\n#ifndef WITH_LEANER\n\tid = soap_attachment(soap, tag, id, a, (struct soap_array*)&a->%s, a->id, a->type, a->options, 1, type, %s);", ident(p->sym->name), soap_type(typ));
11193 fprintf(fout,"\n#else\n\tid = soap_element_id(soap, tag, id, a, (struct soap_array*)&a->%s, 1, type, %s);\n#endif", ident(p->sym->name), soap_type(typ));
11194 }
11195 else
11196 fprintf(fout,"\n\tid = soap_element_id(soap, tag, id, a, (struct soap_array*)&a->%s, 1, type, %s);", ident(p->sym->name), soap_type(typ));
11197 fprintf(fout,"\n\tif (id < 0)\n\t\treturn soap->error;");
11198 fprintf(fout,"\n\tif (");
11199 if (has_ns(typ) || is_untyped(typ) || is_binary(typ))
11200 { if (table->prev)
11201 fprintf(fout,"soap_element_begin_out(soap, tag, id, \"%s\")", xsi_type(typ));
11202 else
11203 fprintf(fout,"soap_element_begin_out(soap, tag, id, type)");
11204 }
11205 else if (has_offset(typ))
11206 { if (d)
11207 fprintf(fout,"soap_array_begin_out(soap, tag, id, t, soap_putoffsets(soap, a->__offset, %d))", d);
11208 else
11209 fprintf(fout,"soap_array_begin_out(soap, tag, id, t, soap_putoffset(soap, a->__offset))");
11210 }
11211 else
11212 fprintf(fout,"soap_array_begin_out(soap, tag, id, t, NULL)");
11213 fprintf(fout, ")\n\t\treturn soap->error;");
11214 if (is_binary(typ) && !is_hexBinary(typ))
11215 fprintf(fout, "\n\tif (soap_putbase64(soap, a->__ptr, a->__size))\n\t\treturn soap->error;");
11216 else if (is_hexBinary(typ))
11217 fprintf(fout, "\n\tif (soap_puthex(soap, a->__ptr, a->__size))\n\t\treturn soap->error;");
11218 else
11219 { fprintf(fout,"\n\tfor (i = 0; i < n; i++)\n\t{");
11220 if (!has_ns(typ) && !is_untyped(typ))
11221 { if (d)
11222 { fprintf(fout,"\n\t\tsoap->position = %d;", d);
11223 for (i = 0; i < d; i++)
11224 { fprintf(fout, "\n\t\tsoap->positions[%d] = i", i);
11225 for (j = i+1; j < d; j++)
11226 fprintf(fout, "/a->__size[%d]", j);
11227 fprintf(fout, "%%a->__size[%d];", i);
11228 }
11229 if (is_XML((Tnode*)p->info.typ->ref) && is_string((Tnode*)p->info.typ->ref))
11230 fprintf(fout,"\n\t\tsoap_outliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11231 else if (is_XML((Tnode*)p->info.typ->ref) && is_wstring((Tnode*)p->info.typ->ref))
11232 fprintf(fout,"\n\t\tsoap_outwliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11233 else if (((Tnode *)p->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
11234 fprintf(fout,"\n\t\ta->%s[i].soap_out(soap, \"item\", -1, \"%s\");", ident(p->sym->name), xsi_type_u(((Tnode *)p->info.typ->ref)));
11235 else
11236 fprintf(fout, "\n\t\tsoap_out_%s(soap, \"%s\", -1, &a->%s[i], \"%s\");",c_ident(((Tnode *)p->info.typ->ref)), item, ident(p->sym->name), xsi_type_u(((Tnode *)p->info.typ->ref)));
11237 }
11238 else
11239 { fprintf(fout,"\n\t\tsoap->position = 1;\n\t\tsoap->positions[0] = i;");
11240 if (is_XML((Tnode*)p->info.typ->ref) && is_string((Tnode*)p->info.typ->ref))
11241 fprintf(fout,"\n\t\tsoap_outliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11242 else if (is_XML((Tnode*)p->info.typ->ref) && is_wstring((Tnode*)p->info.typ->ref))
11243 fprintf(fout,"\n\t\tsoap_outwliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11244 else if (((Tnode *)p->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
11245 fprintf(fout,"\n\t\ta->%s[i].soap_out(soap, \"%s\", -1, \"%s\");", ident(p->sym->name), item, xsi_type_u(((Tnode *)p->info.typ->ref)));
11246 else
11247 fprintf(fout,"\n\t\tsoap_out_%s(soap, \"%s\", -1, &a->%s[i], \"%s\");",c_ident(((Tnode *)p->info.typ->ref)), item, ident(p->sym->name), xsi_type_u(((Tnode *)p->info.typ->ref)));
11248 }
11249 }
11250 else
11251 { if (is_XML((Tnode*)p->info.typ->ref) && is_string((Tnode*)p->info.typ->ref))
11252 fprintf(fout,"\n\t\tsoap_outliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11253 else if (is_XML((Tnode*)p->info.typ->ref) && is_wstring((Tnode*)p->info.typ->ref))
11254 fprintf(fout,"\n\t\tsoap_outwliteral(soap, \"%s\", &a->%s[i], NULL);", item, ident(p->sym->name));
11255 else if (((Tnode *)p->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
11256 fprintf(fout,"\n\t\ta->%s[i].soap_out(soap, \"%s\", -1, \"%s\");", ident(p->sym->name), item, xsi_type_u(((Tnode *)p->info.typ->ref)));
11257 else
11258 fprintf(fout,"\n\t\tsoap_out_%s(soap, \"%s\", -1, &a->%s[i], \"%s\");",c_ident(((Tnode *)p->info.typ->ref)), item, ident(p->sym->name), xsi_type_u(((Tnode *)p->info.typ->ref)));
11259 }
11260 }
11261 if (is_binary(typ))
11262 fprintf(fout,"\n\treturn soap_element_end_out(soap, tag);\n}");
11263 else if (!has_ns(typ) && !is_untyped(typ))
11264 fprintf(fout,"\n\t}\n\tsoap->position = 0;\n\treturn soap_element_end_out(soap, tag);\n}");
11265 else
11266 fprintf(fout,"\n\t}\n\treturn soap_element_end_out(soap, tag);\n}");
11267 }
11268
11269 void
11270 soap_get(Tnode *typ)
11271 {
11272 Tnode *temp;
11273
11274 if (typ->type == Ttemplate || typ->type == Tunion)
11275 return;
11276
11277 if (is_typedef(typ) && is_element(typ))
11278 { fprintf(fhead, "\n\n#define soap_get_%s soap_get_%s\n", c_ident(typ), t_ident(typ));
11279 return;
11280 }
11281
11282 if(typ->type==Tarray)
11283 {
11284 /* ARRAY */
11285 temp = typ;
11286 while(temp->type == Tarray){
11287 temp = (Tnode*)temp->ref;
11288 }
11289 fprintf(fhead,"\nSOAP_FMAC3 %s * SOAP_FMAC4 soap_get_%s(struct soap*, %s, const char*, const char*);", c_type(temp),c_ident(typ),c_type(typ));
11290 fprintf(fout,"\n\nSOAP_FMAC3 %s * SOAP_FMAC4 soap_get_%s(struct soap *soap, %s, const char *tag, const char *type)", c_type(temp),c_ident(typ),c_type_id(typ, "a"));
11291 fprintf(fout,"\n{\t%s;",c_type_id(temp, "(*p)"));
11292 fprintf(fout,"\n\tif ((p = soap_in_%s(soap, tag, a, type)))", c_ident(typ));
11293 }
11294 else if (typ->type==Tclass && !is_external(typ) && !is_volatile(typ) && !is_typedef(typ))
11295 {
11296 /* CLASS */
11297 fprintf(fout,"\n\nvoid *%s::soap_get(struct soap *soap, const char *tag, const char *type)", c_type(typ));
11298 fprintf(fout,"\n{\n\treturn soap_get_%s(soap, this, tag, type);\n}", c_ident(typ));
11299 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_get_%s(struct soap*, %s, const char*, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11300 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_get_%s(struct soap *soap, %s, const char *tag, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*p"));
11301 fprintf(fout,"\n\tif ((p = soap_in_%s(soap, tag, p, type)))", c_ident(typ));
11302 }
11303 else
11304 {
11305 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_get_%s(struct soap*, %s, const char*, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11306 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_get_%s(struct soap *soap, %s, const char *tag, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*p"));
11307 fprintf(fout,"\n\tif ((p = soap_in_%s(soap, tag, p, type)))", c_ident(typ));
11308 }
11309 fprintf(fout,"\n\t\tif (soap_getindependent(soap))\n\t\t\treturn NULL;");
11310 fprintf(fout,"\n\treturn p;\n}");
11311 #if 0
11312 /* some compilers cannot handle this inlined function */
11313 if (typ->type != Treference)
11314 fprintf(fhead, "\n\ninline int soap_read_%s(struct soap *soap, %s) { if (soap_begin_recv(soap) || !soap_get_%s(soap, p, NULL, NULL) || soap_end_recv(soap)) return soap->error; return SOAP_OK; }\n", c_ident(typ), c_type_id(typ, "*p"), c_ident(typ));
11315 #endif
11316 if (typ->type != Treference)
11317 { if (((!is_external(typ) && !is_volatile(typ)) || Qflag) && namespaceid)
11318 fprintf(fhead, "\n\n#ifndef soap_read_%s\n#define soap_read_%s(soap, data) ( soap_begin_recv(soap) || !%s::soap_get_%s(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), namespaceid, c_ident(typ));
11319 else
11320 fprintf(fhead, "\n\n#ifndef soap_read_%s\n#define soap_read_%s(soap, data) ( soap_begin_recv(soap) || !soap_get_%s(soap, data, NULL, NULL) || soap_end_recv(soap), (soap)->error )\n#endif\n", c_ident(typ), c_ident(typ), c_ident(typ));
11321 }
11322 fflush(fout);
11323 }
11324
11325 void
11326 soap_in(Tnode *typ)
11327 { Entry *p = NULL;
11328 Table *table, *t;
11329 int total, a, f, cardinality, i, j;
11330 long min, max;
11331 Tnode *n, *temp;
11332 char *nse = ns_qualifiedElement(typ);
11333 char *nsa = ns_qualifiedAttribute(typ);
11334
11335 if (is_dynamic_array(typ))
11336 { soap_in_Darray(typ);
11337 return;
11338 }
11339
11340 if (is_external(typ))
11341 fprintf(fhead,"\n\nSOAP_FMAC3S int SOAP_FMAC4S soap_s2%s(struct soap*, const char*, %s);",c_ident(typ),c_type_id(typ, "*"));
11342
11343 if (is_typedef(typ) && is_element(typ) && !is_external(typ))
11344 { fprintf(fhead, "\n\n#define soap_in_%s soap_in_%s\n", c_ident(typ), t_ident(typ));
11345 return;
11346 }
11347
11348 if (is_primitive_or_string(typ) && typ->type != Tenum)
11349 {
11350 if (is_stdqname(typ))
11351 { fprintf(fhead,"\nSOAP_FMAC3 std::string * SOAP_FMAC4 soap_in_%s(struct soap*, const char*, std::string*, const char*);", c_ident(typ));
11352 fprintf(fout,"\n\nSOAP_FMAC1 std::string * SOAP_FMAC2 soap_in_%s(struct soap *soap, const char *tag, std::string *s, const char *type)\n{\n\tif (soap_element_begin_in(soap, tag, 1, type))\n\t\treturn NULL;\n\tif (!s)\n\t\ts = soap_new_std__string(soap, -1);\n\tif (soap->null)\n\t\tif (s)\n\t\t\ts->erase();", c_ident(typ));
11353 fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{\tchar *t;\n\t\ts = (std::string*)soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::string), soap->type, soap->arrayType);\n\t\tif (s)\n\t\t{\tif (!(t = soap_string_in(soap, 2, %ld, %ld)))\n\t\t\t\treturn NULL;\n\t\t\ts->assign(t);\n\t\t}\n\t}\n\telse\n\t\ts = (std::string*)soap_id_forward(soap, soap->href, soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::string), soap->type, soap->arrayType), 0, %s, 0, sizeof(std::string), 0, soap_copy_%s);\n\tif (soap->body && soap_element_end_in(soap, tag))\n\t\treturn NULL;\n\treturn s;\n}", soap_type(typ), minlen(typ), maxlen(typ), soap_type(typ), soap_type(typ), c_ident(typ));
11354 return;
11355 }
11356 if (is_stdstring(typ))
11357 { if (is_external(typ))
11358 { fprintf(fhead,"\nSOAP_FMAC1 std::string * SOAP_FMAC2 soap_in_%s(struct soap*, const char*, std::string*, const char*);", c_ident(typ));
11359 return;
11360 }
11361 fprintf(fhead,"\nSOAP_FMAC3 std::string * SOAP_FMAC4 soap_in_%s(struct soap*, const char*, std::string*, const char*);", c_ident(typ));
11362 if (is_stdXML(typ))
11363 fprintf(fout,"\n\nSOAP_FMAC3 std::string * SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, std::string *s, const char *type)\n{\n\tchar *t;\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_inliteral(soap, tag, &t))\n\t{\tif (!s)\n\t\t\ts = soap_new_std__string(soap, -1);\n\t\ts->assign(t);\n\t\treturn s;\n\t}\n\treturn NULL;\n}", c_ident(typ));
11364 else
11365 { fprintf(fout,"\n\nSOAP_FMAC3 std::string * SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, std::string *s, const char *type)\n{\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\treturn NULL;\n\tif (!s)\n\t\ts = soap_new_std__string(soap, -1);\n\tif (soap->null)\n\t\tif (s)\n\t\t\ts->erase();", c_ident(typ));
11366 fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{\tchar *t;\n\t\ts = (std::string*)soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::string), soap->type, soap->arrayType);\n\t\tif (s)\n\t\t{\tif (!(t = soap_string_in(soap, 1, %ld, %ld)))\n\t\t\t\treturn NULL;\n\t\t\ts->assign(t);\n\t\t}\n\t}\n\telse\n\t\ts = (std::string*)soap_id_forward(soap, soap->href, soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::string), soap->type, soap->arrayType), 0, %s, 0, sizeof(std::string), 0, soap_copy_%s);\n\tif (soap->body && soap_element_end_in(soap, tag))\n\t\treturn NULL;\n\treturn s;\n}", soap_type(typ), minlen(typ), maxlen(typ), soap_type(typ), soap_type(typ), c_ident(typ));
11367 }
11368 return;
11369 }
11370 if (is_stdwstring(typ))
11371 { if (is_external(typ))
11372 { fprintf(fhead,"\nSOAP_FMAC3 std::wstring * SOAP_FMAC4 soap_in_%s(struct soap*, const char*, std::wstring*, const char*);", c_ident(typ));
11373 return;
11374 }
11375 if (is_stdXML(typ))
11376 fprintf(fout,"\n\nSOAP_FMAC3 std::wstring * SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, std::wstring *s, const char *type)\n{\n\twchar_t *t;\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_inwliteral(soap, tag, &t))\n\t{\tif (!s)\n\t\t\ts = soap_new_std__wstring(soap, -1);\n\t\ts->assign(t);\n\t\treturn s;\n\t}\n\treturn NULL;\n}", c_ident(typ));
11377 else
11378 { fprintf(fhead,"\nSOAP_FMAC3 std::wstring * SOAP_FMAC4 soap_in_%s(struct soap*, const char*, std::wstring*, const char*);", c_ident(typ));
11379 fprintf(fout,"\n\nSOAP_FMAC3 std::wstring * SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, std::wstring *s, const char *type)\n{\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\treturn NULL;\n\tif (!s)\n\t\ts = soap_new_std__wstring(soap, -1);\n\tif (soap->null)\n\t\tif (s)\n\t\t\ts->erase();", c_ident(typ));
11380 fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{\twchar_t *t;\n\t\ts = (std::wstring*)soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::wstring), soap->type, soap->arrayType);\n\t\tif (s)\n\t\t{\tif (!(t = soap_wstring_in(soap, 1, %ld, %ld)))\n\t\t\t\treturn NULL;\n\t\t\ts->assign(t);\n\t\t}\n\t}\n\telse\n\t\ts = (std::wstring*)soap_id_forward(soap, soap->href, soap_class_id_enter(soap, soap->id, s, %s, sizeof(std::wstring), soap->type, soap->arrayType), 0, %s, 0, sizeof(std::wstring), 0, soap_copy_%s);\n\tif (soap->body && soap_element_end_in(soap, tag))\n\t\treturn NULL;\n\treturn s;\n}", soap_type(typ), minlen(typ), maxlen(typ), soap_type(typ), soap_type(typ), c_ident(typ));
11381 }
11382 return;
11383 }
11384 if (is_external(typ))
11385 { fprintf(fhead,"\nSOAP_FMAC1 %s * SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type(typ), c_ident(typ),c_type_id(typ, "*"));
11386 return;
11387 }
11388 fprintf(fhead,"\nSOAP_FMAC3 %s * SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type(typ), c_ident(typ),c_type_id(typ, "*"));
11389 fprintf(fout,"\n\nSOAP_FMAC3 %s * SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{\t%s;", c_type(typ), c_ident(typ), c_type_id(typ, "*a"), c_type_id(typ, "*p"));
11390 if (is_wstring(typ))
11391 fprintf(fout,"\n\tp = soap_inwstring(soap, tag, a, type, %s, %ld, %ld);", soap_type(typ), minlen(typ), maxlen(typ));
11392 else if (is_string(typ))
11393 fprintf(fout,"\n\tp = soap_instring(soap, tag, a, type, %s, %d, %ld, %ld);", soap_type(typ), is_qname(typ)+1, minlen(typ), maxlen(typ));
11394 else
11395 { if (typ->type == Tllong || typ->type == Tullong)
11396 fprintf(fout,"\n\tp = soap_in%s(soap, tag, a, type, %s);", c_type(typ), soap_type(typ));
11397 else
11398 fprintf(fout,"\n\tp = soap_in%s(soap, tag, a, type, %s);", the_type(typ), soap_type(typ));
11399 if (typ->type <= Tenum)
11400 { if (typ->minLength != MINLONG64 && (typ->minLength > 0 || typ->type < Tuchar || typ->type > Tullong))
11401 fprintf(fout,"\n\tif (p && *p < " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", typ->minLength);
11402 if (typ->maxLength != MAXLONG64)
11403 fprintf(fout,"\n\tif (p && *p > " SOAP_LONG_FORMAT ")\n\t{\tsoap->error = SOAP_LENGTH;\n\t\treturn NULL;\n\t}", typ->maxLength);
11404 }
11405 }
11406 fprintf(fout,"\n\treturn p;\n}");
11407 fflush(fout);
11408 return;
11409 }
11410 if (is_fixedstring(typ))
11411 { fprintf(fhead,"\nSOAP_FMAC3 char* SOAP_FMAC4 soap_in_%s(struct soap*, const char*, char[], const char*);", c_ident(typ));
11412 fprintf(fout,"\n\nSOAP_FMAC3 char* SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, char a[], const char *type)\n{\tchar *p;\n\tif (soap_instring(soap, tag, &p, type, %s, 1, 0, %d))\n\t\treturn strcpy(a, p);\n\treturn NULL;\n}", c_ident(typ), soap_type(typ), typ->width / ((Tnode*)typ->ref)->width - 1);
11413 return;
11414 }
11415 switch(typ->type)
11416 { case Tstruct:
11417 if (is_external(typ))
11418 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11419 return;
11420 }
11421 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11422 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
11423 table = (Table *)typ->ref;
11424 if (is_primclass(typ))
11425 { fprintf(fout, "\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\treturn NULL;");
11426 if (!cflag || has_class(typ))
11427 fprintf(fout,"\n\tif (!(a = (%s)soap_class_id_enter(soap, soap->id, a, %s, sizeof(%s), soap->type, soap->arrayType)))\n\t\treturn NULL;", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11428 else
11429 fprintf(fout,"\n\tif (!(a = (%s)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL)))\n\t\treturn NULL;", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11430 fprintf(fout,"\n\tsoap_revert(soap);\n\t*soap->id = '\\0';");
11431 /* fprintf(fout,"\n\tif (soap->alloced)"); */
11432 fprintf(fout,"\n\tsoap_default_%s(soap, a);",c_ident(typ));
11433 for (t = (Table*)typ->ref; t; t = t->prev)
11434 { for (p = t->list; p; p = p->next)
11435 if (p->info.sto & Sattribute)
11436 soap_attr_value(p, "a", ident(p->sym->name), ns_add(p, nsa));
11437 }
11438 fflush(fout);
11439 for (table = (Table*)typ->ref; table; table = table->prev)
11440 { p = table->list;
11441 if (p && is_item(p))
11442 break;
11443 }
11444 if (is_XML(p->info.typ) && is_string(p->info.typ))
11445 { fprintf(fout,"\n\tif (!soap_inliteral(soap, tag, &a->%s))", ident(p->sym->name));
11446 }
11447 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
11448 { fprintf(fout,"\n\tif (!soap_inwliteral(soap, tag, &a->%s))", ident(p->sym->name));
11449 }
11450 else if(p->info.typ->type==Tarray) {
11451 fprintf(fout,"\n\tif (!soap_in_%s(soap, tag, a->%s, \"%s\"))", c_ident(p->info.typ), ident(p->sym->name), xsi_type(typ));
11452 }
11453 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
11454 fprintf(fout,"\n\tif (!a->%s.soap_in(soap, tag, \"%s\"))", ident(p->sym->name), xsi_type(typ));
11455 }
11456 else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
11457 fprintf(fout,"\n\tif (!soap_in_%s(soap, tag, &a->%s, \"%s\"))", c_ident(p->info.typ), ident(p->sym->name), xsi_type(typ));
11458 }
11459 fprintf(fout,"\n\t\treturn NULL;");
11460 fprintf(fout, "\n\treturn a;\n}");
11461 }
11462 else
11463 { table = (Table*)typ->ref;
11464 if (!is_discriminant(typ))
11465 { for (t = table; t; t = t->prev)
11466 { for (p = t->list; p; p = p->next)
11467 { if (!(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_transient(p->info.typ) && !is_template(p->info.typ))
11468 { if (is_anytype(p) || is_choice(p))
11469 p = p->next;
11470 if (is_repetition(p))
11471 { fprintf(fout,"\n\tstruct soap_blist *soap_blist_%s = NULL;", ident(p->next->sym->name));
11472 p = p->next;
11473 }
11474 else
11475 fprintf(fout,"\n\tsize_t soap_flag_%s = " SOAP_LONG_FORMAT ";", ident(p->sym->name), p->info.maxOccurs);
11476 }
11477 }
11478 }
11479 }
11480 if (!is_invisible(typ->id->name))
11481 { fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 0, type))\n\t\treturn NULL;");
11482 }
11483 else if (!is_discriminant(typ))
11484 { if (table && (table->prev || table->list))
11485 fprintf(fout,"\n\tshort soap_flag;");
11486 }
11487 if (has_class(typ))
11488 { if (is_invisible(typ->id->name))
11489 fprintf(fout,"\n\ta = (%s)soap_class_id_enter(soap, \"\", a, %s, sizeof(%s), soap->type, soap->arrayType);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11490 else
11491 fprintf(fout,"\n\ta = (%s)soap_class_id_enter(soap, soap->id, a, %s, sizeof(%s), soap->type, soap->arrayType);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11492 }
11493 else if (is_invisible(typ->id->name))
11494 fprintf(fout,"\n\ta = (%s)soap_id_enter(soap, \"\", a, %s, sizeof(%s), 0, NULL, NULL, NULL);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11495 else
11496 fprintf(fout,"\n\ta = (%s)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11497 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
11498 /* fprintf(fout,"\n\tif (soap->alloced)"); */
11499 fprintf(fout,"\n\tsoap_default_%s(soap, a);",c_ident(typ));
11500 for (t = table; t; t = t->prev)
11501 { for (p = t->list; p; p = p->next)
11502 if (p->info.sto & Sattribute)
11503 soap_attr_value(p, "a", ident(p->sym->name), ns_add(p, nsa));
11504 }
11505 if (!is_invisible(typ->id->name))
11506 { if (!is_discriminant(typ))
11507 { fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{");
11508 fprintf(fout,"\n\t\tfor (;;)\n\t\t{\tsoap->error = SOAP_TAG_MISMATCH;");
11509 }
11510 else
11511 fprintf(fout,"\n\tif (!tag || *tag == '-' || (soap->body && !*soap->href))\n\t{");
11512 }
11513 else if (!is_discriminant(typ))
11514 { if (table->prev || table->list)
11515 fprintf(fout,"\n\t\tfor (soap_flag = 0;; soap_flag = 1)\n\t\t{\tsoap->error = SOAP_TAG_MISMATCH;");
11516 }
11517 a=0;
11518 f=0;
11519 for (t = table; t; t = t->prev)
11520 { for (p = t->list; p; p = p->next)
11521 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
11522 fprintf(fout, "\n\t\t/* non-serializable %s skipped */", ident(p->sym->name));
11523 else if (is_transient(p->info.typ))
11524 fprintf(fout, "\n\t\t/* transient %s skipped */", ident(p->sym->name));
11525 else if (p->info.sto & Sattribute)
11526 ;
11527 else if (is_repetition(p))
11528 { if (is_unmatched(p->next->sym) || is_invisible(p->next->sym->name))
11529 { p = p->next;
11530 continue;
11531 }
11532 f=1;
11533 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH && ");
11534 fprintf(fout,"!soap_element_begin_in(soap, %s, 1, NULL))", field(p->next, nse));
11535 fprintf(fout,"\n\t\t\t{\tif (a->%s == NULL)\n\t\t\t\t{\tif (soap_blist_%s == NULL)\n\t\t\t\t\t\tsoap_blist_%s = soap_new_block(soap);\n\t\t\t\t\ta->%s = (%s)soap_push_block(soap, soap_blist_%s, sizeof(%s));\n\t\t\t\t\tif (a->%s == NULL)\n\t\t\t\t\t\treturn NULL;", ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name));
11536 if (((Tnode*)p->next->info.typ->ref)->type == Tclass || has_class((Tnode*)p->next->info.typ->ref) || (!cflag && ((Tnode*)p->next->info.typ->ref)->type == Tstruct))
11537 fprintf(fout,"\n\t\t\t\t\tSOAP_PLACEMENT_NEW(a->%s, %s);", ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref));
11538 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
11539 fprintf(fout,"\n\t\t\t\t\ta->%s->soap_default(soap);", ident(p->next->sym->name));
11540 else if (((Tnode*)p->next->info.typ->ref)->type != Tpointer && !is_XML((Tnode*)p->next->info.typ->ref))
11541 fprintf(fout,"\n\t\t\t\t\tsoap_default_%s(soap, a->%s);", c_ident((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name));
11542 else
11543 fprintf(fout,"\n\t\t\t\t\t*a->%s = NULL;", ident(p->next->sym->name));
11544 fprintf(fout,"\n\t\t\t\t}");
11545 fprintf(fout,"\n\t\t\t\tsoap_revert(soap);");
11546 if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
11547 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, a->%s))", field(p->next, nse), ident(p->next->sym->name));
11548 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
11549 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, a->%s))", field(p->next, nse), ident(p->next->sym->name));
11550 else
11551 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), field(p->next, nse), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
11552 fprintf(fout,"\n\t\t\t\t{\ta->%s++;\n\t\t\t\t\ta->%s = NULL;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}", ident(p->sym->name), ident(p->next->sym->name));
11553 p = p->next;
11554 }
11555 else if (is_anytype(p))
11556 { f=1;
11557 fprintf(fout,"\n\t\t\tif (soap_flag_%s && soap->error == SOAP_TAG_MISMATCH)", ident(p->next->sym->name));
11558 fprintf(fout,"\n\t\t\t\tif ((a->%s = soap_getelement(soap, &a->%s)))", ident(p->next->sym->name), ident(p->sym->name));
11559 fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s = 0;", ident(p->next->sym->name));
11560 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11561 fprintf(fout,"\n\t\t\t\t}");
11562 p = p->next;
11563 }
11564 else if (is_discriminant(typ) && p->next)
11565 { f=1;
11566 fprintf(fout,"\n\t\tif (!soap_in_%s(soap, &a->%s, &a->%s))", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name));
11567 fprintf(fout,"\n\t\t\treturn NULL;");
11568 break;
11569 }
11570 else if (is_choice(p))
11571 { f=1;
11572 fprintf(fout,"\n\t\t\tif (soap_flag_%s && soap->error == SOAP_TAG_MISMATCH)", ident(p->next->sym->name));
11573 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, &a->%s, &a->%s))", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name));
11574 fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s = 0;", ident(p->next->sym->name));
11575 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11576 fprintf(fout,"\n\t\t\t\t}");
11577 p = p->next;
11578 }
11579 else
11580 { f=1;
11581 if (!is_invisible(p->sym->name) && !is_primclass(typ) && p->info.typ->type != Tfun && !is_void(p->info.typ))
11582 { if (is_string(p->info.typ) || is_wstring(p->info.typ) || is_stdstr(p->info.typ))
11583 fprintf(fout,"\n\t\t\tif (soap_flag_%s && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG))", ident(p->sym->name));
11584 else if (is_template(p->info.typ))
11585 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
11586 else
11587 fprintf(fout,"\n\t\t\tif (soap_flag_%s && soap->error == SOAP_TAG_MISMATCH)", ident(p->sym->name));
11588 }
11589 if (is_unmatched(p->sym))
11590 {
11591 if (is_XML(p->info.typ) && is_string(p->info.typ)) {
11592 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, NULL, &a->%s))", ident(p->sym->name));
11593 } else if (is_XML(p->info.typ) && is_wstring(p->info.typ)) {
11594 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, NULL, &a->%s))", ident(p->sym->name));
11595 } else if(p->info.typ->type==Tarray) {
11596 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, a->%s, \"%s\"))", c_ident(p->info.typ), ident(p->sym->name), xsi_type(p->info.typ));
11597 } else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
11598 fprintf(fout,"\n\t\t\t\tif (a->%s.soap_in(soap, NULL, \"%s\"))", ident(p->sym->name), xsi_type(p->info.typ));
11599 } else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
11600 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, &a->%s, \"%s\"))", c_ident(p->info.typ), ident(p->sym->name), xsi_type(p->info.typ));
11601 }
11602 }
11603 else if (!is_invisible(p->sym->name))
11604 {
11605 if (is_XML(p->info.typ) && is_string(p->info.typ)) {
11606 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, &a->%s))", field(p, nse), ident(p->sym->name));
11607 } else if (is_XML(p->info.typ) && is_wstring(p->info.typ)) {
11608 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, &a->%s))", field(p, nse), ident(p->sym->name));
11609 } else if(p->info.typ->type==Tarray) {
11610 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s, \"%s\"))", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type(p->info.typ));
11611 } else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
11612 fprintf(fout,"\n\t\t\t\tif (a->%s.soap_in(soap, %s, \"%s\"))", ident(p->sym->name), field(p, nse),xsi_type(p->info.typ));
11613 } else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
11614 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, &a->%s, \"%s\"))", c_ident(p->info.typ), field(p, nse), ident(p->sym->name), xsi_type(p->info.typ));
11615 }
11616 }
11617 if (!is_invisible(p->sym->name) && !is_primclass(typ) && p->info.typ->type != Tfun && !is_void(p->info.typ))
11618 { if (is_template(p->info.typ))
11619 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11620 else
11621 { fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s--;", ident(p->sym->name));
11622 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11623 fprintf(fout,"\n\t\t\t\t}");
11624 }
11625 }
11626 }
11627 fflush(fout);
11628 }
11629 }
11630 if (!is_discriminant(typ))
11631 { for (t = table; t; t = t->prev)
11632 { for (p = t->list; p; p = p->next)
11633 { if (is_repetition(p) && (is_unmatched(p->next->sym) || (is_invisible(p->next->sym->name))))
11634 { f=1;
11635 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH && ");
11636 if (is_unmatched(p->next->sym))
11637 fprintf(fout,"!soap_element_begin_in(soap, NULL, 1, NULL))");
11638 else if (is_invisible(p->next->sym->name))
11639 fprintf(fout,"!soap_peek_element(soap))");
11640 fprintf(fout,"\n\t\t\t{\tif (a->%s == NULL)\n\t\t\t\t{\tif (soap_blist_%s == NULL)\n\t\t\t\t\t\tsoap_blist_%s = soap_new_block(soap);\n\t\t\t\t\ta->%s = (%s)soap_push_block(soap, soap_blist_%s, sizeof(%s));\n\t\t\t\t\tif (a->%s == NULL)\n\t\t\t\t\t\treturn NULL;", ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name));
11641 if (((Tnode*)p->next->info.typ->ref)->type == Tclass || has_class((Tnode*)p->next->info.typ->ref) || (!cflag && ((Tnode*)p->next->info.typ->ref)->type == Tstruct))
11642 fprintf(fout,"\n\t\t\t\t\tSOAP_PLACEMENT_NEW(a->%s, %s);", ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref));
11643 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
11644 fprintf(fout,"\n\t\t\t\t\ta->%s->soap_default(soap);", ident(p->next->sym->name));
11645 else if (((Tnode*)p->next->info.typ->ref)->type != Tpointer && !is_XML((Tnode*)p->next->info.typ->ref))
11646 fprintf(fout,"\n\t\t\t\t\tsoap_default_%s(soap, a->%s);", c_ident((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name));
11647 else
11648 fprintf(fout,"\n\t\t\t\t\t*a->%s = NULL;", ident(p->next->sym->name));
11649 fprintf(fout,"\n\t\t\t\t}");
11650 if (!is_invisible(p->next->sym->name))
11651 fprintf(fout,"\n\t\t\t\tsoap_revert(soap);");
11652 if (is_unmatched(p->next->sym))
11653 { if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
11654 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, NULL, a->%s))", ident(p->next->sym->name));
11655 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
11656 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, NULL, a->%s))", ident(p->next->sym->name));
11657 else
11658 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, a->%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
11659 }
11660 else
11661 { if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
11662 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, a->%s))", field(p->next, nse), ident(p->next->sym->name));
11663 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
11664 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, a->%s))", field(p->next, nse), ident(p->next->sym->name));
11665 else
11666 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), field(p->next, nse), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
11667 }
11668 fprintf(fout,"\n\t\t\t\t{\ta->%s++;\n\t\t\t\t\ta->%s = NULL;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}", ident(p->sym->name), ident(p->next->sym->name));
11669 p = p->next;
11670 }
11671 else if (is_repetition(p) || is_anytype(p) || is_choice(p))
11672 { p = p->next;
11673 continue;
11674 }
11675 else if (is_invisible(p->sym->name)
11676 && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !is_transient(p->info.typ) && !(p->info.sto & Sattribute))
11677 { f=1;
11678 if (is_string(p->info.typ) || is_wstring(p->info.typ) || is_stdstr(p->info.typ))
11679 fprintf(fout,"\n\t\t\tif (soap_flag_%s && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG))", ident(p->sym->name));
11680 else if (is_template(p->info.typ))
11681 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
11682 else
11683 fprintf(fout,"\n\t\t\tif (soap_flag_%s && soap->error == SOAP_TAG_MISMATCH)", ident(p->sym->name));
11684 if (is_XML(p->info.typ) && is_string(p->info.typ))
11685 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, &a->%s))", field(p, nse), ident(p->sym->name));
11686 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
11687 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, &a->%s))", field(p, nse), ident(p->sym->name));
11688 else if(p->info.typ->type==Tarray)
11689 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s, \"%s\"))", c_ident(p->info.typ), field(p, nse),ident(p->sym->name),xsi_type(p->info.typ));
11690 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
11691 fprintf(fout,"\n\t\t\t\tif (a->%s.soap_in(soap, %s, \"%s\"))", ident(p->sym->name), field(p, nse),xsi_type(p->info.typ));
11692 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
11693 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, &a->%s, \"%s\"))", c_ident(p->info.typ), field(p, nse),ident(p->sym->name),xsi_type(p->info.typ));
11694 if (is_template(p->info.typ))
11695 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11696 else
11697 { fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s--;", ident(p->sym->name));
11698 fprintf(fout,"\n\t\t\t\t\tcontinue;");
11699 fprintf(fout,"\n\t\t\t\t}");
11700 }
11701 }
11702 }
11703 }
11704 for (t = table; t; t = t->prev)
11705 for (p = t->list; p; p = p->next)
11706 if (p->info.sto & Sreturn)
11707 if (nse || has_ns_eq(NULL, p->sym->name))
11708 fprintf(fout,"\n\t\t\tsoap_check_result(soap, \"%s\");", ns_add(p, nse));
11709 if (!f && is_invisible(typ->id->name))
11710 fprintf(fout,"\n\tsoap->error = SOAP_TAG_MISMATCH;\n\ta = NULL;");
11711 if (!is_invisible(typ->id->name) || table->prev || table->list)
11712 { fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
11713 if (!is_invisible(typ->id->name) || is_discriminant(typ))
11714 fprintf(fout,"\n\t\t\t\tsoap->error = soap_ignore_element(soap);");
11715 else
11716 fprintf(fout,"\n\t\t\t\tif (soap_flag)\n\t\t\t\t{\tsoap->error = SOAP_OK;\n\t\t\t\t\tbreak;\n\t\t\t\t}");
11717 if (!is_invisible(typ->id->name))
11718 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_NO_TAG)");
11719 else
11720 fprintf(fout,"\n\t\t\tif (soap_flag && soap->error == SOAP_NO_TAG)");
11721 fprintf(fout,"\n\t\t\t\tbreak;");
11722 fprintf(fout,"\n\t\t\tif (soap->error)\n\t\t\t\treturn NULL;");
11723 fprintf(fout,"\n\t\t}");
11724 }
11725 }
11726 if (table && !is_discriminant(typ))
11727 { for (p = table->list; p; p = p->next)
11728 if (is_repetition(p))
11729 { fprintf(fout, "\n\t\tif (a->%s)\n\t\t\tsoap_pop_block(soap, soap_blist_%s);", ident(p->next->sym->name), ident(p->next->sym->name));
11730 fprintf(fout, "\n\t\tif (a->%s)\n\t\t\ta->%s = (%s)soap_save_block(soap, soap_blist_%s, NULL, 1);\n\t\telse\n\t\t{\ta->%s = NULL;\n\t\t\tif (soap_blist_%s)\n\t\t\t\tsoap_end_block(soap, soap_blist_%s);\n\t\t}", ident(p->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), ident(p->next->sym->name));
11731 p = p->next;
11732 }
11733 }
11734 if (!is_invisible(typ->id->name))
11735 { fprintf(fout,"\n\t\tif (soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
11736 fprintf(fout,"\n\t}\n\telse\n\t{\t");
11737 if (has_class(typ))
11738 fprintf(fout,"a = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, soap_copy_%s);",c_type_id(typ, "*"), soap_type(typ), c_type(typ), c_ident(typ));
11739 else
11740 fprintf(fout,"a = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, NULL);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11741 fprintf(fout,"\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
11742 fprintf(fout, "\n\t}");
11743 }
11744 a = 0;
11745 if (table && !is_discriminant(typ))
11746 { for (p = table->list; p; p = p->next)
11747 { if (p->info.minOccurs > 0 && p->info.maxOccurs >= 0 && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_transient(p->info.typ) && !is_template(p->info.typ) && !is_repetition(p) && !is_choice(p) && p->info.hasval == False)
11748 { if (is_item(p))
11749 continue;
11750 if (is_anytype(p))
11751 p = p->next;
11752 if (a==0)
11753 { fprintf(fout,"\n\tif (%s(soap_flag_%s > " SOAP_LONG_FORMAT "", strict_check(), ident(p->sym->name), p->info.maxOccurs - p->info.minOccurs);
11754 a=1;
11755 }
11756 else
11757 fprintf(fout," || soap_flag_%s > " SOAP_LONG_FORMAT "", ident(p->sym->name), p->info.maxOccurs - p->info.minOccurs);
11758 }
11759 else if (is_template(p->info.typ))
11760 { if (p->info.minOccurs > 0)
11761 { if (p->info.typ->type == Tpointer)
11762 { if (a==0)
11763 { fprintf(fout,"\n\tif (%s(!a->%s || a->%s->size() < " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), ident(p->sym->name), p->info.minOccurs);
11764 a=1;
11765 }
11766 else
11767 fprintf(fout," || !a->%s || a->%s->size() < " SOAP_LONG_FORMAT, ident(p->sym->name), ident(p->sym->name), p->info.minOccurs);
11768 }
11769 else
11770 { if (a==0)
11771 { fprintf(fout,"\n\tif (%s(a->%s.size() < " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), p->info.minOccurs);
11772 a=1;
11773 }
11774 else
11775 fprintf(fout," || a->%s.size() < " SOAP_LONG_FORMAT, ident(p->sym->name), p->info.minOccurs);
11776 }
11777 }
11778 if ( p->info.maxOccurs > 1)
11779 { if (p->info.typ->type == Tpointer)
11780 { if (a==0)
11781 { fprintf(fout,"\n\tif (%s((a->%s && a->%s->size() > " SOAP_LONG_FORMAT ")", strict_check(), ident(p->sym->name), ident(p->sym->name), p->info.maxOccurs);
11782 a=1;
11783 }
11784 else
11785 fprintf(fout," || (a->%s && a->%s->size() > " SOAP_LONG_FORMAT ")", ident(p->sym->name), ident(p->sym->name), p->info.maxOccurs);
11786 }
11787 else
11788 { if (a==0)
11789 { fprintf(fout,"\n\tif (%s(a->%s.size() > " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), p->info.maxOccurs);
11790 a=1;
11791 }
11792 else
11793 fprintf(fout," || a->%s.size() > " SOAP_LONG_FORMAT, ident(p->sym->name), p->info.maxOccurs);
11794 }
11795 }
11796 }
11797 else if (is_repetition(p))
11798 { if (p->info.minOccurs > 0)
11799 { if (a==0)
11800 { fprintf(fout,"\n\tif (%s(a->%s < " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), p->info.minOccurs);
11801 a=1;
11802 }
11803 else
11804 fprintf(fout," || a->%s < " SOAP_LONG_FORMAT, ident(p->sym->name), p->info.minOccurs);
11805 }
11806 if (p->info.maxOccurs > 1)
11807 { if (a==0)
11808 { fprintf(fout,"\n\tif (%s(a->%s > " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), p->info.maxOccurs);
11809 a=1;
11810 }
11811 else
11812 fprintf(fout," || a->%s > " SOAP_LONG_FORMAT, ident(p->sym->name), p->info.maxOccurs);
11813 }
11814 p = p->next;
11815 }
11816 else if (is_choice(p))
11817 { if (p->info.minOccurs != 0)
11818 { if (a==0)
11819 { fprintf(fout,"\n\tif (%s(soap_flag_%s", strict_check(), ident(p->next->sym->name));
11820 a=1;
11821 }
11822 else
11823 fprintf(fout," || soap_flag_%s", ident(p->next->sym->name));
11824 }
11825 p = p->next;
11826 }
11827 }
11828 if (a)
11829 fprintf(fout,"))\n\t{\tsoap->error = SOAP_OCCURS;\n\t\treturn NULL;\n\t}");
11830 }
11831 fprintf(fout, "\n\treturn a;\n}");
11832 }
11833 break;
11834
11835 case Tclass:
11836 if (is_external(typ))
11837 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11838 return;
11839 }
11840 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
11841 if (!is_volatile(typ) && !is_typedef(typ))
11842 { fprintf(fout,"\n\nvoid *%s::soap_in(struct soap *soap, const char *tag, const char *type)", c_type(typ));
11843 fprintf(fout,"\n{\treturn soap_in_%s(soap, tag, this, type);\n}",c_ident(typ));
11844 fflush(fout);
11845 }
11846 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
11847 if (is_primclass(typ))
11848 {
11849 fprintf(fout, "\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\treturn NULL;");
11850 fprintf(fout,"\n\tif (!(a = (%s)soap_class_id_enter(soap, soap->id, a, %s, sizeof(%s), soap->type, soap->arrayType)))\n\t{\tsoap->error = SOAP_TAG_MISMATCH;\n\t\treturn NULL;\n\t}", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11851 fprintf(fout,"\n\tsoap_revert(soap);\n\t*soap->id = '\\0';");
11852 fprintf(fout,"\n\tif (soap->alloced)");
11853 fprintf(fout,"\n\t{\ta->soap_default(soap);");
11854 fprintf(fout,"\n\t\tif (soap->clist->type != %s)", soap_type(typ));
11855 fprintf(fout,"\n\t\t\treturn (%s)a->soap_in(soap, tag, type);", c_type_id(typ, "*"));
11856 fprintf(fout,"\n\t}");
11857 for (t = (Table*)typ->ref; t; t = t->prev)
11858 { Entry *e = entry(classtable, t->sym);
11859 char *nsa1 = e ? ns_qualifiedAttribute(e->info.typ) : nsa;
11860 for (p = t->list; p; p = p->next)
11861 if (p->info.sto & Sattribute)
11862 soap_attr_value(p, ptr_cast(t, "a"), ident(p->sym->name), ns_add(p, nsa1));
11863 }
11864 fflush(fout);
11865 for (table = (Table*)typ->ref; table; table = table->prev)
11866 { p = table->list;
11867 if (p && is_item(p))
11868 break;
11869 }
11870 if (is_XML(p->info.typ) && is_string(p->info.typ))
11871 { fprintf(fout,"\n\tif (!soap_inliteral(soap, tag, &(a->%s::%s)))", ident(table->sym->name), ident(p->sym->name));
11872 }
11873 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
11874 { fprintf(fout,"\n\tif (!soap_inwliteral(soap, tag, &(a->%s::%s)))", ident(table->sym->name), ident(p->sym->name));
11875 }
11876 else if(p->info.typ->type==Tarray) {
11877 fprintf(fout,"\n\tif (!soap_in_%s(soap, tag, a->%s::%s, \"%s\"))", c_ident(p->info.typ), ident(table->sym->name), ident(p->sym->name), xsi_type(typ));
11878 }
11879 else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
11880 fprintf(fout,"\n\tif (!(a->%s::%s).soap_in(soap, tag, \"%s\"))", ident(table->sym->name), ident(p->sym->name), xsi_type(typ));
11881 }
11882 else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
11883 fprintf(fout,"\n\tif (!soap_in_%s(soap, tag, &(a->%s::%s), \"%s\"))", c_ident(p->info.typ), ident(table->sym->name), ident(p->sym->name), xsi_type(typ));
11884 }
11885 fprintf(fout,"\n\t\treturn NULL;");
11886 if (has_getter(typ))
11887 fprintf(fout,"\n\tif (a->get(soap))\n\t\treturn NULL;");
11888 fprintf(fout,"\n\treturn a;\n}");
11889 }
11890 else
11891 {
11892 if (!is_invisible(typ->id->name))
11893 { fprintf(fout,"\n\t(void)type; /* appease -Wall -Werror */\n\tif (soap_element_begin_in(soap, tag, 0, NULL))\n\t\treturn NULL;");
11894 fprintf(fout,"\n\ta = (%s)soap_class_id_enter(soap, soap->id, a, %s, sizeof(%s), soap->type, soap->arrayType);", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11895 }
11896 else
11897 fprintf(fout,"\n\ta = (%s)soap_class_id_enter(soap, \"\", a, %s, sizeof(%s), soap->type, soap->arrayType);", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
11898 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
11899 if (!is_discriminant(typ))
11900 { fprintf(fout,"\n\tif (soap->alloced)");
11901 if (is_volatile(typ) || is_typedef(typ))
11902 fprintf(fout,"\n\t{\tsoap_default_%s(soap, a);",c_ident(typ));
11903 else
11904 fprintf(fout,"\n\t{\ta->soap_default(soap);");
11905 if (!is_invisible(typ->id->name))
11906 { fprintf(fout,"\n\t\tif (soap->clist->type != %s)", soap_type(typ));
11907 fprintf(fout,"\n\t\t{\tsoap_revert(soap);");
11908 fprintf(fout,"\n\t\t\t*soap->id = '\\0';");
11909 if (is_volatile(typ) || is_typedef(typ))
11910 fprintf(fout,"\n\t\t\treturn soap_in_%s(soap, tag, a, type);", c_ident(typ));
11911 else
11912 fprintf(fout,"\n\t\t\treturn (%s)a->soap_in(soap, tag, type);", c_type_id(typ, "*"));
11913 fprintf(fout,"\n\t\t}");
11914 }
11915 fprintf(fout,"\n\t}");
11916 }
11917 else
11918 fprintf(fout,"\n\ta->soap_default(soap);");
11919 table=(Table *)typ->ref;
11920 for (t = table; t; t = t->prev)
11921 { Entry *e = entry(classtable, t->sym);
11922 char *nsa1 = e ? ns_qualifiedAttribute(e->info.typ) : nsa;
11923 for (p = t->list; p; p = p->next)
11924 if (p->info.sto & Sattribute)
11925 soap_attr_value(p, ptr_cast(t, "a"), ident(p->sym->name), ns_add(p, nsa1));
11926 }
11927 fflush(fout);
11928
11929 i=0;
11930 if (!is_discriminant(typ))
11931 { for (t = table; t; t = t->prev)
11932 i++;
11933 a=0;
11934 for (; i > 0; i--)
11935 { t = table;
11936 for (j = 0; j < i-1; j++)
11937 t = t->prev;
11938 for (p = t->list; p; p = p->next)
11939 { if (!(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_transient(p->info.typ) && !is_template(p->info.typ))
11940 { if (is_anytype(p) || is_choice(p))
11941 p = p->next;
11942 if (is_repetition(p))
11943 { fprintf(fout,"\n\tstruct soap_blist *soap_blist_%s%d = NULL;", ident(p->next->sym->name), i);
11944 p = p->next;
11945 }
11946 else
11947 fprintf(fout,"\n\tsize_t soap_flag_%s%d = " SOAP_LONG_FORMAT ";", ident(p->sym->name), i, p->info.maxOccurs);
11948 }
11949 }
11950 }
11951 if (a)
11952 fprintf(fout,";");
11953 }
11954 fflush(fout);
11955 if (!is_invisible(typ->id->name))
11956 { if (!is_discriminant(typ))
11957 { fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{");
11958 fprintf(fout,"\n\t\tfor (;;)\n\t\t{\tsoap->error = SOAP_TAG_MISMATCH;");
11959 }
11960 else
11961 fprintf(fout,"\n\tif (!tag || *tag == '-' || (soap->body && !*soap->href))\n\t{");
11962 }
11963 else if (!is_discriminant(typ))
11964 { if (table->prev || table->list)
11965 fprintf(fout,"\n\t\tfor (short soap_flag = 0;; soap_flag = 1)\n\t\t{\tsoap->error = SOAP_TAG_MISMATCH;");
11966 }
11967 table=(Table *)typ->ref;
11968 a=0;
11969 i=0;
11970 f=0;
11971 for (t = table; t; t = t->prev)
11972 i++;
11973 for (; i > 0; i--)
11974 { Entry *e;
11975 char *nse1;
11976 t = table;
11977 for (j = 0; j < i-1; j++)
11978 t = t->prev;
11979 e = entry(classtable, t->sym);
11980 nse1 = e ? ns_qualifiedElement(e->info.typ) : nse;
11981 for (p = t->list; p; p = p->next)
11982 { if (is_item(p))
11983 ;
11984 else if (p->info.sto & (Sconst | Sprivate | Sprotected))
11985 fprintf(fout, "\n\t\t\t/* non-serializable %s skipped */", ident(p->sym->name));
11986 else if (is_transient(p->info.typ))
11987 fprintf(fout, "\n\t\t\t/* transient %s skipped */", ident(p->sym->name));
11988 else if (p->info.sto & Sattribute)
11989 ;
11990 else if (is_repetition(p))
11991 {
11992 if (is_unmatched(p->next->sym) || is_invisible(p->next->sym->name))
11993 { p = p->next;
11994 continue;
11995 }
11996 f=1;
11997 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH && ");
11998 fprintf(fout,"!soap_element_begin_in(soap, %s, 1, NULL))", field(p->next, nse1));
11999 fprintf(fout,"\n\t\t\t{\tif (a->%s::%s == NULL)\n\t\t\t\t{\tif (soap_blist_%s%d == NULL)\n\t\t\t\t\t\tsoap_blist_%s%d = soap_new_block(soap);\n\t\t\t\t\ta->%s::%s = (%s)soap_push_block(soap, soap_blist_%s%d, sizeof(%s));\n\t\t\t\t\tif (a->%s::%s == NULL)\n\t\t\t\t\t\treturn NULL;", ident(t->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), i, ident(p->next->sym->name), i, ident(t->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), i, c_type((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name));
12000 if (((Tnode*)p->next->info.typ->ref)->type == Tclass || has_class((Tnode*)p->next->info.typ->ref) || (!cflag && ((Tnode*)p->next->info.typ->ref)->type == Tstruct))
12001 fprintf(fout,"\n\t\t\t\t\tSOAP_PLACEMENT_NEW(a->%s::%s, %s);", ident(t->sym->name), ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref));
12002 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
12003 fprintf(fout,"\n\t\t\t\t\ta->%s::%s->soap_default(soap);", ident(t->sym->name), ident(p->next->sym->name));
12004 else if (((Tnode*)p->next->info.typ->ref)->type != Tpointer && !is_XML((Tnode*)p->next->info.typ->ref))
12005 fprintf(fout,"\n\t\t\t\t\tsoap_default_%s(soap, a->%s::%s);", c_ident((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name));
12006 else
12007 fprintf(fout,"\n\t\t\t\t\t*a->%s::%s = NULL;", ident(t->sym->name), ident(p->next->sym->name));
12008 fprintf(fout,"\n\t\t\t\t}");
12009 fprintf(fout,"\n\t\t\t\tsoap_revert(soap);");
12010 if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
12011 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, a->%s::%s))", field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
12012 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
12013 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, a->%s::%s))", field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
12014 else
12015 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s::%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
12016 fprintf(fout,"\n\t\t\t\t{\ta->%s::%s++;\n\t\t\t\t\ta->%s::%s = NULL;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}", ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name));
12017 p = p->next;
12018 }
12019 else if (is_anytype(p))
12020 { f=1;
12021 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && soap->error == SOAP_TAG_MISMATCH)", ident(p->next->sym->name), i);
12022 fprintf(fout,"\n\t\t\t\tif ((a->%s::%s = soap_getelement(soap, &a->%s::%s)))", ident(t->sym->name), ident(p->next->sym->name), ident(t->sym->name), ident(p->sym->name));
12023 fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s%d = 0;", ident(p->next->sym->name), i);
12024 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12025 fprintf(fout,"\n\t\t\t\t}");
12026 p = p->next;
12027 }
12028 else if (is_discriminant(typ) && p->next)
12029 { f=1;
12030 fprintf(fout,"\n\t\tif (!soap_in_%s(soap, &a->%s, &a->%s))", c_ident(p->next->info.typ), ident(p->sym->name), ident(p->next->sym->name));
12031 fprintf(fout,"\n\t\t\treturn NULL;");
12032 i = 0;
12033 break;
12034 }
12035 else if (is_choice(p))
12036 { f=1;
12037 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && soap->error == SOAP_TAG_MISMATCH)",ident(p->next->sym->name),i);
12038 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, &a->%s::%s, &a->%s::%s))", c_ident(p->next->info.typ), ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name));
12039 fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s%d = 0;", ident(p->next->sym->name), i);
12040 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12041 fprintf(fout,"\n\t\t\t\t}");
12042 p = p->next;
12043 }
12044 else
12045 { f=1;
12046 if (!is_invisible(p->sym->name) && !is_primclass(typ) && p->info.typ->type != Tfun && !is_void(p->info.typ))
12047 { if (is_string(p->info.typ) || is_wstring(p->info.typ) || is_stdstr(p->info.typ))
12048 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG))",ident(p->sym->name), i);
12049 else if (is_template(p->info.typ))
12050 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
12051 else
12052 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && soap->error == SOAP_TAG_MISMATCH)",ident(p->sym->name), i);
12053 }
12054 if (is_unmatched(p->sym))
12055 {
12056 if (is_XML(p->info.typ) && is_string(p->info.typ)) {
12057 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, NULL, &(a->%s::%s)))", ident(t->sym->name), ident(p->sym->name));
12058 } else if (is_XML(p->info.typ) && is_wstring(p->info.typ)) {
12059 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, NULL, &(a->%s::%s)))", ident(t->sym->name), ident(p->sym->name));
12060 }
12061 else if(p->info.typ->type==Tarray) {
12062 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, a->%s::%s, \"%s\"))", c_ident(p->info.typ),ident(t->sym->name),ident(p->sym->name),xsi_type(p->info.typ));
12063 } else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
12064 fprintf(fout,"\n\t\t\t\tif ((a->%s::%s).soap_in(soap, NULL, \"%s\"))", ident(t->sym->name),ident(p->sym->name),xsi_type(p->info.typ));
12065 } else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
12066 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, &(a->%s::%s), \"%s\"))", c_ident(p->info.typ),ident(t->sym->name),ident(p->sym->name),xsi_type(p->info.typ));
12067 }
12068 }
12069 else if (!is_invisible(p->sym->name))
12070 {
12071 if (is_XML(p->info.typ) && is_string(p->info.typ)) {
12072 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, &(a->%s::%s)))", field_overridden(t, p, nse1), ident(t->sym->name),ident(p->sym->name));
12073 } else if (is_XML(p->info.typ) && is_wstring(p->info.typ)) {
12074 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, &(a->%s::%s)))", field_overridden(t, p, nse1), ident(t->sym->name),ident(p->sym->name));
12075 }
12076 else if(p->info.typ->type==Tarray) {
12077 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s::%s, \"%s\"))", c_ident(p->info.typ), field_overridden(t, p, nse1),ident(t->sym->name),ident(p->sym->name),xsi_type(p->info.typ));
12078 } else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
12079 fprintf(fout,"\n\t\t\t\tif ((a->%s::%s).soap_in(soap, %s, \"%s\"))", ident(t->sym->name),ident(p->sym->name), field_overridden(t, p, nse1),xsi_type(p->info.typ));
12080 } else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
12081 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, &(a->%s::%s), \"%s\"))", c_ident(p->info.typ), field_overridden(t, p, nse1),ident(t->sym->name),ident(p->sym->name),xsi_type(p->info.typ));
12082 }
12083 }
12084 if (!is_invisible(p->sym->name) && !is_primclass(typ) && p->info.typ->type != Tfun && !is_void(p->info.typ))
12085 { if (is_template(p->info.typ))
12086 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12087 else
12088 { fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s%d--;", ident(p->sym->name), i);
12089 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12090 fprintf(fout,"\n\t\t\t\t}");
12091 }
12092 }
12093 fflush(fout);
12094 }
12095 }
12096 }
12097 if (!is_discriminant(typ))
12098 {
12099 Entry *e;
12100 char *nse1;
12101 i=0;
12102 for (t = table; t; t = t->prev)
12103 { i++;
12104 e = entry(classtable, t->sym);
12105 nse1 = e ? ns_qualifiedElement(e->info.typ) : nse;
12106 for (p = t->list; p; p = p->next)
12107 { if (is_repetition(p) && (is_unmatched(p->next->sym) || is_invisible(p->next->sym->name)))
12108 { f=1;
12109 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH && ");
12110 if (is_unmatched(p->next->sym))
12111 fprintf(fout,"!soap_element_begin_in(soap, NULL, 1, NULL))");
12112 else if (is_invisible(p->next->sym->name))
12113 fprintf(fout,"!soap_peek_element(soap))");
12114 fprintf(fout,"\n\t\t\t{\tif (a->%s::%s == NULL)\n\t\t\t\t{\tif (soap_blist_%s%d == NULL)\n\t\t\t\t\t\tsoap_blist_%s%d = soap_new_block(soap);\n\t\t\t\t\ta->%s::%s = (%s)soap_push_block(soap, soap_blist_%s%d, sizeof(%s));\n\t\t\t\t\tif (a->%s::%s == NULL)\n\t\t\t\t\t\treturn NULL;", ident(t->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), i, ident(p->next->sym->name), i, ident(t->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), i, c_type((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name));
12115 if (((Tnode*)p->next->info.typ->ref)->type == Tclass || has_class((Tnode*)p->next->info.typ->ref) || (!cflag && ((Tnode*)p->next->info.typ->ref)->type == Tstruct))
12116 fprintf(fout,"\n\t\t\t\t\tSOAP_PLACEMENT_NEW(a->%s::%s, %s);", ident(t->sym->name), ident(p->next->sym->name), c_type((Tnode*)p->next->info.typ->ref));
12117 if (((Tnode*)p->next->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->next->info.typ->ref) && !is_volatile((Tnode*)p->next->info.typ->ref) && !is_typedef((Tnode*)p->next->info.typ->ref))
12118 fprintf(fout,"\n\t\t\t\t\ta->%s::%s->soap_default(soap);", ident(t->sym->name), ident(p->next->sym->name));
12119 else if (((Tnode*)p->next->info.typ->ref)->type != Tpointer && !is_XML((Tnode*)p->next->info.typ->ref))
12120 fprintf(fout,"\n\t\t\t\t\tsoap_default_%s(soap, a->%s::%s);", c_ident((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name));
12121 else
12122 fprintf(fout,"\n\t\t\t\t\t*a->%s::%s = NULL;", ident(t->sym->name), ident(p->next->sym->name));
12123 fprintf(fout,"\n\t\t\t\t}");
12124 if (!is_invisible(p->next->sym->name))
12125 fprintf(fout,"\n\t\t\t\tsoap_revert(soap);");
12126 if (is_unmatched(p->next->sym))
12127 { if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
12128 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, NULL, a->%s::%s))", ident(t->sym->name), ident(p->next->sym->name));
12129 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
12130 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, NULL, a->%s::%s))", ident(t->sym->name), ident(p->next->sym->name));
12131 else
12132 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, NULL, a->%s::%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), ident(t->sym->name), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
12133 }
12134 else
12135 { if (is_XML((Tnode*)p->next->info.typ->ref) && is_string((Tnode*)p->next->info.typ->ref))
12136 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, a->%s::%s))", field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
12137 else if (is_XML((Tnode*)p->next->info.typ->ref) && is_wstring((Tnode*)p->next->info.typ->ref))
12138 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, a->%s::%s))", field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name));
12139 else
12140 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s::%s, \"%s\"))", c_ident((Tnode*)p->next->info.typ->ref), field(p->next, nse1), ident(t->sym->name), ident(p->next->sym->name), xsi_type((Tnode*)p->next->info.typ->ref));
12141 }
12142 fprintf(fout,"\n\t\t\t\t{\ta->%s::%s++;\n\t\t\t\t\ta->%s::%s = NULL;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}", ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name));
12143 p = p->next;
12144 }
12145 else if (is_repetition(p) || is_anytype(p) || is_choice(p))
12146 { p = p->next;
12147 continue;
12148 }
12149 else if (is_invisible(p->sym->name)
12150 && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !is_transient(p->info.typ) && !(p->info.sto & Sattribute))
12151 { f=1;
12152 if (is_string(p->info.typ) || is_wstring(p->info.typ) || is_stdstr(p->info.typ))
12153 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG))",ident(p->sym->name), i);
12154 else if (is_template(p->info.typ))
12155 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
12156 else
12157 fprintf(fout,"\n\t\t\tif (soap_flag_%s%d && soap->error == SOAP_TAG_MISMATCH)",ident(p->sym->name), i);
12158 if (is_XML(p->info.typ) && is_string(p->info.typ)) {
12159 fprintf(fout,"\n\t\t\t\tif (soap_inliteral(soap, %s, &(a->%s::%s)))", field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name));
12160 } else if (is_XML(p->info.typ) && is_wstring(p->info.typ)) {
12161 fprintf(fout,"\n\t\t\t\tif (soap_inwliteral(soap, %s, &(a->%s::%s)))", field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name));
12162 }
12163 else if(p->info.typ->type==Tarray) {
12164 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, a->%s::%s, \"%s\"))", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name) ,xsi_type(p->info.typ));
12165 } else if(p->info.typ->type==Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ)) {
12166 fprintf(fout,"\n\t\t\t\tif ((a->%s::%s).soap_in(soap, %s, \"%s\"))", ident(t->sym->name), ident(p->sym->name), field_overridden(t, p, nse1),xsi_type(p->info.typ));
12167 } else if (p->info.typ->type != Tfun && !is_void(p->info.typ)) {
12168 fprintf(fout,"\n\t\t\t\tif (soap_in_%s(soap, %s, &(a->%s::%s), \"%s\"))", c_ident(p->info.typ),field_overridden(t, p, nse1), ident(t->sym->name), ident(p->sym->name) ,xsi_type(p->info.typ));
12169 }
12170 if (is_template(p->info.typ))
12171 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12172 else
12173 { fprintf(fout,"\n\t\t\t\t{\tsoap_flag_%s%d--;", ident(p->sym->name), i);
12174 fprintf(fout,"\n\t\t\t\t\tcontinue;");
12175 fprintf(fout,"\n\t\t\t\t}");
12176 }
12177 }
12178 }
12179 }
12180 for (t = table; t; t = t->prev)
12181 for (p = t->list; p; p = p->next)
12182 if (p->info.sto & Sreturn)
12183 if (nse || has_ns_eq(NULL, p->sym->name))
12184 fprintf(fout,"\n\t\t\tsoap_check_result(soap, \"%s\");", ns_add(p, nse));
12185 if (!f && is_invisible(typ->id->name))
12186 fprintf(fout,"\n\tsoap->error = SOAP_TAG_MISMATCH;\n\ta = NULL;");
12187 if (!is_invisible(typ->id->name) || table->prev || table->list)
12188 { fprintf(fout,"\n\t\t\tif (soap->error == SOAP_TAG_MISMATCH)");
12189 if (!is_invisible(typ->id->name) || is_discriminant(typ))
12190 fprintf(fout,"\n\t\t\t\tsoap->error = soap_ignore_element(soap);");
12191 else
12192 fprintf(fout,"\n\t\t\t\tif (soap_flag)\n\t\t\t\t{\n\t\t\t\t\tsoap->error = SOAP_OK;\n\t\t\t\t\tbreak;\n\t\t\t\t}");
12193 if (!is_invisible(typ->id->name))
12194 fprintf(fout,"\n\t\t\tif (soap->error == SOAP_NO_TAG)");
12195 else
12196 fprintf(fout,"\n\t\t\tif (soap_flag && soap->error == SOAP_NO_TAG)");
12197 fprintf(fout,"\n\t\t\t\tbreak;");
12198 fprintf(fout,"\n\t\t\tif (soap->error)\n\t\t\t\treturn NULL;");
12199 fprintf(fout,"\n\t\t}");
12200 }
12201 }
12202 if (!is_discriminant(typ))
12203 { i=0;
12204 for (t = table; t; t = t->prev)
12205 i++;
12206 for (; i > 0; i--)
12207 { t = table;
12208 for (j = 0; j < i-1; j++)
12209 t = t->prev;
12210 for (p = t->list; p; p = p->next)
12211 { if (is_repetition(p))
12212 { fprintf(fout, "\n\t\tif (a->%s::%s)\n\t\t\tsoap_pop_block(soap, soap_blist_%s%d);", ident(t->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), i);
12213 fprintf(fout, "\n\t\tif (a->%s::%s)\n\t\t\ta->%s::%s = (%s)soap_save_block(soap, soap_blist_%s%d, NULL, 1);\n\t\telse\n\t\t{\ta->%s::%s = NULL;\n\t\t\tif (soap_blist_%s%d)\n\t\t\t\tsoap_end_block(soap, soap_blist_%s%d);\n\t\t}", ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->next->sym->name), c_type(p->next->info.typ), ident(p->next->sym->name), i, ident(t->sym->name), ident(p->next->sym->name), ident(p->next->sym->name), i, ident(p->next->sym->name), i);
12214 p = p->next;
12215 }
12216 }
12217 }
12218 }
12219 if (has_getter(typ))
12220 fprintf(fout,"\n\t\tif (a->get(soap))\n\t\t\treturn NULL;");
12221 if (!is_invisible(typ->id->name))
12222 { fprintf(fout, "\n\t\tif (soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12223 fprintf(fout,"\n\t}\n\telse\n\t{");
12224 fprintf(fout,"\ta = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, soap_copy_%s);",c_type_id(typ, "*"), soap_type(typ), c_type(typ), c_ident(typ));
12225 fprintf(fout, "\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12226 fprintf(fout, "\n\t}");
12227 }
12228 if (!is_discriminant(typ))
12229 { a=0;
12230 i = 0;
12231 for (t = table; t; t = t->prev)
12232 i++;
12233 for (; i > 0; i--)
12234 { t = table;
12235 for (j = 0; j < i-1; j++)
12236 t = t->prev;
12237 for (p = t->list; p; p = p->next)
12238 { if (p->info.minOccurs > 0 && p->info.maxOccurs >= 0 && !(p->info.sto & (Sconst | Sprivate | Sprotected)) && !(p->info.sto & Sattribute) && p->info.typ->type != Tfun && !is_void(p->info.typ) && !is_transient(p->info.typ) && !is_template(p->info.typ) && !is_repetition(p) && !is_choice(p) && p->info.hasval == False)
12239 { if (is_item(p))
12240 continue;
12241 if (is_anytype(p))
12242 p = p->next;
12243 if (a==0)
12244 { fprintf(fout,"\n\tif (%s(soap_flag_%s%d > " SOAP_LONG_FORMAT, strict_check(), ident(p->sym->name), i, p->info.maxOccurs - p->info.minOccurs);
12245 a=1;
12246 }
12247 else
12248 fprintf(fout," || soap_flag_%s%d > " SOAP_LONG_FORMAT, ident(p->sym->name), i, p->info.maxOccurs - p->info.minOccurs);
12249 }
12250 else if (is_template(p->info.typ))
12251 { if (p->info.minOccurs > 0)
12252 { if (p->info.typ->type == Tpointer)
12253 { if (a==0)
12254 { fprintf(fout,"\n\tif (%s(!a->%s::%s || a->%s::%s->size() < " SOAP_LONG_FORMAT, strict_check(), ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12255 a=1;
12256 }
12257 else
12258 fprintf(fout," || !a->%s::%s || a->%s::%s->size() < " SOAP_LONG_FORMAT, ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12259 }
12260 else
12261 { if (a==0)
12262 { fprintf(fout,"\n\tif (%s(a->%s::%s.size() < " SOAP_LONG_FORMAT, strict_check(), ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12263 a=1;
12264 }
12265 else
12266 fprintf(fout," || a->%s::%s.size() < " SOAP_LONG_FORMAT, ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12267 }
12268 }
12269 if ( p->info.maxOccurs > 1)
12270 { if (p->info.typ->type == Tpointer)
12271 { if (a==0)
12272 { fprintf(fout,"\n\tif (%s((a->%s::%s && a->%s::%s->size() > " SOAP_LONG_FORMAT ")", strict_check(), ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12273 a=1;
12274 }
12275 else
12276 fprintf(fout," || (a->%s::%s && a->%s::%s->size() > " SOAP_LONG_FORMAT ")", ident(t->sym->name), ident(p->sym->name), ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12277 }
12278 else
12279 { if (a==0)
12280 { fprintf(fout,"\n\tif (%s(a->%s::%s.size() > " SOAP_LONG_FORMAT, strict_check(), ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12281 a=1;
12282 }
12283 else
12284 fprintf(fout," || a->%s::%s.size() > " SOAP_LONG_FORMAT, ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12285 }
12286 }
12287 }
12288 else if (is_repetition(p))
12289 { if (p->info.minOccurs > 0)
12290 { if (a==0)
12291 { fprintf(fout,"\n\tif (%s(a->%s::%s < " SOAP_LONG_FORMAT, strict_check(), ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12292 a=1;
12293 }
12294 else
12295 fprintf(fout," || a->%s::%s < " SOAP_LONG_FORMAT, ident(t->sym->name), ident(p->sym->name), p->info.minOccurs);
12296 }
12297 if (p->info.maxOccurs > 1)
12298 { if (a==0)
12299 { fprintf(fout,"\n\tif (%s(a->%s::%s > " SOAP_LONG_FORMAT, strict_check(), ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12300 a=1;
12301 }
12302 else
12303 fprintf(fout," || a->%s::%s > " SOAP_LONG_FORMAT, ident(t->sym->name), ident(p->sym->name), p->info.maxOccurs);
12304 }
12305 p = p->next;
12306 }
12307 else if (is_choice(p))
12308 { if (p->info.minOccurs != 0)
12309 { if (a==0)
12310 { fprintf(fout,"\n\tif (%s(soap_flag_%s%d", strict_check(), ident(p->next->sym->name), i);
12311 a=1;
12312 }
12313 else
12314 fprintf(fout," || soap_flag_%s%d", ident(p->next->sym->name), i);
12315 }
12316 p = p->next;
12317 }
12318 }
12319 }
12320 if (a)
12321 fprintf(fout,"))\n\t{\tsoap->error = SOAP_OCCURS;\n\t\treturn NULL;\n\t}");
12322 }
12323 fprintf(fout,"\n\treturn a;\n}");
12324 }
12325
12326 break;
12327
12328 case Tunion:
12329 if (is_external(typ))
12330 { fprintf(fhead, "\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, int*, %s);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12331 return;
12332 }
12333 fprintf(fhead, "\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, int*, %s);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12334 fprintf(fout, "\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, int *choice, %s)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
12335 fprintf(fout, "\tsoap->error = SOAP_TAG_MISMATCH;");
12336 table = (Table *)typ->ref;
12337 for (p = table->list; p; p = p->next)
12338 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
12339 fprintf(fout, "\n\t/* non-serializable %s skipped */", ident(p->sym->name));
12340 else if (is_transient(p->info.typ))
12341 fprintf(fout, "\n\t/* transient %s skipped */", ident(p->sym->name));
12342 else if (p->info.sto & Sattribute)
12343 ;
12344 else if (is_repetition(p))
12345 ;
12346 else if (is_anytype(p))
12347 ;
12348 else if (!is_invisible(p->sym->name))
12349 { if (is_unmatched(p->sym))
12350 { if (is_XML(p->info.typ) && is_string(p->info.typ))
12351 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inliteral(soap, NULL, &a->%s))", ident(p->sym->name));
12352 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
12353 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inwliteral(soap, NULL, &a->%s))", ident(p->sym->name));
12354 else if (p->info.typ->type == Tarray)
12355 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, NULL, a->%s, \"%s\"))", c_ident(p->info.typ),ident(p->sym->name),xsi_type(p->info.typ));
12356 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
12357 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && a->%s.soap_in(soap, NULL, \"%s\"))", ident(p->sym->name), xsi_type(p->info.typ));
12358 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
12359 { if (p->info.typ->type == Tpointer)
12360 fprintf(fout, "\n\ta->%s = NULL;", ident(p->sym->name));
12361 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, NULL, &a->%s, \"%s\"))", c_ident(p->info.typ),ident(p->sym->name),xsi_type(p->info.typ));
12362 }
12363 }
12364 else
12365 { if (is_XML(p->info.typ) && is_string(p->info.typ))
12366 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inliteral(soap, \"%s\", &a->%s))", ns_add(p, nse), ident(p->sym->name));
12367 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
12368 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inwliteral(soap, \"%s\", &a->%s))", ns_add(p, nse), ident(p->sym->name));
12369 else if (p->info.typ->type == Tarray)
12370 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, \"%s\", a->%s, \"%s\"))", c_ident(p->info.typ),ns_add(p, nse),ident(p->sym->name),xsi_type(p->info.typ));
12371 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
12372 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && a->%s.soap_in(soap, \"%s\", \"%s\"))", ident(p->sym->name),ns_add(p, nse),xsi_type(p->info.typ));
12373 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
12374 { if (p->info.typ->type == Tpointer)
12375 fprintf(fout, "\n\ta->%s = NULL;", ident(p->sym->name));
12376 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, \"%s\", &a->%s, \"%s\"))", c_ident(p->info.typ),ns_add(p, nse),ident(p->sym->name),xsi_type(p->info.typ));
12377 }
12378 }
12379 fprintf(fout, "\n\t{\t*choice = SOAP_UNION_%s_%s;", c_ident(typ), ident(p->sym->name));
12380 fprintf(fout, "\n\t\treturn a;");
12381 fprintf(fout, "\n\t}");
12382 fflush(fout);
12383 }
12384 }
12385 table = (Table *)typ->ref;
12386 for (p = table->list; p; p = p->next)
12387 { if (p->info.sto & (Sconst | Sprivate | Sprotected))
12388 ;
12389 else if (is_transient(p->info.typ))
12390 ;
12391 else if (p->info.sto & Sattribute)
12392 ;
12393 else if (is_repetition(p))
12394 ;
12395 else if (is_anytype(p))
12396 ;
12397 else if (is_invisible(p->sym->name))
12398 { if (is_XML(p->info.typ) && is_string(p->info.typ))
12399 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inliteral(soap, \"%s\", &a->%s))", ns_add(p, nse), ident(p->sym->name));
12400 else if (is_XML(p->info.typ) && is_wstring(p->info.typ))
12401 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_inwliteral(soap, \"%s\", &a->%s))", ns_add(p, nse), ident(p->sym->name));
12402 else if (p->info.typ->type == Tarray)
12403 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, \"%s\", a->%s, NULL))", c_ident(p->info.typ),ns_add(p, nse),ident(p->sym->name));
12404 else if (p->info.typ->type == Tclass && !is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_typedef(p->info.typ))
12405 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && a->%s.soap_in(soap, \"%s\", NULL))", ident(p->sym->name),ns_add(p, nse));
12406 else if (p->info.typ->type != Tfun && !is_void(p->info.typ))
12407 { if (p->info.typ->type == Tpointer)
12408 fprintf(fout, "\n\ta->%s = NULL;", ident(p->sym->name));
12409 fprintf(fout, "\n\tif (soap->error == SOAP_TAG_MISMATCH && soap_in_%s(soap, \"%s\", &a->%s, NULL))", c_ident(p->info.typ),ns_add(p, nse),ident(p->sym->name));
12410 }
12411 fprintf(fout, "\n\t{\t*choice = SOAP_UNION_%s_%s;", c_ident(typ), ident(p->sym->name));
12412 fprintf(fout, "\n\t\treturn a;");
12413 fprintf(fout, "\n\t}");
12414 fflush(fout);
12415 }
12416 }
12417 fprintf(fout, "\n\t*choice = -1;\n\tif (!soap->error)\n\t\tsoap->error = SOAP_TAG_MISMATCH;\n\treturn NULL;\n}");
12418 break;
12419
12420 case Tpointer:
12421
12422 if (is_external(typ))
12423 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12424 return;
12425 }
12426 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12427 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
12428 fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 1, NULL))");
12429 fprintf(fout,"\n\t\treturn NULL;");
12430
12431 if (is_template(typ))
12432 { fprintf(fout,"\n\tsoap_revert(soap);");
12433 fprintf(fout,"\n\tif (!a)\n\t{\tif (!(a = (%s)soap_malloc(soap, sizeof(%s))))\n\t\t\treturn NULL;\n\t\t*a = NULL;\n\t}", c_type_id(typ, "*"), c_type(typ));
12434 fprintf(fout,"\n\tif (!(*a = soap_in_%s(soap, tag, *a, type)))\n\t\treturn NULL;", c_ident((Tnode*)typ->ref));
12435 fprintf(fout,"\n\treturn a;\n}");
12436 }
12437 else if(((Tnode *) typ->ref)->type == Tclass && !is_external((Tnode*)typ->ref) && !is_volatile((Tnode*)typ->ref) && !is_typedef((Tnode*)typ->ref))
12438 {
12439 fprintf(fout,"\n\tif (!a)\n\t\tif (!(a = (%s)soap_malloc(soap, sizeof(%s))))\n\t\t\treturn NULL;", c_type_id(typ, "*"), c_type(typ));
12440 fprintf(fout,"\n\t*a = NULL;\n\tif (!soap->null && *soap->href != '#')");
12441 fprintf(fout,"\n\t{\tsoap_revert(soap);");
12442 fprintf(fout, "\n\t\tif (!(*a = (%s)soap_instantiate_%s(soap, -1, soap->type, soap->arrayType, NULL)))", c_type(typ), c_ident((Tnode*)typ->ref));
12443 fprintf(fout, "\n\t\t\treturn NULL;");
12444 fprintf(fout, "\n\t\t(*a)->soap_default(soap);");
12445 fprintf(fout, "\n\t\tif (!(*a)->soap_in(soap, tag, NULL))");
12446 fprintf(fout, "\n\t\t\treturn NULL;");
12447 fprintf(fout,"\n\t}\n\telse\n\t{\t%s p = (%s)soap_id_lookup(soap, soap->href, (void**)a, %s, sizeof(%s), %d);", c_type_id(typ, "*"), c_type_id(typ, "*"), soap_type((Tnode*)typ->ref), c_type((Tnode*)typ->ref), reflevel((Tnode*)typ->ref) );
12448 if (((Tnode*)typ->ref)->type == Tclass)
12449 { table = (Table*)((Tnode*)typ->ref)->ref;
12450 for (p = classtable->list; p; p = p->next)
12451 { if (p->info.typ->type == Tclass)
12452 { Table *q = (Table*)p->info.typ->ref;
12453 if (q)
12454 for (q = q->prev; q; q = q->prev)
12455 if (q == table)
12456 fprintf(fout, "\n\t\tif (!p && soap->error == SOAP_HREF)\n\t\t{\tsoap->error = SOAP_OK;\n\t\t\tp = (%s)soap_id_lookup(soap, soap->href, (void**)a, %s, sizeof(%s), 0);\n\t\t}", c_type_id(typ, "*"), soap_type(p->info.typ), c_type(p->info.typ));
12457 }
12458 }
12459 }
12460 fprintf(fout,"\n\t\ta = p;");
12461 fprintf(fout,"\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12462 fprintf(fout,"\n\t}\n\treturn a;\n}");
12463 }
12464 else
12465 {
12466 fprintf(fout,"\n\tif (!a)\n\t\tif (!(a = (%s)soap_malloc(soap, sizeof(%s))))\n\t\t\treturn NULL;", c_type_id(typ, "*"), c_type(typ));
12467 fprintf(fout,"\n\t*a = NULL;\n\tif (!soap->null && *soap->href != '#')");
12468 fprintf(fout,"\n\t{\tsoap_revert(soap);");
12469 fprintf(fout,"\n\t\tif (!(*a = soap_in_%s(soap, tag, *a, type)))", c_ident((Tnode*)typ->ref));
12470 fprintf(fout,"\n\t\t\treturn NULL;");
12471
12472 fprintf(fout,"\n\t}\n\telse\n\t{\ta = (%s)soap_id_lookup(soap, soap->href, (void**)a, %s, sizeof(%s), %d);", c_type_id(typ, "*"), soap_type((Tnode*)typ->ref), c_type((Tnode*)typ->ref), reflevel((Tnode*)typ->ref) );
12473 fprintf(fout,"\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12474 fprintf(fout,"\n\t}\n\treturn a;\n}");
12475 }
12476
12477 break;
12478
12479 case Tarray:
12480 temp = typ;
12481 while(temp->type == Tarray){
12482 temp = (Tnode*)temp->ref;
12483 }
12484 if (is_external(typ))
12485 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);",c_type_id(temp, "*"),c_ident(typ),c_type(typ));
12486 return;
12487 }
12488 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);",c_type_id(temp, "*"),c_ident(typ),c_type(typ));
12489 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{",c_type_id(temp, "*"),c_ident(typ),c_type_id(typ, "a"));
12490 fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 0, NULL))");
12491 fprintf(fout,"\n\t\treturn NULL;");
12492 fprintf(fout,"\n\tif (soap_match_array(soap, type))");
12493 fprintf(fout,"\n\t{\tsoap->error = SOAP_TYPE;\n\t\treturn NULL;\n\t}");
12494 fprintf(fout,"\n\ta = (%s)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL);", c_type_id((Tnode*)typ->ref, "(*)"), soap_type(typ), c_type(typ));
12495 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
12496 fprintf(fout,"\n\tsoap_default_%s(soap, a);",c_ident(typ));
12497 fprintf(fout,"\n\tif (soap->body && !*soap->href)");
12498 total=get_dimension(typ);
12499 n=(Tnode*)typ->ref;
12500 cardinality = 1;
12501 while(n->type==Tarray)
12502 {
12503 total=total*get_dimension(n);
12504 n = (Tnode*)n->ref;
12505 cardinality++;
12506 }
12507 fprintf(fout,"\n\t{\tint i;\n\t\tfor (i = 0; i < %d; i++)",get_dimension(typ));
12508 fprintf(fout,"\n\t\t{\tsoap_peek_element(soap);\n\t\t\tif (soap->position)\n\t\t\t{\ti = soap->positions[0];\n\t\t\t\tif (i < 0 || i >= %d)\n\t\t\t\t{\tsoap->error = SOAP_IOB;\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t}", get_dimension(typ));
12509 fprintf(fout,"\n\t\t\tif (!soap_in_%s(soap, NULL, a", c_ident((Tnode*)typ->ref));
12510
12511 if(cardinality > 1){
12512 fprintf(fout,"[i]");
12513 }else {
12514 fprintf(fout,"+i");
12515 }
12516 fprintf(fout,", \"%s\"))", xsi_type((Tnode*)typ->ref));
12517 fprintf(fout,"\n\t\t\t{\tif (soap->error != SOAP_NO_TAG)\n\t\t\t\t\treturn NULL;");
12518 fprintf(fout,"\n\t\t\t\tsoap->error = SOAP_OK;");
12519 fprintf(fout,"\n\t\t\t\tbreak;");
12520 fprintf(fout,"\n\t\t\t}");
12521 fprintf(fout,"\n\t\t}");
12522 fprintf(fout,"\n\t\tif (soap->mode & SOAP_C_NOIOB)\n\t\t\twhile (soap_element_end_in(soap, tag) == SOAP_SYNTAX_ERROR)\n\t\t\t{\tsoap->peeked = 1;\n\t\t\t\tsoap_ignore_element(soap);\n\t\t\t}");
12523 fprintf(fout,"\n\t\telse if (soap_element_end_in(soap, tag))\n\t\t{\tif (soap->error == SOAP_SYNTAX_ERROR)\n\t\t\t\tsoap->error = SOAP_IOB;\n\t\t\treturn NULL;\n\t\t}");
12524 fprintf(fout,"\n\t}\n\telse\n\t{\ta = (%s)soap_id_forward(soap, soap->href, (void*)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL), 0, %s, 0, sizeof(%s), 0, NULL);", c_type_id((Tnode*)typ->ref, "(*)"), soap_type(typ), c_type(typ), soap_type(typ), c_type(typ));
12525 fprintf(fout,"\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12526 fprintf(fout,"\n\t}\n\treturn (%s)a;\n}", c_type_id(temp, "*"));
12527 break;
12528
12529 case Tenum:
12530 if (is_external(typ))
12531 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);",c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12532 return;
12533 }
12534 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);",c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12535 fprintf(fhead,"\n\nSOAP_FMAC3S int SOAP_FMAC4S soap_s2%s(struct soap*, const char*, %s);",c_ident(typ),c_type_id(typ, "*"));
12536 fprintf(fout,"\n\nSOAP_FMAC3S int SOAP_FMAC4S soap_s2%s(struct soap *soap, const char *s, %s)\n{",c_ident(typ),c_type_id(typ, "*a"));
12537 if (is_typedef(typ))
12538 fprintf(fout, "\n\treturn soap_s2%s(soap, s, a);\n}", t_ident(typ));
12539 else if (!is_mask(typ))
12540 { fprintf(fout, "\n\tconst struct soap_code_map *map;");
12541 t = (Table*)typ->ref;
12542 if (t && t->list && has_ns_eq(NULL, ns_remove1(t->list->sym->name)))
12543 { fprintf(fout, "\n\tchar *t;");
12544 fprintf(fout, "\n\tif (!s)\n\t\treturn soap->error;");
12545 fprintf(fout, "\n\tsoap_s2QName(soap, s, &t, %ld, %ld);", minlen(typ), maxlen(typ));
12546 fprintf(fout, "\n\tmap = soap_code(soap_codes_%s, t);", c_ident(typ));
12547 }
12548 else
12549 { fprintf(fout, "\n\tif (!s)\n\t\treturn soap->error;");
12550 fprintf(fout, "\n\tmap = soap_code(soap_codes_%s, s);", c_ident(typ));
12551 }
12552 min = 0;
12553 max = 0;
12554 for (t = (Table*)typ->ref; t; t = t->prev)
12555 { for (p = t->list; p; p = p->next)
12556 { if (p->info.val.i < min)
12557 min = (unsigned long)p->info.val.i;
12558 if (p->info.val.i > max)
12559 max = (unsigned long)p->info.val.i;
12560 }
12561 }
12562 if (is_boolean(typ))
12563 fprintf(fout, "\n\tif (map)\n\t\t*a = (%s)(map->code != 0);\n\telse\n\t{\tlong n;\n\t\tif (soap_s2long(soap, s, &n) || n < 0 || n > 1)\n\t\t\treturn soap->error = SOAP_TYPE;\n\t\t*a = (%s)(n != 0);\n\t}\n\treturn SOAP_OK;\n}", c_type(typ), c_type(typ));
12564 else if (sflag)
12565 fprintf(fout, "\n\tif (map)\n\t\t*a = (%s)map->code;\n\telse\n\t\treturn soap->error = SOAP_TYPE;\n\treturn SOAP_OK;\n}", c_type(typ));
12566 else
12567 fprintf(fout, "\n\tif (map)\n\t\t*a = (%s)map->code;\n\telse\n\t{\tlong n;\n\t\tif (soap_s2long(soap, s, &n) || ((soap->mode & SOAP_XML_STRICT) && (n < %ld || n > %ld)))\n\t\t\treturn soap->error = SOAP_TYPE;\n\t\t*a = (%s)n;\n\t}\n\treturn SOAP_OK;\n}", c_type(typ), min, max, c_type(typ));
12568 }
12569 else
12570 { t = (Table*)typ->ref;
12571 if (t && t->list && has_ns_eq(NULL, ns_remove1(t->list->sym->name)))
12572 { fprintf(fout, "\n\tchar *t;");
12573 fprintf(fout, "\n\tsoap_s2QName(soap, s, &t, %ld, %ld);", minlen(typ), maxlen(typ));
12574 fprintf(fout, "\n\t*a = (%s)soap_code_bits(soap_codes_%s, t);", c_type(typ), c_ident(typ));
12575 }
12576 else
12577 fprintf(fout, "\n\t*a = (%s)soap_code_bits(soap_codes_%s, s);", c_type(typ), c_ident(typ));
12578 fprintf(fout, "\n\treturn SOAP_OK;\n}");
12579 }
12580 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{",c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
12581 if (is_boolean(typ))
12582 { fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 0, NULL))");
12583 fprintf(fout,"\n\t\treturn NULL;");
12584 fprintf(fout,"\n\tif (*soap->type && soap_match_tag(soap, soap->type, type) && soap_match_tag(soap, soap->type, \":boolean\"))");
12585 fprintf(fout,"\n\t{\tsoap->error = SOAP_TYPE;\n\t\treturn NULL;\n\t}");
12586 }
12587 else if (typ->sym)
12588 { fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 0, NULL))");
12589 fprintf(fout,"\n\t\treturn NULL;");
12590 fprintf(fout,"\n\tif (*soap->type && soap_match_tag(soap, soap->type, type) && soap_match_tag(soap, soap->type, \"%s\"))", base_type(typ, ""));
12591 fprintf(fout,"\n\t{\tsoap->error = SOAP_TYPE;\n\t\treturn NULL;\n\t}");
12592 }
12593 else
12594 { fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 0, type))");
12595 fprintf(fout,"\n\t\treturn NULL;");
12596 }
12597 fprintf(fout,"\n\ta = (%s)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL);", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
12598 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
12599 fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{");
12600 fprintf(fout,"\tif (!a || soap_s2%s(soap, soap_value(soap), a) || soap_element_end_in(soap, tag))\n\t\t\treturn NULL;", c_ident(typ));
12601 fprintf(fout, "\n\t}\n\telse\n\t{\ta = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, NULL);", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
12602 fprintf(fout, "\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12603 fprintf(fout,"\n\t}\n\treturn a;\n}");
12604 break;
12605
12606 case Ttemplate:
12607 if (is_external(typ))
12608 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12609 return;
12610 }
12611 if (is_typedef(typ))
12612 { fprintf(fhead, "\n\n#define soap_in_%s soap_in_%s\n", c_ident(typ), t_ident(typ));
12613 return;
12614 }
12615 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12616 fprintf(fout, "\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)\n{", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
12617 n = (Tnode*)typ->ref;
12618 fprintf(fout, "\n\t(void)type; /* appease -Wall -Werror */");
12619 fprintf(fout, "\n\tshort soap_flag;");
12620 fprintf(fout, "\n\tfor (soap_flag = 0;; soap_flag = 1)\n\t{\t%s;", c_type_id(n, "n"));
12621 fprintf(fout, "\n\t\tif (tag && *tag != '-')\n\t\t{\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\t\t\tbreak;\n\t\t\tsoap_revert(soap);\n\t\t}\n\t\t");
12622 if (n->type == Tpointer)
12623 fprintf(fout,"n = NULL;");
12624 else if (n->type == Tarray)
12625 fprintf(fout,"soap_default_%s(soap, &n);", c_ident(n));
12626 else if (n->type==Tclass && !is_external(n) && !is_volatile(n) && !is_typedef(n))
12627 fprintf(fout,"n.soap_default(soap);");
12628 else if (n->type != Tfun && !is_void(n) && !is_XML(n))
12629 fprintf(fout,"soap_default_%s(soap, &n);", c_ident(n));
12630 fprintf(fout, "\n\t\tif (tag && *tag != '-' && (*soap->id || *soap->href))");
12631 fprintf(fout, "\n\t\t{\tif (!soap_container_id_forward(soap, *soap->id?soap->id:soap->href, a, (size_t)a->size(), %s, %s, sizeof(%s), %d))\n\t\t\t\tbreak;\n\t\t\t", soap_type(reftype(n)), soap_type(typ), c_type(reftype(n)), reflevel(n));
12632 if (is_XML(n) && is_string(n))
12633 fprintf(fout, "if (!soap_inliteral(soap, tag, NULL))");
12634 else if (is_XML(n) && is_wstring(n))
12635 fprintf(fout, "if (!soap_inwliteral(soap, tag, NULL))");
12636 else if (n->type==Tarray)
12637 fprintf(fout, "if (!soap_in_%s(soap, tag, NULL, \"%s\"))", c_ident(n),xsi_type(n));
12638 else if (n->type != Tfun && !is_void(n))
12639 fprintf(fout, "if (!soap_in_%s(soap, tag, NULL, \"%s\"))", c_ident(n),xsi_type(n));
12640 fprintf(fout, "\n\t\t\t\tbreak;\n\t\t}\n\t\telse ");
12641 if (is_XML(n) && is_string(n))
12642 fprintf(fout, "if (!soap_inliteral(soap, tag, &n))");
12643 else if (is_XML(n) && is_wstring(n))
12644 fprintf(fout, "if (!soap_inwliteral(soap, tag, &n))");
12645 else if (n->type==Tarray)
12646 fprintf(fout, "if (!soap_in_%s(soap, tag, &n, \"%s\"))", c_ident(n),xsi_type(n));
12647 else if (n->type != Tfun && !is_void(n))
12648 fprintf(fout, "if (!soap_in_%s(soap, tag, &n, \"%s\"))", c_ident(n),xsi_type(n));
12649 fprintf(fout, "\n\t\t\tbreak;");
12650 fprintf(fout, "\n\t\tif (!a && !(a = soap_new_%s(soap, -1)))\n\t\t\treturn NULL;", c_ident(typ));
12651 if ((!strcmp(typ->id->name, "std::vector") || !strcmp(typ->id->name, "std::deque")) && (is_primitive(n) || n->type == Tpointer))
12652 fprintf(fout, "\n\t\ta->push_back(n);");
12653 else
12654 {
12655 if (is_primitive(n) || n->type == Tpointer)
12656 fprintf(fout, "\n\t\ta->insert(a->end(), n);");
12657 else
12658 fprintf(fout, "\n\t\tsoap_update_pointers(soap, (char*)&n, (char*)&n + sizeof(n), (char*)&(*a->insert(a->end(), n)), (char*)&n);");
12659 }
12660 fprintf(fout, "\n\t\tif (!tag || *tag == '-')\n\t\t\treturn a;\n\t}\n\tif (soap_flag && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG))\n\t{\tsoap->error = SOAP_OK;\n\t\treturn a;\n\t}\n\treturn NULL;\n}");
12661 break;
12662 default: break;
12663 }
12664 fflush(fout);
12665 }
12666
12667
12668 void
12669 soap_in_Darray(Tnode *typ)
12670 { int i, j, d;
12671 Entry *p;
12672 Table *t, *table;
12673 char *nsa = ns_qualifiedAttribute(typ);
12674
12675 table=(Table *)typ->ref;
12676 p = is_dynamic_array(typ);
12677 d = get_Darraydims(typ);
12678
12679 if (is_external(typ))
12680 { fprintf(fhead,"\nSOAP_FMAC1 %s SOAP_FMAC2 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12681 return;
12682 }
12683 fprintf(fhead,"\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap*, const char*, %s, const char*);", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*"));
12684 if (typ->type == Tclass && !is_volatile(typ) && !is_typedef(typ))
12685 { fprintf(fout,"\n\nvoid *%s::soap_in(struct soap *soap, const char *tag, const char *type)", c_type(typ));
12686 fprintf(fout,"\n{\treturn soap_in_%s(soap, tag, this, type);\n}", c_ident(typ));
12687 }
12688 fflush(fout);
12689 fprintf(fout,"\n\nSOAP_FMAC3 %s SOAP_FMAC4 soap_in_%s(struct soap *soap, const char *tag, %s, const char *type)", c_type_id(typ, "*"),c_ident(typ),c_type_id(typ, "*a"));
12690 if ((has_ns(typ) || is_untyped(typ)) && is_binary(typ))
12691 fprintf(fout,"\n{\n\t(void)type; /* appease -Wall -Werror */");
12692 else if (d)
12693 fprintf(fout,"\n{\tint i, j, n;\n\t%s;", c_type_id(p->info.typ, "p"));
12694 else
12695 fprintf(fout,"\n{\tint i, j;\n\t%s;", c_type_id(p->info.typ, "p"));
12696 fprintf(fout,"\n\tif (soap_element_begin_in(soap, tag, 1, NULL))\n\t\treturn NULL;");
12697 if (has_ns(typ) || is_untyped(typ))
12698 { if (is_hexBinary(typ))
12699 fprintf(fout,"\n\tif (*soap->type && soap_match_tag(soap, soap->type, type) && soap_match_tag(soap, soap->type, \":hexBinary\"))");
12700 else if (is_binary(typ))
12701 fprintf(fout,"\n\tif (*soap->type && soap_match_tag(soap, soap->type, type) && soap_match_tag(soap, soap->type, \":base64Binary\") && soap_match_tag(soap, soap->type, \":base64\"))");
12702 else
12703 fprintf(fout,"\n\tif (*soap->type && soap_match_array(soap, \"%s\") && soap_match_tag(soap, soap->type, type))", xsi_type((Tnode*)p->info.typ->ref));
12704 }
12705 else
12706 fprintf(fout,"\n\tif (soap_match_array(soap, type))");
12707 fprintf(fout,"\n\t{\tsoap->error = SOAP_TYPE;\n\t\treturn NULL;\n\t}");
12708 if (typ->type == Tclass)
12709 { fprintf(fout,"\n\ta = (%s)soap_class_id_enter(soap, soap->id, a, %s, sizeof(%s), soap->type, soap->arrayType);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
12710 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
12711 fprintf(fout,"\n\tif (soap->alloced)\n\t\ta->soap_default(soap);");
12712 for (t = (Table*)typ->ref; t; t = t->prev)
12713 { for (p = t->list; p; p = p->next)
12714 if (p->info.sto & Sattribute)
12715 soap_attr_value(p, ptr_cast(t, "a"), ident(p->sym->name), ns_add(p, nsa));
12716 }
12717 }
12718 else
12719 { fprintf(fout,"\n\ta = (%s)soap_id_enter(soap, soap->id, a, %s, sizeof(%s), 0, NULL, NULL, NULL);",c_type_id(typ, "*"), soap_type(typ), c_type(typ));
12720 fprintf(fout,"\n\tif (!a)\n\t\treturn NULL;");
12721 /*fprintf(fout,"\n\tif (soap->alloced)");*/
12722 fprintf(fout,"\n\tsoap_default_%s(soap, a);", c_ident(typ));
12723 for (t = (Table*)typ->ref; t; t = t->prev)
12724 { for (p = t->list; p; p = p->next)
12725 if (p->info.sto & Sattribute)
12726 soap_attr_value(p, "a", ident(p->sym->name), ns_add(p, nsa));
12727 }
12728 }
12729 fprintf(fout,"\n\tif (soap->body && !*soap->href)\n\t{");
12730 p = is_dynamic_array(typ);
12731 if ((has_ns(typ) || is_untyped(typ)) && is_binary(typ))
12732 { if (is_hexBinary(typ))
12733 fprintf(fout,"\n\t\ta->__ptr = soap_gethex(soap, &a->__size);");
12734 else
12735 { fprintf(fout,"\n\t\ta->__ptr = soap_getbase64(soap, &a->__size, 0);");
12736 if (is_attachment(typ))
12737 fprintf(fout,"\n#ifndef WITH_LEANER\n\t\tif (soap_xop_forward(soap, &a->__ptr, &a->__size, &a->id, &a->type, &a->options))\n\t\t\treturn NULL;\n#endif");
12738 }
12739 fprintf(fout,"\n\t\tif ((!a->__ptr && soap->error) || soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12740 }
12741 else
12742 { if (d)
12743 { fprintf(fout,"\n\t\tn = soap_getsizes(soap->arraySize, a->__size, %d);", d);
12744 if (has_offset(typ))
12745 fprintf(fout,"\n\t\tn -= j = soap_getoffsets(soap->arrayOffset, a->__size, a->__offset, %d);", d);
12746 else
12747 fprintf(fout,"\n\t\tn -= j = soap_getoffsets(soap->arrayOffset, a->__size, NULL, %d);", d);
12748 if (p->info.minOccurs > 0)
12749 fprintf(fout,"\n\t\tif (%sn >= 0 && n < " SOAP_LONG_FORMAT ")\n\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\treturn NULL;\n\t\t}", strict_check(), p->info.minOccurs);
12750 if (p->info.maxOccurs > 1)
12751 fprintf(fout,"\n\t\tif (%sn > " SOAP_LONG_FORMAT ")\n\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\treturn NULL;\n\t\t}", strict_check(), p->info.maxOccurs);
12752 fprintf(fout,"\n\t\tif (n >= 0)");
12753 if (((Tnode*)p->info.typ->ref)->type == Tclass
12754 || (((Tnode*)p->info.typ->ref)->type == Tstruct && !cflag))
12755 { fprintf(fout,"\n\t\t{\ta->%s = soap_new_%s(soap, n);", ident(p->sym->name), c_ident((Tnode*)p->info.typ->ref));
12756 if (!is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref) && ((Tnode*)p->info.typ->ref)->type == Tclass)
12757 fprintf(fout, "\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\t(a->%s+i)->%s::soap_default(soap);", ident(p->sym->name), c_type((Tnode*)p->info.typ->ref));
12758 else if (((Tnode*)p->info.typ->ref)->type == Tpointer)
12759 fprintf(fout, "\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12760 }
12761 else if (has_class((Tnode*)p->info.typ->ref))
12762 { fprintf(fout,"\n\t\t{\ta->%s = soap_new_%s(soap, n);", ident(p->sym->name), c_ident((Tnode*)p->info.typ->ref));
12763 fprintf(fout, "\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12764 }
12765 else
12766 { fprintf(fout,"\n\t\t{\ta->%s = (%s)soap_malloc(soap, n*sizeof(%s));", ident(p->sym->name), c_type_id((Tnode*)p->info.typ->ref, "*"), c_type((Tnode*)p->info.typ->ref));
12767 if (((Tnode*)p->info.typ->ref)->type == Tpointer)
12768 fprintf(fout, "\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\ta->%s[i] = NULL;", ident(p->sym->name));
12769 else if (!is_XML((Tnode*)p->info.typ->ref))
12770 fprintf(fout, "\n\t\t\tfor (i = 0; i < n; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12771 }
12772 fprintf(fout,"\n\t\t\tfor (i = 0; i < n; i++)");
12773 fprintf(fout,"\n\t\t\t{\tsoap_peek_element(soap);\n\t\t\t\tif (soap->position == %d)", d);
12774 fprintf(fout,"\n\t\t\t\t{\ti = ");
12775 for (i = 0; i < d; i++)
12776 { fprintf(fout,"soap->positions[%d]", i);
12777 for (j = 1; j < d-i; j++)
12778 fprintf(fout,"*a->__size[%d]", j);
12779 if (i < d-1)
12780 fprintf(fout,"+");
12781 }
12782 fprintf(fout,"-j;");
12783 fprintf(fout,"\n\t\t\t\t\tif (i < 0 || i >= n)\n\t\t\t\t\t{\tsoap->error = SOAP_IOB;\n\t\t\t\t\t\treturn NULL;\n\t\t\t\t\t}\n\t\t\t\t}");
12784 fprintf(fout,"\n\t\t\t\tif (!soap_in_%s(soap, NULL, a->%s + i, \"%s\"))", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type((Tnode*)p->info.typ->ref));
12785 fprintf(fout,"\n\t\t\t\t{\tif (soap->error != SOAP_NO_TAG)\n\t\t\t\t\t\treturn NULL;");
12786 fprintf(fout,"\n\t\t\t\t\tsoap->error = SOAP_OK;");
12787 fprintf(fout,"\n\t\t\t\t\tbreak;");
12788 fprintf(fout,"\n\t\t\t\t}");
12789 }
12790 else
12791 { fprintf(fout,"\n\t\ta->__size = soap_getsize(soap->arraySize, soap->arrayOffset, &j);");
12792 if (has_offset(typ) && (p->next->next->info.sto & Sconst) == 0)
12793 { fprintf(fout,"\n\t\ta->__offset = j;");
12794 }
12795 if (p->info.minOccurs > 0)
12796 fprintf(fout,"\n\t\tif (%sa->__size >= 0 && a->__size < " SOAP_LONG_FORMAT ")\n\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\treturn NULL;\n\t\t}", strict_check(), p->info.minOccurs);
12797 if (p->info.maxOccurs > 1)
12798 fprintf(fout,"\n\t\tif (%sa->__size > " SOAP_LONG_FORMAT ")\n\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\treturn NULL;\n\t\t}", strict_check(), p->info.maxOccurs);
12799 fprintf(fout,"\n\t\tif (a->__size >= 0)");
12800 if (((Tnode*)p->info.typ->ref)->type == Tclass
12801 || (((Tnode*)p->info.typ->ref)->type == Tstruct && !cflag))
12802 { fprintf(fout,"\n\t\t{\ta->%s = soap_new_%s(soap, a->__size);", ident(p->sym->name), c_ident((Tnode*)p->info.typ->ref));
12803 if (!is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref) && ((Tnode*)p->info.typ->ref)->type == Tclass)
12804 fprintf(fout, "\n\t\t\tfor (i = 0; i < a->__size; i++)\n\t\t\t\t(a->%s+i)->%s::soap_default(soap);", ident(p->sym->name), c_type((Tnode*)p->info.typ->ref));
12805 else
12806 fprintf(fout, "\n\t\t\tfor (i = 0; i < a->__size; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12807 }
12808 else if (has_class((Tnode*)p->info.typ->ref))
12809 { fprintf(fout,"\n\t\t{\ta->%s = soap_new_%s(soap, a->__size);", ident(p->sym->name), c_ident((Tnode*)p->info.typ->ref));
12810 fprintf(fout, "\n\t\t\tfor (i = 0; i < a->__size; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12811 }
12812 else
12813 { fprintf(fout,"\n\t\t{\ta->%s = (%s)soap_malloc(soap, sizeof(%s) * a->__size);", ident(p->sym->name), c_type_id((Tnode*)p->info.typ->ref, "*"), c_type((Tnode*)p->info.typ->ref));
12814 if (((Tnode*)p->info.typ->ref)->type == Tpointer)
12815 fprintf(fout, "\n\t\t\tfor (i = 0; i < a->__size; i++)\n\t\t\t\ta->%s[i] = NULL;", ident(p->sym->name));
12816 else if (!is_XML((Tnode*)p->info.typ->ref))
12817 fprintf(fout, "\n\t\t\tfor (i = 0; i < a->__size; i++)\n\t\t\t\tsoap_default_%s(soap, a->%s+i);", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name));
12818 }
12819 fprintf(fout,"\n\t\t\tfor (i = 0; i < a->__size; i++)");
12820 fprintf(fout,"\n\t\t\t{\tsoap_peek_element(soap);\n\t\t\t\tif (soap->position)\n\t\t\t\t{\ti = soap->positions[0]-j;\n\t\t\t\t\tif (i < 0 || i >= a->__size)\n\t\t\t\t\t{\tsoap->error = SOAP_IOB;\n\t\t\t\t\t\treturn NULL;\n\t\t\t\t\t}\n\t\t\t\t}");
12821 if (is_XML((Tnode*)p->info.typ->ref) && is_string((Tnode*)p->info.typ->ref))
12822 fprintf(fout,"\n\t\t\t\tif (!soap_inliteral(soap, NULL, a->%s + i))", ident(p->sym->name));
12823 else if (is_XML((Tnode*)p->info.typ->ref) && is_wstring((Tnode*)p->info.typ->ref))
12824 fprintf(fout,"\n\t\t\t\tif (!soap_inwliteral(soap, NULL, a->%s + i))", ident(p->sym->name));
12825 else
12826 fprintf(fout,"\n\t\t\t\tif (!soap_in_%s(soap, NULL, a->%s + i, \"%s\"))", c_ident((Tnode*)p->info.typ->ref), ident(p->sym->name), xsi_type((Tnode*)p->info.typ->ref));
12827 fprintf(fout,"\n\t\t\t\t{\tif (soap->error != SOAP_NO_TAG)\n\t\t\t\t\t\treturn NULL;");
12828 fprintf(fout,"\n\t\t\t\t\tsoap->error = SOAP_OK;");
12829 fprintf(fout,"\n\t\t\t\t\tbreak;");
12830 fprintf(fout,"\n\t\t\t\t}");
12831 }
12832 fprintf(fout,"\n\t\t\t}\n\t\t}\n\t\telse");
12833 fprintf(fout,"\n\t\t{\tif (soap_new_block(soap) == NULL)\n\t\t\t\treturn NULL;");
12834 if (p->info.maxOccurs > 1)
12835 { if (d)
12836 fprintf(fout,"\n\t\t\tfor (a->__size[0] = 0; a->__size[0] <= " SOAP_LONG_FORMAT "; a->__size[0]++)", p->info.maxOccurs);
12837 else
12838 fprintf(fout,"\n\t\t\tfor (a->__size = 0; a->__size <= " SOAP_LONG_FORMAT "; a->__size++)", p->info.maxOccurs);
12839 }
12840 else
12841 { if (d)
12842 fprintf(fout,"\n\t\t\tfor (a->__size[0] = 0; ; a->__size[0]++)");
12843 else
12844 fprintf(fout,"\n\t\t\tfor (a->__size = 0; ; a->__size++)");
12845 }
12846 fprintf(fout,"\n\t\t\t{\tp = (%s)soap_push_block(soap, NULL, sizeof(%s));\n\t\t\t\tif (!p)\n\t\t\t\t\treturn NULL;", c_type(p->info.typ), c_type((Tnode*)p->info.typ->ref));
12847 if (((Tnode*)p->info.typ->ref)->type == Tclass || has_class((Tnode*)p->info.typ->ref) || (!cflag && ((Tnode*)p->info.typ->ref)->type == Tstruct))
12848 fprintf(fout,"\n\t\t\t\tSOAP_PLACEMENT_NEW(p, %s);", c_type((Tnode*)p->info.typ->ref));
12849 if (((Tnode*)p->info.typ->ref)->type == Tclass && !is_external((Tnode*)p->info.typ->ref) && !is_volatile((Tnode*)p->info.typ->ref) && !is_typedef((Tnode*)p->info.typ->ref))
12850 fprintf(fout,"\n\t\t\t\tp->soap_default(soap);");
12851 else if (((Tnode*)p->info.typ->ref)->type == Tpointer)
12852 fprintf(fout,"\n\t\t\t\t*p = NULL;");
12853 else if (!is_XML((Tnode*)p->info.typ->ref))
12854 fprintf(fout,"\n\t\t\t\tsoap_default_%s(soap, p);", c_ident((Tnode*)p->info.typ->ref));
12855 if (is_XML((Tnode*)p->info.typ->ref) && is_string((Tnode*)p->info.typ->ref))
12856 fprintf(fout,"\n\t\t\t\tif (!soap_inliteral(soap, NULL, p))");
12857 else if (is_XML((Tnode*)p->info.typ->ref) && is_wstring((Tnode*)p->info.typ->ref))
12858 fprintf(fout,"\n\t\t\t\tif (!soap_inwliteral(soap, NULL, p))");
12859 else
12860 fprintf(fout,"\n\t\t\t\tif (!soap_in_%s(soap, NULL, p, \"%s\"))", c_ident((Tnode*)p->info.typ->ref), xsi_type((Tnode*)p->info.typ->ref));
12861 fprintf(fout,"\n\t\t\t\t{\tif (soap->error != SOAP_NO_TAG)\n\t\t\t\t\t\treturn NULL;");
12862 fprintf(fout,"\n\t\t\t\t\tsoap->error = SOAP_OK;");
12863 fprintf(fout,"\n\t\t\t\t\tbreak;");
12864 fprintf(fout,"\n\t\t\t\t}");
12865 fprintf(fout,"\n\t\t\t}");
12866 fprintf(fout,"\n\t\t\tsoap_pop_block(soap, NULL);");
12867 if (p->info.minOccurs > 0)
12868 fprintf(fout,"\n\t\t\tif (%sa->__size < " SOAP_LONG_FORMAT ")\n\t\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\t\treturn NULL;\n\t\t\t}", strict_check(), p->info.minOccurs);
12869 if (p->info.maxOccurs > 1)
12870 fprintf(fout,"\n\t\t\tif (%sa->__size > " SOAP_LONG_FORMAT ")\n\t\t\t{\tsoap->error = SOAP_OCCURS;\n\t\t\t\treturn NULL;\n\t\t\t}", strict_check(), p->info.maxOccurs);
12871 if (((Tnode*)p->info.typ->ref)->type == Tclass
12872 || has_class((Tnode*)p->info.typ->ref)
12873 || (((Tnode*)p->info.typ->ref)->type == Tstruct && !cflag))
12874 fprintf(fout,"\n\t\t\tif (soap->blist->size)\n\t\t\t\ta->%s = soap_new_%s(soap, soap->blist->size/sizeof(%s));\n\t\t\telse\n\t\t\t\ta->%s = NULL;", ident(p->sym->name), c_ident((Tnode*)p->info.typ->ref), c_type((Tnode*)p->info.typ->ref), ident(p->sym->name));
12875 else
12876 fprintf(fout,"\n\t\t\ta->%s = (%s)soap_malloc(soap, soap->blist->size);", ident(p->sym->name), c_type(p->info.typ));
12877 fprintf(fout,"\n\t\t\tsoap_save_block(soap, NULL, (char*)a->%s, 1);", ident(p->sym->name));
12878 fprintf(fout,"\n\t\t}");
12879 fprintf(fout,"\n\t\tif (soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12880 }
12881 if (has_getter(typ))
12882 fprintf(fout,"\n\t\tif (a->get(soap))\n\t\t\treturn NULL;");
12883 fprintf(fout,"\n\t}\n\telse\n\t{\t");
12884 if (is_attachment(typ))
12885 fprintf(fout,"\n#ifndef WITH_LEANER\n\t\tif (*soap->href != '#')\n\t\t{\tif (soap_dime_forward(soap, &a->__ptr, &a->__size, &a->id, &a->type, &a->options))\n\t\t\t\treturn NULL;\n\t\t}\n\t\telse\n#endif\n\t\t\t");
12886 if (typ->type == Tclass)
12887 fprintf(fout,"a = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, soap_copy_%s);", c_type_id(typ, "*"), soap_type(typ), c_type(typ), c_ident(typ));
12888 else
12889 fprintf(fout,"a = (%s)soap_id_forward(soap, soap->href, (void*)a, 0, %s, 0, sizeof(%s), 0, NULL);", c_type_id(typ, "*"), soap_type(typ), c_type(typ));
12890 fprintf(fout,"\n\t\tif (soap->body && soap_element_end_in(soap, tag))\n\t\t\treturn NULL;");
12891 fprintf(fout,"\n\t}");
12892 fprintf(fout,"\n\treturn a;\n}");
12893 }
12894
12895 const char *
12896 cstring(const char *s)
12897 { size_t n;
12898 char *t;
12899 const char *r;
12900 for (n = 0, r = s; *r; n++, r++)
12901 if (*r == '"' || *r == '\\')
12902 n++;
12903 else if (*r < 32)
12904 n += 3;
12905 r = t = (char*)emalloc(n + 1);
12906 for (; *s; s++)
12907 { if (*s == '"' || *s == '\\')
12908 { *t++ = '\\';
12909 *t++ = *s;
12910 }
12911 else if (*s < 32)
12912 { sprintf(t, "\\%03o", (unsigned int)(unsigned char)*s);
12913 t += 4;
12914 }
12915 else
12916 *t++ = *s;
12917 }
12918 *t = '\0';
12919 return r;
12920 }
12921
12922 const char *
12923 xstring(const char *s)
12924 { size_t n;
12925 char *t;
12926 const char *r;
12927 for (n = 0, r = s; *r; n++, r++)
12928 { if (*r < 32 || *r >= 127)
12929 n += 4;
12930 else if (*r == '<' || *r == '>')
12931 n += 3;
12932 else if (*r == '&')
12933 n += 4;
12934 else if (*r == '"')
12935 n += 5;
12936 else if (*r == '\\')
12937 n += 1;
12938 }
12939 r = t = (char*)emalloc(n + 1);
12940 for (; *s; s++)
12941 { if (*s < 32 || *s >= 127)
12942 { sprintf(t, "&#%.2x;", (unsigned char)*s);
12943 t += 5;
12944 }
12945 else if (*s == '<')
12946 { strcpy(t, "&lt;");
12947 t += 4;
12948 }
12949 else if (*s == '>')
12950 { strcpy(t, "&gt;");
12951 t += 4;
12952 }
12953 else if (*s == '&')
12954 { strcpy(t, "&amp;");
12955 t += 5;
12956 }
12957 else if (*s == '"')
12958 { strcpy(t, "&quot;");
12959 t += 6;
12960 }
12961 else if (*s == '\\')
12962 { strcpy(t, "\\\\");
12963 t += 2;
12964 }
12965 else
12966 *t++ = *s;
12967 }
12968 *t = '\0';
12969 return r;
12970 }