service_table.c

来自「原来由英特尔制定的UPnP SDK的」· C语言 代码 · 共 1,167 行 · 第 1/3 页

C
1,167
字号
**	Description :	Traverses the service table and finds the node whose*		control URL Path matches a know value **	Return : service_info * - pointer to the service list node from the *		service table whose control URL Path matches a known value;**	Note :************************************************************************/service_info *FindServiceControlURLPath( service_table * table,                           const char *controlURLPath ){    service_info *finger = NULL;    uri_type parsed_url;    uri_type parsed_url_in;    if( ( table )        &&        ( parse_uri          ( controlURLPath, strlen( controlURLPath ),            &parsed_url_in ) ) ) {        finger = table->serviceList;        while( finger ) {            if( finger->controlURL )                if( ( parse_uri                      ( finger->controlURL, strlen( finger->controlURL ),                        &parsed_url ) ) ) {                    if( !token_cmp                        ( &parsed_url.pathquery,                          &parsed_url_in.pathquery ) )                        return finger;                }            finger = finger->next;        }    }    return NULL;}/*************************************************************************	Function :	printService**	Parameters :*		service_info *service ;Service whose information is to be printed*		Upnp_LogLevel level ; Debug level specified to the print function*		Dbg_Module module ;	Debug module specified to the print function**	Description :	For debugging purposes prints information from the *		service passed into the function.**	Return : void ;**	Note :************************************************************************/#ifdef DEBUGvoid printService(    service_info *service,    Upnp_LogLevel level,    Dbg_Module module ){    if( service ) {        if( service->serviceType ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "serviceType: %s\n", service->serviceType );        }        if( service->serviceId ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "serviceId: %s\n", service->serviceId );        }	if( service->SCPDURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "SCPDURL: %s\n", service->SCPDURL );        }	if( service->controlURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "controlURL: %s\n", service->controlURL );        }	if( service->eventURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "eventURL: %s\n", service->eventURL );        }	if( service->UDN ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "UDN: %s\n\n", service->UDN );        }	if( service->active ) {            UpnpPrintf( level, module, __FILE__, __LINE__,            "Service is active\n" );        } else {            UpnpPrintf( level, module, __FILE__, __LINE__,            "Service is inactive\n" );        }    }}#endif/*************************************************************************	Function :	printServiceList**	Parameters :*		service_info *service ;	Service whose information is to be printed*		Upnp_LogLevel level ;	Debug level specified to the print function*		Dbg_Module module ;	Debug module specified to the print function**	Description :	For debugging purposes prints information of each *		service from the service table passed into the function.**	Return : void ;**	Note :************************************************************************/#ifdef DEBUGvoid printServiceList(    service_info * service,    Upnp_LogLevel level,    Dbg_Module module ){    while( service ) {        if( service->serviceType ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "serviceType: %s\n", service->serviceType );        }        if( service->serviceId ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "serviceId: %s\n", service->serviceId );        }        if( service->SCPDURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "SCPDURL: %s\n", service->SCPDURL );        }        if( service->controlURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "controlURL: %s\n", service->controlURL );        }        if( service->eventURL ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "eventURL: %s\n", service->eventURL );        }        if( service->UDN ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "UDN: %s\n\n", service->UDN );        }        if( service->active ) {            UpnpPrintf( level, module, __FILE__, __LINE__,                "Service is active\n" );        } else {            UpnpPrintf( level, module, __FILE__, __LINE__,                "Service is inactive\n" );        }        service = service->next;    }}#endif/*************************************************************************	Function :	printServiceTable**	Parameters :*		service_table * table ;	Service table to be printed*		Upnp_LogLevel level ;	Debug level specified to the print function*		Dbg_Module module ;	Debug module specified to the print function**	Description :	For debugging purposes prints the URL base of the table*		and information of each service from the service table passed into *		the function.**	Return : void ;**	Note :************************************************************************/#ifdef DEBUGvoid printServiceTable(    service_table * table,    Upnp_LogLevel level,    Dbg_Module module ){    UpnpPrintf( level, module, __FILE__, __LINE__,        "URL_BASE: %s\n", table->URLBase );    UpnpPrintf( level, module, __FILE__, __LINE__,        "Services: \n" );    printServiceList( table->serviceList, level, module );}#endif/*************************************************************************	Function :	freeService**	Parameters :*		service_info *in ;	service information that is to be freed**	Description :	Free's memory allocated for the various components *		of the service entry in the service table.**	Return : void ;**	Note :************************************************************************/void freeService( service_info * in ){    if( in ) {        if( in->serviceType )            ixmlFreeDOMString( in->serviceType );        if( in->serviceId )            ixmlFreeDOMString( in->serviceId );        if( in->SCPDURL )            free( in->SCPDURL );        if( in->controlURL )            free( in->controlURL );        if( in->eventURL )            free( in->eventURL );        if( in->UDN )            ixmlFreeDOMString( in->UDN );        if( in->subscriptionList )            freeSubscriptionList( in->subscriptionList );        in->TotalSubscriptions = 0;        free( in );    }}/*************************************************************************	Function :	freeServiceList**	Parameters :*		service_info * head ;	Head of the service list to be freed**	Description :	Free's memory allocated for the various components *		of each service entry in the service table.**	Return : void ;**	Note :************************************************************************/voidfreeServiceList( service_info * head ){    service_info *next = NULL;    while( head ) {        if( head->serviceType )            ixmlFreeDOMString( head->serviceType );        if( head->serviceId )            ixmlFreeDOMString( head->serviceId );        if( head->SCPDURL )            free( head->SCPDURL );        if( head->controlURL )            free( head->controlURL );        if( head->eventURL )            free( head->eventURL );        if( head->UDN )            ixmlFreeDOMString( head->UDN );        if( head->subscriptionList )            freeSubscriptionList( head->subscriptionList );        head->TotalSubscriptions = 0;        next = head->next;        free( head );        head = next;    }}/*************************************************************************	Function :	freeServiceTable**	Parameters :*		service_table * table ;	Service table whose memory needs to be *								freed**	Description : Free's dynamic memory in table.*		(does not free table, only memory within the structure)**	Return : void ;**	Note :************************************************************************/voidfreeServiceTable( service_table * table ){    ixmlFreeDOMString( table->URLBase );    freeServiceList( table->serviceList );    table->serviceList = NULL;    table->endServiceList = NULL;}/*************************************************************************	Function :	getElementValue**	Parameters :*		IXML_Node *node ;	Input node which provides the list of child *							nodes**	Description :	Returns the clone of the element value**	Return : DOMString ;**	Note : value must be freed with DOMString_free************************************************************************/DOMStringgetElementValue( IXML_Node * node ){    IXML_Node *child = ( IXML_Node * ) ixmlNode_getFirstChild( node );    const DOMString temp = NULL;    if( ( child != 0 ) && ( ixmlNode_getNodeType( child ) == eTEXT_NODE ) ) {        temp = ixmlNode_getNodeValue( child );        return ixmlCloneDOMString( temp );    } else {        return NULL;    }}/*************************************************************************	Function :	getSubElement**	Parameters :*		const char *element_name ;	sub element name to be searched for*		IXML_Node *node ;	Input node which provides the list of child *							nodes*		IXML_Node **out ;	Ouput node to which the matched child node is*							returned.**	Description :	Traverses through a list of XML nodes to find the *		node with the known element name.**	Return : int ;*		1 - On Success*		0 - On Failure**	Note :************************************************************************/intgetSubElement( const char *element_name,               IXML_Node * node,               IXML_Node ** out ){    const DOMString NodeName = NULL;    int found = 0;    IXML_Node *child = ( IXML_Node * ) ixmlNode_getFirstChild( node );    ( *out ) = NULL;    while( ( child != NULL ) && ( !found ) ) {        switch ( ixmlNode_getNodeType( child ) ) {            case eELEMENT_NODE:                NodeName = ixmlNode_getNodeName( child );                if( !strcmp( NodeName, element_name ) ) {                    ( *out ) = child;                    found = 1;                    return found;                }                break;            default:                break;        }        child = ( IXML_Node * ) ixmlNode_getNextSibling( child );    }    return found;}/*************************************************************************	Function :	getServiceList**	Parameters :*		IXML_Node *node ;	XML node information*		service_info **end ; service added is returned to the output*							parameter*		char * URLBase ;	provides Base URL to resolve relative URL **	Description :	Returns pointer to service info after getting the *		sub-elements of the service info. **	Return : service_info * - pointer to the service info node ;**	Note :************************************************************************/

⌨️ 快捷键说明

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