summaryrefslogtreecommitdiff
path: root/src/dbus.c
diff options
context:
space:
mode:
authorDenis Kenzior <denis.kenzior@intel.com>2009-09-02 17:34:31 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-09-02 17:39:23 -0500
commit03a0fde2f4387cf2e0f031bf043f9e6a9320bca2 (patch)
tree82b9fd20ce36cabaa3a3f2a5f8b169845ce91bb5 /src/dbus.c
parent8e62522575265fc4664c8ae683664371a155132a (diff)
Add simple utility to validate paths
Diffstat (limited to 'src/dbus.c')
-rw-r--r--src/dbus.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/dbus.c b/src/dbus.c
index b2486f4d..5308ab15 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -320,6 +320,50 @@ void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply)
*msg = NULL;
}
+gboolean __ofono_dbus_valid_object_path(const char *path)
+{
+ unsigned int i;
+ char c = '\0';
+
+ if (path == NULL)
+ return FALSE;
+
+ if (path[0] == '\0')
+ return FALSE;
+
+ if (path[0] && !path[1] && path[0] == '/')
+ return TRUE;
+
+ if (path[0] != '/')
+ return FALSE;
+
+ for (i = 0; path[i]; i++) {
+ if (path[i] == '/' && c == '/')
+ return FALSE;
+
+ c = path[i];
+
+ if (path[i] >= 'a' && path[i] <= 'z')
+ continue;
+
+ if (path[i] >= 'A' && path[i] <= 'Z')
+ continue;
+
+ if (path[i] >= '0' && path[i] <= '9')
+ continue;
+
+ if (path[i] == '_' || path[i] == '/')
+ continue;
+
+ return FALSE;
+ }
+
+ if (path[i-1] == '/')
+ return FALSE;
+
+ return TRUE;
+}
+
DBusConnection *ofono_dbus_get_connection()
{
return g_connection;