[aravis] gv_interface: strip control characters from device id.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] gv_interface: strip control characters from device id.
- Date: Sun, 8 Sep 2013 21:03:30 +0000 (UTC)
commit d4cd1ec0503a8021d90b12293b914d6b93fa76e2
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Sep 8 23:03:04 2013 +0200
gv_interface: strip control characters from device id.
docs/reference/aravis/aravis-sections.txt | 4 ++--
src/arvcamera.h | 5 -----
src/arvgvinterface.c | 3 +++
src/arvinterface.h | 4 ++++
tests/misc.c | 19 ++++++++++++-------
5 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index eec42ab..04afacf 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -66,8 +66,6 @@ ARV_CAMERA_GET_CLASS
<SUBSECTION Private>
ArvCameraPrivate
ArvCameraClass
-ARV_CAMERA_NAME_ILLEGAL_CHARACTERS
-ARV_CAMERA_NAME_REPLACEMENT_CHARACTER
</SECTION>
<SECTION>
@@ -263,6 +261,8 @@ ARV_IS_DEVICE_CLASS
ARV_DEVICE_GET_CLASS
<SUBSECTION Private>
ArvDeviceClass
+ARV_DEVICE_NAME_ILLEGAL_CHARACTERS
+ARV_DEVICE_NAME_REPLACEMENT_CHARACTER
</SECTION>
<SECTION>
diff --git a/src/arvcamera.h b/src/arvcamera.h
index 7672d65..f918217 100644
--- a/src/arvcamera.h
+++ b/src/arvcamera.h
@@ -28,11 +28,6 @@
G_BEGIN_DECLS
-#define ARV_CAMERA_NAME_ILLEGAL_CHARACTERS
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
-
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
- " _-"
-#define ARV_CAMERA_NAME_REPLACEMENT_CHARACTER '_'
-
#define ARV_TYPE_CAMERA (arv_camera_get_type ())
#define ARV_CAMERA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_CAMERA, ArvCamera))
#define ARV_CAMERA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_CAMERA, ArvCameraClass))
diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c
index 1b4391c..4fe8d61 100644
--- a/src/arvgvinterface.c
+++ b/src/arvgvinterface.c
@@ -30,6 +30,7 @@
#include <arvgvcp.h>
#include <arvdebug.h>
#include <arvmisc.h>
+#include <arvstr.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
#include <sys/types.h>
@@ -224,6 +225,8 @@ arv_gv_interface_device_infos_new (GInetAddress *interface_address,
ARV_GVBS_USER_DEFINED_NAME_SIZE);
infos->name = g_strdup_printf ("%s-%s", infos->manufacturer, infos->serial_number);
+ arv_str_strip (infos->name, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS,
ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);
+
infos->interface_address = interface_address;
infos->mac_string = g_strdup_printf ("%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/src/arvinterface.h b/src/arvinterface.h
index 3f5ac8f..00df963 100644
--- a/src/arvinterface.h
+++ b/src/arvinterface.h
@@ -28,6 +28,10 @@
G_BEGIN_DECLS
+#define ARV_DEVICE_NAME_ILLEGAL_CHARACTERS
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
+ "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+#define ARV_DEVICE_NAME_REPLACEMENT_CHARACTER '\0'
+
typedef struct {
char *device;
char *physical;
diff --git a/tests/misc.c b/tests/misc.c
index 56c14a2..b95262b 100644
--- a/tests/misc.c
+++ b/tests/misc.c
@@ -35,15 +35,20 @@ unaligned_from_le_ptr_test (void)
g_assert_cmpuint (v_uint16, ==, 0x5544);
}
+#define ILLEGAL_CHARACTERS "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
+ "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
+ " _-"
+#define REPLACEMENT_CHARACTER '-'
+
struct {
char *before;
char *after;
} strip_strings[] = {
- {"\n\tHello\r\nworld!\n\t", "Hello_world!"},
+ {"\n\tHello\r\nworld!\n\t", "Hello-world!"},
{"\n\tHello", "Hello"},
{"Hello\r\t", "Hello"},
- {"Hello\rworld!", "Hello_world!"},
- {"Hello\r \rworld!", "Hello_world!"},
+ {"Hello\rworld!", "Hello-world!"},
+ {"Hello\r- -_\rworld!", "Hello-world!"},
{"", ""},
{"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", ""},
{"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", ""},
@@ -60,7 +65,7 @@ arv_str_strip_test (void)
for (i = 0; i < G_N_ELEMENTS (strip_strings); i++) {
string = g_strdup (strip_strings[i].before);
- arv_str_strip (string, ARV_CAMERA_NAME_ILLEGAL_CHARACTERS, '_');
+ arv_str_strip (string, ILLEGAL_CHARACTERS, REPLACEMENT_CHARACTER);
g_assert_cmpstr (string, ==, strip_strings[i].after);
@@ -68,12 +73,12 @@ arv_str_strip_test (void)
}
string = g_strdup ("Hello\r\n world");
- arv_str_strip (string, ARV_CAMERA_NAME_ILLEGAL_CHARACTERS, '\0');
+ arv_str_strip (string, ILLEGAL_CHARACTERS, '\0');
g_assert_cmpstr (string, ==, "Helloworld");
g_free (string);
- g_assert (arv_str_strip (NULL, ARV_CAMERA_NAME_ILLEGAL_CHARACTERS, '_') == NULL);
- g_assert (arv_str_strip (NULL, NULL, '_') == NULL);
+ g_assert (arv_str_strip (NULL, ILLEGAL_CHARACTERS, REPLACEMENT_CHARACTER) == NULL);
+ g_assert (arv_str_strip (NULL, NULL, REPLACEMENT_CHARACTER) == NULL);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]