From 5c1b3864d4c0be14a181594bba6d871ea84b8985 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 8 Jan 2008 11:21:39 +0100 Subject: [PATCH] Add string conversion helper functions --- src/Makefile.am | 3 +- src/connman.h | 8 ++++ src/iface-helper.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/iface-helper.c diff --git a/src/Makefile.am b/src/Makefile.am index 66d2f1c..cd80c8d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,8 @@ dbus_DATA = connman.conf sbin_PROGRAMS = connmand -connmand_SOURCES = main.c connman.h manager.c plugin.c iface.c rtnl.c dhcp.c +connmand_SOURCES = main.c connman.h manager.c plugin.c \ + iface.c iface-helper.c rtnl.c dhcp.c connmand_LDADD = @HAL_LIBS@ @GDBUS_LIBS@ @GMODULE_LIBS@ diff --git a/src/connman.h b/src/connman.h index ec7a1f3..7f789fe 100644 --- a/src/connman.h +++ b/src/connman.h @@ -55,6 +55,14 @@ void __connman_iface_cleanup(void); struct connman_iface *__connman_iface_find(int index); void __connman_iface_list(DBusMessageIter *iter); +const char *__connman_iface_type2string(enum connman_iface_type type); +const char *__connman_iface_state2string(enum connman_iface_state state); +const char *__connman_iface_policy2string(enum connman_iface_policy policy); +enum connman_iface_policy __connman_iface_string2policy(const char *policy); + +const char *__connman_ipv4_method2string(enum connman_ipv4_method method); +enum connman_ipv4_method __connman_ipv4_string2method(const char *method); + #include int __connman_rtnl_init(void); diff --git a/src/iface-helper.c b/src/iface-helper.c new file mode 100644 index 0000000..4fe4b64 --- /dev/null +++ b/src/iface-helper.c @@ -0,0 +1,128 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU 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 + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "connman.h" + +const char *__connman_iface_type2string(enum connman_iface_type type) +{ + switch (type) { + case CONNMAN_IFACE_TYPE_UNKNOWN: + return "unknown"; + case CONNMAN_IFACE_TYPE_80203: + return "80203"; + case CONNMAN_IFACE_TYPE_80211: + return "80211"; + case CONNMAN_IFACE_TYPE_WIMAX: + return "wimax"; + case CONNMAN_IFACE_TYPE_MODEM: + return "modem"; + case CONNMAN_IFACE_TYPE_BLUETOOTH: + return "bluetooth"; + } + + return "unknown"; +} + +const char *__connman_iface_state2string(enum connman_iface_state state) +{ + switch (state) { + case CONNMAN_IFACE_STATE_UNKNOWN: + return "unknown"; + case CONNMAN_IFACE_STATE_OFF: + return "off"; + case CONNMAN_IFACE_STATE_ENABLED: + return "enabled"; + case CONNMAN_IFACE_STATE_CONNECT: + return "connect"; + case CONNMAN_IFACE_STATE_CONFIG: + return "config"; + case CONNMAN_IFACE_STATE_CARRIER: + return "carrier"; + case CONNMAN_IFACE_STATE_READY: + return "ready"; + case CONNMAN_IFACE_STATE_SHUTDOWN: + return "shutdown"; + } + + return "unknown"; +} + +const char *__connman_iface_policy2string(enum connman_iface_policy policy) +{ + switch (policy) { + case CONNMAN_IFACE_POLICY_UNKNOWN: + return "unknown"; + case CONNMAN_IFACE_POLICY_OFF: + return "off"; + case CONNMAN_IFACE_POLICY_IGNORE: + return "ignore"; + case CONNMAN_IFACE_POLICY_AUTO: + return "auto"; + } + + return "unknown"; +} + +enum connman_iface_policy __connman_iface_string2policy(const char *policy) +{ + if (strcasecmp(policy, "off") == 0) + return CONNMAN_IFACE_POLICY_OFF; + else if (strcasecmp(policy, "ignore") == 0) + return CONNMAN_IFACE_POLICY_IGNORE; + else if (strcasecmp(policy, "auto") == 0) + return CONNMAN_IFACE_POLICY_AUTO; + else + return CONNMAN_IFACE_POLICY_UNKNOWN; +} + +const char *__connman_ipv4_method2string(enum connman_ipv4_method method) +{ + switch (method) { + case CONNMAN_IPV4_METHOD_UNKNOWN: + return "unknown"; + case CONNMAN_IPV4_METHOD_OFF: + return "off"; + case CONNMAN_IPV4_METHOD_STATIC: + return "static"; + case CONNMAN_IPV4_METHOD_DHCP: + return "dhcp"; + } + + return "unknown"; +} + +enum connman_ipv4_method __connman_ipv4_string2method(const char *method) +{ + if (strcasecmp(method, "off") == 0) + return CONNMAN_IPV4_METHOD_OFF; + else if (strcasecmp(method, "static") == 0) + return CONNMAN_IPV4_METHOD_STATIC; + else if (strcasecmp(method, "dhcp") == 0) + return CONNMAN_IPV4_METHOD_DHCP; + else + return CONNMAN_IPV4_METHOD_UNKNOWN; +} -- 2.7.4