proxy: cleanup handling of proxy-method

The numeric value of NM_SETTING_PROXY_METHOD_NONE should be zero,
as that is the more natural default.

Also, cast all uses of the enum values in g_object_set() to
(int).
This commit is contained in:
Thomas Haller 2016-10-04 16:32:09 +02:00
parent a93fee0844
commit 29b576bd70
6 changed files with 27 additions and 17 deletions

View file

@ -3482,7 +3482,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
s_proxy = (NMSettingProxy *) nm_setting_proxy_new (); s_proxy = (NMSettingProxy *) nm_setting_proxy_new ();
nm_connection_add_setting (connection, NM_SETTING (s_proxy)); nm_connection_add_setting (connection, NM_SETTING (s_proxy));
g_object_set (s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE, NULL); g_object_set (s_proxy, NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE, NULL);
/* Activate the connection now */ /* Activate the connection now */
nmc->nowait_flag = (nmc->timeout == 0); nmc->nowait_flag = (nmc->timeout == 0);

View file

@ -2133,18 +2133,18 @@ static gboolean
nmc_property_proxy_set_method (NMSetting *setting, const char *prop, nmc_property_proxy_set_method (NMSetting *setting, const char *prop,
const char *val, GError **error) const char *val, GError **error)
{ {
NMSettingProxyMethod method; int method;
gboolean ret; gboolean ret;
ret = nm_utils_enum_from_str (nm_setting_proxy_method_get_type(), val, ret = nm_utils_enum_from_str (nm_setting_proxy_method_get_type(), val,
(int *) &method, NULL); &method, NULL);
if (!ret) { if (!ret) {
gs_free const char **values = NULL; gs_free const char **values = NULL;
gs_free char *values_str = NULL; gs_free char *values_str = NULL;
values = nm_utils_enum_get_values (nm_setting_proxy_method_get_type (), values = nm_utils_enum_get_values (nm_setting_proxy_method_get_type (),
NM_SETTING_PROXY_METHOD_AUTO, NM_SETTING_PROXY_METHOD_NONE,
G_MAXINT); G_MAXINT);
values_str = g_strjoinv (",", (char **) values); values_str = g_strjoinv (",", (char **) values);
g_set_error (error, 1, 0, _("invalid method '%s', use one of %s"), g_set_error (error, 1, 0, _("invalid method '%s', use one of %s"),
@ -2559,7 +2559,7 @@ nmc_setting_custom_init (NMSetting *setting)
NULL); NULL);
} else if (NM_IS_SETTING_PROXY (setting)) { } else if (NM_IS_SETTING_PROXY (setting)) {
g_object_set (NM_SETTING_PROXY (setting), g_object_set (NM_SETTING_PROXY (setting),
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE, NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE,
NULL); NULL);
} else if (NM_IS_SETTING_TUN (setting)) { } else if (NM_IS_SETTING_TUN (setting)) {
g_object_set (NM_SETTING_TUN (setting), g_object_set (NM_SETTING_TUN (setting),

View file

@ -153,7 +153,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
NMSettingProxyMethod method; NMSettingProxyMethod method;
method = priv->method; method = priv->method;
if (method == NM_SETTING_PROXY_METHOD_NONE) {
if (!NM_IN_SET (method,
NM_SETTING_PROXY_METHOD_NONE,
NM_SETTING_PROXY_METHOD_AUTO)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("invalid proxy method"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, NM_SETTING_PROXY_PAC_URL);
return FALSE;
}
if (method != NM_SETTING_PROXY_METHOD_AUTO) {
if (priv->pac_url) { if (priv->pac_url) {
g_set_error (error, g_set_error (error,
NM_CONNECTION_ERROR, NM_CONNECTION_ERROR,
@ -188,9 +200,6 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static void static void
nm_setting_proxy_init (NMSettingProxy *setting) nm_setting_proxy_init (NMSettingProxy *setting)
{ {
NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (setting);
priv->method = NM_SETTING_PROXY_METHOD_NONE;
} }
static void static void
@ -207,7 +216,7 @@ finalize (GObject *object)
static void static void
get_property (GObject *object, guint prop_id, get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
{ {
NMSettingProxy *setting = NM_SETTING_PROXY (object); NMSettingProxy *setting = NM_SETTING_PROXY (object);

View file

@ -32,16 +32,16 @@ G_BEGIN_DECLS
/** /**
* NMSettingProxyMethod: * NMSettingProxyMethod:
* @NM_SETTING_PROXY_METHOD_AUTO: DHCP obtained Proxy/ Manual override * @NM_SETTING_PROXY_METHOD_NONE: No Proxy for the Connection
* @NM_SETTING_PROXY_METHOD_NONE: No Proxy for the Connection * @NM_SETTING_PROXY_METHOD_AUTO: DHCP obtained Proxy/ Manual override
* *
* The Proxy method. * The Proxy method.
* *
* Since: 1.6 * Since: 1.6
*/ */
typedef enum { typedef enum {
NM_SETTING_PROXY_METHOD_AUTO = 0, NM_SETTING_PROXY_METHOD_NONE = 0,
NM_SETTING_PROXY_METHOD_NONE NM_SETTING_PROXY_METHOD_AUTO = 1,
} NMSettingProxyMethod; } NMSettingProxyMethod;
#define NM_TYPE_SETTING_PROXY (nm_setting_proxy_get_type ()) #define NM_TYPE_SETTING_PROXY (nm_setting_proxy_get_type ())

View file

@ -922,7 +922,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
switch (method) { switch (method) {
case NM_SETTING_PROXY_METHOD_AUTO: case NM_SETTING_PROXY_METHOD_AUTO:
g_object_set (s_proxy, g_object_set (s_proxy,
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_AUTO,
NULL); NULL);
value = svGetValue (ifcfg, "PAC_URL", FALSE); value = svGetValue (ifcfg, "PAC_URL", FALSE);
@ -942,8 +942,9 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
break; break;
case NM_SETTING_PROXY_METHOD_NONE: case NM_SETTING_PROXY_METHOD_NONE:
g_object_set (s_proxy, g_object_set (s_proxy,
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE, NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE,
NULL); NULL);
break;
} }
value = svGetValue (ifcfg, "BROWSER_ONLY", FALSE); value = svGetValue (ifcfg, "BROWSER_ONLY", FALSE);

View file

@ -2030,7 +2030,7 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
break; break;
case NM_SETTING_PROXY_METHOD_NONE: case NM_SETTING_PROXY_METHOD_NONE:
svSetValue (ifcfg, "PROXY_METHOD", "none", FALSE); svSetValue (ifcfg, "PROXY_METHOD", "none", FALSE);
/* Write nothing more */ break;
} }
browser_only = nm_setting_proxy_get_browser_only (s_proxy); browser_only = nm_setting_proxy_get_browser_only (s_proxy);