igd_desc_parse.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* $Id: igd_desc_parse.c,v 1.11 2010/12/11 17:56:51 nanard Exp $ */
  2. /* Project : miniupnp
  3. * http://miniupnp.free.fr/
  4. * Author : Thomas Bernard
  5. * Copyright (c) 2005-2010 Thomas Bernard
  6. * This software is subject to the conditions detailed in the
  7. * LICENCE file provided in this distribution. */
  8. #include "igd_desc_parse.h"
  9. #include <stdio.h>
  10. #include <string.h>
  11. /* Start element handler :
  12. * update nesting level counter and copy element name */
  13. void IGDstartelt(void * d, const char * name, int l)
  14. {
  15. struct IGDdatas * datas = (struct IGDdatas *)d;
  16. memcpy( datas->cureltname, name, l);
  17. datas->cureltname[l] = '\0';
  18. datas->level++;
  19. if( (l==7) && !memcmp(name, "service", l) ) {
  20. datas->tmp.controlurl[0] = '\0';
  21. datas->tmp.eventsuburl[0] = '\0';
  22. datas->tmp.scpdurl[0] = '\0';
  23. datas->tmp.servicetype[0] = '\0';
  24. }
  25. }
  26. /* End element handler :
  27. * update nesting level counter and update parser state if
  28. * service element is parsed */
  29. void IGDendelt(void * d, const char * name, int l)
  30. {
  31. struct IGDdatas * datas = (struct IGDdatas *)d;
  32. datas->level--;
  33. /*printf("endelt %2d %.*s\n", datas->level, l, name);*/
  34. if( (l==7) && !memcmp(name, "service", l) )
  35. {
  36. /*
  37. if( datas->state < 1
  38. && !strcmp(datas->servicetype,
  39. // "urn:schemas-upnp-org:service:WANIPConnection:1") )
  40. "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
  41. datas->state ++;
  42. */
  43. if(0==strcmp(datas->tmp.servicetype,
  44. "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
  45. memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service));
  46. } else if(0==strcmp(datas->tmp.servicetype,
  47. "urn:schemas-upnp-org:service:WANIPConnection:1")
  48. || 0==strcmp(datas->tmp.servicetype,
  49. "urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
  50. if(datas->first.servicetype[0] == '\0') {
  51. memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));
  52. } else {
  53. memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service));
  54. }
  55. }
  56. }
  57. }
  58. /* Data handler :
  59. * copy data depending on the current element name and state */
  60. void IGDdata(void * d, const char * data, int l)
  61. {
  62. struct IGDdatas * datas = (struct IGDdatas *)d;
  63. char * dstmember = 0;
  64. /*printf("%2d %s : %.*s\n",
  65. datas->level, datas->cureltname, l, data); */
  66. if( !strcmp(datas->cureltname, "URLBase") )
  67. dstmember = datas->urlbase;
  68. else if( !strcmp(datas->cureltname, "serviceType") )
  69. dstmember = datas->tmp.servicetype;
  70. else if( !strcmp(datas->cureltname, "controlURL") )
  71. dstmember = datas->tmp.controlurl;
  72. else if( !strcmp(datas->cureltname, "eventSubURL") )
  73. dstmember = datas->tmp.eventsuburl;
  74. else if( !strcmp(datas->cureltname, "SCPDURL") )
  75. dstmember = datas->tmp.scpdurl;
  76. /* else if( !strcmp(datas->cureltname, "deviceType") )
  77. dstmember = datas->devicetype_tmp;*/
  78. if(dstmember)
  79. {
  80. if(l>=MINIUPNPC_URL_MAXSIZE)
  81. l = MINIUPNPC_URL_MAXSIZE-1;
  82. memcpy(dstmember, data, l);
  83. dstmember[l] = '\0';
  84. }
  85. }
  86. void printIGD(struct IGDdatas * d)
  87. {
  88. printf("urlbase = '%s'\n", d->urlbase);
  89. printf("WAN Device (Common interface config) :\n");
  90. /*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/
  91. printf(" serviceType = '%s'\n", d->CIF.servicetype);
  92. printf(" controlURL = '%s'\n", d->CIF.controlurl);
  93. printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);
  94. printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);
  95. printf("primary WAN Connection Device (IP or PPP Connection):\n");
  96. /*printf(" deviceType = '%s'\n", d->first.devicetype);*/
  97. printf(" servicetype = '%s'\n", d->first.servicetype);
  98. printf(" controlURL = '%s'\n", d->first.controlurl);
  99. printf(" eventSubURL = '%s'\n", d->first.eventsuburl);
  100. printf(" SCPDURL = '%s'\n", d->first.scpdurl);
  101. printf("secondary WAN Connection Device (IP or PPP Connection):\n");
  102. /*printf(" deviceType = '%s'\n", d->second.devicetype);*/
  103. printf(" servicetype = '%s'\n", d->second.servicetype);
  104. printf(" controlURL = '%s'\n", d->second.controlurl);
  105. printf(" eventSubURL = '%s'\n", d->second.eventsuburl);
  106. printf(" SCPDURL = '%s'\n", d->second.scpdurl);
  107. }
粤ICP备19079148号