You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
5.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: tr.c,v 1.5 2005/05/27 19:28:16 snowdrop Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammet.net
  23. ******************************************************************/
  24. #include "tr.h"
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #define XSD2C_MAP(xsdtype, ctype, builtin) \
  29. trRegisterType(xsdtype, ctype, builtin);
  30. #define XSD2C_MAPNS(xsdtype, ctype, builtin) \
  31. trRegisterTypeNS(trXSDNS, xsdtype, ctype, builtin);
  32. #define XSD2C_MAPNS_LIST(xsdtype, ctype) \
  33. trRegisterListTypeNS(trXSDNS, xsdtype, ctype);
  34. struct XSD2C_TypeRegistry
  35. {
  36. char *xsd_type;
  37. char *c_type;
  38. int isbuildin;
  39. struct XSD2C_TypeRegistry* next;
  40. };
  41. static struct XSD2C_TypeRegistry* tr_head;
  42. static struct XSD2C_TypeRegistry* tr_tail;
  43. static struct XSD2C_TypeRegistry* trl_head;
  44. static struct XSD2C_TypeRegistry* trl_tail;
  45. static char trXSDNS[15];
  46. static int _trInitialized = 0;
  47. static char* _trC2XSD(const char* cType, struct XSD2C_TypeRegistry* head);
  48. static char* _trXSD2C(const char* xsdType, struct XSD2C_TypeRegistry* head);
  49. /*void trInitModule(const char* ns)*/
  50. void trInitModule()
  51. {
  52. if (_trInitialized)
  53. return;
  54. /* struct XSD2C_TypeRegistry* cur;*/
  55. tr_head = NULL;
  56. tr_tail = NULL;
  57. trl_head = NULL;
  58. trl_tail = NULL;
  59. /*
  60. strcpy(trXSDNS, ns);
  61. #include "types.map"
  62. cur = tr_head;
  63. while (cur != NULL)
  64. {
  65. cur->isbuildin = 1;
  66. cur = cur->next;
  67. }
  68. */
  69. _trInitialized = 1;
  70. };
  71. void trFreeModule()
  72. {
  73. struct XSD2C_TypeRegistry* cur, *tmp;
  74. cur = tr_head;
  75. while (cur != NULL)
  76. {
  77. if (cur->xsd_type) free(cur->xsd_type);
  78. if (cur->c_type) free(cur->c_type);
  79. tmp = cur->next;
  80. free(cur);
  81. cur = tmp;
  82. }
  83. cur = trl_head;
  84. while (cur != NULL)
  85. {
  86. if (cur->xsd_type) free(cur->xsd_type);
  87. if (cur->c_type) free(cur->c_type);
  88. tmp = cur->next;
  89. free(cur);
  90. cur = tmp;
  91. }
  92. }
  93. int trGetBuildInFlag(const char* xsdType)
  94. {
  95. struct XSD2C_TypeRegistry* cur;
  96. cur = tr_head;
  97. while (cur != NULL)
  98. {
  99. if (!strcmp(cur->xsd_type, xsdType))
  100. {
  101. return cur->isbuildin;
  102. }
  103. cur = cur->next;
  104. }
  105. return -1;
  106. }
  107. char* trC2XSD(const char* cType)
  108. {
  109. return _trC2XSD(cType, tr_head);
  110. }
  111. char* trXSD2C(const char* xsdType)
  112. {
  113. return _trXSD2C(xsdType, tr_head);
  114. }
  115. char* trC2XSDList(const char* cType)
  116. {
  117. return _trC2XSD(cType, trl_head);
  118. }
  119. char* trXSD2CList(const char* xsdType)
  120. {
  121. return _trXSD2C(xsdType, trl_head);
  122. }
  123. void trRegisterType(const char* xsdType, const char* cType, int builtin)
  124. {
  125. trRegisterTypeNS(NULL, xsdType, cType, builtin);
  126. }
  127. void trRegisterTypeNS(const char* ns, const char* xsdType, const char* cType, int builtin)
  128. {
  129. struct XSD2C_TypeRegistry* reg;
  130. if (xsdType == NULL || cType == NULL)
  131. {
  132. fprintf(stderr, "WARNING: Can not register type\n");
  133. return;
  134. }
  135. reg = (struct XSD2C_TypeRegistry*)malloc(sizeof(struct XSD2C_TypeRegistry));
  136. reg->xsd_type = (char*)malloc((ns?strlen(ns):0)+strlen(xsdType)+2);
  137. reg->c_type = (char*)malloc(strlen(cType)+1);
  138. reg->next = NULL;
  139. reg->isbuildin = builtin;
  140. if (ns)
  141. sprintf(reg->xsd_type, "%s:%s",ns,xsdType);
  142. else
  143. strcpy(reg->xsd_type, xsdType);
  144. strcpy(reg->c_type, cType);
  145. printf("[TYPE] Registered '%s'->'%s'\n", reg->xsd_type, reg->c_type);
  146. if (tr_tail)
  147. {
  148. tr_tail->next = reg;
  149. }
  150. if (tr_head == NULL)
  151. {
  152. tr_head = reg;
  153. }
  154. tr_tail = reg;
  155. }
  156. char* trXSDParseNs(char* xsdType)
  157. {
  158. int c = 0;
  159. while (xsdType[c] != '\0' ) {
  160. if (xsdType[c] == ':') return &xsdType[++c];
  161. c++;
  162. }
  163. return xsdType;
  164. }
  165. void trRegisterListType(const char* xsdType, const char* cType)
  166. {
  167. trRegisterListTypeNS(NULL, xsdType, cType);
  168. }
  169. void trRegisterListTypeNS(const char* ns, const char* xsdType, const char* cType)
  170. {
  171. struct XSD2C_TypeRegistry* reg;
  172. if (xsdType == NULL || cType == NULL)
  173. {
  174. fprintf(stderr, "WARNING: Can not register type\n");
  175. return;
  176. }
  177. reg = (struct XSD2C_TypeRegistry*)malloc(sizeof(struct XSD2C_TypeRegistry));
  178. reg->xsd_type = (char*)malloc((ns?strlen(ns):0)+strlen(xsdType)+2);
  179. reg->c_type = (char*)malloc(strlen(cType)+1);
  180. reg->next = NULL;
  181. reg->isbuildin = 0;
  182. if (ns)
  183. sprintf(reg->xsd_type, "%s:%s",ns,xsdType);
  184. else
  185. strcpy(reg->xsd_type, xsdType);
  186. strcpy(reg->c_type, cType);
  187. if (trl_tail)
  188. {
  189. trl_tail->next = reg;
  190. }
  191. if (trl_head == NULL)
  192. {
  193. trl_head = reg;
  194. }
  195. trl_tail = reg;
  196. }
  197. static
  198. char* _trC2XSD(const char* cType, struct XSD2C_TypeRegistry* head)
  199. {
  200. struct XSD2C_TypeRegistry* cur;
  201. printf("[TYPE] Search: '%s' ", cType?cType:"null");
  202. cur = head;
  203. while (cur != NULL)
  204. {
  205. if (!strcmp(cur->c_type, cType))
  206. {
  207. printf("FOUND\n");
  208. return cur->xsd_type;
  209. }
  210. cur = cur->next;
  211. }
  212. printf("NOT FOUND\n");
  213. return NULL;
  214. }
  215. static char* _trXSD2C(const char* xsdType, struct XSD2C_TypeRegistry* head)
  216. {
  217. struct XSD2C_TypeRegistry* cur;
  218. cur = head;
  219. while (cur != NULL)
  220. {
  221. /* printf("%s\n", cur->xsd_type);*/
  222. if (!strcmp(cur->xsd_type, xsdType))
  223. {
  224. return cur->c_type;
  225. }
  226. cur = cur->next;
  227. }
  228. return NULL;
  229. }