diff options
-rw-r--r-- | conf.c | 81 | ||||
-rw-r--r-- | conf.h | 14 | ||||
-rw-r--r-- | deadbeef.h | 38 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | plugins.c | 15 | ||||
-rw-r--r-- | plugins/alsa/alsa.c | 6 | ||||
-rw-r--r-- | plugins/artwork/artwork.c | 13 | ||||
-rw-r--r-- | plugins/cdda/cdda.c | 6 | ||||
-rw-r--r-- | plugins/ffmpeg/ffmpeg.c | 4 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 16 | ||||
-rw-r--r-- | plugins/gtkui/dspconfig.c | 4 | ||||
-rw-r--r-- | plugins/gtkui/eq.c | 9 | ||||
-rw-r--r-- | plugins/gtkui/gdkdrawing.c | 28 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 27 | ||||
-rw-r--r-- | plugins/gtkui/mainplaylist.c | 4 | ||||
-rw-r--r-- | plugins/gtkui/pluginconf.c | 4 | ||||
-rw-r--r-- | plugins/gtkui/prefwin.c | 42 | ||||
-rw-r--r-- | plugins/gtkui/tagwritersettings.c | 3 | ||||
-rw-r--r-- | plugins/lastfm/lastfm.c | 20 | ||||
-rw-r--r-- | plugins/mpgmad/mpgmad.c | 3 | ||||
-rw-r--r-- | plugins/notify/notify.c | 6 | ||||
-rw-r--r-- | plugins/oss/oss.c | 7 | ||||
-rw-r--r-- | plugins/shn/shn.c | 5 | ||||
-rw-r--r-- | plugins/sid/csid.cpp | 5 | ||||
-rw-r--r-- | plugins/sndfile/sndfile.c | 4 | ||||
-rw-r--r-- | plugins/tta/ttaplug.c | 3 | ||||
-rw-r--r-- | plugins/vfs_curl/vfs_curl.c | 10 | ||||
-rw-r--r-- | plugins/wildmidi/wildmidiplug.c | 3 | ||||
-rw-r--r-- | streamer.c | 5 |
29 files changed, 285 insertions, 104 deletions
@@ -21,9 +21,39 @@ #include <stdlib.h> #include <inttypes.h> #include "conf.h" +#include "threading.h" + +#define min(x,y) ((x)<(y)?(x):(y)) static DB_conf_item_t *conf_items; static int changed = 0; +static uintptr_t mutex; + +void +conf_init (void) { + mutex = mutex_create (); +} + +void +conf_lock (void) { + mutex_lock (mutex); +} + +void +conf_unlock (void) { + mutex_unlock (mutex); +} + +void +conf_free (void) { + mutex_lock (mutex); + DB_conf_item_t *next = NULL; + for (DB_conf_item_t *it = conf_items; it; it = next) { + next = it->next; + conf_item_free (it); + } + mutex_free (mutex); +} int conf_load (void) { @@ -35,6 +65,7 @@ conf_load (void) { fprintf (stderr, "failed to load config file\n"); return -1; } + conf_lock (); int line = 0; while (fgets (str, 1024, fp) != NULL) { line++; @@ -70,6 +101,7 @@ conf_load (void) { } fclose (fp); changed = 0; + conf_unlock (); return 0; } @@ -83,24 +115,18 @@ conf_save (void) { fprintf (stderr, "failed to open config file for writing\n"); return -1; } + conf_lock (); for (DB_conf_item_t *it = conf_items; it; it = it->next) { fprintf (fp, "%s %s\n", it->key, it->value); } fclose (fp); + conf_unlock (); return 0; } void -conf_free (void) { - DB_conf_item_t *next = NULL; - for (DB_conf_item_t *it = conf_items; it; it = next) { - next = it->next; - conf_item_free (it); - } -} - -void conf_item_free (DB_conf_item_t *it) { + conf_lock (); if (it) { if (it->key) { free (it->key); @@ -110,10 +136,11 @@ conf_item_free (DB_conf_item_t *it) { } free (it); } + conf_unlock (); } const char * -conf_get_str (const char *key, const char *def) { +conf_get_str_fast (const char *key, const char *def) { for (DB_conf_item_t *it = conf_items; it; it = it->next) { if (!strcasecmp (key, it->key)) { return it->value; @@ -122,21 +149,43 @@ conf_get_str (const char *key, const char *def) { return def; } +void +conf_get_str (const char *key, const char *def, char *buffer, int buffer_size) { + conf_lock (); + const char *out = conf_get_str_fast (key, def); + if (out) { + int n = strlen (out)+1; + n = min (n, buffer_size); + memcpy (buffer, out, n); + buffer[buffer_size-1] = 0; + } + else { + *buffer = 0; + } + conf_unlock (); +} + float conf_get_float (const char *key, float def) { - const char *v = conf_get_str (key, NULL); + conf_lock (); + const char *v = conf_get_str_fast (key, NULL); + conf_unlock (); return v ? atof (v) : def; } int conf_get_int (const char *key, int def) { - const char *v = conf_get_str (key, NULL); + conf_lock (); + const char *v = conf_get_str_fast (key, NULL); + conf_unlock (); return v ? atoi (v) : def; } int64_t conf_get_int64 (const char *key, int64_t def) { - const char *v = conf_get_str (key, NULL); + conf_lock (); + const char *v = conf_get_str_fast (key, NULL); + conf_unlock (); return v ? atoll (v) : def; } @@ -153,6 +202,7 @@ conf_find (const char *group, DB_conf_item_t *prev) { void conf_set_str (const char *key, const char *val) { + conf_lock (); changed = 1; DB_conf_item_t *prev = NULL; for (DB_conf_item_t *it = conf_items; it; it = it->next) { @@ -160,6 +210,7 @@ conf_set_str (const char *key, const char *val) { if (!cmp) { free (it->value); it->value = strdup (val); + conf_unlock (); return; } else if (cmp < 0) { @@ -168,6 +219,7 @@ conf_set_str (const char *key, const char *val) { prev = it; } if (!val) { + conf_unlock (); return; } DB_conf_item_t *it = malloc (sizeof (DB_conf_item_t)); @@ -183,6 +235,7 @@ conf_set_str (const char *key, const char *val) { it->next = conf_items; conf_items = it; } + conf_unlock (); } void @@ -219,6 +272,7 @@ conf_setchanged (int c) { void conf_remove_items (const char *key) { int l = strlen (key); + conf_lock (); DB_conf_item_t *prev = NULL; DB_conf_item_t *it; for (it = conf_items; it; prev = it, it = it->next) { @@ -241,4 +295,5 @@ conf_remove_items (const char *key) { else { conf_items = next; } + conf_unlock (); } @@ -27,16 +27,28 @@ int conf_save (void); void +conf_init (void); + +void conf_free (void); +void +conf_lock (void); + +void +conf_unlock (void); + int conf_ischanged (void); void conf_setchanged (int c); +void +conf_get_str (const char *key, const char *def, char *buffer, int buffer_size); + const char * -conf_get_str (const char *key, const char *def); +conf_get_str_fast (const char *key, const char *def); float conf_get_float (const char *key, float def); @@ -299,19 +299,23 @@ typedef struct { // versioning int vmajor; int vminor; + // event subscribing void (*ev_subscribe) (struct DB_plugin_s *plugin, int ev, DB_callback_t callback, uintptr_t data); void (*ev_unsubscribe) (struct DB_plugin_s *plugin, int ev, DB_callback_t callback, uintptr_t data); + // md5sum calc void (*md5) (uint8_t sig[16], const char *in, int len); void (*md5_to_str) (char *str, const uint8_t sig[16]); void (*md5_init)(DB_md5_t *s); void (*md5_append)(DB_md5_t *s, const uint8_t *data, int nbytes); void (*md5_finish)(DB_md5_t *s, uint8_t digest[16]); + // playback control struct DB_output_s* (*get_output) (void); float (*playback_get_pos) (void); // [0..100] void (*playback_set_pos) (float pos); // [0..100] + // streamer access DB_playItem_t *(*streamer_get_playing_track) (void); DB_playItem_t *(*streamer_get_streaming_track) (void); @@ -327,6 +331,7 @@ typedef struct { struct ddb_dsp_context_s * (*streamer_get_dsp_chain) (void); void (*streamer_set_dsp_chain) (struct ddb_dsp_context_s *chain); void (*streamer_dsp_refresh) (void); // call after changing parameters + // system folders // normally functions will return standard folders derived from --prefix // portable version will return pathes specified in comments below @@ -335,8 +340,10 @@ typedef struct { const char *(*get_doc_dir) (void); // installdir/doc | DOCDIR const char *(*get_plugin_dir) (void); // installdir/plugins | LIBDIR/deadbeef const char *(*get_pixmap_dir) (void); // installdir/pixmaps | PREFIX "/share/deadbeef/pixmaps" + // process control void (*quit) (void); + // threading intptr_t (*thread_start) (void (*fn)(void *ctx), void *ctx); intptr_t (*thread_start_low_priority) (void (*fn)(void *ctx), void *ctx); @@ -353,6 +360,7 @@ typedef struct { int (*cond_wait) (uintptr_t cond, uintptr_t mutex); int (*cond_signal) (uintptr_t cond); int (*cond_broadcast) (uintptr_t cond); + // playlist management int (*plt_get_count) (void); DB_playItem_t * (*plt_get_head) (int plt); @@ -367,6 +375,7 @@ typedef struct { void *(*plt_get_handle) (int idx); int (*plt_get_title) (void *handle, char *buffer, int bufsize); int (*plt_set_title) (void *handle, const char *title); + // playlist metadata // this kind of metadata is stored in playlist (dbpl) files void (*plt_add_meta) (void *handle, const char *key, const char *value); @@ -380,11 +389,13 @@ typedef struct { int (*plt_find_meta_int) (void *handle, const char *key, int def); float (*plt_find_meta_float) (void *handle, const char *key, float def); void (*plt_delete_all_meta) (void *handle); - // playlist control + + // playlist locking void (*pl_lock) (void); void (*pl_unlock) (void); void (*plt_lock) (void); void (*plt_unlock) (void); + // playlist tracks access DB_playItem_t * (*pl_item_alloc) (void); DB_playItem_t * (*pl_item_alloc_init) (const char *fname, const char *decoder_id); @@ -455,7 +466,9 @@ typedef struct { void (*pl_copy_items) (int iter, int plt_from, DB_playItem_t *before, uint32_t *indices, int cnt); void (*pl_search_reset) (void); void (*pl_search_process) (const char *text); + // direct access to metadata structures + // not thread-safe, make sure to wrap with pl_lock/pl_unlock DB_metaInfo_t * (*pl_get_metadata_head) (DB_playItem_t *it); // returns head of metadata linked list void (*pl_delete_metadata) (DB_playItem_t *it, DB_metaInfo_t *meta); @@ -467,9 +480,10 @@ typedef struct { void (*pl_delete_meta) (DB_playItem_t *it, const char *key); // this function is not thread-safe - // make sure you put it into pl_lock/unlock block + // make sure to wrap it with pl_lock/pl_unlock block const char *(*pl_find_meta) (DB_playItem_t *it, const char *key); + // following functions are thread-safe int (*pl_find_meta_int) (DB_playItem_t *it, const char *key, int def); float (*pl_find_meta_float) (DB_playItem_t *it, const char *key, float def); void (*pl_replace_meta) (DB_playItem_t *it, const char *key, const char *value); @@ -490,15 +504,18 @@ typedef struct { void (*pl_playqueue_pop) (void); void (*pl_playqueue_remove) (DB_playItem_t *it); int (*pl_playqueue_test) (DB_playItem_t *it); + // cuesheet support DB_playItem_t *(*pl_insert_cue_from_buffer) (DB_playItem_t *after, DB_playItem_t *origin, const uint8_t *buffer, int buffersize, int numsamples, int samplerate); DB_playItem_t * (*pl_insert_cue) (DB_playItem_t *after, DB_playItem_t *origin, int numsamples, int samplerate); + // volume control void (*volume_set_db) (float dB); float (*volume_get_db) (void); void (*volume_set_amp) (float amp); float (*volume_get_amp) (void); float (*volume_get_min_db) (void); + // junk reading/writing int (*junk_id3v1_read) (DB_playItem_t *it, DB_FILE *fp); int (*junk_id3v1_find) (DB_FILE *fp); @@ -529,6 +546,7 @@ typedef struct { int (*junk_recode) (const char *in, int inlen, char *out, int outlen, const char *cs); int (*junk_iconv) (const char *in, int inlen, char *out, int outlen, const char *cs_in, const char *cs_out); int (*junk_rewrite_tags) (DB_playItem_t *it, uint32_t flags, int id3v2_version, const char *id3v1_encoding); + // vfs DB_FILE* (*fopen) (const char *fname); void (*fclose) (DB_FILE *f); @@ -540,10 +558,21 @@ typedef struct { const char *(*fget_content_type) (DB_FILE *stream); void (*fset_track) (DB_FILE *stream, DB_playItem_t *it); void (*fabort) (DB_FILE *stream); + // message passing int (*sendmessage) (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); + // configuration access - const char * (*conf_get_str) (const char *key, const char *def); + // + // conf_get_str_fast is not thread-safe, and + // must only be used from within conf_lock/conf_unlock block + // it should be preferred for fast non-blocking lookups + // + // all the other config access functions are thread safe + void (*conf_lock) (void); + void (*conf_unlock) (void); + const char * (*conf_get_str_fast) (const char *key, const char *def); + void (*conf_get_str) (const char *key, const char *def, char *buffer, int buffer_size); float (*conf_get_float) (const char *key, float def); int (*conf_get_int) (const char *key, int def); int64_t (*conf_get_int64) (const char *key, int64_t def); @@ -554,6 +583,7 @@ typedef struct { DB_conf_item_t * (*conf_find) (const char *group, DB_conf_item_t *prev); void (*conf_remove_items) (const char *key); int (*conf_save) (void); + // plugin communication struct DB_decoder_s **(*plug_get_decoder_list) (void); struct DB_vfs_s **(*plug_get_vfs_list) (void); @@ -565,10 +595,12 @@ typedef struct { const char * (*plug_get_decoder_id) (const char *id); void (*plug_remove_decoder_id) (const char *id); struct DB_plugin_s *(*plug_get_for_id) (const char *id); + // plugin events void (*plug_trigger_event_trackchange) (DB_playItem_t *from, DB_playItem_t *to); void (*plug_trigger_event_trackinfochanged) (DB_playItem_t *track); void (*plug_trigger_event_playlistchanged) (void); + // misc utilities int (*is_local_file) (const char *fname); // returns 1 for local filename, 0 otherwise @@ -220,7 +220,8 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi } if (parg < pend) { if (conf_get_int ("cli_add_to_specific_playlist", 1)) { - const char *str = conf_get_str ("cli_add_playlist_name", "Default"); + char str[200]; + conf_get_str ("cli_add_playlist_name", "Default", str, sizeof (str)); int idx = plt_find (str); if (idx < 0) { idx = plt_add (plt_get_count (), str); @@ -779,6 +780,7 @@ main (int argc, char *argv[]) { pl_init (); + conf_init (); conf_load (); // required by some plugins at startup conf_set_str ("deadbeef_version", VERSION); @@ -257,6 +257,9 @@ static DB_functions_t deadbeef_api = { // message passing .sendmessage = messagepump_push, // configuration access + .conf_lock = conf_lock, + .conf_unlock = conf_unlock, + .conf_get_str_fast = conf_get_str_fast, .conf_get_str = conf_get_str, .conf_get_float = conf_get_float, .conf_get_int = conf_get_int, @@ -665,7 +668,8 @@ load_plugin (const char *plugdir, char *d_name, int l) { static int load_gui_plugin (const char **plugdirs) { - const char *conf_gui_plug = conf_get_str ("gui_plugin", "GTK2"); + char conf_gui_plug[100]; + conf_get_str ("gui_plugin", "GTK2", conf_gui_plug, sizeof (conf_gui_plug)); char name[100]; // try to load selected plugin @@ -706,7 +710,8 @@ load_gui_plugin (const char **plugdirs) { int load_plugin_dir (const char *plugdir) { int n = 0; - const char *conf_blacklist_plugins = conf_get_str ("blacklist_plugins", ""); + char conf_blacklist_plugins[1000]; + conf_get_str ("blacklist_plugins", "", conf_blacklist_plugins, sizeof (conf_blacklist_plugins)); trace ("loading plugins from %s\n", plugdir); struct dirent **namelist = NULL; n = scandir (plugdir, &namelist, NULL, dirent_alphasort); @@ -1128,7 +1133,8 @@ plug_select_output (void) { #ifdef ANDROID return 0; #else - const char *outplugname = conf_get_str ("output_plugin", _("ALSA output plugin")); + char outplugname[100]; + conf_get_str ("output_plugin", "ALSA output plugin", outplugname, sizeof (outplugname)); for (int i = 0; g_output_plugins[i]; i++) { DB_output_t *p = g_output_plugins[i]; if (!strcmp (p->plugin.name, outplugname)) { @@ -1166,7 +1172,8 @@ plug_reinit_sound (void) { } if (plug_select_output () < 0) { - const char *outplugname = conf_get_str ("output_plugin", "ALSA output plugin"); + char outplugname[100]; + conf_get_str ("output_plugin", "ALSA output plugin", outplugname, sizeof (outplugname)); trace ("failed to select output plugin %s\nreverted to %s\n", outplugname, prev->plugin.name); output_plugin = prev; } diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c index ed4ed014..6d619cf1 100644 --- a/plugins/alsa/alsa.c +++ b/plugins/alsa/alsa.c @@ -341,7 +341,7 @@ palsa_init (void) { mutex = 0; // get and cache conf variables - strcpy (conf_alsa_soundcard, deadbeef->conf_get_str ("alsa_soundcard", "default")); + deadbeef->conf_get_str ("alsa_soundcard", "default", conf_alsa_soundcard, sizeof (conf_alsa_soundcard)); trace ("alsa_soundcard: %s\n", conf_alsa_soundcard); snd_pcm_sw_params_t *sw_params = NULL; @@ -682,7 +682,8 @@ palsa_callback (char *stream, int len) { static int palsa_configchanged (DB_event_t *ev, uintptr_t data) { - const char *alsa_soundcard = deadbeef->conf_get_str ("alsa_soundcard", "default"); + deadbeef->conf_lock (); + const char *alsa_soundcard = deadbeef->conf_get_str_fast ("alsa_soundcard", "default"); int buffer = deadbeef->conf_get_int ("alsa.buffer", DEFAULT_BUFFER_SIZE); int period = deadbeef->conf_get_int ("alsa.period", DEFAULT_PERIOD_SIZE); if (audio && @@ -692,6 +693,7 @@ palsa_configchanged (DB_event_t *ev, uintptr_t data) { trace ("alsa: config option changed, restarting\n"); deadbeef->sendmessage (M_REINIT_SOUND, 0, 0, 0); } + deadbeef->conf_unlock (); return 0; } diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index af154c97..fffc701e 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -722,9 +722,9 @@ artwork_on_configchanged (DB_event_t *ev, uintptr_t data) { int new_artwork_enable_local = deadbeef->conf_get_int ("artwork.enable_localfolder", 1); int new_artwork_enable_lfm = deadbeef->conf_get_int ("artwork.enable_lastfm", 0); int new_artwork_enable_aao = deadbeef->conf_get_int ("artwork.enable_albumartorg", 0); + char new_artwork_filemask[200]; - strncpy (new_artwork_filemask, deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK), sizeof (new_artwork_filemask)); - new_artwork_filemask[sizeof(new_artwork_filemask)-1] = 0; + deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK, new_artwork_filemask, sizeof (new_artwork_filemask)); if (new_artwork_enable_embedded != artwork_enable_embedded || new_artwork_enable_local != artwork_enable_local @@ -749,7 +749,9 @@ artwork_on_configchanged (DB_event_t *ev, uintptr_t data) { static int artwork_plugin_start (void) { - const char *def_art = deadbeef->conf_get_str ("gtkui.nocover_pixmap", NULL); + deadbeef->conf_lock (); + + const char *def_art = deadbeef->conf_get_str_fast ("gtkui.nocover_pixmap", NULL); if (!def_art) { snprintf (default_cover, sizeof (default_cover), "%s/noartwork.jpg", deadbeef->get_pixmap_dir ()); } @@ -764,7 +766,10 @@ artwork_plugin_start (void) artwork_enable_aao = deadbeef->conf_get_int ("artwork.enable_albumartorg", 0); artwork_reset_time = deadbeef->conf_get_int64 ("artwork.cache_reset_time", 0); - strncpy (artwork_filemask, deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK), sizeof (artwork_filemask)); + deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK, artwork_filemask, sizeof (artwork_filemask)); + + deadbeef->conf_unlock (); + artwork_filemask[sizeof(artwork_filemask)-1] = 0; deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (artwork_on_configchanged), 0); diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c index 55352e97..b49c0cea 100644 --- a/plugins/cdda/cdda.c +++ b/plugins/cdda/cdda.c @@ -243,7 +243,8 @@ resolve_disc (CdIo_t *cdio) conn = cddb_new(); - cddb_set_server_name (conn, deadbeef->conf_get_str ("cdda.freedb.host", DEFAULT_SERVER)); + deadbeef->conf_lock (); + cddb_set_server_name (conn, deadbeef->conf_get_str_fast ("cdda.freedb.host", DEFAULT_SERVER)); cddb_set_server_port (conn, deadbeef->conf_get_int ("cdda.freedb.port", DEFAULT_PORT)); if (!deadbeef->conf_get_int ("cdda.protocol", DEFAULT_PROTOCOL)) @@ -252,9 +253,10 @@ resolve_disc (CdIo_t *cdio) if (deadbeef->conf_get_int ("network.proxy", 0)) { cddb_set_server_port(conn, deadbeef->conf_get_int ("network.proxy.port", 8080)); - cddb_set_server_name(conn, deadbeef->conf_get_str ("network.proxy.address", "")); + cddb_set_server_name(conn, deadbeef->conf_get_str_fast ("network.proxy.address", "")); } } + deadbeef->conf_unlock (); int matches = cddb_query (conn, disc); if (matches == -1) diff --git a/plugins/ffmpeg/ffmpeg.c b/plugins/ffmpeg/ffmpeg.c index 6872db8a..d28b54b4 100644 --- a/plugins/ffmpeg/ffmpeg.c +++ b/plugins/ffmpeg/ffmpeg.c @@ -674,7 +674,8 @@ static URLProtocol vfswrapper = { static void ffmpeg_init_exts (void) { - const char *new_exts = deadbeef->conf_get_str ("ffmpeg.extensions", DEFAULT_EXTS); + deadbeef->conf_lock (); + const char *new_exts = deadbeef->conf_get_str_fast ("ffmpeg.extensions", DEFAULT_EXTS); for (int i = 0; exts[i]; i++) { free (exts[i]); } @@ -702,6 +703,7 @@ ffmpeg_init_exts (void) { new_exts = e+1; } exts[n] = NULL; + deadbeef->conf_unlock (); } static int diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index 00ff70c6..71cf1bca 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -145,7 +145,9 @@ on_open_activate (GtkMenuItem *menuitem, gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), TRUE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); @@ -179,7 +181,9 @@ on_add_files_activate (GtkMenuItem *menuitem, gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), TRUE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); @@ -225,7 +229,9 @@ on_add_folders_activate (GtkMenuItem *menuitem, gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), TRUE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); @@ -1127,7 +1133,9 @@ on_custom2_activate (GtkMenuItem *menuitem, GtkEntry *entry = GTK_ENTRY (lookup_widget (dlg, "sortfmt")); gtk_combo_box_set_active (combo, deadbeef->conf_get_int ("gtkui.sortby_order", 0)); - gtk_entry_set_text (entry, deadbeef->conf_get_str ("gtkui.sortby_fmt", "")); + deadbeef->conf_lock (); + gtk_entry_set_text (entry, deadbeef->conf_get_str_fast ("gtkui.sortby_fmt", "")); + deadbeef->conf_unlock (); int r = gtk_dialog_run (GTK_DIALOG (dlg)); diff --git a/plugins/gtkui/dspconfig.c b/plugins/gtkui/dspconfig.c index 75f9999c..268f1b16 100644 --- a/plugins/gtkui/dspconfig.c +++ b/plugins/gtkui/dspconfig.c @@ -112,7 +112,9 @@ dsp_setup_init (GtkWidget *_prefwin) { GtkWidget *combobox = lookup_widget (prefwin, "dsp_preset"); GtkWidget *entry = gtk_bin_get_child (GTK_BIN (combobox)); if (entry) { - gtk_entry_set_text (GTK_ENTRY (entry), deadbeef->conf_get_str ("gtkui.conf_dsp_preset", "")); + deadbeef->conf_lock (); + gtk_entry_set_text (GTK_ENTRY (entry), deadbeef->conf_get_str_fast ("gtkui.conf_dsp_preset", "")); + deadbeef->conf_unlock (); } // fill list of presets diff --git a/plugins/gtkui/eq.c b/plugins/gtkui/eq.c index 3a5932b9..bfb77703 100644 --- a/plugins/gtkui/eq.c +++ b/plugins/gtkui/eq.c @@ -189,7 +189,9 @@ on_load_preset_clicked (GtkMenuItem *menuitem, gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), FALSE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); @@ -252,7 +254,10 @@ on_import_fb2k_preset_clicked (GtkButton *button, gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), FALSE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); + int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); diff --git a/plugins/gtkui/gdkdrawing.c b/plugins/gtkui/gdkdrawing.c index e9d496f4..cb795ccb 100644 --- a/plugins/gtkui/gdkdrawing.c +++ b/plugins/gtkui/gdkdrawing.c @@ -227,6 +227,7 @@ gtkui_override_tabstrip_colors (void) { void gtkui_init_theme_colors (void) { + deadbeef->conf_lock (); override_listview_colors= deadbeef->conf_get_int ("gtkui.override_listview_colors", 0); override_bar_colors = deadbeef->conf_get_int ("gtkui.override_bar_colors", 0); override_tabstrip_colors = deadbeef->conf_get_int ("gtkui.override_tabstrip_colors", 0); @@ -242,11 +243,11 @@ gtkui_init_theme_colors (void) { } else { snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->base[GTK_STATE_SELECTED].red, style->base[GTK_STATE_SELECTED].green, style->base[GTK_STATE_SELECTED].blue); - clr = deadbeef->conf_get_str ("gtkui.color.bar_foreground", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.bar_foreground", color_text); sscanf (clr, "%hd %hd %hd", >kui_bar_foreground_color.red, >kui_bar_foreground_color.green, >kui_bar_foreground_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->fg[GTK_STATE_NORMAL].red, style->fg[GTK_STATE_NORMAL].green, style->fg[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.bar_background", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.bar_background", color_text); sscanf (clr, "%hd %hd %hd", >kui_bar_background_color.red, >kui_bar_background_color.green, >kui_bar_background_color.blue); } @@ -260,23 +261,23 @@ gtkui_init_theme_colors (void) { } else { snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->dark[GTK_STATE_NORMAL].red, style->dark[GTK_STATE_NORMAL].green, style->dark[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.tabstrip_dark", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.tabstrip_dark", color_text); sscanf (clr, "%hd %hd %hd", >kui_tabstrip_dark_color.red, >kui_tabstrip_dark_color.green, >kui_tabstrip_dark_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->mid[GTK_STATE_NORMAL].red, style->mid[GTK_STATE_NORMAL].green, style->mid[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.tabstrip_mid", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.tabstrip_mid", color_text); sscanf (clr, "%hd %hd %hd", >kui_tabstrip_mid_color.red, >kui_tabstrip_mid_color.green, >kui_tabstrip_mid_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->light[GTK_STATE_NORMAL].red, style->light[GTK_STATE_NORMAL].green, style->light[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.tabstrip_light", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.tabstrip_light", color_text); sscanf (clr, "%hd %hd %hd", >kui_tabstrip_light_color.red, >kui_tabstrip_light_color.green, >kui_tabstrip_light_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->bg[GTK_STATE_NORMAL].red, style->bg[GTK_STATE_NORMAL].green, style->bg[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.tabstrip_base", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.tabstrip_base", color_text); sscanf (clr, "%hd %hd %hd", >kui_tabstrip_base_color.red, >kui_tabstrip_base_color.green, >kui_tabstrip_base_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->text[GTK_STATE_NORMAL].red, style->text[GTK_STATE_NORMAL].green, style->text[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.tabstrip_text", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.tabstrip_text", color_text); sscanf (clr, "%hd %hd %hd", >kui_tabstrip_text_color.red, >kui_tabstrip_text_color.green, >kui_tabstrip_text_color.blue); } @@ -290,29 +291,30 @@ gtkui_init_theme_colors (void) { } else { snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->light[GTK_STATE_NORMAL].red, style->light[GTK_STATE_NORMAL].green, style->light[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_even_row", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_even_row", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_even_row_color.red, >kui_listview_even_row_color.green, >kui_listview_even_row_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->mid[GTK_STATE_NORMAL].red, style->mid[GTK_STATE_NORMAL].green, style->mid[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_odd_row", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_odd_row", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_odd_row_color.red, >kui_listview_odd_row_color.green, >kui_listview_odd_row_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->mid[GTK_STATE_NORMAL].red, style->mid[GTK_STATE_NORMAL].green, style->mid[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_selection", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_selection", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_selection_color.red, >kui_listview_selection_color.green, >kui_listview_selection_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->fg[GTK_STATE_NORMAL].red, style->fg[GTK_STATE_NORMAL].green, style->fg[GTK_STATE_NORMAL].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_text", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_text", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_text_color.red, >kui_listview_text_color.green, >kui_listview_text_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->fg[GTK_STATE_SELECTED].red, style->fg[GTK_STATE_SELECTED].green, style->fg[GTK_STATE_SELECTED].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_selected_text", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_selected_text", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_selected_text_color.red, >kui_listview_selected_text_color.green, >kui_listview_selected_text_color.blue); snprintf (color_text, sizeof (color_text), "%hd %hd %hd", style->fg[GTK_STATE_SELECTED].red, style->fg[GTK_STATE_SELECTED].green, style->fg[GTK_STATE_SELECTED].blue); - clr = deadbeef->conf_get_str ("gtkui.color.listview_cursor", color_text); + clr = deadbeef->conf_get_str_fast ("gtkui.color.listview_cursor", color_text); sscanf (clr, "%hd %hd %hd", >kui_listview_cursor_color.red, >kui_listview_cursor_color.green, >kui_listview_cursor_color.blue); } + deadbeef->conf_unlock (); } void diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index f27f1ecb..fac73135 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -119,6 +119,7 @@ update_songinfo (gpointer ctx) { if (!gtk_widget_get_visible (mainwin) || iconified) { return FALSE; } + DB_output_t *output = deadbeef->get_output (); char sbtext_new[512] = "-"; float songpos = last_songpos; @@ -144,7 +145,7 @@ update_songinfo (gpointer ctx) { float duration = track ? deadbeef->pl_get_item_duration (track) : -1; - if (deadbeef->get_output ()->state () == OUTPUT_STATE_STOPPED || !track || !c) { + if (!output || (output->state () == OUTPUT_STATE_STOPPED || !track || !c)) { snprintf (sbtext_new, sizeof (sbtext_new), _("Stopped | %d tracks | %s total playtime"), deadbeef->pl_getcount (PL_MAIN), totaltime_str); songpos = 0; } @@ -397,13 +398,13 @@ gtkui_set_titlebar (DB_playItem_t *it) { else { deadbeef->pl_item_ref (it); } + char fmt[500]; char str[600]; - const char *fmt; if (it) { - fmt = deadbeef->conf_get_str ("gtkui.titlebar_playing", "%a - %t - DeaDBeeF-%V"); + deadbeef->conf_get_str ("gtkui.titlebar_playing", "%a - %t - DeaDBeeF-%V", fmt, sizeof (fmt)); } else { - fmt = deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V"); + deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V", fmt, sizeof (fmt)); } deadbeef->pl_format_title (it, -1, str, sizeof (str), -1, fmt); gtk_window_set_title (GTK_WINDOW (mainwin), str); @@ -532,7 +533,7 @@ gtkui_on_playlistswitch (DB_event_t *ev, uintptr_t data) { } static gboolean -gtkui_on_frameupdate (uintptr_t data) { +gtkui_on_frameupdate (gpointer data) { update_songinfo (NULL); return TRUE; @@ -570,7 +571,9 @@ gtkui_update_status_icon (gpointer unused) { // system tray icon traymenu = create_traymenu (); - const char *icon_name = deadbeef->conf_get_str ("gtkui.custom_tray_icon", TRAY_ICON); + char tmp[1000]; + const char *icon_name = tmp; + deadbeef->conf_get_str ("gtkui.custom_tray_icon", TRAY_ICON, tmp, sizeof (tmp)); GtkIconTheme *theme = gtk_icon_theme_get_default(); if (!gtk_icon_theme_has_icon(theme, icon_name)) @@ -669,7 +672,9 @@ save_playlist_as (void) { gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dlg), TRUE); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dlg), "untitled.dbpl"); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.playlist.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); + deadbeef->conf_unlock (); GtkFileFilter* flt; flt = gtk_file_filter_new (); @@ -769,7 +774,9 @@ on_playlist_load_activate (GtkMenuItem *menuitem, GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Load Playlist"), GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.playlist.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); + deadbeef->conf_unlock (); GtkFileFilter* flt; flt = gtk_file_filter_new (); @@ -1044,8 +1051,10 @@ gtkui_thread (void *ctx) { g_timeout_add (100, gtkui_on_frameupdate, NULL); + char fmt[500]; char str[600]; - deadbeef->pl_format_title (NULL, -1, str, sizeof (str), -1, deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V")); + deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V", fmt, sizeof (fmt)); + deadbeef->pl_format_title (NULL, -1, str, sizeof (str), -1, fmt); gtk_window_set_title (GTK_WINDOW (mainwin), str); gtk_initialized = 1; diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c index 9a774eb4..f4616f8d 100644 --- a/plugins/gtkui/mainplaylist.c +++ b/plugins/gtkui/mainplaylist.c @@ -325,7 +325,9 @@ main_playlist_init (GtkWidget *widget) { g_object_set_property (G_OBJECT (widget), "has-tooltip", &value); g_signal_connect (G_OBJECT (widget), "query-tooltip", G_CALLBACK (playlist_tooltip_handler), NULL); } - strncpy (group_by_str, deadbeef->conf_get_str ("playlist.group_by", ""), sizeof (group_by_str)); + deadbeef->conf_lock (); + strncpy (group_by_str, deadbeef->conf_get_str_fast ("playlist.group_by", ""), sizeof (group_by_str)); + deadbeef->conf_unlock (); group_by_str[sizeof (group_by_str)-1] = 0; } diff --git a/plugins/gtkui/pluginconf.c b/plugins/gtkui/pluginconf.c index 6e4aeff4..c7c73ae8 100644 --- a/plugins/gtkui/pluginconf.c +++ b/plugins/gtkui/pluginconf.c @@ -43,7 +43,9 @@ on_prop_browse_file (GtkButton *button, gpointer user_data) { gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), FALSE); // restore folder - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str ("filechooser.lastdir", "")); + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.lastdir", "")); + deadbeef->conf_unlock (); int response = gtk_dialog_run (GTK_DIALOG (dlg)); // store folder gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index 7b67a0a8..cb1985c0 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -59,9 +59,11 @@ gtk_enum_sound_callback (const char *name, const char *desc, void *userdata) { GtkComboBox *combobox = GTK_COMBO_BOX (userdata); gtk_combo_box_append_text (combobox, desc); - if (!strcmp (deadbeef->conf_get_str ("alsa_soundcard", "default"), name)) { + deadbeef->conf_lock (); + if (!strcmp (deadbeef->conf_get_str_fast ("alsa_soundcard", "default"), name)) { gtk_combo_box_set_active (combobox, num_alsa_devices); } + deadbeef->conf_unlock (); strncpy (alsa_device_names[num_alsa_devices], name, 63); alsa_device_names[num_alsa_devices][63] = 0; @@ -73,15 +75,19 @@ preferences_fill_soundcards (void) { if (!prefwin) { return; } - const char *s = deadbeef->conf_get_str ("alsa_soundcard", "default"); GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (prefwin, "pref_soundcard")); GtkTreeModel *mdl = gtk_combo_box_get_model (combobox); gtk_list_store_clear (GTK_LIST_STORE (mdl)); gtk_combo_box_append_text (combobox, _("Default Audio Device")); + + deadbeef->conf_lock (); + const char *s = deadbeef->conf_get_str_fast ("alsa_soundcard", "default"); if (!strcmp (s, "default")) { gtk_combo_box_set_active (combobox, 0); } + deadbeef->conf_unlock (); + num_alsa_devices = 1; strcpy (alsa_device_names[0], "default"); if (deadbeef->get_output ()->enum_soundcards) { @@ -455,15 +461,16 @@ on_preferences_activate (GtkMenuItem *menuitem, if (prefwin) { return; } + deadbeef->conf_lock (); GtkWidget *w = prefwin = create_prefwin (); gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (mainwin)); GtkComboBox *combobox = NULL; // output plugin selection - const char *outplugname = deadbeef->conf_get_str ("output_plugin", _("ALSA output plugin")); combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_output_plugin")); + const char *outplugname = deadbeef->conf_get_str_fast ("output_plugin", _("ALSA output plugin")); DB_output_t **out_plugs = deadbeef->plug_get_output_list (); for (int i = 0; out_plugs[i]; i++) { gtk_combo_box_append_text (combobox, out_plugs[i]->plugin.name); @@ -515,14 +522,14 @@ on_preferences_activate (GtkMenuItem *menuitem, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "auto_name_playlist_from_folder")), deadbeef->conf_get_int ("gtkui.name_playlist_from_folder", 0)); // titlebar text - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "titlebar_format_playing")), deadbeef->conf_get_str ("gtkui.titlebar_playing", "%a - %t - DeaDBeeF-%V")); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "titlebar_format_stopped")), deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "titlebar_format_playing")), deadbeef->conf_get_str_fast ("gtkui.titlebar_playing", "%a - %t - DeaDBeeF-%V")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "titlebar_format_stopped")), deadbeef->conf_get_str_fast ("gtkui.titlebar_stopped", "DeaDBeeF-%V")); // cli playlist int active = deadbeef->conf_get_int ("cli_add_to_specific_playlist", 1); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (prefwin, "cli_add_to_playlist")), active); gtk_widget_set_sensitive (lookup_widget (prefwin, "cli_playlist_name"), active); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (prefwin, "cli_playlist_name")), deadbeef->conf_get_str ("cli_add_playlist_name", "Default")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (prefwin, "cli_playlist_name")), deadbeef->conf_get_str_fast ("cli_add_playlist_name", "Default")); // resume last session gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "resume_last_session")), deadbeef->conf_get_int ("resume_last_session", 0)); @@ -532,7 +539,7 @@ on_preferences_activate (GtkMenuItem *menuitem, const char **names = deadbeef->plug_get_gui_names (); for (int i = 0; names[i]; i++) { gtk_combo_box_append_text (combobox, names[i]); - if (!strcmp (names[i], deadbeef->conf_get_str ("gui_plugin", "GTK2"))) { + if (!strcmp (names[i], deadbeef->conf_get_str_fast ("gui_plugin", "GTK2"))) { gtk_combo_box_set_active (combobox, i); } } @@ -557,10 +564,10 @@ on_preferences_activate (GtkMenuItem *menuitem, // network gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "pref_network_enableproxy")), deadbeef->conf_get_int ("network.proxy", 0)); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyaddress")), deadbeef->conf_get_str ("network.proxy.address", "")); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyport")), deadbeef->conf_get_str ("network.proxy.port", "8080")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyaddress")), deadbeef->conf_get_str_fast ("network.proxy.address", "")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyport")), deadbeef->conf_get_str_fast ("network.proxy.port", "8080")); combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_network_proxytype")); - const char *type = deadbeef->conf_get_str ("network.proxy.type", "HTTP"); + const char *type = deadbeef->conf_get_str_fast ("network.proxy.type", "HTTP"); if (!strcasecmp (type, "HTTP")) { gtk_combo_box_set_active (combobox, 0); } @@ -579,8 +586,8 @@ on_preferences_activate (GtkMenuItem *menuitem, else if (!strcasecmp (type, "SOCKS5_HOSTNAME")) { gtk_combo_box_set_active (combobox, 5); } - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxyuser")), deadbeef->conf_get_str ("network.proxy.username", "")); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxypassword")), deadbeef->conf_get_str ("network.proxy.password", "")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxyuser")), deadbeef->conf_get_str_fast ("network.proxy.username", "")); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxypassword")), deadbeef->conf_get_str_fast ("network.proxy.password", "")); // list of plugins GtkTreeView *tree = GTK_TREE_VIEW (lookup_widget (w, "pref_pluginlist")); @@ -624,6 +631,7 @@ on_preferences_activate (GtkMenuItem *menuitem, prefwin_add_hotkeys_tab (prefwin); } + deadbeef->conf_unlock (); gtk_dialog_run (GTK_DIALOG (prefwin)); dsp_setup_free (); gtk_widget_destroy (prefwin); @@ -638,11 +646,13 @@ on_pref_soundcard_changed (GtkComboBox *combobox, { int active = gtk_combo_box_get_active (combobox); if (active >= 0 && active < num_alsa_devices) { - const char *soundcard = deadbeef->conf_get_str ("alsa_soundcard", "default"); + deadbeef->conf_lock (); + const char *soundcard = deadbeef->conf_get_str_fast ("alsa_soundcard", "default"); if (strcmp (soundcard, alsa_device_names[active])) { deadbeef->conf_set_str ("alsa_soundcard", alsa_device_names[active]); deadbeef->sendmessage (M_CONFIG_CHANGED, 0, 0, 0); } + deadbeef->conf_unlock (); } } @@ -650,13 +660,14 @@ void on_pref_output_plugin_changed (GtkComboBox *combobox, gpointer user_data) { - const char *outplugname = deadbeef->conf_get_str ("output_plugin", _("ALSA output plugin")); int active = gtk_combo_box_get_active (combobox); DB_output_t **out_plugs = deadbeef->plug_get_output_list (); DB_output_t *prev = NULL; DB_output_t *new = NULL; + deadbeef->conf_lock (); + const char *outplugname = deadbeef->conf_get_str_fast ("output_plugin", _("ALSA output plugin")); for (int i = 0; out_plugs[i]; i++) { if (!strcmp (out_plugs[i]->plugin.name, outplugname)) { prev = out_plugs[i]; @@ -665,6 +676,7 @@ on_pref_output_plugin_changed (GtkComboBox *combobox, new = out_plugs[i]; } } + deadbeef->conf_unlock (); if (!new) { fprintf (stderr, "failed to find output plugin selected in preferences window\n"); @@ -781,7 +793,7 @@ on_pref_pluginlist_cursor_changed (GtkTreeView *treeview, void gtkui_conf_get_str (const char *key, char *value, int len, const char *def) { - strcpy (value, deadbeef->conf_get_str (key, def)); + deadbeef->conf_get_str (key, def, value, len); } void diff --git a/plugins/gtkui/tagwritersettings.c b/plugins/gtkui/tagwritersettings.c index 8451bd44..ede3d447 100644 --- a/plugins/gtkui/tagwritersettings.c +++ b/plugins/gtkui/tagwritersettings.c @@ -39,7 +39,8 @@ run_tagwriter_settings (GtkWidget *parentwindow) { int write_id3v1 = deadbeef->conf_get_int ("mp3.write_id3v1", 1); int write_apev2 = deadbeef->conf_get_int ("mp3.write_apev2", 0); int id3v2_version = deadbeef->conf_get_int ("mp3.id3v2_version", 3); - const char *id3v1_encoding = deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1"); + char id3v1_encoding[50]; + deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1", id3v1_encoding, sizeof (id3v1_encoding)); int ape_strip_id3v2 = deadbeef->conf_get_int ("ape.strip_id3v2", 0); int ape_strip_apev2 = deadbeef->conf_get_int ("ape.strip_apev2", 0); int ape_write_id3v2 = deadbeef->conf_get_int ("ape.write_id3v2", 0); diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 68f1adc0..b29355b1 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -67,13 +67,15 @@ static DB_playItem_t *lfm_subm_queue[LFM_SUBMISSION_QUEUE_SIZE]; static void lfm_update_auth (void) { - const char *user = deadbeef->conf_get_str ("lastfm.login", ""); - const char *pass = deadbeef->conf_get_str ("lastfm.password", ""); + deadbeef->conf_lock (); + const char *user = deadbeef->conf_get_str_fast ("lastfm.login", ""); + const char *pass = deadbeef->conf_get_str_fast ("lastfm.password", ""); if (strcmp (user, lfm_user) || strcmp (pass, lfm_pass)) { strcpy (lfm_user, user); strcpy (lfm_pass, pass); lfm_sess[0] = 0; } + deadbeef->conf_unlock (); } static size_t @@ -128,9 +130,10 @@ curl_req_send (const char *req, const char *post) { curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(post)); } if (deadbeef->conf_get_int ("network.proxy", 0)) { - curl_easy_setopt (curl, CURLOPT_PROXY, deadbeef->conf_get_str ("network.proxy.address", "")); + deadbeef->conf_lock (); + curl_easy_setopt (curl, CURLOPT_PROXY, deadbeef->conf_get_str_fast ("network.proxy.address", "")); curl_easy_setopt (curl, CURLOPT_PROXYPORT, deadbeef->conf_get_int ("network.proxy.port", 8080)); - const char *type = deadbeef->conf_get_str ("network.proxy.type", "HTTP"); + const char *type = deadbeef->conf_get_str_fast ("network.proxy.type", "HTTP"); int curlproxytype = CURLPROXY_HTTP; if (!strcasecmp (type, "HTTP")) { curlproxytype = CURLPROXY_HTTP; @@ -158,8 +161,8 @@ curl_req_send (const char *req, const char *post) { #endif curl_easy_setopt (curl, CURLOPT_PROXYTYPE, curlproxytype); - const char *proxyuser = deadbeef->conf_get_str ("network.proxy.username", ""); - const char *proxypass = deadbeef->conf_get_str ("network.proxy.password", ""); + const char *proxyuser = deadbeef->conf_get_str_fast ("network.proxy.username", ""); + const char *proxypass = deadbeef->conf_get_str_fast ("network.proxy.password", ""); if (*proxyuser || *proxypass) { #if LIBCURL_VERSION_MINOR >= 19 && LIBCURL_VERSION_PATCH >= 1 curl_easy_setopt (curl, CURLOPT_PROXYUSERNAME, proxyuser); @@ -170,6 +173,7 @@ curl_req_send (const char *req, const char *post) { curl_easy_setopt (curl, CURLOPT_PROXYUSERPWD, pwd); #endif } + deadbeef->conf_unlock (); } int status = curl_easy_perform(curl); curl_easy_cleanup (curl); @@ -207,12 +211,14 @@ auth (void) { deadbeef->md5 (sig, token, strlen (token)); deadbeef->md5_to_str (token, sig); - const char *scrobbler_url = deadbeef->conf_get_str ("lastfm.scrobbler_url", SCROBBLER_URL_LFM); + deadbeef->conf_lock (); + const char *scrobbler_url = deadbeef->conf_get_str_fast ("lastfm.scrobbler_url", SCROBBLER_URL_LFM); #if LFM_TESTMODE snprintf (req, sizeof (req), "%s/?hs=true&p=1.2.1&c=tst&v=1.0&u=%s&t=%d&a=%s", scrobbler_url, lfm_user, (int)timestamp, token); #else snprintf (req, sizeof (req), "%s/?hs=true&p=1.2.1&c=%s&v=%d.%d&u=%s&t=%d&a=%s", scrobbler_url, LFM_CLIENTID, plugin.plugin.version_major, plugin.plugin.version_minor, lfm_user, (int)timestamp, token); #endif + deadbeef->conf_unlock (); // handshake int status = curl_req_send (req, NULL); if (!status) { diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index 29ea88b9..9e51ae6d 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -1397,7 +1397,8 @@ cmp3_write_metadata (DB_playItem_t *it) { if (id3v2_version != 3 && id3v2_version != 4) { id3v2_version = 3; } - const char *id3v1_encoding = deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1"); + char id3v1_encoding[50]; + deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1", id3v1_encoding, sizeof (id3v1_encoding)); return deadbeef->junk_rewrite_tags (it, junk_flags, id3v2_version, id3v1_encoding); } diff --git a/plugins/notify/notify.c b/plugins/notify/notify.c index 6bd42ab8..84669594 100644 --- a/plugins/notify/notify.c +++ b/plugins/notify/notify.c @@ -184,8 +184,10 @@ cover_avail_callback (const char *fname, const char *artist, const char *album, static void show_notification (DB_playItem_t *track) { char title[1024]; char content[1024]; - deadbeef->pl_format_title (track, -1, title, sizeof (title), -1, deadbeef->conf_get_str ("notify.format", NOTIFY_DEFAULT_TITLE)); - deadbeef->pl_format_title (track, -1, content, sizeof (content), -1, deadbeef->conf_get_str ("notify.format_content", NOTIFY_DEFAULT_CONTENT)); + deadbeef->conf_lock (); + deadbeef->pl_format_title (track, -1, title, sizeof (title), -1, deadbeef->conf_get_str_fast ("notify.format", NOTIFY_DEFAULT_TITLE)); + deadbeef->pl_format_title (track, -1, content, sizeof (content), -1, deadbeef->conf_get_str_fast ("notify.format_content", NOTIFY_DEFAULT_CONTENT)); + deadbeef->conf_unlock (); // escape & // char esc_title[1024]; diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index e2fdf3ee..1570c2a0 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -309,19 +309,20 @@ oss_get_state (void) { static int oss_configchanged (DB_event_t *ev, uintptr_t data) { - const char *dev = deadbeef->conf_get_str ("oss.device", "/dev/dsp"); + deadbeef->conf_lock (); + const char *dev = deadbeef->conf_get_str_fast ("oss.device", "/dev/dsp"); if (strcmp (dev, oss_device)) { strncpy (oss_device, dev, sizeof (oss_device)-1); trace ("oss: config option changed, restarting\n"); deadbeef->sendmessage (M_REINIT_SOUND, 0, 0, 0); } + deadbeef->conf_unlock (); return 0; } static int oss_plugin_start (void) { - const char *dev = deadbeef->conf_get_str ("oss.device", "/dev/dsp"); - strncpy (oss_device, dev, sizeof (oss_device)-1); + deadbeef->conf_get_str ("oss.device", "/dev/dsp", oss_device, sizeof (oss_device)); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (oss_configchanged), 0); return 0; } diff --git a/plugins/shn/shn.c b/plugins/shn/shn.c index 87440ee2..4a90583c 100644 --- a/plugins/shn/shn.c +++ b/plugins/shn/shn.c @@ -306,8 +306,9 @@ shn_init_decoder (shn_fileinfo_t *info) { static void shn_init_config (void) { shn_cfg.error_output_method = ERROR_OUTPUT_DEVNULL; - strncpy (shn_cfg.seek_tables_path, deadbeef->conf_get_str ("shn.seektable_path", ""), sizeof (shn_cfg.seek_tables_path)); - strncpy (shn_cfg.relative_seek_tables_path, deadbeef->conf_get_str ("shn.relative_seektable_path", "seektables"), sizeof (shn_cfg.relative_seek_tables_path)); + + deadbeef->conf_get_str ("shn.seektable_path", "", shn_cfg.seek_tables_path, sizeof (shn_cfg.seek_tables_path)); + deadbeef->conf_get_str ("shn.relative_seektable_path", "seektables", shn_cfg.relative_seek_tables_path, sizeof (shn_cfg.relative_seek_tables_path)); shn_cfg.verbose = 0; shn_cfg.swap_bytes = deadbeef->conf_get_int ("shn.swap_bytes", 0); } diff --git a/plugins/sid/csid.cpp b/plugins/sid/csid.cpp index dd176e05..ffdd4548 100644 --- a/plugins/sid/csid.cpp +++ b/plugins/sid/csid.cpp @@ -108,8 +108,9 @@ sldb_load() sldb_disable = 1; return; } - const char *conf_hvsc_path = deadbeef->conf_get_str ("hvsc_path", NULL); - if (!conf_hvsc_path) { + char conf_hvsc_path[1000]; + deadbeef->conf_get_str ("hvsc_path", "", conf_hvsc_path, sizeof (conf_hvsc_path)); + if (!conf_hvsc_path[0]) { sldb_disable = 1; return; } diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c index 1117788e..3af4616f 100644 --- a/plugins/sndfile/sndfile.c +++ b/plugins/sndfile/sndfile.c @@ -379,13 +379,14 @@ static const char *filetypes[] = { "WAV", NULL }; static void sndfile_init_exts (void) { - const char *new_exts = deadbeef->conf_get_str ("sndfile.extensions", DEFAULT_EXTS); for (int i = 0; exts[i]; i++) { free (exts[i]); } exts[0] = NULL; int n = 0; + deadbeef->conf_lock (); + const char *new_exts = deadbeef->conf_get_str_fast ("sndfile.extensions", DEFAULT_EXTS); while (*new_exts) { if (n >= EXT_MAX) { fprintf (stderr, "sndfile: too many extensions, max is %d\n", EXT_MAX); @@ -406,6 +407,7 @@ sndfile_init_exts (void) { } new_exts = e+1; } + deadbeef->conf_unlock (); exts[n] = NULL; } diff --git a/plugins/tta/ttaplug.c b/plugins/tta/ttaplug.c index b83e805b..20a0c8a5 100644 --- a/plugins/tta/ttaplug.c +++ b/plugins/tta/ttaplug.c @@ -285,7 +285,8 @@ static int tta_write_metadata (DB_playItem_t *it) { } int id3v2_version = 4; - const char *id3v1_encoding = deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1"); + char id3v1_encoding[50]; + deadbeef->conf_get_str ("mp3.id3v1_encoding", "iso8859-1", id3v1_encoding, sizeof (id3v1_encoding)); return deadbeef->junk_rewrite_tags (it, junk_flags, id3v2_version, id3v1_encoding); } diff --git a/plugins/vfs_curl/vfs_curl.c b/plugins/vfs_curl/vfs_curl.c index 5a2d4ddd..528b3809 100644 --- a/plugins/vfs_curl/vfs_curl.c +++ b/plugins/vfs_curl/vfs_curl.c @@ -558,9 +558,10 @@ http_thread_func (void *ctx) { curl_easy_setopt (curl, CURLOPT_RESUME_FROM, fp->pos); } if (deadbeef->conf_get_int ("network.proxy", 0)) { - curl_easy_setopt (curl, CURLOPT_PROXY, deadbeef->conf_get_str ("network.proxy.address", "")); + deadbeef->conf_lock (); + curl_easy_setopt (curl, CURLOPT_PROXY, deadbeef->conf_get_str_fast ("network.proxy.address", "")); curl_easy_setopt (curl, CURLOPT_PROXYPORT, deadbeef->conf_get_int ("network.proxy.port", 8080)); - const char *type = deadbeef->conf_get_str ("network.proxy.type", "HTTP"); + const char *type = deadbeef->conf_get_str_fast ("network.proxy.type", "HTTP"); int curlproxytype = CURLPROXY_HTTP; if (!strcasecmp (type, "HTTP")) { curlproxytype = CURLPROXY_HTTP; @@ -588,8 +589,8 @@ http_thread_func (void *ctx) { #endif curl_easy_setopt (curl, CURLOPT_PROXYTYPE, curlproxytype); - const char *proxyuser = deadbeef->conf_get_str ("network.proxy.username", ""); - const char *proxypass = deadbeef->conf_get_str ("network.proxy.password", ""); + const char *proxyuser = deadbeef->conf_get_str_fast ("network.proxy.username", ""); + const char *proxypass = deadbeef->conf_get_str_fast ("network.proxy.password", ""); if (*proxyuser || *proxypass) { #if LIBCURL_VERSION_MINOR >= 19 && LIBCURL_VERSION_PATCH >= 1 curl_easy_setopt (curl, CURLOPT_PROXYUSERNAME, proxyuser); @@ -600,6 +601,7 @@ http_thread_func (void *ctx) { curl_easy_setopt (curl, CURLOPT_PROXYUSERPWD, pwd); #endif } + deadbeef->conf_unlock (); } // fp->status = STATUS_INITIAL; trace ("vfs_curl: calling curl_easy_perform (status=%d)...\n", fp->status); diff --git a/plugins/wildmidi/wildmidiplug.c b/plugins/wildmidi/wildmidiplug.c index b12de3f1..fd9a9bbe 100644 --- a/plugins/wildmidi/wildmidiplug.c +++ b/plugins/wildmidi/wildmidiplug.c @@ -131,7 +131,8 @@ wmidi_insert (DB_playItem_t *after, const char *fname) { int wmidi_start (void) { - const char *config_files = deadbeef->conf_get_str ("wildmidi.config", DEFAULT_TIMIDITY_CONFIG); + char config_files[1000]; + deadbeef->conf_get_str ("wildmidi.config", DEFAULT_TIMIDITY_CONFIG, config_files, sizeof (config_files)); char config[1024] = ""; const char *p = config_files; while (p) { @@ -1390,11 +1390,12 @@ streamer_dsp_init (void) { // load legacy eq settings from pre-0.5 if (conf_find ("eq.", NULL)) { eq->enabled = deadbeef->conf_get_int ("eq.enable", 0); - eqplug->set_param (eq, 0, conf_get_str ("eq.preamp", "0")); + char s[50]; + eqplug->set_param (eq, 0, (conf_get_str ("eq.preamp", "0", s, sizeof (s)), s)); for (int i = 0; i < 18; i++) { char key[100]; snprintf (key, sizeof (key), "eq.band%d", i); - eqplug->set_param (eq, 1+i, conf_get_str (key, "0")); + eqplug->set_param (eq, 1+i, (conf_get_str (key, "0", s, sizeof (s)), s)); } // delete obsolete settings conf_remove_items ("eq."); |