From: Denis Kenzior Date: Wed, 2 Sep 2009 22:34:31 +0000 (-0500) Subject: Add simple utility to validate paths X-Git-Tag: 0.4~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03a0fde2f4387cf2e0f031bf043f9e6a9320bca2;p=platform%2Fupstream%2Fofono.git Add simple utility to validate paths --- diff --git a/src/dbus.c b/src/dbus.c index b2486f4..5308ab1 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; diff --git a/src/ofono.h b/src/ofono.h index bf31531..ffafae8 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -53,6 +53,8 @@ DBusMessage *__ofono_error_sim_not_ready(DBusMessage *msg); void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply); +gboolean __ofono_dbus_valid_object_path(const char *path); + #include #include