📄 upnpapi.c
字号:
#if EXCLUDE_WEB_SERVER == 0
web_server_destroy( );
#endif
ThreadPoolShutdown( &gSendThreadPool );
ThreadPoolShutdown( &gRecvThreadPool );
DBGONLY( UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit ); ThreadPoolGetStats( &gRecvThreadPool, &stats ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Recv Thread Pool \n High Jobs pending = %d" " \nMed Jobs Pending = %d\n Low Jobs Pending = %d \nWorker Threads" " = %d\nIdle Threads = %d\nPersistent Threads = %d\nAverage Time " "spent in High Q = %lf\nAverage Time spent in Med Q = %lf\nAverage" " Time spent in Low Q = %lf\nMax Threads Used: %d\nTotal Work Time" "= %lf\nTotal Idle Time = %lf\n", stats.currentJobsHQ, stats.currentJobsMQ, stats.currentJobsLQ, stats.persistentThreads, stats.avgWaitHQ, stats.avgWaitMQ, stats.avgWaitLQ, stats.maxThreads, stats.totalWorkTime, stats.totalIdleTime ); ThreadPoolGetStats( &gSendThreadPool, &stats ); UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, "Send Thread Pool \n High Jobs pending = %d" " \nMed Jobs Pending = %d\n Low Jobs Pending = %d \nWorker Threads" " = %d\nIdle Threads = %d\nPersistent Threads = %d\nAverage Time " "spent in High Q = %lf\nAverage Time spent in Med Q = %lf\nAverage" " Time spent in Low Q = %lf\nMax Threads Used: %d\nTotal Work Time" "= %lf\nTotal Idle Time = %lf\n", stats.currentJobsHQ, stats.currentJobsMQ, stats.currentJobsLQ, stats.persistentThreads, stats.avgWaitHQ, stats.avgWaitMQ, stats.avgWaitLQ, stats.maxThreads, stats.totalWorkTime, stats.totalIdleTime ); ) // DBGONLY
DBGONLY( CloseLog( );
);
CLIENTONLY( ithread_mutex_destroy( &GlobalClientSubscribeMutex );
)
ithread_mutex_destroy( &GlobalHndMutex );
ithread_mutex_destroy( &gUUIDMutex );
// remove all virtual dirs
UpnpRemoveAllVirtualDirs( );
UpnpSdkInit = 0;
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 short
UpnpGetServerPort( 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.
*****************************************************************************/
int
UpnpAddRootDevice( 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.
*****************************************************************************/
int
UpnpRegisterRootDevice( 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.
*****************************************************************************/
int
UpnpRemoveRootDevice( 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.
*****************************************************************************/
int
UpnpUnRegisterRootDevice( IN UpnpDevice_Handle Hnd )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -