⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssdplib.c

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 C
📖 第 1 页 / 共 4 页
字号:
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int SendReply(struct sockaddr_in * DestAddr, char *DevType, int RootDev, char * Udn, char *Server, char * Location, int  Duration, int ByType) {    char *szReq[1], Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];    int RetVal;    if(RootDev) //If deviceis a root device , here we need to send 3 advertisement or reply    {       szReq[0] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL) return UPNP_E_OUTOF_MEMORY ;       strcpy(Mil_Nt,"upnp:rootdevice");       sprintf(Mil_Usn,"%s::upnp:rootdevice",Udn);       CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(DestAddr,1, szReq) ;       free(szReq[0]);    }    else //If device is not a root device then it is a sub-device., here we need to send 2 advertisement or reply    {        szReq[0] = (char*)malloc(BUFSIZE);        if (szReq[0] == NULL) return UPNP_E_OUTOF_MEMORY;        if(ByType == 0)        {           sprintf(Mil_Nt,"%s",Udn);           sprintf(Mil_Usn,"%s",Udn);           CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);           RetVal = NewRequestHandler(DestAddr,1, szReq);        }        else        {           sprintf(Mil_Nt,"%s",DevType);           sprintf(Mil_Usn,"%s::%s",Udn,DevType);           CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);           RetVal = NewRequestHandler(DestAddr,1, szReq);        }        free(szReq[0]);    }    return RetVal; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function    : int DeviceReply(int RootDev, char *DevType,char * Udn,struct sockaddr_in * DestAddr,char *Server,char * Location,int  Duration) // Description : This function creates the reply packet based on the input parameter, and send it to the client addesss //               given in its input parameter DestAddr. // Parameters  : RootDev : 1 means root device 0 means embedded device. //               Udn : Device UDN //               DevType : Device Type. //               Location : Loaction of Device description document. //               Duration : Life time of this device. //               DestAddr : destination IP address. // Return value: 1 if successfull. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  int DeviceReply(struct sockaddr_in * DestAddr, char *DevType, int RootDev, char * Udn, char *Server, char * Location, int  Duration) {    char *szReq[3], Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];    int RetVal;    if(RootDev) //If deviceis a root device , here we need to send 3 advertisement or reply    {       szReq[0] = (char*)malloc(BUFSIZE);       szReq[1] = (char*)malloc(BUFSIZE);       szReq[2] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL || szReq[1] == NULL|| szReq[2] == NULL ) return UPNP_E_OUTOF_MEMORY ;       strcpy(Mil_Nt,"upnp:rootdevice");       sprintf(Mil_Usn,"%s::upnp:rootdevice",Udn);       CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",Udn);       sprintf(Mil_Usn,"%s",Udn);       CreateServiceRequestPacket(2,szReq[1],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",DevType);       sprintf(Mil_Usn,"%s::%s",Udn,DevType);       CreateServiceRequestPacket(2,szReq[2],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(DestAddr,3, szReq) ;       free(szReq[0]);       free(szReq[1]);       free(szReq[2]);    }    else //If device is not a root device then it is a sub-device., here we need to send 2 advertisement or reply    {       szReq[0] = (char*)malloc(BUFSIZE);       szReq[1] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL || szReq[1] == NULL ) return UPNP_E_OUTOF_MEMORY ;       sprintf(Mil_Nt,"%s",Udn);       sprintf(Mil_Usn,"%s",Udn);       CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",DevType);       sprintf(Mil_Usn,"%s::%s",Udn,DevType);       CreateServiceRequestPacket(2,szReq[1],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(DestAddr,2, szReq);       free(szReq[0]);       free(szReq[1]);     }    return RetVal; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function    : int ServiceAdvertisement( char * Udn, char * ServType,char *Server,char * Location,int  Duration) // Description : This function creates the advertisement packet based on the input parameter, and send it to the //               multicast channel. // Parameters  : Server : Os. //               Udn : Device UDN //               ServType : Service Type. //               Location : Loaction of Device description document. //               Duration : Life time of this device. // Return value: 1 if successfull. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   int ServiceAdvertisement( char * Udn, char * ServType,char *Server,char * Location,int  Duration)  {       char Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];       char * szReq[1];       struct sockaddr_in DestAddr;       int RetVal;       fflush(stdout);       szReq[0] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL) return UPNP_E_OUTOF_MEMORY ;       DestAddr.sin_family = AF_INET;       DestAddr.sin_addr.s_addr = inet_addr(SSDP_IP);       DestAddr.sin_port = htons(SSDP_PORT);       sprintf(Mil_Nt,"%s",ServType);       sprintf(Mil_Usn,"%s::%s",Udn,ServType);       CreateServiceRequestPacket(1,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(&DestAddr,1, szReq);       free(szReq[0]);       return RetVal;  } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function    : int ServiceReply( char * Udn, char * ServType,char *Server,char * Location,int  Duration,struct sockaddr_in *DestAddr) // Description : This function creates the advertisement packet based on the input parameter, and send it to the //               multicast channel. // Parameters  : Server : Os //               Udn : Device UDN //               ServType : Service Type. //               Location : Loaction of Device description document. //               Duration : Life time of this device. //               DestAddr : Client IP address. // Return value: 1 if successfull. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   int ServiceReply(struct sockaddr_in *DestAddr,  char * ServType, char * Udn, char *Server,char * Location,int  Duration)  {       char Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];       char * szReq[1];       int RetVal;       szReq[0] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL) return UPNP_E_OUTOF_MEMORY ;       sprintf(Mil_Nt,"%s",ServType);       sprintf(Mil_Usn,"%s::%s",Udn,ServType);       CreateServiceRequestPacket(2,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(DestAddr,1, szReq);       free(szReq[0]);       return RetVal;  }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function    : int ServiceShutdown(int RootDev, char *DevType,char * Udn,struct sockaddr_in * DestAddr,char *Server,char * Location,int  Duration) // Description : This function creates a HTTP service shutdown request packet and sent it to the multicast channel through //               RequestHandler. // Parameters  : RootDev  : 1 means root device. //               DevType  : Device Type or category //               Udn      : Device UDN //               Location : Location URL. //               Duration : Service duration in sec. // // Return value: None //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  int ServiceShutdown( char * Udn, char * ServType,char *Server,char * Location,int  Duration){               char Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];       char * szReq[1];       struct sockaddr_in DestAddr;       int RetVal;       szReq[0] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL) return UPNP_E_OUTOF_MEMORY ;       DestAddr.sin_family = AF_INET;       DestAddr.sin_addr.s_addr = inet_addr(SSDP_IP);       DestAddr.sin_port = htons(SSDP_PORT);       sprintf(Mil_Nt,"%s",ServType);       sprintf(Mil_Usn,"%s::%s",Udn,ServType);       CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(&DestAddr,1, szReq);       free(szReq[0]);       return RetVal;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function    : int DeviceShutdown(int RootDev, char *DevType,char * Udn,struct sockaddr_in * DestAddr,char *Server,char * Location,int  Duration) // Description : This function creates a HTTP service shutdown request packet and sent it to the multicast channel through //               RequestHandler. // Parameters  : RootDev  : 1 means root device. //               DevType  : Device Type or category //               Udn      : Device UDN //               Location : Location URL. //               Duration : Service duration in sec. // // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int DeviceShutdown(char * DevType, int RootDev,char * Udn, char *Server, char * Location, int  Duration) {    struct sockaddr_in DestAddr;    char *szReq[3], Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];    int RetVal;    DBGONLY(UpnpPrintf(UPNP_ALL,SSDP,__FILE__,__LINE__,"In function SendDeviceAdvertisemenrt\n");)    DestAddr.sin_family = AF_INET;    DestAddr.sin_addr.s_addr = inet_addr(SSDP_IP);    DestAddr.sin_port = htons(SSDP_PORT);    if(RootDev) //If deviceis a root device , here we need to send 3 advertisement or reply    {       szReq[0] = (char*)malloc(BUFSIZE);       szReq[1] = (char*)malloc(BUFSIZE);       szReq[2] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL || szReq[1] == NULL || szReq[2] == NULL) return UPNP_E_OUTOF_MEMORY ;       strcpy(Mil_Nt,"upnp:rootdevice");       sprintf(Mil_Usn,"%s::upnp:rootdevice",Udn);       CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",Udn);       sprintf(Mil_Usn,"%s",Udn);       CreateServiceRequestPacket(0,szReq[1],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",DevType);       sprintf(Mil_Usn,"%s::%s",Udn,DevType);       CreateServiceRequestPacket(0,szReq[2],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(&DestAddr,3, szReq) ;       free(szReq[0]);       free(szReq[1]);       free(szReq[2]);    }    else //If device is not a root device then it is a sub-device., here we need to send 2 advertisement or reply    {       szReq[0] = (char*)malloc(BUFSIZE);       szReq[1] = (char*)malloc(BUFSIZE);       if (szReq[0] == NULL || szReq[1] == NULL ) return UPNP_E_OUTOF_MEMORY ;       sprintf(Mil_Nt,"%s",Udn);       sprintf(Mil_Usn,"%s",Udn);       CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn,Server,Location,Duration);       sprintf(Mil_Nt,"%s",DevType);       sprintf(Mil_Usn,"%s::%s",Udn,DevType);       CreateServiceRequestPacket(0,szReq[1],Mil_Nt,Mil_Usn,Server,Location,Duration);       RetVal = NewRequestHandler(&DestAddr,2, szReq);       free(szReq[0]);       free(szReq[1]);     }     return RetVal;}#endif#endif

⌨️ 快捷键说明

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