[PATCH v4 1/7] libnm: API for Proxy Feature



libnm-core has been expanded to include proxy settings which clients
like nmcli, nm-connection-editor use to configure proxy in PacRunner. It
offers three modes i.e 'auto', 'manual'and 'none' and accordingly take
data to configure PacRunner. The modes matches on the PacRunner side too.
---
 libnm-core/Makefile.libnm-core     |   2 +
 libnm-core/nm-connection.c         |  18 +
 libnm-core/nm-connection.h         |   2 +
 libnm-core/nm-core-internal.h      |   1 +
 libnm-core/nm-core-types.h         |   1 +
 libnm-core/nm-setting-proxy.c      | 876 +++++++++++++++++++++++++++++++++++++
 libnm-core/nm-setting-proxy.h      | 123 ++++++
 libnm-core/nm-vpn-dbus-interface.h |   3 +
 libnm/NetworkManager.h             |   1 +
 libnm/libnm.ver                    |  19 +
 10 files changed, 1046 insertions(+)
 create mode 100644 libnm-core/nm-setting-proxy.c
 create mode 100644 libnm-core/nm-setting-proxy.h

diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core
index 52c71da..72bfcae 100644
--- a/libnm-core/Makefile.libnm-core
+++ b/libnm-core/Makefile.libnm-core
@@ -32,6 +32,7 @@ libnm_core_headers =                          \
        $(core)/nm-setting-olpc-mesh.h          \
        $(core)/nm-setting-ppp.h                \
        $(core)/nm-setting-pppoe.h              \
+       $(core)/nm-setting-proxy.h              \
        $(core)/nm-setting-serial.h             \
        $(core)/nm-setting-team-port.h          \
        $(core)/nm-setting-team.h               \
@@ -94,6 +95,7 @@ libnm_core_sources =                          \
        $(core)/nm-setting-olpc-mesh.c          \
        $(core)/nm-setting-ppp.c                \
        $(core)/nm-setting-pppoe.c              \
+       $(core)/nm-setting-proxy.c              \
        $(core)/nm-setting-serial.c             \
        $(core)/nm-setting-team-port.c          \
        $(core)/nm-setting-team.c               \
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 2fd3401..eb1efc7 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -2137,6 +2137,24 @@ nm_connection_get_setting_pppoe (NMConnection *connection)
 }
 
 /**
+ * nm_connection_get_setting_proxy:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingProxy the connection might contain.
+ *
+ * Returns:an #NMSettingProxy if the connection contains one, otherwise %NULL
+ *
+ * Since: 1.4
+ **/
+NMSettingProxy *
+nm_connection_get_setting_proxy (NMConnection *connection)
+{
+       g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+       return (NMSettingProxy *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PROXY);
+}
+
+/**
  * nm_connection_get_setting_serial:
  * @connection: the #NMConnection
  *
diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h
index 21e3042..54c4d6f 100644
--- a/libnm-core/nm-connection.h
+++ b/libnm-core/nm-connection.h
@@ -211,6 +211,8 @@ NMSettingMacvlan *         nm_connection_get_setting_macvlan           (NMConnec
 NMSettingOlpcMesh *        nm_connection_get_setting_olpc_mesh         (NMConnection *connection);
 NMSettingPpp *             nm_connection_get_setting_ppp               (NMConnection *connection);
 NMSettingPppoe *           nm_connection_get_setting_pppoe             (NMConnection *connection);
+NM_AVAILABLE_IN_1_2
+NMSettingProxy *           nm_connection_get_setting_proxy             (NMConnection *connection);
 NMSettingSerial *          nm_connection_get_setting_serial            (NMConnection *connection);
 NMSettingTun *             nm_connection_get_setting_tun               (NMConnection *connection);
 NMSettingVpn *             nm_connection_get_setting_vpn               (NMConnection *connection);
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index e3c5bcc..ed7343c 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -50,6 +50,7 @@
 #include "nm-setting-gsm.h"
 #include "nm-setting-infiniband.h"
 #include "nm-setting-ip-tunnel.h"
+#include "nm-setting-proxy.h"
 #include "nm-setting-ip4-config.h"
 #include "nm-setting-ip6-config.h"
 #include "nm-setting-macvlan.h"
diff --git a/libnm-core/nm-core-types.h b/libnm-core/nm-core-types.h
index cd19923..8e7c0ce 100644
--- a/libnm-core/nm-core-types.h
+++ b/libnm-core/nm-core-types.h
@@ -43,6 +43,7 @@ typedef struct _NMSettingGsm              NMSettingGsm;
 typedef struct _NMSettingInfiniband       NMSettingInfiniband;
 typedef struct _NMSettingIPConfig         NMSettingIPConfig;
 typedef struct _NMSettingIPTunnel         NMSettingIPTunnel;
+typedef struct _NMSettingProxy            NMSettingProxy;
 typedef struct _NMSettingIP4Config        NMSettingIP4Config;
 typedef struct _NMSettingIP6Config        NMSettingIP6Config;
 typedef struct _NMSettingMacvlan          NMSettingMacvlan;
diff --git a/libnm-core/nm-setting-proxy.c b/libnm-core/nm-setting-proxy.c
new file mode 100644
index 0000000..af3f4ed
--- /dev/null
+++ b/libnm-core/nm-setting-proxy.c
@@ -0,0 +1,876 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2016 Atul Anand <atulhjp gmail com>.
+ */
+
+#include "nm-default.h"
+
+#include "nm-setting-proxy.h"
+#include "nm-utils.h"
+#include "nm-setting-private.h"
+
+/**
+ * SECTION:nm-setting-proxy
+ * @short_description: Describes Proxy Url, Script and other related properties
+ *
+ * The #NMSettingProxy object is a #NMSetting subclass that describes properties
+ * related to Proxy settings like Pac Url, Pac Script etc.
+ *
+ * NetworkManager support 3 values for the #NMSettingProxy:method property for
+ * proxy. If "auto" is specified then WPAD takes places and the appropriate details
+ * are pushed into PacRunner or user can override this URL with a new PAC url or a
+ * PAC Script. If "manual" is selected then users can specify different proxy servers
+ * for different protocols. If "none" is selected then no proxy configuration is given
+ * to PacRunner to fulfill client queries.
+ **/
+
+G_DEFINE_TYPE_WITH_CODE (NMSettingProxy, nm_setting_proxy, NM_TYPE_SETTING,
+                         _nm_register_setting (PROXY, 4))
+NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PROXY)
+
+#define NM_SETTING_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PROXY, 
NMSettingProxyPrivate))
+
+typedef struct {
+       NMSettingProxyMethod method;
+       char *http_proxy;
+       guint32 http_port;
+       gboolean http_default;
+       char *ssl_proxy;
+       guint32 ssl_port;
+       char *ftp_proxy;
+       guint32 ftp_port;
+       char *socks_proxy;
+       guint32 socks_port;
+       gboolean socks_version_5;
+       GPtrArray *no_proxy_for;
+       gboolean browser_only;
+       char *pac_url;
+       char *pac_script;
+} NMSettingProxyPrivate;
+
+enum {
+       PROP_0,
+       PROP_METHOD,
+       PROP_HTTP_PROXY,
+       PROP_HTTP_PORT,
+       PROP_HTTP_DEFAULT,
+       PROP_SSL_PROXY,
+       PROP_SSL_PORT,
+       PROP_FTP_PROXY,
+       PROP_FTP_PORT,
+       PROP_SOCKS_PROXY,
+       PROP_SOCKS_PORT,
+       PROP_SOCKS_VERSION_5,
+       PROP_NO_PROXY_FOR,
+       PROP_BROWSER_ONLY,
+       PROP_PAC_URL,
+       PROP_PAC_SCRIPT,
+
+       LAST_PROP
+};
+
+/**
+ * nm_setting_proxy_new:
+ *
+ * Creates a new #NMSettingProxy object.
+ *
+ * Returns: the new empty #NMSettingProxy object
+ *
+ * Since: 1.4
+ **/
+NMSetting *
+nm_setting_proxy_new (void)
+{
+       return (NMSetting *) g_object_new (NM_TYPE_SETTING_PROXY, NULL);
+}
+
+/**
+ * nm_setting_proxy_get_method:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns the proxy configuration method. By default the value is "NONE".
+ * "NONE" should be selected for a connection intended for direct network
+ * access.
+ *
+ * Returns: the proxy configuration method
+ *
+ * Since: 1.4
+ **/
+NMSettingProxyMethod
+nm_setting_proxy_get_method (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NM_SETTING_PROXY_METHOD_NONE);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->method;
+}
+
+/**
+ * nm_setting_proxy_get_http_proxy:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the HTTP proxy
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_http_proxy (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->http_proxy;
+}
+
+/**
+ * nm_setting_proxy_get_http_port:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the HTTP port number
+ *
+ * Since: 1.4
+ **/
+guint32
+nm_setting_proxy_get_http_port (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), 0);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->http_port;
+}
+
+/**
+ * nm_setting_proxy_get_http_default:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: TRUE if HTTP Proxy is default for all
+ * protocols. FALSE if not.
+ *
+ * Since: 1.4
+ **/
+gboolean
+nm_setting_proxy_get_http_default (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), FALSE);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->http_default;
+}
+
+/**
+ * nm_setting_proxy_get_ssl_proxy:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the SSL proxy
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_ssl_proxy (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->ssl_proxy;
+}
+
+/**
+ * nm_setting_proxy_get_ssl_port:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the SSL port number
+ *
+ * Since: 1.4
+ **/
+guint32
+nm_setting_proxy_get_ssl_port (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), 0);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->ssl_port;
+}
+
+/**
+ * nm_setting_proxy_get_ftp_proxy:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the FTP proxy
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_ftp_proxy (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->ftp_proxy;
+}
+
+/**
+ * nm_setting_proxy_get_ftp_port:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the FTP port number
+ *
+ * Since: 1.4
+ **/
+guint32
+nm_setting_proxy_get_ftp_port (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), 0);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->ftp_port;
+}
+
+/**
+ * nm_setting_proxy_get_socks_proxy:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the SOCKS proxy
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_socks_proxy (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->socks_proxy;
+}
+
+/**
+ * nm_setting_proxy_get_socks_port:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the SOCKS port number
+ *
+ * Since: 1.4
+ **/
+guint32
+nm_setting_proxy_get_socks_port (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), 0);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->socks_port;
+}
+
+/**
+ * nm_setting_proxy_get_socks_version_5:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: TRUE if SOCKS version is 5.
+ * FALSE if SOCKS version is 4.
+ *
+ * Since: 1.4
+**/
+gboolean
+nm_setting_proxy_get_socks_version_5 (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), FALSE);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->socks_version_5;
+}
+
+/**
+ * nm_setting_proxy_get_no_proxy_for:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the hosts to be excluded from proxy
+ *
+ * Since: 1.4
+ **/
+char **
+nm_setting_proxy_get_no_proxy_for (NMSettingProxy *setting)
+{
+       NMSettingProxyPrivate *priv;
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       priv = NM_SETTING_PROXY_GET_PRIVATE (setting);
+
+       return _nm_utils_ptrarray_to_strv (priv->no_proxy_for);
+}
+
+/**
+ * nm_setting_proxy_get_browser_only:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: TRUE if this proxy configuration is only for Browser
+ * clients/schemes otherwise FALSE.
+ *
+ * Since: 1.4
+ **/
+gboolean
+nm_setting_proxy_get_browser_only (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), FALSE);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->browser_only;
+}
+
+/**
+ * nm_setting_proxy_get_pac_url:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the PAC url for obtaining PAC file
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_pac_url (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->pac_url;
+}
+
+/**
+ * nm_setting_proxy_get_pac_script:
+ * @setting: the #NMSettingProxy
+ *
+ * Returns: the path to PAC Script
+ *
+ * Since: 1.4
+ **/
+const char *
+nm_setting_proxy_get_pac_script (NMSettingProxy *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_PROXY (setting), NULL);
+
+       return NM_SETTING_PROXY_GET_PRIVATE (setting)->pac_script;
+}
+
+static gboolean
+verify (NMSetting *setting, NMConnection *connection, GError **error)
+{
+       NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (setting);
+       NMSettingProxyMethod method;
+
+       method = priv->method;
+       if (method == NM_SETTING_PROXY_METHOD_AUTO || method == NM_SETTING_PROXY_METHOD_NONE) {
+               if (priv->http_proxy) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_HTTP_PROXY);
+                       return FALSE;
+               }
+
+               if (priv->http_port) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_HTTP_PORT);
+                       return FALSE;
+               }
+
+               if (priv->http_default) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_HTTP_DEFAULT);
+                       return FALSE;
+               }
+
+               if (priv->ssl_proxy) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_SSL_PROXY);
+                       return FALSE;
+               }
+
+               if (priv->ssl_port) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_SSL_PORT);
+                       return FALSE;
+               }
+
+               if (priv->ftp_proxy) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_FTP_PROXY);
+                       return FALSE;
+               }
+
+               if (priv->ftp_port) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_FTP_PORT);
+                       return FALSE;
+               }
+
+               if (priv->socks_proxy) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_SOCKS_PROXY);
+                       return FALSE;
+               }
+
+               if (priv->socks_port) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_SOCKS_PORT);
+                       return FALSE;
+               }
+
+               if (priv->socks_version_5) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_SOCKS_VERSION_5);
+                       return FALSE;
+               }
+
+               if (priv->no_proxy_for->len > 0) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method auto/none"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_NO_PROXY_FOR);
+                       return FALSE;
+               }
+
+               if (method == NM_SETTING_PROXY_METHOD_NONE) {
+                       if (priv->pac_url) {
+                               g_set_error (error,
+                                            NM_CONNECTION_ERROR,
+                                            NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                            _("this property is not allowed for method none"));
+                               g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_PAC_URL);
+                               return FALSE;
+                       }
+
+                       if (priv->pac_script) {
+                               g_set_error (error,
+                                            NM_CONNECTION_ERROR,
+                                            NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                            _("this property is not allowed for method none"));
+                               g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_PAC_SCRIPT);
+                               return FALSE;
+                       }
+               }
+       } else if (method == NM_SETTING_PROXY_METHOD_MANUAL) {
+               if (priv->pac_url) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method manual"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_PAC_URL);
+                       return FALSE;
+               }
+
+               if (priv->pac_script) {
+                       g_set_error (error,
+                                    NM_CONNECTION_ERROR,
+                                    NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                    _("this property is not allowed for method manual"));
+                       g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, 
NM_SETTING_PROXY_PAC_SCRIPT);
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
+static void
+nm_setting_proxy_init (NMSettingProxy *setting)
+{
+       NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (setting);
+
+       priv->method = NM_SETTING_PROXY_METHOD_NONE;
+       priv->no_proxy_for = g_ptr_array_new_with_free_func (g_free);
+}
+
+static void
+finalize (GObject *object)
+{
+       NMSettingProxy *self = NM_SETTING_PROXY (object);
+       NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (self);
+
+       g_free (priv->http_proxy);
+       g_free (priv->ssl_proxy);
+       g_free (priv->ftp_proxy);
+       g_free (priv->socks_proxy);
+       g_free (priv->pac_url);
+       g_free (priv->pac_script);
+
+       g_ptr_array_unref (priv->no_proxy_for);
+
+       G_OBJECT_CLASS (nm_setting_proxy_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+                         GValue *value, GParamSpec *pspec)
+{
+       NMSettingProxy *setting = NM_SETTING_PROXY (object);
+
+       switch (prop_id) {
+       case PROP_METHOD:
+               g_value_set_int (value, nm_setting_proxy_get_method (setting));
+               break;
+       case PROP_HTTP_PROXY:
+               g_value_set_string (value, nm_setting_proxy_get_http_proxy (setting));
+               break;
+       case PROP_HTTP_PORT:
+               g_value_set_uint (value, nm_setting_proxy_get_http_port (setting));
+               break;
+       case PROP_HTTP_DEFAULT:
+               g_value_set_boolean (value, nm_setting_proxy_get_http_default (setting));
+               break;
+       case PROP_SSL_PROXY:
+               g_value_set_string (value, nm_setting_proxy_get_ssl_proxy (setting));
+               break;
+       case PROP_SSL_PORT:
+               g_value_set_uint (value, nm_setting_proxy_get_ssl_port (setting));
+               break;
+       case PROP_FTP_PROXY:
+               g_value_set_string (value, nm_setting_proxy_get_ftp_proxy (setting));
+               break;
+       case PROP_FTP_PORT:
+               g_value_set_uint (value, nm_setting_proxy_get_ftp_port (setting));
+               break;
+       case PROP_SOCKS_PROXY:
+               g_value_set_string (value, nm_setting_proxy_get_socks_proxy (setting));
+               break;
+       case PROP_SOCKS_PORT:
+               g_value_set_uint (value, nm_setting_proxy_get_socks_port (setting));
+               break;
+       case PROP_SOCKS_VERSION_5:
+               g_value_set_boolean (value, nm_setting_proxy_get_socks_version_5 (setting));
+               break;
+       case PROP_NO_PROXY_FOR:
+               g_value_take_boxed (value, nm_setting_proxy_get_no_proxy_for (setting));
+               break;
+       case PROP_BROWSER_ONLY:
+               g_value_set_boolean (value, nm_setting_proxy_get_browser_only (setting));
+               break;
+       case PROP_PAC_URL:
+               g_value_set_string (value, nm_setting_proxy_get_pac_url (setting));
+               break;
+       case PROP_PAC_SCRIPT:
+               g_value_set_string (value, nm_setting_proxy_get_pac_script (setting));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+       NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (object);
+
+       switch (prop_id) {
+       case PROP_METHOD:
+               priv->method = g_value_get_int (value);
+               break;
+       case PROP_HTTP_PROXY:
+               g_free (priv->http_proxy);
+               priv->http_proxy = g_value_dup_string (value);
+               break;
+       case PROP_HTTP_PORT:
+               priv->http_port = g_value_get_uint (value);
+               break;
+       case PROP_HTTP_DEFAULT:
+               priv->http_default = g_value_get_boolean (value);
+               break;
+       case PROP_SSL_PROXY:
+               g_free (priv->ssl_proxy);
+               priv->ssl_proxy = g_value_dup_string (value);
+               break;
+       case PROP_SSL_PORT:
+               priv->ssl_port = g_value_get_uint (value);
+               break;
+       case PROP_FTP_PROXY:
+               g_free (priv->ftp_proxy);
+               priv->ftp_proxy = g_value_dup_string (value);
+               break;
+       case PROP_FTP_PORT:
+               priv->ftp_port = g_value_get_uint (value);
+               break;
+       case PROP_SOCKS_PROXY:
+               g_free (priv->socks_proxy);
+               priv->socks_proxy = g_value_dup_string (value);
+               break;
+       case PROP_SOCKS_PORT:
+               priv->socks_port = g_value_get_uint (value);
+               break;
+       case PROP_SOCKS_VERSION_5:
+               priv->socks_version_5 = g_value_get_boolean (value);
+               break;
+       case PROP_NO_PROXY_FOR:
+               g_ptr_array_unref (priv->no_proxy_for);
+               priv->no_proxy_for = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
+               break;
+       case PROP_BROWSER_ONLY:
+               priv->browser_only = g_value_get_boolean (value);
+               break;
+       case PROP_PAC_URL:
+               g_free (priv->pac_url);
+               priv->pac_url = g_value_dup_string (value);
+               break;
+       case PROP_PAC_SCRIPT:
+               g_free (priv->pac_script);
+               priv->pac_script = g_value_dup_string (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nm_setting_proxy_class_init (NMSettingProxyClass *setting_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
+       NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+
+       g_type_class_add_private (setting_class, sizeof (NMSettingProxyPrivate));
+
+       /* virtual methods */
+       object_class->set_property = set_property;
+       object_class->get_property = get_property;
+       object_class->finalize = finalize;
+       parent_class->verify = verify;
+
+       /**
+        * NMSettingProxy:method:
+        *
+        * Method for proxy configuration, Default is "NONE"
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_METHOD,
+            g_param_spec_int (NM_SETTING_PROXY_METHOD, "", "",
+                              G_MININT32, G_MAXINT32, NM_SETTING_PROXY_METHOD_NONE,
+                              G_PARAM_READWRITE |
+                              G_PARAM_CONSTRUCT |
+                              G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:http-proxy:
+        *
+        * HTTP proxy
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_HTTP_PROXY,
+            g_param_spec_string (NM_SETTING_PROXY_HTTP_PROXY, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:http-port:
+        *
+        * Port number for HTTP proxy
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_HTTP_PORT,
+            g_param_spec_uint (NM_SETTING_PROXY_HTTP_PORT, "", "",
+                               0, G_MAXUINT32, 0,
+                               G_PARAM_READWRITE |
+                               G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:http-default:
+        *
+        * Make HTTP proxy default for all protocols.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_HTTP_DEFAULT,
+            g_param_spec_boolean (NM_SETTING_PROXY_HTTP_DEFAULT, "", "",
+                                  FALSE,
+                                  G_PARAM_READWRITE |
+                                  G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:ssl-proxy:
+        *
+        * SSL proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_SSL_PROXY,
+            g_param_spec_string (NM_SETTING_PROXY_SSL_PROXY, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:ssl-port:
+        *
+        * Port number for SSL proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_SSL_PORT,
+            g_param_spec_uint (NM_SETTING_PROXY_SSL_PORT, "", "",
+                               0, G_MAXUINT32, 0,
+                               G_PARAM_READWRITE |
+                               G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:ftp-proxy:
+        *
+        * FTP proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_FTP_PROXY,
+            g_param_spec_string (NM_SETTING_PROXY_FTP_PROXY, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:ftp-port:
+        *
+        * Port number for FTP proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_FTP_PORT,
+            g_param_spec_uint (NM_SETTING_PROXY_FTP_PORT, "", "",
+                               0, G_MAXUINT32, 0,
+                               G_PARAM_READWRITE |
+                               G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:socks-proxy:
+        *
+        * SOCKS proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_SOCKS_PROXY,
+            g_param_spec_string (NM_SETTING_PROXY_SOCKS_PROXY, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:socks-port:
+        *
+        * Port number for SOCKS proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_SOCKS_PORT,
+            g_param_spec_uint (NM_SETTING_PROXY_SOCKS_PORT, "", "",
+                               0, G_MAXUINT32, 0,
+                               G_PARAM_READWRITE |
+                               G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:socks-version-5:
+        *
+        * set %TRUE if SOCKS version is 5.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_SOCKS_VERSION_5,
+            g_param_spec_boolean (NM_SETTING_PROXY_SOCKS_VERSION_5, "", "",
+                                  FALSE,
+                                  G_PARAM_READWRITE |
+                                  G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:nm-proxy-for:
+        *
+        * Array of host to be excluded from proxy.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_NO_PROXY_FOR,
+            g_param_spec_boxed (NM_SETTING_PROXY_NO_PROXY_FOR, "", "",
+                                G_TYPE_STRV,
+                                G_PARAM_READWRITE |
+                                G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:browser-only:
+        *
+        * TRUE if Proxy is for Browser Stuff.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_BROWSER_ONLY,
+            g_param_spec_boolean (NM_SETTING_PROXY_BROWSER_ONLY, "", "",
+                                      FALSE,
+                                      G_PARAM_READWRITE |
+                                      G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:pac-url:
+        *
+        * PAC Url for obtaining PAC File.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_PAC_URL,
+            g_param_spec_string (NM_SETTING_PROXY_PAC_URL, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NMSettingProxy:pac-script:
+        *
+        * PAC Script location.
+        *
+        * Since: 1.4
+        **/
+       g_object_class_install_property
+           (object_class, PROP_PAC_SCRIPT,
+            g_param_spec_string (NM_SETTING_PROXY_PAC_SCRIPT, "", "",
+                                 NULL,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS));
+}
diff --git a/libnm-core/nm-setting-proxy.h b/libnm-core/nm-setting-proxy.h
new file mode 100644
index 0000000..8e3aaaa
--- /dev/null
+++ b/libnm-core/nm-setting-proxy.h
@@ -0,0 +1,123 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2016 Atul Anand <atulhjp gmail com>.
+ */
+
+#ifndef __NM_SETTING_PROXY_H__
+#define __NM_SETTING_PROXY_H__
+
+#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
+#error "Only <NetworkManager.h> can be included directly."
+#endif
+
+#include <nm-setting.h>
+
+G_BEGIN_DECLS
+
+/**
+ * NMSettingProxyMethod:
+ * @NM_SETTING_PROXY_METHOD_AUTO:   DHCP obtained Proxy
+ * @NM_SETTING_PROXY_METHOD_MANUAL: Manual mode
+ * @NM_SETTING_PROXY_METHOD_NONE:   No Proxy for the Connection
+ *
+ * The Proxy method.
+ *
+ * Since: 1.4
+ */
+typedef enum {
+       NM_SETTING_PROXY_METHOD_AUTO = 0,
+       NM_SETTING_PROXY_METHOD_MANUAL,
+       NM_SETTING_PROXY_METHOD_NONE
+} NMSettingProxyMethod;
+
+#define NM_TYPE_SETTING_PROXY            (nm_setting_proxy_get_type ())
+#define NM_SETTING_PROXY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_PROXY, 
NMSettingProxy))
+#define NM_SETTING_PROXY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_PROXY, 
NMSettingProxyClass))
+#define NM_IS_SETTING_PROXY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_PROXY))
+#define NM_IS_SETTING_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_PROXY))
+#define NM_SETTING_PROXY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_PROXY, 
NMSettingProxyClass))
+
+#define NM_SETTING_PROXY_SETTING_NAME "proxy"
+
+#define NM_SETTING_PROXY_METHOD "method"
+#define NM_SETTING_PROXY_HTTP_PROXY "http-proxy"
+#define NM_SETTING_PROXY_HTTP_PORT "http-port"
+#define NM_SETTING_PROXY_HTTP_DEFAULT "http-default"
+#define NM_SETTING_PROXY_SSL_PROXY "ssl-proxy"
+#define NM_SETTING_PROXY_SSL_PORT "ssl-port"
+#define NM_SETTING_PROXY_FTP_PROXY "ftp-proxy"
+#define NM_SETTING_PROXY_FTP_PORT "ftp-port"
+#define NM_SETTING_PROXY_SOCKS_PROXY "socks-proxy"
+#define NM_SETTING_PROXY_SOCKS_PORT "socks-port"
+#define NM_SETTING_PROXY_SOCKS_VERSION_5 "socks-version-5"
+#define NM_SETTING_PROXY_NO_PROXY_FOR "no-proxy-for"
+#define NM_SETTING_PROXY_BROWSER_ONLY "browser-only"
+#define NM_SETTING_PROXY_PAC_URL "pac-url"
+#define NM_SETTING_PROXY_PAC_SCRIPT "pac-script"
+
+struct _NMSettingProxy {
+       NMSetting parent;
+};
+
+typedef struct {
+       NMSettingClass parent;
+
+       gpointer padding[4];
+} NMSettingProxyClass;
+
+NM_AVAILABLE_IN_1_4
+GType nm_setting_proxy_get_type (void);
+
+NM_AVAILABLE_IN_1_4
+NMSetting *nm_setting_proxy_new (void);
+
+NM_AVAILABLE_IN_1_4
+NMSettingProxyMethod nm_setting_proxy_get_method (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_http_proxy (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+guint32 nm_setting_proxy_get_http_port (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+gboolean nm_setting_proxy_get_http_default (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_ssl_proxy (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+guint32 nm_setting_proxy_get_ssl_port (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_ftp_proxy (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+guint32 nm_setting_proxy_get_ftp_port (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_socks_proxy (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+guint32 nm_setting_proxy_get_socks_port (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+gboolean nm_setting_proxy_get_socks_version_5 (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+char **nm_setting_proxy_get_no_proxy_for (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+gboolean nm_setting_proxy_get_browser_only (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_pac_url (NMSettingProxy *setting);
+NM_AVAILABLE_IN_1_4
+const char *nm_setting_proxy_get_pac_script (NMSettingProxy *setting);
+
+G_END_DECLS
+
+#endif /* __NM_SETTING_PROXY_H__ */
diff --git a/libnm-core/nm-vpn-dbus-interface.h b/libnm-core/nm-vpn-dbus-interface.h
index 3295a1a..1495c95 100644
--- a/libnm-core/nm-vpn-dbus-interface.h
+++ b/libnm-core/nm-vpn-dbus-interface.h
@@ -183,6 +183,9 @@ typedef enum {
 /* string: VPN interface name (tun0, tap0, etc) */
 #define NM_VPN_PLUGIN_CONFIG_TUNDEV      "tundev"
 
+/* string: Proxy PAC */
+#define NM_VPN_PLUGIN_CONFIG_PROXY_PAC   "pac"
+
 /* string: Login message */
 #define NM_VPN_PLUGIN_CONFIG_BANNER      "banner"
 
diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h
index b5dab8f..cca05cf 100644
--- a/libnm/NetworkManager.h
+++ b/libnm/NetworkManager.h
@@ -62,6 +62,7 @@
 #include <nm-setting-infiniband.h>
 #include <nm-setting-ip-config.h>
 #include <nm-setting-ip-tunnel.h>
+#include <nm-setting-proxy.h>
 #include <nm-setting-ip4-config.h>
 #include <nm-setting-ip6-config.h>
 #include <nm-setting-macvlan.h>
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index cc2fc7d..25e71cc 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1066,6 +1066,25 @@ libnm_1_2_4 {
 libnm_1_4_0 {
 global:
        nm_device_team_get_config;
+       nm_connection_get_setting_proxy;
+       nm_setting_proxy_get_type;
+       nm_setting_proxy_new;
+       nm_setting_proxy_get_method;
+       nm_setting_proxy_method_get_type;
+       nm_setting_proxy_get_http_proxy;
+       nm_setting_proxy_get_http_port;
+       nm_setting_proxy_get_http_default;
+       nm_setting_proxy_get_ssl_proxy;
+       nm_setting_proxy_get_ssl_port;
+       nm_setting_proxy_get_ftp_proxy;
+       nm_setting_proxy_get_ftp_port;
+       nm_setting_proxy_get_socks_proxy;
+       nm_setting_proxy_get_socks_port;
+       nm_setting_proxy_get_socks_version_5;
+       nm_setting_proxy_get_pac_script;
+       nm_setting_proxy_get_no_proxy_for;
+       nm_setting_proxy_get_browser_only;
+       nm_setting_proxy_get_pac_url;
        nm_setting_connection_get_stable_id;
        nm_setting_ip6_config_get_token;
        nm_setting_ip_config_get_dns_priority;
-- 
2.5.5




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]