⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample_util.c

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 C
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000 Intel Corporation // All rights reserved. //// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: //// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission.// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.///////////////////////////////////////////////////////////////////////////////// $Revision: 1.1.1.3 $// $Date: 2001/06/15 00:21:09 $//#include "sample_util.h"/******************************************************************************** * SampleUtil_GetElementValue * * Description:  *       Given a DOM node such as <Channel>11</Channel>, this routine *       extracts the value (e.g., 11) from the node and returns it as  *       a string. * * Parameters: *   node -- The DOM node from which to extract the value * ********************************************************************************/char* SampleUtil_GetElementValue(Upnp_Node node){  Upnp_Node child = UpnpNode_getFirstChild(node);  Upnp_DOMException err;  char * temp;   if ( (child!=0) && (UpnpNode_getNodeType(child)==TEXT_NODE))    {      temp= (char *) UpnpNode_getNodeValue(child,&err);      UpnpNode_free(child);           return temp;    }  else    {          return NULL;    }}/******************************************************************************** * SampleUtil_GetFirstServiceList * * Description:  *       Given a DOM node representing a UPnP Device Description Document, *       this routine parses the document and finds the first service list *       (i.e., the service list for the root device).  The service list *       is returned as a DOM node list. * * Parameters: *   node -- The DOM node from which to extract the service list * ********************************************************************************/Upnp_NodeList SampleUtil_GetFirstServiceList(Upnp_Node node) {    Upnp_NodeList ServiceList=NULL;    Upnp_NodeList servlistnodelist=NULL;    Upnp_Node servlistnode=NULL;	    servlistnodelist = UpnpDocument_getElementsByTagName(node, "serviceList");    if(servlistnodelist && UpnpNodeList_getLength(servlistnodelist)) {	/* we only care about the first service list, from the root device */	servlistnode = UpnpNodeList_item(servlistnodelist, 0);	/* create as list of DOM nodes */	ServiceList = UpnpElement_getElementsByTagName(servlistnode, "service");    }    if (servlistnodelist) UpnpNodeList_free(servlistnodelist);    if (servlistnode) UpnpNode_free(servlistnode);    return ServiceList;}/******************************************************************************** * SampleUtil_GetFirstDocumentItem * * Description:  *       Given a DOM node, this routine searches for the first element *       named by the input string item, and returns its value as a string. * * Parameters: *   node -- The DOM node from which to extract the value *   item -- The item to search for * ********************************************************************************/char* SampleUtil_GetFirstDocumentItem(Upnp_Node node, char *item) {    Upnp_NodeList NodeList=NULL;    Upnp_Node textNode=NULL;    Upnp_Node tmpNode=NULL;    Upnp_DOMException err;     char *ret=NULL;    int len;	    NodeList = UpnpDocument_getElementsByTagName(node, item);    if (NodeList == NULL) {	printf("Error finding %s in XML Node\n", item);    } else {	if ((tmpNode = UpnpNodeList_item(NodeList, 0)) == NULL) {	    printf("Error finding %s value in XML Node\n", item);	} else {	    textNode = UpnpNode_getFirstChild(tmpNode);	    len = strlen(UpnpNode_getNodeValue(textNode, &err));	    if (err != NO_ERR) {		printf("Error getting node value for %s in XML Node\n", item);		if (NodeList) UpnpNodeList_free(NodeList);		if (tmpNode) UpnpNode_free(tmpNode);		if (textNode) UpnpNode_free(textNode);		return ret;	    }	    ret = (char *) malloc(len+1);	    if (!ret) {		printf("Error allocating memory for %s in XML Node\n", item);	    } else {		strcpy(ret, UpnpNode_getNodeValue(textNode, &err));	    }	}    }    if (NodeList) UpnpNodeList_free(NodeList);    if (tmpNode) UpnpNode_free(tmpNode);    if (textNode) UpnpNode_free(textNode);    return ret;}/******************************************************************************** * SampleUtil_GetFirstElementItem * * Description:  *       Given a DOM element, this routine searches for the first element *       named by the input string item, and returns its value as a string. * * Parameters: *   node -- The DOM node from which to extract the value *   item -- The item to search for * ********************************************************************************/char* SampleUtil_GetFirstElementItem(Upnp_Element node, char *item) {    Upnp_NodeList NodeList=NULL;    Upnp_Node textNode=NULL;    Upnp_Node tmpNode=NULL;    Upnp_DOMException err;     char *ret=NULL;    int len;	    NodeList = UpnpElement_getElementsByTagName(node, item);    if (NodeList == NULL) {	printf("Error finding %s in XML Node\n", item);    } else {	if ((tmpNode = UpnpNodeList_item(NodeList, 0)) == NULL) {	    printf("Error finding %s value in XML Node\n", item);	} else {	    textNode = UpnpNode_getFirstChild(tmpNode);	    len = strlen(UpnpNode_getNodeValue(textNode, &err));	    if (err != NO_ERR) {		printf("Error getting node value for %s in XML Node\n", item);		if (NodeList) UpnpNodeList_free(NodeList);		if (tmpNode) UpnpNode_free(tmpNode);		if (textNode) UpnpNode_free(textNode);		return ret;	    }	    ret = (char *) malloc(len+1);	    if (!ret) {		printf("Error allocating memory for %s in XML Node\n", item);	    } else {		strcpy(ret, UpnpNode_getNodeValue(textNode, &err));	    }	}    }    if (NodeList) UpnpNodeList_free(NodeList);    if (tmpNode) UpnpNode_free(tmpNode);    if (textNode) UpnpNode_free(textNode);    return ret;}/******************************************************************************** * SampleUtil_PrintEventType * * Description:  *       Prints a callback event type as a string. * * Parameters: *   S -- The callback event * ********************************************************************************/void SampleUtil_PrintEventType(Upnp_EventType S){    switch(S) {    case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:	printf("UPNP_DISCOVERY_ADVERTISEMENT_ALIVE\n");	break;    case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:	printf("UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE\n");	break;    case UPNP_DISCOVERY_SEARCH_RESULT:	printf("UPNP_DISCOVERY_SEARCH_RESULT\n");	break;    case UPNP_DISCOVERY_SEARCH_TIMEOUT:	printf("UPNP_DISCOVERY_SEARCH_TIMEOUT\n");	break;	/* SOAP Stuff */    case UPNP_CONTROL_ACTION_REQUEST:	printf("UPNP_CONTROL_ACTION_REQUEST\n");	break;    case UPNP_CONTROL_ACTION_COMPLETE:	printf("UPNP_CONTROL_ACTION_COMPLETE\n");	break;    case UPNP_CONTROL_GET_VAR_REQUEST:	printf("UPNP_CONTROL_GET_VAR_REQUEST\n");	break;    case UPNP_CONTROL_GET_VAR_COMPLETE:	printf("UPNP_CONTROL_GET_VAR_COMPLETE\n");	break;	/* GENA Stuff */    case UPNP_EVENT_SUBSCRIPTION_REQUEST:	printf("UPNP_EVENT_SUBSCRIPTION_REQUEST\n");	break;    case UPNP_EVENT_RECEIVED:	printf("UPNP_EVENT_RECEIVED\n");	break;    case UPNP_EVENT_RENEWAL_COMPLETE:	printf("UPNP_EVENT_RENEWAL_COMPLETE\n");	break;    case UPNP_EVENT_SUBSCRIBE_COMPLETE:	printf("UPNP_EVENT_SUBSCRIBE_COMPLETE\n");	break;    case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:	printf("UPNP_EVENT_UNSUBSCRIBE_COMPLETE\n");	break;    case UPNP_EVENT_AUTORENEWAL_FAILED:	printf("UPNP_EVENT_AUTORENEWAL_FAILED\n");	break;    case UPNP_EVENT_SUBSCRIPTION_EXPIRED:	printf("UPNP_EVENT_SUBSCRIPTION_EXPIRED\n");	break;    }}/******************************************************************************** * SampleUtil_PrintEvent * * Description:  *       Prints callback event structure details. * * Parameters: *   EventType -- The type of callback event

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -