Add string conversion helper functions
authorMarcel Holtmann <marcel@holtmann.org>
Tue, 8 Jan 2008 10:21:39 +0000 (11:21 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 8 Jan 2008 10:21:39 +0000 (11:21 +0100)
src/Makefile.am
src/connman.h
src/iface-helper.c [new file with mode: 0644]

index 66d2f1c..cd80c8d 100644 (file)
@@ -5,7 +5,8 @@ dbus_DATA = connman.conf
 
 sbin_PROGRAMS = connmand
 
 
 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@
  
 
 connmand_LDADD = @HAL_LIBS@ @GDBUS_LIBS@ @GMODULE_LIBS@
  
index ec7a1f3..7f789fe 100644 (file)
@@ -55,6 +55,14 @@ void __connman_iface_cleanup(void);
 struct connman_iface *__connman_iface_find(int index);
 void __connman_iface_list(DBusMessageIter *iter);
 
 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 <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
 #include <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
diff --git a/src/iface-helper.c b/src/iface-helper.c
new file mode 100644 (file)
index 0000000..4fe4b64
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include <string.h>
+
+#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;
+}