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.

759 lines
17 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: wsdl2c.c,v 1.9 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@jprogrammer.net
  23. */
  24. #include <libxml/xpath.h>
  25. #include <xsd2c/xsd2c.h>
  26. #include <xsd2c/util.h> /* parseNS */
  27. #include <xsd2c/formatter.h> /* formatter sax serializer */
  28. #include <xsd2c/obj.h> /* formatter sax serializer */
  29. #include <string.h>
  30. #define _DESERIALIZER_DISABLE_
  31. #include "CallList.h"
  32. /* ------------- Just for test --------------------------------- */
  33. int Writer_Tab = 0;
  34. int Writer_Ret = 0;
  35. void Writer_StartElement(const char* element_name, int attr_count, char **keys, char **values, void* userData)
  36. {
  37. int i, j;
  38. if (Writer_Ret) printf("\n");
  39. for (j=0;j<Writer_Tab;j++) printf("\t");
  40. printf("<%s", element_name);
  41. for (i=0;i<attr_count;i++)
  42. {
  43. printf(" %s = \"%s\"", keys[i], values[i]);
  44. }
  45. printf(">");
  46. Writer_Tab++;
  47. Writer_Ret = 1;
  48. }
  49. void Writer_Characters(const char* element_name, const char* chars, void* userData)
  50. {
  51. printf("%s", chars!=NULL?chars:"null");
  52. }
  53. void Writer_EndElement(const char* element_name, void* userData)
  54. {
  55. int j;
  56. Writer_Tab--;
  57. if (!Writer_Ret)
  58. for (j=0;j<Writer_Tab;j++) printf("\t");
  59. printf("</%s>\n", element_name);
  60. Writer_Ret = 0;
  61. }
  62. /* ------------------------------------------------------------- */
  63. struct CallList* callList = NULL;
  64. char soap_prefix[50];
  65. char wsdl_prefix[50];
  66. char target_ns[150];
  67. char target_prefix[50];
  68. xmlXPathObjectPtr xpath_eval(xmlDocPtr doc, const char *xpath)
  69. {
  70. xmlXPathContextPtr context;
  71. xmlXPathObjectPtr result;
  72. xmlNodePtr node;
  73. xmlNsPtr default_ns;
  74. node = xmlDocGetRootElement(doc);
  75. if (node == NULL) {
  76. fprintf(stderr,"empty document\n");
  77. return NULL;
  78. }
  79. context = xmlXPathNewContext(doc);
  80. context->namespaces = xmlGetNsList(doc, node);
  81. context->nsNr = 0;
  82. if (context->namespaces != NULL) {
  83. while (context->namespaces[context->nsNr] != NULL) {
  84. /* fprintf(stdout, "NS: '%s' - '%s'\n", context->namespaces[context->nsNr]->href,
  85. context->namespaces[context->nsNr]->prefix); */
  86. context->nsNr++;
  87. }
  88. }
  89. /* search default namespace */
  90. default_ns = xmlSearchNs(doc, node, NULL);
  91. if (default_ns != NULL && default_ns->href != NULL) {
  92. fprintf(stdout, "Register default namespace '%s'\n", (const char*)default_ns->href);
  93. /* default_ns : "http://schemas.xmlsoap.org/wsdl/" */
  94. xmlXPathRegisterNs(context, "wsdl", default_ns->href );
  95. }
  96. printf("XPath: '%s'\n", xpath);
  97. result = xmlXPathEvalExpression((xmlChar*)xpath, context);
  98. if (result == NULL) {
  99. fprintf(stderr, "ERROR: XPath error!\n");
  100. return NULL;
  101. }
  102. if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
  103. /* no result */
  104. printf("XPath result is empty\n");
  105. return NULL;
  106. }
  107. xmlXPathFreeContext(context);
  108. return result;
  109. }
  110. xmlNodePtr findPortType(xmlDocPtr doc, const char *name)
  111. {
  112. xmlNodePtr root;
  113. xmlNodePtr cur;
  114. xmlChar *attr_name;
  115. root = xmlDocGetRootElement(doc);
  116. if (root == NULL) {
  117. fprintf(stderr, "Empty document!\n");
  118. return NULL;
  119. }
  120. cur = root->xmlChildrenNode;
  121. while (cur != NULL) {
  122. if (cur->type != XML_ELEMENT_NODE) {
  123. cur = cur->next;
  124. continue;
  125. }
  126. if (xmlStrcmp(cur->name, (const xmlChar*)"portType")) {
  127. cur = cur->next;
  128. continue;
  129. }
  130. attr_name = xmlGetProp(cur, "name");
  131. if (attr_name == NULL) {
  132. cur = cur->next;
  133. continue;
  134. }
  135. if (!xmlStrcmp(attr_name, (const xmlChar*)name)) {
  136. /*xmlFree(attr_name);*/
  137. return cur;
  138. }
  139. /*xmlFree(attr_name);*/
  140. cur = cur->next;
  141. }
  142. return NULL;
  143. }
  144. xmlNodePtr findMessage(xmlDocPtr doc, const char *name)
  145. {
  146. xmlNodePtr root;
  147. xmlNodePtr cur;
  148. xmlChar *attr_name;
  149. root = xmlDocGetRootElement(doc);
  150. if (root == NULL) {
  151. fprintf(stderr, "Empty document!\n");
  152. return NULL;
  153. }
  154. cur = root->xmlChildrenNode;
  155. while (cur != NULL) {
  156. if (cur->type != XML_ELEMENT_NODE) {
  157. cur = cur->next;
  158. continue;
  159. }
  160. if (xmlStrcmp(cur->name, (const xmlChar*)"message")) {
  161. cur = cur->next;
  162. continue;
  163. }
  164. attr_name = xmlGetProp(cur, "name");
  165. if (attr_name == NULL) {
  166. cur = cur->next;
  167. continue;
  168. }
  169. if (!xmlStrcmp(attr_name, (const xmlChar*)name)) {
  170. /*xmlFree(attr_name);*/
  171. return cur;
  172. }
  173. /*xmlFree(attr_name);*/
  174. cur = cur->next;
  175. }
  176. return NULL;
  177. }
  178. xmlNodePtr findSubNode(xmlNodePtr root, const char *element_name)
  179. {
  180. xmlNodePtr cur;
  181. cur = root->xmlChildrenNode;
  182. while (cur != NULL) {
  183. if (cur->type != XML_ELEMENT_NODE) {
  184. cur = cur->next;
  185. continue;
  186. }
  187. if (!xmlStrcmp(cur->name, (const xmlChar*)element_name)) {
  188. return cur;
  189. }
  190. cur = cur->next;
  191. }
  192. return NULL;
  193. }
  194. void handleInputParameters(xmlDocPtr doc, const char *name, struct CallFunc *func)
  195. {
  196. char ns[10];
  197. char message_name[255];
  198. xmlNodePtr node;
  199. xmlNodePtr cur;
  200. struct CallVar *var;
  201. xmlChar *var_name, *var_type;
  202. parseNS(name, ns, message_name); /* check why to pase ns? */
  203. node = findMessage(doc, message_name);
  204. if (node == NULL) {
  205. fprintf(stderr, "ERROR: Can not find message '%s'\n", message_name);
  206. return;
  207. }
  208. cur = node->xmlChildrenNode;
  209. while (cur != NULL) {
  210. if (cur->type != XML_ELEMENT_NODE) {
  211. cur = cur->next;
  212. continue;
  213. }
  214. if (xmlStrcmp(cur->name, (const xmlChar*)"part")) {
  215. cur = cur->next;
  216. continue;
  217. }
  218. var_name = xmlGetProp(cur, "name");
  219. if (var_name == NULL) {
  220. fprintf(stderr, "ERROR: Found <part> without attrbute 'name'! (message:'%s')\n",
  221. message_name);
  222. cur = cur->next;
  223. continue;
  224. }
  225. var_type = xmlGetProp(cur, "type");
  226. if (var_type == NULL) {
  227. var_type = xmlGetProp(cur, "element");
  228. }
  229. if (var_type == NULL) {
  230. fprintf(stderr, "ERROR: Found <part> without attrbute 'type' or 'element'! (message:'%s')\n",
  231. message_name);
  232. /*xmlFree(var_name);*/
  233. cur = cur->next;
  234. continue;
  235. }
  236. var = CallVar_Create();
  237. CallVar_Set_name(var, (const char*)var_name);
  238. CallVar_Set_type(var, (const char*)var_type);
  239. CallFunc_Add_in(func, var);
  240. fprintf(stdout, "\t\t(%s,%s)\n", trXSD2C((const char*)var_type), (const char*)var_name);
  241. /*xmlFree(var_name);
  242. xmlFree(var_type);*/
  243. cur = cur->next;
  244. }
  245. }
  246. void handleOutputParameters(xmlDocPtr doc, const char *name, struct CallFunc *func)
  247. {
  248. char ns[10];
  249. char message_name[255];
  250. xmlNodePtr node;
  251. xmlNodePtr cur;
  252. struct CallVar *var;
  253. xmlChar *var_name, *var_type;
  254. parseNS(name, ns, message_name); /* check why to pase ns? */
  255. node = findMessage(doc, message_name);
  256. if (node == NULL) {
  257. fprintf(stderr, "ERROR: Can not find message '%s'\n", message_name);
  258. return;
  259. }
  260. cur = node->xmlChildrenNode;
  261. while (cur != NULL) {
  262. if (cur->type != XML_ELEMENT_NODE) {
  263. cur = cur->next;
  264. continue;
  265. }
  266. if (xmlStrcmp(cur->name, (const xmlChar*)"part")) {
  267. cur = cur->next;
  268. continue;
  269. }
  270. var_name = xmlGetProp(cur, "name");
  271. if (var_name == NULL) {
  272. fprintf(stderr, "ERROR: Found <part> without attrbute 'name'! (message:'%s')\n",
  273. message_name);
  274. cur = cur->next;
  275. continue;
  276. }
  277. var_type = xmlGetProp(cur, "type");
  278. if (var_type == NULL) {
  279. var_type = xmlGetProp(cur, "element");
  280. }
  281. if (var_type == NULL) {
  282. fprintf(stderr, "ERROR: Found <part> without attrbute 'type' or 'element'! (message:'%s')\n",
  283. message_name);
  284. /*xmlFree(var_name);*/
  285. cur = cur->next;
  286. continue;
  287. }
  288. var = CallVar_Create();
  289. CallVar_Set_name(var, (const char*)var_name);
  290. CallVar_Set_type(var, (const char*)var_type);
  291. CallFunc_Set_out(func, var);
  292. fprintf(stdout, "\t\t(%s,%s)\n", trXSD2C((const char*)var_type), (const char*)var_name);
  293. /*xmlFree(var_name);
  294. xmlFree(var_type);*/
  295. cur = cur->next;
  296. break; /* only one return parameter */
  297. }
  298. }
  299. void handlePortType(xmlDocPtr doc, const char *name)
  300. {
  301. xmlNodePtr node;
  302. xmlNodePtr input;
  303. xmlNodePtr output;
  304. xmlNodePtr cur;
  305. xmlChar *attr_name;
  306. xmlChar *message;
  307. struct CallFunc *func;
  308. char opname[255];
  309. node = findPortType(doc, name);
  310. if (node == NULL) {
  311. fprintf(stderr, "PortType '%s' not found!\n", name);
  312. return;
  313. }
  314. cur = node->xmlChildrenNode;
  315. while (cur != NULL) {
  316. if (cur->type != XML_ELEMENT_NODE) {
  317. cur = cur->next;
  318. continue;
  319. }
  320. if (xmlStrcmp(cur->name, (const xmlChar*)"operation")) {
  321. cur = cur->next;
  322. continue;
  323. }
  324. attr_name = xmlGetProp(cur, "name");
  325. if (attr_name == NULL) {
  326. cur = cur->next;
  327. continue;
  328. }
  329. strcpy(opname, (const char*)attr_name);
  330. /*xmlFree(attr_name);*/
  331. func = CallFunc_Create();
  332. CallList_Add_operation(callList, func);
  333. CallFunc_Set_name(func, opname);
  334. fprintf(stdout, "Operation -> '%s'\n", opname);
  335. /* handle input */
  336. input = findSubNode(cur, "input");
  337. if (input == NULL) {
  338. fprintf(stderr, "WARNING: No input for operation '%'\n", opname);
  339. cur = cur->next;
  340. continue;
  341. }
  342. message = xmlGetProp(input, "message");
  343. if (message == NULL) {
  344. fprintf(stderr, "ERROR: No message attribute for input operation '%s'\n", opname);
  345. cur = cur->next;
  346. continue;
  347. }
  348. fprintf(stdout, "\tinput = '%s'\n", (const char*)message);
  349. handleInputParameters(doc, (const char*)message, func);
  350. /*xmlFree(message);*/
  351. /* handle output */
  352. output = findSubNode(cur, "output");
  353. if (output == NULL) { /* one way operation is ok */
  354. cur = cur->next;
  355. continue;
  356. }
  357. message = xmlGetProp(output, "message");
  358. if (message == NULL) {
  359. fprintf(stderr, "ERROR: No message attribute for output operation '%s'\n", opname);
  360. cur = cur->next;
  361. continue;
  362. }
  363. fprintf(stdout, "\toutput = '%s'\n", (const char*)message);
  364. /*xmlFree(message);*/
  365. handleOutputParameters(doc, (const char*)message, func);
  366. cur = cur->next;
  367. }
  368. }
  369. void handleBinding(xmlDocPtr doc, const char *type)
  370. {
  371. int i;
  372. xmlChar *name;
  373. xmlChar *btype;
  374. xmlNodeSetPtr nodeset;
  375. xmlXPathObjectPtr xpathObj;
  376. char query[255];
  377. char port_name[255], port_ns[10];
  378. char binding_type[255], binding_ns[10];
  379. parseNS(type, binding_ns, binding_type);
  380. /* Set xpath query */
  381. if (wsdl_prefix[0])
  382. sprintf(query, "//%s:definitions/%s:binding[@name=\"%s\"]", wsdl_prefix, wsdl_prefix, binding_type);
  383. else
  384. sprintf(query, "//definitions/binding[@name=\"%s\"]", binding_type);
  385. /* Find Bindings */
  386. xpathObj = xpath_eval(doc, query);
  387. if (xpathObj == NULL) {
  388. fprintf(stderr, "No Soap Binding found!\n");
  389. return;
  390. }
  391. /* Check if found nodes */
  392. nodeset = xpathObj->nodesetval;
  393. if (nodeset == NULL) {
  394. fprintf(stderr, "No Soap Binding found! nodeset empty!\n");
  395. return;
  396. }
  397. /* Iterate all soap services */
  398. for (i=0;i < nodeset->nodeNr; i++) {
  399. name = xmlGetProp(nodeset->nodeTab[i], "name");
  400. if (name == NULL) {
  401. fprintf(stderr, "WARNING: no attribute name found!\n");
  402. } else {
  403. fprintf(stdout, "Found Binding -> (name: '%s')\n",
  404. (const char*)name);
  405. }
  406. btype = xmlGetProp(nodeset->nodeTab[i], "type");
  407. if (btype == NULL) {
  408. fprintf(stderr, "WARNING: no attribute type found!\n");
  409. } else {
  410. parseNS(btype, port_ns, port_name);
  411. handlePortType(doc, port_name);
  412. }
  413. /* if (name != NULL) xmlFree(name);
  414. if (btype != NULL) xmlFree(btype); */
  415. }
  416. }
  417. void wsdlParse(xmlDocPtr doc)
  418. {
  419. int i;
  420. xmlChar *name, *binding;
  421. xmlNodeSetPtr nodeset;
  422. xmlXPathObjectPtr xpathObj;
  423. char query[255];
  424. if (wsdl_prefix[0])
  425. sprintf(query, "//%s:definitions/%s:service/%s:port[%s:address]", wsdl_prefix, wsdl_prefix, wsdl_prefix, soap_prefix);
  426. else
  427. sprintf(query, "//definitions/service/port[%s:address]", soap_prefix);
  428. /* Find Soap Service */
  429. xpathObj = xpath_eval(doc, query);
  430. if (xpathObj == NULL) {
  431. fprintf(stderr, "No Soap Service found!\n");
  432. return;
  433. }
  434. /* Check if found nodes */
  435. nodeset = xpathObj->nodesetval;
  436. if (nodeset == NULL) {
  437. fprintf(stderr, "No Soap Service found! nodeset empty!\n");
  438. return;
  439. }
  440. /* Iterate all soap services */
  441. for (i=0;i < nodeset->nodeNr; i++) {
  442. name = xmlGetProp(nodeset->nodeTab[i], "name");
  443. binding = xmlGetProp(nodeset->nodeTab[i], "binding");
  444. if (name == NULL) {
  445. fprintf(stderr, "WARNING: no attribute type found!\n");
  446. } if (binding == NULL) {
  447. fprintf(stderr, "WARNING: no attribute binding found!\n");
  448. } else {
  449. fprintf(stdout, "Found SOAP port -> (type: '%s') (binding: '%s')\n",
  450. (const char*)name, (const char*)binding);
  451. }
  452. handleBinding(doc, binding);
  453. /* if (name != NULL) xmlFree(name);
  454. if (binding != NULL) xmlFree(binding);*/
  455. }
  456. }
  457. static
  458. void usage(const char* execname);
  459. int main(int argc, char *argv[])
  460. {
  461. xmlDocPtr doc;
  462. xmlNodePtr cur;
  463. xmlNodePtr node;
  464. xmlNodePtr xsdRoot;
  465. xmlNsPtr default_ns;
  466. xmlNsPtr soap_ns;
  467. xmlNsPtr wsdl_ns;
  468. xmlNsPtr tar_ns;
  469. xmlChar *tar_ns_str;
  470. int i;
  471. char outDir[1054];
  472. char fname[255];
  473. if (argc < 2) {
  474. usage(argv[0]);
  475. return 1;
  476. }
  477. strcpy(outDir, ".");
  478. for (i=1;i<argc;i++)
  479. {
  480. if (!strcmp(argv[i], "-d"))
  481. if (i==argc-1) usage(argv[0]);
  482. else strcpy(outDir, argv[++i]);
  483. else if (!strcmp(argv[i], "-S"))
  484. formatter_generate_sax_serializer = 1;
  485. else strcpy(fname, argv[i]);
  486. }
  487. xsdRoot = wsdlLoadFile(fname);
  488. if (xsdRoot == NULL )
  489. {
  490. fprintf(stderr,"No Schema data found\n");
  491. doc = xmlParseFile(fname);
  492. if (doc == NULL)
  493. {
  494. fprintf(stderr,"Can not parse document\n");
  495. return 1;
  496. }
  497. }
  498. else
  499. {
  500. doc = xsdRoot->doc;
  501. }
  502. node = xmlDocGetRootElement(doc);
  503. if (node == NULL) {
  504. fprintf(stderr,"empty document\n");
  505. xmlFreeDoc(doc);
  506. return 1;
  507. }
  508. /* Search for wsdl soap namespace
  509. http://schemas.xmlsoap.org/wsdl/soap/
  510. */
  511. soap_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl/soap/");
  512. if (soap_ns == NULL) {
  513. soap_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl/soap");
  514. }
  515. if (soap_ns != NULL && soap_ns->prefix != NULL) {
  516. fprintf(stdout, "Wsdl SOAP prefix: '%s'\n", soap_ns->prefix);
  517. strcpy(soap_prefix, soap_ns->prefix);
  518. } else {
  519. fprintf(stderr,"Namespace 'http://schemas.xmlsoap.org/wsdl/soap/' expected\n");
  520. xmlFreeDoc(doc);
  521. return 1;
  522. }
  523. /* Search for wsdl namespace
  524. http://schemas.xmlsoap.org/wsdl/
  525. */
  526. wsdl_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl/");
  527. if (wsdl_ns == NULL) {
  528. wsdl_ns = xmlSearchNsByHref(doc, node, "http://schemas.xmlsoap.org/wsdl");
  529. }
  530. if (wsdl_ns != NULL && wsdl_ns->prefix != NULL) {
  531. fprintf(stdout, "Wsdl prefix: '%s'\n", wsdl_ns->prefix);
  532. strcpy(wsdl_prefix, wsdl_ns->prefix);
  533. } else {
  534. /* search default namespace */
  535. default_ns = xmlSearchNs(doc, node, NULL);
  536. if (default_ns == NULL || ( default_ns != NULL && default_ns->href == NULL)) {
  537. fprintf(stdout, "Adding default namespace 'http://schemas.xmlsoap.org/wsdl/'\n");
  538. xmlNewDocProp(doc, "xmlns", "http://schemas.xmlsoap.org/wsdl/");
  539. }
  540. /*strcpy(wsdl_prefix, "wsdl");*/
  541. wsdl_prefix[0] = '\0';
  542. }
  543. /* search targetNamespace */
  544. tar_ns_str = xmlGetProp(node, "targetNamespace");
  545. if (tar_ns_str) {
  546. strcpy(target_ns, tar_ns_str);
  547. /* Search for target namespace
  548. */
  549. tar_ns = xmlSearchNsByHref(doc, node, target_ns);
  550. if (tar_ns && tar_ns->prefix) {
  551. strcpy(target_prefix, tar_ns->prefix);
  552. printf("Target namespace: %s\nTarget NS Prefix: %s\n",
  553. target_ns, target_prefix);
  554. } else {
  555. target_prefix[0] = '\0';
  556. }
  557. /*xmlFree*/
  558. } else {
  559. target_ns[0] = '\0';
  560. target_prefix[0] = '\0';
  561. }
  562. xsdRoot = xsdRoot?xsdRoot:node;
  563. while (xsdRoot) {
  564. if (xsdRoot->type != XML_ELEMENT_NODE) {
  565. xsdRoot = xsdRoot->next;
  566. continue;
  567. }
  568. if (!xsdInitTrModule(xsdRoot))
  569. return 1;
  570. if (!xsdInitObjModule(xsdRoot))
  571. return 1;
  572. printf("Calling xsd engine\n");
  573. if (xsdEngineRun(xsdRoot, outDir)) {
  574. fprintf(stderr, "xsd2c engine error\n");
  575. return 1;
  576. }
  577. xsdRoot = xsdRoot->next;
  578. }
  579. callList = CallList_Create();
  580. wsdlParse(doc);
  581. /* CallList_Sax_Serialize(callList, "CallList",
  582. Writer_StartElement,
  583. Writer_Characters,
  584. Writer_EndElement, 0);
  585. */
  586. codeWriteStubHeader(callList, "test_stub.h");
  587. CallList_Free(callList);
  588. trFreeModule();
  589. objFreeModule();
  590. xmlFreeDoc(doc);
  591. return 0;
  592. }
  593. static
  594. void usage(const char* execname)
  595. {
  596. fprintf(stderr, "usage: %s -d dest <wsdl file>\n", execname);
  597. }