vlc_linux/vlc-3.0.16/modules/services_discovery/upnp.cpp
/*
 * Fetches and parses the UPNP response
 */
Fetches and parses the UPNP response
Fetches and parses the UPNP response
bool MediaServer::fetchContents()
{
    std::string StartingIndex = "0";
    std::string RequestedCount = "5000";
    const char* psz_TotalMatches = "0";
    const char* psz_NumberReturned = "0";
    long  l_reqCount = 0;
    do
    {
        IXML_Document* p_response = _browseAction( m_psz_objectId,
                                                  "BrowseDirectChildren",
                                                  "*",
                                                  StartingIndex.c_str(),
                                                  RequestedCount.c_str(), 
                                                  "" 
                                                  );
        if ( !p_response )
        {
            msg_Err( m_access, "No response from browse() action" );
            return false;
        }
        psz_TotalMatches = xml_getChildElementValue( (IXML_Element*)p_response, "TotalMatches" );
        psz_NumberReturned = xml_getChildElementValue( (IXML_Element*)p_response, "NumberReturned" );
        StartingIndex = std::to_string(  std::stol(psz_NumberReturned) + std::stol(StartingIndex) );
        l_reqCount = std::stol(psz_TotalMatches) - std::stol(StartingIndex) ;
        RequestedCount = std::to_string(l_reqCount);
        IXML_Document* p_result = parseBrowseResult( p_response );
        ixmlDocument_free( p_response );
        if ( !p_result )
        {
            msg_Err( m_access, "browse() response parsing failed" );
            return false;
        }
#ifndef NDEBUG
        msg_Dbg( m_access, "Got DIDL document: %s", ixmlPrintDocument( p_result ) );
#endif
        IXML_NodeList* containerNodeList =
        ixmlDocument_getElementsByTagName( p_result, "container" );
        if ( containerNodeList )
        {
            for ( unsigned int i = 0; i < ixmlNodeList_length( containerNodeList ); i++)
                addContainer( (IXML_Element*)ixmlNodeList_item( containerNodeList, i ) );
            ixmlNodeList_free( containerNodeList );
        }
        IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result,
                                                                        "item" );
        if ( itemNodeList )
        {
            for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++)
                addItem( (IXML_Element*)ixmlNodeList_item( itemNodeList, i ) );
            ixmlNodeList_free( itemNodeList );
        }
        ixmlDocument_free( p_result );
    }
    while( l_reqCount );
    return true;
}
bool MediaServer :: fetchContents ( ) { std :: string StartingIndex = " " ; std :: string RequestedCount = " " ; const char * psz_TotalMatches = " " ; const char * psz_NumberReturned = " " ; long l_reqCount = 0 ; do { IXML_Document * p_response = _browseAction ( m_psz_objectId , " " , " " , StartingIndex . c_str ( ) , RequestedCount . c_str ( ) , " " ) ; if ( ! p_response ) { msg_Err ( m_access , " " ) ; return false ; } psz_TotalMatches = xml_getChildElementValue ( ( IXML_Element * ) p_response , " " ) ; psz_NumberReturned = xml_getChildElementValue ( ( IXML_Element * ) p_response , " " ) ; StartingIndex = std :: to_string ( std :: stol ( psz_NumberReturned ) + std :: stol ( StartingIndex ) ) ; l_reqCount = std :: stol ( psz_TotalMatches ) - std :: stol ( StartingIndex ) ; RequestedCount = std :: to_string ( l_reqCount ) ; IXML_Document * p_result = parseBrowseResult ( p_response ) ; ixmlDocument_free ( p_response ) ; if ( ! p_result ) { msg_Err ( m_access , " " ) ; return false ; } #ifndef NDEBUG msg_Dbg ( m_access , " " , ixmlPrintDocument ( p_result ) ) ; #endif IXML_NodeList * containerNodeList = ixmlDocument_getElementsByTagName ( p_result , " " ) ; if ( containerNodeList ) { for ( unsigned int i = 0 ; i < ixmlNodeList_length ( containerNodeList ) ; i ++ ) addContainer ( ( IXML_Element * ) ixmlNodeList_item ( containerNodeList , i ) ) ; ixmlNodeList_free ( containerNodeList ) ; } IXML_NodeList * itemNodeList = ixmlDocument_getElementsByTagName ( p_result , " " ) ; if ( itemNodeList ) { for ( unsigned int i = 0 ; i < ixmlNodeList_length ( itemNodeList ) ; i ++ ) addItem ( ( IXML_Element * ) ixmlNodeList_item ( itemNodeList , i ) ) ; ixmlNodeList_free ( itemNodeList ) ; } ixmlDocument_free ( p_result ) ; } while ( l_reqCount ) ; return true ; }
Fetches and parses the UPNP response
Fetches and parses the UPNP response
// Some servers don't understand "0" as "no-limit" /* RequestedCount */ /* SortCriteria */