📄 upnpapi.c
字号:
if( GetClientHandleInfo( &client_handle, &temp ) == HND_CLIENT ) UpnpUnRegisterClient( client_handle );#endif TimerThreadShutdown( &gTimerThread ); StopMiniServer();#if EXCLUDE_WEB_SERVER == 0 web_server_destroy();#endif ThreadPoolShutdown(&gMiniServerThreadPool); ThreadPoolShutdown(&gRecvThreadPool); ThreadPoolShutdown(&gSendThreadPool); PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool"); PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool"); PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");#ifdef INCLUDE_CLIENT_APIS ithread_mutex_destroy(&GlobalClientSubscribeMutex);#endif ithread_rwlock_destroy(&GlobalHndRWLock); ithread_mutex_destroy(&gUUIDMutex); // remove all virtual dirs UpnpRemoveAllVirtualDirs(); // allow static linking#ifdef WIN32#ifdef PTW32_STATIC_LIB pthread_win32_thread_detach_np();#endif#endif UpnpSdkInit = 0; UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit); UpnpCloseLog(); return UPNP_E_SUCCESS;}/*************************** End of UpnpFinish *****************************//****************************************************************************** * Function: UpnpGetServerPort * * Parameters: NONE * * Description: * Gives back the miniserver port. * * Return Values: * local port on success, zero on failure. *****************************************************************************/unsigned shortUpnpGetServerPort( void ){ if( UpnpSdkInit != 1 ) return 0; return LOCAL_PORT;}/*************************************************************************** * Function: UpnpGetServerIpAddress * * Parameters: NONE * * Description: * Gives back the local ipaddress. * * Return Values: char * * return the IP address string on success else NULL of failure ***************************************************************************/char *UpnpGetServerIpAddress( void ){ if( UpnpSdkInit != 1 ) return NULL; return LOCAL_HOST;}#ifdef INCLUDE_DEVICE_APIS#if 0/**************************************************************************** * Function: UpnpAddRootDevice * * Parameters: * IN const char *DescURL: Location of the root device * description xml file * IN UpnpDevice_Handle Hnd: The device handle * * Description: * downloads the description file and update the service table of the * device. This function has been deprecated. * * Return Values: * UPNP_E_SUCCESS on success, nonzero on failure. *****************************************************************************/intUpnpAddRootDevice( IN const char *DescURL, IN UpnpDevice_Handle Hnd ){ int retVal = 0; struct Handle_Info *HInfo; IXML_Document *temp; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } if( ( retVal = UpnpDownloadXmlDoc( DescURL, &( temp ) ) ) != UPNP_E_SUCCESS ) { return retVal; } HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_INVALID_HANDLE; } if( addServiceTable ( ( IXML_Node * ) temp, &HInfo->ServiceTable, DescURL ) ) { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "UpnpAddRootDevice: GENA Service Table \n" ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Here are the known services: \n" ); printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "\nUpnpAddRootDevice: No Eventing Support Found \n" ); } ixmlDocument_free( temp ); HandleUnlock(); return UPNP_E_SUCCESS;}#endif // 0#endif //INCLUDE_DEVICE_APIS#ifdef INCLUDE_DEVICE_APIS/**************************************************************************** * Function: UpnpRegisterRootDevice * * Parameters: * IN const char *DescUrl:Pointer to a string containing the * description URL for this root device instance. * IN Upnp_FunPtr Callback: Pointer to the callback function for * receiving asynchronous events. * IN const void *Cookie: Pointer to user data returned with the * callback function when invoked. * OUT UpnpDevice_Handle *Hnd: Pointer to a variable to store the * new device handle. * * Description: * This function registers a device application with * the UPnP Library. A device application cannot make any other API * calls until it registers using this function. * * Return Values: * UPNP_E_SUCCESS on success, nonzero on failure. *****************************************************************************/intUpnpRegisterRootDevice( IN const char *DescUrl, IN Upnp_FunPtr Fun, IN const void *Cookie, OUT UpnpDevice_Handle * Hnd ){ struct Handle_Info *HInfo; int retVal = 0; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Inside UpnpRegisterRootDevice\n" ); HandleLock(); if( UpnpSdkDeviceRegistered ) { HandleUnlock(); return UPNP_E_ALREADY_REGISTERED; } if( Hnd == NULL || Fun == NULL || DescUrl == NULL || strlen( DescUrl ) == 0 ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) { HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) ); if( HInfo == NULL ) { HandleUnlock(); return UPNP_E_OUTOF_MEMORY; } HandleTable[*Hnd] = HInfo; UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Root device URL is %s\n", DescUrl ); HInfo->aliasInstalled = 0; HInfo->HType = HND_DEVICE; strcpy( HInfo->DescURL, DescUrl ); HInfo->Callback = Fun; HInfo->Cookie = ( void * )Cookie; HInfo->MaxAge = DEFAULT_MAXAGE; HInfo->DeviceList = NULL; HInfo->ServiceList = NULL; HInfo->DescDocument = NULL; CLIENTONLY( ListInit( &HInfo->SsdpSearchList, NULL, NULL ); ) CLIENTONLY( HInfo->ClientSubList = NULL; ) HInfo->MaxSubscriptions = UPNP_INFINITE; HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE; if( ( retVal = UpnpDownloadXmlDoc( HInfo->DescURL, &( HInfo->DescDocument ) ) ) != UPNP_E_SUCCESS ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle( *Hnd ); HandleUnlock(); return retVal; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: Valid Description\n" ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: DescURL : %s\n", HInfo->DescURL ); HInfo->DeviceList = ixmlDocument_getElementsByTagName( HInfo->DescDocument, "device" ); if( !HInfo->DeviceList ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); HandleUnlock(); UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: No devices found for RootDevice\n" ); return UPNP_E_INVALID_DESC; } HInfo->ServiceList = ixmlDocument_getElementsByTagName( HInfo->DescDocument, "serviceList" ); if( !HInfo->ServiceList ) { UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: No services found for RootDevice\n" ); } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: Gena Check\n" ); //******************************* // GENA SET UP //******************************* if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, &HInfo->ServiceTable, HInfo->DescURL ) ) { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: GENA Service Table \n" ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Here are the known services: \n" ); printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "\nUpnpRegisterRootDevice2: Empty service table\n" ); } UpnpSdkDeviceRegistered = 1; HandleUnlock(); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting RegisterRootDevice Successfully\n" ); return UPNP_E_SUCCESS;}#endif // INCLUDE_DEVICE_APIS#ifdef INCLUDE_DEVICE_APIS#if 0/**************************************************************************** * Function: UpnpRemoveRootDevice * * Parameters: * IN const char *DescURL: Location of the root device * description xml file * IN UpnpDevice_Handle Hnd: The device handle * * Description: * downloads the description file and update the service table of the * device. This function has been deprecated. * * Return Values: * UPNP_E_SUCCESS on success, nonzero on failure. *****************************************************************************/intUpnpRemoveRootDevice( IN const char *DescURL, IN UpnpDevice_Handle Hnd ){ int retVal = 0; struct Handle_Info *HInfo; IXML_Document *temp; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } if( ( retVal = UpnpDownloadXmlDoc( DescURL, &( temp ) ) ) != UPNP_E_SUCCESS ) { return retVal; } HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_INVALID_HANDLE; } if( removeServiceTable( ( IXML_Node * ) temp, &HInfo->ServiceTable ) ) { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "UpnpRemoveRootDevice: GENA Service Table \n" ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Here are the known services: \n" ); printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } else { UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "\nUpnpRemoveRootDevice: No Services Removed\n" ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Here are the known services: \n" ); printServiceTable( &HInfo->ServiceTable, UPNP_INFO, API ); } HandleUnlock(); ixmlDocument_free( temp ); return UPNP_E_SUCCESS;}#endif //0#endif //INCLUDE_DEVICE_APIS#ifdef INCLUDE_DEVICE_APIS/**************************************************************************** * Function: UpnpUnRegisterRootDevice * * Parameters: * IN UpnpDevice_Handle Hnd: The handle of the device instance * to unregister * Description: * This function unregisters a root device registered with * UpnpRegisterRootDevice} or UpnpRegisterRootDevice2. After this call, the * UpnpDevice_Handle Hnd is no longer valid. For all advertisements that * have not yet expired, the UPnP library sends a device unavailable message * automatically. * * Return Values: * UPNP_E_SUCCESS on success, nonzero on failure. *****************************************************************************/intUpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd ){ int retVal = 0; struct Handle_Info *HInfo = NULL; // struct Handle_Info *info=NULL; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } HandleLock(); if( !UpnpSdkDeviceRegistered ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } HandleUnlock(); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Inside UpnpUnRegisterRootDevice \n" );#if EXCLUDE_GENA == 0 if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS ) return UPNP_E_INVALID_HANDLE;#endif HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } HandleUnlock();#if EXCLUDE_SSDP == 0 retVal = AdvertiseAndReply( -1, Hnd, 0, ( struct sockaddr_in * )NULL, ( char * )NULL, ( char * )NULL, ( char * )NULL, HInfo->MaxAge );#endif HandleLock(); if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } //info = (struct Handle_Info *) HandleTable[Hnd]; ixmlNodeList_free( HInfo->DeviceList ); ixmlNodeList_free( HInfo->ServiceList ); ixmlDocument_free( HInfo->DescDocument ); CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ); )#ifdef INTERNAL_WEB_SERVER if( HInfo->aliasInstalled ) { web_server_set_alias( NULL, NULL, 0, 0 ); }#endif // INTERNAL_WEB_SERVER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -