/** * Merging meta */ void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src ) { char **ppsz_all_keys; int i; if( !dst || !src ) return; for( i = 0; i < VLC_META_TYPE_COUNT; i++ ) { if( src->ppsz_meta[i] ) { free( dst->ppsz_meta[i] ); dst->ppsz_meta[i] = strdup( src->ppsz_meta[i] ); } } /* XXX: If speed up are needed, it is possible */ ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags ); for( i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ ) { /* Always try to remove the previous value */ vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i], vlc_meta_FreeExtraKey, NULL ); void *p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] ); vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], strdup( (const char*)p_value ) ); free( ppsz_all_keys[i] ); } free( ppsz_all_keys ); }
int main (void) { static const char * our_keys[] = { "Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted" }; const int size = sizeof(our_keys)/sizeof(our_keys[0]); char ** keys; int i = 0; vlc_dictionary_t dict; vlc_dictionary_init( &dict, 0 ); assert( vlc_dictionary_keys_count( &dict ) == 0 ); keys = vlc_dictionary_all_keys( &dict ); assert( keys && !keys[0] ); free(keys); /* Insert some values */ for( i = 0; i < size; i++ ) vlc_dictionary_insert( &dict, our_keys[i], (void*)i ); test_dictionary_validity( &dict, our_keys, size ); vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL ); test_dictionary_validity( &dict, our_keys, size-1 ); vlc_dictionary_clear( &dict, NULL, NULL ); assert( vlc_dictionary_keys_count( &dict ) == 0 ); return 0; }
void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value ) { char *psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name ); if( psz_oldvalue != kVLCDictionaryNotFound ) vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name, vlc_meta_FreeExtraKey, NULL ); vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) ); }
/***************************************************************************** * browser_callback *****************************************************************************/ static void browse_callback( AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata ) { VLC_UNUSED(b); VLC_UNUSED(flags); services_discovery_t *p_sd = ( services_discovery_t* )userdata; services_discovery_sys_t *p_sys = p_sd->p_sys; if( event == AVAHI_BROWSER_NEW ) { if( avahi_service_resolver_new( p_sys->client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, userdata ) == NULL ) { msg_Err( p_sd, "failed to resolve service '%s': %s", name, avahi_strerror( avahi_client_errno( p_sys->client ) ) ); } } else if( name ) { /** \todo Store the input id and search it, rather than searching the items */ input_item_t *p_item; p_item = vlc_dictionary_value_for_key( &p_sys->services_name_to_input_item, name ); if( !p_item ) msg_Err( p_sd, "failed to find service '%s' in playlist", name ); else { services_discovery_RemoveItem( p_sd, p_item ); vlc_dictionary_remove_value_for_key( &p_sys->services_name_to_input_item, name, NULL, NULL ); } } }