testigddescparse.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* $Id: testigddescparse.c,v 1.2 2009/12/03 13:50:06 nanard Exp $ */
  2. /* Project : miniupnp
  3. * http://miniupnp.free.fr/
  4. * Author : Thomas Bernard
  5. * Copyright (c) 2008-2009 Thomas Bernard
  6. * This software is subject to the conditions detailed in the
  7. * LICENCE file provided in this distribution.
  8. * */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "igd_desc_parse.h"
  13. #include "minixml.h"
  14. #include "miniupnpc.h"
  15. int test_igd_desc_parse(char * buffer, int len)
  16. {
  17. struct IGDdatas igd;
  18. struct xmlparser parser;
  19. struct UPNPUrls urls;
  20. memset(&igd, 0, sizeof(struct IGDdatas));
  21. memset(&parser, 0, sizeof(struct xmlparser));
  22. parser.xmlstart = buffer;
  23. parser.xmlsize = len;
  24. parser.data = &igd;
  25. parser.starteltfunc = IGDstartelt;
  26. parser.endeltfunc = IGDendelt;
  27. parser.datafunc = IGDdata;
  28. parsexml(&parser);
  29. printIGD(&igd);
  30. GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml");
  31. printf("ipcondescURL='%s'\n", urls.ipcondescURL);
  32. printf("controlURL='%s'\n", urls.controlURL);
  33. printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
  34. FreeUPNPUrls(&urls);
  35. return 0;
  36. }
  37. int main(int argc, char * * argv)
  38. {
  39. FILE * f;
  40. char * buffer;
  41. int len;
  42. int r = 0;
  43. if(argc<2) {
  44. fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
  45. return 1;
  46. }
  47. f = fopen(argv[1], "r");
  48. if(!f) {
  49. fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
  50. return 1;
  51. }
  52. fseek(f, 0, SEEK_END);
  53. len = ftell(f);
  54. fseek(f, 0, SEEK_SET);
  55. buffer = malloc(len);
  56. fread(buffer, 1, len, f);
  57. fclose(f);
  58. r = test_igd_desc_parse(buffer, len);
  59. free(buffer);
  60. return r;
  61. }
粤ICP备19079148号