File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpc / igd_desc_parse.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:16:22 2012 UTC (12 years, 3 months ago) by misho
Branches: miniupnpc, elwix, MAIN
CVS tags: v1_8p0, v1_8, v1_6, HEAD
miniupnpc

    1: /* $Id: igd_desc_parse.c,v 1.1.1.1 2012/02/21 23:16:22 misho 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: 
    9: #include "igd_desc_parse.h"
   10: #include <stdio.h>
   11: #include <string.h>
   12: 
   13: /* Start element handler :
   14:  * update nesting level counter and copy element name */
   15: void IGDstartelt(void * d, const char * name, int l)
   16: {
   17: 	struct IGDdatas * datas = (struct IGDdatas *)d;
   18: 	memcpy( datas->cureltname, name, l);
   19: 	datas->cureltname[l] = '\0';
   20: 	datas->level++;
   21: 	if( (l==7) && !memcmp(name, "service", l) ) {
   22: 		datas->tmp.controlurl[0] = '\0';
   23: 		datas->tmp.eventsuburl[0] = '\0';
   24: 		datas->tmp.scpdurl[0] = '\0';
   25: 		datas->tmp.servicetype[0] = '\0';
   26: 	}
   27: }
   28: 
   29: /* End element handler :
   30:  * update nesting level counter and update parser state if
   31:  * service element is parsed */
   32: void IGDendelt(void * d, const char * name, int l)
   33: {
   34: 	struct IGDdatas * datas = (struct IGDdatas *)d;
   35: 	datas->level--;
   36: 	/*printf("endelt %2d %.*s\n", datas->level, l, name);*/
   37: 	if( (l==7) && !memcmp(name, "service", l) )
   38: 	{
   39: 		/*
   40: 		if( datas->state < 1
   41: 			&& !strcmp(datas->servicetype,
   42: 				//	"urn:schemas-upnp-org:service:WANIPConnection:1") )
   43: 				"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
   44: 			datas->state ++;
   45: 		*/
   46: 		if(0==strcmp(datas->tmp.servicetype,
   47: 				"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
   48: 			memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service));
   49: 		} else if(0==strcmp(datas->tmp.servicetype,
   50: 				"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1")) {
   51: 			memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service));
   52: 		} else if(0==strcmp(datas->tmp.servicetype,
   53: 				"urn:schemas-upnp-org:service:WANIPConnection:1")
   54: 				 || 0==strcmp(datas->tmp.servicetype,
   55: 				"urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
   56: 			if(datas->first.servicetype[0] == '\0') {
   57: 				memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));
   58: 			} else {
   59: 				memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service));
   60: 			}
   61: 		}
   62: 	}
   63: }
   64: 
   65: /* Data handler :
   66:  * copy data depending on the current element name and state */
   67: void IGDdata(void * d, const char * data, int l)
   68: {
   69: 	struct IGDdatas * datas = (struct IGDdatas *)d;
   70: 	char * dstmember = 0;
   71: 	/*printf("%2d %s : %.*s\n",
   72:            datas->level, datas->cureltname, l, data);	*/
   73: 	if( !strcmp(datas->cureltname, "URLBase") )
   74: 		dstmember = datas->urlbase;
   75: 	else if( !strcmp(datas->cureltname, "presentationURL") )
   76: 		dstmember = datas->presentationurl;
   77: 	else if( !strcmp(datas->cureltname, "serviceType") )
   78: 		dstmember = datas->tmp.servicetype;
   79: 	else if( !strcmp(datas->cureltname, "controlURL") )
   80: 		dstmember = datas->tmp.controlurl;
   81: 	else if( !strcmp(datas->cureltname, "eventSubURL") )
   82: 		dstmember = datas->tmp.eventsuburl;
   83: 	else if( !strcmp(datas->cureltname, "SCPDURL") )
   84: 		dstmember = datas->tmp.scpdurl;
   85: /*	else if( !strcmp(datas->cureltname, "deviceType") )
   86: 		dstmember = datas->devicetype_tmp;*/
   87: 	if(dstmember)
   88: 	{
   89: 		if(l>=MINIUPNPC_URL_MAXSIZE)
   90: 			l = MINIUPNPC_URL_MAXSIZE-1;
   91: 		memcpy(dstmember, data, l);
   92: 		dstmember[l] = '\0';
   93: 	}
   94: }
   95: 
   96: void printIGD(struct IGDdatas * d)
   97: {
   98: 	printf("urlbase = '%s'\n", d->urlbase);
   99: 	printf("WAN Device (Common interface config) :\n");
  100: 	/*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/
  101: 	printf(" serviceType = '%s'\n", d->CIF.servicetype);
  102: 	printf(" controlURL = '%s'\n", d->CIF.controlurl);
  103: 	printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);
  104: 	printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);
  105: 	printf("primary WAN Connection Device (IP or PPP Connection):\n");
  106: 	/*printf(" deviceType = '%s'\n", d->first.devicetype);*/
  107: 	printf(" servicetype = '%s'\n", d->first.servicetype);
  108: 	printf(" controlURL = '%s'\n", d->first.controlurl);
  109: 	printf(" eventSubURL = '%s'\n", d->first.eventsuburl);
  110: 	printf(" SCPDURL = '%s'\n", d->first.scpdurl);
  111: 	printf("secondary WAN Connection Device (IP or PPP Connection):\n");
  112: 	/*printf(" deviceType = '%s'\n", d->second.devicetype);*/
  113: 	printf(" servicetype = '%s'\n", d->second.servicetype);
  114: 	printf(" controlURL = '%s'\n", d->second.controlurl);
  115: 	printf(" eventSubURL = '%s'\n", d->second.eventsuburl);
  116: 	printf(" SCPDURL = '%s'\n", d->second.scpdurl);
  117: 	printf("WAN IPv6 Firewall Control :\n");
  118: 	/*printf(" deviceType = '%s'\n", d->IPv6FC.devicetype);*/
  119: 	printf(" servicetype = '%s'\n", d->IPv6FC.servicetype);
  120: 	printf(" controlURL = '%s'\n", d->IPv6FC.controlurl);
  121: 	printf(" eventSubURL = '%s'\n", d->IPv6FC.eventsuburl);
  122: 	printf(" SCPDURL = '%s'\n", d->IPv6FC.scpdurl);
  123: }
  124: 
  125: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>