Merge lp:~kvalo/indicator-network/libconnman-ipv4 into lp:~indicator-applet-developers/indicator-network/indicator-network

Proposed by Kalle Valo
Status: Merged
Merged at revision: 140
Proposed branch: lp:~kvalo/indicator-network/libconnman-ipv4
Merge into: lp:~indicator-applet-developers/indicator-network/indicator-network
Diff against target: 1089 lines (+744/-39)
12 files modified
.bzrignore (+1/-0)
src/libconnman/Connman-1.0.vapi (+28/-4)
src/libconnman/Makefile.am (+3/-1)
src/libconnman/connman-ipv4.c (+315/-0)
src/libconnman/connman-ipv4.h (+93/-0)
src/libconnman/connman-manager.c (+10/-3)
src/libconnman/connman-service.c (+216/-23)
src/libconnman/connman-service.h (+6/-0)
src/libconnman/connman.h (+2/-0)
src/libconnman/generate_vapi (+6/-1)
tests/connman-mock/connman-mock (+9/-5)
tests/libconnman-vala/libconnman-vala.vala (+55/-2)
To merge this branch: bzr merge lp:~kvalo/indicator-network/libconnman-ipv4
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+48452@code.launchpad.net

Description of the change

ipv4 implementation for libconnman. If this is ok, I'm planning to duplicate for ipv6 as well.

ipv6 is almost same the, but not quite, so I'm planning to make ipv6 just a copy of ipv4 implementation.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks good. Really nice work Kalle!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-01-25 10:10:02 +0000
3+++ .bzrignore 2011-02-03 11:39:11 +0000
4@@ -114,3 +114,4 @@
5 tests/libconnman-vala/libconnman-vala
6 tests/libconnman-vala/libconnman-vala.c
7 tests/libconnman-vala/libconnman_vala_vala.stamp
8+src/libconnman/libconnman_la-connman-ipv4.lo
9
10=== modified file 'src/libconnman/Connman-1.0.vapi'
11--- src/libconnman/Connman-1.0.vapi 2011-01-31 17:40:06 +0000
12+++ src/libconnman/Connman-1.0.vapi 2011-02-03 11:39:11 +0000
13@@ -1,13 +1,25 @@
14 /*
15 Connman-1.0.vapi generated by vapigen, but modified manually by kvalo.
16-
17- Changes:
18- o correct cheader_filename attributes
19-
20 */
21
22 [CCode (cprefix = "Connman", lower_case_cprefix = "connman_")]
23 namespace Connman {
24+ [CCode (cheader_filename = "connman-ipv4.h")]
25+ public class IPv4 : GLib.Object {
26+ [CCode (has_construct_function = false)]
27+ public IPv4 (Connman.IPv4Method method, string address, string netmask, string gateway) throws GLib.Error;
28+ public unowned string get_address ();
29+ public unowned string get_gateway ();
30+ public Connman.IPv4Method get_method ();
31+ public unowned string get_method_as_string ();
32+ public unowned string get_netmask ();
33+ [CCode (has_construct_function = false)]
34+ public IPv4.with_strings (string method, string address, string netmask, string gateway) throws GLib.Error;
35+ public string address { get; construct; }
36+ public string gateway { get; construct; }
37+ public uint method { get; construct; }
38+ public string netmask { get; construct; }
39+ }
40 [CCode (cheader_filename = "connman-manager.h")]
41 public class Manager : GLib.Object {
42 public weak GLib.Object parent;
43@@ -40,6 +52,8 @@
44 public unowned string get_error ();
45 public bool get_favorite ();
46 public bool get_immutable ();
47+ public unowned Connman.IPv4 get_ipv4 ();
48+ public unowned Connman.IPv4 get_ipv4_configuration ();
49 public bool get_login_required ();
50 public unowned string get_mcc ();
51 public unowned string get_mnc ();
52@@ -63,6 +77,7 @@
53 public void set_apn (string apn);
54 public void set_autoconnect (bool autoconnect);
55 public void set_domains_configuration ([CCode (array_length = false, array_null_terminated = true)] string[] domains);
56+ public void set_ipv4_configuration (Connman.IPv4 ipv4);
57 public void set_nameservers_configuration ([CCode (array_length = false, array_null_terminated = true)] string[] nameservers);
58 public void set_passphrase (string passphrase);
59 public static unowned string state2str (Connman.ServiceState state);
60@@ -78,6 +93,8 @@
61 public string error { get; }
62 public bool favorite { get; }
63 public bool immutable { get; }
64+ public Connman.IPv4 ipv4 { get; }
65+ public Connman.IPv4 ipv4_configuration { get; set; }
66 public bool login_required { get; }
67 public string mcc { get; }
68 public string mnc { get; }
69@@ -99,6 +116,13 @@
70 [NoAccessorMethod]
71 public uint type { get; }
72 }
73+ [CCode (cprefix = "CONNMAN_IPV4_METHOD_", cheader_filename = "connman-service.h")]
74+ public enum IPv4Method {
75+ OFF,
76+ MANUAL,
77+ FIXED,
78+ AUTO
79+ }
80 [CCode (cprefix = "CONNMAN_SERVICE_MODE_", cheader_filename = "connman-service.h")]
81 public enum ServiceMode {
82 MANAGED,
83
84=== modified file 'src/libconnman/Makefile.am'
85--- src/libconnman/Makefile.am 2011-02-01 07:51:20 +0000
86+++ src/libconnman/Makefile.am 2011-02-03 11:39:11 +0000
87@@ -5,7 +5,9 @@
88 connman-manager.c \
89 connman-manager.h \
90 connman-service.c \
91- connman-service.h
92+ connman-service.h \
93+ connman-ipv4.c \
94+ connman-ipv4.h
95
96 libconnman_la_LIBADD = \
97 $(GLIB_LIBS) \
98
99=== added file 'src/libconnman/connman-ipv4.c'
100--- src/libconnman/connman-ipv4.c 1970-01-01 00:00:00 +0000
101+++ src/libconnman/connman-ipv4.c 2011-02-03 11:39:11 +0000
102@@ -0,0 +1,315 @@
103+/*
104+ * indicator-network - user interface for connman
105+ * Copyright 2011 Canonical Ltd.
106+ *
107+ * Authors:
108+ * Kalle Valo <kalle.valo@canonical.com>
109+ *
110+ * This program is free software: you can redistribute it and/or modify it
111+ * under the terms of the GNU General Public License version 3, as published
112+ * by the Free Software Foundation.
113+ *
114+ * This program is distributed in the hope that it will be useful, but
115+ * WITHOUT ANY WARRANTY; without even the implied warranties of
116+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
117+ * PURPOSE. See the GNU General Public License for more details.
118+ *
119+ * You should have received a copy of the GNU General Public License along
120+ * with this program. If not, see <http://www.gnu.org/licenses/>.
121+ */
122+
123+#include "connman-ipv4.h"
124+
125+#include <string.h>
126+
127+G_DEFINE_TYPE(ConnmanIPv4, connman_ipv4, G_TYPE_OBJECT)
128+
129+#define GET_PRIVATE(o) \
130+ (G_TYPE_INSTANCE_GET_PRIVATE((o), CONNMAN_TYPE_IPV4, \
131+ ConnmanIPv4Private))
132+
133+typedef struct _ConnmanIPv4Private ConnmanIPv4Private;
134+
135+struct _ConnmanIPv4Private {
136+ ConnmanIPv4Method method;
137+ gchar *address;
138+ gchar *netmask;
139+ gchar *gateway;
140+};
141+
142+enum
143+{
144+ /* reserved */
145+ PROP_0,
146+
147+ PROP_METHOD,
148+ PROP_ADDRESS,
149+ PROP_NETMASK,
150+ PROP_GATEWAY,
151+};
152+
153+struct ipv4_method_entry
154+{
155+ const gchar *str;
156+ ConnmanIPv4Method method;
157+};
158+
159+static const struct ipv4_method_entry method_map[] = {
160+ { "off", CONNMAN_IPV4_METHOD_OFF },
161+ { "manual", CONNMAN_IPV4_METHOD_MANUAL },
162+ { "fixed", CONNMAN_IPV4_METHOD_FIXED },
163+ { "dhcp", CONNMAN_IPV4_METHOD_DHCP },
164+};
165+
166+static ConnmanIPv4Method str2method(const gchar *state)
167+{
168+ const struct ipv4_method_entry *s;
169+ guint i;
170+
171+ for (i = 0; i < G_N_ELEMENTS(method_map); i++) {
172+ s = &method_map[i];
173+ if (g_strcmp0(s->str, state) == 0)
174+ return s->method;
175+ }
176+
177+ g_warning("unknown ipv4 method: %s", state);
178+
179+ return CONNMAN_IPV4_METHOD_DHCP;
180+}
181+
182+static const gchar *method2str(ConnmanIPv4Method method)
183+{
184+ const struct ipv4_method_entry *s;
185+ guint i;
186+
187+ for (i = 0; i < G_N_ELEMENTS(method_map); i++) {
188+ s = &method_map[i];
189+ if (s->method == method)
190+ return s->str;
191+ }
192+
193+ g_warning("%s(): unknown method %d", __func__, method);
194+
195+ return "dhcp";
196+}
197+
198+ConnmanIPv4Method connman_ipv4_get_method(ConnmanIPv4 *self)
199+{
200+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
201+
202+ g_return_val_if_fail(CONNMAN_IS_IPV4(self), CONNMAN_IPV4_METHOD_OFF);
203+ g_return_val_if_fail(priv != NULL, CONNMAN_IPV4_METHOD_OFF);
204+
205+ return priv->method;
206+}
207+
208+const gchar *connman_ipv4_get_method_as_string(ConnmanIPv4 *self)
209+{
210+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
211+
212+ g_return_val_if_fail(CONNMAN_IS_IPV4(self), CONNMAN_IPV4_METHOD_OFF);
213+ g_return_val_if_fail(priv != NULL, CONNMAN_IPV4_METHOD_OFF);
214+
215+ return method2str(priv->method);
216+}
217+
218+
219+const gchar *connman_ipv4_get_address(ConnmanIPv4 *self)
220+{
221+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
222+
223+ g_return_val_if_fail(CONNMAN_IS_IPV4(self), NULL);
224+ g_return_val_if_fail(priv != NULL, NULL);
225+
226+ return priv->address;
227+}
228+
229+const gchar *connman_ipv4_get_netmask(ConnmanIPv4 *self)
230+{
231+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
232+
233+ g_return_val_if_fail(CONNMAN_IS_IPV4(self), NULL);
234+ g_return_val_if_fail(priv != NULL, NULL);
235+
236+ return priv->netmask;
237+}
238+
239+const gchar *connman_ipv4_get_gateway(ConnmanIPv4 *self)
240+{
241+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
242+
243+ g_return_val_if_fail(CONNMAN_IS_IPV4(self), NULL);
244+ g_return_val_if_fail(priv != NULL, NULL);
245+
246+ return priv->gateway;
247+}
248+
249+static void connman_ipv4_set_property(GObject *object, guint property_id,
250+ const GValue *value, GParamSpec *pspec)
251+{
252+ ConnmanIPv4 *self = CONNMAN_IPV4(object);
253+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
254+
255+ g_return_if_fail(priv != NULL);
256+
257+ switch(property_id) {
258+ case PROP_METHOD:
259+ priv->method = g_value_get_uint(value);
260+ break;
261+ case PROP_ADDRESS:
262+ g_free(priv->address);
263+ priv->address = g_value_dup_string(value);
264+ break;
265+ case PROP_NETMASK:
266+ g_free(priv->netmask);
267+ priv->netmask = g_value_dup_string(value);
268+ break;
269+ case PROP_GATEWAY:
270+ g_free(priv->gateway);
271+ priv->gateway = g_value_dup_string(value);
272+ break;
273+ default:
274+ /* We don't have any other property... */
275+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
276+ break;
277+ }
278+}
279+
280+static void connman_ipv4_get_property(GObject *object, guint property_id,
281+ GValue *value, GParamSpec *pspec)
282+{
283+ ConnmanIPv4 *self = CONNMAN_IPV4(object);
284+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
285+
286+ g_return_if_fail(priv != NULL);
287+
288+ switch(property_id) {
289+ case PROP_METHOD:
290+ g_value_set_uint(value, priv->method);
291+ break;
292+ case PROP_ADDRESS:
293+ g_value_set_string(value, priv->address);
294+ break;
295+ case PROP_NETMASK:
296+ g_value_set_string(value, priv->netmask);
297+ break;
298+ case PROP_GATEWAY:
299+ g_value_set_string(value, priv->gateway);
300+ break;
301+ default:
302+ /* We don't have any other property... */
303+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
304+ break;
305+ }
306+}
307+
308+static void connman_ipv4_dispose(GObject *object)
309+{
310+ G_OBJECT_CLASS(connman_ipv4_parent_class)->dispose(object);
311+}
312+
313+static void connman_ipv4_finalize(GObject *object)
314+{
315+ ConnmanIPv4 *self = CONNMAN_IPV4(object);
316+ ConnmanIPv4Private *priv = GET_PRIVATE(self);
317+
318+ g_free(priv->address);
319+ g_free(priv->netmask);
320+ g_free(priv->gateway);
321+
322+ G_OBJECT_CLASS(connman_ipv4_parent_class)->finalize(object);
323+}
324+
325+static void connman_ipv4_class_init(ConnmanIPv4Class *klass)
326+{
327+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
328+ GParamSpec *pspec;
329+
330+ g_type_class_add_private(klass, sizeof(ConnmanIPv4Private));
331+
332+ gobject_class->dispose = connman_ipv4_dispose;
333+ gobject_class->finalize = connman_ipv4_finalize;
334+ gobject_class->set_property = connman_ipv4_set_property;
335+ gobject_class->get_property = connman_ipv4_get_property;
336+
337+ pspec = g_param_spec_uint("method",
338+ "ConnmanIPv4's method property",
339+ "The ipv4 method",
340+ 0, G_MAXUINT,
341+ CONNMAN_IPV4_METHOD_OFF,
342+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
343+ g_object_class_install_property(gobject_class, PROP_METHOD, pspec);
344+
345+ pspec = g_param_spec_string("address",
346+ "ConnmanIPv4's address",
347+ "IPv4 address",
348+ NULL,
349+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
350+ g_object_class_install_property(gobject_class, PROP_ADDRESS, pspec);
351+
352+ pspec = g_param_spec_string("netmask",
353+ "ConnmanIPv4's netmask",
354+ "IPv4 netmask",
355+ NULL,
356+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
357+ g_object_class_install_property(gobject_class, PROP_NETMASK, pspec);
358+
359+ pspec = g_param_spec_string("gateway",
360+ "ConnmanIPv4's gateway",
361+ "IPv4 gateway",
362+ NULL,
363+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
364+ g_object_class_install_property(gobject_class, PROP_GATEWAY, pspec);
365+}
366+
367+static void connman_ipv4_init(ConnmanIPv4 *self)
368+{
369+}
370+
371+ConnmanIPv4 *connman_ipv4_new(ConnmanIPv4Method method,
372+ const gchar *address,
373+ const gchar *netmask,
374+ const gchar *gateway,
375+ GError **error)
376+{
377+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
378+
379+ return g_object_new(CONNMAN_TYPE_IPV4,
380+ "method", method,
381+ "address", address,
382+ "netmask", netmask,
383+ "gateway", gateway,
384+ NULL);
385+}
386+
387+ConnmanIPv4 *connman_ipv4_new_with_strings(const gchar *method,
388+ const gchar *address,
389+ const gchar *netmask,
390+ const gchar *gateway,
391+ GError **error)
392+{
393+ const struct ipv4_method_entry *s;
394+ gboolean valid = FALSE;
395+ guint i;
396+
397+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
398+
399+ /* check that method is valid and if not, throw an error */
400+ for (i = 0; i < G_N_ELEMENTS(method_map); i++) {
401+ s = &method_map[i];
402+ if (g_strcmp0(s->str, method) == 0) {
403+ valid = TRUE;
404+ break;
405+ }
406+ }
407+
408+ if (valid == FALSE) {
409+ g_set_error(error, CONNMAN_IPV4_ERROR,
410+ CONNMAN_IPV4_ERROR_INVALID_METHOD,
411+ "Invalid ipv4 method: %s", method);
412+ return NULL;
413+ }
414+
415+ return connman_ipv4_new(str2method(method), address, netmask, gateway,
416+ error);
417+}
418
419=== added file 'src/libconnman/connman-ipv4.h'
420--- src/libconnman/connman-ipv4.h 1970-01-01 00:00:00 +0000
421+++ src/libconnman/connman-ipv4.h 2011-02-03 11:39:11 +0000
422@@ -0,0 +1,93 @@
423+/*
424+ * indicator-network - user interface for connman
425+ * Copyright 2011 Canonical Ltd.
426+ *
427+ * Authors:
428+ * Kalle Valo <kalle.valo@canonical.com>
429+ *
430+ * This program is free software: you can redistribute it and/or modify it
431+ * under the terms of the GNU General Public License version 3, as published
432+ * by the Free Software Foundation.
433+ *
434+ * This program is distributed in the hope that it will be useful, but
435+ * WITHOUT ANY WARRANTY; without even the implied warranties of
436+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
437+ * PURPOSE. See the GNU General Public License for more details.
438+ *
439+ * You should have received a copy of the GNU General Public License along
440+ * with this program. If not, see <http://www.gnu.org/licenses/>.
441+ */
442+
443+#ifndef _CONNMAN_IPV4_H_
444+#define _CONNMAN_IPV4_H_
445+
446+#include <glib-object.h>
447+
448+G_BEGIN_DECLS
449+
450+#define CONNMAN_TYPE_IPV4 connman_ipv4_get_type()
451+
452+#define CONNMAN_IPV4(obj) \
453+ (G_TYPE_CHECK_INSTANCE_CAST((obj), CONNMAN_TYPE_IPV4, \
454+ ConnmanIPv4))
455+
456+#define CONNMAN_IPV4_CLASS(klass) \
457+ (G_TYPE_CHECK_CLASS_CAST((klass), CONNMAN_TYPE_IPV4, \
458+ ConnmanIPv4Class))
459+
460+#define CONNMAN_IS_IPV4(obj) \
461+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), CONNMAN_TYPE_IPV4))
462+
463+#define CONNMAN_IS_IPV4_CLASS(klass) \
464+ (G_TYPE_CHECK_CLASS_TYPE((klass), CONNMAN_TYPE_IPV4))
465+
466+#define CONNMAN_IPV4_GET_CLASS(obj) \
467+ (G_TYPE_INSTANCE_GET_CLASS((obj), CONNMAN_TYPE_IPV4, \
468+ ConnmanIPv4Class))
469+
470+typedef struct {
471+ GObject parent;
472+} ConnmanIPv4;
473+
474+typedef struct {
475+ GObjectClass parent_class;
476+} ConnmanIPv4Class;
477+
478+#define CONNMAN_IPV4_ERROR connman_ipv4_error_quark()
479+
480+static inline GQuark connman_ipv4_error_quark(void)
481+{
482+ return g_quark_from_static_string ("connman-ipv4-error-quark");
483+}
484+
485+typedef enum {
486+ CONNMAN_IPV4_ERROR_INVALID_METHOD,
487+ CONNMAN_IPV4_ERROR_INVALID_SETTINGS,
488+} ConnmanIPv4Error;
489+
490+typedef enum {
491+ CONNMAN_IPV4_METHOD_OFF,
492+ CONNMAN_IPV4_METHOD_MANUAL,
493+ CONNMAN_IPV4_METHOD_FIXED,
494+ CONNMAN_IPV4_METHOD_DHCP,
495+} ConnmanIPv4Method;
496+
497+GType connman_ipv4_get_type(void);
498+
499+ConnmanIPv4Method connman_ipv4_get_method(ConnmanIPv4 *self);
500+const gchar *connman_ipv4_get_method_as_string(ConnmanIPv4 *self);
501+const gchar *connman_ipv4_get_address(ConnmanIPv4 *self);
502+const gchar *connman_ipv4_get_netmask(ConnmanIPv4 *self);
503+const gchar *connman_ipv4_get_gateway(ConnmanIPv4 *self);
504+ConnmanIPv4 *connman_ipv4_new(ConnmanIPv4Method method,
505+ const gchar *address,
506+ const gchar *netmask,
507+ const gchar *gateway,
508+ GError **error);
509+ConnmanIPv4 *connman_ipv4_new_with_strings(const gchar *method,
510+ const gchar *address,
511+ const gchar *netmask,
512+ const gchar *gateway,
513+ GError **error);
514+
515+#endif
516
517=== modified file 'src/libconnman/connman-manager.c'
518--- src/libconnman/connman-manager.c 2011-01-31 19:01:47 +0000
519+++ src/libconnman/connman-manager.c 2011-02-03 11:39:11 +0000
520@@ -185,7 +185,7 @@
521 /**
522 * connman_manager_get_services:
523 *
524- * @self:: self
525+ * @self: self
526 *
527 * Returns: (array zero-terminated=1) (array length=false) (element-type Connman.Service) (transfer none): Null terminated list of services,
528 * owned by ConnmanManager. Caller must create a reference if it uses them.
529@@ -242,8 +242,8 @@
530 /**
531 * connman_manager_get_service:
532 *
533- * @self:: self
534- * @path:: path
535+ * @self: self
536+ * @path: path
537 *
538 * Returns: (transfer none): The service or null if not found.
539 */
540@@ -258,6 +258,13 @@
541 return g_hash_table_lookup(priv->services, path);
542 }
543
544+/**
545+ * connman_manager_get_default_service:
546+ *
547+ * @self: self
548+ *
549+ * Returns: (transfer none): The service or null if not found.
550+ */
551 ConnmanService *connman_manager_get_default_service(ConnmanManager *self)
552 {
553 ConnmanManagerPrivate *priv = GET_PRIVATE(self);
554
555=== modified file 'src/libconnman/connman-service.c'
556--- src/libconnman/connman-service.c 2011-02-01 08:36:43 +0000
557+++ src/libconnman/connman-service.c 2011-02-03 11:39:11 +0000
558@@ -63,6 +63,8 @@
559 gchar **nameservers_configuration;
560 gchar **domains;
561 gchar **domains_configuration;
562+ ConnmanIPv4 *ipv4;
563+ ConnmanIPv4 *ipv4_configuration;
564 };
565
566 enum
567@@ -95,8 +97,8 @@
568 PROP_NAMESERVERS_CONFIGURATION, /* rw */
569 PROP_DOMAINS,
570 PROP_DOMAINS_CONFIGURATION, /* rw */
571- /* PROP_IPV4, */
572- /* PROP_IPV4_CONFIGURATION, /\* rw *\/ */
573+ PROP_IPV4,
574+ PROP_IPV4_CONFIGURATION, /* rw */
575 /* PROP_IPV6, */
576 /* PROP_IPV6_CONFIGURATION, /\* rw *\/ */
577 /* PROP_PROXY, */
578@@ -478,7 +480,7 @@
579 /**
580 * connman_service_get_nameservers:
581 *
582- * @self:: self
583+ * @self: self
584 *
585 * Returns: (array zero-terminated=1) (array length=false) (transfer none):
586 * Null terminated list of strings, owned by ConnmanService. Caller must
587@@ -497,7 +499,7 @@
588 /**
589 * connman_service_get_nameservers_configuration:
590 *
591- * @self:: self
592+ * @self: self
593 *
594 * Returns: (array zero-terminated=1) (array length=false) (transfer none):
595 * Null terminated list of strings, owned by ConnmanService. Caller must
596@@ -516,7 +518,7 @@
597 /**
598 * connman_service_set_nameservers_configuration:
599 *
600- * @self:: self
601+ * @self: self
602 * @nameservers: (array zero-terminated=1) (transfer none): Null terminated list of strings, owned by caller.
603 */
604 void connman_service_set_nameservers_configuration(ConnmanService *self,
605@@ -537,7 +539,7 @@
606 /**
607 * connman_service_get_domains:
608 *
609- * @self:: self
610+ * @self: self
611 *
612 * Returns: (array zero-terminated=1) (array length=false) (transfer none): Null terminated list of strings,
613 * owned by ConnmanManager. Caller must copy if it uses them.
614@@ -555,7 +557,7 @@
615 /**
616 * connman_service_get_domains_configuration:
617 *
618- * @self:: self
619+ * @self: self
620 *
621 * Returns: (array zero-terminated=1) (array length=false) (transfer none):
622 * Null terminated list of strings, owned by ConnmanService. Caller must
623@@ -574,7 +576,7 @@
624 /**
625 * connman_service_set_domains_configuration:
626 *
627- * @self:: self
628+ * @self: self
629 * @domains: (array zero-terminated=1) (transfer none): Null terminated list of strings, owned by caller.
630 */
631 void connman_service_set_domains_configuration(ConnmanService *self,
632@@ -592,6 +594,52 @@
633 g_object_set(self, "domains-configuration", domains, NULL);
634 }
635
636+/**
637+ * connman_service_get_ipv4:
638+ *
639+ * @self: self
640+ *
641+ * Returns: (transfer none): Current ipv4 settings. The caller must
642+ * take a reference.
643+ */
644+ConnmanIPv4 *connman_service_get_ipv4(ConnmanService *self)
645+{
646+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
647+
648+ g_return_val_if_fail(CONNMAN_IS_SERVICE(self), NULL);
649+ g_return_val_if_fail(priv != NULL, NULL);
650+
651+ return priv->ipv4;
652+}
653+
654+/**
655+ * connman_service_get_ipv4_configuration:
656+ *
657+ * @self: self
658+ *
659+ * Returns: (transfer none): Current configured ipv4 settings. The caller must
660+ * take a reference.
661+ */
662+ConnmanIPv4 *connman_service_get_ipv4_configuration(ConnmanService *self)
663+{
664+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
665+
666+ g_return_val_if_fail(CONNMAN_IS_SERVICE(self), NULL);
667+ g_return_val_if_fail(priv != NULL, NULL);
668+
669+ return priv->ipv4_configuration;
670+}
671+
672+void connman_service_set_ipv4_configuration(ConnmanService *self,
673+ ConnmanIPv4 *ipv4)
674+{
675+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
676+
677+ g_return_if_fail(CONNMAN_IS_SERVICE(self));
678+ g_return_if_fail(priv != NULL);
679+
680+ g_object_set(self, "ipv4-configuration", ipv4, NULL);
681+}
682
683 const gchar *connman_service_get_path(ConnmanService *self)
684 {
685@@ -994,6 +1042,85 @@
686 g_object_notify(G_OBJECT(self), "domains-configuration");
687 }
688
689+static void ipv4_updated(ConnmanService *self, GVariant *variant)
690+{
691+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
692+ gchar *method = NULL, *address = NULL, *netmask = NULL, *gateway = NULL,
693+ *key;
694+ GError *error = NULL;
695+ GVariantIter iter;
696+ GVariant *value;
697+
698+ g_variant_iter_init(&iter, variant);
699+
700+ while (g_variant_iter_next(&iter, "{sv}", &key, &value)) {
701+ if (g_strcmp0(key, "Method") == 0)
702+ method = g_variant_dup_string(value, NULL);
703+ else if (g_strcmp0(key, "Address") == 0)
704+ address = g_variant_dup_string(value, NULL);
705+ else if (g_strcmp0(key, "Netmask") == 0)
706+ netmask = g_variant_dup_string(value, NULL);
707+ else if (g_strcmp0(key, "Gateway") == 0)
708+ gateway = g_variant_dup_string(value, NULL);
709+ else
710+ g_warning("Unknown ipv4 property: %s", key);
711+
712+ g_free(key);
713+ g_variant_unref(value);
714+ }
715+
716+ priv->ipv4 = connman_ipv4_new_with_strings(method, address, netmask,
717+ gateway, &error);
718+ if (error != NULL) {
719+ g_warning("Received invalid ipv4 settings: %s", error->message);
720+ g_error_free(error);
721+ return;
722+ }
723+
724+ g_object_notify(G_OBJECT(self), "ipv4");
725+}
726+
727+static void ipv4_configuration_updated(ConnmanService *self, GVariant *variant)
728+{
729+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
730+ gchar *method = NULL, *address = NULL, *netmask = NULL, *gateway = NULL,
731+ *key;
732+ GError *error = NULL;
733+ GVariantIter iter;
734+ GVariant *value;
735+
736+ g_variant_iter_init(&iter, variant);
737+
738+ while (g_variant_iter_next(&iter, "{sv}", &key, &value)) {
739+ if (g_strcmp0(key, "Method") == 0)
740+ method = g_variant_dup_string(value, NULL);
741+ else if (g_strcmp0(key, "Address") == 0)
742+ address = g_variant_dup_string(value, NULL);
743+ else if (g_strcmp0(key, "Netmask") == 0)
744+ netmask = g_variant_dup_string(value, NULL);
745+ else if (g_strcmp0(key, "Gateway") == 0)
746+ gateway = g_variant_dup_string(value, NULL);
747+ else
748+ g_warning("Unknown ipv4 property: %s", key);
749+
750+ g_free(key);
751+ g_variant_unref(value);
752+ }
753+
754+ priv->ipv4_configuration = connman_ipv4_new_with_strings(method,
755+ address,
756+ netmask,
757+ gateway,
758+ &error);
759+ if (error != NULL) {
760+ g_warning("Received invalid ipv4 configuration settings: %s",
761+ error->message);
762+ g_error_free(error);
763+ return;
764+ }
765+ g_object_notify(G_OBJECT(self), "ipv4-configuration");
766+}
767+
768 struct property_map
769 {
770 const gchar *property;
771@@ -1023,6 +1150,8 @@
772 { CONNMAN_PROPERTY_NAMESERVERS_CONFIGURATION, nameservers_configuration_updated },
773 { CONNMAN_PROPERTY_DOMAINS, domains_updated },
774 { CONNMAN_PROPERTY_DOMAINS_CONFIGURATION, domains_configuration_updated },
775+ { CONNMAN_PROPERTY_IPV4, ipv4_updated },
776+ { CONNMAN_PROPERTY_IPV4_CONFIGURATION, ipv4_configuration_updated },
777 };
778
779 static void property_updated(ConnmanService *self, const gchar *property,
780@@ -1308,6 +1437,34 @@
781 set_service_property(self, "Domains.Configuration", value);
782 }
783
784+static void update_ipv4_configuration(ConnmanService *self)
785+{
786+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
787+ GVariantBuilder builder;
788+ ConnmanIPv4 *ipv4;
789+ GVariant *value;
790+
791+ if (priv->ipv4_configuration == NULL)
792+ return;
793+
794+ ipv4 = priv->ipv4_configuration;
795+
796+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
797+
798+ g_variant_builder_add(&builder, "{sv}", "Method",
799+ g_variant_new_string(connman_ipv4_get_method_as_string(ipv4)));
800+ g_variant_builder_add(&builder, "{sv}", "Address",
801+ g_variant_new_string(connman_ipv4_get_address(ipv4)));
802+ g_variant_builder_add(&builder, "{sv}", "Netmask",
803+ g_variant_new_string(connman_ipv4_get_netmask(ipv4)));
804+ g_variant_builder_add(&builder, "{sv}", "Gateway",
805+ g_variant_new_string(connman_ipv4_get_gateway(ipv4)));
806+
807+ value = g_variant_new("a{sv}", &builder);
808+
809+ set_service_property(self, "IPv4.Configuration", value);
810+}
811+
812 static void connman_service_set_property(GObject *object,
813 guint property_id,
814 const GValue *value,
815@@ -1403,6 +1560,17 @@
816 priv->domains_configuration = g_strdupv(g_value_get_boxed(value));
817 update_domains_configuration(self);
818 break;
819+ case PROP_IPV4:
820+ if (priv->ipv4 != NULL)
821+ g_object_unref(priv->ipv4);
822+ priv->ipv4 = g_value_dup_object(value);
823+ break;
824+ case PROP_IPV4_CONFIGURATION:
825+ if (priv->ipv4_configuration != NULL)
826+ g_object_unref(priv->ipv4_configuration);
827+ priv->ipv4_configuration = g_value_dup_object(value);
828+ update_ipv4_configuration(self);
829+ break;
830 default:
831 /* We don't have any other property... */
832 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
833@@ -1505,29 +1673,39 @@
834
835 G_OBJECT_CLASS(connman_service_parent_class)->dispose(object);
836
837- if (priv->path != NULL) {
838- g_free(priv->path);
839- priv->path = NULL;
840- }
841-
842- if (priv->error != NULL) {
843- g_free(priv->error);
844- priv->error = NULL;
845- }
846-
847- if (priv->name != NULL) {
848- g_free(priv->name);
849- priv->name = NULL;
850- }
851-
852 if (priv->proxy != NULL) {
853 g_object_unref(priv->proxy);
854 priv->proxy = NULL;
855 }
856+
857+ if (priv->ipv4 != NULL) {
858+ g_object_unref(priv->ipv4);
859+ priv->ipv4 = NULL;
860+ }
861+
862+ if (priv->ipv4_configuration != NULL) {
863+ g_object_unref(priv->ipv4_configuration);
864+ priv->ipv4_configuration = NULL;
865+ }
866 }
867
868 static void connman_service_finalize(GObject *object)
869 {
870+ ConnmanService *self = CONNMAN_SERVICE(object);
871+ ConnmanServicePrivate *priv = GET_PRIVATE(self);
872+
873+ g_free(priv->path);
874+ g_free(priv->error);
875+ g_free(priv->name);
876+ g_free(priv->passphrase);
877+ g_free(priv->apn);
878+ g_free(priv->mcc);
879+ g_free(priv->mnc);
880+ g_strfreev(priv->nameservers);
881+ g_strfreev(priv->nameservers_configuration);
882+ g_strfreev(priv->domains);
883+ g_strfreev(priv->domains_configuration);
884+
885 G_OBJECT_CLASS(connman_service_parent_class)->finalize(object);
886 }
887
888@@ -1723,6 +1901,21 @@
889 G_PARAM_READWRITE);
890 g_object_class_install_property(gobject_class, PROP_DOMAINS_CONFIGURATION,
891 pspec);
892+
893+ pspec = g_param_spec_object("ipv4",
894+ "ConnmanService's ipv4 property",
895+ "ConnmanIPv4 object",
896+ CONNMAN_TYPE_IPV4,
897+ G_PARAM_READABLE);
898+ g_object_class_install_property(gobject_class, PROP_IPV4, pspec);
899+
900+ pspec = g_param_spec_object("ipv4-configuration",
901+ "ConnmanService's ipv4-configuration property",
902+ "ConnmanIPv4 object",
903+ CONNMAN_TYPE_IPV4,
904+ G_PARAM_READWRITE);
905+ g_object_class_install_property(gobject_class, PROP_IPV4_CONFIGURATION,
906+ pspec);
907 }
908
909 static void connman_service_init(ConnmanService *self)
910
911=== modified file 'src/libconnman/connman-service.h'
912--- src/libconnman/connman-service.h 2011-01-31 17:40:06 +0000
913+++ src/libconnman/connman-service.h 2011-02-03 11:39:11 +0000
914@@ -21,6 +21,8 @@
915 #ifndef _CONNMAN_SERVICE_H_
916 #define _CONNMAN_SERVICE_H_
917
918+#include "connman-ipv4.h"
919+
920 #include <glib-object.h>
921 #include <gio/gio.h>
922
923@@ -119,6 +121,10 @@
924 gchar **connman_service_get_domains_configuration(ConnmanService *self);
925 void connman_service_set_domains_configuration(ConnmanService *self,
926 gchar **domains);
927+ConnmanIPv4 *connman_service_get_ipv4(ConnmanService *self);
928+ConnmanIPv4 *connman_service_get_ipv4_configuration(ConnmanService *self);
929+void connman_service_set_ipv4_configuration(ConnmanService *self,
930+ ConnmanIPv4 *ipv4);
931
932 /* methods */
933 void connman_service_connect(ConnmanService *self,
934
935=== modified file 'src/libconnman/connman.h'
936--- src/libconnman/connman.h 2011-01-28 11:02:51 +0000
937+++ src/libconnman/connman.h 2011-02-03 11:39:11 +0000
938@@ -72,6 +72,8 @@
939 #define CONNMAN_PROPERTY_NAMESERVERS_CONFIGURATION "Nameservers.Configuration"
940 #define CONNMAN_PROPERTY_DOMAINS "Domains"
941 #define CONNMAN_PROPERTY_DOMAINS_CONFIGURATION "Domains.Configuration"
942+#define CONNMAN_PROPERTY_IPV4 "IPv4"
943+#define CONNMAN_PROPERTY_IPV4_CONFIGURATION "IPv4.Configuration"
944
945 #define CONNMAN_STATE_ONLINE "online"
946 #define CONNMAN_STATE_CONNECTING "connecting"
947
948=== modified file 'src/libconnman/generate_vapi'
949--- src/libconnman/generate_vapi 2011-01-13 18:38:16 +0000
950+++ src/libconnman/generate_vapi 2011-02-03 11:39:11 +0000
951@@ -3,6 +3,8 @@
952 # output to Test-1.0.vapi because for now we need to maintain
953 # Connman-1.0.vapi manually :(
954
955+set -x
956+
957 g-ir-scanner \
958 --add-include-path=. \
959 --namespace=Connman \
960@@ -12,8 +14,11 @@
961 --include=Gio-2.0 \
962 --library=libconnman.la \
963 --output Test-1.0.gir \
964+ --warn-all \
965 connman.h connman-manager.c connman-manager.h \
966- connman-service.c connman-service.h libconnman.la
967+ connman-service.c connman-service.h \
968+ connman-ipv4.c connman-ipv4.h \
969+ libconnman.la
970
971 vapigen \
972 --library=Test-1.0 \
973
974=== modified file 'tests/connman-mock/connman-mock'
975--- tests/connman-mock/connman-mock 2010-12-10 12:15:31 +0000
976+++ tests/connman-mock/connman-mock 2011-02-03 11:39:11 +0000
977@@ -90,14 +90,18 @@
978 self.properties["Nameservers.Configuration"] = [ "127.0.0.1" ]
979 self.properties["Domains"] = [ "example.com" ]
980 self.properties["Domains.Configuration"] = [ "example.com" ]
981- self.properties["IPv4"] = {
982+ self.properties["IPv4"] = dbus.Dictionary({
983 "Method" : "dhcp",
984 "Address" : "192.168.1.2",
985 "Netmask" : "255.255.255.0",
986- "Gateway" : "192.168.1.1" }
987- self.properties["IPv4.Configuration"] = { "Method" : "dhcp" }
988- self.properties["IPv6"] = { "Method" : "off" }
989- self.properties["IPv6.Configuration"] = { "Method" : "off" }
990+ "Gateway" : "192.168.1.1" },
991+ signature='sv')
992+ self.properties["IPv4.Configuration"] = dbus.Dictionary(
993+ { "Method" : "dhcp" }, signature='sv')
994+ self.properties["IPv6"] = dbus.Dictionary({ "Method" : "off" },
995+ signature='sv')
996+ self.properties["IPv6.Configuration"] = dbus.Dictionary(
997+ { "Method" : "off" }, signature='sv')
998 self.properties["Proxy"] = { "Method" : "direct" }
999 self.properties["Provider"] = dbus.Dictionary(signature='sv')
1000 self.properties["Ethernet"] = {
1001
1002=== modified file 'tests/libconnman-vala/libconnman-vala.vala'
1003--- tests/libconnman-vala/libconnman-vala.vala 2011-02-01 08:40:45 +0000
1004+++ tests/libconnman-vala/libconnman-vala.vala 2011-02-03 11:39:11 +0000
1005@@ -99,6 +99,17 @@
1006 stdout.printf(" MNC = %s\n", service.mnc);
1007 }
1008
1009+ var ipv4 = service.ipv4;
1010+ stdout.printf(" IPv4 = { Method=%s Address=%s Netmask=%s Gateway=%s\n }\n",
1011+ ipv4.get_method_as_string(), ipv4.address, ipv4.netmask,
1012+ ipv4.gateway);
1013+
1014+ ipv4 = service.ipv4_configuration;
1015+ stdout.printf(" IPv4.Configuration = " +
1016+ "{ Method=%s Address=%s Netmask=%s Gateway=%s\n }\n",
1017+ ipv4.get_method_as_string(), ipv4.address, ipv4.netmask,
1018+ ipv4.gateway);
1019+
1020 stdout.printf(" Nameservers = %s\n",
1021 string.joinv(" ", service.get_nameservers()));
1022 stdout.printf(" Nameservers.Configuration = %s\n",
1023@@ -162,6 +173,45 @@
1024 service.set_domains_configuration(domains);
1025 }
1026
1027+static void edit_ipv4(Service service, string[] args) {
1028+ string method, address, netmask, gateway;
1029+
1030+ if (args.length < 1) {
1031+ stdout.printf("Invalid number of arguments: %d\n", args.length);
1032+ return;
1033+ }
1034+
1035+ method = args[0];
1036+
1037+ switch (method) {
1038+ case "dhcp":
1039+ case "off":
1040+ address = "";
1041+ netmask = "";
1042+ gateway = "";
1043+ break;
1044+ case "manual":
1045+ if (args.length < 4) {
1046+ stdout.printf("Invalid number of ipv4 arguments: %d\n", args.length); return;
1047+ }
1048+ address = args[1];
1049+ netmask = args[2];
1050+ gateway = args[3];
1051+ break;
1052+ default:
1053+ stdout.printf("Unknown ipv4 method: %s\n", method);
1054+ return;
1055+ }
1056+
1057+ try {
1058+ var ipv4 = new IPv4.with_strings(method, address, netmask, gateway);
1059+ service.set_ipv4_configuration(ipv4);
1060+ } catch(GLib.Error e) {
1061+ stdout.printf("Failed to set ipv4 address: %s", e.message);
1062+ return;
1063+ }
1064+}
1065+
1066 static void edit(string[] args) {
1067
1068 if (args.length < 2) {
1069@@ -177,9 +227,9 @@
1070 edit_args += args[2];
1071 }
1072 else if (args.length > 3) {
1073- edit_args = args[2: args.length - 1];
1074+ edit_args = args[2: args.length];
1075 }
1076-
1077+
1078 var service = manager.get_service(path);
1079
1080 if (service == null) {
1081@@ -197,6 +247,9 @@
1082 case "domains":
1083 edit_domains(service, edit_args);
1084 break;
1085+ case "ipv4":
1086+ edit_ipv4(service, edit_args);
1087+ break;
1088 }
1089 }
1090

Subscribers

People subscribed via source and target branches