summaryrefslogtreecommitdiff
path: root/gst-libs
diff options
context:
space:
mode:
authorEdward Hervey <edward.hervey@collabora.co.uk>2010-12-21 16:33:50 +0100
committerEdward Hervey <edward.hervey@collabora.co.uk>2010-12-21 16:38:40 +0100
commit4b3e1403a1ac83cc5cc2a19c009bfd1149f0f496 (patch)
treec1166707db64cf1622a5172447ce6195e3991dbc /gst-libs
parent6ffabccf04a7025822252a895b4111af6af6ac0e (diff)
encoding-target: Ensure target names and categories are valid
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/gst/pbutils/encoding-target.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gst-libs/gst/pbutils/encoding-target.c b/gst-libs/gst/pbutils/encoding-target.c
index 19065e8fe..b62895c1f 100644
--- a/gst-libs/gst/pbutils/encoding-target.c
+++ b/gst-libs/gst/pbutils/encoding-target.c
@@ -19,6 +19,7 @@
*/
#include <locale.h>
+#include <string.h>
#include "encoding-target.h"
/*
@@ -150,6 +151,40 @@ gst_encoding_target_get_profiles (GstEncodingTarget * target)
return target->profiles;
}
+static inline gboolean
+validate_name (const gchar * name)
+{
+ guint i, len;
+
+ len = strlen (name);
+ if (len == 0)
+ return FALSE;
+
+ /* First character can only be a lower case ASCII character */
+ if (!g_ascii_isalpha (name[0]) || !g_ascii_islower (name[0]))
+ return FALSE;
+
+ /* All following characters can only by:
+ * either a lower case ASCII character
+ * or an hyphen
+ * or a numeric */
+ for (i = 1; i < len; i++) {
+ /* if uppercase ASCII letter, return */
+ if (g_ascii_isupper (name[i]))
+ return FALSE;
+ /* if a digit, continue */
+ if (g_ascii_isdigit (name[i]))
+ continue;
+ /* if an hyphen, continue */
+ if (name[i] == '-')
+ continue;
+ /* remaining should only be ascii letters */
+ if (!g_ascii_isalpha (name[i]))
+ return FALSE;
+ }
+
+ return TRUE;
+}
/**
* gst_encoding_target_new:
@@ -160,6 +195,10 @@ gst_encoding_target_get_profiles (GstEncodingTarget * target)
*
* Creates a new #GstEncodingTarget.
*
+ * The name and category can only consist of lowercase ASCII letters for the
+ * first character, followed by either lowercase ASCII letters, digits or
+ * hyphens ('-').
+ *
* Since: 0.10.32
*
* Returns: The newly created #GstEncodingTarget or %NULL if there was an
@@ -176,6 +215,12 @@ gst_encoding_target_new (const gchar * name, const gchar * category,
g_return_val_if_fail (category != NULL, NULL);
g_return_val_if_fail (description != NULL, NULL);
+ /* Validate name */
+ if (!validate_name (name))
+ goto invalid_name;
+ if (!validate_name (category))
+ goto invalid_category;
+
res = (GstEncodingTarget *) gst_mini_object_new (GST_TYPE_ENCODING_TARGET);
res->name = g_strdup (name);
res->category = g_strdup (category);
@@ -190,6 +235,18 @@ gst_encoding_target_new (const gchar * name, const gchar * category,
}
return res;
+
+invalid_name:
+ {
+ GST_ERROR ("Invalid name for encoding category : '%s'", name);
+ return NULL;
+ }
+
+invalid_category:
+ {
+ GST_ERROR ("Invalid category for encoding category : '%s'", category);
+ return NULL;
+ }
}
/**