📄 service_table.c
字号:
service_info *head = NULL; service_info *current = NULL; service_info *previous = NULL; IXML_NodeList *serviceNodeList = NULL; int NumOfServices = 0; int i = 0; int fail = 0; if( getSubElement( "UDN", node, &UDN ) && getSubElement( "serviceList", node, &serviceList ) ) { serviceNodeList = ixmlElement_getElementsByTagName( ( IXML_Element * ) serviceList, "service" ); if( serviceNodeList != NULL ) { NumOfServices = ixmlNodeList_length( serviceNodeList ); for( i = 0; i < NumOfServices; i++ ) { current_service = ixmlNodeList_item( serviceNodeList, i ); fail = 0; if( current ) { current->next = ( service_info * ) malloc( sizeof( service_info ) ); previous = current; current = current->next; } else { head = ( service_info * ) malloc( sizeof( service_info ) ); current = head; } if( !current ) { freeServiceList( head ); return NULL; } current->next = NULL; current->controlURL = NULL; current->eventURL = NULL; current->serviceType = NULL; current->serviceId = NULL; current->SCPDURL = NULL; current->active = 1; current->subscriptionList = NULL; current->TotalSubscriptions = 0; if( !( current->UDN = getElementValue( UDN ) ) ) fail = 1; if( ( !getSubElement( "serviceType", current_service, &serviceType ) ) || ( !( current->serviceType = getElementValue( serviceType ) ) ) ) fail = 1; if( ( !getSubElement( "serviceId", current_service, &serviceId ) ) || ( ! ( current->serviceId = getElementValue( serviceId ) ) ) ) fail = 1; if( ( ! ( getSubElement ( "SCPDURL", current_service, &SCPDURL ) ) ) || ( !( tempDOMString = getElementValue( SCPDURL ) ) ) || ( ! ( current->SCPDURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) fail = 1; ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( ( ! ( getSubElement ( "controlURL", current_service, &controlURL ) ) ) || ( !( tempDOMString = getElementValue( controlURL ) ) ) || ( ! ( current->controlURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { DBGONLY( UpnpPrintf ( UPNP_INFO, GENA, __FILE__, __LINE__, "BAD OR MISSING CONTROL URL" ) ); DBGONLY( UpnpPrintf ( UPNP_INFO, GENA, __FILE__, __LINE__, "CONTROL URL SET TO NULL IN SERVICE INFO" ) ); current->controlURL = NULL; fail = 0; } ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( ( ! ( getSubElement ( "eventSubURL", current_service, &eventURL ) ) ) || ( !( tempDOMString = getElementValue( eventURL ) ) ) || ( ! ( current->eventURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { DBGONLY( UpnpPrintf ( UPNP_INFO, GENA, __FILE__, __LINE__, "BAD OR MISSING EVENT URL" ) ); DBGONLY( UpnpPrintf ( UPNP_INFO, GENA, __FILE__, __LINE__, "EVENT URL SET TO NULL IN SERVICE INFO" ) ); current->eventURL = NULL; fail = 0; } ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( fail ) { freeServiceList( current ); if( previous ) previous->next = NULL; else head = NULL; current = previous; } } ixmlNodeList_free( serviceNodeList ); } ( *end ) = current; return head; } else return NULL;}/************************************************************************* Function : getAllServiceList** Parameters :* IXML_Node *node ; XML node information* char * URLBase ; provides Base URL to resolve relative URL * service_info **out_end ; service added is returned to the output* parameter** Description : Returns pointer to service info after getting the * sub-elements of the service info. ** Return : service_info * ;** Note :************************************************************************/service_info *getAllServiceList( IXML_Node * node, char *URLBase, service_info ** out_end ){ service_info *head = NULL; service_info *end = NULL; service_info *next_end = NULL; IXML_NodeList *deviceList = NULL; IXML_Node *currentDevice = NULL; int NumOfDevices = 0; int i = 0; ( *out_end ) = NULL; deviceList = ixmlElement_getElementsByTagName( ( IXML_Element * ) node, "device" ); if( deviceList != NULL ) { NumOfDevices = ixmlNodeList_length( deviceList ); for( i = 0; i < NumOfDevices; i++ ) { currentDevice = ixmlNodeList_item( deviceList, i ); if( head ) { end->next = getServiceList( currentDevice, &next_end, URLBase ); end = next_end; } else head = getServiceList( currentDevice, &end, URLBase ); } ixmlNodeList_free( deviceList ); } ( *out_end ) = end; return head;}/************************************************************************* Function : removeServiceTable** Parameters :* IXML_Node *node ; XML node information* service_table *in ; service table from which services will be * removed** Description : This function assumes that services for a particular * root device are placed linearly in the service table, and in the * order in which they are found in the description document* all services for this root device are removed from the list** Return : int ;** Note :************************************************************************/intremoveServiceTable( IXML_Node * node, service_table * in ){ IXML_Node *root = NULL; IXML_Node *currentUDN = NULL; DOMString UDN = NULL; IXML_NodeList *deviceList = NULL; IXML_Node *currentDevice = NULL; service_info *current_service = NULL; service_info *start_search = NULL; service_info *prev_service = NULL; int NumOfDevices = 0; int i = 0; if( getSubElement( "root", node, &root ) ) { current_service = in->serviceList; start_search = in->serviceList; deviceList = ixmlElement_getElementsByTagName( ( IXML_Element * ) root, "device" ); if( deviceList != NULL ) { NumOfDevices = ixmlNodeList_length( deviceList ); for( i = 0; i < NumOfDevices; i++ ) { currentDevice = ixmlNodeList_item( deviceList, i ); if( ( start_search ) && ( ( getSubElement( "UDN", node, ¤tUDN ) ) && ( UDN = getElementValue( currentUDN ) ) ) ) { current_service = start_search; //Services are put in the service table in the order in which they appear in the //description document, therefore we go through the list only once to remove a particular //root device while( ( current_service ) && ( strcmp( current_service->UDN, UDN ) ) ) { current_service = current_service->next; prev_service = current_service->next; } while( ( current_service ) && ( !strcmp( current_service->UDN, UDN ) ) ) { if( prev_service ) { prev_service->next = current_service->next; } else { in->serviceList = current_service->next; } if( current_service == in->endServiceList ) in->endServiceList = prev_service; start_search = current_service->next; freeService( current_service ); current_service = start_search; } } } ixmlNodeList_free( deviceList ); } } return 1;}/************************************************************************* Function : addServiceTable** Parameters :* IXML_Node *node ; XML node information * service_table *in ; service table that will be initialized with * services* const char *DefaultURLBase ; Default base URL on which the URL * will be returned to the service list.** Description : Add Service to the table.** Return : int ;** Note :************************************************************************/intaddServiceTable( IXML_Node * node, service_table * in, const char *DefaultURLBase ){ IXML_Node *root = NULL; IXML_Node *URLBase = NULL; service_info *tempEnd = NULL; if( in->URLBase ) { free( in->URLBase ); in->URLBase = NULL; } if( getSubElement( "root", node, &root ) ) { if( getSubElement( "URLBase", root, &URLBase ) ) { in->URLBase = getElementValue( URLBase ); } else { if( DefaultURLBase ) { in->URLBase = ixmlCloneDOMString( DefaultURLBase ); } else { in->URLBase = ixmlCloneDOMString( "" ); } } if( ( in->endServiceList->next = getAllServiceList( root, in->URLBase, &tempEnd ) ) ) { in->endServiceList = tempEnd; return 1; } } return 0;}/************************************************************************* Function : getServiceTable** Parameters :* IXML_Node *node ; XML node information* service_table *out ; output parameter which will contain the * service list and URL * const char *DefaultURLBase ; Default base URL on which the URL * will be returned.** Description : Retrieve service from the table** Return : int ;** Note :************************************************************************/intgetServiceTable( IXML_Node * node, service_table * out, const char *DefaultURLBase ){ IXML_Node *root = NULL; IXML_Node *URLBase = NULL; if( getSubElement( "root", node, &root ) ) { if( getSubElement( "URLBase", root, &URLBase ) ) { out->URLBase = getElementValue( URLBase ); } else { if( DefaultURLBase ) { out->URLBase = ixmlCloneDOMString( DefaultURLBase ); } else { out->URLBase = ixmlCloneDOMString( "" ); } } if( ( out->serviceList = getAllServiceList( root, out->URLBase, &out-> endServiceList ) ) ) { return 1; } } return 0;}#endif // INCLUDE_DEVICE_APIS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -