📄 upnpapi.c
字号:
* * 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 ) ) { DBGONLY( 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 { DBGONLY( 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; } DBGONLY( 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; DBGONLY( 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; } DBGONLY( 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 == NULL ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); HandleUnlock( ); DBGONLY( 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 == NULL ) { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); ixmlNodeList_free( HInfo->DeviceList ); ixmlDocument_free( HInfo->DescDocument ); FreeHandle( *Hnd ); HandleUnlock( ); DBGONLY( UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: No services found for RootDevice\n" ); ) return UPNP_E_INVALID_DESC; } DBGONLY( UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "UpnpRegisterRootDevice: Gena Check\n" ); ) //******************************* //GENA SET UP //******************************* if( getServiceTable( ( IXML_Node * ) HInfo->DescDocument, &HInfo->ServiceTable, HInfo->DescURL ) ) { DBGONLY( 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 { CLIENTONLY( ListDestroy( &HInfo->SsdpSearchList, 0 ) ); FreeHandle( *Hnd ); HandleUnlock( ); DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "\nUpnpRegisterRootDevice: Errors retrieving service table \n" ); ) return UPNP_E_INVALID_DESC; } UpnpSdkDeviceRegistered = 1; HandleUnlock( ); DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting RegisterRootDevice Successfully\n" ); ) return UPNP_E_SUCCESS;} /****************** End of UpnpRegisterRootDevice *********************/#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 ) ) { DBGONLY( 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 { DBGONLY( 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( ); DBGONLY( 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 FreeHandle( Hnd ); UpnpSdkDeviceRegistered = 0; HandleUnlock( );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -