]> git.sesse.net Git - vlc/commitdiff
src/input: add a new input option flag to replace values of existing options
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Sat, 10 May 2014 15:34:27 +0000 (17:34 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Tue, 13 May 2014 19:05:32 +0000 (21:05 +0200)
This flag can be used with input_item_AddOption to replace the value
of an input option, if this option already exists. Otherwise, the
new option is added as usual.

refs #11471

include/vlc_input_item.h
src/input/item.c

index 944ac2f126b8f1663f6d281dd265587aee668594..dcd38c9a03a25d8d36e6f509e066f1e3cd6d44b2 100644 (file)
@@ -179,6 +179,13 @@ enum input_item_option_e
     /* Add the option, unless the same option
      * is already present. */
     VLC_INPUT_OPTION_UNIQUE  = 0x100,
+
+    /* Search for an existing option in the format
+     * option=value and replaces the first one found.
+     * Else, the new option is added.
+     * This option and VLC_INPUT_OPTION_UNIQUE are
+     * mutually exclusive. */
+    VLC_INPUT_OPTION_REPLACE = 0x200,
 };
 
 /**
index b27250b347400241d361ee0bb902f6ed540ca93b..30c6d3ad48133169d996cac851f02265e0b1e818 100644 (file)
@@ -473,6 +473,28 @@ int input_item_AddOption( input_item_t *p_input, const char *psz_option,
                 goto out;
     }
 
+    if (flags & VLC_INPUT_OPTION_REPLACE)
+    {
+        /* search for option format "option=value" */
+
+        const char *psz_found = strchr( psz_option, '=' );
+        if( likely( psz_found ) )
+        {
+            for( int i = 0 ; i < p_input->i_options; i++ )
+            {
+                if( !strncmp( p_input->ppsz_options[i], psz_option,
+                             psz_found - psz_option + 1 /* = */ ) )
+                {
+                    free( p_input->ppsz_options[i] );
+                    p_input->ppsz_options[i] = strdup( psz_option );
+
+                    goto out;
+                }
+            }
+        }
+
+    }
+
     uint8_t *flagv = realloc (p_input->optflagv, p_input->optflagc + 1);
     if (flagv == NULL)
     {