- {
- struct Upnp_Discovery* discovery = ( struct Upnp_Discovery* )event;
-
- IXML_Document *descriptionDoc = 0;
-
- int res;
- res = UpnpDownloadXmlDoc( discovery->Location, &descriptionDoc );
- if ( res != UPNP_E_SUCCESS )
- {
- msg_Dbg( cookie->serviceDiscovery, "%s:%d: Could not download device description!", __FILE__, __LINE__ );
- return res;
- }
-
- MediaServer::parseDeviceDescription( descriptionDoc, discovery->Location, cookie );
-
- ixmlDocument_free( descriptionDoc );
- }
- break;
-
+ {
+ struct Upnp_Discovery* discovery = ( struct Upnp_Discovery* )event;
+
+ IXML_Document *descriptionDoc = 0;
+
+ int res;
+ res = UpnpDownloadXmlDoc( discovery->Location, &descriptionDoc );
+ if ( res != UPNP_E_SUCCESS )
+ {
+ msg_Dbg( cookie->serviceDiscovery, "%s:%d: Could not download device description!", __FILE__, __LINE__ );
+ return res;
+ }
+
+ MediaServer::parseDeviceDescription( descriptionDoc, discovery->Location, cookie );
+
+ ixmlDocument_free( descriptionDoc );
+ }
+ break;
+
-
- for ( unsigned int i = 0; i < ixmlNodeList_length( deviceList ); i++ )
- {
- IXML_Element* deviceElement = ( IXML_Element* )ixmlNodeList_item( deviceList, i );
-
- const char* deviceType = xml_getChildElementValue( deviceElement, "deviceType" );
- if ( !deviceType ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no deviceType!", __FILE__, __LINE__ ); continue; }
- if ( strcmp( MEDIA_SERVER_DEVICE_TYPE, deviceType ) != 0 ) continue;
-
- const char* UDN = xml_getChildElementValue( deviceElement, "UDN" );
- if ( !UDN ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no UDN!", __FILE__, __LINE__ ); continue; }
- if ( cookie->serverList->getServer( UDN ) != 0 ) continue;
-
- const char* friendlyName = xml_getChildElementValue( deviceElement, "friendlyName" );
- if ( !friendlyName ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no friendlyName!", __FILE__, __LINE__ ); continue; }
-
- MediaServer* server = new MediaServer( UDN, friendlyName, cookie );
- if ( !cookie->serverList->addServer( server ) ) {
-
- delete server;
- server = 0;
- continue;
- }
-
- // Check for ContentDirectory service...
-
- IXML_NodeList* serviceList = ixmlElement_getElementsByTagName( deviceElement, "service" );
- if ( serviceList )
- {
- for ( unsigned int j = 0; j < ixmlNodeList_length( serviceList ); j++ )
- {
- IXML_Element* serviceElement = ( IXML_Element* )ixmlNodeList_item( serviceList, j );
-
- const char* serviceType = xml_getChildElementValue( serviceElement, "serviceType" );
- if ( !serviceType ) continue;
- if ( strcmp( CONTENT_DIRECTORY_SERVICE_TYPE, serviceType ) != 0 ) continue;
-
- const char* eventSubURL = xml_getChildElementValue( serviceElement, "eventSubURL" );
- if ( !eventSubURL ) continue;
-
- const char* controlURL = xml_getChildElementValue( serviceElement, "controlURL" );
- if ( !controlURL ) continue;
-
- // Try to subscribe to ContentDirectory service
-
- char* url = ( char* )malloc( strlen( baseURL ) + strlen( eventSubURL ) + 1 );
- if ( url )
- {
- char* s1 = strdup( baseURL );
- char* s2 = strdup( eventSubURL );
-
- if ( UpnpResolveURL( s1, s2, url ) == UPNP_E_SUCCESS )
- {
- // msg_Dbg( cookie->serviceDiscovery, "CDS EVENT URL: %s", url );
-
- server->setContentDirectoryEventURL( url );
- server->subscribeToContentDirectory();
- }
-
- free( s1 );
- free( s2 );
- free( url );
- }
-
- // Try to browse content directory...
-
- url = ( char* )malloc( strlen( baseURL ) + strlen( controlURL ) + 1 );
- if ( url )
- {
- char* s1 = strdup( baseURL );
- char* s2 = strdup( controlURL );
-
- if ( UpnpResolveURL( s1, s2, url ) == UPNP_E_SUCCESS )
- {
- // msg_Dbg( cookie->serviceDiscovery, "CDS CTRL URL: %s", url );
-
- server->setContentDirectoryControlURL( url );
- server->fetchContents();
- }
-
- free( s1 );
- free( s2 );
- free( url );
- }
- }
-
- ixmlNodeList_free( serviceList );
- }
- }
-
- ixmlNodeList_free( deviceList );
+
+ for ( unsigned int i = 0; i < ixmlNodeList_length( deviceList ); i++ )
+ {
+ IXML_Element* deviceElement = ( IXML_Element* )ixmlNodeList_item( deviceList, i );
+
+ const char* deviceType = xml_getChildElementValue( deviceElement, "deviceType" );
+ if ( !deviceType ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no deviceType!", __FILE__, __LINE__ ); continue; }
+ if ( strcmp( MEDIA_SERVER_DEVICE_TYPE, deviceType ) != 0 ) continue;
+
+ const char* UDN = xml_getChildElementValue( deviceElement, "UDN" );
+ if ( !UDN ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no UDN!", __FILE__, __LINE__ ); continue; }
+ if ( cookie->serverList->getServer( UDN ) != 0 ) continue;
+
+ const char* friendlyName = xml_getChildElementValue( deviceElement, "friendlyName" );
+ if ( !friendlyName ) { msg_Dbg( cookie->serviceDiscovery, "%s:%d: no friendlyName!", __FILE__, __LINE__ ); continue; }
+
+ MediaServer* server = new MediaServer( UDN, friendlyName, cookie );
+ if ( !cookie->serverList->addServer( server ) ) {
+
+ delete server;
+ server = 0;
+ continue;
+ }
+
+ // Check for ContentDirectory service...
+
+ IXML_NodeList* serviceList = ixmlElement_getElementsByTagName( deviceElement, "service" );
+ if ( serviceList )
+ {
+ for ( unsigned int j = 0; j < ixmlNodeList_length( serviceList ); j++ )
+ {
+ IXML_Element* serviceElement = ( IXML_Element* )ixmlNodeList_item( serviceList, j );
+
+ const char* serviceType = xml_getChildElementValue( serviceElement, "serviceType" );
+ if ( !serviceType ) continue;
+ if ( strcmp( CONTENT_DIRECTORY_SERVICE_TYPE, serviceType ) != 0 ) continue;
+
+ const char* eventSubURL = xml_getChildElementValue( serviceElement, "eventSubURL" );
+ if ( !eventSubURL ) continue;
+
+ const char* controlURL = xml_getChildElementValue( serviceElement, "controlURL" );
+ if ( !controlURL ) continue;
+
+ // Try to subscribe to ContentDirectory service
+
+ char* url = ( char* )malloc( strlen( baseURL ) + strlen( eventSubURL ) + 1 );
+ if ( url )
+ {
+ char* s1 = strdup( baseURL );
+ char* s2 = strdup( eventSubURL );
+
+ if ( UpnpResolveURL( s1, s2, url ) == UPNP_E_SUCCESS )
+ {
+ // msg_Dbg( cookie->serviceDiscovery, "CDS EVENT URL: %s", url );
+
+ server->setContentDirectoryEventURL( url );
+ server->subscribeToContentDirectory();
+ }
+
+ free( s1 );
+ free( s2 );
+ free( url );
+ }
+
+ // Try to browse content directory...
+
+ url = ( char* )malloc( strlen( baseURL ) + strlen( controlURL ) + 1 );
+ if ( url )
+ {
+ char* s1 = strdup( baseURL );
+ char* s2 = strdup( controlURL );
+
+ if ( UpnpResolveURL( s1, s2, url ) == UPNP_E_SUCCESS )
+ {
+ // msg_Dbg( cookie->serviceDiscovery, "CDS CTRL URL: %s", url );
+
+ server->setContentDirectoryControlURL( url );
+ server->fetchContents();
+ }
+
+ free( s1 );
+ free( s2 );
+ free( url );
+ }
+ }
+
+ ixmlNodeList_free( serviceList );
+ }
+ }
+
+ ixmlNodeList_free( deviceList );
- 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* childCountStr = ixmlElement_getAttribute( containerElement, "childCount" );
- if ( !childCountStr ) continue;
- int childCount = atoi( childCountStr );
-
- const char* title = xml_getChildElementValue( containerElement, "dc:title" );
- if ( !title ) continue;
-
- const char* resource = xml_getChildElementValue( containerElement, "res" );
-
- if ( resource && childCount < 1 )
- {
- Item* item = new Item( parent, objectID, title, resource );
- parent->addItem( item );
- }
- else
- {
- Container* container = new Container( parent, objectID, title );
- parent->addContainer( container );
-
- if ( childCount > 0 ) _fetchContents( container );
- }
- }
-
- ixmlNodeList_free( containerNodeList );
+ IXML_Element* containerElement = ( IXML_Element* )ixmlNodeList_item( containerNodeList, i );
+
+ const char* objectID = ixmlElement_getAttribute( containerElement, "id" );
+ if ( !objectID ) continue;
+
+ const char* childCountStr = ixmlElement_getAttribute( containerElement, "childCount" );
+ if ( !childCountStr ) continue;
+ int childCount = atoi( childCountStr );
+
+ const char* title = xml_getChildElementValue( containerElement, "dc:title" );
+ if ( !title ) continue;
+
+ const char* resource = xml_getChildElementValue( containerElement, "res" );
+
+ if ( resource && childCount < 1 )
+ {
+ Item* item = new Item( parent, objectID, title, resource );
+ parent->addItem( item );
+ }
+ else
+ {
+ Container* container = new Container( parent, objectID, title );
+ parent->addContainer( container );
+
+ if ( childCount > 0 ) _fetchContents( container );
+ }
+ }
+
+ ixmlNodeList_free( containerNodeList );
- for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
- {
- IXML_Element* itemElement = ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );
-
- const char* objectID = ixmlElement_getAttribute( itemElement, "id" );
- if ( !objectID ) continue;
-
- const char* title = xml_getChildElementValue( itemElement, "dc:title" );
- if ( !title ) continue;
-
- const char* resource = xml_getChildElementValue( itemElement, "res" );
- if ( !resource ) continue;
-
- Item* item = new Item( parent, objectID, title, resource );
- parent->addItem( item );
- }
-
- ixmlNodeList_free( itemNodeList );
+ for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
+ {
+ IXML_Element* itemElement = ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );
+
+ const char* objectID = ixmlElement_getAttribute( itemElement, "id" );
+ if ( !objectID ) continue;
+
+ const char* title = xml_getChildElementValue( itemElement, "dc:title" );
+ if ( !title ) continue;
+
+ const char* resource = xml_getChildElementValue( itemElement, "res" );
+ if ( !resource ) continue;
+
+ Item* item = new Item( parent, objectID, title, resource );
+ parent->addItem( item );
+ }
+
+ ixmlNodeList_free( itemNodeList );
- Item* item = parent->getItem( i );
- playlist_item_t* parentNode = parent->getPlaylistNode();
-
- playlist_item_t* node = playlist_ItemNew( _cookie->serviceDiscovery,
- item->getResource(),
- item->getTitle() );
-
- playlist_NodeAddItem( _cookie->serviceDiscovery->p_sys->p_playlist,
- node,
- VIEW_CATEGORY,
- parentNode, PLAYLIST_APPEND, PLAYLIST_END );
-
- item->setPlaylistNode( node );
+ Item* item = parent->getItem( i );
+ playlist_item_t* parentNode = parent->getPlaylistNode();
+
+ input_item_t* p_input = input_ItemNew( _cookie->serviceDiscovery,
+ item->getResource(),
+ item->getTitle() );
+ int i_cat;
+ playlist_BothAddInput( p_playlist, p_input, parentNode,
+ PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
+ VLC_FALSE );
+ /* TODO: do this better by storing ids */
+ playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, VLC_FALSE );
+ assert( p_node );
+ item->setPlaylistNode( p_node );