[vlc-devel] [PATCHv2 03/13] upnp: refactor containers addition
Thomas Guillem
thomas at gllm.fr
Tue May 3 19:02:30 CEST 2016
And rename addItem to addContainer.
---
modules/services_discovery/upnp.cpp | 30 +++++++++++++-----------------
modules/services_discovery/upnp.hpp | 2 +-
2 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 122c378..02ca710 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -775,20 +775,29 @@ MediaServer::~MediaServer()
free( psz_root_ );
}
-void MediaServer::addItem(const char *objectID, const char *title )
+bool MediaServer::addContainer( IXML_Element* containerElement )
{
char* psz_url;
+ const char* objectID = ixmlElement_getAttribute( containerElement, "id" );
+ if ( !objectID )
+ return false;
+
+ const char* title = xml_getChildElementValue( containerElement, "dc:title" );
+ if ( !title )
+ return false;
+
if( asprintf( &psz_url, "upnp://%s?ObjectID=%s", psz_root_, objectID ) < 0 )
- return;
+ return false;
input_item_t* p_item = input_item_NewDirectory( psz_url, title, ITEM_NET );
free( psz_url);
if ( !p_item )
- return;
+ return false;
input_item_CopyOptions( p_item, node_->p_item );
input_item_node_AppendItem( node_, p_item );
input_item_Release( p_item );
+ return true;
}
int MediaServer::sendActionCb( Upnp_EventType eventType,
@@ -944,20 +953,7 @@ bool MediaServer::fetchContents()
if ( containerNodeList )
{
for ( unsigned int i = 0; i < ixmlNodeList_length( containerNodeList ); i++ )
- {
- IXML_Element* containerElement = (IXML_Element*)ixmlNodeList_item( containerNodeList, i );
-
- const char* objectID = ixmlElement_getAttribute( containerElement,
- "id" );
- if ( !objectID )
- continue;
-
- const char* title = xml_getChildElementValue( containerElement,
- "dc:title" );
- if ( !title )
- continue;
- addItem(objectID, title);
- }
+ addContainer( (IXML_Element*)ixmlNodeList_item( containerNodeList, i ) );
ixmlNodeList_free( containerNodeList );
}
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index 26593d0..a1cfa97 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -149,7 +149,7 @@ private:
MediaServer(const MediaServer&);
MediaServer& operator=(const MediaServer&);
- void addItem(const char* objectID, const char* title);
+ bool addContainer( IXML_Element* containerElement );
IXML_Document* _browseAction(const char*, const char*,
const char*, const char*, const char* );
--
2.8.0.rc3
More information about the vlc-devel
mailing list