// Extracts the result document from a SOAP response IXML_Document* parseBrowseResult( IXML_Document* doc ) { ixmlRelaxParser(1); if ( !doc ) return 0; IXML_NodeList* resultList = ixmlDocument_getElementsByTagName( doc, "Result" ); if ( !resultList ) return 0; IXML_Node* resultNode = ixmlNodeList_item( resultList, 0 ); ixmlNodeList_free( resultList ); if ( !resultNode ) return 0; IXML_Node* textNode = ixmlNode_getFirstChild( resultNode ); if ( !textNode ) return 0; const char* resultString = ixmlNode_getNodeValue( textNode ); char* resultXML = strdup( resultString ); IXML_Document* browseDoc = ixmlParseBuffer( resultXML ); free( resultXML ); return browseDoc; }
/* * Extracts the result document from a SOAP response */ IXML_Document* parseBrowseResult( IXML_Document* p_doc ) { ixmlRelaxParser( 1 ); if ( !p_doc ) return 0; IXML_NodeList* p_result_list = ixmlDocument_getElementsByTagName( p_doc, "Result" ); if ( !p_result_list ) return 0; IXML_Node* p_result_node = ixmlNodeList_item( p_result_list, 0 ); ixmlNodeList_free( p_result_list ); if ( !p_result_node ) return 0; IXML_Node* p_text_node = ixmlNode_getFirstChild( p_result_node ); if ( !p_text_node ) return 0; const char* psz_result_string = ixmlNode_getNodeValue( p_text_node ); IXML_Document* p_browse_doc = ixmlParseBuffer( psz_result_string ); return p_browse_doc; }
UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, Upnp_FunPtr callback, SD::MediaServerList *opaque) { vlc_mutex_locker lock( &s_lock ); if ( s_instance == NULL ) { UpnpInstanceWrapper* instance = new(std::nothrow) UpnpInstanceWrapper; if ( unlikely( !instance ) ) return NULL; #ifdef UPNP_ENABLE_IPV6 char* psz_miface = var_InheritString( p_obj, "miface" ); msg_Info( p_obj, "Initializing libupnp on '%s' interface", psz_miface ); int i_res = UpnpInit2( psz_miface, 0 ); free( psz_miface ); #else /* If UpnpInit2 isnt available, initialize on first IPv4-capable interface */ int i_res = UpnpInit( 0, 0 ); #endif if( i_res != UPNP_E_SUCCESS ) { msg_Err( p_obj, "Initialization failed: %s", UpnpGetErrorMessage( i_res ) ); delete instance; return NULL; } ixmlRelaxParser( 1 ); /* Register a control point */ i_res = UpnpRegisterClient( Callback, instance, &instance->handle_ ); if( i_res != UPNP_E_SUCCESS ) { msg_Err( p_obj, "Client registration failed: %s", UpnpGetErrorMessage( i_res ) ); delete instance; return NULL; } /* libupnp does not treat a maximum content length of 0 as unlimited * until 64dedf (~ pupnp v1.6.7) and provides no sane way to discriminate * between versions */ if( (i_res = UpnpSetMaxContentLength( INT_MAX )) != UPNP_E_SUCCESS ) { msg_Err( p_obj, "Failed to set maximum content length: %s", UpnpGetErrorMessage( i_res )); delete instance; return NULL; } s_instance = instance; } s_instance->refcount_++; // This assumes a single UPNP SD instance if (callback && opaque) { assert(!s_instance->callback_ && !s_instance->opaque_); s_instance->opaque_ = opaque; s_instance->callback_ = callback; } return s_instance; }
/* * Initializes UPNP instance. */ static int Open( vlc_object_t *p_this ) { int i_res; services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys = ( services_discovery_sys_t * ) calloc( 1, sizeof( services_discovery_sys_t ) ); if( !( p_sd->p_sys = p_sys ) ) return VLC_ENOMEM; #ifdef UPNP_ENABLE_IPV6 char* psz_miface; psz_miface = var_InheritString( p_sd, "miface" ); msg_Info( p_sd, "Initializing libupnp on '%s' interface", psz_miface ); i_res = UpnpInit2( psz_miface, 0 ); free( psz_miface ); #else /* If UpnpInit2 isnt available, initialize on first IPv4-capable interface */ i_res = UpnpInit( 0, 0 ); #endif if( i_res != UPNP_E_SUCCESS ) { msg_Err( p_sd, "Initialization failed: %s", UpnpGetErrorMessage( i_res ) ); free( p_sys ); return VLC_EGENERIC; } ixmlRelaxParser( 1 ); p_sys->p_server_list = new MediaServerList( p_sd ); vlc_mutex_init( &p_sys->callback_lock ); /* Register a control point */ i_res = UpnpRegisterClient( Callback, p_sd, &p_sys->client_handle ); if( i_res != UPNP_E_SUCCESS ) { msg_Err( p_sd, "Client registration failed: %s", UpnpGetErrorMessage( i_res ) ); Close( (vlc_object_t*) p_sd ); return VLC_EGENERIC; } /* Search for media servers */ i_res = UpnpSearchAsync( p_sys->client_handle, 5, MEDIA_SERVER_DEVICE_TYPE, p_sd ); if( i_res != UPNP_E_SUCCESS ) { msg_Err( p_sd, "Error sending search request: %s", UpnpGetErrorMessage( i_res ) ); Close( (vlc_object_t*) p_sd ); return VLC_EGENERIC; } /* libupnp does not treat a maximum content length of 0 as unlimited * until 64dedf (~ pupnp v1.6.7) and provides no sane way to discriminate * between versions */ if( (i_res = UpnpSetMaxContentLength( INT_MAX )) != UPNP_E_SUCCESS ) { msg_Err( p_sd, "Failed to set maximum content length: %s", UpnpGetErrorMessage( i_res )); Close( (vlc_object_t*) p_sd ); return VLC_EGENERIC; } return VLC_SUCCESS; }