]> git.sesse.net Git - vlc/commitdiff
Partially introduce vlc_config_set() to modify module_config_t through a less brittle API
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 15 Dec 2007 20:50:54 +0000 (20:50 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 15 Dec 2007 20:50:54 +0000 (20:50 +0000)
BEWARE: If you have non-recompiled plugins, they WILL crash.

include/vlc_configuration.h
src/config/core.c
src/modules/entry.c

index b0c1d27aa67050452827b1a71406dc06440814a1..da7524996e0bc73d545fe00aa62c6e93a28b101f 100644 (file)
@@ -231,6 +231,22 @@ VLC_EXPORT( vlc_bool_t, __config_ExistIntf,  ( vlc_object_t *, const char * ) );
 #define config_RemoveIntf(a,b) __config_RemoveIntf(VLC_OBJECT(a),b)
 #define config_ExistIntf(a,b) __config_ExistIntf(VLC_OBJECT(a),b)
 
+typedef enum vlc_config_properties
+{
+    /* DO NOT EVER REMOVE, INSERT OR REPLACE ANY ITEM! It would break the ABI!
+     * Append new items at the end ONLY. */
+    VLC_CONFIG_NAME,     /* command line name (args=const char *, vlc_callback_t) */
+    VLC_CONFIG_DESC,     /* description (args=const char *, const char *) */
+    VLC_CONFIG_VALUE,    /* actual value (args=<type>) */
+    VLC_CONFIG_RANGE,    /* minimum value (args=<type>, <type>) */
+    VLC_CONFIG_STEP,     /* interval value (args=<type>) */
+    VLC_CONFIG_ADVANCED, /* enable advanced flag (args=none) */
+    VLC_CONFIG_VOLATILE, /* don't write variable to storage (args=none) */
+    VLC_CONFIG_PRIVATE,  /* hide from user (args=none) */
+} vlc_config_t;
+
+
+VLC_EXPORT( int, vlc_config_set, (module_config_t *, vlc_config_t, ...) );
 
 /*****************************************************************************
  * Macros used to build the configuration structure.
@@ -258,8 +274,8 @@ VLC_EXPORT( vlc_bool_t, __config_ExistIntf,  ( vlc_object_t *, const char * ) );
 
 #define add_typedesc_inner( type, text, longtext ) \
     add_type_inner( type ); \
-    p_config[i_config].psz_text = text; \
-    p_config[i_config].psz_longtext = longtext
+    vlc_config_set (p_config + i_config, VLC_CONFIG_DESC, \
+                    (const char *)(text), (const char *)(longtext))
 
 #define add_typeadv_inner( type, text, longtext, advc ) \
     add_typedesc_inner( type, text, longtext ); \
@@ -267,8 +283,8 @@ VLC_EXPORT( vlc_bool_t, __config_ExistIntf,  ( vlc_object_t *, const char * ) );
 
 #define add_typename_inner( type, name, text, longtext, advc, cb ) \
     add_typeadv_inner( type, text, longtext, advc ); \
-    p_config[i_config].psz_name = name; \
-    p_config[i_config].pf_callback = cb
+    vlc_config_set (p_config + i_config, VLC_CONFIG_NAME, \
+                    (const char *)(name), (vlc_callback_t)(cb))
 
 #define add_string_inner( type, name, text, longtext, advc, cb, v ) \
     add_typename_inner( type, name, text, longtext, advc, cb ); \
index cf83e7576a3fad6a355eac52ac76be36984a1abf..2edc59a7da0ee0911695292498384655ea067cdb 100644 (file)
@@ -547,10 +547,10 @@ int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
         }
 
         p_module->p_config[i].psz_type = strdupnull (p_orig[i].psz_type);
-        p_module->p_config[i].psz_name = strdupnull (p_orig[i].psz_name);
+        p_module->p_config[i].psz_name = p_orig[i].psz_name;
         p_module->p_config[i].psz_current = strdupnull (p_orig[i].psz_current);
-        p_module->p_config[i].psz_text = _strdupnull (p_orig[i].psz_text);
-        p_module->p_config[i].psz_longtext = _strdupnull (p_orig[i].psz_longtext);
+        p_module->p_config[i].psz_text = p_orig[i].psz_text;
+        p_module->p_config[i].psz_longtext = p_orig[i].psz_longtext;
 
         p_module->p_config[i].p_lock = &p_module->object_lock;
 
index 8086517d8c4448f6edd556b4ae45acce1d9c1b0d..b1ee2b5a9b2873773fbf921c8bf20c0ab2665c09 100644 (file)
 
 #include <vlc/vlc.h>
 #include <assert.h>
+#include <stdarg.h>
 
-#include "modules/modules.h"
+#include "modules.h"
 #include "libvlc.h"
-#include "../libvlc.h"
 
 static const char default_name[] = "unnamed";
 
@@ -140,3 +140,48 @@ int vlc_module_set (module_t *module, int propid, void *value)
     }
     return 0;
 }
+
+int vlc_config_set (module_config_t *restrict item, vlc_config_t id, ...)
+{
+    int ret = -1;
+    va_list ap;
+
+    assert (item != NULL);
+    va_start (ap, id);
+
+    switch (id)
+    {
+        case VLC_CONFIG_NAME:
+        {
+            const char *name = va_arg (ap, const char *);
+            vlc_callback_t cb = va_arg (ap, vlc_callback_t);
+
+            assert (name != NULL);
+            item->psz_name = strdup (name);
+            item->pf_callback = cb;
+            break;
+        }
+
+        case VLC_CONFIG_DESC:
+        {
+            const char *text = va_arg (ap, const char *);
+            const char *longtext = va_arg (ap, const char *);
+
+            item->psz_text = text ? strdup (gettext (text)) : NULL;
+            item->psz_longtext = longtext ? strdup (gettext (text)) : NULL;
+            ret = 0;
+            break;
+        }
+
+        case VLC_CONFIG_VALUE:
+        case VLC_CONFIG_RANGE:
+        case VLC_CONFIG_STEP:
+        case VLC_CONFIG_ADVANCED:
+        case VLC_CONFIG_VOLATILE:
+        case VLC_CONFIG_PRIVATE:
+            break;
+    }
+
+    va_end (ap);
+    return ret;
+}