📄 mscp_controlpoint.c
字号:
printf(" Action: %s\r\n",a->Name); a = a->Next; } s = s->Next; } d = device->EmbeddedDevices; while(d!=NULL) { MSCP_PrintUPnPDevice(indents+5,d); d = d->Next; }}struct UPnPService *MSCP_GetService(struct UPnPDevice *device, char* ServiceName, int length){ struct UPnPService *RetService = NULL; struct UPnPService *s = device->Services; struct parser_result *pr,*pr2; pr = ILibParseString(ServiceName,0,length,":",1); while(s!=NULL) { pr2 = ILibParseString(s->ServiceType,0,(int)strlen(s->ServiceType),":",1); if(length-pr->LastResult->datalength >= (int)strlen(s->ServiceType)-pr2->LastResult->datalength && memcmp(ServiceName,s->ServiceType,length-pr->LastResult->datalength)==0) { if(atoi(pr->LastResult->data)<=atoi(pr2->LastResult->data)) { RetService = s; ILibDestructParserResults(pr2); break; } } ILibDestructParserResults(pr2); s = s->Next; } ILibDestructParserResults(pr); return(RetService);}struct UPnPService *MSCP_GetService_ContentDirectory(struct UPnPDevice *device){ return(MSCP_GetService(device,"urn:schemas-upnp-org:service:ContentDirectory:1",47));}struct UPnPService *MSCP_GetService_Registrar(struct UPnPDevice *device){ return(MSCP_GetService(device,"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1",55));}static struct UPnPDevice *MSCP_GetDevice2(struct UPnPDevice *device, int index, int *c_Index){ struct UPnPDevice *RetVal = NULL; struct UPnPDevice *e_Device = NULL; int currentIndex = *c_Index; if(strncmp(device->DeviceType,"urn:schemas-upnp-org:device:MediaServer:",40)==0 && atoi(device->DeviceType+40)>=1) { ++currentIndex; if(currentIndex==index) { *c_Index = currentIndex; return(device); } } e_Device = device->EmbeddedDevices; while(e_Device!=NULL) { RetVal = MSCP_GetDevice2(e_Device,index,¤tIndex); if(RetVal!=NULL) { break; } e_Device = e_Device->Next; } *c_Index = currentIndex; return(RetVal);}struct UPnPDevice* MSCP_GetDevice1(struct UPnPDevice *device,int index){ int c_Index = -1; return(MSCP_GetDevice2(device,index,&c_Index));}int MSCP_GetDeviceCount(struct UPnPDevice *device){ int RetVal = 0; struct UPnPDevice *e_Device = device->EmbeddedDevices; while(e_Device!=NULL) { RetVal += MSCP_GetDeviceCount(e_Device); e_Device = e_Device->Next; } if(strncmp(device->DeviceType,"urn:schemas-upnp-org:device:MediaServer:1",41)==0) { ++RetVal; } return(RetVal);}static int MSCP_GetErrorCode(char *buffer, int length){ int RetVal = 500; struct ILibXMLNode *xml,*rootXML; char *temp; int tempLength; rootXML = xml = ILibParseXML(buffer,0,length); ILibProcessXMLNodeList(xml); while(xml!=NULL) { if(xml->NameLength==8 && memcmp(xml->Name,"Envelope",8)==0) { xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==4 && memcmp(xml->Name,"Body",4)==0) { xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==5 && memcmp(xml->Name,"Fault",5)==0) { xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==6 && memcmp(xml->Name,"detail",6)==0) { xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==9 && memcmp(xml->Name,"MSCP_Error",9)==0) { xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==9 && memcmp(xml->Name,"errorCode",9)==0) { tempLength = ILibReadInnerXML(xml,&temp); temp[tempLength] = 0; RetVal =atoi(temp); xml = NULL; } if(xml!=NULL) {xml = xml->Peer;} } } if(xml!=NULL) {xml = xml->Peer;} } } if(xml!=NULL) {xml = xml->Peer;} } } if(xml!=NULL) {xml = xml->Peer;} } } if(xml!=NULL) {xml = xml->Peer;} } } if(xml!=NULL) {xml = xml->Peer;} } ILibDestructXMLNodeList(rootXML); return(RetVal);}static void MSCP_ProcessSCPD(char* buffer, int length, struct UPnPService *service){ struct UPnPAction *action; struct UPnPStateVariable *sv = NULL; struct UPnPAllowedValue *av = NULL; struct UPnPAllowedValue *avs = NULL; struct ILibXMLNode *xml,*rootXML; int flg2,flg3,flg4; char* tempString; int tempStringLength; struct UPnPDevice *root = service->Parent; while(root->Parent!=NULL) {root = root->Parent;} rootXML = xml = ILibParseXML(buffer,0,length); if(ILibProcessXMLNodeList(xml)!=0) { root->SCPDError=UPNP_ERROR_SCPD_NOT_WELL_FORMED; ILibDestructXMLNodeList(rootXML); return; } while(xml!=NULL && strncmp(xml->Name,"!",1)==0) { xml = xml->Next; } xml = xml->Next; while(xml!=NULL) { if(xml->NameLength==10 && memcmp(xml->Name,"actionList",10)==0) { xml = xml->Next; flg2 = 0; while(flg2==0) { if(xml->NameLength==6 && memcmp(xml->Name,"action",6)==0) { action = (struct UPnPAction*)malloc(sizeof(struct UPnPAction)); action->Name = NULL; action->Next = service->Actions; service->Actions = action; xml = xml->Next; flg3 = 0; while(flg3==0) { if(xml->NameLength==4 && memcmp(xml->Name,"name",4)==0) { tempStringLength = ILibReadInnerXML(xml,&tempString); action->Name = (char*)malloc(1+tempStringLength); memcpy(action->Name,tempString,tempStringLength); action->Name[tempStringLength] = '\0'; } if(xml->Peer==NULL) { flg3 = -1; xml = xml->Parent; } else { xml = xml->Peer; } } } if(xml->Peer==NULL) { flg2 = -1; xml = xml->Parent; } else { xml = xml->Peer; } } } if(xml->NameLength==17 && memcmp(xml->Name,"serviceStateTable",17)==0) { if(xml->Next->StartTag!=0) { xml = xml->Next; flg2 = 0; while(flg2==0) { if(xml->NameLength==13 && memcmp(xml->Name,"stateVariable",13)==0) { sv = (struct UPnPStateVariable*)malloc(sizeof(struct UPnPStateVariable)); sv->AllowedValues = NULL; sv->NumAllowedValues = 0; sv->Max = NULL; sv->Min = NULL; sv->Step = NULL; sv->Name = NULL; sv->Next = service->Variables; service->Variables = sv; sv->Parent = service; xml = xml->Next; flg3 = 0; while(flg3==0) { if(xml->NameLength==4 && memcmp(xml->Name,"name",4)==0) { tempStringLength = ILibReadInnerXML(xml,&tempString); sv->Name = (char*)malloc(1+tempStringLength); memcpy(sv->Name,tempString,tempStringLength); sv->Name[tempStringLength] = '\0'; } if(xml->NameLength==16 && memcmp(xml->Name,"allowedValueList",16)==0) { if(xml->Next->StartTag!=0) { avs = NULL; xml = xml->Next; flg4 = 0; while(flg4==0) { if(xml->NameLength==12 && memcmp(xml->Name,"allowedValue",12)==0) { av = (struct UPnPAllowedValue*)malloc(sizeof(struct UPnPAllowedValue)); av->Next = avs; avs = av; tempStringLength = ILibReadInnerXML(xml,&tempString); av->Value = (char*)malloc(1+tempStringLength); memcpy(av->Value,tempString,tempStringLength); av->Value[tempStringLength] = '\0'; } if(xml->Peer!=NULL) { xml = xml->Peer; } else { xml = xml->Parent; flg4 = -1; } } av = avs; while(av!=NULL) { ++sv->NumAllowedValues; av = av->Next; } av = avs; sv->AllowedValues = (char**)malloc(sv->NumAllowedValues*sizeof(char*)); for(flg4=0;flg4<sv->NumAllowedValues;++flg4) { sv->AllowedValues[flg4] = av->Value; av = av->Next; } av = avs; while(av!=NULL) { avs = av->Next; free(av); av = avs; } } } if(xml->NameLength==17 && memcmp(xml->Name,"allowedValueRange",17)==0) { if(xml->Next->StartTag!=0) { xml = xml->Next; flg4 = 0; while(flg4==0) { if(xml->NameLength==7) { if(memcmp(xml->Name,"minimum",7)==0) { tempStringLength = ILibReadInnerXML(xml,&tempString); sv->Min = (char*)malloc(1+tempStringLength); memcpy(sv->Min,tempString,tempStringLength); sv->Min[tempStringLength] = '\0'; } else if(memcmp(xml->Name,"maximum",7)==0) { tempStringLength = ILibReadInnerXML(xml,&tempString); sv->Max = (char*)malloc(1+tempStringLength); memcpy(sv->Max,tempString,tempStringLength); sv->Max[tempStringLength] = '\0'; } } if(xml->NameLength==4 && memcmp(xml->Name,"step",4)==0) { tempStringLength = ILibReadInnerXML(xml,&tempString); sv->Step = (char*)malloc(1+tempStringLength); memcpy(sv->Step,tempString,tempStringLength); sv->Step[tempStringLength] = '\0'; } if(xml->Peer!=NULL) { xml = xml->Peer; } else { xml = xml->Parent; flg4 = -1; } } } } if(xml->Peer!=NULL) { xml = xml->Peer; } else { flg3 = -1; xml = xml->Parent; } } } if(xml->Peer!=NULL) { xml = xml->Peer; } else { xml = xml->Parent; flg2 = -1; } } } } xml = xml->Peer; } ILibDestructXMLNodeList(rootXML);}static void MSCP_InterfaceChanged(struct UPnPDevice *device){ void *cp = device->CP; char *UDN; char *LocationURL; int Timeout; Timeout = device->CacheTime; UDN = (char*)malloc((int)strlen(device->UDN)+1); strcpy(UDN,device->UDN); LocationURL = device->Reserved3; device->Reserved3 = NULL; MSCP_SSDP_Sink(NULL, device->UDN, 0, NULL, 0,UPnPSSDP_NOTIFY,device->CP); MSCP_SSDP_Sink(NULL, UDN, -1, LocationURL, Timeout, UPnPSSDP_NOTIFY,cp); free(UDN); free(LocationURL);}static void MSCP_ExpiredDevice(struct UPnPDevice *device){ LVL3DEBUG(printf("Device[%s] failed to re-advertise in a timely manner\r\n",device->FriendlyName);) while(device->Parent!=NULL) {device = device->Parent;} MSCP_SSDP_Sink(NULL, device->UDN, 0, NULL, 0,UPnPSSDP_NOTIFY,device->CP);}static void MSCP_FinishProcessingDevice(struct MSCP_CP* CP, struct UPnPDevice *RootDevice){ int Timeout = RootDevice->CacheTime; struct UPnPDevice *RetDevice; int i=0; RootDevice->ReferenceCount = 1; do { RetDevice = MSCP_GetDevice1(RootDevice,i++); if(RetDevice!=NULL) { RetDevice->Reserved=1; MSCP_AddRef(RetDevice); if(CP->DiscoverSink!=NULL) { CP->DiscoverSink(RetDevice); } } }while(RetDevice!=NULL); ILibLifeTime_Add(CP->LifeTimeMonitor,RootDevice,Timeout,&MSCP_ExpiredDevice,NULL);}static void MSCP_SCPD_Sink(void *WebReaderToken,int IsInterrupt,struct packetheader *header,char *buffer,int *p_BeginPointer,int EndPointer,int done,void *dv,void *sv,int *PAUSE){ struct UPnPDevice *device; struct UPnPService *service = (struct UPnPService*)sv; struct MSCP_CP *CP = service->Parent->CP; if(!(header==NULL || header->StatusCode!=200) && done!=0) { MSCP_ProcessSCPD(buffer,EndPointer, service); device = service->Parent; while(device->Parent!=NULL) { device = device->Parent; } --device->SCPDLeft; if(device->SCPDLeft==0) { if(device->SCPDError==0) { MSCP_FinishProcessingDevice(CP,device); } else if(IsInterrupt==0) { MSCP_CP_ProcessDeviceRemoval(CP,device);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -