From a6cc4ca8b8432acdc2ce7bf7ebb92583eeeeff9f Mon Sep 17 00:00:00 2001 From: snowdrop Date: Fri, 15 Oct 2004 13:34:47 +0000 Subject: development --- wsdl2c/CallFunc.c | 2 +- wsdl2c/CallVar.c | 4 +- wsdl2c/codewriter.c | 125 +++++++ wsdl2c/codewriter.h | 12 + wsdl2c/wsdl2c.c | 211 +++++++++-- xsd2c/Enumeration.c | 121 ++++++ xsd2c/Enumeration.h | 67 ++++ xsd2c/formatter.c | 153 +++++--- xsd2c/obj.c | 49 ++- xsd2c/obj.h | 74 +++- xsd2c/tr.c | 39 +- xsd2c/tr.h | 11 +- xsd2c/types.map | 3 +- xsd2c/xsd2c.c | 1038 +++++++++++++++++++++++++++++++++------------------ xsd2c/xsd2c.h | 15 +- 15 files changed, 1443 insertions(+), 481 deletions(-) create mode 100755 wsdl2c/codewriter.c create mode 100755 wsdl2c/codewriter.h create mode 100755 xsd2c/Enumeration.c create mode 100755 xsd2c/Enumeration.h diff --git a/wsdl2c/CallFunc.c b/wsdl2c/CallFunc.c index db13579..3314203 100644 --- a/wsdl2c/CallFunc.c +++ b/wsdl2c/CallFunc.c @@ -99,7 +99,7 @@ struct CallFunc* CallFunc_Deserialize(xmlNodePtr xmlRoot) if ((!xmlStrcmp(cur->name, (const xmlChar *)"name"))){ key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1); CallFunc_Set_name(obj, (const char*)key); - xmlFree(key); + /*xmlFree(key);*/ } if ((!xmlStrcmp(cur->name, (const xmlChar *)"in"))){ CallFunc_Add_in( obj, CallVar_Deserialize(cur) ); diff --git a/wsdl2c/CallVar.c b/wsdl2c/CallVar.c index 035f56c..cc42dae 100644 --- a/wsdl2c/CallVar.c +++ b/wsdl2c/CallVar.c @@ -86,12 +86,12 @@ struct CallVar* CallVar_Deserialize(xmlNodePtr xmlRoot) if ((!xmlStrcmp(cur->name, (const xmlChar *)"name"))){ key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1); CallVar_Set_name(obj, (const char*)key); - xmlFree(key); + /*xmlFree(key);*/ } if ((!xmlStrcmp(cur->name, (const xmlChar *)"type"))){ key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1); CallVar_Set_type(obj, (const char*)key); - xmlFree(key); + /*xmlFree(key);*/ } // TODO: cur = cur->next; diff --git a/wsdl2c/codewriter.c b/wsdl2c/codewriter.c new file mode 100755 index 0000000..7f46b7f --- /dev/null +++ b/wsdl2c/codewriter.c @@ -0,0 +1,125 @@ +#include "codewriter.h" +#include +#include + +#include + +static FILE *header; +static FILE *source; +static char* ns = "impl"; + +static int openSourceFile(const char* filename); +static void closeSourceFile(); + +static int openHeaderFile(const char* filename); +static void closeHeaderFile(); + +static void writeOperation(struct CallFunc *call) +{ + struct CallVar_List* var; + + fprintf(header, "%s %s_%s(", trXSD2C(call->out->type), ns, call->name); + + var = CallFunc_Get_in(call); + + while (var) { + fprintf(header, "const %s %s", trXSD2C(var->value->type), var->value->name); + var = var->next; + if (var) fprintf(header, ","); + } + + fprintf(header, ")"); +} + +void codeWriteStubHeader(struct CallList *cl, const char* filename) +{ + struct CallFunc_List *call; + struct CallVar_List* var; + HCOMPLEXTYPE ct; + + openHeaderFile(filename); + + fprintf(header, "#ifndef __TEST_SOAP_H__\n#define __TEST_SOAP_H__\n\n"); + + /* Find header files */ + call = CallList_Get_operation(cl); + while (call) { + var = CallFunc_Get_in(call->value); + while (var) { + ct = objRegistryGetComplexType(var->value->type); + if (ct /* TODO: && not in written before */) + fprintf(header, "#include \"%s.h\"\n", trXSDParseNs(var->value->type)); /* _xsd*/ + var = var->next; + } + call = call->next; + } + + fprintf(header, "\n"); + call = CallList_Get_operation(cl); + while (call) { + + writeOperation(call->value); + fprintf(header, ";\n"); + call = call->next; + } + + fprintf(header, "\n\n#endif\n"); + + closeHeaderFile(); +} + + +void codeWriteStubSource(struct CallList *cl, const char* filename) +{ + struct CallFunc_List *call; + + openSourceFile(filename); + + fprintf(source, "#include \"test_stub.h\"\n\n"); + + call = CallList_Get_operation(cl); + while (call) { + + writeOperation(call->value); +/* fwrite(source, "\n{\n\t*/ + call = call->next; + } + + + fprintf(source, "\n"); + + closeSourceFile(); +} + + + +static +int openSourceFile(const char* filename) +{ + source = fopen(filename, "w"); + if (!source) return 0; + return 1; +} + +static +void closeSourceFile() +{ + fclose(source); +} + +static +int openHeaderFile(const char* filename) +{ + header= fopen(filename, "w"); + if (!header) return 0; + return 1; +} + + +static +void closeHeaderFile() +{ + fclose(header); +} + + diff --git a/wsdl2c/codewriter.h b/wsdl2c/codewriter.h new file mode 100755 index 0000000..ab2a5f4 --- /dev/null +++ b/wsdl2c/codewriter.h @@ -0,0 +1,12 @@ +#ifndef __CODE_WRITER_H__ +#define __CODE_WRITER_H__ + + +#include "CallList.h" + +void codeWriteStubHeader(struct CallList *cl, const char* filename); +void codeWriteStubSource(struct CallList *cl, const char* filename); + + +#endif + diff --git a/wsdl2c/wsdl2c.c b/wsdl2c/wsdl2c.c index f726dff..55a2e71 100755 --- a/wsdl2c/wsdl2c.c +++ b/wsdl2c/wsdl2c.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: wsdl2c.c,v 1.7 2004/06/08 12:55:04 snowdrop Exp $ + * $Id: wsdl2c.c,v 1.8 2004/10/15 13:34:47 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -70,6 +70,9 @@ void Writer_EndElement(const char* element_name, void* userData) struct CallList* callList = NULL; char soap_prefix[50]; +char wsdl_prefix[50]; +char target_ns[150]; +char target_prefix[50]; xmlXPathObjectPtr xpath_eval(xmlDocPtr doc, const char *xpath) { @@ -101,11 +104,12 @@ xmlXPathObjectPtr xpath_eval(xmlDocPtr doc, const char *xpath) default_ns = xmlSearchNs(doc, node, NULL); if (default_ns != NULL && default_ns->href != NULL) { fprintf(stdout, "Register default namespace '%s'\n", (const char*)default_ns->href); - xmlXPathRegisterNs(context, "wsdl", default_ns->href ); /* default_ns : "http://schemas.xmlsoap.org/wsdl/" */ + /* default_ns : "http://schemas.xmlsoap.org/wsdl/" */ + xmlXPathRegisterNs(context, "wsdl", default_ns->href ); } - + printf("XPath: '%s'\n", xpath); result = xmlXPathEvalExpression((xmlChar*)xpath, context); if (result == NULL) { fprintf(stderr, "ERROR: XPath error!\n"); @@ -114,6 +118,7 @@ xmlXPathObjectPtr xpath_eval(xmlDocPtr doc, const char *xpath) if(xmlXPathNodeSetIsEmpty(result->nodesetval)){ /* no result */ + printf("XPath result is empty\n"); return NULL; } @@ -154,11 +159,11 @@ xmlNodePtr findPortType(xmlDocPtr doc, const char *name) } if (!xmlStrcmp(attr_name, (const xmlChar*)name)) { - xmlFree(attr_name); + /*xmlFree(attr_name);*/ return cur; } - xmlFree(attr_name); + /*xmlFree(attr_name);*/ cur = cur->next; } @@ -199,11 +204,11 @@ xmlNodePtr findMessage(xmlDocPtr doc, const char *name) } if (!xmlStrcmp(attr_name, (const xmlChar*)name)) { - xmlFree(attr_name); + /*xmlFree(attr_name);*/ return cur; } - xmlFree(attr_name); + /*xmlFree(attr_name);*/ cur = cur->next; } @@ -281,7 +286,7 @@ void handleInputParameters(xmlDocPtr doc, const char *name, struct CallFunc *fun if (var_type == NULL) { fprintf(stderr, "ERROR: Found without attrbute 'type' or 'element'! (message:'%s')\n", message_name); - xmlFree(var_name); + /*xmlFree(var_name);*/ cur = cur->next; continue; } @@ -293,10 +298,78 @@ void handleInputParameters(xmlDocPtr doc, const char *name, struct CallFunc *fun fprintf(stdout, "\t\t(%s,%s)\n", trXSD2C((const char*)var_type), (const char*)var_name); - xmlFree(var_name); - xmlFree(var_type); + /*xmlFree(var_name); + xmlFree(var_type);*/ + + cur = cur->next; + } + +} + +void handleOutputParameters(xmlDocPtr doc, const char *name, struct CallFunc *func) +{ + char ns[10]; + char message_name[255]; + xmlNodePtr node; + xmlNodePtr cur; + struct CallVar *var; + xmlChar *var_name, *var_type; + + parseNS(name, ns, message_name); /* check why to pase ns? */ + + node = findMessage(doc, message_name); + if (node == NULL) { + fprintf(stderr, "ERROR: Can not find message '%s'\n", message_name); + return; + } + + cur = node->xmlChildrenNode; + while (cur != NULL) { + + if (cur->type != XML_ELEMENT_NODE) { + cur = cur->next; + continue; + } + + if (xmlStrcmp(cur->name, (const xmlChar*)"part")) { + cur = cur->next; + continue; + } + + var_name = xmlGetProp(cur, "name"); + if (var_name == NULL) { + fprintf(stderr, "ERROR: Found without attrbute 'name'! (message:'%s')\n", + message_name); + cur = cur->next; + continue; + } + + var_type = xmlGetProp(cur, "type"); + if (var_type == NULL) { + var_type = xmlGetProp(cur, "element"); + } + + if (var_type == NULL) { + fprintf(stderr, "ERROR: Found without attrbute 'type' or 'element'! (message:'%s')\n", + message_name); + /*xmlFree(var_name);*/ + cur = cur->next; + continue; + } + var = CallVar_Create(); + CallVar_Set_name(var, (const char*)var_name); + CallVar_Set_type(var, (const char*)var_type); + CallFunc_Set_out(func, var); + + fprintf(stdout, "\t\t(%s,%s)\n", trXSD2C((const char*)var_type), (const char*)var_name); + + /*xmlFree(var_name); + xmlFree(var_type);*/ + cur = cur->next; + + break; /* only one return parameter */ } } @@ -338,7 +411,7 @@ void handlePortType(xmlDocPtr doc, const char *name) } strcpy(opname, (const char*)attr_name); - xmlFree(attr_name); + /*xmlFree(attr_name);*/ func = CallFunc_Create(); CallList_Add_operation(callList, func); @@ -356,7 +429,7 @@ void handlePortType(xmlDocPtr doc, const char *name) message = xmlGetProp(input, "message"); if (message == NULL) { - fprintf(stderr, "ERROR: No message attribute for input operation '%'\n", opname); + fprintf(stderr, "ERROR: No message attribute for input operation '%s'\n", opname); cur = cur->next; continue; } @@ -365,7 +438,7 @@ void handlePortType(xmlDocPtr doc, const char *name) handleInputParameters(doc, (const char*)message, func); - xmlFree(message); + /*xmlFree(message);*/ /* handle output */ output = findSubNode(cur, "output"); @@ -376,14 +449,15 @@ void handlePortType(xmlDocPtr doc, const char *name) message = xmlGetProp(output, "message"); if (message == NULL) { - fprintf(stderr, "ERROR: No message attribute for output operation '%'\n", opname); + fprintf(stderr, "ERROR: No message attribute for output operation '%s'\n", opname); cur = cur->next; continue; } fprintf(stdout, "\toutput = '%s'\n", (const char*)message); - xmlFree(message); + /*xmlFree(message);*/ + handleOutputParameters(doc, (const char*)message, func); cur = cur->next; } @@ -404,7 +478,10 @@ void handleBinding(xmlDocPtr doc, const char *type) parseNS(type, binding_ns, binding_type); /* Set xpath query */ - sprintf(query, "//wsdl:definitions/wsdl:binding[@name=\"%s\"]", binding_type); + if (wsdl_prefix[0]) + sprintf(query, "//%s:definitions/%s:binding[@name=\"%s\"]", wsdl_prefix, wsdl_prefix, binding_type); + else + sprintf(query, "//definitions/binding[@name=\"%s\"]", binding_type); /* Find Bindings */ xpathObj = xpath_eval(doc, query); @@ -442,8 +519,8 @@ void handleBinding(xmlDocPtr doc, const char *type) handlePortType(doc, port_name); } - if (name != NULL) xmlFree(name); - if (btype != NULL) xmlFree(btype); +/* if (name != NULL) xmlFree(name); + if (btype != NULL) xmlFree(btype); */ } } @@ -456,7 +533,11 @@ void wsdlParse(xmlDocPtr doc) xmlXPathObjectPtr xpathObj; char query[255]; - sprintf(query, "//wsdl:definitions/wsdl:service/wsdl:port[%s:address]", soap_prefix); + if (wsdl_prefix[0]) + sprintf(query, "//%s:definitions/%s:service/%s:port[%s:address]", wsdl_prefix, wsdl_prefix, wsdl_prefix, soap_prefix); + else + sprintf(query, "//definitions/service/port[%s:address]", soap_prefix); + /* Find Soap Service */ xpathObj = xpath_eval(doc, query); @@ -490,8 +571,8 @@ void wsdlParse(xmlDocPtr doc) handleBinding(doc, binding); - if (name != NULL) xmlFree(name); - if (binding != NULL) xmlFree(binding); +/* if (name != NULL) xmlFree(name); + if (binding != NULL) xmlFree(binding);*/ } @@ -509,6 +590,10 @@ int main(int argc, char *argv[]) xmlNodePtr xsdRoot; xmlNsPtr default_ns; xmlNsPtr soap_ns; + xmlNsPtr wsdl_ns; + xmlNsPtr tar_ns; + xmlChar *tar_ns_str; + int i; char outDir[1054]; char fname[255]; @@ -567,7 +652,7 @@ int main(int argc, char *argv[]) } if (soap_ns != NULL && soap_ns->prefix != NULL) { - fprintf(stdout, "Wsdl Soap prefix: '%s'\n", soap_ns->prefix); + fprintf(stdout, "Wsdl SOAP prefix: '%s'\n", soap_ns->prefix); strcpy(soap_prefix, soap_ns->prefix); } else { fprintf(stderr,"Namespace 'http://schemas.xmlsoap.org/wsdl/soap/' expected\n"); @@ -576,34 +661,84 @@ int main(int argc, char *argv[]) } + /* Search for wsdl namespace + http://schemas.xmlsoap.org/wsdl/ + */ + wsdl_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl/"); + if (wsdl_ns == NULL) { + wsdl_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl"); + } - /* search default namespace */ - default_ns = xmlSearchNs(doc, node, NULL); - if (default_ns == NULL || ( default_ns != NULL && default_ns->href == NULL)) { - fprintf(stdout, "Adding default namespace 'http://schemas.xmlsoap.org/wsdl/'\n"); - xmlNewDocProp(doc, "xmlns", "http://schemas.xmlsoap.org/wsdl/"); - } - if (!xsdInitTrModule(xsdRoot)) - return 1; + if (wsdl_ns != NULL && wsdl_ns->prefix != NULL) { + fprintf(stdout, "Wsdl prefix: '%s'\n", wsdl_ns->prefix); + strcpy(wsdl_prefix, wsdl_ns->prefix); + } else { + /* search default namespace */ + default_ns = xmlSearchNs(doc, node, NULL); + if (default_ns == NULL || ( default_ns != NULL && default_ns->href == NULL)) { + fprintf(stdout, "Adding default namespace 'http://schemas.xmlsoap.org/wsdl/'\n"); + xmlNewDocProp(doc, "xmlns", "http://schemas.xmlsoap.org/wsdl/"); + } + + /*strcpy(wsdl_prefix, "wsdl");*/ + wsdl_prefix[0] = '\0'; + } + + + + /* search targetNamespace */ + tar_ns_str = xmlGetProp(node, "targetNamespace"); + if (tar_ns_str) { + strcpy(target_ns, tar_ns_str); + /* Search for target namespace + */ + tar_ns = xmlSearchNsByHref(doc, node, target_ns); + if (tar_ns && tar_ns->prefix) { + strcpy(target_prefix, tar_ns->prefix); + printf("Target namespace: %s\nTarget NS Prefix: %s\n", + target_ns, target_prefix); + } else { + target_prefix[0] = '\0'; + } + /*xmlFree*/ + } else { + target_ns[0] = '\0'; + target_prefix[0] = '\0'; + } - if (!xsdInitObjModule(xsdRoot)) - return 1; + xsdRoot = xsdRoot?xsdRoot:node; + while (xsdRoot) { + + if (xsdRoot->type != XML_ELEMENT_NODE) { + xsdRoot = xsdRoot->next; + continue; + } + + if (!xsdInitTrModule(xsdRoot)) + return 1; - - if (xsdEngineRun(xsdRoot, outDir)) { - fprintf(stderr, "xsd2c engine error\n"); - return 1; - } + if (!xsdInitObjModule(xsdRoot)) + return 1; + + printf("Calling xsd engine\n"); + if (xsdEngineRun(xsdRoot, outDir)) { + fprintf(stderr, "xsd2c engine error\n"); + return 1; + } + xsdRoot = xsdRoot->next; + } callList = CallList_Create(); wsdlParse(doc); - CallList_Sax_Serialize(callList, "CallList", +/* CallList_Sax_Serialize(callList, "CallList", Writer_StartElement, Writer_Characters, Writer_EndElement, 0); +*/ + codeWriteStubHeader(callList, "test_stub.h"); CallList_Free(callList); diff --git a/xsd2c/Enumeration.c b/xsd2c/Enumeration.c new file mode 100755 index 0000000..e795206 --- /dev/null +++ b/xsd2c/Enumeration.c @@ -0,0 +1,121 @@ +/** Generated by xsd2c */ +#include +#include +#include +#include "Enumeration.h" + + +struct Enumeration* Enumeration_Create() +{ + struct Enumeration* _res; + _res = (struct Enumeration*)malloc(sizeof(struct Enumeration)); + + _res->value_head = NULL; + _res->value_tail = NULL; + + return _res; +} + +void Enumeration_Free(struct Enumeration* obj) +{ + struct Enumeration_value_List* value_cur; + struct Enumeration_value_List* value_tmp; + if (obj == NULL) return; + + value_cur = obj->value_head; + while (value_cur != NULL) + { + if (value_cur->value) free(value_cur->value); + value_tmp = value_cur->next; + free(value_cur); + value_cur = value_tmp; + } + free(obj); +} + +void Enumeration_Sax_Serialize(struct Enumeration* obj, + const char *root_element_name, + void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData), + void (*OnCharacters)(const char* element_name, const char* chars, void* userData), + void (*OnEndElement)(const char* element_name, void* userData), + void* userData) +{ + int attrCount, curCount; + char **keys; + char **values; + char buffer[255]; + + struct Enumeration_value_List* value_cur; + + attrCount = 0; + + keys = (char**)malloc(sizeof(char*)*attrCount); + values = (char**)malloc(sizeof(char*)*attrCount); + + curCount = 0; + + + OnStartElement(root_element_name, attrCount, keys, values, userData); + value_cur = obj->value_head; + while (value_cur != NULL) + { + + OnStartElement("value", 0, NULL, NULL, userData); + if (value_cur->value != NULL) + OnCharacters("value", value_cur->value, userData); + OnEndElement("value", userData); + value_cur = value_cur->next; + } + + OnEndElement(root_element_name, userData); +} + +#ifndef _DESERIALIZER_DISABLED_ + +struct Enumeration* Enumeration_Deserialize(xmlNodePtr xmlRoot) +{ + xmlNodePtr cur; + xmlChar *key; + struct Enumeration* obj; + obj = Enumeration_Create(); + cur = xmlRoot->xmlChildrenNode; + while (cur != NULL) { + if (cur->type != XML_ELEMENT_NODE) { + cur = cur->next; + continue; + } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"value"))){ + key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1); + Enumeration_Add_value(obj, (const char*)key); +/* xmlFree(key);*/ + } + // TODO: + cur = cur->next; + } + return obj; +} + +#endif +struct Enumeration_value_List* Enumeration_Get_value(struct Enumeration* obj) +{ + return obj->value_head; +} + +void Enumeration_Add_value(struct Enumeration* obj, const char* value) +{ + struct Enumeration_value_List* value_node; + value_node = (struct Enumeration_value_List*)malloc(sizeof(struct Enumeration_value_List)); + value_node->value = (char*)malloc(strlen(value)+1); + strcpy(value_node->value, value); + value_node->next = NULL; + if (obj->value_tail) + { + obj->value_tail->next = value_node; + } + if (obj->value_head == NULL) + { + obj->value_head = value_node; + } + obj->value_tail = value_node; +} + diff --git a/xsd2c/Enumeration.h b/xsd2c/Enumeration.h new file mode 100755 index 0000000..49edae5 --- /dev/null +++ b/xsd2c/Enumeration.h @@ -0,0 +1,67 @@ +/** Generated by xsd2c*/ +#ifndef __Enumeration_H__ +#define __Enumeration_H__ + + + +#ifndef _DESERIALIZER_DISABLE_ + #include +#endif + + +#define TO_ENUMERATION(derived) (derived->__base) + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct Enumeration_value_List { + char* value; + struct Enumeration_value_List* next; +}; + +/** + * OBJECT: Enumeration + */ +struct Enumeration +{ + struct Enumeration_value_List* value_head; + struct Enumeration_value_List* value_tail; +}; + +/** + * LIST: Enumeration_List + */ +struct Enumeration_List +{ + struct Enumeration* value; + struct Enumeration_List* next; +}; + + +struct Enumeration* Enumeration_Create(); +void Enumeration_Free(struct Enumeration* obj); +void Enumeration_Sax_Serialize(struct Enumeration* obj, + const char *root_element_name, + void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData), + void (*OnCharacters)(const char* element_name, const char* chars, void* userData), + void (*OnEndElement)(const char* element_name, void* userData), + void* userData); + +#ifndef _DESERIALIZER_DISABLE_ +struct Enumeration* Enumeration_Deserialize(xmlNodePtr xmlRoot); +#endif + +void Enumeration_Add_value(struct Enumeration* obj, const char* value); +struct Enumeration_value_List* Enumeration_Get_value(struct Enumeration* obj); + + +#ifdef __cplusplus +}; +#endif /*__cplusplus*/ + + + +#endif diff --git a/xsd2c/formatter.c b/xsd2c/formatter.c index 6808502..6264fdf 100644 --- a/xsd2c/formatter.c +++ b/xsd2c/formatter.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: formatter.c,v 1.4 2004/06/04 09:09:40 snowdrop Exp $ + * $Id: formatter.c,v 1.5 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -42,6 +42,7 @@ static int genFunctionNameCreate(HCOMPLEXTYPE obj, char *buffer); static int genFunctionNameFree(HCOMPLEXTYPE obj, char *buffer); static int genFunctionNameSaxSerialize(HCOMPLEXTYPE obj, char *buffer); static int genFunctionNameDeserialize(HCOMPLEXTYPE obj, char *buffer); +static int genFunctionNameSimpleMinMaxSetter(HCOMPLEXTYPE obj, char *buffer); /* ------------------------------------------------------------- */ @@ -68,6 +69,8 @@ static void writeCodeGetter(FILE* f, HFIELD field); static void writeCodeSetter(FILE* f, HFIELD field); static void writeCodeAdder(FILE* f, HFIELD field); +/* ------------------------------------------------------------- */ +static void writeSimpleMinMaxSetter(FILE* f, HCOMPLEXTYPE obj); /* ------------------------------------------------------------- */ void writeComplexTypeHeaderFile(FILE* f, HCOMPLEXTYPE obj) @@ -110,7 +113,8 @@ void writeComplexTypeHeaderFile(FILE* f, HCOMPLEXTYPE obj) /* write upcasting define macro */ toUpperCase(obj->type, buffer); - fprintf(f, "\n#define TO_%s(derived) (derived->__base) \n\n", buffer); + if (!obj->isSimpleContent && !obj->restriction) + fprintf(f, "\n#define TO_%s(derived) (derived->__base) \n\n", buffer); /* write extern "C" for __cplusplus linking */ fprintf(f, "\n#ifdef __cplusplus\nextern \"C\" {\n#endif \n\n", buffer); @@ -142,14 +146,28 @@ void writeComplexTypeHeaderFile(FILE* f, HCOMPLEXTYPE obj) fprintf(f, "#endif\n\n"); } - /* write setter functions */ - enumFields(f, obj, writeFieldSetter); - - /* write adder functions */ - enumFields(f, obj, writeListAdder); - - /* write getter functions */ - enumFields(f, obj, writeFieldGetter); + if (obj->isSimpleContent && obj->restriction) + { + switch (obj->restriction->mode) + { + case RES_MODE_MINMAX: + /* do nothing yet */ + break; + case RES_MODE_ENUMERATION: + break; + } + } + else + { + /* write setter functions */ + enumFields(f, obj, writeFieldSetter); + + /* write adder functions */ + enumFields(f, obj, writeListAdder); + + /* write getter functions */ + enumFields(f, obj, writeFieldGetter); + } /* write extern "C" for __cplusplus linking */ fprintf(f, "\n\n#ifdef __cplusplus\n};\n#endif /*__cplusplus*/\n\n", buffer); @@ -157,48 +175,88 @@ void writeComplexTypeHeaderFile(FILE* f, HCOMPLEXTYPE obj) fprintf(f, "\n\n#endif\n"); } + + /* ------------------------------------------------------------- */ static void writeComplexTypeDeclare(FILE* f, HCOMPLEXTYPE obj) { HFIELD field; + struct Enumeration_value_List *enumList; char *type; + char buffer[250]; + char buffer2[250]; if (obj == NULL) { fprintf(stderr, "Can not declare a null object!\n"); return; } - - /* === */ - fprintf(f, "\n/**\n *\tOBJECT: %s\n */\n", obj->type); - fprintf(f, "struct %s\n{\n", obj->type); - - /* === */ - if (obj->base_type != NULL) + + if (obj->isSimpleContent) { - type = trXSD2C(obj->base_type); - if (type != NULL) + if (obj->restriction) { + if (obj->restriction->mode == RES_MODE_ENUMERATION) { + fprintf(f, "\ntypedef enum _enum_%s {\n", obj->type); + enumList = Enumeration_Get_value(obj->restriction->enumeration); + while(enumList) { + toUpperCase(enumList->value, buffer); + toUpperCase(obj->type, buffer2); + fprintf(f, "\t%s_%s, /* Constant for \"%s\" */\n", buffer2, buffer, enumList->value); + enumList = enumList->next; + } + + fprintf(f, "}%s;\n", obj->type); + + } + else { + fprintf(f, "\n/** type definition for simple content element '%s' */\n", obj->type); + fprintf(f, "typedef %s %s;\n\n", trXSD2C(obj->restriction->type), obj->type); + + } + + /* === Else List ======== */ + fprintf(f, "\n/**\n *\tLIST: %s_List\n */\n", obj->type); + fprintf(f, "%s_List\n{\n", obj->type); + fprintf(f, "\t%s value;\n", obj->type); + fprintf(f, "\tstruct %s_List* next;\n", obj->type); + fprintf(f, "};\n\n\n"); + } /* restriction */ + } /* isSimpleContent */ + else + { + /* === */ + fprintf(f, "\n/**\n *\tOBJECT: %s\n */\n", obj->type); + fprintf(f, "struct %s\n{\n", obj->type); + + /* === */ + if (obj->base_type != NULL) { - fprintf(f, "\t%s __base;\n", type); + type = trXSD2C(obj->base_type); + if (type != NULL) + { + fprintf(f, "\t%s __base;\n", type); + } } - } + + /* === */ + field = obj->head; + while (field != NULL) + { + printf("%s::writeFieldDeclare(%s)\n", obj->type, field->type); + writeFieldDeclare(f, field); + field = field->next; + } + fprintf(f, "};\n"); + + /* === */ + fprintf(f, "\n/**\n *\tLIST: %s_List\n */\n", obj->type); + fprintf(f, "struct %s_List\n{\n", obj->type); + fprintf(f, "\tstruct %s* value;\n", obj->type); + fprintf(f, "\tstruct %s_List* next;\n", obj->type); + fprintf(f, "};\n\n\n"); + } /* else of isSimpleContent */ - /* === */ - field = obj->head; - while (field != NULL) - { - writeFieldDeclare(f, field); - field = field->next; - } - fprintf(f, "};\n"); - - /* === */ - fprintf(f, "\n/**\n *\tLIST: %s_List\n */\n", obj->type); - fprintf(f, "struct %s_List\n{\n", obj->type); - fprintf(f, "\tstruct %s* value;\n", obj->type); - fprintf(f, "\tstruct %s_List* next;\n", obj->type); - fprintf(f, "};\n\n\n"); } @@ -215,6 +273,7 @@ void writeFieldDeclare(FILE* f, HFIELD field) if (field->maxOccurs > 1 || field->maxOccurs == -1) { + printf("OBJ:%s FIELD: %s\n", field->parentObj->type, buffer); fprintf(f, "\t%s %s_head;\n", buffer, field->name); fprintf(f, "\t%s %s_tail;\n", buffer, field->name); } @@ -230,6 +289,7 @@ static int genFunctionNameCreate(HCOMPLEXTYPE obj, char *buffer) { const char *funcname = "struct %s* %s_Create()"; + if (obj->isSimpleContent && obj->restriction) return 0; sprintf(buffer, funcname, obj->type, obj->type); return 1; } @@ -240,6 +300,7 @@ static int genFunctionNameFree(HCOMPLEXTYPE obj, char *buffer) { const char *funcname = "void %s_Free(struct %s* obj)"; + if (obj->isSimpleContent && obj->restriction) return 0; sprintf(buffer, funcname, obj->type, obj->type); return 1; } @@ -329,11 +390,15 @@ static int genFunctionNameAdder(HFIELD field, char *buffer) static int genFunctionNameSaxSerialize(HCOMPLEXTYPE obj, char *buffer) { const char *funcname = "void %s_Sax_Serialize(struct %s* obj,\n\t\t const char *root_element_name,\n\t\t %s,\n\t\t %s,\n\t\t %s,\n\t\t void* userData)"; + const char *funcnameSimple = "void %s_Sax_Serialize(%s obj,\n\t\t const char *root_element_name,\n\t\t %s,\n\t\t %s,\n\t\t %s,\n\t\t void* userData)"; const char *start = "void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData)"; const char *chars = "void (*OnCharacters)(const char* element_name, const char* chars, void* userData)"; const char *end = "void (*OnEndElement)(const char* element_name, void* userData)"; - sprintf(buffer, funcname, obj->type, obj->type, start, chars, end); + if (obj->isSimpleContent && obj->restriction) + sprintf(buffer, funcnameSimple, obj->type, obj->type, start, chars, end); + else + sprintf(buffer, funcname, obj->type, obj->type, start, chars, end); return 1; } @@ -342,8 +407,12 @@ static int genFunctionNameSaxSerialize(HCOMPLEXTYPE obj, char *buffer) static int genFunctionNameDeserialize(HCOMPLEXTYPE obj, char *buffer) { const char *funcname = "struct %s* %s_Deserialize(xmlNodePtr xmlRoot)"; + const char *funcnameSimple = "%s %s_Deserialize(xmlNodePtr xmlRoot)"; - sprintf(buffer, funcname, obj->type, obj->type); + if (obj->isSimpleContent && obj->restriction) + sprintf(buffer, funcnameSimple, obj->type, obj->type); + else + sprintf(buffer, funcname, obj->type, obj->type); return 1; } @@ -1151,7 +1220,7 @@ static void writeCodeDeserialize(FILE* f, HCOMPLEXTYPE obj) fprintf(stderr, "WARNING: Type '%s' not found as attribute\n", type); } - fprintf(f, "\t\txmlFree(key);\n"); + fprintf(f, "\t\t/*xmlFree(key);*/\n"); fprintf(f, "\t}\n"); } @@ -1193,7 +1262,7 @@ static void writeCodeDeserialize(FILE* f, HCOMPLEXTYPE obj) } else { fprintf(f, "\t\t\t%s_Set_%s(obj, (const char*)key);\n", field->parentObj->type, field->name); } - fprintf(f, "\t\t\txmlFree(key);\n"); + fprintf(f, "\t\t\t/*xmlFree(key);*/\n"); } else if (!strcmp(type, "int") || !strcmp(type, "integer")) { @@ -1203,7 +1272,7 @@ static void writeCodeDeserialize(FILE* f, HCOMPLEXTYPE obj) } else { fprintf(f, "\t\t\t%s_Set_%s(obj, atoi((const char*)key));\n", field->parentObj->type, field->name); } - fprintf(f, "\t\t\txmlFree(key);\n"); + fprintf(f, "\t\t\t/*xmlFree(key);*/\n"); } else if (!strcmp(type, "float") || !strcmp(type, "double")) { @@ -1213,7 +1282,7 @@ static void writeCodeDeserialize(FILE* f, HCOMPLEXTYPE obj) } else { fprintf(f, "\t\t\t%s_Set_%s(obj, atof((const char*)key));\n", field->parentObj->type, field->name); } - fprintf(f, "\t\t\txmlFree(key);\n"); + fprintf(f, "\t\t\t/*xmlFree(key);*/\n"); } } else diff --git a/xsd2c/obj.c b/xsd2c/obj.c index 1107807..4c4da23 100644 --- a/xsd2c/obj.c +++ b/xsd2c/obj.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: obj.c,v 1.3 2004/06/03 20:23:03 snowdrop Exp $ + * $Id: obj.c,v 1.4 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -42,18 +42,21 @@ static void objFreeComplexType(HCOMPLEXTYPE obj); static void objRegistryAddComplexType(HCOMPLEXTYPE obj); static char *targetNS = NULL; +static int _objInitialized = 0; /* ------------------------------------------------------------------ */ void objInitModule(const char* tns) { - objRegistry.head = NULL; - objRegistry.tail = NULL; - if (tns != NULL) { targetNS = (char*)malloc(strlen(tns)+1); strcpy(targetNS, tns); } + if (_objInitialized) return; + + objRegistry.head = NULL; + objRegistry.tail = NULL; + _objInitialized = 1; } void objFreeModule() @@ -82,11 +85,14 @@ HCOMPLEXTYPE objCreateComplexType(const char* typename) ct->head = ct->tail = NULL; ct->next = NULL; ct->base_type = NULL; - + ct->restriction = NULL; + ct->isSimpleContent = 0; + strcpy(ct->targetNS, targetNS); + sprintf(ct->fullName, "%s:%s", targetNS, typename); objRegistryAddComplexType(ct); sprintf(buf, "struct %s*", typename); - trRegisterTypeNS(targetNS, typename, buf); + trRegisterTypeNS(targetNS, typename, buf, 0); sprintf(buf, "struct %s_List*", typename); trRegisterListTypeNS(targetNS, typename, buf); return ct; @@ -127,6 +133,15 @@ void objSetBaseType(HCOMPLEXTYPE obj, const char* typename) HCOMPLEXTYPE objRegistryGetComplexType(const char* typename) { + HCOMPLEXTYPE cur; + + cur = objRegistry.head; + while (cur != NULL) + { + if (!strcmp(cur->fullName, typename)) + return cur; + cur = cur->next; + } return NULL; } @@ -187,6 +202,7 @@ void fieldFree(HFIELD field) static void objAddField(HCOMPLEXTYPE obj, HFIELD field) { + printf("ADD FIELD %s %s\n", obj->type, field->type); if (obj->tail) { obj->tail->next = field; @@ -229,3 +245,24 @@ static void objRegistryAddComplexType(HCOMPLEXTYPE obj) objRegistry.tail = obj; } + + + +HRESTRICTION resCreate(const char *type) +{ + HRESTRICTION res = (HRESTRICTION)malloc(sizeof(struct RESTRICTION)); + res->mode = RES_MODE_EMPTY; + res->type = (char*)malloc(strlen(type)+1); + strcpy(res->type, type); + + res->minInclusiveSet = 0; + res->maxInclusiveSet = 0; + res->minExclusiveSet = 0; + res->maxExclusiveSet = 0; + + res->enumeration = Enumeration_Create(); + + return res; +} + + diff --git a/xsd2c/obj.h b/xsd2c/obj.h index a51fb17..455b402 100644 --- a/xsd2c/obj.h +++ b/xsd2c/obj.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: obj.h,v 1.2 2004/06/02 14:57:23 snowdrop Exp $ + * $Id: obj.h,v 1.3 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,9 +24,11 @@ #ifndef XSD2C_OBJ_H #define XSD2C_OBJ_H +#include "Enumeration.h" typedef struct FIELD* HFIELD; typedef struct COMPLEXTYPE* HCOMPLEXTYPE; +typedef struct RESTRICTION* HRESTRICTION; typedef int (*CT_ENUM)(HCOMPLEXTYPE); struct FIELD @@ -48,8 +50,74 @@ struct COMPLEXTYPE HFIELD head; HFIELD tail; HCOMPLEXTYPE next; + int isSimpleContent; + HRESTRICTION restriction; + char targetNS[150]; + char fullName[250]; }; +#define RES_MODE_EMPTY 0 +#define RES_MODE_MINMAX 1 +#define RES_MODE_ENUMERATION 2 + +struct RESTRICTION +{ + int mode; + + char *type; + + /* Defines a list of acceptable values*/ + struct Enumeration *enumeration; + + /* Specifies the maximum number of decimal places allowed. + Must be equal to or greater than zero */ + int fractionDigits; + + /* Specifies the exact number of characters or list items allowed. + Must be equal to or greater than zero*/ + int length; + + /* Specifies the upper bounds for numeric + values (the value must be less than this value) */ + int maxExclusive; + int maxExclusiveSet; + + /* Specifies the upper bounds for numeric values + (the value must be less than or equal to this value) */ + int maxInclusive; + int maxInclusiveSet; + + /* Specifies the lower bounds for numeric values + (the value must be greater than this value) */ + int minExclusive; + int minExclusiveSet; + + /* Specifies the lower bounds for numeric values + (the value must be greater than or equal to this value) */ + int minInclusive; + int minInclusiveSet; + + /* Specifies the maximum number of characters or list items allowed. + Must be equal to or greater than zero */ + int maxLength; + + + /* Specifies the minimum number of characters or list items allowed. + Must be equal to or greater than zero */ + int minLength; + + /* Defines the exact sequence of + characters that are acceptable */ + char pattern[150]; + + /* Specifies the exact number of digits allowed. + Must be greater than zero */ + int totalDigits; + + /* Specifies how white space (line feeds, tabs, + spaces, and carriage returns) is handled */ + char whiteSpace[50]; +}; void objInitModule(); void objFreeModule(); @@ -62,4 +130,8 @@ HFIELD objAddAttribute(HCOMPLEXTYPE obj, const char* name, const char* type, int HCOMPLEXTYPE objRegistryGetComplexType(const char* typename); void objRegistryEnumComplexType(CT_ENUM callback); + + +HRESTRICTION resCreate(const char* type); + #endif diff --git a/xsd2c/tr.c b/xsd2c/tr.c index 5edfd4d..3e5bd75 100644 --- a/xsd2c/tr.c +++ b/xsd2c/tr.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: tr.c,v 1.3 2004/09/01 07:58:08 snowdrop Exp $ + * $Id: tr.c,v 1.4 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -25,11 +25,11 @@ #include "tr.h" #include -#define XSD2C_MAP(xsdtype, ctype) \ - trRegisterType(xsdtype, ctype); +#define XSD2C_MAP(xsdtype, ctype, builtin) \ + trRegisterType(xsdtype, ctype, builtin); -#define XSD2C_MAPNS(xsdtype, ctype) \ - trRegisterTypeNS(trXSDNS, xsdtype, ctype); +#define XSD2C_MAPNS(xsdtype, ctype, builtin) \ + trRegisterTypeNS(trXSDNS, xsdtype, ctype, builtin); #define XSD2C_MAPNS_LIST(xsdtype, ctype) \ trRegisterListTypeNS(trXSDNS, xsdtype, ctype); @@ -49,19 +49,22 @@ static struct XSD2C_TypeRegistry* trl_tail; static char trXSDNS[15]; - +static int _trInitialized = 0; static char* _trC2XSD(const char* cType, struct XSD2C_TypeRegistry* head); static char* _trXSD2C(const char* xsdType, struct XSD2C_TypeRegistry* head); -void trInitModule(const char* ns) +/*void trInitModule(const char* ns)*/ +void trInitModule() { - struct XSD2C_TypeRegistry* cur; + if (_trInitialized) + return; +/* struct XSD2C_TypeRegistry* cur;*/ tr_head = NULL; tr_tail = NULL; trl_head = NULL; trl_tail = NULL; - +/* strcpy(trXSDNS, ns); #include "types.map" @@ -73,6 +76,8 @@ void trInitModule(const char* ns) cur->isbuildin = 1; cur = cur->next; } +*/ + _trInitialized = 1; }; @@ -141,12 +146,12 @@ char* trXSD2CList(const char* xsdType) return _trXSD2C(xsdType, trl_head); } -void trRegisterType(const char* xsdType, const char* cType) +void trRegisterType(const char* xsdType, const char* cType, int builtin) { - trRegisterTypeNS(NULL, xsdType, cType); + trRegisterTypeNS(NULL, xsdType, cType, builtin); } -void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType) +void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType, int builtin) { struct XSD2C_TypeRegistry* reg; if (xsdType == NULL || cType == NULL) @@ -159,14 +164,15 @@ void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType) reg->xsd_type = (char*)malloc((ns?strlen(ns):0)+strlen(xsdType)+2); reg->c_type = (char*)malloc(strlen(cType)+1); reg->next = NULL; - reg->isbuildin = 0; + reg->isbuildin = builtin; - if (ns) + if (ns) sprintf(reg->xsd_type, "%s:%s",ns,xsdType); else strcpy(reg->xsd_type, xsdType); strcpy(reg->c_type, cType); + printf("[TYPE] Registered '%s'->'%s'\n", reg->xsd_type, reg->c_type); if (tr_tail) { @@ -181,7 +187,7 @@ void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType) tr_tail = reg; } -char* trXSDParseNs(const char* xsdType) +char* trXSDParseNs(char* xsdType) { int c = 0; while (xsdType[c] != '\0' ) { @@ -237,17 +243,20 @@ char* _trC2XSD(const char* cType, struct XSD2C_TypeRegistry* head) { struct XSD2C_TypeRegistry* cur; + printf("[TYPE] Search: '%s' ", cType?cType:"null"); cur = head; while (cur != NULL) { if (!strcmp(cur->c_type, cType)) { + printf("FOUND\n"); return cur->xsd_type; } cur = cur->next; } + printf("NOT FOUND\n"); return NULL; } diff --git a/xsd2c/tr.h b/xsd2c/tr.h index fe6cb60..15fe5a4 100644 --- a/xsd2c/tr.h +++ b/xsd2c/tr.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: tr.h,v 1.2 2004/06/03 20:23:03 snowdrop Exp $ + * $Id: tr.h,v 1.3 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,7 +24,8 @@ #ifndef XSD2C_TR_H #define XSD2C_TR_H -void trInitModule(const char* ns); +/*void trInitModule(const char* ns);*/ +void trInitModule(); void trFreeModule(); char* trC2XSD(const char* cType); @@ -33,14 +34,14 @@ char* trXSD2C(const char* xsdType); char* trC2XSDList(const char* cType); char* trXSD2CList(const char* xsdType); -void trRegisterType(const char* xsdType, const char* cType); -void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType); +void trRegisterType(const char* xsdType, const char* cType, int builtin); +void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType, int builtin); void trRegisterListType(const char* xsdType, const char* cType); void trRegisterListTypeNS(const char* ns, const char* xsdType, const char* cType); int trGetBuildInFlag(const char* xsdType); -char* trXSDParseNs(const char* xsdType); +char* trXSDParseNs(char* xsdType); #endif diff --git a/xsd2c/types.map b/xsd2c/types.map index e6f4bc3..4f22de3 100644 --- a/xsd2c/types.map +++ b/xsd2c/types.map @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: types.map,v 1.1 2004/06/02 11:17:03 snowdrop Exp $ + * $Id: types.map,v 1.2 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -35,4 +35,5 @@ XSD2C_MAPNS("string", "char*") XSD2C_MAPNS("integer", "int") XSD2C_MAPNS("int", "int") XSD2C_MAPNS("double", "double") +XSD2C_MAPNS("float", "float") XSD2C_MAPNS("boolean", "int") diff --git a/xsd2c/xsd2c.c b/xsd2c/xsd2c.c index d8d5cb1..ccb821b 100644 --- a/xsd2c/xsd2c.c +++ b/xsd2c/xsd2c.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: xsd2c.c,v 1.6 2004/06/03 20:23:03 snowdrop Exp $ + * $Id: xsd2c.c,v 1.7 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -38,45 +38,86 @@ #define NODE_NAME_EQUALS(xmlnode, text) \ (!xmlStrcmp(xmlnode->name, (const xmlChar *)text)) -static xmlNodePtr _xmlGetChild(xmlNodePtr node); -static xmlNodePtr _xmlGetNext(xmlNodePtr node); -static HCOMPLEXTYPE xsdProcComplexType(xmlNodePtr node, const char* type); +static xmlNodePtr _xmlGetChild (xmlNodePtr node); +static xmlNodePtr _xmlGetNext (xmlNodePtr node); +static HCOMPLEXTYPE xsdProcComplexType (xmlNodePtr node, const char *type); -static -xsdKeyword xsdGetKeyword(xmlNodePtr node) +static xsdKeyword +xsdGetKeyword (xmlNodePtr node) { - if (node == NULL) return XSD_UNKNOWN; - - if (NODE_NAME_EQUALS(node, XSD_ALL_STR)) return XSD_ALL; - if (NODE_NAME_EQUALS(node, XSD_ANNOTATION_STR)) return XSD_ANNOTATION; - if (NODE_NAME_EQUALS(node, XSD_ANY_STR)) return XSD_ANY; - if (NODE_NAME_EQUALS(node, XSD_ANY_ATTRIBUTE_STR)) return XSD_ANY_ATTRIBUTE; - if (NODE_NAME_EQUALS(node, XSD_APPINFO_STR)) return XSD_APPINFO; - if (NODE_NAME_EQUALS(node, XSD_ATTRIBUTE_STR)) return XSD_ATTRIBUTE; - if (NODE_NAME_EQUALS(node, XSD_ATTRIBUTE_GROUP_STR)) return XSD_ATTRIBUTE_GROUP; - if (NODE_NAME_EQUALS(node, XSD_CHOICE_STR)) return XSD_CHOICE; - if (NODE_NAME_EQUALS(node, XSD_COMPLEX_TYPE_STR)) return XSD_COMPLEX_TYPE; - if (NODE_NAME_EQUALS(node, XSD_COMPLEX_CONTENT_STR)) return XSD_COMPLEX_CONTENT; - if (NODE_NAME_EQUALS(node, XSD_DOCUMENTATION_STR)) return XSD_DOCUMENTATION; - if (NODE_NAME_EQUALS(node, XSD_ELEMENT_STR)) return XSD_ELEMENT; - if (NODE_NAME_EQUALS(node, XSD_EXTENSION_STR)) return XSD_EXTENSION; - if (NODE_NAME_EQUALS(node, XSD_FIELD_STR)) return XSD_FIELD; - if (NODE_NAME_EQUALS(node, XSD_GROUP_STR)) return XSD_GROUP; - if (NODE_NAME_EQUALS(node, XSD_IMPORT_STR)) return XSD_IMPORT; - if (NODE_NAME_EQUALS(node, XSD_INCLUDE_STR)) return XSD_INCLUDE; - if (NODE_NAME_EQUALS(node, XSD_KEY_STR)) return XSD_KEY; - if (NODE_NAME_EQUALS(node, XSD_KEYREF_STR)) return XSD_KEYREF; - if (NODE_NAME_EQUALS(node, XSD_LIST_STR)) return XSD_LIST; - if (NODE_NAME_EQUALS(node, XSD_NOTATION_STR)) return XSD_NOTATION; - if (NODE_NAME_EQUALS(node, XSD_REDEFINE_STR)) return XSD_REDEFINE; - if (NODE_NAME_EQUALS(node, XSD_RESTRICTION_STR)) return XSD_RESTRICTION; - if (NODE_NAME_EQUALS(node, XSD_SCHEMA_STR)) return XSD_SCHEMA; - if (NODE_NAME_EQUALS(node, XSD_SELECTOR_STR)) return XSD_SELECTOR; - if (NODE_NAME_EQUALS(node, XSD_SEQUENCE_STR)) return XSD_SEQUENCE; - if (NODE_NAME_EQUALS(node, XSD_SIMPLE_CONTENT_STR)) return XSD_SIMPLE_CONTENT; - if (NODE_NAME_EQUALS(node, XSD_SIMPLE_TYPE_STR)) return XSD_SIMPLE_TYPE; - if (NODE_NAME_EQUALS(node, XSD_UNION_STR)) return XSD_UNION; - if (NODE_NAME_EQUALS(node, XSD_UNIQUE_STR)) return XSD_UNIQUE; + if (node == NULL) + return XSD_UNKNOWN; + + if (NODE_NAME_EQUALS (node, XSD_ALL_STR)) + return XSD_ALL; + if (NODE_NAME_EQUALS (node, XSD_ANNOTATION_STR)) + return XSD_ANNOTATION; + if (NODE_NAME_EQUALS (node, XSD_ANY_STR)) + return XSD_ANY; + if (NODE_NAME_EQUALS (node, XSD_ANY_ATTRIBUTE_STR)) + return XSD_ANY_ATTRIBUTE; + if (NODE_NAME_EQUALS (node, XSD_APPINFO_STR)) + return XSD_APPINFO; + if (NODE_NAME_EQUALS (node, XSD_ATTRIBUTE_STR)) + return XSD_ATTRIBUTE; + if (NODE_NAME_EQUALS (node, XSD_ATTRIBUTE_GROUP_STR)) + return XSD_ATTRIBUTE_GROUP; + if (NODE_NAME_EQUALS (node, XSD_CHOICE_STR)) + return XSD_CHOICE; + if (NODE_NAME_EQUALS (node, XSD_COMPLEX_TYPE_STR)) + return XSD_COMPLEX_TYPE; + if (NODE_NAME_EQUALS (node, XSD_COMPLEX_CONTENT_STR)) + return XSD_COMPLEX_CONTENT; + if (NODE_NAME_EQUALS (node, XSD_DOCUMENTATION_STR)) + return XSD_DOCUMENTATION; + if (NODE_NAME_EQUALS (node, XSD_ELEMENT_STR)) + return XSD_ELEMENT; + if (NODE_NAME_EQUALS (node, XSD_ENUMERATION_STR)) + return XSD_ENUMERATION; + if (NODE_NAME_EQUALS (node, XSD_EXTENSION_STR)) + return XSD_EXTENSION; + if (NODE_NAME_EQUALS (node, XSD_FIELD_STR)) + return XSD_FIELD; + if (NODE_NAME_EQUALS (node, XSD_GROUP_STR)) + return XSD_GROUP; + if (NODE_NAME_EQUALS (node, XSD_IMPORT_STR)) + return XSD_IMPORT; + if (NODE_NAME_EQUALS (node, XSD_INCLUDE_STR)) + return XSD_INCLUDE; + if (NODE_NAME_EQUALS (node, XSD_KEY_STR)) + return XSD_KEY; + if (NODE_NAME_EQUALS (node, XSD_KEYREF_STR)) + return XSD_KEYREF; + if (NODE_NAME_EQUALS (node, XSD_LIST_STR)) + return XSD_LIST; + if (NODE_NAME_EQUALS (node, XSD_NOTATION_STR)) + return XSD_NOTATION; + if (NODE_NAME_EQUALS (node, XSD_REDEFINE_STR)) + return XSD_REDEFINE; + if (NODE_NAME_EQUALS (node, XSD_RESTRICTION_STR)) + return XSD_RESTRICTION; + if (NODE_NAME_EQUALS (node, XSD_SCHEMA_STR)) + return XSD_SCHEMA; + if (NODE_NAME_EQUALS (node, XSD_SELECTOR_STR)) + return XSD_SELECTOR; + if (NODE_NAME_EQUALS (node, XSD_SEQUENCE_STR)) + return XSD_SEQUENCE; + if (NODE_NAME_EQUALS (node, XSD_SIMPLE_CONTENT_STR)) + return XSD_SIMPLE_CONTENT; + if (NODE_NAME_EQUALS (node, XSD_SIMPLE_TYPE_STR)) + return XSD_SIMPLE_TYPE; + if (NODE_NAME_EQUALS (node, XSD_UNION_STR)) + return XSD_UNION; + if (NODE_NAME_EQUALS (node, XSD_UNIQUE_STR)) + return XSD_UNIQUE; + if (NODE_NAME_EQUALS (node, XSD_MIN_INCLUSIVE_STR)) + return XSD_MIN_INCLUSIVE; + if (NODE_NAME_EQUALS (node, XSD_MAX_INCLUSIVE_STR)) + return XSD_MAX_INCLUSIVE; + if (NODE_NAME_EQUALS (node, XSD_MIN_EXCLUSIVE_STR)) + return XSD_MIN_EXCLUSIVE; + if (NODE_NAME_EQUALS (node, XSD_MAX_EXCLUSIVE_STR)) + return XSD_MAX_EXCLUSIVE; return XSD_UNKNOWN; } @@ -87,20 +128,23 @@ static char outDir[1054]; -static -xmlNodePtr xmlFindSubElement(xmlNodePtr root, const char* element_name) +static xmlNodePtr +xmlFindSubElement (xmlNodePtr root, const char *element_name) { xmlNodePtr cur; cur = root->xmlChildrenNode; - while (cur != NULL) { - - if (cur->type != XML_ELEMENT_NODE) { + while (cur != NULL) + { + + if (cur->type != XML_ELEMENT_NODE) + { cur = cur->next; continue; } - if (!xmlStrcmp(cur->name, (const xmlChar*)element_name)) { + if (!xmlStrcmp (cur->name, (const xmlChar *) element_name)) + { return cur; } @@ -110,67 +154,75 @@ xmlNodePtr xmlFindSubElement(xmlNodePtr root, const char* element_name) return NULL; } -xmlNodePtr xsdLoadFile(const char* filename) +xmlNodePtr +xsdLoadFile (const char *filename) { xmlDocPtr doc; xmlNodePtr cur; - doc = xmlParseFile(filename); - if (doc == NULL) return NULL; + doc = xmlParseFile (filename); + if (doc == NULL) + return NULL; - cur = xmlDocGetRootElement(doc); + cur = xmlDocGetRootElement (doc); return cur; } -xmlNodePtr wsdlLoadFile(const char* filename) +xmlNodePtr +wsdlLoadFile (const char *filename) { xmlDocPtr doc; xmlNodePtr cur; xmlNodePtr sub; xsdKeyword keyword; - doc = xmlParseFile(filename); - if (doc == NULL) return NULL; + doc = xmlParseFile (filename); + if (doc == NULL) + return NULL; - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { + cur = xmlDocGetRootElement (doc); + if (cur == NULL) + { return NULL; } - cur = xmlFindSubElement(cur, "types"); - if (cur == NULL) return NULL; + cur = xmlFindSubElement (cur, "types"); + if (cur == NULL) + return NULL; /* sub = xmlFindSubElement(cur, "schema"); if (sub != NULL) return sub; */ /* some wsdl's defines xsd without root element */ - sub = _xmlGetChild(cur); - keyword = xsdGetKeyword(sub); - switch (keyword) + sub = _xmlGetChild (cur); + keyword = xsdGetKeyword (sub); + switch (keyword) { - case XSD_ELEMENT: - case XSD_COMPLEX_TYPE: - case XSD_SIMPLE_TYPE: - case XSD_SCHEMA: - return sub; - default: - fprintf(stderr, "Unexpected node: '%s'\n", cur->name); + case XSD_ELEMENT: + case XSD_COMPLEX_TYPE: + case XSD_SIMPLE_TYPE: + case XSD_SCHEMA: + return sub; + default: + fprintf (stderr, "Unexpected node: '%s'\n", cur->name); } return NULL; } -static -xmlNodePtr _xmlGetChild(xmlNodePtr node) +static xmlNodePtr +_xmlGetChild (xmlNodePtr node) { xmlNodePtr cur = NULL; cur = node->xmlChildrenNode; - while (cur != NULL) { - if (cur->type != XML_ELEMENT_NODE) { + while (cur != NULL) + { + if (cur->type != XML_ELEMENT_NODE) + { cur = cur->next; continue; } @@ -179,13 +231,15 @@ xmlNodePtr _xmlGetChild(xmlNodePtr node) return cur; } -static -xmlNodePtr _xmlGetNext(xmlNodePtr node) +static xmlNodePtr +_xmlGetNext (xmlNodePtr node) { xmlNodePtr cur = NULL; cur = node->next; - while (cur != NULL) { - if (cur->type != XML_ELEMENT_NODE) { + while (cur != NULL) + { + if (cur->type != XML_ELEMENT_NODE) + { cur = cur->next; continue; } @@ -194,37 +248,37 @@ xmlNodePtr _xmlGetNext(xmlNodePtr node) return cur; } -static -void xsdProcAttribute(HCOMPLEXTYPE parent, xmlNodePtr node) +static void +xsdProcAttribute (HCOMPLEXTYPE parent, xmlNodePtr node) { char *name, *type; /* xmlNodePtr cur; char buffer[1054]; */ - name = xmlGetProp(node, ATTR_NAME_STR); - type = xmlGetProp(node, ATTR_TYPE_STR); + name = xmlGetProp (node, ATTR_NAME_STR); + type = xmlGetProp (node, ATTR_TYPE_STR); - /* printf(" %s: %s\n", type?type:"(null)", - name?name:"(null)"); -*/ + /* printf(" %s: %s\n", type?type:"(null)", + name?name:"(null)"); + */ if (name == NULL) { - fprintf(stderr, "WARNING: Attribute without name!\n"); + fprintf (stderr, "WARNING: Attribute without name!\n"); return; } if (type == NULL) { - fprintf(stderr, "WARNING: Attribute '%s' has no type\n", name); + fprintf (stderr, "WARNING: Attribute '%s' has no type\n", name); } /* sprintf(buffer, "attr_%s", name); */ - objAddAttribute(parent, name, type, 0); + objAddAttribute (parent, name, type, 0); } -static -void xsdProcElement(HCOMPLEXTYPE parent, xmlNodePtr node) +static void +xsdProcElement (HCOMPLEXTYPE parent, xmlNodePtr node) { char *name, *type, *minostr, *maxostr; xmlNodePtr cur; @@ -232,231 +286,366 @@ void xsdProcElement(HCOMPLEXTYPE parent, xmlNodePtr node) char buffer[1054]; HCOMPLEXTYPE ct; int mino, maxo; - - name = xmlGetProp(node, ATTR_NAME_STR); - type = xmlGetProp(node, ATTR_TYPE_STR); - minostr = xmlGetProp(node, ATTR_MIN_OCCURS_STR); - maxostr = xmlGetProp(node, ATTR_MAX_OCCURS_STR); + + name = xmlGetProp (node, ATTR_NAME_STR); + type = xmlGetProp (node, ATTR_TYPE_STR); + minostr = xmlGetProp (node, ATTR_MIN_OCCURS_STR); + maxostr = xmlGetProp (node, ATTR_MAX_OCCURS_STR); /* printf(" %s: %s\n", type?type:"(null)", name?name:"(null)"); */ - if (minostr == NULL) mino = 1; - else mino = atoi(minostr); + if (minostr == NULL) + mino = 1; + else + mino = atoi (minostr); - if (maxostr == NULL) maxo = 1; - else { - if (!strcmp(maxostr, ATTR_VALUE_UNBOUNDED)) + if (maxostr == NULL) + maxo = 1; + else + { + if (!strcmp (maxostr, ATTR_VALUE_UNBOUNDED)) maxo = -1; else - maxo = atoi(maxostr); + maxo = atoi (maxostr); } - + if (type == NULL) { /* check for complexType */ - cur = _xmlGetChild(node); + cur = _xmlGetChild (node); if (cur == NULL) { - fprintf(stderr, "WARNING: Element '%s' has no childs\n", name); + fprintf (stderr, "WARNING: Element '%s' has no childs\n", name); return; } do { - keyword = xsdGetKeyword(cur); + keyword = xsdGetKeyword (cur); switch (keyword) { - case XSD_COMPLEX_TYPE: - /* - type = xmlGetProp(cur, ATTR_NAME_STR); - if (type == NULL) - { - fprintf(stderr, "WARNING: Type name not found\n"); - break; - } - */ - - sprintf(buffer, "%s_%s", parent->type, (const char*)name); - ct = xsdProcComplexType(cur, (const char*)buffer); - if (ct != NULL) - { - objAddElement(parent, name, buffer,0, mino, maxo); - } - break; - - default: - fprintf(stderr, "Unexpected node: '%s'\n", cur->name); + case XSD_COMPLEX_TYPE: + /* + type = xmlGetProp(cur, ATTR_NAME_STR); + if (type == NULL) + { + fprintf(stderr, "WARNING: Type name not found\n"); + break; + } + */ + + sprintf (buffer, "%s_%s", parent->type, (const char *) name); + ct = xsdProcComplexType (cur, (const char *) buffer); + if (ct != NULL) + { + objAddElement (parent, name, buffer, 0, mino, maxo); + } + break; + + default: + fprintf (stderr, "Unexpected node: '%s'\n", cur->name); } - } while ((cur = _xmlGetNext(cur)) != NULL); + } while ((cur = _xmlGetNext (cur)) != NULL); } else { - objAddElement(parent, name, type,0, mino, maxo); + objAddElement (parent, name, type, 0, mino, maxo); } - if (name) xmlFree(name); - if (type) xmlFree(type); +/* if (name) xmlFree(name); + if (type) xmlFree(type);*/ } -static -void xsdProcSequence(HCOMPLEXTYPE ct, xmlNodePtr node) +static void +xsdProcSequence (HCOMPLEXTYPE ct, xmlNodePtr node) { xmlNodePtr cur = NULL; xsdKeyword keyword; - cur = _xmlGetChild(node); - if (cur == NULL) { - fprintf(stderr, "WARNING: Empty sequence\n"); + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty sequence\n"); return; } - do { - keyword = xsdGetKeyword(cur); + do + { + keyword = xsdGetKeyword (cur); - switch (keyword) + switch (keyword) { - case XSD_ANNOTATION: - /* nothing to do*/ - break; + case XSD_ANNOTATION: + /* nothing to do */ + break; - case XSD_GROUP: - fprintf(stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); - break; + case XSD_GROUP: + fprintf (stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); + break; - case XSD_CHOICE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); - break; + case XSD_CHOICE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); + break; - case XSD_SEQUENCE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_SEQUENCE_STR); - break; + case XSD_SEQUENCE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_SEQUENCE_STR); + break; - case XSD_ANY: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ANY_STR); - break; + case XSD_ANY: + fprintf (stderr, "WARNING: %s not supported\n", XSD_ANY_STR); + break; - case XSD_ELEMENT: - xsdProcElement(ct, cur); - break; + case XSD_ELEMENT: + xsdProcElement (ct, cur); + break; - default: - fprintf(stderr, "WARNING: Unknown child ('%s')!\n", (char*)cur->name); + default: + fprintf (stderr, "WARNING: Unknown child ('%s')!\n", + (char *) cur->name); }; - } while ((cur = _xmlGetNext(cur)) != NULL); + } while ((cur = _xmlGetNext (cur)) != NULL); } -static -void xsdProcExtension(HCOMPLEXTYPE ct, xmlNodePtr node, const char* type) +static void +xsdProcExtension (HCOMPLEXTYPE ct, xmlNodePtr node, const char *type) { xmlNodePtr cur = NULL; xsdKeyword keyword; - char * base; + char *base; - base = xmlGetProp(node, ATTR_BASE_STR); - if (base == NULL) { - fprintf(stderr, "WARNING: No base defined\n"); + base = xmlGetProp (node, ATTR_BASE_STR); + if (base == NULL) + { + fprintf (stderr, "WARNING: No base defined\n"); return; } - - printf(" =[Base] -> %s\n", base); - objSetBaseType(ct, base); - xmlFree(base); - - cur = _xmlGetChild(node); - if (cur == NULL) { - fprintf(stderr, "WARNING: Empty node\n"); + + printf (" =[Base] -> %s\n", base); + objSetBaseType (ct, base); +/* xmlFree(base);*/ + + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty node\n"); return; } - do { - keyword = xsdGetKeyword(cur); + do + { + keyword = xsdGetKeyword (cur); - switch (keyword) + switch (keyword) { - case XSD_ANNOTATION: - /* nothing to do*/ - break; + case XSD_ANNOTATION: + /* nothing to do */ + break; - case XSD_ALL: - fprintf(stderr, " WARNING: %s not supported\n", XSD_ALL_STR); - break; + case XSD_ALL: + fprintf (stderr, " WARNING: %s not supported\n", XSD_ALL_STR); + break; - case XSD_GROUP: - fprintf(stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); - break; + case XSD_GROUP: + fprintf (stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); + break; - case XSD_CHOICE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); - break; + case XSD_CHOICE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); + break; - case XSD_ATTRIBUTE: - xsdProcAttribute(ct, cur); - break; + case XSD_ATTRIBUTE: + xsdProcAttribute (ct, cur); + break; - case XSD_ATTRIBUTE_GROUP: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ATTRIBUTE_GROUP_STR); - break; + case XSD_ATTRIBUTE_GROUP: + fprintf (stderr, "WARNING: %s not supported\n", + XSD_ATTRIBUTE_GROUP_STR); + break; - case XSD_ANY_ATTRIBUTE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ANY_ATTRIBUTE_STR); - break; + case XSD_ANY_ATTRIBUTE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_ANY_ATTRIBUTE_STR); + break; + + case XSD_SEQUENCE: + xsdProcSequence (ct, cur); + break; - case XSD_SEQUENCE: - xsdProcSequence(ct, cur); - break; - - default: - fprintf(stderr, "WARNING: Unknown child ('%s')!\n", (char*)cur->name); + default: + fprintf (stderr, "WARNING: Unknown child ('%s')!\n", + (char *) cur->name); }; - - } while ((cur = _xmlGetNext(cur)) != NULL); + + } while ((cur = _xmlGetNext (cur)) != NULL); } -static -void xsdProcComplexContent(HCOMPLEXTYPE ct, xmlNodePtr node, const char* type) +static void +xsdProcComplexContent (HCOMPLEXTYPE ct, xmlNodePtr node, const char *type) { xmlNodePtr cur = NULL; xsdKeyword keyword; - cur = _xmlGetChild(node); - if (cur == NULL) { - fprintf(stderr, "WARNING: Empty sequence\n"); + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty sequence\n"); return; } - do { - keyword = xsdGetKeyword(cur); + do + { + keyword = xsdGetKeyword (cur); - switch (keyword) + switch (keyword) { - case XSD_ANNOTATION: - /* nothing to do*/ - break; + case XSD_ANNOTATION: + /* nothing to do */ + break; - case XSD_EXTENSION: - xsdProcExtension(ct, cur, type); - break; + case XSD_EXTENSION: + xsdProcExtension (ct, cur, type); + break; - case XSD_RESTRICTION: - fprintf(stderr, "WARNING: %s not supported\n", XSD_RESTRICTION_STR); - break; + case XSD_RESTRICTION: + fprintf (stderr, "WARNING: %s not supported\n", XSD_RESTRICTION_STR); + break; + + default: + fprintf (stderr, "WARNING: Unknown child ('%s')!\n", + (char *) cur->name); + }; + + } while ((cur = _xmlGetNext (cur)) != NULL); +} + +void +xsdProcRestriction(HCOMPLEXTYPE ct, xmlNodePtr node, const char *type) +{ + xmlNodePtr cur = NULL; + xsdKeyword keyword; + char *value; + HRESTRICTION res; + char *base; + + + base = xmlGetProp (node, ATTR_BASE_STR); + if (base == NULL) + { + fprintf (stderr, "WARNING: No base defined\n"); + return; + } + + printf (" =[Base] -> %s\n", base); + res = resCreate(base); + ct->restriction = res; + +/* xmlFree(base);*/ + + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty sequence\n"); + return; + } + + do + { + value = xmlGetProp (cur, ATTR_VALUE_STR); + if (!value) { + fprintf(stderr, "WARNING: Found SimpleContent->%s without attribute value.\n", + cur->name); + continue; + } + + keyword = xsdGetKeyword (cur); + + switch (keyword) + { + case XSD_MIN_INCLUSIVE: + res->minInclusive = atoi(value); + res->minInclusiveSet = 1; + res->mode = RES_MODE_MINMAX; + break; + + case XSD_MAX_INCLUSIVE: + res->maxInclusive = atoi(value); + res->maxInclusiveSet = 1; + res->mode = RES_MODE_MINMAX; + break; + + case XSD_MIN_EXCLUSIVE: + res->minExclusive = atoi(value); + res->minExclusiveSet = 1; + res->mode = RES_MODE_MINMAX; + break; + + case XSD_MAX_EXCLUSIVE: + res->maxExclusive = atoi(value); + res->maxExclusiveSet = 1; + res->mode = RES_MODE_MINMAX; + break; + + case XSD_ENUMERATION: + Enumeration_Add_value(res->enumeration, value); + res->mode = RES_MODE_ENUMERATION; + default: + fprintf (stderr, "WARNING: Unknown child (SimpleContent->'%s')!\n", + (char *) cur->name); + }; - default: - fprintf(stderr, "WARNING: Unknown child ('%s')!\n", (char*)cur->name); + } while ((cur = _xmlGetNext (cur)) != NULL); + +} + +void +xsdProcSimpleContent (HCOMPLEXTYPE ct, xmlNodePtr node, const char *type) +{ + xmlNodePtr cur = NULL; + xsdKeyword keyword; + + ct->isSimpleContent = 1; + + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty node\n"); + return; + } + + do + { + keyword = xsdGetKeyword (cur); + + switch (keyword) + { + case XSD_ANNOTATION: + /* nothing to do */ + break; + + case XSD_RESTRICTION: + xsdProcRestriction(ct, cur, type); + break; + + case XSD_ATTRIBUTE: + xsdProcAttribute (ct, cur); + break; + + default: + fprintf (stderr, "WARNING: Unknown child (SimpleContent->'%s')!\n", + (char *) cur->name); }; - - } while ((cur = _xmlGetNext(cur)) != NULL); + + } while ((cur = _xmlGetNext (cur)) != NULL); } -static -HCOMPLEXTYPE xsdProcComplexType(xmlNodePtr node, const char* type) +static HCOMPLEXTYPE +xsdProcComplexType (xmlNodePtr node, const char *type) { char *name; xmlNodePtr cur = NULL; @@ -465,232 +654,343 @@ HCOMPLEXTYPE xsdProcComplexType(xmlNodePtr node, const char* type) if (!type) - name = xmlGetProp(node, ATTR_NAME_STR); - else { - name = (char*)malloc(strlen(type)+1); - strcpy(name, type); + name = xmlGetProp (node, ATTR_NAME_STR); + else + { + name = (char *) malloc (strlen (type) + 1); + strcpy (name, type); } if (!name) { - fprintf(stderr, "\nWARNING: complexType has no typename!\n"); + fprintf (stderr, "\nWARNING: complexType has no typename!\n"); return NULL; } - - ct = objCreateComplexType(name); - - printf("\ncomplexType->%s\n", name); - - cur = _xmlGetChild(node); - if (cur == NULL) { - fprintf(stderr, "WARNING: Empty complexType\n"); + + ct = objCreateComplexType (name); + + printf ("\ncomplexType->%s\n", name); + + cur = _xmlGetChild (node); + if (cur == NULL) + { + fprintf (stderr, "WARNING: Empty complexType\n"); return ct; } + + do + { + keyword = xsdGetKeyword (cur); - do { - keyword = xsdGetKeyword(cur); - - switch (keyword) + switch (keyword) { - case XSD_ANNOTATION: - /* nothing to do*/ - break; + case XSD_ANNOTATION: + /* nothing to do */ + break; - case XSD_SIMPLE_CONTENT: - fprintf(stderr, "WARNING: %s not supported\n", XSD_SIMPLE_CONTENT_STR); - break; + case XSD_SIMPLE_CONTENT: + xsdProcSimpleContent (ct, cur, name); + break; - case XSD_COMPLEX_CONTENT: - xsdProcComplexContent(ct, cur, name); + case XSD_COMPLEX_CONTENT: + xsdProcComplexContent (ct, cur, name); /* fprintf(stderr, "WARNING: %s not supported\n", XSD_COMPLEX_CONTENT_STR); */ - break; + break; - case XSD_ALL: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ALL_STR); - break; + case XSD_ALL: + fprintf (stderr, "WARNING: %s not supported\n", XSD_ALL_STR); + break; - case XSD_GROUP: - fprintf(stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); - break; + case XSD_GROUP: + fprintf (stderr, "WARNING: %s not supported\n", XSD_GROUP_STR); + break; - case XSD_CHOICE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); - break; + case XSD_CHOICE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_CHOICE_STR); + break; - case XSD_ATTRIBUTE: - xsdProcAttribute(ct, cur); - break; + case XSD_ATTRIBUTE: + xsdProcAttribute (ct, cur); + break; - case XSD_ATTRIBUTE_GROUP: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ATTRIBUTE_GROUP_STR); - break; + case XSD_ATTRIBUTE_GROUP: + fprintf (stderr, "WARNING: %s not supported\n", + XSD_ATTRIBUTE_GROUP_STR); + break; - case XSD_ANY_ATTRIBUTE: - fprintf(stderr, "WARNING: %s not supported\n", XSD_ANY_ATTRIBUTE_STR); - break; + case XSD_ANY_ATTRIBUTE: + fprintf (stderr, "WARNING: %s not supported\n", XSD_ANY_ATTRIBUTE_STR); + break; + + case XSD_SEQUENCE: + xsdProcSequence (ct, cur); + break; - case XSD_SEQUENCE: - xsdProcSequence(ct, cur); - break; - - default: - fprintf(stderr, "WARNING: Unknown child ('%s')!\n", (char*)cur->name); + default: + fprintf (stderr, "WARNING: Unknown child ('%s')!\n", + (char *) cur->name); }; - - } while ((cur = _xmlGetNext(cur)) != NULL); - xmlFree(name); + } while ((cur = _xmlGetNext (cur)) != NULL); + +/* xmlFree(name);*/ return ct; } -static -void runGenerator(xmlNodePtr xsdRoot) +static void +runGenerator (xmlNodePtr xsdRoot) { xmlNodePtr cur; xmlNodePtr node; xmlChar *type; cur = xsdRoot->xmlChildrenNode; - while (cur != NULL) { + while (cur != NULL) + { - if (cur->type != XML_ELEMENT_NODE) { + if (cur->type != XML_ELEMENT_NODE) + { cur = cur->next; continue; } - if (xsdGetKeyword(cur) == XSD_COMPLEX_TYPE){ - - xsdProcComplexType(cur, NULL); - - } else if (xsdGetKeyword(cur) == XSD_ELEMENT) { - - type = xmlGetProp(cur, "name"); - if (type == NULL) { - fprintf(stderr, "WARNING: Element found without name ('%s')\n", cur->name); - } else { - - node = xmlFindSubElement(cur, XSD_COMPLEX_TYPE_STR); - if (node != NULL) { - xsdProcComplexType(node, type); - } + if (xsdGetKeyword (cur) == XSD_COMPLEX_TYPE) + { + xsdProcComplexType (cur, NULL); + + } + else if (xsdGetKeyword (cur) == XSD_SIMPLE_TYPE) + { + + fprintf (stderr, "WARNING: SimpleType not supported!\n"); + + } + else if (xsdGetKeyword (cur) == XSD_ELEMENT) + { + + type = xmlGetProp (cur, "name"); + if (type == NULL) + { + fprintf (stderr, "WARNING: Element found without name ('%s')\n", + cur->name); } + else + { - /*xsdProcElement(..., cur);*/ + node = xmlFindSubElement (cur, XSD_COMPLEX_TYPE_STR); + if (node != NULL) + { + xsdProcComplexType (node, type); + } + else + { + /* fprintf (stderr, "WARNING: Element on root node will be ignored\n"); */ + /* TODO: I don't know if this is a good idea!? + make typedef instead.*/ + xsdProcComplexType(cur, type); + } + } + /*xsdProcElement(..., cur); */ + } + else + { + fprintf(stderr, "WARNING: '%s' not supported!\n", cur->name); } cur = cur->next; } } -int declareStructs(HCOMPLEXTYPE ct) +int +declareStructs (HCOMPLEXTYPE ct) { char fname[255]; - FILE* f; + FILE *f; - sprintf(fname, "%s/%s.h", outDir, ct->type); /* _xsd*/ - printf("Generating file '%s' ...\n", fname); - f = fopen(fname, "w"); + sprintf (fname, "%s/%s.h", outDir, ct->type); /* _xsd */ + printf ("Generating file '%s' ...\n", fname); + f = fopen (fname, "w"); if (f == NULL) { - fprintf(stderr, "Can not open '%s'\n", fname); + fprintf (stderr, "Can not open '%s'\n", fname); return 0; } - writeComplexTypeHeaderFile(f, ct); - fclose(f); + writeComplexTypeHeaderFile (f, ct); + fclose (f); return 1; -} +} -int writeSource(HCOMPLEXTYPE ct) +int +writeSource (HCOMPLEXTYPE ct) { char fname[255]; - FILE* f; + FILE *f; - sprintf(fname, "%s/%s.c", outDir, ct->type); /* _xsd*/ - printf("Generating file '%s' ...\n", fname); - f = fopen(fname, "w"); + sprintf (fname, "%s/%s.c", outDir, ct->type); /* _xsd */ + printf ("Generating file '%s' ...\n", fname); + f = fopen (fname, "w"); if (f == NULL) { - fprintf(stderr, "Can not open '%s'\n", fname); + fprintf (stderr, "Can not open '%s'\n", fname); return 0; } - writeComplexTypeSourceFile(f, ct); - fclose(f); + writeComplexTypeSourceFile (f, ct); + fclose (f); return 1; } -int xsdInitTrModule(xmlNodePtr xsdNode) +int +xsdInitTrModule (xmlNodePtr xsdNode) { xmlNsPtr ns = NULL; + char xsd_ns[50]; + + ns = + xmlSearchNsByHref (xsdNode->doc, xsdNode, + "http://www.w3.org/2001/XMLSchema"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xsdNode, + "http://www.w3.org/2001/XMLSchema/"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xsdNode, + "http://www.w3.org/1999/XMLSchema"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xsdNode, + "http://www.w3.org/1999/XMLSchema/"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xmlDocGetRootElement (xsdNode->doc), + "http://www.w3.org/2001/XMLSchema"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xmlDocGetRootElement (xsdNode->doc), + "http://www.w3.org/2001/XMLSchema/"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xmlDocGetRootElement (xsdNode->doc), + "http://www.w3.org/1999/XMLSchema"); + if (ns == NULL) + ns = + xmlSearchNsByHref (xsdNode->doc, xmlDocGetRootElement (xsdNode->doc), + "http://www.w3.org/1999/XMLSchema/"); - if (xsdNode != NULL) { - - ns = xmlSearchNsByHref(xsdNode->doc, xsdNode, "http://www.w3.org/2001/XMLSchema"); - +/* if (ns != NULL && ns->prefix != NULL) { fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); trInitModule(ns->prefix); - } else { - /* - Search for: - - - - ... - */ - ns = xmlSearchNsByHref(xsdNode->doc, xmlDocGetRootElement(xsdNode->doc), "http://www.w3.org/2001/XMLSchema"); - if (ns != NULL && ns->prefix != NULL) { - fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); - trInitModule(ns->prefix); - } else { - trInitModule("xs"); - } - } - - } else { - trInitModule("xs"); + } else { */ + /* + Search for: + + + + ... + */ + /*if (ns != NULL && ns->prefix != NULL) { + fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); + trInitModule(ns->prefix); + } else { + printf("Initializing XML Schema type register with default 'xs'\n"); + trInitModule("xs"); + } + } + + } else { + printf("Initializing XML Schema type register with default 'xs'\n"); + trInitModule("xs"); + } + */ + if (ns != NULL && ns->prefix != NULL) + { + strcpy (xsd_ns, ns->prefix); + } + else + { + fprintf (stderr, "WARNING: using XML Schema prefix 'xsd' as default!\n"); + strcpy (xsd_ns, "xsd"); } + trInitModule (); + + fprintf(stdout, "XML Schema prefix: '%s'\n", xsd_ns); + + trRegisterTypeNS (xsd_ns, "ID", "char*", 1); + trRegisterTypeNS (xsd_ns, "IDREF", "char*", 1); + trRegisterTypeNS (xsd_ns, "IDREFS", "char*", 1); + trRegisterTypeNS (xsd_ns, "string", "char*", 1); + trRegisterTypeNS (xsd_ns, "integer", "int", 1); + trRegisterTypeNS (xsd_ns, "int", "int", 1); + trRegisterTypeNS (xsd_ns, "double", "double", 1); + trRegisterTypeNS (xsd_ns, "float", "float", 1); + trRegisterTypeNS (xsd_ns, "boolean", "int", 1); + + ns = xmlSearchNsByHref (xsdNode->doc, xsdNode, "http://www.w3.org/2003/05/soap-encoding"); + if (ns == NULL) + ns = xmlSearchNsByHref (xsdNode->doc, xsdNode, "http://www.w3.org/2003/05/soap-encoding/"); + if (ns != NULL && ns->prefix != NULL) { + strcpy(xsd_ns, ns->prefix); + trRegisterTypeNS (xsd_ns, "ID", "char*", 1); + trRegisterTypeNS (xsd_ns, "IDREF", "char*", 1); + trRegisterTypeNS (xsd_ns, "IDREFS", "char*", 1); + trRegisterTypeNS (xsd_ns, "string", "char*", 1); + trRegisterTypeNS (xsd_ns, "integer", "int", 1); + trRegisterTypeNS (xsd_ns, "int", "int", 1); + trRegisterTypeNS (xsd_ns, "double", "double", 1); + trRegisterTypeNS (xsd_ns, "float", "float", 1); + trRegisterTypeNS (xsd_ns, "boolean", "int", 1); + } + return 1; } -int xsdInitObjModule(xmlNodePtr xsdNode) +int +xsdInitObjModule (xmlNodePtr xsdNode) { xmlChar *tns = NULL; xmlNsPtr ns; - if (xsdNode != NULL) - tns = xmlGetProp(xsdNode, (const xmlChar*)"targetNamespace"); + if (xsdNode != NULL) + tns = xmlGetProp (xsdNode, (const xmlChar *) "targetNamespace"); - if (tns == NULL) { - - objInitModule(NULL); + if (tns == NULL) + { + + objInitModule (NULL); - } else { + } + else + { - ns = xmlSearchNsByHref(xsdNode->doc, xsdNode, tns); - if (ns == NULL) { - fprintf(stderr, "WARNING: Target namespace not found!\n"); + ns = xmlSearchNsByHref (xsdNode->doc, xsdNode, tns); + if (ns == NULL) + { + fprintf (stderr, "WARNING: Target namespace not found!\n"); return 0; - } + } - if (ns->prefix == NULL) { - fprintf(stderr, "WARNING: Target namespace not found!\n"); + if (ns->prefix == NULL) + { + fprintf (stderr, "WARNING: Target namespace not found!\n"); return 0; } - fprintf(stdout, "Target namespace ('%s') prefix: '%s'\n", tns, ns->prefix); - objInitModule(ns->prefix); + fprintf (stdout, "Target namespace ('%s') prefix: '%s'\n", tns, + ns->prefix); + objInitModule (ns->prefix); } @@ -698,31 +998,33 @@ int xsdInitObjModule(xmlNodePtr xsdNode) return 1; } -void xsdSetDestDir(const char* destDir) +void +xsdSetDestDir (const char *destDir) { - strcpy(outDir, destDir); - - mkdir(destDir, S_IRUSR|S_IWUSR|S_IXUSR | - S_IRGRP|S_IWGRP|S_IXGRP | - S_IROTH|S_IXOTH ); + strcpy (outDir, destDir); + +#ifdef __MINGW32__ + mkdir (destDir); +#else + mkdir (destDir, S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH); +#endif } -int xsdEngineRun(xmlNodePtr xsdNode, const char* destDir) +int +xsdEngineRun (xmlNodePtr xsdNode, const char *destDir) { - xsdSetDestDir(destDir); + xsdSetDestDir (destDir); - if (xsdNode != NULL) { - runGenerator(xsdNode); - objRegistryEnumComplexType(declareStructs); - objRegistryEnumComplexType(writeSource); + if (xsdNode != NULL) + { + runGenerator (xsdNode); + objRegistryEnumComplexType (declareStructs); + objRegistryEnumComplexType (writeSource); } - + return 0; } - - - - diff --git a/xsd2c/xsd2c.h b/xsd2c/xsd2c.h index 7bb4b8c..91e7e1f 100755 --- a/xsd2c/xsd2c.h +++ b/xsd2c/xsd2c.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: xsd2c.h,v 1.2 2004/06/03 08:53:34 snowdrop Exp $ + * $Id: xsd2c.h,v 1.3 2004/10/15 13:35:39 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -40,6 +40,7 @@ #define XSD_COMPLEX_CONTENT_STR "complexContent" #define XSD_DOCUMENTATION_STR "documentation" #define XSD_ELEMENT_STR "element" +#define XSD_ENUMERATION_STR "enumeration" #define XSD_EXTENSION_STR "extension" #define XSD_FIELD_STR "field" #define XSD_GROUP_STR "group" @@ -58,10 +59,15 @@ #define XSD_SIMPLE_TYPE_STR "simpleType" #define XSD_UNION_STR "union" #define XSD_UNIQUE_STR "unique" +#define XSD_MIN_INCLUSIVE_STR "minInclusive" +#define XSD_MAX_INCLUSIVE_STR "maxInclusive" +#define XSD_MIN_EXCLUSIVE_STR "minExclusive" +#define XSD_MAX_EXCLUSIVE_STR "maxExclusive" #define ATTR_TYPE_STR "type" #define ATTR_NAME_STR "name" #define ATTR_BASE_STR "base" +#define ATTR_VALUE_STR "value" #define ATTR_MIN_OCCURS_STR "minOccurs" #define ATTR_MAX_OCCURS_STR "maxOccurs" @@ -92,6 +98,7 @@ enum _xsdKeyword XSD_COMPLEX_CONTENT, XSD_DOCUMENTATION, XSD_ELEMENT, + XSD_ENUMERATION, XSD_EXTENSION, XSD_FIELD, XSD_GROUP, @@ -109,7 +116,11 @@ enum _xsdKeyword XSD_SIMPLE_CONTENT, XSD_SIMPLE_TYPE, XSD_UNION, - XSD_UNIQUE + XSD_UNIQUE, + XSD_MIN_INCLUSIVE, + XSD_MAX_INCLUSIVE, + XSD_MIN_EXCLUSIVE, + XSD_MAX_EXCLUSIVE, }; typedef enum _xsdKeyword xsdKeyword; -- cgit v1.1-32-gdbae