📄 service_table.c
字号:
{ next=head->next; freeSubscription(head); free(head); head=next; }}void freeServiceList(service_info * head){ service_info *next=NULL; while (head) { if (head->serviceType) UpnpDOMString_free(head->serviceType); if (head->serviceId) UpnpDOMString_free(head->serviceId); if (head->SCPDURL) free(head->SCPDURL); if (head->controlURL) free(head->controlURL); if (head->eventURL) free(head->eventURL); if (head->UDN) UpnpDOMString_free(head->UDN); if (head->subscriptionList) freeSubscriptionList(head->subscriptionList); head->TotalSubscriptions=0; next=head->next; free(head); head=next; }}void freeServiceTable(service_table * table){ UpnpDOMString_free(table->URLBase); freeServiceList(table->serviceList); table->serviceList=NULL;}Upnp_DOMString getElementValue(Upnp_Node node){ Upnp_Node child = UpnpNode_getFirstChild(node); Upnp_DOMException err; Upnp_DOMString temp=NULL; if ( (child!=0) && (UpnpNode_getNodeType(child)==TEXT_NODE)) { temp= UpnpNode_getNodeValue(child,&err); UpnpNode_free(child); return temp; } else { return NULL; }}int getSubElement(const char * element_name,Upnp_Node node, Upnp_Node *out){ Upnp_DOMString NodeName=NULL; int found=0; Upnp_Node temp=NULL; Upnp_Node child=UpnpNode_getFirstChild(node); (*out)=NULL; while ( (child!=NULL) && (!found)) { switch(UpnpNode_getNodeType(child)) { case ELEMENT_NODE : NodeName =UpnpNode_getNodeName(child); if (!strcmp(NodeName,element_name)) { (*out)=child; found=1; UpnpDOMString_free(NodeName); return found; } UpnpDOMString_free(NodeName); break; default: ; } temp=UpnpNode_getNextSibling(child); UpnpNode_free(child); child=temp; } return found;}service_info * getServiceList(Upnp_Node node,service_info **end, char * URLBase){ Upnp_Node serviceList=NULL; Upnp_Node current_service=NULL; Upnp_Node UDN=NULL; Upnp_Node serviceType=NULL; Upnp_Node serviceId=NULL; Upnp_Node SCPDURL=NULL; Upnp_Node controlURL=NULL; Upnp_Node eventURL=NULL; service_info * head=NULL; service_info * current=NULL; service_info * previous=NULL; Upnp_DOMString tempDOMString=NULL; Upnp_NodeList serviceNodeList=NULL; int NumOfServices=0; int i=0; int fail=0; if ( (getSubElement("UDN",node,&UDN)) && (getSubElement("serviceList",node,&serviceList)) ) { serviceNodeList=UpnpElement_getElementsByTagName(serviceList, "service"); if (serviceNodeList!=NULL) { NumOfServices=UpnpNodeList_getLength(serviceNodeList); for (i=0;i<NumOfServices;i++) { current_service=UpnpNodeList_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; UpnpDOMString_free(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; } UpnpDOMString_free(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; } UpnpDOMString_free(tempDOMString); tempDOMString=NULL; if (fail) { freeServiceList(current); if (previous) previous->next=NULL; else head=NULL; current=previous; } UpnpNode_free(controlURL); UpnpNode_free(eventURL); UpnpNode_free(SCPDURL); UpnpNode_free(serviceId); UpnpNode_free(serviceType); UpnpNode_free(current_service); } UpnpNodeList_free(serviceNodeList); } (*end)=current; UpnpNode_free(UDN); UpnpNode_free(serviceList); return head; } else return NULL; }service_info * getAllServiceList(Upnp_Node node, char * URLBase){ service_info * head=NULL; service_info * end=NULL; service_info *next_end=NULL; Upnp_NodeList deviceList=NULL; Upnp_Node currentDevice=NULL; int NumOfDevices=0; int i=0; deviceList=UpnpElement_getElementsByTagName(node, "device"); if (deviceList!=NULL) { NumOfDevices=UpnpNodeList_getLength(deviceList); for (i=0;i<NumOfDevices;i++) { currentDevice=UpnpNodeList_item(deviceList,i); if (head) { end->next=getServiceList(currentDevice,&next_end,URLBase); end=next_end; } else head=getServiceList(currentDevice,&end,URLBase); UpnpNode_free(currentDevice); } UpnpNodeList_free(deviceList); } return head;} int getServiceTable(Upnp_Node node, service_table * out, char * DefaultURLBase){ Upnp_Node root=NULL; Upnp_Node URLBase=NULL; // Upnp_Node device; if (getSubElement("root",node,&root)) { if (getSubElement("URLBase",root,&URLBase)) { out->URLBase=getElementValue(URLBase); UpnpNode_free(URLBase); } else { if (DefaultURLBase) { out->URLBase=UpnpCloneDOMString(DefaultURLBase); } else { out->URLBase=UpnpCloneDOMString(""); (*out->URLBase)=0; } } if ((out->serviceList=getAllServiceList(root,out->URLBase))) { UpnpNode_free(root); return 1; } UpnpNode_free(root); } return 0;})#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -