Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
George Kiagiadakis
gst-plugins-base
Commits
4b3e1403
Commit
4b3e1403
authored
Dec 21, 2010
by
Edward Hervey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding-target: Ensure target names and categories are valid
parent
6ffabccf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
gst-libs/gst/pbutils/encoding-target.c
gst-libs/gst/pbutils/encoding-target.c
+57
-0
tests/check/libs/profile.c
tests/check/libs/profile.c
+78
-0
No files found.
gst-libs/gst/pbutils/encoding-target.c
View file @
4b3e1403
...
...
@@ -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
;
}
}
/**
...
...
tests/check/libs/profile.c
View file @
4b3e1403
...
...
@@ -132,6 +132,83 @@ GST_START_TEST (test_profile_output_caps)
GST_END_TEST
;
GST_START_TEST
(
test_target_naming
)
{
GstEncodingTarget
*
target
;
/* NULL values */
ASSERT_CRITICAL
(
target
=
gst_encoding_target_new
(
NULL
,
NULL
,
NULL
,
NULL
));
fail_if
(
target
!=
NULL
);
ASSERT_CRITICAL
(
target
=
gst_encoding_target_new
(
"donkey"
,
NULL
,
NULL
,
NULL
));
fail_if
(
target
!=
NULL
);
ASSERT_CRITICAL
(
target
=
gst_encoding_target_new
(
NULL
,
"donkey"
,
NULL
,
NULL
));
fail_if
(
target
!=
NULL
);
ASSERT_CRITICAL
(
target
=
gst_encoding_target_new
(
NULL
,
NULL
,
"donkey"
,
NULL
));
fail_if
(
target
!=
NULL
);
/* Name and Category validation */
/* empty non-NULL strings */
fail_if
(
gst_encoding_target_new
(
""
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
""
,
"description"
,
NULL
)
!=
NULL
);
/* don't start with a lower case ASCII character */
fail_if
(
gst_encoding_target_new
(
"A"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"3"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"-"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"!"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
" "
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"A"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"3"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"-"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"!"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
" "
,
"description"
,
NULL
)
!=
NULL
);
/* Starting with anything else is valid */
target
=
gst_encoding_target_new
(
"a"
,
"valid"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
target
=
gst_encoding_target_new
(
"z"
,
"valid"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
target
=
gst_encoding_target_new
(
"valid"
,
"a"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
target
=
gst_encoding_target_new
(
"valid"
,
"z"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
/* only inner valid characters are lower-case ASCII letters *OR* digits *OR* hyphens */
fail_if
(
gst_encoding_target_new
(
"aA"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"a!"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"space donkeys"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"howaboutùnicode"
,
"valid"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"aA"
,
"description"
,
NULL
)
!=
NULL
);
fail_if
(
gst_encoding_target_new
(
"valid"
,
"a!"
,
"description"
,
NULL
)
!=
NULL
);
target
=
gst_encoding_target_new
(
"donkey-4-ever"
,
"valid"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
target
=
gst_encoding_target_new
(
"valid"
,
"donkey-4-ever"
,
"description"
,
NULL
);
fail_if
(
target
==
NULL
);
gst_encoding_target_unref
(
target
);
}
GST_END_TEST
;
static
GstEncodingTarget
*
create_saveload_target
(
void
)
{
...
...
@@ -395,6 +472,7 @@ profile_suite (void)
tcase_add_test
(
tc_chain
,
test_profile_creation
);
tcase_add_test
(
tc_chain
,
test_profile_output_caps
);
tcase_add_test
(
tc_chain
,
test_target_naming
);
if
(
can_write
)
{
tcase_add_test
(
tc_chain
,
test_loading_profile
);
tcase_add_test
(
tc_chain
,
test_saving_profile
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment