Re: [PATCH 1/5] New GObject NMProxyConfig added to hold proxy details.



Hi,

nice work; the patch set looks overall very good. I'll take a closer
look tomorrow.

Two general nitpicks:

Please comment more. Especially the non-static procedures often need a
Gtk-Doc block. E.g. looking at nm_pacrunner_manager_send() I have very
little idea why do I need to pass ip* configs, and what are they used
for without digging too deep into the code. Also, the logic sometimes
need comments: for instance after a quick look at add_ip4_config() I
can't figure why it only works for type=vpn.

Also, please add license blocks for files you add and copyright notices
wherever you add non-trivial amount of code.

Thank you,
Lubo

On Fri, 2016-06-24 at 00:42 +0530, Atul Anand wrote:
A new Object NMProxyConfig added with properties for proxies,
PAC Url and PAC Script. Getters are setters implemented for
manipulating those fields.
---
 src/Makefile.am       |   4 +
 src/nm-proxy-config.c | 243
++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nm-proxy-config.h |  53 +++++++++++
 3 files changed, 300 insertions(+)
 create mode 100644 src/nm-proxy-config.c
 create mode 100644 src/nm-proxy-config.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 5e289d9..700cfc4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -415,6 +415,8 @@ libNetworkManager_la_SOURCES = \
      nm-exported-object.h \
      nm-firewall-manager.c \
      nm-firewall-manager.h \
+     nm-proxy-config.c \
+     nm-proxy-config.h \
      nm-ip4-config.c \
      nm-ip4-config.h \
      nm-ip6-config.c \
@@ -565,6 +567,8 @@ libnm_iface_helper_la_SOURCES = \
      \
      nm-exported-object.c \
      nm-exported-object.h \
+     nm-proxy-config.c \
+     nm-proxy-config.h \
      nm-ip4-config.c \
      nm-ip4-config.h \
      nm-ip6-config.c \
diff --git a/src/nm-proxy-config.c b/src/nm-proxy-config.c
new file mode 100644
index 0000000..93f9b21
--- /dev/null
+++ b/src/nm-proxy-config.c
@@ -0,0 +1,243 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4
-*- */
+
+#include "nm-default.h"
+
+#include "nm-proxy-config.h"
+
+#include <string.h>
+
+#include "nm-utils.h"
+#include "NetworkManagerUtils.h"
+
+#define NM_PROXY_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE
((o), NM_TYPE_PROXY_CONFIG, NMProxyConfigPrivate))
+
+G_DEFINE_TYPE (NMProxyConfig, nm_proxy_config, G_TYPE_OBJECT)
+
+typedef struct {
+     NMProxyConfigMethod method;
+     GPtrArray *proxies;
+     char *pac_url;
+     char *pac_script;
+} NMProxyConfigPrivate;
+
+NM_GOBJECT_PROPERTIES_DEFINE (NMProxyConfig,
+     PROP_METHOD,
+     PROP_PROXIES,
+     PROP_PAC_URL,
+     PROP_PAC_SCRIPT,
+);
+
+NMProxyConfig *
+nm_proxy_config_new (void)
+{
+     return NM_PROXY_CONFIG (g_object_new (NM_TYPE_PROXY_CONFIG,
NULL));
+}
+
+void
+nm_proxy_config_set_method (NMProxyConfig *config,
NMProxyConfigMethod method)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     priv->method = method;
+}
+
+NMProxyConfigMethod
+nm_proxy_config_get_method (const NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     return priv->method;
+}
+
+void
+nm_proxy_config_reset_proxies (NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     if (priv->proxies->len !=0) {
+             g_ptr_array_set_size (priv->proxies, 0);
+             _notify (config, PROP_PROXIES);
+     }
+}
+
+void
+nm_proxy_config_add_proxy (NMProxyConfig *config, const char *proxy)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+     int i;
+
+     g_return_if_fail (proxy != NULL);
+     g_return_if_fail (proxy[0] != '\0');
+
+     for (i = 0; i < priv->proxies->len; i++)
+             if (!g_strcmp0 (g_ptr_array_index (priv->proxies,
i), proxy))
+                     return;
+
+     g_ptr_array_add (priv->proxies, g_strdup (proxy));
+     _notify (config, PROP_PROXIES);
+}
+
+void
+nm_proxy_config_del_proxy (NMProxyConfig *config, guint i)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     g_return_if_fail (i < priv->proxies->len);
+
+     g_ptr_array_remove_index (priv->proxies, i);
+     _notify (config, PROP_PROXIES);
+}
+
+guint32
+nm_proxy_config_get_num_proxies (const NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     return priv->proxies->len;
+}
+
+const char *
+nm_proxy_config_get_proxy (const NMProxyConfig *config, guint i)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     return g_ptr_array_index (priv->proxies, i);
+}
+
+void
+nm_proxy_config_set_pac_url (NMProxyConfig *config, const char *url)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     g_free (priv->pac_url);
+     priv->pac_url = g_strdup (url);
+}
+
+const char *
+nm_proxy_config_get_pac_url (const NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     return priv->pac_url;
+}
+
+void
+nm_proxy_config_set_pac_script (NMProxyConfig *config, const char
*script)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     g_free (priv->pac_script);
+     priv->pac_script = g_strdup (script);
+}
+
+const char *
+nm_proxy_config_get_pac_script (const NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     return priv->pac_script;
+}
+
+static void
+nm_proxy_config_init (NMProxyConfig *config)
+{
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     priv->method = NM_PROXY_CONFIG_METHOD_NONE;
+     priv->proxies = g_ptr_array_new_with_free_func (g_free);
+}
+
+static void
+finalize (GObject *object)
+{
+     NMProxyConfig *self = NM_PROXY_CONFIG (object);
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(self);
+
+     g_ptr_array_unref (priv->proxies);
+     g_free (priv->pac_url);
+     g_free (priv->pac_script);
+
+     G_OBJECT_CLASS (nm_proxy_config_parent_class)->finalize
(object);
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
+{
+     NMProxyConfig *config = NM_PROXY_CONFIG (object);
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(config);
+
+     switch (prop_id) {
+     case PROP_METHOD:
+             g_value_set_int (value, priv->method);
+             break;
+     case PROP_PROXIES:
+             nm_utils_g_value_set_strv (value, priv->proxies);
+             break;
+     case PROP_PAC_URL:
+             g_value_set_string (value, priv->pac_url);
+             break;
+     case PROP_PAC_SCRIPT:
+             g_value_set_string (value, priv->pac_script);
+             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)
+{
+     NMProxyConfig *self = NM_PROXY_CONFIG (object);
+     NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE
(self);
+
+     switch (prop_id) {
+     case PROP_METHOD:
+             priv->method = g_value_get_int (value);
+             break;
+     default:
+             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id,
pspec);
+             break;
+     }
+}
+
+static void
+nm_proxy_config_class_init (NMProxyConfigClass *klass)
+{
+     GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+     g_type_class_add_private (object_class, sizeof
(NMProxyConfigPrivate));
+
+     /* virtual methods */
+     object_class->get_property = get_property;
+     object_class->set_property = set_property;
+     object_class->finalize = finalize;
+
+     obj_properties[PROP_METHOD] =
+             g_param_spec_int (NM_PROXY_CONFIG_METHOD, "", "",
+                               0, G_MAXINT, 0,
+                               G_PARAM_READWRITE |
+                               G_PARAM_CONSTRUCT_ONLY |
+                               G_PARAM_STATIC_STRINGS);
+     obj_properties[PROP_PROXIES] =
+             g_param_spec_boxed (NM_PROXY_CONFIG_PROXIES, "", "",
+                                 G_TYPE_STRV,
+                                 G_PARAM_READABLE |
+                                 G_PARAM_STATIC_STRINGS);
+     obj_properties[PROP_PAC_URL] =
+             g_param_spec_string (NM_PROXY_CONFIG_PAC_URL, "",
"",
+                                  NULL,
+                                  G_PARAM_READABLE |
+                                  G_PARAM_STATIC_STRINGS);
+     obj_properties[PROP_PAC_SCRIPT] =
+             g_param_spec_string (NM_PROXY_CONFIG_PAC_SCRIPT, "",
"",
+                                  NULL,
+                                  G_PARAM_READABLE |
+                                  G_PARAM_STATIC_STRINGS);
+
+     g_object_class_install_properties (object_class,
_PROPERTY_ENUMS_LAST, obj_properties);
+}
diff --git a/src/nm-proxy-config.h b/src/nm-proxy-config.h
new file mode 100644
index 0000000..b709e82
--- /dev/null
+++ b/src/nm-proxy-config.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4
-*- */
+
+#include "nm-default.h"
+
+#ifndef __NETWORKMANAGER_PROXY_CONFIG_H__
+#define __NETWORKMANAGER_PROXY_CONFIG_H__
+
+typedef enum {
+     NM_PROXY_CONFIG_METHOD_NONE = 0,
+     NM_PROXY_CONFIG_METHOD_AUTO,
+     NM_PROXY_CONFIG_METHOD_MANUAL
+} NMProxyConfigMethod;
+
+#define NM_TYPE_PROXY_CONFIG (nm_proxy_config_get_type ())
+#define NM_PROXY_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
NM_TYPE_PROXY_CONFIG, NMProxyConfig))
+#define NM_PROXY_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST
((klass), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass))
+#define NM_IS_PROXY_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
NM_TYPE_PROXY_CONFIG))
+#define NM_IS_PROXY_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE
((klass), NM_TYPE_PROXY_CONFIG))
+#define NM_PROXY_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS
((obj), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass))
+
+struct _NMProxyConfig {
+     GObject parent;
+};
+
+typedef struct {
+     GObjectClass parent;
+} NMProxyConfigClass;
+
+#define NM_PROXY_CONFIG_METHOD "method"
+#define NM_PROXY_CONFIG_PROXIES "proxies"
+#define NM_PROXY_CONFIG_PAC_URL "pac-url"
+#define NM_PROXY_CONFIG_PAC_SCRIPT "pac-script"
+
+GType nm_proxy_config_get_type (void);
+
+NMProxyConfig * nm_proxy_config_new (void);
+
+void nm_proxy_config_set_method (NMProxyConfig *config,
NMProxyConfigMethod method);
+NMProxyConfigMethod nm_proxy_config_get_method (const NMProxyConfig
*config);
+
+void nm_proxy_config_reset_proxies (NMProxyConfig *config);
+void nm_proxy_config_add_proxy (NMProxyConfig *config, const char
*proxy);
+void nm_proxy_config_del_proxy (NMProxyConfig *config, guint i);
+guint32 nm_proxy_config_get_num_proxies (const NMProxyConfig
*config);
+const char * nm_proxy_config_get_proxy (const NMProxyConfig *config,
guint i);
+
+void nm_proxy_config_set_pac_url (NMProxyConfig *config, const char
*url);
+const char * nm_proxy_config_get_pac_url (const NMProxyConfig
*config);
+
+void nm_proxy_config_set_pac_script (NMProxyConfig *config, const
char *script);
+const char * nm_proxy_config_get_pac_script (const NMProxyConfig
*config);
+
+#endif /* __NETWORKMANAGER_PROXY_CONFIG_H__ */


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