+ vlc_restorecancel (canc);
+ }
+ vlc_cleanup_pop();
+ assert(0); /* dead code */
+}
+
+static int UrlsChange( vlc_object_t *p_this, char const *psz_var,
+ vlc_value_t oldval, vlc_value_t newval,
+ void *p_data )
+{
+ VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval);
+ VLC_UNUSED(newval);
+ services_discovery_sys_t *p_sys = (services_discovery_sys_t *)p_data;
+
+ vlc_mutex_lock( &p_sys->lock );
+ p_sys->b_update = true;
+ p_sys->update_type = UPDATE_URLS;
+ vlc_cond_signal( &p_sys->wait );
+ vlc_mutex_unlock( &p_sys->lock );
+ return VLC_SUCCESS;
+}
+
+static int Request( vlc_object_t *p_this, char const *psz_var,
+ vlc_value_t oldval, vlc_value_t newval,
+ void *p_data )
+{
+ VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval);
+ services_discovery_sys_t *p_sys = (services_discovery_sys_t *)p_data;
+
+ vlc_mutex_lock( &p_sys->lock );
+ free( p_sys->psz_request );
+ p_sys->psz_request = NULL;
+ if( newval.psz_string && *newval.psz_string ) {
+ p_sys->psz_request = strdup( newval.psz_string );
+ p_sys->b_update = true;
+ p_sys->update_type = UPDATE_REQUEST;
+ vlc_cond_signal( &p_sys->wait );
+ }
+ vlc_mutex_unlock( &p_sys->lock );
+ return VLC_SUCCESS;
+}
+
+static void ParseUrls( services_discovery_t *p_sd, char *psz_urls )
+{
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+ int i_new_items = 0;
+ input_item_t **pp_new_items = NULL;
+
+ int i_new_urls = 0;
+ char **ppsz_new_urls = NULL;
+
+ int i, j;
+
+ for( ;; )
+ {
+ if( !psz_urls ) break;
+
+ char *psz_tok = strchr( psz_urls, '|' );
+ if( psz_tok ) *psz_tok = '\0';
+
+ for( i = 0; i < p_sys->i_urls; i++ )
+ if( !strcmp( psz_urls, p_sys->ppsz_urls[i] ) )
+ break;
+ if( i == p_sys->i_urls )
+ {
+ INSERT_ELEM( ppsz_new_urls, i_new_urls, i_new_urls,
+ strdup( psz_urls ) );
+
+ input_item_t *p_input;
+ p_input = input_item_New( p_sd, psz_urls, psz_urls );
+ input_item_AddOption( p_input, "demux=podcast", VLC_INPUT_OPTION_TRUSTED );
+
+ INSERT_ELEM( pp_new_items, i_new_items, i_new_items, p_input );
+ services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ );
+
+ INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input,
+ input_CreateAndStart( p_sd, p_input, NULL ) );
+ }
+ else
+ {
+ INSERT_ELEM( ppsz_new_urls, i_new_urls, i_new_urls,
+ strdup( p_sys->ppsz_urls[i]) );
+ INSERT_ELEM( pp_new_items, i_new_items, i_new_items, p_sys->pp_items[i] );
+ }
+ if( psz_tok ) psz_urls = psz_tok+1;
+ else break;
+ }
+
+ /* delete removed items and signal the removal */
+ for( i = 0; i<p_sys->i_items; ++i )
+ {
+ for( j = 0; j < i_new_items; ++j )
+ if( pp_new_items[j] == p_sys->pp_items[i] ) break;
+ if( j == i_new_items )
+ {
+ services_discovery_RemoveItem( p_sd, p_sys->pp_items[i] );
+ vlc_gc_decref( p_sys->pp_items[i] );
+ }
+ }
+ free( p_sys->pp_items );
+ for( int i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
+ free( p_sys->ppsz_urls );
+
+ p_sys->ppsz_urls = ppsz_new_urls;
+ p_sys->i_urls = i_new_urls;
+ p_sys->pp_items = pp_new_items;
+ p_sys->i_items = i_new_items;
+}
+
+static void ParseRequest( services_discovery_t *p_sd )
+{
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+
+ char *psz_request = p_sys->psz_request;
+
+ int i;
+
+ char *psz_tok = strchr( psz_request, ':' );
+ if( !psz_tok ) return;
+ *psz_tok = '\0';
+ if( !strcmp( psz_request, "ADD" ) )
+ {
+ psz_request = psz_tok + 1;
+ for( i = 0; i<p_sys->i_urls; i++ )
+ if( !strcmp(p_sys->ppsz_urls[i],psz_request) )
+ break;
+ if( i == p_sys->i_urls )
+ {
+ INSERT_ELEM( p_sys->ppsz_urls, p_sys->i_urls, p_sys->i_urls,
+ strdup( psz_request ) );
+
+ input_item_t *p_input;
+ p_input = input_item_New( p_sd, psz_request, psz_request );
+ input_item_AddOption( p_input, "demux=podcast", VLC_INPUT_OPTION_TRUSTED );
+
+ INSERT_ELEM( p_sys->pp_items, p_sys->i_items, p_sys->i_items, p_input );
+ services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ );
+
+ INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input,
+ input_CreateAndStart( p_sd, p_input, NULL ) );
+ SaveUrls( p_sd );
+ }
+ }
+ else if ( !strcmp( psz_request, "RM" ) )
+ {
+ psz_request = psz_tok + 1;
+ for( i = 0; i<p_sys->i_urls; i++ )
+ if( !strcmp(p_sys->ppsz_urls[i],psz_request) )
+ break;
+ if( i != p_sys->i_urls )
+ {
+ services_discovery_RemoveItem( p_sd, p_sys->pp_items[i] );
+ vlc_gc_decref( p_sys->pp_items[i] );
+ REMOVE_ELEM( p_sys->ppsz_urls, p_sys->i_urls, i );
+ REMOVE_ELEM( p_sys->pp_items, p_sys->i_items, i );
+ }
+ SaveUrls( p_sd );
+ }
+
+ free( p_sys->psz_request );
+ p_sys->psz_request = NULL;
+}
+
+static void SaveUrls( services_discovery_t *p_sd )
+{
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+ int i;
+ char *psz_urls;
+ int len = 0;
+
+ for( i=0; i < p_sys->i_urls; i++ )
+ len += strlen( p_sys->ppsz_urls[i] ) + 1;
+
+ psz_urls = (char*) calloc( len, sizeof(char) );
+
+ for( i=0; i < p_sys->i_urls; i++ )
+ {
+ strcat( psz_urls, p_sys->ppsz_urls[i] );
+ if( i < p_sys->i_urls - 1 ) strcat( psz_urls, "|" );