diff options
Diffstat (limited to 'cli/src/network-manager.c')
-rw-r--r-- | cli/src/network-manager.c | 157 |
1 files changed, 33 insertions, 124 deletions
diff --git a/cli/src/network-manager.c b/cli/src/network-manager.c index 5ecfde3a1..e695c0e42 100644 --- a/cli/src/network-manager.c +++ b/cli/src/network-manager.c @@ -17,8 +17,6 @@ * (C) Copyright 2010 - 2011 Red Hat, Inc. */ -#include "config.h" - #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -35,27 +33,19 @@ /* Available fields for 'nm status' */ static NmcOutputField nmc_fields_nm_status[] = { {"RUNNING", N_("RUNNING"), 15, NULL, 0}, /* 0 */ - {"VERSION", N_("VERSION"), 10, NULL, 0}, /* 1 */ - {"STATE", N_("STATE"), 15, NULL, 0}, /* 2 */ - {"NET-ENABLED", N_("NET-ENABLED"), 13, NULL, 0}, /* 3 */ - {"WIFI-HARDWARE", N_("WIFI-HARDWARE"), 15, NULL, 0}, /* 4 */ - {"WIFI", N_("WIFI"), 10, NULL, 0}, /* 5 */ - {"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 6 */ - {"WWAN", N_("WWAN"), 10, NULL, 0}, /* 7 */ - {"WIMAX-HARDWARE", N_("WIMAX-HARDWARE"), 15, NULL, 0}, /* 8 */ - {"WIMAX", N_("WIMAX"), 10, NULL, 0}, /* 9 */ - {NULL, NULL, 0, NULL, 0} + {"STATE", N_("STATE"), 15, NULL, 0}, /* 1 */ + {"NET-ENABLED", N_("NET-ENABLED"), 13, NULL, 0}, /* 2 */ + {"WIFI-HARDWARE", N_("WIFI-HARDWARE"), 15, NULL, 0}, /* 3 */ + {"WIFI", N_("WIFI"), 10, NULL, 0}, /* 4 */ + {"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 5 */ + {"WWAN", N_("WWAN"), 10, NULL, 0}, /* 6 */ + {NULL, NULL, 0, NULL, 0} }; -#if WITH_WIMAX -#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,VERSION,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN,WIMAX-HARDWARE,WIMAX" -#else -#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,VERSION,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN" -#endif +#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN" #define NMC_FIELDS_NM_STATUS_COMMON "RUNNING,STATE,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN" #define NMC_FIELDS_NM_NET_ENABLED "NET-ENABLED" #define NMC_FIELDS_NM_WIFI "WIFI" #define NMC_FIELDS_NM_WWAN "WWAN" -#define NMC_FIELDS_NM_WIMAX "WIMAX" extern GMainLoop *loop; @@ -71,21 +61,13 @@ static void usage (void) { fprintf (stderr, - _("Usage: nmcli nm { COMMAND | help }\n\n" -#if WITH_WIMAX - " COMMAND := { status | enable | sleep | wifi | wwan | wimax }\n\n" -#else - " COMMAND := { status | enable | sleep | wifi | wwan }\n\n" -#endif - " status\n" - " enable [true|false]\n" - " sleep [true|false]\n" - " wifi [on|off]\n" - " wwan [on|off]\n" -#if WITH_WIMAX - " wimax [on|off]\n\n" -#endif - )); + _("Usage: nmcli nm { COMMAND | help }\n\n" + " COMMAND := { status | enable | sleep | wifi | wwan }\n\n" + " status\n" + " enable [true|false]\n" + " sleep [true|false]\n" + " wifi [on|off]\n" + " wwan [on|off]\n\n")); } /* quit main loop */ @@ -103,14 +85,8 @@ nm_state_to_string (NMState state) return _("asleep"); case NM_STATE_CONNECTING: return _("connecting"); - case NM_STATE_CONNECTED_LOCAL: - return _("connected (local only)"); - case NM_STATE_CONNECTED_SITE: - return _("connected (site only)"); - case NM_STATE_CONNECTED_GLOBAL: + case NM_STATE_CONNECTED: return _("connected"); - case NM_STATE_DISCONNECTING: - return _("disconnecting"); case NM_STATE_DISCONNECTED: return _("disconnected"); case NM_STATE_UNKNOWN: @@ -127,9 +103,6 @@ show_nm_status (NmCli *nmc) const char *net_enabled_str; const char *wireless_hw_enabled_str, *wireless_enabled_str; const char *wwan_hw_enabled_str, *wwan_enabled_str; -#if WITH_WIMAX - const char *wimax_hw_enabled_str, *wimax_enabled_str; -#endif GError *error = NULL; const char *fields_str; const char *fields_all = NMC_FIELDS_NM_STATUS_ALL; @@ -158,11 +131,12 @@ show_nm_status (NmCli *nmc) return nmc->return_value; } + nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES; + nmc->print_fields.header_name = _("NetworkManager status"); + print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ + nm_running = nmc_is_nm_running (nmc, NULL); if (nm_running) { - if (!nmc_versions_match (nmc)) - goto error; - nmc->get_client (nmc); /* create NMClient */ state = nm_client_get_state (nmc->client); net_enabled_str = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled"); @@ -170,44 +144,22 @@ show_nm_status (NmCli *nmc) wireless_enabled_str = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled"); wwan_hw_enabled_str = nm_client_wwan_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled"); wwan_enabled_str = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled"); -#if WITH_WIMAX - wimax_hw_enabled_str = nm_client_wimax_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled"); - wimax_enabled_str = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled"); -#endif } else { -#if WITH_WIMAX - net_enabled_str = wireless_hw_enabled_str = wireless_enabled_str = - wwan_hw_enabled_str = wwan_enabled_str = wimax_hw_enabled_str = wimax_enabled_str = _("unknown"); -#else - net_enabled_str = wireless_hw_enabled_str = wireless_enabled_str = - wwan_hw_enabled_str = wwan_enabled_str = _("unknown"); -#endif + net_enabled_str = wireless_hw_enabled_str = wireless_enabled_str = wwan_hw_enabled_str = wwan_enabled_str = _("unknown"); } - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES; - nmc->print_fields.header_name = _("NetworkManager status"); - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ - nmc->allowed_fields[0].value = nm_running ? _("running") : _("not running"); - nmc->allowed_fields[1].value = nm_client_get_version (nmc->client); - nmc->allowed_fields[2].value = nm_state_to_string (state); - nmc->allowed_fields[3].value = net_enabled_str; - nmc->allowed_fields[4].value = wireless_hw_enabled_str; - nmc->allowed_fields[5].value = wireless_enabled_str; - nmc->allowed_fields[6].value = wwan_hw_enabled_str; - nmc->allowed_fields[7].value = wwan_enabled_str; -#if WITH_WIMAX - nmc->allowed_fields[8].value = wimax_hw_enabled_str; - nmc->allowed_fields[9].value = wimax_enabled_str; -#endif + nmc->allowed_fields[1].value = nm_state_to_string (state); + nmc->allowed_fields[2].value = net_enabled_str; + nmc->allowed_fields[3].value = wireless_hw_enabled_str; + nmc->allowed_fields[4].value = wireless_enabled_str; + nmc->allowed_fields[5].value = wwan_hw_enabled_str; + nmc->allowed_fields[6].value = wwan_enabled_str; nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ return NMC_RESULT_SUCCESS; - -error: - return nmc->return_value; } /* libnm-glib doesn't provide API fro Sleep method - implement D-Bus call ourselves */ @@ -255,9 +207,6 @@ do_network_manager (NmCli *nmc, int argc, char **argv) gboolean enable_net; gboolean enable_wifi; gboolean enable_wwan; -#if WITH_WIMAX - gboolean enable_wimax; -#endif guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; @@ -293,9 +242,9 @@ do_network_manager (NmCli *nmc, int argc, char **argv) if (nmc_is_nm_running (nmc, NULL)) { nmc->get_client (nmc); /* create NMClient */ - nmc->allowed_fields[3].value = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled"); + nmc->allowed_fields[2].value = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled"); } else - nmc->allowed_fields[3].value = _("unknown"); + nmc->allowed_fields[2].value = _("unknown"); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ } else { @@ -348,9 +297,9 @@ do_network_manager (NmCli *nmc, int argc, char **argv) if (nmc_is_nm_running (nmc, NULL)) { nmc->get_client (nmc); /* create NMClient */ - nmc->allowed_fields[5].value = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled"); + nmc->allowed_fields[4].value = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled"); } else - nmc->allowed_fields[5].value = _("unknown"); + nmc->allowed_fields[4].value = _("unknown"); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ } else { @@ -386,9 +335,9 @@ do_network_manager (NmCli *nmc, int argc, char **argv) if (nmc_is_nm_running (nmc, NULL)) { nmc->get_client (nmc); /* create NMClient */ - nmc->allowed_fields[7].value = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled"); + nmc->allowed_fields[6].value = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled"); } else - nmc->allowed_fields[7].value = _("unknown"); + nmc->allowed_fields[6].value = _("unknown"); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ } else { @@ -405,46 +354,6 @@ do_network_manager (NmCli *nmc, int argc, char **argv) nm_client_wwan_set_enabled (nmc->client, enable_wwan); } } -#if WITH_WIMAX - else if (matches (*argv, "wimax") == 0) { - if (next_arg (&argc, &argv) != 0) { - if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) - goto opt_error; - /* no argument, show current WiMAX state */ - if (nmc->required_fields && strcasecmp (nmc->required_fields, "WIMAX")) { - g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here; allowed fields: %s"), - nmc->required_fields, NMC_FIELDS_NM_WIMAX); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto end; - } - nmc->allowed_fields = nmc_fields_nm_status; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_WIMAX, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES; - nmc->print_fields.header_name = _("WiMAX enabled"); - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ - - if (nmc_is_nm_running (nmc, NULL)) { - nmc->get_client (nmc); /* create NMClient */ - nmc->allowed_fields[9].value = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled"); - } else - nmc->allowed_fields[9].value = _("unknown"); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - } else { - if (!strcmp (*argv, "on")) - enable_wimax = TRUE; - else if (!strcmp (*argv, "off")) - enable_wimax = FALSE; - else { - g_string_printf (nmc->return_text, _("Error: invalid 'wimax' parameter: '%s'."), *argv); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto end; - } - nmc->get_client (nmc); /* create NMClient */ - nm_client_wimax_set_enabled (nmc->client, enable_wimax); - } - } -#endif else if (strcmp (*argv, "help") == 0) { usage (); } |