summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Bell <richard.s.bell@intel.com>2015-05-01 13:31:22 -0700
committerRick Bell <richard.s.bell@intel.com>2015-05-01 13:31:22 -0700
commitf47f094a71f21f2be141071b0d0e00b618b91f3b (patch)
treeb5be7f52192038a1dd327a22a145cb86dd67a2c1
parentc6d681d1a9e495e94d3f22f6d4faaffb604f16b9 (diff)
downloaddleyna-core-f47f094a71f21f2be141071b0d0e00b618b91f3b.tar.gz
Added new core.c and core.h to add new function dleyna_core_prv_convert_udn_to_path to support persistent path identifier
-rw-r--r--libdleyna/core/core.c73
-rw-r--r--libdleyna/core/core.h73
2 files changed, 146 insertions, 0 deletions
diff --git a/libdleyna/core/core.c b/libdleyna/core/core.c
new file mode 100644
index 0000000..8d9bdda
--- /dev/null
+++ b/libdleyna/core/core.c
@@ -0,0 +1,73 @@
+/*
+ * dLeyna
+ *
+ * Copyright (C) 2012-2015 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Rick Bell <richard.s.bell@intel.com>
+ *
+ */
+
+#include <string.h>
+
+#include "core.h"
+
+gchar *dleyna_core_prv_convert_udn_to_path(const gchar *udn)
+{
+ gchar *uuid;
+ size_t len;
+ size_t dest_len;
+ size_t i;
+
+ /* This function will generate a valid dbus path from the udn
+ * We are not going to check the UDN validity. We will try to
+ * convert it anyway. To avoid any security problem, we will
+ * check some limits and possibly return only a partial
+ * UDN. For a better understanding, a valid UDN should be:
+ * UDN = "uuid:4Hex-2Hex-2Hex-2Hex-6Hex"
+ *
+ * The convertion rules are:
+ * 1 - An invalid char will be escaped using its hexa representation
+ * prefixed with '_':
+ * Example 1 ': ' -> '_3A'
+ * Example 2 '- ' -> '_2D'
+ * 2 - The max size of the converted UDN can be 3 times the original
+ * size (if all char are not dbus compliant).
+ * The max size of a dbus path is an UINT32: G_MAXUINT32
+ * We will limit the of the converted string size to G_MAXUINT32 / 2
+ * otherwise we will never have space to generate object path.
+ */
+
+ len = strlen(udn);
+ dest_len = MIN(len * 3, G_MAXUINT32 / 2);
+
+ uuid = g_malloc(dest_len + 1);
+ i = 0;
+
+ while (*udn && (i < dest_len))
+ {
+ if (g_ascii_isalnum(*udn) || (*udn == '_'))
+ uuid[i++] = *udn;
+ else
+ i += g_snprintf(uuid + i, dest_len + 1,"_%02x", *udn);
+
+ udn++;
+ }
+
+
+ uuid[i]=0;
+
+ return uuid;
+}
diff --git a/libdleyna/core/core.h b/libdleyna/core/core.h
new file mode 100644
index 0000000..8d9bdda
--- /dev/null
+++ b/libdleyna/core/core.h
@@ -0,0 +1,73 @@
+/*
+ * dLeyna
+ *
+ * Copyright (C) 2012-2015 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Rick Bell <richard.s.bell@intel.com>
+ *
+ */
+
+#include <string.h>
+
+#include "core.h"
+
+gchar *dleyna_core_prv_convert_udn_to_path(const gchar *udn)
+{
+ gchar *uuid;
+ size_t len;
+ size_t dest_len;
+ size_t i;
+
+ /* This function will generate a valid dbus path from the udn
+ * We are not going to check the UDN validity. We will try to
+ * convert it anyway. To avoid any security problem, we will
+ * check some limits and possibly return only a partial
+ * UDN. For a better understanding, a valid UDN should be:
+ * UDN = "uuid:4Hex-2Hex-2Hex-2Hex-6Hex"
+ *
+ * The convertion rules are:
+ * 1 - An invalid char will be escaped using its hexa representation
+ * prefixed with '_':
+ * Example 1 ': ' -> '_3A'
+ * Example 2 '- ' -> '_2D'
+ * 2 - The max size of the converted UDN can be 3 times the original
+ * size (if all char are not dbus compliant).
+ * The max size of a dbus path is an UINT32: G_MAXUINT32
+ * We will limit the of the converted string size to G_MAXUINT32 / 2
+ * otherwise we will never have space to generate object path.
+ */
+
+ len = strlen(udn);
+ dest_len = MIN(len * 3, G_MAXUINT32 / 2);
+
+ uuid = g_malloc(dest_len + 1);
+ i = 0;
+
+ while (*udn && (i < dest_len))
+ {
+ if (g_ascii_isalnum(*udn) || (*udn == '_'))
+ uuid[i++] = *udn;
+ else
+ i += g_snprintf(uuid + i, dest_len + 1,"_%02x", *udn);
+
+ udn++;
+ }
+
+
+ uuid[i]=0;
+
+ return uuid;
+}