+ mfield_parse( p_sd->pp_media[i_count]->psz_medianame,
+ & psz_proto, & psz_port );
+
+ if( !psz_proto || !psz_port )
+ {
+ return;
+ }
+
+ if( p_sd->pp_media[i_count]->psz_mediaconnection )
+ {
+ cfield_parse( p_sd->pp_media[i_count]->psz_mediaconnection,
+ & psz_uri );
+ }
+ else
+ {
+ psz_uri = psz_uri_default;
+ }
+
+ if( psz_uri == NULL )
+ {
+ return;
+ }
+
+ for( i = 0 ; i< p_sd->i_attributes ; i++ )
+ {
+ if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "type") &&
+ strstr( p_sd->pp_attributes[i]->psz_value, "http") )
+ {
+ b_http = VLC_TRUE;
+ }
+ if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "http-path"))
+ {
+ psz_http_path = strdup( p_sd->pp_attributes[i]->psz_value );
+ }
+ if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup"))
+ {
+ int i_group_id;
+ p_playlist =
+ (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+ FIND_ANYWHERE );
+ if( p_playlist == NULL )
+ {
+ return;
+ }
+
+ i_group_id = playlist_GroupToId( p_playlist,
+ p_sd->pp_attributes[i]->psz_value);
+ if( i_group_id != 0 )
+ {
+ i_group = i_group_id;
+ }
+ else
+ {
+ playlist_group_t *p_group =
+ playlist_CreateGroup( p_playlist,
+ p_sd->pp_attributes[i]->psz_value);
+ i_group = p_group->i_id;
+ }
+ vlc_object_release( p_playlist );
+ }
+ }
+
+ /* Filling psz_uri */
+ if( b_http == VLC_FALSE )
+ {
+ psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) +
+ strlen( psz_port ) + 7 );
+ if( ismult( psz_uri ) )
+ {
+ sprintf( psz_item_uri, "%s://@%s:%s",
+ psz_proto, psz_uri, psz_port );
+ }
+ else
+ {
+ sprintf( psz_item_uri, "%s://%s:%s",
+ psz_proto, psz_uri, psz_port );
+ }
+ }
+ else
+ {
+ if( psz_http_path == NULL )
+ {
+ psz_http_path = strdup( "/" );
+ }
+
+ psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) +
+ strlen( psz_port ) + strlen(psz_http_path) +
+ 5 );
+ sprintf( psz_item_uri, "%s://%s:%s%s", psz_proto,
+ psz_uri, psz_port,psz_http_path );
+
+ if( psz_http_path )
+ {
+ free( psz_http_path );
+ }
+ }
+
+ /* Check if we already know this item */
+ for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ )
+ {
+ if( !strcmp( p_intf->p_sys->pp_announces[i]->psz_uri,
+ psz_item_uri ) )
+ {
+ p_intf->p_sys->pp_announces[i]->i_last = mdate();
+
+ /* Check if the name changed */
+ if( strcmp( p_intf->p_sys->pp_announces[i]->psz_name,
+ p_sd->psz_sessionname ) )
+ {
+ playlist_item_t *p_item;
+ p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+ FIND_ANYWHERE );
+
+ msg_Dbg(p_intf, "Name changed (%s -> %s) for %s",
+ p_intf->p_sys->pp_announces[i]->psz_name,
+ p_sd->psz_sessionname,
+ psz_item_uri );
+
+ p_item = playlist_ItemGetById( p_playlist,
+ p_intf->p_sys->pp_announces[i]->i_id );
+
+ /* Change the name in the item */
+ if( p_item->psz_name )
+ free( p_item->psz_name );
+ p_item->psz_name = strdup( p_sd->psz_sessionname);
+
+ /* Update the stored name */
+ if( p_intf->p_sys->pp_announces[i]->psz_name )
+ free( p_intf->p_sys->pp_announces[i]->psz_name );
+ p_intf->p_sys->pp_announces[i]->psz_name =
+ strdup( p_sd->psz_sessionname );
+
+ vlc_object_release( p_playlist );
+ }
+ return;
+ }
+ }
+
+ /* Add the item in the playlist */
+ p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+ FIND_ANYWHERE );
+ i_id = playlist_Add ( p_playlist, psz_item_uri ,
+ p_sd->psz_sessionname,
+ PLAYLIST_CHECK_INSERT, PLAYLIST_END );
+ p_item = playlist_ItemGetById( p_playlist, i_id );
+ if( p_item )
+ {
+ vlc_mutex_lock( &p_item->lock );
+ playlist_ItemSetGroup( p_item, i_group );
+ vlc_mutex_unlock( &p_item->lock );
+ }
+
+ /* Then remember it */
+ p_announce = (struct sap_announce_t *)malloc(
+ sizeof(struct sap_announce_t) );
+ if( p_sd->psz_sessionname )
+ {
+ p_announce->psz_name = strdup( p_sd->psz_sessionname );
+ }
+ else
+ {
+ p_announce->psz_name = strdup( "" );
+ }
+ if( psz_item_uri )
+ {
+ p_announce->psz_uri = strdup( psz_item_uri );
+ }
+ else
+ {
+ p_announce->psz_uri = strdup( "" );
+ }
+ p_announce->i_id = i_id;
+
+ p_announce->i_last = mdate();
+
+ vlc_object_release( p_playlist );
+
+ INSERT_ELEM( p_intf->p_sys->pp_announces,
+ p_intf->p_sys->i_announces,
+ p_intf->p_sys->i_announces,
+ p_announce );
+ free( psz_item_uri );
+ }
+}