📄 upnpapi.c
字号:
else { DBGONLY( xmlBuf = UpnpNewPrintDocument(*xmlDoc); UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Printing the Parsed xml document \n %s\n", xmlBuf); UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"********************* END OF Parsed XML Doc*******************\n"); free(xmlBuf); UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Exiting UpnpDownloadXmlDoc\n");) return UPNP_E_SUCCESS; }} /****************** End of UpnpDownloadXmlDoc *********************/ //-----------------------------------------------------------------------------//// UPNP-API Internal function implementation////-----------------------------------------------------------------------------//********************************************************//* Name: AdvertiseAndReply//* Description: Function to send SSDP advertisements, replies and//* shutdown messages.//* Called by: UpnpSendAdvertisement, SsdpCallbackHandler, //* UpnpUnRegisterRootDevice.//* In: int AdFlag ://* AdFlag = -1 : Send Shutdown //* AdFlag = 0 : Send Reply//* AdFlag = 1 : Send Advertisement//* UpnpDevice_Handle Hnd : Device handle//* enum SsdpSearchType SearchType : Search type for sending//* replies.//* struct sockaddr_in *DestAddr : Destination address//* char *DeviceType : Device type//* char *DeviceUDN : Device UDN//* char *ServiceType : Service type//* int Exp : Advertisement age//* Out: none//* Return Codes: UPNP_E_SUCCESS//* Error Codes: UPNP_E_INVALID_HANDLE//*//********************************************************#ifdef INCLUDE_DEVICE_APIS#if EXCLUDE_SSDP == 0int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd, enum SsdpSearchType SearchType, struct sockaddr_in *DestAddr, char *DeviceType, char *DeviceUDN, char *ServiceType, int Exp){ int i, j; int defaultExp = DEFAULT_MAXAGE; struct Handle_Info * SInfo=NULL; char UDNstr[100], devType[100], servType[100]; Upnp_NodeList NodeList = NULL; Upnp_NodeList tmpNodeList = NULL; Upnp_Node tmpNode = NULL; Upnp_Node tmpNode2 = NULL; Upnp_Node textNode = NULL; Upnp_DOMException err; Upnp_DOMString tmpStr; DBGONLY( Upnp_DOMString dbgStr; UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Inside AdvertiseAndReply with AdFlag = %d\n", AdFlag);) HandleLock(); if(GetHandleInfo(Hnd, &SInfo) != HND_DEVICE) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } defaultExp = SInfo->MaxAge; // Modified to prevent more than one thread accessing the same UpnpDocument // HandleUnlock(); // parse the device list and send advertisements/replies for (i = 0; ; i++) { DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Entering new device list with i = %d\n\n", i);) UpnpNode_free(tmpNode); tmpNode = UpnpNodeList_item(SInfo->DeviceList, i); if (tmpNode == NULL) { DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Exiting new device list with i = %d\n\n", i);) break; } DBGONLY( dbgStr = UpnpNode_getNodeName(tmpNode); UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Extracting device type once for %s\n", dbgStr); free(dbgStr);) // extract device type NodeList = UpnpElement_getElementsByTagName(tmpNode, "deviceType"); if (NodeList == NULL) { continue; } DBGONLY( dbgStr = UpnpNode_getNodeName(tmpNode); UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Extracting UDN for %s\n", dbgStr); free(dbgStr);) DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Extracting device type\n");) tmpNode2 = UpnpNodeList_item(NodeList, 0); UpnpNodeList_free(NodeList); if (tmpNode2 == NULL) { continue; } textNode = UpnpNode_getFirstChild(tmpNode2); UpnpNode_free(tmpNode2); if (textNode == NULL) { continue; } DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Extracting device type \n");) tmpStr = UpnpNode_getNodeValue(textNode, &err); UpnpNode_free(textNode); if (tmpStr == NULL) { continue; } strcpy(devType , tmpStr); free(tmpStr); if (devType == NULL) { continue; } DBGONLY( UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Extracting device type = %s\n", devType); if (tmpNode == NULL) UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"TempNode is NULL\n"); dbgStr = UpnpNode_getNodeName(tmpNode); UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Extracting UDN for %s\n",dbgStr); free(dbgStr);) // extract UDN NodeList = UpnpElement_getElementsByTagName(tmpNode, "UDN"); if (NodeList == NULL) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,API,__FILE__,__LINE__,"UDN not found!!!\n");) continue; } tmpNode2 = UpnpNodeList_item(NodeList, 0); UpnpNodeList_free(NodeList); if (tmpNode2 == NULL) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,API,__FILE__,__LINE__,"UDN not found!!!\n");) continue; } textNode = UpnpNode_getFirstChild(tmpNode2); UpnpNode_free(tmpNode2); if (textNode == NULL) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,API,__FILE__,__LINE__,"UDN not found!!!\n");) continue; } tmpStr = UpnpNode_getNodeValue(textNode, &err); UpnpNode_free(textNode); if (tmpStr == NULL) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,API,__FILE__,__LINE__,"UDN not found!!!!\n");) continue; } strcpy(UDNstr, tmpStr); free(tmpStr); if (UDNstr == NULL) { continue; } DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Sending UDNStr = %s \n", UDNstr);) if (AdFlag) { // send the device advertisement if (AdFlag == 1) { DeviceAdvertisement(devType, i==0 , UDNstr, SERVER,SInfo->DescURL, Exp); } else // AdFlag == -1 { DeviceShutdown(devType, i==0 , UDNstr, SERVER, SInfo->DescURL, Exp); } } else { switch (SearchType) { case SSDP_ALL : DeviceReply(DestAddr, devType, i==0, UDNstr, SERVER,SInfo->DescURL, defaultExp); break; case SSDP_ROOTDEVICE : if (i==0) { SendReply(DestAddr, devType, 1, UDNstr, SERVER,SInfo->DescURL, defaultExp, 0); } break; case SSDP_DEVICE : if (DeviceUDN != NULL && strlen(DeviceUDN) != 0) { if (strcasecmp(DeviceUDN, UDNstr)) { DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"DeviceUDN=%s and search UDN=%s did not match\n",UDNstr, DeviceUDN);) break; } else { DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"DeviceUDN=%s and search UDN=%s MATCH\n",UDNstr, DeviceUDN);) SendReply(DestAddr, devType, 0, UDNstr,SERVER, SInfo->DescURL, defaultExp, 0); break; } } if (!strcasecmp(DeviceType, devType)) { DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"DeviceType=%s and search devType=%s MATCH\n",devType,DeviceType);) SendReply(DestAddr, devType, 0, UDNstr,SERVER, SInfo->DescURL, defaultExp, 1); } DBGONLY(else UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"DeviceType=%s and search devType=%s DID NOT MATCH\n",devType,DeviceType);) break; default : break; } } // send service advertisements for services corresponding to the same device DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Sending service Advertisement\n");) UpnpNode_free(tmpNode); tmpNode = UpnpNodeList_item(SInfo->ServiceList, i); if (tmpNode == NULL) continue; NodeList = UpnpElement_getElementsByTagName(tmpNode, "service"); if (NodeList == NULL) { DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"Service not found 3\n");) continue; } for (j = 0; ; j++) { UpnpNode_free(tmpNode); tmpNode = UpnpNodeList_item(NodeList, j); if (tmpNode == NULL) break; tmpNodeList = UpnpElement_getElementsByTagName(tmpNode,"serviceType"); if (tmpNodeList == NULL) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,API,__FILE__,__LINE__,"ServiceType not found \n");) continue; } tmpNode2 = UpnpNodeList_item(tmpNodeList, 0); UpnpNodeList_free(tmpNodeList); if (tmpNode2 == NULL) { continue; } textNode = UpnpNode_getFirstChild(tmpNode2); UpnpNode_free(tmpNode2); if (textNode == NULL) { continue; } // servType is of format Servicetype:ServiceVersion tmpStr = UpnpNode_getNodeValue(textNode, &err); UpnpNode_free(textNode); if (tmpStr == NULL) { continue; } strcpy(servType, tmpStr); free(tmpStr); if (servType == NULL) { continue; } DBGONLY(UpnpPrintf(UPNP_INFO,API,__FILE__,__LINE__,"ServiceType = %s\n", servType);) if (AdFlag) { if (AdFlag == 1) { ServiceAdvertisement(UDNstr, servType,SERVER, SInfo->DescURL, Exp); } else // AdFlag == -1 { ServiceShutdown(UDNstr, servType, SERVER,SInfo->DescURL, Exp); } } else { switch(SearchType) { case SSDP_ALL : ServiceReply(DestAddr, servType, UDNstr,SERVER, SInfo->DescURL, defaultExp); break; case SSDP_SERVICE : if (ServiceType != NULL) { if (!strcasecmp(ServiceType, servType)) { ServiceReply(DestAddr, servType,UDNstr, SERVER, SInfo->DescURL, defaultExp); } } break; default : break; } // switch(SearchType) } } } DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Exiting AdvertiseAndReply : \n");) HandleUnlock();// Modified to prevent more than one //thread accessing the same UpnpDocument return UPNP_E_SUCCESS; } /****************** End of AdvertiseAndReply *********************/#endif#endif#ifdef INCLUDE_CLIENT_APIS//********************************************************//* Name: UpnpThreadDistribution//* Description: Function to schedule async functions in threadpool.//* Called by: threadpool functions//* In: struct UpnpNonblockParam * Param//* Out: none//* Return Codes: none//* Error Codes: none//********************************************************void UpnpThreadDistribution(struct UpnpNonblockParam * Param){ DBGONLY(UpnpPrintf(UPNP_ALL,API,__FILE__,__LINE__,"Inside UpnpThreadDistribution \n");) switch(Param->FunName) { #if EXCLUDE_GENA == 0 CLIENTONLY( case SUBSCRIBE: { struct Upnp_Event_Subscribe Evt; Evt.ErrCode = genaSubscribe (Param->Handle, Param->Url, (int *)&(Param->TimeOut), (char *) Evt.Sid); strcpy(Evt.PublisherUrl, Param->Url); Evt.TimeOut = Param->TimeOut; Param->Fun(UPNP_EVENT_SUBSCRIBE_COMPLETE,&Evt,Param->Cookie); free(Param); break; } case UNSUBSCRIBE: { struct Upnp_Event_Subscribe Evt; Evt.ErrCode = genaUnSubscribe (Param->Handle, Param->SubsId); strcpy((char *) Evt.Sid, Param->SubsId); Param->Fun(UPNP_EVENT_UNSUBSCRIBE_COMPLETE,&Evt,Param->Cookie); free(Param); break; } case RENEW : { struct Upnp_Event_Subscribe Evt; Evt.ErrCode = genaRenewSubscription (Param->Handle, Param->SubsId, &(Param->TimeOut)); Evt.TimeOut = Param->TimeOut; strcpy((char *) Evt.Sid, Param->SubsId); Param->Fun(UPNP_EVENT_RENEWAL_COMPLETE,&Evt,Param->Cookie); free(Param); break; }) #endif #if EXCLUDE_SOAP == 0 case ACTION: { struct Upnp_Action_Complete Evt; Evt.ActionResult = NULL; #ifdef INCLUDE_CLIENT_APIS Evt.ErrCode = SoapSendAction (Param->Url,Param->ServiceType, Param->Act, &Evt.ActionResult); #endif Evt.ActionRequest = Param->Act; strcpy(Evt.CtrlUrl, Param->Url); Param->Fun(UPNP_CONTROL_ACTION_COMPLETE,&Evt,Param->Cookie); UpnpDocument_free(Evt.ActionRequest); UpnpDocument_free(Evt.ActionResult); free(Param); break; } case STATUS: { struct Upnp_State_Var_Complete Evt; #ifdef INCLUDE_CLIENT_APIS Evt.ErrCode = SoapGetServiceVarStatus (Param->Url, Param->VarName, &(Evt.CurrentVal)); #endif strcpy(Evt.StateVarName, Param->VarName); strcpy(Evt.CtrlUrl, Param->Url); Param->Fun(UPNP_CONTROL_GET_VAR_COMPLETE,&Evt,Param->Cookie); free(Evt.CurrentVal); free(Param); break; } #endif //EXCLUDE_SOAP default : break; } // end of switch(Param-
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -