Debian Codegraph @

lib/service.c

raw symbols SCIP
1 /*
2 *
3 * Connection Manager UI
4 *
5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include <gdbus/gdbus.h>
23
24 #include <connman-private.h>
25 #include <cui-dbus.h>
26
27 #define CONNMAN_SERVICE_INTERFACE CONNMAN_DBUS_NAME ".Service"
28
29 #define PROPERTY(n) Service_updatable_properties[n]
30
31 enum connman_service_property {
32 SERVICE_STATE = 0,
33 SERVICE_ERROR = 1,
34 SERVICE_STRENGTH = 2,
35 SERVICE_FAVORITE = 3,
36 SERVICE_AUTOCONNECT = 4,
37 SERVICE_ROAMING = 5,
38 SERVICE_NAMESERVERS = 6,
39 SERVICE_NAMESERVERS_CONFIGURATION = 7,
40 SERVICE_TIMESERVERS = 8,
41 SERVICE_TIMESERVERS_CONFIGURATION = 9,
42 SERVICE_DOMAINS = 10,
43 SERVICE_DOMAINS_CONFIGURATION = 11,
44 SERVICE_IPv4 = 12,
45 SERVICE_IPv4_CONFIGURATION = 13,
46 SERVICE_IPv6 = 14,
47 SERVICE_IPv6_CONFIGURATION = 15,
48 SERVICE_PROXY = 16,
49 SERVICE_PROXY_CONFIGURATION = 17,
50 SERVICE_PROVIDER = 18,
51 SERVICE_ETHERNET = 19,
52 SERVICE_MAX = 20,
53 };
54
55 static const char *Service_updatable_properties[] = {
56 "State",
57 "Error",
58 "Strength",
59 "Favorite",
60 "AutoConnect",
61 "Roaming",
62 "Nameservers",
63 "Nameservers.Configuration",
64 "Timeservers",
65 "Timeservers.Configuration",
66 "Domains",
67 "Domains.Configuration",
68 "IPv4",
69 "IPv4.Configuration",
70 "IPv6",
71 "IPv6.Configuration",
72 "Proxy",
73 "Proxy.Configuration",
74 "Provider",
75 "Ethernet",
76 };
77
78 struct connman_service {
79 char *path;
80
81 enum connman_state state;
82 char *error;
83 char *name;
84 char *type;
85 char *security;
86
87 uint8_t strength;
88
89 gboolean favorite;
90 gboolean immutable;
91 gboolean autoconnect;
92 gboolean roaming;
93
94 char *nameservers;
95 char *nameservers_conf;
96
97 char *timeservers;
98 char *timeservers_conf;
99
100 char *domains;
101 char *domains_conf;
102
103 struct connman_ipv4 *ipv4;
104 struct connman_ipv4 *ipv4_conf;
105
106 struct connman_ipv6 *ipv6;
107 struct connman_ipv6 *ipv6_conf;
108
109 struct connman_proxy *proxy;
110 struct connman_proxy *proxy_conf;
111
112 struct connman_provider *provider;
113 struct connman_ethernet *ethernet;
114
115 int update_index;
116
117 guint property_changed_wid;
118 guint to_update[SERVICE_MAX];
119 connman_property_changed_cb_f property_changed_cb;
120 void *property_changed_user_data;
121
122 DBusPendingCall *call_modify[SERVICE_MAX];
123 guint to_error[SERVICE_MAX];
124 connman_property_set_cb_f property_set_error_cb;
125 void *property_set_error_user_data;
126 };
127
128 struct connman_service_interface {
129 DBusConnection *dbus_cnx;
130
131 gboolean refreshed;
132
133 GHashTable *services;
134 GSList *ordered_services;
135
136 connman_path_changed_cb_f removed_cb;
137
138 connman_refresh_cb_f refresh_services_cb;
139 connman_scan_cb_f scan_services_cb;
140 guint to_refresh;
141 void *refresh_user_data;
142
143 struct connman_service *selected_service;
144 };
145
146 static struct connman_service_interface *service_if = NULL;
147
148 static void ipv4_free(gpointer data)
149 {
150 struct connman_ipv4 *ipv4 = data;
151
152 if (ipv4 == NULL)
153 return;
154
155 g_free(ipv4->method);
156 g_free(ipv4->address);
157 g_free(ipv4->netmask);
158 g_free(ipv4->gateway);
159
160 g_free(ipv4);
161 }
162
163 static void ipv6_free(gpointer data)
164 {
165 struct connman_ipv6 *ipv6 = data;
166
167 if (ipv6 == NULL)
168 return;
169
170 g_free(ipv6->method);
171 g_free(ipv6->address);
172 g_free(ipv6->gateway);
173 g_free(ipv6->privacy);
174
175 g_free(ipv6);
176 }
177
178 static void proxy_free(gpointer data)
179 {
180 struct connman_proxy *proxy = data;
181
182 if (proxy == NULL)
183 return;
184
185 g_free(proxy->method);
186 g_free(proxy->url);
187 g_free(proxy->servers);
188 g_free(proxy->excludes);
189
190 g_free(proxy);
191 }
192
193 static void provider_free(gpointer data)
194 {
195 struct connman_provider *provider = data;
196
197 if (provider == NULL)
198 return;
199
200 g_free(provider->host);
201 g_free(provider->domain);
202 g_free(provider->name);
203 g_free(provider->type);
204
205 g_free(provider);
206 }
207
208 static void ethernet_free(gpointer data)
209 {
210 struct connman_ethernet *ethernet = data;
211
212 if (ethernet == NULL)
213 return;
214
215 g_free(ethernet->method);
216 g_free(ethernet->interface);
217 g_free(ethernet->address);
218 g_free(ethernet->duplex);
219
220 g_free(ethernet);
221 }
222
223 static void service_free(gpointer data)
224 {
225 struct connman_service *service = data;
226 int i;
227
228 if (service_if != NULL && service_if->selected_service == service)
229 return;
230
231 if (service->property_changed_wid != 0)
232 g_dbus_remove_watch(service_if->dbus_cnx,
233 service->property_changed_wid);
234
235 for (i = 0; i < SERVICE_MAX; i++) {
236 if (service->to_update[i] != 0)
237 g_source_remove(service->to_update[i]);
238
239 if (service->call_modify[i] != 0) {
240 dbus_pending_call_cancel(service->call_modify[i]);
241 dbus_pending_call_unref(service->call_modify[i]);
242 }
243
244 if (service->to_error[i] != 0)
245 g_source_remove(service->to_error[i]);
246 }
247
248 g_free(service->path);
249 g_free(service->error);
250 g_free(service->name);
251 g_free(service->type);
252 g_free(service->security);
253 g_free(service->nameservers);
254 g_free(service->nameservers_conf);
255 g_free(service->timeservers);
256 g_free(service->timeservers_conf);
257 g_free(service->domains);
258 g_free(service->domains_conf);
259
260 ipv4_free(service->ipv4);
261 ipv4_free(service->ipv4_conf);
262
263 ipv6_free(service->ipv6);
264 ipv6_free(service->ipv6_conf);
265
266 proxy_free(service->proxy);
267 proxy_free(service->proxy_conf);
268
269 provider_free(service->provider);
270
271 ethernet_free(service->ethernet);
272
273 g_free(service);
274 }
275
276 static struct connman_service *get_service(const char *path)
277 {
278 struct connman_service *service;
279
280 if (path == NULL || service_if == NULL)
281 return NULL;
282
283 service = g_hash_table_lookup(service_if->services, path);
284 if (service == NULL && service_if->selected_service != NULL) {
285 if (g_strcmp0(path, service_if->selected_service->path) == 0)
286 service = service_if->selected_service;
287 }
288
289 return service;
290 }
291
292 static void destroy_property(gpointer user_data)
293 {
294 struct property_change *property = user_data;
295 struct connman_service *service;
296
297 if (property == NULL)
298 return;
299
300 service = get_service(property->path);
301 if (service != NULL) {
302 if (property->error != 0)
303 service->to_error[property->index] = 0;
304 else
305 service->to_update[property->index] = 0;
306 }
307
308 g_free(property);
309 }
310
311 static gboolean property_changed_or_error(gpointer user_data)
312 {
313 struct property_change *property = user_data;
314 struct connman_service *service;
315
316 service = get_service(property->path);
317 if (service == NULL)
318 return FALSE;
319
320 if (property->error != 0) {
321 if (service->property_set_error_cb == NULL)
322 return FALSE;
323
324 service->property_set_error_cb(property->path,
325 property->name, property->error,
326 service->property_set_error_user_data);
327 return FALSE;
328 }
329
330 if (service->property_changed_cb != NULL) {
331 service->property_changed_cb(property->path,
332 property->name, service->property_changed_user_data);
333 }
334
335 return FALSE;
336 }
337
338 static void property_update(struct connman_service *service, int index)
339 {
340 struct property_change *property;
341
342 if (service->property_changed_cb == NULL)
343 return;
344
345 property = g_try_malloc0(sizeof(struct property_change));
346 if (property == NULL)
347 return;
348
349 property->index = index;
350 property->name = PROPERTY(index);
351 property->path = service->path;
352
353 if (service->to_update[index] != 0)
354 g_source_remove(service->to_update[index]);
355
356 service->to_update[index] = g_timeout_add_full(G_PRIORITY_DEFAULT,
357 0, property_changed_or_error,
358 property, destroy_property);
359 }
360
361 static struct connman_ipv4 *parse_ipv4(DBusMessageIter *arg,
362 struct connman_ipv4 *ipv4)
363 {
364 DBusMessageIter dict;
365 gboolean set = FALSE;
366 char *value;
367
368 if (ipv4 == NULL) {
369 ipv4 = g_try_malloc0(sizeof(struct connman_ipv4));
370 if (ipv4 == NULL)
371 return NULL;
372 }
373
374 dbus_message_iter_recurse(arg, &dict);
375
376 if (cui_dbus_get_dict_entry_basic(&dict, "Method",
377 DBUS_TYPE_STRING, &value) == 0) {
378 g_free(ipv4->method);
379 ipv4->method = g_strdup(value);
380 set = TRUE;
381 }
382
383 if (cui_dbus_get_dict_entry_basic(&dict, "Address",
384 DBUS_TYPE_STRING, &value) == 0) {
385 g_free(ipv4->address);
386 ipv4->address = g_strdup(value);
387 set = TRUE;
388 }
389
390 if (cui_dbus_get_dict_entry_basic(&dict, "Netmask",
391 DBUS_TYPE_STRING, &value) == 0) {
392 g_free(ipv4->netmask);
393 ipv4->netmask = g_strdup(value);
394 set = TRUE;
395 }
396
397 if (cui_dbus_get_dict_entry_basic(&dict, "Gateway",
398 DBUS_TYPE_STRING, &value) == 0) {
399 g_free(ipv4->gateway);
400 ipv4->gateway = g_strdup(value);
401 set = TRUE;
402 }
403
404 if (set == TRUE)
405 return ipv4;
406
407 g_free(ipv4);
408 return NULL;
409 }
410
411 static struct connman_ipv6 *parse_ipv6(DBusMessageIter *arg,
412 struct connman_ipv6 *ipv6)
413 {
414 uint16_t uint16_value;
415 DBusMessageIter dict;
416 gboolean set = FALSE;
417 char *value;
418
419 if (ipv6 == NULL) {
420 ipv6 = g_try_malloc0(sizeof(struct connman_ipv6));
421 if (ipv6 == NULL)
422 return NULL;
423 }
424
425 dbus_message_iter_recurse(arg, &dict);
426
427 if (cui_dbus_get_dict_entry_basic(&dict, "Method",
428 DBUS_TYPE_STRING, &value) == 0) {
429 g_free(ipv6->method);
430 ipv6->method = g_strdup(value);
431 set = TRUE;
432 }
433
434 if (cui_dbus_get_dict_entry_basic(&dict, "Address",
435 DBUS_TYPE_STRING, &value) == 0) {
436 g_free(ipv6->address);
437 ipv6->address = g_strdup(value);
438 set = TRUE;
439 }
440
441 if (cui_dbus_get_dict_entry_basic(&dict, "Prefix",
442 DBUS_TYPE_UINT16, &uint16_value) == 0) {
443 ipv6->prefix = uint16_value;
444 set = TRUE;
445 }
446
447 if (cui_dbus_get_dict_entry_basic(&dict, "Gateway",
448 DBUS_TYPE_STRING, &value) == 0) {
449 g_free(ipv6->gateway);
450 ipv6->gateway = g_strdup(value);
451 set = TRUE;
452 }
453
454 if (cui_dbus_get_dict_entry_basic(&dict, "Privacy",
455 DBUS_TYPE_STRING, &value) == 0) {
456 g_free(ipv6->privacy);
457 ipv6->privacy = g_strdup(value);
458 set = TRUE;
459 }
460
461 if (set == TRUE)
462 return ipv6;
463
464 g_free(ipv6);
465 return NULL;
466 }
467
468 static struct connman_proxy *parse_proxy(DBusMessageIter *arg,
469 struct connman_proxy *proxy)
470 {
471 DBusMessageIter dict;
472 gboolean set = FALSE;
473 char *value, **array;
474 int length;
475
476 if (proxy == NULL) {
477 proxy = g_try_malloc0(sizeof(struct connman_proxy));
478 if (proxy == NULL)
479 return NULL;
480 }
481
482 dbus_message_iter_recurse(arg, &dict);
483
484 if (cui_dbus_get_dict_entry_basic(&dict, "Method",
485 DBUS_TYPE_STRING, &value) == 0) {
486 g_free(proxy->method);
487 proxy->method = g_strdup(value);
488 set = TRUE;
489 }
490
491 if (cui_dbus_get_dict_entry_basic(&dict, "URL",
492 DBUS_TYPE_STRING, &value) == 0) {
493 g_free(proxy->url);
494 proxy->url = g_strdup(value);
495 set = TRUE;
496 }
497
498 if (cui_dbus_get_dict_entry_array(&dict, "Servers",
499 DBUS_TYPE_STRING, &length, &array) == 0) {
500 g_free(proxy->servers);
501 if (array != NULL) {
502 proxy->servers = g_strjoinv(";", array);
503 g_free(array);
504 } else
505 proxy->servers = NULL;
506
507 set = TRUE;
508 }
509
510 if (cui_dbus_get_dict_entry_array(&dict, "Excludes",
511 DBUS_TYPE_STRING, &length, &array) == 0) {
512 g_free(proxy->excludes);
513 if (array != NULL) {
514 proxy->excludes = g_strjoinv(";", array);
515 g_free(array);
516 } else
517 proxy->excludes = NULL;
518
519 set = TRUE;
520 }
521
522 if (set == TRUE)
523 return proxy;
524
525 g_free(proxy);
526 return NULL;
527 }
528
529 static struct connman_provider *parse_provider(DBusMessageIter *arg,
530 struct connman_provider *provider)
531 {
532 DBusMessageIter dict;
533 gboolean set = FALSE;
534 char *value;
535
536 if (provider == NULL) {
537 provider = g_try_malloc0(sizeof(struct connman_provider));
538 if (provider == NULL)
539 return NULL;
540 }
541
542 dbus_message_iter_recurse(arg, &dict);
543
544 if (cui_dbus_get_dict_entry_basic(&dict, "Host",
545 DBUS_TYPE_STRING, &value) == 0) {
546 g_free(provider->host);
547 provider->host = g_strdup(value);
548 set = TRUE;
549 }
550
551 if (cui_dbus_get_dict_entry_basic(&dict, "Domain",
552 DBUS_TYPE_STRING, &value) == 0) {
553 g_free(provider->domain);
554 provider->domain = g_strdup(value);
555 set = TRUE;
556 }
557
558 if (cui_dbus_get_dict_entry_basic(&dict, "Name",
559 DBUS_TYPE_STRING, &value) == 0) {
560 g_free(provider->name);
561 provider->name = g_strdup(value);
562 set = TRUE;
563 }
564
565 if (cui_dbus_get_dict_entry_basic(&dict, "Type",
566 DBUS_TYPE_STRING, &value) == 0) {
567 g_free(provider->type);
568 provider->type = g_strdup(value);
569 set = TRUE;
570 }
571
572 if (set == TRUE)
573 return provider;
574
575 g_free(provider);
576 return NULL;
577 }
578
579 static struct connman_ethernet *parse_ethernet(DBusMessageIter *arg,
580 struct connman_ethernet *ethernet)
581 {
582 uint16_t uint16_value;
583 DBusMessageIter dict;
584 char *value;
585
586 if (ethernet == NULL) {
587 ethernet = g_try_malloc0(sizeof(struct connman_ethernet));
588 if (ethernet == NULL)
589 return NULL;
590 };
591
592 dbus_message_iter_recurse(arg, &dict);
593
594 if (cui_dbus_get_dict_entry_basic(&dict, "Method",
595 DBUS_TYPE_STRING, &value) == 0) {
596 g_free(ethernet->method);
597 ethernet->method = g_strdup(value);
598 }
599
600 if (cui_dbus_get_dict_entry_basic(&dict, "Interface",
601 DBUS_TYPE_STRING, &value) == 0) {
602 g_free(ethernet->interface);
603 ethernet->interface = g_strdup(value);
604 }
605
606 if (cui_dbus_get_dict_entry_basic(&dict, "Address",
607 DBUS_TYPE_STRING, &value) == 0) {
608 g_free(ethernet->address);
609 ethernet->address = g_strdup(value);
610 }
611
612 if (cui_dbus_get_dict_entry_basic(&dict, "MTU",
613 DBUS_TYPE_UINT16, &uint16_value) == 0)
614 ethernet->mtu = uint16_value;
615
616
617 if (cui_dbus_get_dict_entry_basic(&dict, "Speed",
618 DBUS_TYPE_UINT16, &uint16_value) == 0)
619 ethernet->speed = uint16_value;
620
621 if (cui_dbus_get_dict_entry_basic(&dict, "Duplex",
622 DBUS_TYPE_STRING, &value) == 0) {
623 g_free(ethernet->duplex);
624 ethernet->duplex = g_strdup(value);
625 }
626
627 return ethernet;
628 }
629
630 static bool update_service_property(DBusMessageIter *arg, void *user_data)
631 {
632 struct connman_service *service = user_data;
633 const char *name, *value;
634 gboolean boolean_value;
635 char **array;
636 int length;
637
638 if (cui_dbus_get_basic(arg, DBUS_TYPE_STRING, &name) != 0)
639 return FALSE;
640
641 dbus_message_iter_next(arg);
642
643 if (g_strcmp0(name, "Name") == 0) {
644 cui_dbus_get_basic_variant(arg, DBUS_TYPE_STRING, &value);
645 service->name = g_strdup(value);
646 } else if (g_strcmp0(name, "Type") == 0) {
647 cui_dbus_get_basic_variant(arg, DBUS_TYPE_STRING, &value);
648 service->type = g_strdup(value);
649 } else if (g_strcmp0(name, "Security") == 0) {
650 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
651
652 g_free(service->security);
653 if (array != NULL) {
654 service->security = g_strjoinv(";", array);
655 g_free(array);
656 } else
657 service->security = NULL;
658 } else if (g_strcmp0(name, "Immutable") == 0) {
659 cui_dbus_get_basic_variant(arg,
660 DBUS_TYPE_BOOLEAN, &boolean_value);
661 service->immutable = boolean_value;
662 } else if (g_strcmp0(name, PROPERTY(SERVICE_STATE)) == 0) {
663 cui_dbus_get_basic_variant(arg, DBUS_TYPE_STRING, &value);
664
665 service->state = string2enum_state(value);
666
667 service->update_index = SERVICE_STATE;
668 } else if (g_strcmp0(name, PROPERTY(SERVICE_ERROR)) == 0) {
669 cui_dbus_get_basic_variant(arg, DBUS_TYPE_STRING, &value);
670
671 g_free(service->error);
672 service->error = g_strdup(value);
673
674 service->update_index = SERVICE_ERROR;
675 } else if (g_strcmp0(name, PROPERTY(SERVICE_STRENGTH)) == 0) {
676 uint8_t uint8_value;
677
678 cui_dbus_get_basic_variant(arg, DBUS_TYPE_BYTE, &uint8_value);
679 service->strength = uint8_value;
680
681 service->update_index = SERVICE_STRENGTH;
682 } else if (g_strcmp0(name, PROPERTY(SERVICE_FAVORITE)) == 0) {
683 cui_dbus_get_basic_variant(arg,
684 DBUS_TYPE_BOOLEAN, &boolean_value);
685 service->favorite = boolean_value;
686
687 service->update_index = SERVICE_FAVORITE;
688 } else if (g_strcmp0(name, PROPERTY(SERVICE_AUTOCONNECT)) == 0) {
689 cui_dbus_get_basic_variant(arg,
690 DBUS_TYPE_BOOLEAN, &boolean_value);
691 service->autoconnect = boolean_value;
692
693 service->update_index = SERVICE_AUTOCONNECT;
694 } else if (g_strcmp0(name, PROPERTY(SERVICE_ROAMING)) == 0) {
695 cui_dbus_get_basic_variant(arg,
696 DBUS_TYPE_BOOLEAN, &boolean_value);
697 service->roaming = boolean_value;
698
699 service->update_index = SERVICE_ROAMING;
700 } else if (g_strcmp0(name, PROPERTY(SERVICE_NAMESERVERS)) == 0) {
701 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
702
703 g_free(service->nameservers);
704 if (array != NULL) {
705 service->nameservers = g_strjoinv(";", array);
706 g_free(array);
707 } else
708 service->nameservers = NULL;
709
710 service->update_index = SERVICE_NAMESERVERS;
711 } else if (g_strcmp0(name,
712 PROPERTY(SERVICE_NAMESERVERS_CONFIGURATION)) == 0) {
713 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
714
715 g_free(service->nameservers_conf);
716 if (array != NULL) {
717 service->nameservers_conf = g_strjoinv(";", array);
718 g_free(array);
719 } else
720 service->nameservers_conf = NULL;
721
722 service->update_index = SERVICE_NAMESERVERS_CONFIGURATION;
723 } else if (g_strcmp0(name, PROPERTY(SERVICE_DOMAINS)) == 0) {
724 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
725
726 g_free(service->domains);
727 if (array != NULL) {
728 service->domains = g_strjoinv(";", array);
729 g_free(array);
730 } else
731 service->domains = NULL;
732
733 service->update_index = SERVICE_DOMAINS;
734 } else if (g_strcmp0(name,
735 PROPERTY(SERVICE_DOMAINS_CONFIGURATION)) == 0) {
736 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
737
738 g_free(service->domains_conf);
739 if (array != NULL) {
740 service->domains_conf = g_strjoinv(";", array);
741 g_free(array);
742 } else
743 service->domains_conf = NULL;
744
745 service->update_index = SERVICE_DOMAINS_CONFIGURATION;
746 } else if (g_strcmp0(name, PROPERTY(SERVICE_TIMESERVERS)) == 0) {
747 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
748
749 g_free(service->timeservers);
750 if (array != NULL) {
751 service->timeservers = g_strjoinv(";", array);
752 g_free(array);
753 } else
754 service->timeservers = NULL;
755
756 service->update_index = SERVICE_TIMESERVERS;
757 } else if (g_strcmp0(name,
758 PROPERTY(SERVICE_TIMESERVERS_CONFIGURATION)) == 0) {
759 cui_dbus_get_array(arg, DBUS_TYPE_STRING, &length, &array);
760
761 g_free(service->timeservers_conf);
762 if (array != NULL) {
763 service->timeservers_conf = g_strjoinv(";", array);
764 g_free(array);
765 } else
766 service->timeservers_conf = NULL;
767
768 service->update_index = SERVICE_TIMESERVERS_CONFIGURATION;
769 } else if (g_strcmp0(name, PROPERTY(SERVICE_IPv4)) == 0) {
770 service->ipv4 = parse_ipv4(arg, service->ipv4);
771 service->update_index = SERVICE_IPv4;
772 } else if (g_strcmp0(name,
773 PROPERTY(SERVICE_IPv4_CONFIGURATION)) == 0) {
774 service->ipv4_conf = parse_ipv4(arg, service->ipv4_conf);
775 service->update_index = SERVICE_IPv4_CONFIGURATION;
776 } else if (g_strcmp0(name, PROPERTY(SERVICE_IPv6)) == 0) {
777 service->ipv6 = parse_ipv6(arg, service->ipv6);
778 service->update_index = SERVICE_IPv6;
779 } else if (g_strcmp0(name,
780 PROPERTY(SERVICE_IPv6_CONFIGURATION)) == 0) {
781 service->ipv6_conf = parse_ipv6(arg, service->ipv6_conf);
782 service->update_index = SERVICE_IPv6_CONFIGURATION;
783 } else if (g_strcmp0(name, PROPERTY(SERVICE_PROXY)) == 0) {
784 service->proxy = parse_proxy(arg, service->proxy);
785 service->update_index = SERVICE_PROXY;
786 } else if (g_strcmp0(name,
787 PROPERTY(SERVICE_PROXY_CONFIGURATION)) == 0) {
788 service->proxy_conf = parse_proxy(arg, service->proxy_conf);
789 service->update_index = SERVICE_PROXY_CONFIGURATION;
790 } else if (g_strcmp0(name, PROPERTY(SERVICE_PROVIDER)) == 0) {
791 service->provider = parse_provider(arg, service->provider);
792 service->update_index = SERVICE_PROVIDER;
793 } else if (g_strcmp0(name, PROPERTY(SERVICE_ETHERNET)) == 0) {
794 service->ethernet = parse_ethernet(arg, service->ethernet);
795 service->update_index = SERVICE_ETHERNET;
796 }
797
798 return FALSE;
799 }
800
801 static gboolean property_changed_signal_cb(DBusConnection *dbus_cnx,
802 DBusMessage *message, void *user_data)
803 {
804 struct connman_service *service = user_data;
805 DBusMessageIter arg;
806
807 if (message == NULL)
808 return TRUE;
809
810 if (dbus_message_iter_init(message, &arg) == FALSE)
811 return TRUE;
812
813 service->update_index = SERVICE_MAX;
814
815 update_service_property(&arg, service);
816
817 if (service->update_index < SERVICE_MAX)
818 property_update(service, service->update_index);
819
820 return TRUE;
821 }
822
823 static void update_or_create_service(const char *obj_path,
824 DBusMessageIter *dict)
825 {
826 struct connman_service *service;
827
828 if (service_if == NULL)
829 return;
830
831 service = get_service(obj_path);
832 if (service == NULL) {
833 service = g_try_malloc0(sizeof(struct connman_service));
834 if (service == NULL)
835 return;
836
837 service->path = g_strdup(obj_path);
838
839 g_hash_table_insert(service_if->services,
840 service->path, service);
841
842 service->property_changed_wid = g_dbus_add_signal_watch(
843 service_if->dbus_cnx,
844 CONNMAN_DBUS_NAME,
845 service->path,
846 CONNMAN_SERVICE_INTERFACE,
847 "PropertyChanged",
848 property_changed_signal_cb,
849 service, NULL);
850 }
851
852 service_if->ordered_services = g_slist_append(
853 service_if->ordered_services, service->path);
854
855 cui_dbus_foreach_dict_entry(dict, update_service_property, service);
856 }
857
858 gboolean refresh_cb(gpointer data)
859 {
860 if (service_if == NULL || service_if->refresh_services_cb == NULL)
861 return FALSE;
862
863 service_if->refresh_services_cb(service_if->refresh_user_data);
864
865 return FALSE;
866 }
867
868 static void call_refresh_callback(void)
869 {
870 if (service_if == NULL || service_if->refresh_services_cb == NULL)
871 return;
872
873 if (service_if->to_refresh != 0)
874 g_source_remove(service_if->to_refresh);
875
876 service_if->to_refresh = g_timeout_add_full(G_PRIORITY_DEFAULT,
877 0, refresh_cb, NULL, NULL);
878 }
879
880 static void service_changed_signal_cb(DBusMessageIter *iter)
881 {
882 DBusMessageIter array, strt;
883 char *obj_path;
884 int arg_type;
885
886 if (service_if == NULL)
887 return;
888
889 g_slist_free(service_if->ordered_services);
890 service_if->ordered_services = NULL;
891
892 dbus_message_iter_recurse(iter, &array);
893
894 arg_type = dbus_message_iter_get_arg_type(&array);
895 while (arg_type != DBUS_TYPE_INVALID) {
896 dbus_message_iter_recurse(&array, &strt);
897
898 cui_dbus_get_basic(&strt, DBUS_TYPE_OBJECT_PATH, &obj_path);
899
900 dbus_message_iter_next(&strt);
901 update_or_create_service(obj_path, &strt);
902
903 dbus_message_iter_next(&array);
904 arg_type = dbus_message_iter_get_arg_type(&array);
905 }
906
907 dbus_message_iter_next(iter);
908 dbus_message_iter_recurse(iter, &array);
909
910 arg_type = dbus_message_iter_get_arg_type(&array);
911 while (arg_type != DBUS_TYPE_INVALID) {
912 struct connman_service *service;
913
914 cui_dbus_get_basic(&array, DBUS_TYPE_OBJECT_PATH, &obj_path);
915
916 service = get_service(obj_path);
917 if (service != NULL) {
918 g_hash_table_remove(service_if->services, obj_path);
919 if (service_if->removed_cb != NULL)
920 service_if->removed_cb(obj_path);
921 }
922
923 dbus_message_iter_next(&array);
924 arg_type = dbus_message_iter_get_arg_type(&array);
925 }
926
927 if (service_if->refreshed == TRUE)
928 call_refresh_callback();
929 }
930
931 static void get_services_cb(DBusMessageIter *iter)
932 {
933 DBusMessageIter array;
934 DBusMessageIter strt;
935 char *obj_path;
936 int arg_type;
937
938 if (iter == NULL || service_if == NULL)
939 return;
940
941 g_slist_free(service_if->ordered_services);
942 service_if->ordered_services = NULL;
943
944 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
945 return;
946
947 dbus_message_iter_recurse(iter, &array);
948
949 arg_type = dbus_message_iter_get_arg_type(&array);
950 while (arg_type != DBUS_TYPE_INVALID) {
951 dbus_message_iter_recurse(&array, &strt);
952
953 cui_dbus_get_basic(&strt, DBUS_TYPE_OBJECT_PATH, &obj_path);
954
955 dbus_message_iter_next(&strt);
956 update_or_create_service(obj_path, &strt);
957
958 dbus_message_iter_next(&array);
959 arg_type = dbus_message_iter_get_arg_type(&array);
960 }
961
962 if (service_if->refreshed == FALSE) {
963 service_if->refreshed = TRUE;
964 __connman_manager_get_services(get_services_cb);
965 } else
966 call_refresh_callback();
967 }
968
969 static void scan_services_cb(void *user_data)
970 {
971 if (service_if == NULL)
972 return;
973
974 if (service_if->scan_services_cb != NULL)
975 service_if->scan_services_cb(service_if->refresh_user_data);
976 }
977
978 static int call_empty_method(const char *path, const char *method)
979 {
980 struct connman_service *service;
981 DBusMessage *message;
982
983 service = get_service(path);
984 if (service == NULL)
985 return -EINVAL;
986
987 message = dbus_message_new_method_call(CONNMAN_DBUS_NAME,
988 service->path,
989 CONNMAN_SERVICE_INTERFACE,
990 method);
991 if (message == NULL)
992 return -ENOMEM;
993
994 if (g_dbus_send_message(service_if->dbus_cnx, message) == FALSE) {
995 dbus_message_unref(message);
996 return -EINVAL;
997 }
998
999 return 0;
1000 }
1001
1002 static void set_property_cb(DBusPendingCall *pending, void *user_data)
1003 {
1004 struct property_setting *set = user_data;
1005 struct connman_service *service;
1006 struct property_change *property;
1007 DBusMessage *reply;
1008 DBusError error;
1009
1010 if (dbus_pending_call_get_completed(pending) == FALSE)
1011 return;
1012
1013 if (set == NULL)
1014 return;
1015
1016 service = set->data;
1017
1018 service->call_modify[set->index] = NULL;
1019
1020 if (service->property_set_error_cb == NULL)
1021 return;
1022
1023 property = g_try_malloc0(sizeof(struct property_change));
1024 if (property == NULL)
1025 return;
1026
1027 reply = dbus_pending_call_steal_reply(pending);
1028 if (reply == NULL)
1029 return;
1030
1031 dbus_error_init(&error);
1032 if (dbus_set_error_from_message(&error, reply) == FALSE)
1033 goto done;
1034
1035 printf("SetProperty Error: %s\n", error.message);
1036 dbus_error_free(&error);
1037
1038 if (service->property_set_error_cb == NULL)
1039 goto done;
1040
1041 property = g_try_malloc0(sizeof(struct property_change));
1042 if (property == NULL)
1043 goto done;
1044
1045 property->path = service->path;
1046 property->name = PROPERTY(set->index);
1047 property->error = -1;
1048
1049 if (service->to_error[set->index] != 0)
1050 g_source_remove(service->to_error[set->index]);
1051
1052 service->to_error[set->index] = g_timeout_add_full(
1053 G_PRIORITY_DEFAULT,
1054 0, property_changed_or_error,
1055 property, destroy_property);
1056
1057 done:
1058 dbus_message_unref(reply);
1059 }
1060
1061 static void append_ipv4_config(DBusMessageIter *dict, void *data)
1062 {
1063 const struct connman_ipv4 *ipv4 = data;
1064
1065 cui_dbus_append_dict_entry_basic(dict, "Method",
1066 DBUS_TYPE_STRING, (void *) &ipv4->method);
1067 cui_dbus_append_dict_entry_basic(dict, "Address",
1068 DBUS_TYPE_STRING, (void *) &ipv4->address);
1069 cui_dbus_append_dict_entry_basic(dict, "Netmask",
1070 DBUS_TYPE_STRING, (void *) &ipv4->netmask);
1071 cui_dbus_append_dict_entry_basic(dict, "Gateway",
1072 DBUS_TYPE_STRING, (void *) &ipv4->gateway);
1073 }
1074
1075 static void append_ipv6_config(DBusMessageIter *dict, void *data)
1076 {
1077 const struct connman_ipv6 *ipv6 = data;
1078
1079 cui_dbus_append_dict_entry_basic(dict, "Method",
1080 DBUS_TYPE_STRING, (void *) &ipv6->method);
1081 cui_dbus_append_dict_entry_basic(dict, "Address",
1082 DBUS_TYPE_STRING, (void *) &ipv6->address);
1083 cui_dbus_append_dict_entry_basic(dict, "PrefixLength",
1084 DBUS_TYPE_BYTE, (void *) &ipv6->prefix);
1085 cui_dbus_append_dict_entry_basic(dict, "Gateway",
1086 DBUS_TYPE_STRING, (void *) &ipv6->gateway);
1087 cui_dbus_append_dict_entry_basic(dict, "Privacy",
1088 DBUS_TYPE_STRING, (void *) &ipv6->privacy);
1089 }
1090
1091 static void append_string_list(DBusMessageIter *iter, void *data)
1092 {
1093 const char **string_list = data;
1094
1095 for (; *string_list != NULL; string_list++)
1096 cui_dbus_append_basic(iter, NULL,
1097 DBUS_TYPE_STRING, string_list);
1098 }
1099
1100 static void append_proxy_config(DBusMessageIter *dict, void *data)
1101 {
1102 const struct connman_proxy *proxy = data;
1103 char **config_list;
1104
1105 cui_dbus_append_dict_entry_basic(dict, "Method",
1106 DBUS_TYPE_STRING, (void *) &proxy->method);
1107 cui_dbus_append_dict_entry_basic(dict, "URL",
1108 DBUS_TYPE_STRING, (void *) &proxy->url);
1109
1110 config_list = g_strsplit(proxy->servers, ";", 0);
1111 cui_dbus_append_dict_entry_array(dict, "Servers",
1112 DBUS_TYPE_STRING, append_string_list,
1113 (void *)config_list);
1114 g_strfreev(config_list);
1115
1116 config_list = g_strsplit(proxy->excludes, ";", 0);
1117 cui_dbus_append_dict_entry_array(dict, "Excludes",
1118 DBUS_TYPE_STRING, append_string_list,
1119 (void *)config_list);
1120 g_strfreev(config_list);
1121 }
1122
1123 static int set_service_property(struct connman_service *service,
1124 enum connman_service_property property,
1125 int dbus_type, void *data)
1126 {
1127 struct property_setting *set = NULL;
1128 const char *property_name;
1129 DBusMessage *message;
1130 DBusMessageIter arg;
1131
1132 if (connman == NULL)
1133 return -EINVAL;
1134
1135 if (service->call_modify[property] != NULL)
1136 return -EINVAL;
1137
1138 message = dbus_message_new_method_call(CONNMAN_DBUS_NAME,
1139 service->path,
1140 CONNMAN_SERVICE_INTERFACE,
1141 "SetProperty");
1142 if (message == NULL)
1143 return -ENOMEM;
1144
1145 set = g_try_malloc0(sizeof(struct property_setting));
1146 if (set == NULL)
1147 goto error;
1148
1149 set->data = service;
1150 set->index = property;
1151
1152 property_name = PROPERTY(property);
1153
1154 dbus_message_iter_init_append(message, &arg);
1155
1156 switch (property) {
1157 case SERVICE_IPv4_CONFIGURATION:
1158 cui_dbus_append_dict(&arg, property_name,
1159 append_ipv4_config, data);
1160 break;
1161 case SERVICE_IPv6_CONFIGURATION:
1162 cui_dbus_append_dict(&arg, property_name,
1163 append_ipv6_config, data);
1164 break;
1165 case SERVICE_PROXY_CONFIGURATION:
1166 cui_dbus_append_dict(&arg, property_name,
1167 append_proxy_config, data);
1168 break;
1169 case SERVICE_NAMESERVERS_CONFIGURATION:
1170 case SERVICE_DOMAINS_CONFIGURATION:
1171 case SERVICE_TIMESERVERS_CONFIGURATION:
1172 cui_dbus_append_array(&arg, property_name,
1173 DBUS_TYPE_STRING, append_string_list, data);
1174 break;
1175 default:
1176 cui_dbus_append_basic(&arg, property_name, dbus_type, data);
1177 break;
1178 }
1179
1180 if (dbus_connection_send_with_reply(service_if->dbus_cnx, message,
1181 &service->call_modify[property],
1182 DBUS_TIMEOUT_USE_DEFAULT) == FALSE)
1183 goto error;
1184
1185 if (dbus_pending_call_set_notify(service->call_modify[property],
1186 set_property_cb, set, g_free) == FALSE)
1187 goto error;
1188
1189 return 0;
1190
1191 error:
1192 dbus_message_unref(message);
1193
1194 if (set == NULL)
1195 return -ENOMEM;
1196
1197 g_free(set);
1198
1199 return -EINVAL;
1200 }
1201
1202 int connman_service_init(void)
1203 {
1204 if (connman == NULL)
1205 return -EINVAL;
1206
1207 if (service_if != NULL)
1208 return 0;
1209
1210 service_if = g_try_malloc0(sizeof(struct connman_service_interface));
1211 if (service_if == NULL)
1212 return -ENOMEM;
1213
1214 service_if->services = g_hash_table_new_full(g_str_hash, g_str_equal,
1215 NULL, service_free);
1216 if (service_if->services == NULL) {
1217 g_free(service_if);
1218
1219 return -ENOMEM;
1220 };
1221
1222 service_if->dbus_cnx = dbus_connection_ref(connman->dbus_cnx);
1223
1224 return 0;
1225 }
1226
1227 void connman_service_finalize(void)
1228 {
1229 if (service_if == NULL)
1230 return;
1231
1232 __connman_manager_register_service_signal(NULL);
1233
1234 dbus_connection_unref(service_if->dbus_cnx);
1235
1236 connman_service_deselect();
1237
1238 g_slist_free(service_if->ordered_services);
1239 g_hash_table_destroy(service_if->services);
1240
1241 g_free(service_if);
1242
1243 service_if = NULL;
1244 }
1245
1246 int connman_service_refresh_services_list(connman_refresh_cb_f refresh_cb,
1247 connman_scan_cb_f scan_cb, void *user_data)
1248 {
1249 GList *techs;
1250 GList *list;
1251 char *path;
1252
1253 if (service_if == NULL)
1254 return -EINVAL;
1255
1256 service_if->refreshed = FALSE;
1257
1258 techs = connman_technology_get_technologies();
1259 if (techs == NULL)
1260 return -EINVAL;
1261
1262 for (list = techs; list != NULL; list = list->next) {
1263 const char *type;
1264 path = list->data;
1265
1266 type = connman_technology_get_type(path);
1267
1268 if (g_strcmp0(type, "wifi") == 0)
1269 break;
1270
1271 path = NULL;
1272 };
1273
1274 g_list_free(techs);
1275
1276 service_if->refresh_services_cb = refresh_cb;
1277 service_if->scan_services_cb = scan_cb;
1278 service_if->refresh_user_data = user_data;
1279
1280 if (path == NULL || connman_technology_is_enabled(path) == FALSE) {
1281 __connman_manager_get_services(get_services_cb);
1282
1283 if (service_if->scan_services_cb != NULL)
1284 service_if->scan_services_cb(
1285 service_if->refresh_user_data);
1286 } else {
1287 __connman_manager_register_service_signal(
1288 service_changed_signal_cb);
1289 connman_technology_scan(path, scan_services_cb, NULL);
1290
1291 __connman_manager_get_services(get_services_cb);
1292 }
1293
1294 return 0;
1295 }
1296
1297 GSList *connman_service_get_services(void)
1298 {
1299 if (service_if == NULL || service_if->ordered_services == NULL)
1300 return NULL;
1301
1302 return g_slist_copy(service_if->ordered_services);
1303 }
1304
1305 void connman_service_free_services_list(void)
1306 {
1307 if (service_if == NULL)
1308 return;
1309
1310 __connman_manager_register_service_signal(NULL);
1311
1312 g_slist_free(service_if->ordered_services);
1313 service_if->ordered_services = NULL;
1314
1315 g_hash_table_remove_all(service_if->services);
1316 }
1317
1318 void connman_service_set_property_changed_callback(const char *path,
1319 connman_property_changed_cb_f property_changed_cb,
1320 void *user_data)
1321 {
1322 struct connman_service *service;
1323
1324 service = get_service(path);
1325 if (service == NULL)
1326 return;
1327
1328 service->property_changed_cb = property_changed_cb;
1329 service->property_changed_user_data = user_data;
1330 }
1331
1332 void connman_service_set_property_error_callback(const char *path,
1333 connman_property_set_cb_f property_set_cb,
1334 void *user_data)
1335 {
1336 struct connman_service *service;
1337
1338 service = get_service(path);
1339 if (service == NULL)
1340 return;
1341
1342 service->property_set_error_cb = property_set_cb;
1343 service->property_set_error_user_data = user_data;
1344 }
1345
1346 void connman_service_set_removed_callback(
1347 connman_path_changed_cb_f removed_cb)
1348 {
1349 if (service_if != NULL)
1350 service_if->removed_cb = removed_cb;
1351 }
1352
1353 const char *connman_service_get_name(const char *path)
1354 {
1355 struct connman_service *service;
1356
1357 service = get_service(path);
1358 if (service == NULL)
1359 return NULL;
1360
1361 return service->name;
1362 }
1363
1364 const char *connman_service_get_type(const char *path)
1365 {
1366 struct connman_service *service;
1367
1368 service = get_service(path);
1369 if (service == NULL)
1370 return NULL;
1371
1372 return service->type;
1373 }
1374
1375 enum connman_state connman_service_get_state(const char *path)
1376 {
1377 struct connman_service *service;
1378
1379 service = get_service(path);
1380 if (service == NULL)
1381 return CONNMAN_STATE_OFFLINE;
1382
1383 return service->state;
1384 }
1385
1386 const char *connman_service_get_error(const char *path)
1387 {
1388 struct connman_service *service;
1389
1390 service = get_service(path);
1391 if (service == NULL)
1392 return NULL;
1393
1394 return service->error;
1395 }
1396
1397 const char *connman_service_get_security(const char *path)
1398 {
1399 struct connman_service *service;
1400
1401 service = get_service(path);
1402 if (service == NULL)
1403 return NULL;
1404
1405 return service->security;
1406 }
1407
1408 uint8_t connman_service_get_strength(const char *path)
1409 {
1410 struct connman_service *service;
1411
1412 service = get_service(path);
1413 if (service == NULL)
1414 return 0;
1415
1416 return service->strength;
1417 }
1418
1419 gboolean connman_service_is_favorite(const char *path)
1420 {
1421 struct connman_service *service;
1422
1423 service = get_service(path);
1424 if (service == NULL)
1425 return FALSE;
1426
1427 return service->favorite;
1428 }
1429
1430 gboolean connman_service_is_immutable(const char *path)
1431 {
1432 struct connman_service *service;
1433
1434 service = get_service(path);
1435 if (service == NULL)
1436 return FALSE;
1437
1438 return service->immutable;
1439 }
1440
1441 gboolean connman_service_is_autoconnect(const char *path)
1442 {
1443 struct connman_service *service;
1444
1445 service = get_service(path);
1446 if (service == NULL)
1447 return FALSE;
1448
1449 return service->autoconnect;
1450 }
1451
1452 gboolean connman_service_is_roaming(const char *path)
1453 {
1454 struct connman_service *service;
1455
1456 service = get_service(path);
1457 if (service == NULL)
1458 return FALSE;
1459
1460 return service->roaming;
1461 }
1462
1463 const char *connman_service_get_nameservers(const char *path)
1464 {
1465 struct connman_service *service;
1466
1467 service = get_service(path);
1468 if (service == NULL)
1469 return NULL;
1470
1471 return service->nameservers;
1472 }
1473
1474 const char *connman_service_get_nameservers_config(const char *path)
1475 {
1476 struct connman_service *service;
1477
1478 service = get_service(path);
1479 if (service == NULL)
1480 return NULL;
1481
1482 return service->nameservers_conf;
1483 }
1484
1485 const char *connman_service_get_domains(const char *path)
1486 {
1487 struct connman_service *service;
1488
1489 service = get_service(path);
1490 if (service == NULL)
1491 return NULL;
1492
1493 return service->domains;
1494 }
1495
1496 const char *connman_service_get_domains_config(const char *path)
1497 {
1498 struct connman_service *service;
1499
1500 service = get_service(path);
1501 if (service == NULL)
1502 return NULL;
1503
1504 return service->domains_conf;
1505 }
1506
1507 const char *connman_service_get_timeservers(const char *path)
1508 {
1509 struct connman_service *service;
1510
1511 service = get_service(path);
1512 if (service == NULL)
1513 return NULL;
1514
1515 return service->timeservers;
1516 }
1517
1518 const char *connman_service_get_timeservers_config(const char *path)
1519 {
1520 struct connman_service *service;
1521
1522 service = get_service(path);
1523 if (service == NULL)
1524 return NULL;
1525
1526 return service->timeservers_conf;
1527 }
1528
1529 const struct connman_ipv4 *connman_service_get_ipv4(const char *path)
1530 {
1531 struct connman_service *service;
1532
1533 service = get_service(path);
1534 if (service == NULL)
1535 return NULL;
1536
1537 return service->ipv4;
1538 }
1539
1540 const struct connman_ipv4 *connman_service_get_ipv4_config(const char *path)
1541 {
1542 struct connman_service *service;
1543
1544 service = get_service(path);
1545 if (service == NULL)
1546 return NULL;
1547
1548 return service->ipv4_conf;
1549 }
1550
1551 const struct connman_ipv6 *connman_service_get_ipv6(const char *path)
1552 {
1553 struct connman_service *service;
1554
1555 service = get_service(path);
1556 if (service == NULL)
1557 return NULL;
1558
1559 return service->ipv6;
1560 }
1561
1562 const struct connman_ipv6 *connman_service_get_ipv6_config(const char *path)
1563 {
1564 struct connman_service *service;
1565
1566 service = get_service(path);
1567 if (service == NULL)
1568 return NULL;
1569
1570 return service->ipv6_conf;
1571 }
1572
1573 const struct connman_proxy *connman_service_get_proxy(const char *path)
1574 {
1575 struct connman_service *service;
1576
1577 service = get_service(path);
1578 if (service == NULL)
1579 return NULL;
1580
1581 return service->proxy;
1582 }
1583
1584 const struct connman_proxy *connman_service_get_proxy_config(const char *path)
1585 {
1586 struct connman_service *service;
1587
1588 service = get_service(path);
1589 if (service == NULL)
1590 return NULL;
1591
1592 return service->proxy_conf;
1593 }
1594
1595 const struct connman_provider *connman_service_get_provider(const char *path)
1596 {
1597 struct connman_service *service;
1598
1599 service = get_service(path);
1600 if (service == NULL)
1601 return NULL;
1602
1603 return service->provider;
1604 }
1605
1606 const struct connman_ethernet *connman_service_get_ethernet(const char *path)
1607 {
1608 struct connman_service *service;
1609
1610 service = get_service(path);
1611 if (service == NULL)
1612 return NULL;
1613
1614 return service->ethernet;
1615 }
1616
1617 gboolean connman_service_is_connected(const char *path)
1618 {
1619 struct connman_service *service;
1620
1621 service = get_service(path);
1622 if (service == NULL)
1623 return FALSE;
1624
1625 if (service->state == CONNMAN_STATE_READY ||
1626 service->state == CONNMAN_STATE_ONLINE)
1627 return TRUE;
1628
1629 return FALSE;
1630 }
1631
1632 int connman_service_select(const char *path)
1633 {
1634 struct connman_service *service;
1635
1636 service = get_service(path);
1637 if (service == NULL)
1638 return -EINVAL;
1639
1640 service_if->selected_service = service;
1641
1642 return 0;
1643 }
1644
1645 void connman_service_deselect(void)
1646 {
1647 struct connman_service *service, *service_in_ht;
1648
1649 if (service_if == NULL || service_if->selected_service == NULL)
1650 return;
1651
1652 service = service_if->selected_service;
1653 service_if->selected_service = NULL;
1654
1655 service_in_ht = get_service(service->path);
1656 if (service_in_ht == NULL)
1657 service_free(service);
1658 }
1659
1660 int connman_service_connect(const char *path)
1661 {
1662 return call_empty_method(path, "Connect");
1663 }
1664
1665 int connman_service_disconnect(const char *path)
1666 {
1667 return call_empty_method(path, "Disconnect");
1668 }
1669
1670 int connman_service_remove(const char *path)
1671 {
1672 return call_empty_method(path, "Remove");
1673 }
1674
1675 int connman_service_set_autoconnectable(const char *path, gboolean enable)
1676 {
1677 struct connman_service *service;
1678
1679 service = get_service(path);
1680 if (service == NULL)
1681 return -EINVAL;
1682
1683 return set_service_property(service, SERVICE_AUTOCONNECT,
1684 DBUS_TYPE_BOOLEAN, &enable);
1685 }
1686
1687 int connman_service_set_ipv4_config(const char *path,
1688 const struct connman_ipv4 *ipv4_config)
1689 {
1690 struct connman_service *service;
1691
1692 if (ipv4_config == NULL)
1693 return -EINVAL;
1694
1695 service = get_service(path);
1696 if (service == NULL)
1697 return -EINVAL;
1698
1699 if (service->ipv4_conf != NULL) {
1700 struct connman_ipv4 *orig = service->ipv4_conf;
1701
1702 if (g_strcmp0(orig->method, ipv4_config->method) != 0 ||
1703 g_strcmp0(orig->address,
1704 ipv4_config->address) != 0 ||
1705 g_strcmp0(orig->netmask,
1706 ipv4_config->netmask) != 0 ||
1707 g_strcmp0(orig->gateway,
1708 ipv4_config->gateway) != 0)
1709 goto set;
1710 else
1711 return 0;
1712 }
1713
1714 set:
1715 return set_service_property(service,
1716 SERVICE_IPv4_CONFIGURATION, 0, (void *)ipv4_config);
1717 }
1718
1719 int connman_service_set_ipv6_config(const char *path,
1720 const struct connman_ipv6 *ipv6_config)
1721 {
1722 struct connman_service *service;
1723
1724 if (ipv6_config == NULL)
1725 return -EINVAL;
1726
1727 service = get_service(path);
1728 if (service == NULL)
1729 return -EINVAL;
1730
1731 if (service->ipv6_conf != NULL) {
1732 struct connman_ipv6 *orig = service->ipv6_conf;
1733
1734 if (g_strcmp0(orig->method, ipv6_config->method) != 0 ||
1735 g_strcmp0(orig->address,
1736 ipv6_config->address) != 0 ||
1737 g_strcmp0(orig->gateway,
1738 ipv6_config->gateway) != 0 ||
1739 g_strcmp0(orig->privacy,
1740 ipv6_config->privacy) != 0 ||
1741 orig->prefix != ipv6_config->prefix)
1742 goto set;
1743 else
1744 return 0;
1745 }
1746
1747 set:
1748 return set_service_property(service,
1749 SERVICE_IPv6_CONFIGURATION, 0, (void *)ipv6_config);
1750 }
1751
1752 int connman_service_set_proxy_config(const char *path,
1753 const struct connman_proxy *proxy_config)
1754 {
1755 struct connman_service *service;
1756
1757 if (proxy_config == NULL)
1758 return -EINVAL;
1759
1760 service = get_service(path);
1761 if (service == NULL)
1762 return -EINVAL;
1763
1764 if (service->proxy_conf != NULL) {
1765 struct connman_proxy *orig = service->proxy_conf;
1766
1767 if (g_strcmp0(orig->method, proxy_config->method) != 0 ||
1768 g_strcmp0(orig->url,
1769 proxy_config->url) != 0 ||
1770 g_strcmp0(orig->servers,
1771 proxy_config->servers) != 0 ||
1772 g_strcmp0(orig->excludes,
1773 proxy_config->excludes) != 0)
1774 goto set;
1775 else
1776 return 0;
1777 }
1778
1779 set:
1780 return set_service_property(service,
1781 SERVICE_PROXY_CONFIGURATION, 0, (void *)proxy_config);
1782 }
1783
1784 int connman_service_set_nameservers_config(const char *path,
1785 const char *nameservers_config)
1786 {
1787 struct connman_service *service;
1788 char **config_list;
1789 int ret;
1790
1791 service = get_service(path);
1792 if (service == NULL)
1793 return -EINVAL;
1794
1795 if (g_strcmp0(service->nameservers_conf, nameservers_config) == 0)
1796 return 0;
1797
1798 config_list = g_strsplit(nameservers_config, ";", 0);
1799 if (config_list == NULL)
1800 return -ENOMEM;
1801
1802 ret = set_service_property(service,
1803 SERVICE_NAMESERVERS_CONFIGURATION,
1804 DBUS_TYPE_STRING, (void *)config_list);
1805 g_strfreev(config_list);
1806
1807 return ret;
1808 }
1809
1810 int connman_service_set_domains_config(const char *path,
1811 const char *domains_config)
1812 {
1813 struct connman_service *service;
1814 char **config_list;
1815 int ret;
1816
1817 service = get_service(path);
1818 if (service == NULL)
1819 return -EINVAL;
1820
1821 if (g_strcmp0(service->domains_conf, domains_config) == 0)
1822 return 0;
1823
1824 config_list = g_strsplit(domains_config, ";", 0);
1825 if (config_list == NULL)
1826 return -ENOMEM;
1827
1828 ret = set_service_property(service,
1829 SERVICE_DOMAINS_CONFIGURATION,
1830 DBUS_TYPE_STRING, (void *)config_list);
1831 g_strfreev(config_list);
1832
1833 return ret;
1834 }
1835
1836 int connman_service_set_timeservers_config(const char *path,
1837 const char *timeservers_config)
1838 {
1839 struct connman_service *service;
1840 char **config_list;
1841 int ret;
1842
1843 service = get_service(path);
1844 if (service == NULL)
1845 return -EINVAL;
1846
1847 if (g_strcmp0(service->timeservers_conf, timeservers_config) == 0)
1848 return 0;
1849
1850 config_list = g_strsplit(timeservers_config, ";", 0);
1851 if (config_list == NULL)
1852 return -ENOMEM;
1853
1854 ret = set_service_property(service,
1855 SERVICE_TIMESERVERS_CONFIGURATION,
1856 DBUS_TYPE_STRING, (void *)config_list);
1857 g_strfreev(config_list);
1858
1859 return ret;
1860 }