[vlc-commits] var_LocationParse: helper for DVB/V4L2-style MRLs
Rémi Denis-Courmont
git at videolan.org
Sat Mar 12 14:48:48 CET 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 12 15:48:05 2011 +0200| [73e0e21f603e24f8ede4a5703f010bd456ac5593] | committer: Rémi Denis-Courmont
var_LocationParse: helper for DVB/V4L2-style MRLs
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73e0e21f603e24f8ede4a5703f010bd456ac5593
---
include/vlc_variables.h | 3 +++
src/libvlccore.sym | 1 +
src/misc/variables.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index e0f5f88..16b3584 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -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_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)
+
/**
* @}
*/
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 45c4e8e..30173a5 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -486,6 +486,7 @@ var_TriggerCallback
var_Type
var_Inherit
var_InheritURational
+var_LocationParse
video_format_CopyCrop
video_format_ScaleCropAr
video_format_FixRgb
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 3d3ab40..2e25df4 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -1079,8 +1079,49 @@ cleanup:
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)
More information about the vlc-commits
mailing list