summaryrefslogtreecommitdiff
path: root/src/dhcp-manager
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-03-11 14:34:34 +0100
committerThomas Haller <thaller@redhat.com>2014-04-11 11:31:34 +0200
commit0600fa0004b98302625bb3ff37c714b3ddfd3239 (patch)
tree9abac7cde95d88aa28499765661451e07549ce0a /src/dhcp-manager
parent2941109d3b8f8a17082ac598f1d3c57694f4c96c (diff)
downloadNetworkManager-0600fa0004b98302625bb3ff37c714b3ddfd3239.tar.gz
dhcp: refactor state to string conversion
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'src/dhcp-manager')
-rw-r--r--src/dhcp-manager/nm-dhcp-client.c83
1 files changed, 37 insertions, 46 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index 1ff7ac9cc5..6cec7448a1 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -575,63 +575,54 @@ state_is_bound (guint32 state)
return FALSE;
}
-typedef struct {
- NMDHCPState state;
- const char *name;
-} DhcState;
-
-#define STATE_TABLE_SIZE (sizeof (state_table) / sizeof (state_table[0]))
-
-static DhcState state_table[] = {
- { DHC_NBI, "nbi" },
- { DHC_PREINIT, "preinit" },
- { DHC_PREINIT6,"preinit6" },
- { DHC_BOUND4, "bound" },
- { DHC_BOUND6, "bound6" },
- { DHC_IPV4LL, "ipv4ll" },
- { DHC_RENEW4, "renew" },
- { DHC_RENEW6, "renew6" },
- { DHC_REBOOT, "reboot" },
- { DHC_REBIND4, "rebind" },
- { DHC_REBIND6, "rebind6" },
- { DHC_STOP, "stop" },
- { DHC_STOP6, "stop6" },
- { DHC_MEDIUM, "medium" },
- { DHC_TIMEOUT, "timeout" },
- { DHC_FAIL, "fail" },
- { DHC_EXPIRE, "expire" },
- { DHC_EXPIRE6, "expire6" },
- { DHC_RELEASE, "release" },
- { DHC_RELEASE6,"release6" },
- { DHC_START, "start" },
- { DHC_ABEND, "abend" },
- { DHC_END, "end" },
- { DHC_DEPREF6, "depref6" },
+static const char *state_table[] = {
+ [DHC_NBI] = "nbi",
+ [DHC_PREINIT] = "preinit",
+ [DHC_PREINIT6] = "preinit6",
+ [DHC_BOUND4] = "bound",
+ [DHC_BOUND6] = "bound6",
+ [DHC_IPV4LL] = "ipv4ll",
+ [DHC_RENEW4] = "renew",
+ [DHC_RENEW6] = "renew6",
+ [DHC_REBOOT] = "reboot",
+ [DHC_REBIND4] = "rebind",
+ [DHC_REBIND6] = "rebind6",
+ [DHC_DEPREF6] = "depref6",
+ [DHC_STOP] = "stop",
+ [DHC_STOP6] = "stop6",
+ [DHC_MEDIUM] = "medium",
+ [DHC_TIMEOUT] = "timeout",
+ [DHC_FAIL] = "fail",
+ [DHC_EXPIRE] = "expire",
+ [DHC_EXPIRE6] = "expire6",
+ [DHC_RELEASE] = "release",
+ [DHC_RELEASE6] = "release6",
+ [DHC_START] = "start",
+ [DHC_ABEND] = "abend",
+ [DHC_END] = "end",
};
-static inline const char *
-state_to_string (guint32 state)
+static const char *
+state_to_string (NMDHCPState state)
{
- int i;
-
- for (i = 0; i < STATE_TABLE_SIZE; i++) {
- if (state == state_table[i].state)
- return state_table[i].name;
- }
-
+ if (state >= 0 && state < G_N_ELEMENTS (state_table))
+ return state_table[state];
return NULL;
}
-static inline NMDHCPState
+static NMDHCPState
string_to_state (const char *name)
{
int i;
- for (i = 0; i < STATE_TABLE_SIZE; i++) {
- if (!strcasecmp (name, state_table[i].name))
- return state_table[i].state;
- }
+ if (name) {
+ for (i = 0; i < G_N_ELEMENTS (state_table); i++) {
+ const char *n = state_table[i];
+ if (n && !strcasecmp (name, n))
+ return i;
+ }
+ }
return 255;
}