/thirdparty/libportfwd/third-party/miniupnpc-1.6/igd_desc_parse.c

http://github.com/tomahawk-player/tomahawk · C · 125 lines · 88 code · 7 blank · 30 comment · 26 complexity · 97a94ab8fac15b6b62587f4885541fc1 MD5 · raw file

  1. /* $Id: igd_desc_parse.c,v 1.14 2011/04/11 09:19:24 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:WANIPv6FirewallControl:1")) {
  48. memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service));
  49. } else if(0==strcmp(datas->tmp.servicetype,
  50. "urn:schemas-upnp-org:service:WANIPConnection:1")
  51. || 0==strcmp(datas->tmp.servicetype,
  52. "urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
  53. if(datas->first.servicetype[0] == '\0') {
  54. memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));
  55. } else {
  56. memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service));
  57. }
  58. }
  59. }
  60. }
  61. /* Data handler :
  62. * copy data depending on the current element name and state */
  63. void IGDdata(void * d, const char * data, int l)
  64. {
  65. struct IGDdatas * datas = (struct IGDdatas *)d;
  66. char * dstmember = 0;
  67. /*printf("%2d %s : %.*s\n",
  68. datas->level, datas->cureltname, l, data); */
  69. if( !strcmp(datas->cureltname, "URLBase") )
  70. dstmember = datas->urlbase;
  71. else if( !strcmp(datas->cureltname, "presentationURL") )
  72. dstmember = datas->presentationurl;
  73. else if( !strcmp(datas->cureltname, "serviceType") )
  74. dstmember = datas->tmp.servicetype;
  75. else if( !strcmp(datas->cureltname, "controlURL") )
  76. dstmember = datas->tmp.controlurl;
  77. else if( !strcmp(datas->cureltname, "eventSubURL") )
  78. dstmember = datas->tmp.eventsuburl;
  79. else if( !strcmp(datas->cureltname, "SCPDURL") )
  80. dstmember = datas->tmp.scpdurl;
  81. /* else if( !strcmp(datas->cureltname, "deviceType") )
  82. dstmember = datas->devicetype_tmp;*/
  83. if(dstmember)
  84. {
  85. if(l>=MINIUPNPC_URL_MAXSIZE)
  86. l = MINIUPNPC_URL_MAXSIZE-1;
  87. memcpy(dstmember, data, l);
  88. dstmember[l] = '\0';
  89. }
  90. }
  91. void printIGD(struct IGDdatas * d)
  92. {
  93. printf("urlbase = '%s'\n", d->urlbase);
  94. printf("WAN Device (Common interface config) :\n");
  95. /*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/
  96. printf(" serviceType = '%s'\n", d->CIF.servicetype);
  97. printf(" controlURL = '%s'\n", d->CIF.controlurl);
  98. printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);
  99. printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);
  100. printf("primary WAN Connection Device (IP or PPP Connection):\n");
  101. /*printf(" deviceType = '%s'\n", d->first.devicetype);*/
  102. printf(" servicetype = '%s'\n", d->first.servicetype);
  103. printf(" controlURL = '%s'\n", d->first.controlurl);
  104. printf(" eventSubURL = '%s'\n", d->first.eventsuburl);
  105. printf(" SCPDURL = '%s'\n", d->first.scpdurl);
  106. printf("secondary WAN Connection Device (IP or PPP Connection):\n");
  107. /*printf(" deviceType = '%s'\n", d->second.devicetype);*/
  108. printf(" servicetype = '%s'\n", d->second.servicetype);
  109. printf(" controlURL = '%s'\n", d->second.controlurl);
  110. printf(" eventSubURL = '%s'\n", d->second.eventsuburl);
  111. printf(" SCPDURL = '%s'\n", d->second.scpdurl);
  112. printf("WAN IPv6 Firewall Control :\n");
  113. /*printf(" deviceType = '%s'\n", d->IPv6FC.devicetype);*/
  114. printf(" servicetype = '%s'\n", d->IPv6FC.servicetype);
  115. printf(" controlURL = '%s'\n", d->IPv6FC.controlurl);
  116. printf(" eventSubURL = '%s'\n", d->IPv6FC.eventsuburl);
  117. printf(" SCPDURL = '%s'\n", d->IPv6FC.scpdurl);
  118. }