?? symbol2.c
字號:
{ if (!Eptr->next || Eptr->next->info.typ->type != Tpointer) { sprintf(errbuf, "Field '%s' with leading __ not followed by a pointer field in class '%s'", Eptr->sym->name, typ->id->name); semwarn(errbuf); } } else if (!strncmp(Eptr->sym->name, "__", 2)) { sprintf(errbuf, "Field '%s' with leading __ not used in array or binary type class '%s'", Eptr->sym->name, typ->id->name); semwarn(errbuf); } } } if (!is_transient(typ)) { fprintf(fd,"\n\tvirtual void soap_default(struct soap*); "); fprintf(fd,"\n\tvirtual void soap_serialize(struct soap*) const;"); fprintf(fd,"\n\tvirtual void soap_mark(struct soap*) const;"); fprintf(fd,"\n\tvirtual void soap_put(struct soap*, const char*, const char*) const;"); fprintf(fd,"\n\tvirtual void soap_out(struct soap*, const char*, int, const char*) const;"); fprintf(fd,"\n\tvirtual void *soap_get(struct soap*, const char*, const char*);"); fprintf(fd,"\n\tvirtual void *soap_in(struct soap*, const char*, const char*); "); } fprintf(fd,"\n};"); } else { sprintf(errbuf, "class '%s' is empty", typ->id->name); semwarn(errbuf); } } if (!strcmp(typ->id->name, "SOAP_ENV__Header") || !strcmp(typ->id->name, "SOAP_ENV__Fault")) fprintf(fheader, "\n#endif");}voidgenerate_header(Table *t){ Entry *p, *q; fprintf(fheader, "\n/* Enumerations */"); if (enumtable) for (p = enumtable->list; p; p = p->next) { fprintf(fheader, "\n"); if (is_mask(p->info.typ)) fprintf(fheader, "\n/* Bitmask: */"); fprintf(fheader, "\nenum %s {", p->info.typ->id->name); if ((Table*)p->info.typ->ref) { q = ((Table*)p->info.typ->ref)->list; if (q) { fprintf(fheader, "%s = %lld", q->sym->name, q->info.val.i); for (q = q->next; q; q = q->next) fprintf(fheader, ", %s = %lld", q->sym->name, q->info.val.i); } } fprintf(fheader, "};"); } fprintf(fheader, "\n\n/* Classes and Structs */"); if (classtable) for (p = classtable->list; p; p = p->next) { fprintf(fheader, "\n\n"); gen_class(fheader, p->info.typ); } fprintf(fheader, "\n\n/* Typedefs */"); if (typetable) for (p = typetable->list; p; p = p->next) fprintf(fheader,"\n\n%s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name)); fprintf(fheader, "\n\n/* Variables */"); if (t) for (p = t->list; p; p = p->next) if (p->info.typ->type != Tfun) fprintf(fheader,"\n\nextern %s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name)); fflush(fheader);}voidget_namespace_prefixes(){ Symbol *p, *q; int i, n; char buf[256]; if (nslist) return; for (p = symlist; p; p = p->next) { if (*p->name != '~') { n = strlen(p->name)-2; for (i = 1; i < n; i++) { if (p->name[i] == '_' && p->name[i+1] == '_' && p->name[i+2] && p->name[i+2] != '_') { strncpy(buf, p->name, i); buf[i] = '\0'; if (!strcmp(buf, "SOAP_ENV") || !strcmp(buf, "SOAP_ENC") || !strcmp(buf, "xsd")) goto nsnext; for (q = nslist; q; q = q->next) if (!strcmp(q->name, buf)) goto nsnext; q = (Symbol*)emalloc(sizeof(Symbol)); q->name = (char*)emalloc(i+1); strcpy(q->name, buf); q->name[i] = '\0'; q->next = nslist; nslist = q; } } }nsnext: ; }}voidgenerate_schema(Table *t){ Entry *p; Symbol *ns, *ns1; char *name = NULL; char *URL = NULL; char *executable = NULL; char *URI = NULL; char *encoding = NULL; Service *sp, *sq; char buf[256]; FILE *fd; get_namespace_prefixes(); for (ns = nslist; ns; ns = ns->next) { for (sp = services; sp; sp = sp->next) if (!strcmp(sp->ns, ns->name)) { name = sp->name; URL = sp->URL; executable = sp->executable; URI = sp->URI; encoding = sp->encoding; if (name) fprintf(stderr, "Using %s service name: %s\n", ns->name, name); if (URL) fprintf(stderr, "Using %s service location: %s\n", ns->name, URL); if (executable) fprintf(stderr, "Using %s service executable: %s\n", ns->name, executable); if (URI) fprintf(stderr, "Using %s service namespace: %s\n", ns->name, URI); if (encoding) fprintf(stderr, "Using %s service encoding: %s\n", ns->name, encoding); break; } if (!name) name = "%{Service}%"; if (!URL) URL = "%{URL}%"; if (!executable) { executable = emalloc(strlen(name)+5); strcpy(executable, name); strcat(executable, ".cgi"); } if (!URI) URI = "%{URI}%"; if (t) for (p = t->list; p; p = p->next) { if (p->info.typ->type == Tfun && has_ns_eq(ns->name, p->sym->name)) { if (sp && sp->name) sprintf(buf, "%s.wsdl", name); else sprintf(buf, "%s.wsdl", ns_convert(ns->name)); fprintf(stderr, "Saving %s Web Service description\n", buf); fd = fopen(buf, "w"); if (!fd) execerror("Cannot write to WSDL file"); gen_wsdl(fd, t, ns->name, name, URL, executable, URI, encoding); fclose(fd); if (sp && sp->name) sprintf(buf, "%s.nsmap", name); else sprintf(buf, "%s.nsmap", ns_convert(ns->name)); fprintf(stderr, "Saving %s namespace mapping table\n", buf); fd = fopen(buf, "w"); if (!fd) execerror("Cannot write to nsmap file"); fprintf(fd, "\nstruct Namespace namespaces[] =\n{ {\"SOAP-ENV\", \"http://schemas.xmlsoap.org/soap/envelope/\"},\n {\"SOAP-ENC\", \"http://schemas.xmlsoap.org/soap/encoding/\"},\n {\"xsi\", \"http://www.w3.org/2001/XMLSchema-instance\", \"http://www.w3.org/*/XMLSchema-instance\"},\n {\"xsd\", \"http://www.w3.org/2001/XMLSchema\", \"http://www.w3.org/*/XMLSchema\"},\n {\"%s\", \"%s\"},\n", ns_convert(ns->name), URI); for (ns1 = nslist; ns1; ns1 = ns1->next) if (ns1 != ns) { for (sq = services; sq; sq = sq->next) if (!strcmp(sq->ns, ns1->name) && sq->URI) break; if (sq) fprintf(fd, " {\"%s\", \"%s\"},\n", ns_convert(ns1->name), sq->URI); else fprintf(fd, " {\"%s\", \"%s/%s.xsd\"},\n", ns_convert(ns1->name), URL, ns_convert(ns1->name)); } fprintf(fd, " {NULL, NULL}\n};\n"); fclose(fd); break; } } sprintf(buf, "%s.xsd", ns_convert(ns->name)); fprintf(stderr, "Saving %s.xsd XML Schema description\n", ns_convert(ns->name)); fd = fopen(buf, "w"); if (!fd) execerror("Cannot write to schema file"); fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n"); copyrightnote(fd, ns->name); fprintf(fd, "-->\n"); gen_schema(fd, t, ns->name, ns->name, 1, 0, URL); fclose(fd); }}char *nsofhdr(char *part){ Entry *p; Service *sp; char *s; p = entry(classtable, lookup("SOAP_ENV__Header")); for (p = ((Table*)p->info.typ->ref)->list; p; p = p->next) { s = strstr(p->sym->name, "__"); if (!strcmp(part, p->sym->name) || s && strcmp(part, s+2)) { for (sp = services; sp; sp = sp->next) if (sp->URI && s && !strncmp(sp->ns, p->sym->name, s-p->sym->name)) return sp->URI; sprintf(errbuf, "Cannot save header part reference in WSDL: SOAP_ENV__Header \"%s\" field has no namespace", p->sym->name); semwarn(errbuf); return ""; } } sprintf(errbuf, "Cannot save header part reference in WSDL: SOAP_ENV__Header has no \"%s\" field", part); semwarn(errbuf); return "";} voidgen_wsdl(FILE *fd, Table *t, char *ns, char *name, char *URL, char *executable, char *URI, char *encoding){ Entry *p, *q; Symbol *s; Service *sp; fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(fd, "<definitions name=\"%s\"\n xmlns=\"http://schemas.xmlsoap.org/wsdl/\"\n xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n xmlns:SOAP=\"http://schemas.xmlsoap.org/wsdl/soap/\"\n xmlns:WSDL=\"http://schemas.xmlsoap.org/wsdl/\"\n xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n", name); for (sp = services; sp; sp = sp->next) if (!strcmp(sp->ns, ns) && sp->URI) break; if (sp) if (sp->WSDL) fprintf(fd, " targetNamespace=\"%s\"\n xmlns:tns=\"%s\"", sp->WSDL, sp->WSDL); else fprintf(fd, " targetNamespace=\"%s\"\n xmlns:tns=\"%s\"", sp->URI, sp->URI); else fprintf(fd, " targetNamespace=\"%s/%s.wsdl\"\n xmlns:tns=\"%s/%s.wsdl\"", URL, name, URL, name); for (s = nslist; s; s = s->next) { for (sp = services; sp; sp = sp->next) if (!strcmp(sp->ns, s->name) && sp->URI) break; if (sp) fprintf(fd, "\n xmlns:%s=\"%s\"", ns_convert(s->name), sp->URI); else fprintf(fd, "\n xmlns:%s=\"%s/%s.xsd\"", ns_convert(s->name), URL, ns_convert(s->name)); } fprintf(fd, ">\n\n"); fprintf(fd, "<types>\n"); for (s = nslist; s; s = s->next) gen_schema(fd, t, ns, s->name, !strcmp(s->name, ns), 1, URL); fprintf(fd, "</types>\n\n"); fflush(fd); if (t) { for (p = t->list; p; p = p->next) if (p->info.typ->type == Tfun && has_ns_eq(ns, p->sym->name)) { fprintf(fd, "<message name=\"%sRequest\">\n", ns_remove(p->sym->name)); fflush(fd); q = entry(classtable, p->sym); if (q) for (q = ((Table*)q->info.typ->ref)->list; q; q = q->next) if (is_XML(q->info.typ)) fprintf(fd, " <part name=\"body\" element=\"%s\"/>\n", ns_convert(p->sym->name)); else if (!is_transient(q->info.typ) && q->info.typ->type != Tfun) fprintf(fd, " <part name=\"%s\" type=\"%s\"/>\n", ns_convert(q->sym->name), wsdl_type(q->info.typ, ns)); fprintf(fd, "</message>\n\n"); fflush(fd); q = (Entry*)p->info.typ->ref; if (q && is_transient(q->info.typ)) ; else if (q && !is_response(q->info.typ)) if (is_XML(q->info.typ->ref)) fprintf(fd, "<message name=\"%sResponse\">\n <part name=\"body\" element=\"%sResponse\"/>\n</message>\n\n", ns_remove(p->sym->name), ns_convert(p->sym->name)); else fprintf(fd, "<message name=\"%sResponse\">\n <part name=\"%s\" type=\"%s\"/>\n</message>\n\n", ns_remove(p->sym->name), ns_convert(q->sym->name), wsdl_type(q->info.typ, ns)); else if (q && q->info.typ->wsdl == False) { q->info.typ->wsdl = True; fprintf(fd, "<message name=\"%s\">\n", ns_remove(((Tnode*)q->info.typ->ref)->id->name)); if (((Tnode*)q->info.typ->ref)->ref) { for (q = ((Table*)((Tnode*)q->info.typ->ref)->ref)->list; q; q = q->next) if (is_XML(q->info.typ)) fprintf(fd, " <part name=\"body\" element=\"%s\"/>\n", ns_convert(((Tnode*)((Entry*)p->info.typ->ref)->info.typ->ref)->id->name)); else if (!is_transient(q->info.typ) && q->info.typ->type != Tfun) fprintf(fd, " <part name=\"%s\" type=\"%s\"/>\n", ns_convert(q->sym->name), wsdl_type(q->info.typ, ns)); } fprintf(fd, "</message>\n\n"); } fflush(fd); } if (custom_header) { fprintf(fd, "<message name=\"%sHeader\">\n", name); for (q = ((Table*)entry(classtable, lookup("SOAP_ENV__Header"))->info.typ->ref)->list; q; q = q->next) if (!is_transient(q->info.typ) && q->info.typ->type != Tfun) fprintf(fd, " <part name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns)); fprintf(fd, "</message>\n\n"); } if (custom_fault) { fprintf(fd, "<message name=\"%sFault\">\n", name); for (q = ((Table*)entry(classtable, lookup("SOAP_ENV__Fault"))->info.typ->ref)->list; q; q = q->next) if (!is_transient(q->info.typ) && q->info.typ->type != Tfun) fprintf(fd, " <part name=\"%s\" type=\"%s\"/>\n", ns_remove(q->sym->name), wsdl_type(q->info.typ, ns)); fprintf(fd, "</message>\n\n"); } fflush(fd); fprintf(fd, "<portType name=\"%sPortType\">\n", name); for (p = t->list; p; p = p->next)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -