Path: blob/master/thirdparty/miniupnpc/src/igd_desc_parse.c
9904 views
/* $Id: igd_desc_parse.c,v 1.17 2015/09/15 13:30:04 nanard Exp $ */1/* Project : miniupnp2* http://miniupnp.free.fr/3* Author : Thomas Bernard4* Copyright (c) 2005-2015 Thomas Bernard5* This software is subject to the conditions detailed in the6* LICENCE file provided in this distribution. */78#include "igd_desc_parse.h"9#include <stdio.h>10#include <string.h>1112/* Start element handler :13* update nesting level counter and copy element name */14void IGDstartelt(void * d, const char * name, int l)15{16struct IGDdatas * datas = (struct IGDdatas *)d;17if(l >= MINIUPNPC_URL_MAXSIZE)18l = MINIUPNPC_URL_MAXSIZE-1;19memcpy(datas->cureltname, name, l);20datas->cureltname[l] = '\0';21datas->level++;22if( (l==7) && !memcmp(name, "service", l) ) {23datas->tmp.controlurl[0] = '\0';24datas->tmp.eventsuburl[0] = '\0';25datas->tmp.scpdurl[0] = '\0';26datas->tmp.servicetype[0] = '\0';27}28}2930#define COMPARE(str, cstr) (0==memcmp(str, cstr, sizeof(cstr) - 1))3132/* End element handler :33* update nesting level counter and update parser state if34* service element is parsed */35void IGDendelt(void * d, const char * name, int l)36{37struct IGDdatas * datas = (struct IGDdatas *)d;38datas->level--;39/*printf("endelt %2d %.*s\n", datas->level, l, name);*/40if( (l==7) && !memcmp(name, "service", l) )41{42if(COMPARE(datas->tmp.servicetype,43"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:")) {44memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service));45} else if(COMPARE(datas->tmp.servicetype,46"urn:schemas-upnp-org:service:WANIPv6FirewallControl:")) {47memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service));48} else if(COMPARE(datas->tmp.servicetype,49"urn:schemas-upnp-org:service:WANIPConnection:")50|| COMPARE(datas->tmp.servicetype,51"urn:schemas-upnp-org:service:WANPPPConnection:") ) {52if(datas->first.servicetype[0] == '\0') {53memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));54} else {55memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service));56}57}58}59}6061/* Data handler :62* copy data depending on the current element name and state */63void IGDdata(void * d, const char * data, int l)64{65struct IGDdatas * datas = (struct IGDdatas *)d;66char * dstmember = 0;67/*printf("%2d %s : %.*s\n",68datas->level, datas->cureltname, l, data); */69if( !strcmp(datas->cureltname, "URLBase") )70dstmember = datas->urlbase;71else if( !strcmp(datas->cureltname, "presentationURL") )72dstmember = datas->presentationurl;73else if( !strcmp(datas->cureltname, "serviceType") )74dstmember = datas->tmp.servicetype;75else if( !strcmp(datas->cureltname, "controlURL") )76dstmember = datas->tmp.controlurl;77else if( !strcmp(datas->cureltname, "eventSubURL") )78dstmember = datas->tmp.eventsuburl;79else if( !strcmp(datas->cureltname, "SCPDURL") )80dstmember = datas->tmp.scpdurl;81/* else if( !strcmp(datas->cureltname, "deviceType") )82dstmember = datas->devicetype_tmp;*/83if(dstmember)84{85if(l>=MINIUPNPC_URL_MAXSIZE)86l = MINIUPNPC_URL_MAXSIZE-1;87memcpy(dstmember, data, l);88dstmember[l] = '\0';89}90}9192#ifdef DEBUG93void printIGD(struct IGDdatas * d)94{95printf("urlbase = '%s'\n", d->urlbase);96printf("WAN Device (Common interface config) :\n");97/*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/98printf(" serviceType = '%s'\n", d->CIF.servicetype);99printf(" controlURL = '%s'\n", d->CIF.controlurl);100printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);101printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);102printf("primary WAN Connection Device (IP or PPP Connection):\n");103/*printf(" deviceType = '%s'\n", d->first.devicetype);*/104printf(" servicetype = '%s'\n", d->first.servicetype);105printf(" controlURL = '%s'\n", d->first.controlurl);106printf(" eventSubURL = '%s'\n", d->first.eventsuburl);107printf(" SCPDURL = '%s'\n", d->first.scpdurl);108printf("secondary WAN Connection Device (IP or PPP Connection):\n");109/*printf(" deviceType = '%s'\n", d->second.devicetype);*/110printf(" servicetype = '%s'\n", d->second.servicetype);111printf(" controlURL = '%s'\n", d->second.controlurl);112printf(" eventSubURL = '%s'\n", d->second.eventsuburl);113printf(" SCPDURL = '%s'\n", d->second.scpdurl);114printf("WAN IPv6 Firewall Control :\n");115/*printf(" deviceType = '%s'\n", d->IPv6FC.devicetype);*/116printf(" servicetype = '%s'\n", d->IPv6FC.servicetype);117printf(" controlURL = '%s'\n", d->IPv6FC.controlurl);118printf(" eventSubURL = '%s'\n", d->IPv6FC.eventsuburl);119printf(" SCPDURL = '%s'\n", d->IPv6FC.scpdurl);120}121#endif /* DEBUG */122123124125