Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: src/ipconfig.c

Issue 6659006: flimflam: add support for multiple profiles (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/flimflam.git@master
Patch Set: more ers comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/device.c ('k') | src/main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * 2 *
3 * Connection Manager 3 * Connection Manager
4 * 4 *
5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 * 10 *
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 ipconfig->element.type = etype; 869 ipconfig->element.type = etype;
870 ipconfig->element.name = g_strdup((gchar *) name); /* XXX __DECONST */ 870 ipconfig->element.name = g_strdup((gchar *) name); /* XXX __DECONST */
871 ipconfig->element.destruct = ipconfig_destruct; 871 ipconfig->element.destruct = ipconfig_destruct;
872 ipconfig->element.index = index; 872 ipconfig->element.index = index;
873 873
874 ipconfig->tag = tag; 874 ipconfig->tag = tag;
875 ipconfig->driver = ipconfig_driver_lookup(type); 875 ipconfig->driver = ipconfig_driver_lookup(type);
876 876
877 ipconfig_list = g_list_append(ipconfig_list, ipconfig); 877 ipconfig_list = g_list_append(ipconfig_list, ipconfig);
878 878
879 » __connman_storage_save_ipconfig(ipconfig); 879 » __connman_profile_save_ipconfig(ipconfig);
880 880
881 return ipconfig; 881 return ipconfig;
882 } 882 }
883 883
884 struct connman_ipconfig *connman_ipconfig_find(void * tag, 884 struct connman_ipconfig *connman_ipconfig_find(void * tag,
885 enum connman_ipconfig_type type) 885 enum connman_ipconfig_type type)
886 { 886 {
887 enum connman_element_type etype = ipconfig_type_to_element_type(type); 887 enum connman_element_type etype = ipconfig_type_to_element_type(type);
888 GList *list; 888 GList *list;
889 889
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 * @ipconfig: ipconfig instance 987 * @ipconfig: ipconfig instance
988 * @parent: parent element 988 * @parent: parent element
989 * 989 *
990 * Register the ipconfig instance in the element hierarchy as a child of parent. 990 * Register the ipconfig instance in the element hierarchy as a child of parent.
991 */ 991 */
992 int connman_ipconfig_register(struct connman_ipconfig *ipconfig, 992 int connman_ipconfig_register(struct connman_ipconfig *ipconfig,
993 struct connman_element *parent) 993 struct connman_element *parent)
994 { 994 {
995 _DBG_IPCONFIG("ipconfig %p parent %p", ipconfig, parent); 995 _DBG_IPCONFIG("ipconfig %p parent %p", ipconfig, parent);
996 996
997 » __connman_storage_load_ipconfig(ipconfig); 997 » __connman_profile_load_ipconfig(ipconfig);
998 998
999 return connman_element_register(&ipconfig->element, parent); 999 return connman_element_register(&ipconfig->element, parent);
1000 } 1000 }
1001 1001
1002 /** 1002 /**
1003 * connman_ipconfig_unregister: 1003 * connman_ipconfig_unregister:
1004 * @ipconfig: ipconfig instance 1004 * @ipconfig: ipconfig instance
1005 * 1005 *
1006 * Remove the ipconfig instance from the element hierarchy. 1006 * Remove the ipconfig instance from the element hierarchy.
1007 */ 1007 */
1008 void connman_ipconfig_unregister(struct connman_ipconfig *ipconfig) 1008 void connman_ipconfig_unregister(struct connman_ipconfig *ipconfig)
1009 { 1009 {
1010 _DBG_IPCONFIG("ipconfig %p", ipconfig); 1010 _DBG_IPCONFIG("ipconfig %p", ipconfig);
1011 1011
1012 » __connman_storage_save_ipconfig(ipconfig); 1012 » __connman_profile_save_ipconfig(ipconfig);
1013 1013
1014 connman_element_unregister(&ipconfig->element); 1014 connman_element_unregister(&ipconfig->element);
1015 } 1015 }
1016 1016
1017 struct connman_device *connman_ipconfig_get_device(struct connman_ipconfig *ipc onfig) 1017 struct connman_device *connman_ipconfig_get_device(struct connman_ipconfig *ipc onfig)
1018 { 1018 {
1019 struct connman_element *parent; 1019 struct connman_element *parent;
1020 1020
1021 parent = ipconfig->element.parent; 1021 parent = ipconfig->element.parent;
1022 CONNMAN_ASSERT(parent->type == CONNMAN_ELEMENT_TYPE_DEVICE); 1022 CONNMAN_ASSERT(parent->type == CONNMAN_ELEMENT_TYPE_DEVICE);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 { 1448 {
1449 connman_info("setdomains(%s)", str); 1449 connman_info("setdomains(%s)", str);
1450 1450
1451 g_strfreev(ipaddr->search_domains); 1451 g_strfreev(ipaddr->search_domains);
1452 /* list of domains is a ,-separated list */ 1452 /* list of domains is a ,-separated list */
1453 ipaddr->search_domains = g_strsplit(str, ",", 0); 1453 ipaddr->search_domains = g_strsplit(str, ",", 0);
1454 ipaddr->mask |= CONNMAN_IPCONFIG_SEARCH; 1454 ipaddr->mask |= CONNMAN_IPCONFIG_SEARCH;
1455 ipaddr->smask |= CONNMAN_IPCONFIG_SEARCH; 1455 ipaddr->smask |= CONNMAN_IPCONFIG_SEARCH;
1456 } 1456 }
1457 1457
1458 static int ipconfig_storage_load(struct connman_ipconfig *ipconfig) 1458 static int ipconfig_storage_load(struct connman_ipconfig *ipconfig,
1459 GKeyFile *keyfile)
1459 { 1460 {
1460 const char *ident = __connman_profile_active_ident();
1461 GKeyFile *keyfile;
1462 gchar *key; 1461 gchar *key;
1463 struct connman_ipaddress *ipaddr = ipconfig->address; 1462 struct connman_ipaddress *ipaddr = ipconfig->address;
1464 GError *error; 1463 GError *error;
1465 char *str; 1464 char *str;
1466 gint val; 1465 gint val;
1466 int err = 0;
1467 1467
1468 _DBG_IPCONFIG("ipconfig %p", ipconfig); 1468 _DBG_IPCONFIG("ipconfig %p", ipconfig);
1469 1469
1470 keyfile = __connman_storage_open(ident);
1471 if (keyfile == NULL)
1472 return 0;
1473
1474 key = g_strdup_printf("ipconfig_%s", ipconfig->element.name); 1470 key = g_strdup_printf("ipconfig_%s", ipconfig->element.name);
1475 if (key == NULL) { 1471 if (key == NULL) {
1476 connman_error("%s: no memory for identifier", __func__); 1472 connman_error("%s: no memory for identifier", __func__);
1473 err = -ENOMEM;
1477 goto done; 1474 goto done;
1478 } 1475 }
1479 1476
1477 if (g_key_file_has_group(keyfile, key) == FALSE) {
1478 err = -ESRCH;
1479 goto done;
1480 }
1481
1480 /* NB: connman_ipconfig_create sets the type */ 1482 /* NB: connman_ipconfig_create sets the type */
1481 1483
1482 error = NULL; 1484 error = NULL;
1483 val = g_key_file_get_integer(keyfile, key, "Prefixlen", &error); 1485 val = g_key_file_get_integer(keyfile, key, "Prefixlen", &error);
1484 if (error == NULL) { 1486 if (error == NULL) {
1485 if (!(0 <= val && val <= MAX_PREFIXLEN)) { 1487 if (!(0 <= val && val <= MAX_PREFIXLEN)) {
1486 connman_error("%s: %s", __func__, error->message); 1488 connman_error("%s: %s", __func__, error->message);
1487 goto done; 1489 goto done;
1488 } 1490 }
1489 ipaddr->prefixlen = (unsigned char) val; 1491 ipaddr->prefixlen = (unsigned char) val;
(...skipping 21 matching lines...) Expand all
1511 } 1513 }
1512 str = g_key_file_get_string(keyfile, key, "NameServers", NULL); 1514 str = g_key_file_get_string(keyfile, key, "NameServers", NULL);
1513 if (str != NULL) 1515 if (str != NULL)
1514 setdns(ipaddr, str); 1516 setdns(ipaddr, str);
1515 str = g_key_file_get_string(keyfile, key, "SearchDomains", NULL); 1517 str = g_key_file_get_string(keyfile, key, "SearchDomains", NULL);
1516 if (str != NULL) 1518 if (str != NULL)
1517 setdomains(ipaddr, str); 1519 setdomains(ipaddr, str);
1518 /* TODO(sleffler) do consistency checking */ 1520 /* TODO(sleffler) do consistency checking */
1519 done: 1521 done:
1520 g_free(key); 1522 g_free(key);
1521 » __connman_storage_close(ident, keyfile, FALSE); 1523
1522 » return 0; 1524 » return err;
1523 } 1525 }
1524 1526
1525 struct ipconfig_paths { 1527 struct ipconfig_paths {
1526 const char const **names; 1528 const char const **names;
1527 int maxnames; 1529 int maxnames;
1528 int ix; 1530 int ix;
1529 }; 1531 };
1530 static void enumerate_ipconfig(struct connman_ipconfig *ipconfig, void *arg) 1532 static void enumerate_ipconfig(struct connman_ipconfig *ipconfig, void *arg)
1531 { 1533 {
1532 struct ipconfig_paths *paths = arg; 1534 struct ipconfig_paths *paths = arg;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 static void set_integer(GKeyFile *keyfile, gchar *key, 1566 static void set_integer(GKeyFile *keyfile, gchar *key,
1565 const struct connman_ipaddress *ipaddr, int mask, 1567 const struct connman_ipaddress *ipaddr, int mask,
1566 const char *name, int value) 1568 const char *name, int value)
1567 { 1569 {
1568 if (ipaddr->smask & mask) 1570 if (ipaddr->smask & mask)
1569 g_key_file_set_integer(keyfile, key, name, value); 1571 g_key_file_set_integer(keyfile, key, name, value);
1570 else 1572 else
1571 g_key_file_remove_key(keyfile, key, name, NULL); 1573 g_key_file_remove_key(keyfile, key, name, NULL);
1572 } 1574 }
1573 1575
1574 static int ipconfig_storage_save(const struct connman_ipconfig *ipconfig) 1576 static int ipconfig_storage_save(const struct connman_ipconfig *ipconfig,
1577 GKeyFile *keyfile)
1575 { 1578 {
1576 const char *ident = __connman_profile_active_ident();
1577 GKeyFile *keyfile;
1578 gchar *key; 1579 gchar *key;
1579 const struct connman_ipaddress *ipaddr = 1580 const struct connman_ipaddress *ipaddr =
1580 connman_ipconfig_get_ipaddress(ipconfig); 1581 connman_ipconfig_get_ipaddress(ipconfig);
1581 1582
1582 _DBG_IPCONFIG("ipconfig %p", ipconfig); 1583 _DBG_IPCONFIG("ipconfig %p", ipconfig);
1583 1584
1584 keyfile = __connman_storage_open(ident);
1585 if (keyfile == NULL)
1586 return 0;
1587
1588 key = g_strdup_printf("ipconfig_%s", ipconfig->element.name); 1585 key = g_strdup_printf("ipconfig_%s", ipconfig->element.name);
1589 if (key == NULL) { 1586 if (key == NULL) {
1590 connman_error("%s: no memory for identifier", __func__); 1587 connman_error("%s: no memory for identifier", __func__);
1591 goto done; 1588 goto done;
1592 } 1589 }
1593 1590
1594 /* TODO(sleffler) wrong type */ 1591 /* TODO(sleffler) wrong type */
1595 g_key_file_set_string(keyfile, key, "Method", 1592 g_key_file_set_string(keyfile, key, "Method",
1596 method2str(ipconfig->element.type)); 1593 method2str(ipconfig->element.type));
1597 1594
(...skipping 21 matching lines...) Expand all
1619 } 1616 }
1620 if (ipaddr->smask & CONNMAN_IPCONFIG_SEARCH) { 1617 if (ipaddr->smask & CONNMAN_IPCONFIG_SEARCH) {
1621 gchar *domains = g_strjoinv(",", ipaddr->search_domains); 1618 gchar *domains = g_strjoinv(",", ipaddr->search_domains);
1622 g_key_file_set_string(keyfile, key, "SearchDomains", domains); 1619 g_key_file_set_string(keyfile, key, "SearchDomains", domains);
1623 g_free(domains); 1620 g_free(domains);
1624 } else { 1621 } else {
1625 g_key_file_remove_key(keyfile, key, "SearchDomains", NULL); 1622 g_key_file_remove_key(keyfile, key, "SearchDomains", NULL);
1626 } 1623 }
1627 done: 1624 done:
1628 g_free(key); 1625 g_free(key);
1629 __connman_storage_close(ident, keyfile, TRUE);
1630 return 0; 1626 return 0;
1631 } 1627 }
1632 1628
1633 static int ipconfig_storage_remove(const struct connman_ipconfig *ipconfig) 1629 static int ipconfig_storage_remove(const struct connman_ipconfig *ipconfig)
1634 { 1630 {
1635 » const char *ident = __connman_profile_active_ident(); 1631 » const struct connman_storage_ident *ident =
1632 » __connman_profile_active_ident();
1636 GKeyFile *keyfile; 1633 GKeyFile *keyfile;
1637 gchar *group; 1634 gchar *group;
1638 1635
1639 » _DBG_IPCONFIG("ipconfig %p", ipconfig); 1636 » _DBG_IPCONFIG("ipconfig %p ident %p", ipconfig, ident);
1637
1638 » if (ident == NULL)
1639 » » return -EINVAL;
1640 1640
1641 keyfile = __connman_storage_open(ident); 1641 keyfile = __connman_storage_open(ident);
1642 if (keyfile == NULL) 1642 if (keyfile == NULL)
1643 return 0; 1643 return 0;
1644 1644
1645 group = g_strdup_printf("ipconfig_%s", ipconfig->element.name); 1645 group = g_strdup_printf("ipconfig_%s", ipconfig->element.name);
1646 if (group == NULL) { 1646 if (group == NULL) {
1647 connman_error("%s: no memory for group", __func__); 1647 connman_error("%s: no memory for group", __func__);
1648 goto done; 1648 goto done;
1649 } 1649 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 } else if (g_str_equal(key, "SearchDomains") == TRUE) { 1857 } else if (g_str_equal(key, "SearchDomains") == TRUE) {
1858 if (type != DBUS_TYPE_STRING) 1858 if (type != DBUS_TYPE_STRING)
1859 return __connman_error_invalid_arguments(msg); 1859 return __connman_error_invalid_arguments(msg);
1860 if (!ipconfig_isstatic(ipconfig)) 1860 if (!ipconfig_isstatic(ipconfig))
1861 return __connman_error_not_supported(msg); 1861 return __connman_error_not_supported(msg);
1862 dbus_message_iter_get_basic(&value, &str); 1862 dbus_message_iter_get_basic(&value, &str);
1863 setdomains(ipaddr, str); 1863 setdomains(ipaddr, str);
1864 } else 1864 } else
1865 return __connman_error_invalid_property(msg); 1865 return __connman_error_invalid_property(msg);
1866 1866
1867 » __connman_storage_save_ipconfig(ipconfig); 1867 » __connman_profile_save_ipconfig(ipconfig);
1868 1868
1869 connman_element_update(&ipconfig->element); 1869 connman_element_update(&ipconfig->element);
1870 1870
1871 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1871 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1872 } 1872 }
1873 1873
1874 static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg, 1874 static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg,
1875 void *data) 1875 void *data)
1876 { 1876 {
1877 struct connman_ipconfig *ipconfig = data; 1877 struct connman_ipconfig *ipconfig = data;
(...skipping 26 matching lines...) Expand all
1904 mask = CONNMAN_IPCONFIG_DOMAIN; 1904 mask = CONNMAN_IPCONFIG_DOMAIN;
1905 else if (g_str_equal(name, "NameServers") == TRUE) 1905 else if (g_str_equal(name, "NameServers") == TRUE)
1906 mask = CONNMAN_IPCONFIG_DNS; 1906 mask = CONNMAN_IPCONFIG_DNS;
1907 else 1907 else
1908 return __connman_error_invalid_property(msg); 1908 return __connman_error_invalid_property(msg);
1909 1909
1910 ipaddr->smask &= ~mask; 1910 ipaddr->smask &= ~mask;
1911 /* TODO(sleffler) should we leave current state alone? */ 1911 /* TODO(sleffler) should we leave current state alone? */
1912 /* NB: no way to record dynamic state (e.g. DHCP dns config) */ 1912 /* NB: no way to record dynamic state (e.g. DHCP dns config) */
1913 ipaddress_clear(ipaddr, mask); 1913 ipaddress_clear(ipaddr, mask);
1914 » __connman_storage_save_ipconfig(ipconfig); 1914 » __connman_profile_save_ipconfig(ipconfig);
1915 1915
1916 connman_element_update(&ipconfig->element); 1916 connman_element_update(&ipconfig->element);
1917 1917
1918 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1918 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1919 } 1919 }
1920 1920
1921 static DBusMessage *remove_ipconfig(DBusConnection *conn, DBusMessage *msg, 1921 static DBusMessage *remove_ipconfig(DBusConnection *conn, DBusMessage *msg,
1922 void *data) 1922 void *data)
1923 { 1923 {
1924 struct connman_ipconfig *ipconfig = data; 1924 struct connman_ipconfig *ipconfig = data;
1925 struct connman_device *device; 1925 struct connman_device *device;
1926 1926
1927 _DBG_IPCONFIG("conn %p", conn); 1927 _DBG_IPCONFIG("conn %p", conn);
1928 1928
1929 if (__connman_security_check_privilege(msg, 1929 if (__connman_security_check_privilege(msg,
1930 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0) 1930 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
1931 return __connman_error_permission_denied(msg); 1931 return __connman_error_permission_denied(msg);
1932 1932
1933 device = connman_ipconfig_get_device(ipconfig); 1933 device = connman_ipconfig_get_device(ipconfig);
1934 /* TODO(sleffler) expand storage api? */ 1934 /* TODO(sleffler) expand storage api? */
1935 /* NB: must be done before in-memory state is reclaimed */ 1935 /* NB: must be done before in-memory state is reclaimed */
1936 ipconfig_storage_remove(ipconfig); 1936 ipconfig_storage_remove(ipconfig);
1937 __connman_device_remove_ipconfig(device, ipconfig); 1937 __connman_device_remove_ipconfig(device, ipconfig);
1938 » __connman_storage_save_device(device); 1938 » __connman_profile_save_device(device);
1939 1939
1940 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1940 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1941 } 1941 }
1942 1942
1943 static DBusMessage *move_ipconfig(struct connman_ipconfig *ipconfig, 1943 static DBusMessage *move_ipconfig(struct connman_ipconfig *ipconfig,
1944 DBusMessage *msg, connman_bool_t before) 1944 DBusMessage *msg, connman_bool_t before)
1945 { 1945 {
1946 struct connman_ipconfig *target; 1946 struct connman_ipconfig *target;
1947 struct connman_device *device; 1947 struct connman_device *device;
1948 const char *path; 1948 const char *path;
1949 1949
1950 _DBG_IPCONFIG("ipconfig %p %s", ipconfig, before ? "before" : "after"); 1950 _DBG_IPCONFIG("ipconfig %p %s", ipconfig, before ? "before" : "after");
1951 1951
1952 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, 1952 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
1953 DBUS_TYPE_INVALID); 1953 DBUS_TYPE_INVALID);
1954 1954
1955 target = ipconfig_find(path); 1955 target = ipconfig_find(path);
1956 if (target == NULL || target == ipconfig) 1956 if (target == NULL || target == ipconfig)
1957 return __connman_error_invalid_ipconfig(msg); 1957 return __connman_error_invalid_ipconfig(msg);
1958 1958
1959 _DBG_IPCONFIG("target %p", target); 1959 _DBG_IPCONFIG("target %p", target);
1960 1960
1961 device = connman_ipconfig_get_device(ipconfig); 1961 device = connman_ipconfig_get_device(ipconfig);
1962 ipconfig_move(ipconfig, target, before ? 0 : 1); 1962 ipconfig_move(ipconfig, target, before ? 0 : 1);
1963 » __connman_storage_save_device(device); 1963 » __connman_profile_save_device(device);
1964 1964
1965 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1965 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1966 } 1966 }
1967 1967
1968 static DBusMessage *move_before(DBusConnection *conn, DBusMessage *msg, 1968 static DBusMessage *move_before(DBusConnection *conn, DBusMessage *msg,
1969 void *user_data) 1969 void *user_data)
1970 { 1970 {
1971 struct connman_ipconfig *ipconfig = user_data; 1971 struct connman_ipconfig *ipconfig = user_data;
1972 1972
1973 return move_ipconfig(ipconfig, msg, TRUE); 1973 return move_ipconfig(ipconfig, msg, TRUE);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 { 2156 {
2157 GSList *list; 2157 GSList *list;
2158 2158
2159 for (list = driver_list; list != NULL; list = list->next) { 2159 for (list = driver_list; list != NULL; list = list->next) {
2160 const struct connman_ipconfig_driver *driver = list->data; 2160 const struct connman_ipconfig_driver *driver = list->data;
2161 if (driver->type == type) 2161 if (driver->type == type)
2162 return driver; 2162 return driver;
2163 } 2163 }
2164 return NULL; 2164 return NULL;
2165 } 2165 }
OLDNEW
« no previous file with comments | « src/device.c ('k') | src/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698