Commit 73e0e21f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

var_LocationParse: helper for DVB/V4L2-style MRLs

parent ec6df3cd
...@@ -736,6 +736,9 @@ VLC_EXPORT( int, var_InheritURational, ( vlc_object_t *, unsigned *num, unsigned ...@@ -736,6 +736,9 @@ VLC_EXPORT( int, var_InheritURational, ( vlc_object_t *, unsigned *num, unsigned
#define var_GetNonEmptyString(a,b) var_GetNonEmptyString( VLC_OBJECT(a),b) #define var_GetNonEmptyString(a,b) var_GetNonEmptyString( VLC_OBJECT(a),b)
#define var_GetAddress(a,b) var_GetAddress( VLC_OBJECT(a),b) #define var_GetAddress(a,b) var_GetAddress( VLC_OBJECT(a),b)
VLC_EXPORT( int, var_LocationParse, (vlc_object_t *, const char *mrl, const char *prefix) );
#define var_LocationParse(o, m, p) var_LocationParse(VLC_OBJECT(o), m, p)
/** /**
* @} * @}
*/ */
......
...@@ -486,6 +486,7 @@ var_TriggerCallback ...@@ -486,6 +486,7 @@ var_TriggerCallback
var_Type var_Type
var_Inherit var_Inherit
var_InheritURational var_InheritURational
var_LocationParse
video_format_CopyCrop video_format_CopyCrop
video_format_ScaleCropAr video_format_ScaleCropAr
video_format_FixRgb video_format_FixRgb
......
...@@ -1079,8 +1079,49 @@ cleanup: ...@@ -1079,8 +1079,49 @@ cleanup:
free( psz_name ); free( psz_name );
} }
#undef var_LocationParse
/**
* Parses a set of colon-separated <variable name>=<value> pairs. Some access
* (or access_demux) plugins uses this scheme in media resource location.
* @note Only trusted/safe variables are allowed. This is intended.
*
* @warning Only use this for plugins implementing VLC-specific resource
* location schemes. This would not make any sense for standardized ones.
*
* @param obj VLC object on which to set variables (and emit error messages)
* @param mrl string to parse
* @param pref prefix to prepend to option names in the string
*
* @return VLC_ENOMEM on error, VLC_SUCCESS on success.
*/
int var_LocationParse (vlc_object_t *obj, const char *mrl, const char *pref)
{
int ret = VLC_SUCCESS;
size_t preflen = strlen (pref);
assert(mrl != NULL);
while (*mrl != '\0')
{
mrl += strspn (mrl, ":"); /* skip leading colon(s) */
size_t len = strcspn (mrl, ":");
char *buf = malloc (preflen + len);
if (likely(buf != NULL))
{
/* NOTE: this does not support the "no-<varname>" bool syntax. */
/* DO NOT use asprintf() here; it won't work! Think again. */
snprintf (buf, preflen + len, "%s%s", pref, mrl);
var_OptionParse (obj, buf, false);
free (buf);
}
else
ret = VLC_ENOMEM;
mrl += len;
}
/* Following functions are local */ return ret;
}
/** /**
* Waits until the variable is inactive (i.e. not executing a callback) * Waits until the variable is inactive (i.e. not executing a callback)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment