/* * Constructs UpnpAction to browse available content. */ IXML_Document* MediaServer::_browseAction( const char* psz_object_id_, const char* psz_browser_flag_, const char* psz_filter_, const char* psz_starting_index_, const char* psz_requested_count_, const char* psz_sort_criteria_ ) { IXML_Document* p_action = 0; IXML_Document* p_response = 0; const char* psz_url = getContentDirectoryControlURL(); if ( !psz_url ) { msg_Dbg( _p_sd, "No subscription url set!" ); return 0; } char* psz_service_type = strdup( CONTENT_DIRECTORY_SERVICE_TYPE ); psz_service_type[strlen( psz_service_type ) - 1] = _i_content_directory_service_version; int i_res; i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "ObjectID", psz_object_id_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'ObjectID' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "BrowseFlag", psz_browser_flag_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'BrowseFlag' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "Filter", psz_filter_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'Filter' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "StartingIndex", psz_starting_index_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'StartingIndex' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "RequestedCount", psz_requested_count_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'RequestedCount' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", psz_service_type, "SortCriteria", psz_sort_criteria_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "AddToAction 'SortCriteria' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpSendAction( _p_sd->p_sys->client_handle, psz_url, psz_service_type, 0, /* ignored in SDK, must be NULL */ p_action, &p_response ); if ( i_res != UPNP_E_SUCCESS ) { msg_Err( _p_sd, "%s when trying the send() action with URL: %s", UpnpGetErrorMessage( i_res ), psz_url ); ixmlDocument_free( p_response ); p_response = 0; } browseActionCleanup: free( psz_service_type ); ixmlDocument_free( p_action ); return p_response; }
IXML_Document* MediaServer::_browseAction( const char* pObjectID, const char* pBrowseFlag, const char* pFilter, const char* pStartingIndex, const char* pRequestedCount, const char* pSortCriteria ) { IXML_Document* action = 0; IXML_Document* response = 0; const char* url = getContentDirectoryControlURL(); if ( !url || strcmp( url, "" ) == 0 ) { msg_Dbg( _p_sd, "No subscription url set!" ); return 0; } char* ObjectID = strdup( pObjectID ); char* BrowseFlag = strdup( pBrowseFlag ); char* Filter = strdup( pFilter ); char* StartingIndex = strdup( pStartingIndex ); char* RequestedCount = strdup( pRequestedCount ); char* SortCriteria = strdup( pSortCriteria ); char* serviceType = strdup( CONTENT_DIRECTORY_SERVICE_TYPE ); int res; res = UpnpAddToAction( &action, "Browse", serviceType, "ObjectID", ObjectID ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpAddToAction( &action, "Browse", serviceType, "BrowseFlag", BrowseFlag ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpAddToAction( &action, "Browse", serviceType, "Filter", Filter ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpAddToAction( &action, "Browse", serviceType, "StartingIndex", StartingIndex ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpAddToAction( &action, "Browse", serviceType, "RequestedCount", RequestedCount ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpAddToAction( &action, "Browse", serviceType, "SortCriteria", SortCriteria ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ) ); goto browseActionCleanup; } res = UpnpSendAction( _p_sd->p_sys->clientHandle, url, CONTENT_DIRECTORY_SERVICE_TYPE, 0, action, &response ); if ( res != UPNP_E_SUCCESS ) { msg_Dbg( _p_sd, "%s:%d: ERROR: %s when trying the send() action with URL: %s", __FILE__, __LINE__, UpnpGetErrorMessage( res ), url ); ixmlDocument_free( response ); response = 0; } browseActionCleanup: free( ObjectID ); free( BrowseFlag ); free( Filter ); free( StartingIndex ); free( RequestedCount ); free( SortCriteria ); free( serviceType ); ixmlDocument_free( action ); return response; }
/* Access part */ IXML_Document* MediaServer::_browseAction( const char* psz_object_id_, const char* psz_browser_flag_, const char* psz_filter_, const char* psz_requested_count_, const char* psz_sort_criteria_ ) { IXML_Document* p_action = NULL; IXML_Document* p_response = NULL; const char* psz_url = url_.c_str(); if ( url_.empty() ) { msg_Dbg( access_, "No subscription url set!" ); return NULL; } int i_res; i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "ObjectID", psz_object_id_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'ObjectID' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "StartingIndex", "0" ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'StartingIndex' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "BrowseFlag", psz_browser_flag_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'BrowseFlag' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "Filter", psz_filter_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'Filter' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "RequestedCount", psz_requested_count_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'RequestedCount' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpAddToAction( &p_action, "Browse", CONTENT_DIRECTORY_SERVICE_TYPE, "SortCriteria", psz_sort_criteria_ ); if ( i_res != UPNP_E_SUCCESS ) { msg_Dbg( access_, "AddToAction 'SortCriteria' failed: %s", UpnpGetErrorMessage( i_res ) ); goto browseActionCleanup; } i_res = UpnpSendAction( access_->p_sys->p_upnp->handle(), psz_url, CONTENT_DIRECTORY_SERVICE_TYPE, NULL, /* ignored in SDK, must be NULL */ p_action, &p_response ); if ( i_res != UPNP_E_SUCCESS ) { msg_Err( access_, "%s when trying the send() action with URL: %s", UpnpGetErrorMessage( i_res ), psz_url ); ixmlDocument_free( p_response ); p_response = NULL; } browseActionCleanup: ixmlDocument_free( p_action ); return p_response; }