vlc_linux/vlc-3.0.16/modules/services_discovery/upnp.cpp
/*
 * Extracts the result document from a SOAP response
 */
Extracts the result document from a SOAP response
Extracts the result document from a SOAP response
IXML_Document* parseBrowseResult( IXML_Document* p_doc )
{
    assert( p_doc );
    const char* psz_raw_didl = xml_getChildElementValue( (IXML_Element*)p_doc, "Result" );
    if( !psz_raw_didl )
        return NULL;
    IXML_Document* p_result_doc = ixmlParseBuffer( psz_raw_didl );
    if( !p_result_doc ) {
        const char* psz_xml_result_fmt = "<?xml version=\"1.0\" ?>"
            "<Result xmlns:sec=\"urn:samsung:metadata:2009\">%s</Result>";
        char* psz_xml_result_string = NULL;
        if( -1 == asprintf( &psz_xml_result_string,
                             psz_xml_result_fmt,
                             psz_raw_didl) )
            return NULL;
        p_result_doc = ixmlParseBuffer( psz_xml_result_string );
        free( psz_xml_result_string );
    }
    if( !p_result_doc )
        return NULL;
    IXML_NodeList *p_elems = ixmlDocument_getElementsByTagName( p_result_doc,
                                                                "DIDL-Lite" );
    IXML_Node *p_node = ixmlNodeList_item( p_elems, 0 );
    ixmlNodeList_free( p_elems );
    return (IXML_Document*)p_node;
}
IXML_Document * parseBrowseResult ( IXML_Document * p_doc ) { assert ( p_doc ) ; const char * psz_raw_didl = xml_getChildElementValue ( ( IXML_Element * ) p_doc , " " ) ; if ( ! psz_raw_didl ) return NULL ; IXML_Document * p_result_doc = ixmlParseBuffer ( psz_raw_didl ) ; if ( ! p_result_doc ) { const char * psz_xml_result_fmt = " \" \" " " \" \" " ; char * psz_xml_result_string = NULL ; if ( -1 == asprintf ( & psz_xml_result_string , psz_xml_result_fmt , psz_raw_didl ) ) return NULL ; p_result_doc = ixmlParseBuffer ( psz_xml_result_string ) ; free ( psz_xml_result_string ) ; } if ( ! p_result_doc ) return NULL ; IXML_NodeList * p_elems = ixmlDocument_getElementsByTagName ( p_result_doc , " " ) ; IXML_Node * p_node = ixmlNodeList_item ( p_elems , 0 ) ; ixmlNodeList_free ( p_elems ) ; return ( IXML_Document * ) p_node ; }
Extracts the result document from a SOAP response
Extracts the result document from a SOAP response
// ixml*_getElementsByTagName will ultimately only case the pointer to a Node // pointer, and pass it to a private function. Don't bother have a IXML_Document // version of getChildElementValue /* First, try parsing the buffer as is */ /* Missing namespaces confuse the ixml parser. This is a very ugly
         * hack but it is needeed until devices start sending valid XML.
         *
         * It works that way:
         *
         * The DIDL document is extracted from the Result tag, then wrapped into
         * a valid XML header and a new root tag which contains missing namespace
         * definitions so the ixml parser understands it.
         *
         * If you know of a better workaround, please oh please fix it */