From: Patrik Flykt Date: Wed, 20 Feb 2013 11:42:05 +0000 (+0200) Subject: client: Add boolean parsing helper function X-Git-Tag: 1.12~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09239d9b11483c8fcc71e7f76a2f5f83ae1b4473;p=platform%2Fupstream%2Fconnman.git client: Add boolean parsing helper function --- diff --git a/client/services.c b/client/services.c index 7e6424f..a545000 100644 --- a/client/services.c +++ b/client/services.c @@ -36,6 +36,32 @@ #include "services.h" #include "dbus.h" +int parse_boolean(char *arg) +{ + if (arg == NULL) + return -1; + + if (strcasecmp(arg, "no") == 0 || + strcasecmp(arg, "false") == 0 || + strcasecmp(arg, "off" ) == 0 || + strcasecmp(arg, "disable" ) == 0 || + strcasecmp(arg, "n") == 0 || + strcasecmp(arg, "f") == 0 || + strcasecmp(arg, "0") == 0) + return 0; + + if (strcasecmp(arg, "yes") == 0 || + strcasecmp(arg, "true") == 0 || + strcasecmp(arg, "on") == 0 || + strcasecmp(arg, "enable" ) == 0 || + strcasecmp(arg, "y") == 0 || + strcasecmp(arg, "t") == 0 || + strcasecmp(arg, "1") == 0) + return 1; + + return -1; +} + static void append_property_array(DBusMessageIter *iter, char *property, char **data, int num_args) { diff --git a/client/services.h b/client/services.h index eccc60a..09ed2c0 100644 --- a/client/services.h +++ b/client/services.h @@ -33,6 +33,7 @@ struct service_data { dbus_bool_t online; }; +int parse_boolean(char *arg); char *strip_service_path(char *service); void extract_service_name(DBusMessageIter *dict, struct service_data *service); int set_service_property(DBusConnection *connection, DBusMessage *message,