📄 service_table.c
字号:
/************************************************************************
* Function : FindServiceControlURLPath
*
* Parameters :
* service_table * table ; service table
* char * controlURLPath ; control URL path used to find a service
* from the table
*
* 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,
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
* Dbg_Level 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 :
************************************************************************/
DBGONLY( void printService( service_info * service, Dbg_Level 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" );}
}
)
/************************************************************************
* Function : printServiceList
*
* Parameters :
* service_info *service ; Service whose information is to be printed
* Dbg_Level 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 :
************************************************************************/
DBGONLY( void printServiceList( service_info * service,
Dbg_Level 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;}
}
)
/************************************************************************
* Function : printServiceTable
*
* Parameters :
* service_table * table ; Service table to be printed
* Dbg_Level 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 :
************************************************************************/
DBGONLY( void printServiceTable( service_table * table,
Dbg_Level 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 );}
)
/************************************************************************
* 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 :
************************************************************************/
void
freeServiceList( 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 :
************************************************************************/
void
freeServiceTable( 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
************************************************************************/
DOMString
getElementValue( IXML_Node * node )
{
IXML_Node *child = ( IXML_Node * ) ixmlNode_getFirstChild( node );
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 :
************************************************************************/
int
getSubElement( 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 :
************************************************************************/
service_info *
getServiceList( IXML_Node * node,
service_info ** end,
char *URLBase )
{
IXML_Node *serviceList = NULL;
IXML_Node *current_service = NULL;
IXML_Node *UDN = NULL;
IXML_Node *serviceType = NULL;
IXML_Node *serviceId = NULL;
IXML_Node *SCPDURL = NULL;
IXML_Node *controlURL = NULL;
IXML_Node *eventURL = NULL;
DOMString tempDOMString = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -