2
0

testigddescparse.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* $Id: testigddescparse.c,v 1.1 2008/04/23 11:53:45 nanard Exp $ */
  2. /* Project : miniupnp
  3. * http://miniupnp.free.fr/
  4. * Author : Thomas Bernard
  5. * Copyright (c) 2008 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. int test_igd_desc_parse(char * buffer, int len)
  15. {
  16. struct IGDdatas igd;
  17. struct xmlparser parser;
  18. memset(&igd, 0, sizeof(struct IGDdatas));
  19. memset(&parser, 0, sizeof(struct xmlparser));
  20. parser.xmlstart = buffer;
  21. parser.xmlsize = len;
  22. parser.data = &igd;
  23. parser.starteltfunc = IGDstartelt;
  24. parser.endeltfunc = IGDendelt;
  25. parser.datafunc = IGDdata;
  26. parsexml(&parser);
  27. printIGD(&igd);
  28. return 0;
  29. }
  30. int main(int argc, char * * argv)
  31. {
  32. FILE * f;
  33. char * buffer;
  34. int len;
  35. int r = 0;
  36. if(argc<2) {
  37. fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
  38. return 1;
  39. }
  40. f = fopen(argv[1], "r");
  41. if(!f) {
  42. fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
  43. return 1;
  44. }
  45. fseek(f, 0, SEEK_END);
  46. len = ftell(f);
  47. fseek(f, 0, SEEK_SET);
  48. buffer = malloc(len);
  49. fread(buffer, 1, len, f);
  50. fclose(f);
  51. r = test_igd_desc_parse(buffer, len);
  52. free(buffer);
  53. return r;
  54. }