📄 mmscp.c
字号:
/*********************************************************************************************************************** * BEGIN: UPnP Callback Sinks * These methods are callback sinks that are wired to the underlying UPNP stack. ***********************************************************************************************************************/#ifndef MMSCP_LEAN_AND_MEANvoid MMSCP_ProcessResponse_GetCurrentConnectionInfo(struct UPnPService* Service,int ErrorCode,void *User,int RcsID,int AVTransportID,char* ProtocolInfo,char* PeerConnectionManager,int PeerConnectionID,char* Direction,char* Status){ printf("MSCP Invoke Response: ConnectionManager/GetCurrentConnectionInfo(%d,%d,%s,%s,%d,%s,%s)\r\n",RcsID,AVTransportID,ProtocolInfo,PeerConnectionManager,PeerConnectionID,Direction,Status); UNSUPPORTED_BY_CP;}void MMSCP_ProcessResponse_GetProtocolInfo(struct UPnPService* Service,int ErrorCode,void *User,char* Source,char* Sink){ printf("MSCP Invoke Response: ConnectionManager/GetProtocolInfo(%s,%s)\r\n",Source,Sink); UNSUPPORTED_BY_CP;}void MMSCP_ProcessResponse_GetCurrentConnectionIDs(struct UPnPService* Service,int ErrorCode,void *User,char* ConnectionIDs){ printf("MSCP Invoke Response: ConnectionManager/GetCurrentConnectionIDs(%s)\r\n",ConnectionIDs); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_ExportResource(struct UPnPService* Service,int ErrorCode,void *User,unsigned int TransferID){ printf("MSCP Invoke Response: ContentDirectory/ExportResource(%u)\r\n",TransferID); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_StopTransferResource(struct UPnPService* Service,int ErrorCode,void *User){ printf("MSCP Invoke Response: ContentDirectory/StopTransferResource()\r\n"); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_DestroyObject(struct UPnPService* Service,int ErrorCode,void *User){ printf("MSCP Invoke Response: ContentDirectory/DestroyObject()\r\n"); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_UpdateObject(struct UPnPService* Service,int ErrorCode,void *User){ printf("MSCP Invoke Response: ContentDirectory/UpdateObject()\r\n"); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_GetSystemUpdateID(struct UPnPService* Service,int ErrorCode,void *User,unsigned int Id){ printf("MSCP Invoke Response: ContentDirectory/GetSystemUpdateID(%u)\r\n",Id); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_GetTransferProgress(struct UPnPService* Service,int ErrorCode,void *User,char* TransferStatus,char* TransferLength,char* TransferTotal){ printf("MSCP Invoke Response: ContentDirectory/GetTransferProgress(%s,%s,%s)\r\n",TransferStatus,TransferLength,TransferTotal); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_GetSortCapabilities(struct UPnPService* Service,int ErrorCode,void *User,char* SortCaps){ printf("MSCP Invoke Response: ContentDirectory/GetSortCapabilities(%s)\r\n",SortCaps); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_GetSearchCapabilities(struct UPnPService* Service,int ErrorCode,void *User,char* SearchCaps){ printf("MSCP Invoke Response: ContentDirectory/GetSearchCapabilities(%s)\r\n",SearchCaps); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_CreateObject(struct UPnPService* Service,int ErrorCode,void *User,char* ObjectID,char* Result){ printf("MSCP Invoke Response: ContentDirectory/CreateObject(%s,%s)\r\n",ObjectID,Result); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_Search(struct UPnPService* Service,int ErrorCode,void *User,char* Result,unsigned int NumberReturned,unsigned int TotalMatches,unsigned int UpdateID){ printf("MSCP Invoke Response: ContentDirectory/Search(%s,%u,%u,%u)\r\n",Result,NumberReturned,TotalMatches,UpdateID); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_ImportResource(struct UPnPService* Service,int ErrorCode,void *User,unsigned int TransferID){ printf("MSCP Invoke Response: ContentDirectory/ImportResource(%u)\r\n",TransferID); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_CreateReference(struct UPnPService* Service,int ErrorCode,void *User,char* NewID){ printf("MSCP Invoke Response: ContentDirectory/CreateReference(%s)\r\n",NewID); UNSUPPORTED_BY_CP;}void MSCPResponseSink_ContentDirectory_DeleteResource(struct UPnPService* Service,int ErrorCode,void *User){ printf("MSCP Invoke Response: ContentDirectory/DeleteResource()\r\n"); UNSUPPORTED_BY_CP;}void MMSCPEventSink_ConnectionManager_SourceProtocolInfo(struct UPnPService* Service,char* SourceProtocolInfo){ printf("MSCP Event from %s/ConnectionManager/SourceProtocolInfo: %s\r\n",Service->Parent->FriendlyName,SourceProtocolInfo); UNSUPPORTED_BY_CP;}void MMSCPEventSink_ConnectionManager_SinkProtocolInfo(struct UPnPService* Service,char* SinkProtocolInfo){ printf("MSCP Event from %s/ConnectionManager/SinkProtocolInfo: %s\r\n",Service->Parent->FriendlyName,SinkProtocolInfo); UNSUPPORTED_BY_CP;}void MMSCPEventSink_ConnectionManager_CurrentConnectionIDs(struct UPnPService* Service,char* CurrentConnectionIDs){ printf("MSCP Event from %s/ConnectionManager/CurrentConnectionIDs: %s\r\n",Service->Parent->FriendlyName,CurrentConnectionIDs); UNSUPPORTED_BY_CP;}void MMSCPEventSink_ContentDirectory_TransferIDs(struct UPnPService* Service,char* TransferIDs){ printf("MSCP Event from %s/ContentDirectory/TransferIDs: %s\r\n",Service->Parent->FriendlyName,TransferIDs); UNSUPPORTED_BY_CP;}#endifstatic void MMSCP_AddRefRootDevice(struct UPnPService* Service){ struct UPnPDevice *d = Service->Parent; //char str[1024]; //sprintf(str, "RF+: %s(%d)\r\n", d->UDN, d->ReferenceCount); //OutputDebugString(str); MSCP_AddRef(d);}static void MMSCP_ReleaseRootDevice(struct UPnPService* Service){ struct UPnPDevice *d = Service->Parent; //char str[1024]; //sprintf(str, "RF-: %s(%d)\r\n", d->UDN, d->ReferenceCount); //OutputDebugString(str); MSCP_Release(d);}static void MSCPResponseSink_ContentDirectory_Browse(struct UPnPService* Service,int ErrorCode,void *User,char* Result,unsigned int NumberReturned,unsigned int TotalMatches,unsigned int UpdateID){ struct ILibXMLNode* nodeList; struct ILibXMLNode* node; struct MMSCP_ResultsList *resultsList; struct ILibXMLAttribute *attribs; int resultLen; int parsePeerResult = 0; char *lastResultPos; struct MMSCP_MediaObject *newObj; TEMPDEBUGONLY(printf("MSCP Invoke Response: ContentDirectory/Browse(%s,%u,%u,%u)\r\n",Result,NumberReturned,TotalMatches,UpdateID);) if ((ErrorCode == 0) && (Result != NULL)) { newObj = NULL; resultLen = ILibInPlaceXmlUnEscape(Result); resultsList = (struct MMSCP_ResultsList*) MMSCP_MALLOC (sizeof(struct MMSCP_ResultsList)); memset(resultsList, 0, sizeof(struct MMSCP_ResultsList)); resultsList->LinkedList = ILibLinkedList_Create(); lastResultPos = Result + resultLen; nodeList = ILibParseXML(Result, 0, resultLen); parsePeerResult = ILibProcessXMLNodeList(nodeList); if (parsePeerResult != 0) { MMSCP_Callback_Browse(Service, User, (int)MMSC_Error_XmlNotWellFormed, NULL); } else if (resultLen == 0) { MMSCP_Callback_Browse(Service, User, ErrorCode, NULL); } else { node = nodeList; while (node != NULL) { if (node->StartTag != 0) { /*[DONOTREPARSE] null terminate string */ attribs = ILibGetXMLAttributes(node); node->Name[node->NameLength] = '\0'; newObj = NULL; if (stricmp(node->Name, MMSCP_TAG_CONTAINER) == 0) { newObj = MMSCP_CreateMediaObject(node, attribs, 0, Result, lastResultPos); node = node->Next; } else if (stricmp(node->Name, MMSCP_TAG_ITEM) == 0) { newObj = MMSCP_CreateMediaObject(node, attribs, 1, Result, lastResultPos); node = node->Next; } else if (stricmp(node->Name, MMSCP_TAG_DIDL) == 0) { /* this is didl-lite root node, go to first child */ node = node->Next; } else { /* this node is not supported, go to next sibling/peer */ if (node->Peer != NULL) { node = node->Peer; } else { node = node->Parent->Peer; } } if (newObj != NULL) { /* set reminder of which CDS provided this object */ MMSCP_AddRefRootDevice(Service); newObj->ServiceObject = Service; if (resultsList->LinkedList != NULL) { MMSCP_ObjRef_Add(newObj); ILibLinkedList_AddTail(resultsList->LinkedList, newObj); } } /* free attribute mappings */ ILibDestructXMLAttributeList(attribs); } else { node = node->Next; } } } resultsList->NumberReturned = NumberReturned; resultsList->TotalMatches = TotalMatches; resultsList->UpdateID = UpdateID; /* validate number of parsed objects against returned count */ resultsList->NumberParsed = ILibLinkedList_GetCount(resultsList->LinkedList); if ((int)resultsList->NumberParsed != (int)resultsList->NumberReturned) { printf("MSCPResponseSink_ContentDirectory_Browse: Detected mismatch with number of objects returned=%u and parsed=%d.\r\n", resultsList->NumberReturned, resultsList->NumberParsed); } /* free resources from XML parsing */ ILibDestructXMLNodeList(nodeList); /* execute callback with results */ MMSCP_Callback_Browse(Service, User, ErrorCode, resultsList); } else { MMSCP_Callback_Browse(Service, User, ErrorCode, NULL); }}static void MMSCPEventSink_ContentDirectory_ContainerUpdateIDs(struct UPnPService* Service,char* ContainerUpdateIDs){ printf("MSCP Event from %s/ContentDirectory/ContainerUpdateIDs: %s\r\n",Service->Parent->FriendlyName,ContainerUpdateIDs); UNSUPPORTED_BY_CP;}static void MMSCPEventSink_ContentDirectory_SystemUpdateID(struct UPnPService* Service,unsigned int SystemUpdateID){ printf("MSCP Event from %s/ContentDirectory/SystemUpdateID: %u\r\n",Service->Parent->FriendlyName,SystemUpdateID); UNSUPPORTED_BY_CP;}/* Called whenever a new device on the correct type is discovered */static void MMSCP_UPnPSink_DeviceAdd(struct UPnPDevice *device){ /* #### Begin CARDEA code #### */ struct UPnPService *service; /* #### End CARDEA code #### */ printf("MSCP Device Added: %s\r\n", device->FriendlyName); if (MMSCP_Callback_DeviceAddRemove != NULL) { MMSCP_Callback_DeviceAddRemove(device, MMSCP_DEVICE_ADDED); } /* #### Begin CARDEA code #### */ service = MSCP_GetService_Registrar(device); if (service == NULL){ /* Not WMC capable */ device->ms_upnp = NULL; } else { /* WMC capable subscribe to events */ device->ms_upnp = new_ms_device(device->FriendlyName, (void *)device); MSCP_SubscribeForUPnPEvents(service, NULL); } /* #### End CARDEA code #### */}/* Called whenever a discovered device was removed from the network */static void MMSCP_UPnPSink_DeviceRemove(struct UPnPDevice *device){ printf("MSCP Device Removed: %s\r\n", device->FriendlyName); /* #### Begin CARDEA code #### */ if (device->ms_upnp){ /* Destroy WMC extension */ destroy_ms_device(device->ms_upnp); } /* #### End CARDEA code #### */ if (MMSCP_Callback_DeviceAddRemove != NULL) { MMSCP_Callback_DeviceAddRemove(device, MMSCP_DEVICE_REMOVED); }}/*********************************************************************************************************************** * END: UPnP Callback Sinks ***********************************************************************************************************************//*********************************************************************************************************************** * BEGIN: API method implementations ***********************************************************************************************************************/void MMSCP_DestroyResultsList (struct MMSCP_ResultsList *resultsList){ void *h; struct MMSCP_MediaObject *obj; if ((resultsList != NULL) && (resultsList->LinkedList)) { ILibLinkedList_Lock(resultsList->LinkedList); h = ILibLinkedList_GetNode_Head(resultsList->LinkedList); while (h != NULL) { obj = (struct MMSCP_MediaObject*) ILibLinkedList_GetDataFromNode(h); if (obj != NULL) { MMSCP_ObjRef_Release(obj); } ILibLinkedList_Remove(h); h = ILibLinkedList_GetNode_Head(resultsList->LinkedList); } ILibLinkedList_UnLock(resultsList->LinkedList); ILibLinkedList_Destroy(resultsList->LinkedList); MMSCP_FREE (resultsList); }}void *MMSCP_Init(void *chain, MMSCP_Fn_Result_Browse callbackBrowse, MMSCP_Fn_Device_AddRemove callbackDeviceAddRemove){ MMSCP_Callback_Browse = callbackBrowse; MMSCP_Callback_DeviceAddRemove = callbackDeviceAddRemove; /* Event callback function registration code */#ifndef MMSCP_LEAN_AND_MEAN /* These require that the generated stack monitors and reports these state variables. */ /* TODO: Provide a BrowseOnly DeviceBuilder settings file that provides these other state variables. */ MSCP_EventCallback_ConnectionManager_SourceProtocolInfo=&MMSCPEventSink_ConnectionManager_SourceProtocolInfo; MSCP_EventCallback_ConnectionManager_SinkProtocolInfo=&MMSCPEventSink_ConnectionManager_SinkProtocolInfo; MSCP_EventCallback_ConnectionManager_CurrentConnectionIDs=&MMSCPEventSink_ConnectionManager_CurrentConnectionIDs; MSCP_EventCallback_ContentDirectory_TransferIDs=&MMSCPEventSink_ContentDirectory_TransferIDs;#endif MSCP_EventCallback_ContentDirectory_ContainerUpdateIDs=&MMSCPEventSink_ContentDirectory_ContainerUpdateIDs; MSCP_EventCallback_ContentDirectory_SystemUpdateID=&MMSCPEventSink_ContentDirectory_SystemUpdateID; /* create the underlying UPnP control point stack */ return MSCP_CreateControlPoint(chain, &MMSCP_UPnPSink_DeviceAdd, &MMSCP_UPnPSink_DeviceRemove);}void MMSCP_Invoke_Browse(void *serviceObj, struct MMSCP_BrowseArgs *args){ char *browseFlagString; if (args->BrowseFlag == MMSCP_BrowseFlag_Metadata) { browseFlagString = MMSCP_BROWSE_FLAG_METADATA_STRING; } else { browseFlagString = MMSCP_BROWSE_FLAG_CHILDREN_STRING; } MSCP_Invoke_ContentDirectory_Browse ( serviceObj, MSCPResponseSink_ContentDirectory_Browse, args, args->ObjectID, browseFlagString, args->Filter, args->StartingIndex, args->RequestedCount, args->SortCriteria );}struct MMSCP_MediaResource* MMSCP_SelectBestIpNetworkResource(const struct MMSCP_MediaObject *mediaObj, const char *protocolInfoSet, int *ipAddressList, int ipAddressListLen){ struct MMSCP_MediaResource* retVal = NULL, *res; long ipMatch = 0xFFFFFFFF, protInfoMatch = 0, bestIpMatch = 0xFFFFFFFF, bestProtInfoMatch = 0; int protInfoCount = 0; char *protInfoSet; int protInfoSetStringSize, protInfoSetStringLen; int i, pi; short finding; char **protInfos; char *protocol, *network, *mimeType, *info; int protocolLen, networkLen, mimeTypeLen, infoLen; char *resprotocol, *resnetwork, *resmimeType, *resinfo; int resprotocolLen, resnetworkLen, resmimeTypeLen, resinfoLen; int posIpByteStart, posIpByteLength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -