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

📄 mscp_controlpoint.c

📁 intel upnp stack source code
💻 C
📖 第 1 页 / 共 5 页
字号:
				MSCP_DestructUPnPDevice(device);			}		}	}	else	{		if(done!=0 && (header==NULL || header->StatusCode!=200))		{			device = service->Parent;			while(device->Parent!=NULL)			{				device = device->Parent;			}			--device->SCPDLeft;			device->SCPDError=1;			if(device->SCPDLeft==0 && IsInterrupt==0)			{				MSCP_CP_ProcessDeviceRemoval(CP,device);				MSCP_DestructUPnPDevice(device);			}		}	}}static void MSCP_CalculateSCPD_FetchCount(struct UPnPDevice *device){	int count = 0;	struct UPnPDevice *root;	struct UPnPDevice *e_Device = device->EmbeddedDevices;	struct UPnPService *s;		while(e_Device!=NULL)	{		MSCP_CalculateSCPD_FetchCount(e_Device);		e_Device = e_Device->Next;	}		s = device->Services;	while(s!=NULL)	{		++count;		s = s->Next;	}		root = device;	while(root->Parent!=NULL)	{		root = root->Parent;	}	root->SCPDLeft += count;}static void MSCP_SCPD_Fetch(struct UPnPDevice *device){	struct UPnPDevice *e_Device = device->EmbeddedDevices;	struct UPnPService *s;	char *IP,*Path;	unsigned short Port;	struct packetheader *p;	struct sockaddr_in addr;		while(e_Device!=NULL)	{		MSCP_SCPD_Fetch(e_Device);		e_Device = e_Device->Next;	}		s = device->Services;	while(s!=NULL)	{		ILibParseUri(s->SCPDURL,&IP,&Port,&Path);		DEBUGSTATEMENT(printf("SCPD: %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);				ILibWebClient_PipelineRequest(		((struct MSCP_CP*)device->CP)->HTTP,		&addr,		p,		&MSCP_SCPD_Sink,		device,		s);				free(IP);		free(Path);		s = s->Next;	}}char *MSCP_GetCustomTagFromDevice(struct UPnPDevice *d, char* FullNameSpace, char* Name){	if(ILibHasEntry(d->CustomTagTable,FullNameSpace,(int)strlen(FullNameSpace))!=0)	{		return(ILibGetEntry(ILibGetEntry(d->CustomTagTable,FullNameSpace,(int)strlen(FullNameSpace)),Name,(int)strlen(Name)));	}	else	{		return(NULL);	}}static struct UPnPDevice* MSCP_ProcessDeviceXML_device(struct ILibXMLNode *xml, void *v_CP,const char *BaseURL, int Timeout, int RecvAddr){	struct ILibXMLNode *tempNode;	int flg,flg2;	char *tempString;	int tempStringLength;		char *tempString2;		struct parser_result *tpr;		char* ServiceType = NULL;	int ServiceTypeLength = 0;	char* SCPDURL = NULL;	int SCPDURLLength = 0;	char* EventSubURL = NULL;	int EventSubURLLength = 0;	char* ControlURL = NULL;	int ControlURLLength = 0;		struct UPnPDevice *tempDevice;	struct UPnPService *TempService;	struct UPnPDevice *device = (struct UPnPDevice*)malloc(sizeof(struct UPnPDevice));	memset(device,0,sizeof(struct UPnPDevice));		device->CustomTagTable = ILibInitHashTree();			device->CP = v_CP;	device->CacheTime = Timeout;	device->InterfaceToHost = (char*)malloc(16);	sprintf(device->InterfaceToHost,"%d.%d.%d.%d",(RecvAddr&0xFF),((RecvAddr>>8)&0xFF),((RecvAddr>>16)&0xFF),((RecvAddr>>24)&0xFF));		xml = xml->Next;	while(xml!=NULL)	{		if(xml->NameLength==10 && memcmp(xml->Name,"deviceList",10)==0)		{			if(xml->Next->StartTag!=0)			{				xml = xml->Next;				flg2 = 0;				while(flg2==0)				{					if(xml->NameLength==6 && memcmp(xml->Name,"device",6)==0)					{						tempDevice = MSCP_ProcessDeviceXML_device(xml,v_CP,BaseURL,Timeout, RecvAddr);						tempDevice->Parent = device;						tempDevice->Next = device->EmbeddedDevices;						device->EmbeddedDevices = tempDevice;					}					if(xml->Peer==NULL)					{						flg2 = 1;						xml = xml->Parent;					}					else					{						xml = xml->Peer;					}				}			}		} else		if(xml->NameLength==3 && memcmp(xml->Name,"UDN",3)==0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			if(tempStringLength>5)			{				if(memcmp(tempString,"uuid:",5)==0)				{					tempString += 5;					tempStringLength -= 5;				}				device->UDN = (char*)malloc(tempStringLength+1);				memcpy(device->UDN,tempString,tempStringLength);				device->UDN[tempStringLength] = '\0';			}		} else		if(xml->NameLength==10 && memcmp(xml->Name,"deviceType",10) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);						device->DeviceType = (char*)malloc(tempStringLength+1);			memcpy(device->DeviceType,tempString,tempStringLength);			device->DeviceType[tempStringLength] = '\0';		} else		if(xml->NameLength==12 && memcmp(xml->Name,"friendlyName",12) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->FriendlyName = (char*)malloc(1+tempStringLength);			memcpy(device->FriendlyName,tempString,tempStringLength);			device->FriendlyName[tempStringLength] = '\0';		} else		if(xml->NameLength==12 && memcmp(xml->Name,"manufacturer",12) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ManufacturerName = (char*)malloc(1+tempStringLength);			memcpy(device->ManufacturerName,tempString,tempStringLength);			device->ManufacturerName[tempStringLength] = '\0';		} else		if(xml->NameLength==15 && memcmp(xml->Name,"manufacturerURL",15) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ManufacturerURL = (char*)malloc(1+tempStringLength);			memcpy(device->ManufacturerURL,tempString,tempStringLength);			device->ManufacturerURL[tempStringLength] = '\0';		} else		if(xml->NameLength==16 && memcmp(xml->Name,"modelDescription",16) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ModelDescription = (char*)malloc(1+tempStringLength);			memcpy(device->ModelDescription,tempString,tempStringLength);			device->ModelDescription[tempStringLength] = '\0';		} else		if(xml->NameLength==9 && memcmp(xml->Name,"modelName",9) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ModelName = (char*)malloc(1+tempStringLength);			memcpy(device->ModelName,tempString,tempStringLength);			device->ModelName[tempStringLength] = '\0';		} else		if(xml->NameLength==11 && memcmp(xml->Name,"modelNumber",11) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ModelNumber = (char*)malloc(1+tempStringLength);			memcpy(device->ModelNumber,tempString,tempStringLength);			device->ModelNumber[tempStringLength] = '\0';		} else		if(xml->NameLength==8 && memcmp(xml->Name,"modelURL",8) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			device->ModelURL = (char*)malloc(1+tempStringLength);			memcpy(device->ModelURL,tempString,tempStringLength);			device->ModelURL[tempStringLength] = '\0';		} else		if(xml->NameLength==15 && memcmp(xml->Name,"presentationURL",15) == 0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			tempString[tempStringLength] = 0;			tpr = ILibParseString(tempString,0,tempStringLength,"://",3);			if(tpr->NumResults==1)			{				/* RelativeURL */				if(tempString[0]=='/')				{					device->PresentationURL = (char*)malloc(1+strlen(BaseURL)+tempStringLength);					memcpy(device->PresentationURL,BaseURL,strlen(BaseURL));					strcpy(device->PresentationURL+strlen(BaseURL),tempString+1);				}				else				{					device->PresentationURL = (char*)malloc(2+strlen(BaseURL)+tempStringLength);					memcpy(device->PresentationURL,BaseURL,strlen(BaseURL));					strcpy(device->PresentationURL+strlen(BaseURL),tempString);				}			}			else			{				/* AbsoluteURL */				device->PresentationURL = (char*)malloc(1+tempStringLength);				memcpy(device->PresentationURL,tempString,tempStringLength);				device->PresentationURL[tempStringLength] = '\0';			}			ILibDestructParserResults(tpr);		} else		if(xml->NameLength==9 && memcmp(xml->Name,"X_DLNADOC",9)==0)		{			tempString = ILibXML_LookupNamespace(xml,xml->NSTag,xml->NSLength);			if(strcmp(tempString,"urn:schemas-dlna-org:device-1-0")==0)			{				tempStringLength = ILibReadInnerXML(xml,&tempString);				tempString2 = (char*)malloc(tempStringLength+1);				memcpy(tempString2,tempString,tempStringLength);				tempString2[tempStringLength]=0;				if(ILibGetEntry(device->CustomTagTable,"urn:schemas-dlna-org:device-1-0",31)==NULL)				{					ILibAddEntry(device->CustomTagTable,"urn:schemas-dlna-org:device-1-0",31,ILibInitHashTree());				}				ILibAddEntry(ILibGetEntry(device->CustomTagTable,"urn:schemas-dlna-org:device-1-0",31),xml->Name,xml->NameLength,tempString2);			}		} 		else				if(xml->NameLength==11 && memcmp(xml->Name,"serviceList",11)==0)		{			tempNode = xml;			xml = xml->Next;			while(xml!=NULL)			{				if(xml->NameLength==7 && memcmp(xml->Name,"service",7)==0)				{					ServiceType = NULL;					ServiceTypeLength = 0;					SCPDURL = NULL;					SCPDURLLength = 0;					EventSubURL = NULL;					EventSubURLLength = 0;					ControlURL = NULL;					ControlURLLength = 0;										xml = xml->Next;					flg = 0;					while(flg==0)					{						if(xml->NameLength==11 && memcmp(xml->Name,"serviceType",11)==0)						{							ServiceTypeLength = ILibReadInnerXML(xml,&ServiceType);						} else						if(xml->NameLength==7 && memcmp(xml->Name,"SCPDURL",7) == 0)						{							SCPDURLLength = ILibReadInnerXML(xml,&SCPDURL);						} else						if(xml->NameLength==10 && memcmp(xml->Name,"controlURL",10) == 0)						{							ControlURLLength = ILibReadInnerXML(xml,&ControlURL);						} else						if(xml->NameLength==11 && memcmp(xml->Name,"eventSubURL",11) == 0)						{							EventSubURLLength = ILibReadInnerXML(xml,&EventSubURL);						}												if(xml->Peer!=NULL)						{							xml = xml->Peer;						}						else						{							flg = 1;							xml = xml->Parent;						}					}										/* Finished Parsing the ServiceSection, build the Service */					ServiceType[ServiceTypeLength] = '\0';					SCPDURL[SCPDURLLength] = '\0';					EventSubURL[EventSubURLLength] = '\0';					ControlURL[ControlURLLength] = '\0';										TempService = (struct UPnPService*)malloc(sizeof(struct UPnPService));					TempService->SubscriptionID = NULL;					TempService->ServiceId = NULL;					TempService->Actions = NULL;					TempService->Variables = NULL;					TempService->Next = NULL;					TempService->Parent = device;					if(EventSubURLLength>=7 && memcmp(EventSubURL,"http://",6)==0)					{						/* Explicit */						TempService->SubscriptionURL = (char*)malloc(EventSubURLLength+1);						memcpy(TempService->SubscriptionURL,EventSubURL,EventSubURLLength);						TempService->SubscriptionURL[EventSubURLLength] = '\0';					}					else					{						/* Relative */						if(memcmp(EventSubURL,"/",1)!=0)						{							TempService->SubscriptionURL = (char*)malloc(EventSubURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->SubscriptionURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->SubscriptionURL+(int)strlen(BaseURL),EventSubURL,EventSubURLLength);							TempService->SubscriptionURL[EventSubURLLength+(int)strlen(BaseURL)] = '\0';						}						else						{							TempService->SubscriptionURL = (char*)malloc(EventSubURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->SubscriptionURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->SubscriptionURL+(int)strlen(BaseURL),EventSubURL+1,EventSubURLLength-1);							TempService->SubscriptionURL[EventSubURLLength+(int)strlen(BaseURL)-1] = '\0';						}					}					if(ControlURLLength>=7 && memcmp(ControlURL,"http://",6)==0)					{						/* Explicit */						TempService->ControlURL = (char*)malloc(ControlURLLength+1);						memcpy(TempService->ControlURL,ControlURL,ControlURLLength);						TempService->ControlURL[ControlURLLength] = '\0';					}					else					{						/* Relative */						if(memcmp(ControlURL,"/",1)!=0)						{							TempService->ControlURL = (char*)malloc(ControlURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->ControlURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->ControlURL+(int)strlen(BaseURL),ControlURL,ControlURLLength);							TempService->ControlURL[ControlURLLength+(int)strlen(BaseURL)] = '\0';						}						else						{							TempService->ControlURL = (char*)malloc(ControlURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->ControlURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->ControlURL+(int)strlen(BaseURL),ControlURL+1,ControlURLLength-1);							TempService->ControlURL[ControlURLLength+(int)strlen(BaseURL)-1] = '\0';						}					}					if(SCPDURLLength>=7 && memcmp(SCPDURL,"http://",6)==0)					{						/* Explicit */						TempService->SCPDURL = (char*)malloc(SCPDURLLength+1);						memcpy(TempService->SCPDURL,SCPDURL,SCPDURLLength);						TempService->SCPDURL[SCPDURLLength] = '\0';					}					else					{						/* Relative */						if(memcmp(SCPDURL,"/",1)!=0)						{							TempService->SCPDURL = (char*)malloc(SCPDURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->SCPDURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->SCPDURL+(int)strlen(BaseURL),SCPDURL,SCPDURLLength);							TempService->SCPDURL[SCPDURLLength+(int)strlen(BaseURL)] = '\0';						}						else						{							TempService->SCPDURL = (char*)malloc(SCPDURLLength+(int)strlen(BaseURL)+1);							memcpy(TempService->SCPDURL,BaseURL,(int)strlen(BaseURL));							memcpy(TempService->SCPDURL+(int)strlen(BaseURL),SCPDURL+1,SCPDURLLength-1);							TempService->SCPDURL[SCPDURLLength+(int)strlen(BaseURL)-1] = '\0';						}					}										TempService->ServiceType = (char*)malloc(ServiceTypeLength+1);					sprintf(TempService->ServiceType,ServiceType,ServiceTypeLength);					TempService->Next = device->Services;					device->Services = TempService;										DEBUGSTATEMENT(printf("ServiceType: %s\r\nSCPDURL: %s\r\nEventSubURL: %s\r\nControl URL: %s\r\n",ServiceType,SCPDURL,EventSubURL,ControlURL));				}				xml = xml->Peer;			}			xml = tempNode;		} // End of ServiceList		xml = xml->Peer;	} // End of While		return(device);}static void MSCP_ProcessDeviceXML(void *v_CP,char* buffer, int BufferSize, char* LocationURL, int RecvAddr, int Timeout){	struct UPnPDevice *RootDevice = NULL;		char* IP;	unsigned short Port;	char* Path;		char* BaseURL = NULL;		struct ILibXMLNode *rootXML;	struct ILibXMLNode *xml;	char* tempString;	int tempStringLength;	if (BufferSize == 0)		return;		rootXML = ILibParseXML(buffer,0,BufferSize);	ILibProcessXMLNodeList(rootXML);	ILibXML_BuildNamespaceLookupTable(rootXML);		xml = rootXML;	xml = xml->Next;	while(xml!=NULL)	{		if(xml->NameLength==7 && memcmp(xml->Name,"URLBase",7)==0)		{			tempStringLength = ILibReadInnerXML(xml,&tempString);			if(tempString[tempStringLength-1]!='/')			{				BaseURL = (char*)malloc(2+tempStringLength);				memcpy(BaseURL,tempString,tempStringLength);				BaseURL[tempStringLength] = '/';				BaseURL[tempStringLength+1] = '\0';			}			else			{				BaseURL = (char*)malloc(1+tempStringLength);				memcpy(BaseURL,tempString,tempStringLength);				BaseURL[tempStringLength] = '\0';			}			break;

⌨️ 快捷键说明

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