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

📄 mscp_controlpoint.c

📁 intel upnp stack source code
💻 C
📖 第 1 页 / 共 5 页
字号:
		}		xml = xml->Peer;	}		if(BaseURL==NULL)	{		ILibParseUri(LocationURL,&IP,&Port,&Path);		BaseURL = (char*)malloc(18+(int)strlen(IP));		sprintf(BaseURL,"http://%s:%d/",IP,Port);				free(IP);		free(Path);	}		DEBUGSTATEMENT(printf("BaseURL: %s\r\n",BaseURL));		xml = rootXML;	xml = xml->Next;	while(xml->NameLength!=6 && memcmp(xml->Name,"device",6)!=0 && xml!=NULL)	{		xml = xml->Peer;	}	if(xml==NULL)	{		/* Error */		ILibDestructXMLNodeList(rootXML);		return;	}		RootDevice = MSCP_ProcessDeviceXML_device(xml,v_CP,BaseURL,Timeout,RecvAddr);	free(BaseURL);	ILibDestructXMLNodeList(rootXML);			/* Save reference to LocationURL in the RootDevice */	RootDevice->LocationURL = (char*)malloc(strlen(LocationURL)+1);	sprintf(RootDevice->LocationURL,"%s",LocationURL);		MSCP_ProcessDevice(v_CP,RootDevice);	RootDevice->SCPDLeft = 0;	MSCP_CalculateSCPD_FetchCount(RootDevice);	if(RootDevice->SCPDLeft==0)	{		MSCP_FinishProcessingDevice(v_CP,RootDevice);	}	else	{		MSCP_SCPD_Fetch(RootDevice);	}}static void MSCP_HTTP_Sink_DeviceDescription(void *WebReaderToken,int IsInterrupt,struct packetheader *header,char *buffer,int *p_BeginPointer,int EndPointer,int done,void *user,void *cp,int *PAUSE){	struct CustomUserData *customData = (struct CustomUserData*)user;	if(header!=NULL && done!=0)	{		MSCP_ProcessDeviceXML(cp,buffer,EndPointer-(*p_BeginPointer),customData->buffer,header->ReceivingAddress,customData->Timeout);	}	if(done!=0)	{		free(customData->buffer);		free(user);	}}static void MSCP__FlushRequest(struct UPnPDevice *device){	struct UPnPDevice *ed = device->EmbeddedDevices;	struct UPnPService *s = device->Services;		while(ed!=NULL)	{		MSCP__FlushRequest(ed);		ed = ed->Next;	}	while(s!=NULL)	{		s = s->Next;	}}static void MSCP_CP_RecursiveReleaseAndEventDevice(struct MSCP_CP* CP, struct UPnPDevice *device){	struct UPnPDevice *temp = device->EmbeddedDevices;		while(temp!=NULL)	{		MSCP_CP_RecursiveReleaseAndEventDevice(CP,temp);		temp = temp->Next;	}		if(device->Reserved!=0)	{		if(CP->RemoveSink!=NULL)		{			CP->RemoveSink(device);		}		MSCP_Release(device);	}}void MSCP_CP_ProcessDeviceRemoval(struct MSCP_CP* CP, struct UPnPDevice *device){	struct UPnPDevice *temp = device->EmbeddedDevices;	struct UPnPService *s;	char *IP;	unsigned short port;	char *PATH;	struct UPnPDevice *dTemp = device;		if(dTemp->Parent!=NULL)	{		dTemp = dTemp->Parent;	}	ILibLifeTime_Remove(CP->LifeTimeMonitor,dTemp);			ILibLifeTime_Remove(CP->LifeTimeMonitor,dTemp);		while(temp!=NULL)	{		MSCP_CP_ProcessDeviceRemoval(CP,temp);		temp = temp->Next;	}		s = device->Services;	while(s!=NULL)	{		//		// Remove all the pending requests		//		ILibParseUri(s->ControlURL,&IP,&port,&PATH);		ILibWebClient_DeleteRequests(((struct MSCP_CP*)device->CP)->HTTP,IP,(int)port);		free(IP);		free(PATH);				ILibLifeTime_Remove(CP->LifeTimeMonitor,s);		s = s->Next;	}		if(device->Reserved!=0)	{		// device was flagged, and given to the user		if(CP->RemoveSink!=NULL)		{			CP->RemoveSink(device);		}		MSCP_Release(device);	}		ILibHashTree_Lock(CP->DeviceTable);	ILibDeleteEntry(CP->DeviceTable,device->UDN,(int)strlen(device->UDN));	if(device->LocationURL!=NULL)	{		ILibDeleteEntry(CP->DeviceTable,device->LocationURL,(int)strlen(device->LocationURL));	}	ILibHashTree_UnLock(CP->DeviceTable);}void MSCP_SSDP_Sink(void *sender, char* UDN, int Alive, char* LocationURL, int Timeout,UPnPSSDP_MESSAGE m,void *cp){	struct CustomUserData *customData;	char* buffer;	char* IP;	unsigned short Port;	char* Path;	struct packetheader *p;	struct sockaddr_in addr;		struct UPnPDevice *device;	int i=0;	struct MSCP_CP *CP = (struct MSCP_CP*)cp;	struct timeval t;		if(Alive!=0)	{		if(Timeout==0) {return;}	// ToDo: Solve this the correct way		/* Hello */		DEBUGSTATEMENT(printf("BinaryLight Hello\r\n"));		DEBUGSTATEMENT(printf("LocationURL: %s\r\n",LocationURL));		ILibHashTree_Lock(CP->DeviceTable);		if(ILibHasEntry(CP->DeviceTable,LocationURL,(int)strlen(LocationURL))==0 && ILibHasEntry(CP->DeviceTable,UDN,(int)strlen(UDN))==0)		{			ILibAddEntry(CP->DeviceTable,LocationURL,(int)strlen(LocationURL),NULL);			ILibAddEntry(CP->DeviceTable,UDN,(int)strlen(UDN),NULL);			ILibParseUri(LocationURL,&IP,&Port,&Path);			DEBUGSTATEMENT(printf("IP: %s Port: %d Path: %s\r\n",IP,Port,Path));			p = MSCP_BuildPacket(IP,Port,Path,"GET");						memset((char *)&addr, 0,sizeof(addr));			addr.sin_family = AF_INET;			addr.sin_addr.s_addr = inet_addr(IP);			addr.sin_port = htons(Port);						buffer = (char*)malloc((int)strlen(LocationURL)+1);			strcpy(buffer,LocationURL);						customData = (struct CustomUserData*)malloc(sizeof(struct CustomUserData));			customData->Timeout = Timeout;			customData->buffer = buffer;						ILibWebClient_PipelineRequest(			((struct MSCP_CP*)cp)->HTTP,			&addr,			p,			&MSCP_HTTP_Sink_DeviceDescription,			customData, 			cp);						free(IP);			free(Path);		}		else		{			// Periodic Notify Packets			device = (struct UPnPDevice*)ILibGetEntry(CP->DeviceTable,UDN,(int)strlen(UDN));			if(device!=NULL && m==UPnPSSDP_NOTIFY)			{				while(device->Parent!=NULL)				{					device = device->Parent;				}				if(strcmp(device->LocationURL,LocationURL)==0)				{					//Extend LifetimeMonitor duration					gettimeofday(&t,NULL);					device->Reserved2 = t.tv_sec;					ILibLifeTime_Remove(((struct MSCP_CP*)cp)->LifeTimeMonitor,device);					ILibLifeTime_Add(((struct MSCP_CP*)cp)->LifeTimeMonitor,device,Timeout,&MSCP_ExpiredDevice,NULL);				}				else				{					//					// Same device, different Interface					// Wait up to 7 seconds to see if the old interface is still					// valid.					//					gettimeofday(&t,NULL);					if(t.tv_sec-device->Reserved2>10)					{						device->Reserved2 = t.tv_sec;						if(device->Reserved3!=NULL) {free(device->Reserved3);}						device->Reserved3 = (char*)malloc(strlen(LocationURL)+1);						strcpy(device->Reserved3,LocationURL);						ILibLifeTime_Remove(((struct MSCP_CP*)cp)->LifeTimeMonitor,device);						ILibLifeTime_Add(((struct MSCP_CP*)cp)->LifeTimeMonitor,device,7,&MSCP_InterfaceChanged,NULL);					}				}			}		}		ILibHashTree_UnLock(CP->DeviceTable);	}	else	{		/* Bye Bye */		DEBUGSTATEMENT(printf("BinaryLight ByeBye\r\n"));		ILibHashTree_Lock(CP->DeviceTable);		device = (struct UPnPDevice*)ILibGetEntry(CP->DeviceTable,UDN,(int)strlen(UDN));		ILibHashTree_UnLock(CP->DeviceTable);		if(device!=NULL)		{			while(device->Parent!=NULL)			{				device = device->Parent;			}			ILibLifeTime_Remove(((struct MSCP_CP*)cp)->LifeTimeMonitor,device);			MSCP_CP_ProcessDeviceRemoval(CP,device);			i = device->ReferenceTiedToEvents;			while(i!=0)			{				MSCP_Release(device);				--i;			}			MSCP_Release(device);		}	}}static void MSCP_ContentDirectory_EventSink(char* buffer, int bufferlength, struct UPnPService *service){	struct ILibXMLNode *xml,*rootXML;	char *tempString;	int tempStringLength;	int flg,flg2;		char* ContainerUpdateIDs = 0;	unsigned int SystemUpdateID = 0;	char* TransferIDs = 0;	unsigned long TempULong;		/* Parse SOAP */	rootXML = xml = ILibParseXML(buffer,0,bufferlength);	ILibProcessXMLNodeList(xml);		while(xml!=NULL)	{		if(xml->NameLength==11 && memcmp(xml->Name,"propertyset",11)==0)		{			if(xml->Next->StartTag!=0)			{				flg = 0;				xml = xml->Next;				while(flg==0)				{					if(xml->NameLength==8 && memcmp(xml->Name,"property",8)==0)					{						xml = xml->Next;						flg2 = 0;						while(flg2==0)						{							if(xml->NameLength==18 && memcmp(xml->Name,"ContainerUpdateIDs",18) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								tempString[tempStringLength] = '\0';								ContainerUpdateIDs = tempString;								if(MSCP_EventCallback_ContentDirectory_ContainerUpdateIDs != NULL)								{									MSCP_EventCallback_ContentDirectory_ContainerUpdateIDs(service,ContainerUpdateIDs);								}							}							if(xml->NameLength==14 && memcmp(xml->Name,"SystemUpdateID",14) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)								{									SystemUpdateID = (unsigned int) TempULong;								}								if(MSCP_EventCallback_ContentDirectory_SystemUpdateID != NULL)								{									MSCP_EventCallback_ContentDirectory_SystemUpdateID(service,SystemUpdateID);								}							}							if(xml->NameLength==11 && memcmp(xml->Name,"TransferIDs",11) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								tempString[tempStringLength] = '\0';								TransferIDs = tempString;								if(MSCP_EventCallback_ContentDirectory_TransferIDs != NULL)								{									MSCP_EventCallback_ContentDirectory_TransferIDs(service,TransferIDs);								}							}							if(xml->Peer!=NULL)							{								xml = xml->Peer;							}							else							{								flg2 = -1;								xml = xml->Parent;							}						}					}					if(xml->Peer!=NULL)					{						xml = xml->Peer;					}					else					{						flg = -1;						xml = xml->Parent;					}				}			}		}		xml = xml->Peer;	}		ILibDestructXMLNodeList(rootXML);}static void MSCP_urn_microsoft_com_service_X_MS_MediaReceiverRegistrar_EventSink(char* buffer, int bufferlength, struct UPnPService *service){	struct ILibXMLNode *xml,*rootXML;	char *tempString;	int tempStringLength;	int flg,flg2;		unsigned int AuthorizationDeniedUpdateID = 0;	unsigned int ValidationSucceededUpdateID = 0;	unsigned int ValidationRevokedUpdateID = 0;	unsigned int AuthorizationGrantedUpdateID = 0;	unsigned long TempULong;		/* Parse SOAP */	rootXML = xml = ILibParseXML(buffer,0,bufferlength);	ILibProcessXMLNodeList(xml);		while(xml!=NULL)	{		if(xml->NameLength==11 && memcmp(xml->Name,"propertyset",11)==0)		{			if(xml->Next->StartTag!=0)			{				flg = 0;				xml = xml->Next;				while(flg==0)				{					if(xml->NameLength==8 && memcmp(xml->Name,"property",8)==0)					{						xml = xml->Next;						flg2 = 0;						while(flg2==0)						{							if(xml->NameLength==27 && memcmp(xml->Name,"AuthorizationDeniedUpdateID",27) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)								{									AuthorizationDeniedUpdateID = (unsigned int) TempULong;								}								if(MSCP_EventCallback_Registrar_AuthorizationDeniedUpdateID != NULL)								{									MSCP_EventCallback_Registrar_AuthorizationDeniedUpdateID(service,AuthorizationDeniedUpdateID);								}							}							if(xml->NameLength==27 && memcmp(xml->Name,"ValidationSucceededUpdateID",27) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)								{									ValidationSucceededUpdateID = (unsigned int) TempULong;								}								if(MSCP_EventCallback_Registrar_ValidationSucceededUpdateID != NULL)								{									MSCP_EventCallback_Registrar_ValidationSucceededUpdateID(service,ValidationSucceededUpdateID);								}							}							if(xml->NameLength==25 && memcmp(xml->Name,"ValidationRevokedUpdateID",25) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)								{									ValidationRevokedUpdateID = (unsigned int) TempULong;								}								if(MSCP_EventCallback_Registrar_ValidationRevokedUpdateID != NULL)								{									MSCP_EventCallback_Registrar_ValidationRevokedUpdateID(service,ValidationRevokedUpdateID);								}							}							if(xml->NameLength==28 && memcmp(xml->Name,"AuthorizationGrantedUpdateID",28) == 0)							{								tempStringLength = ILibReadInnerXML(xml,&tempString);								if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)								{									AuthorizationGrantedUpdateID = (unsigned int) TempULong;								}								if(MSCP_EventCallback_Registrar_AuthorizationGrantedUpdateID != NULL)								{									MSCP_EventCallback_Registrar_AuthorizationGrantedUpdateID(service,AuthorizationGrantedUpdateID);								}							}							if(xml->Peer!=NULL)							{								xml = xml->Peer;							}							else							{								flg2 = -1;								xml = xml->Parent;							}						}					}					if(xml->Peer!=NULL)					{						xml = xml->Peer;					}					else					{						flg = -1;						xml = xml->Parent;					}				}			}		}		xml = xml->Peer;	}	

⌨️ 快捷键说明

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