fix ipv4 info retrieving, add ethernet.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 31 Dec 2009 03:31:03 +0000 (03:31 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 31 Dec 2009 03:31:03 +0000 (03:31 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@44819 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/e_dbus_connman_test.c
src/bin/e_dbus_connman_test_api.c
src/lib/connman/E_Connman.h
src/lib/connman/e_connman.c
src/lib/connman/e_connman_element.c
src/lib/connman/e_connman_private.h
src/lib/connman/e_connman_service.c

index 8d1c4e3..adfe961 100644 (file)
@@ -1832,7 +1832,7 @@ _on_cmd_service_get_ipv4_method(char *cmd, char *args)
 
    e = e_connman_service_get(path);
    if (e_connman_service_ipv4_method_get(e, &ipv4_method))
-     printf(":::Service %s ipv4 method = \"%s\"\n", path, ipv4_method);
+     printf(":::Service %s IPv4 Method = \"%s\"\n", path, ipv4_method);
    else
      fputs("ERROR: can't get service ipv4 method\n", stderr);
    return 1;
@@ -1854,12 +1854,239 @@ _on_cmd_service_get_ipv4_address(char *cmd, char *args)
 
    e = e_connman_service_get(path);
    if (e_connman_service_ipv4_address_get(e, &ipv4_address))
-     printf(":::Service %s ipv4 address = \"%s\"\n", path, ipv4_address);
+     printf(":::Service %s IPv4 Address = \"%s\"\n", path, ipv4_address);
    else
      fputs("ERROR: can't get service ipv4 address\n", stderr);
    return 1;
 }
 
+static int
+_on_cmd_service_get_ipv4_gateway(char *cmd, char *args)
+{
+   const char *ipv4_gateway, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_gateway_get(e, &ipv4_gateway))
+     printf(":::Service %s IPv4 Gateway = \"%s\"\n", path, ipv4_gateway);
+   else
+     fputs("ERROR: can't get service ipv4 gateway\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ipv4_netmask(char *cmd, char *args)
+{
+   const char *ipv4_netmask, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_netmask_get(e, &ipv4_netmask))
+     printf(":::Service %s IPv4 Netmask = \"%s\"\n", path, ipv4_netmask);
+   else
+     fputs("ERROR: can't get service ipv4 netmask\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ipv4_configuration_method(char *cmd, char *args)
+{
+   const char *ipv4_method, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_configuration_method_get(e, &ipv4_method))
+     printf(":::Service %s IPv4 Configuration Method = \"%s\"\n",
+           path, ipv4_method);
+   else
+     fputs("ERROR: can't get service ipv4_configuration method\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ipv4_configuration_address(char *cmd, char *args)
+{
+   const char *ipv4_address, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_configuration_address_get(e, &ipv4_address))
+     printf(":::Service %s IPv4 Configuration Address = \"%s\"\n",
+           path, ipv4_address);
+   else
+     fputs("ERROR: can't get service ipv4_configuration address\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ipv4_configuration_gateway(char *cmd, char *args)
+{
+   const char *ipv4_gateway, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_configuration_gateway_get(e, &ipv4_gateway))
+     printf(":::Service %s IPv4 Configuration Gateway = \"%s\"\n",
+           path, ipv4_gateway);
+   else
+     fputs("ERROR: can't get service ipv4_configuration gateway\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ipv4_configuration_netmask(char *cmd, char *args)
+{
+   const char *ipv4_netmask, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ipv4_configuration_netmask_get(e, &ipv4_netmask))
+     printf(":::Service %s IPv4 Configuration Netmask = \"%s\"\n",
+           path, ipv4_netmask);
+   else
+     fputs("ERROR: can't get service ipv4 configuration netmask\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ethernet_method(char *cmd, char *args)
+{
+   const char *ethernet_method, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ethernet_method_get(e, &ethernet_method))
+     printf(":::Service %s Ethernet Method = \"%s\"\n", path, ethernet_method);
+   else
+     fputs("ERROR: can't get service ethernet method\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ethernet_address(char *cmd, char *args)
+{
+   const char *ethernet_address, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ethernet_address_get(e, &ethernet_address))
+     printf(":::Service %s Ethernet Address = \"%s\"\n",
+           path, ethernet_address);
+   else
+     fputs("ERROR: can't get service ethernet address\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ethernet_mtu(char *cmd, char *args)
+{
+   const char *path;
+   E_Connman_Element *e;
+   unsigned short ethernet_mtu;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ethernet_mtu_get(e, &ethernet_mtu))
+     printf(":::Service %s Ethernet MTU = %hu\n", path, ethernet_mtu);
+   else
+     fputs("ERROR: can't get service ethernet mtu\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_service_get_ethernet_netmask(char *cmd, char *args)
+{
+   const char *ethernet_netmask, *path;
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the service path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+   path = args;
+
+   e = e_connman_service_get(path);
+   if (e_connman_service_ethernet_netmask_get(e, &ethernet_netmask))
+     printf(":::Service %s Ethernet Netmask = \"%s\"\n",
+           path, ethernet_netmask);
+   else
+     fputs("ERROR: can't get service ethernet netmask\n", stderr);
+   return 1;
+}
+
 
 static int
 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
@@ -1949,6 +2176,16 @@ _on_input(void *data, Ecore_Fd_Handler *fd_handler)
      {"service_get_roaming", _on_cmd_service_get_roaming},
      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
+     {"service_get_ipv4_gateway", _on_cmd_service_get_ipv4_gateway},
+     {"service_get_ipv4_netmask", _on_cmd_service_get_ipv4_netmask},
+     {"service_get_ipv4_configuration_method", _on_cmd_service_get_ipv4_configuration_method},
+     {"service_get_ipv4_configuration_address", _on_cmd_service_get_ipv4_configuration_address},
+     {"service_get_ipv4_configuration_gateway", _on_cmd_service_get_ipv4_configuration_gateway},
+     {"service_get_ipv4_configuration_netmask", _on_cmd_service_get_ipv4_configuration_netmask},
+     {"service_get_ethernet_method", _on_cmd_service_get_ethernet_method},
+     {"service_get_ethernet_address", _on_cmd_service_get_ethernet_address},
+     {"service_get_ethernet_mtu", _on_cmd_service_get_ethernet_mtu},
+     {"service_get_ethernet_netmask", _on_cmd_service_get_ethernet_netmask},
      {NULL, NULL}
    };
 
index 0c53c0b..17e200b 100644 (file)
@@ -464,6 +464,16 @@ static const struct test_desc test_desc_service[] = {
   TEST_DESC_BOOL_GET(e_connman_service_roaming_get, 1),
   TEST_DESC_STRING_GET(e_connman_service_ipv4_method_get, 1),
   TEST_DESC_STRING_GET(e_connman_service_ipv4_address_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_gateway_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_netmask_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_method_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_address_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_gateway_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_netmask_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ethernet_method_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ethernet_address_get, 1),
+  TEST_DESC_USHORT_GET(e_connman_service_ethernet_mtu_get, 1),
+  TEST_DESC_STRING_GET(e_connman_service_ethernet_netmask_get, 1),
   TEST_DESC_SENTINEL
 };
 
index 6b89d1f..c3dbd76 100644 (file)
@@ -182,21 +182,32 @@ extern "C" {
 
   EAPI bool e_connman_service_ipv4_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
 
-  // TODO: ipv4_netmask_get
-  // TODO: ipv4_gateway_get
-  // TODO: ipv4_configuration_metod_get
-  // TODO: ipv4_configuration_metod_set
-  // TODO: ipv4_configuration_address_get
+  EAPI bool e_connman_service_ipv4_gateway_get(const E_Connman_Element *service, const char **gateway) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ipv4_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ipv4_configuration_method_get(const E_Connman_Element *service, const char **method) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ipv4_configuration_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ipv4_configuration_gateway_get(const E_Connman_Element *service, const char **gateway) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ipv4_configuration_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ethernet_method_get(const E_Connman_Element *service, const char **method) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ethernet_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ethernet_mtu_get(const E_Connman_Element *service, unsigned short *mtu) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_service_ethernet_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_PURE EINA_WARN_UNUSED_RESULT;
+
+  // TODO: ipv4_configuration_method_set
   // TODO: ipv4_configuration_address_set
-  // TODO: ipv4_configuration_netmask_get
   // TODO: ipv4_configuration_netmask_set
-  // TODO: ipv4_configuration_gateway_get
   // TODO: ipv4_configuration_gateway_set
-  // TODO: ethernet_method_get
-  // TODO: ethernet_address_get
-  // TODO: ethernet_mtu_get
-  // TODO: ethernet_speed_get
-  // TODO: ethernet_duplex_get
+  // TODO: ethernet_speed_get (not in connman yet)
+  // TODO: ethernet_duplex_get (not in connman yet)
 
   /* Low-Level API:
    *
@@ -228,6 +239,7 @@ extern "C" {
 
   EAPI bool e_connman_element_property_type_get_stringshared(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_PURE EINA_WARN_UNUSED_RESULT;
   EAPI bool e_connman_element_property_type_get(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_PURE EINA_WARN_UNUSED_RESULT;
+  EAPI bool e_connman_element_property_dict_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key_name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_PURE EINA_WARN_UNUSED_RESULT;
   EAPI bool e_connman_element_property_get_stringshared(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_PURE EINA_WARN_UNUSED_RESULT;
   EAPI bool e_connman_element_property_get(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_PURE EINA_WARN_UNUSED_RESULT;
 
index ac224f0..a383c1b 100644 (file)
@@ -34,9 +34,14 @@ const char *e_connman_prop_default = NULL;
 const char *e_connman_prop_device = NULL;
 const char *e_connman_prop_devices = NULL;
 const char *e_connman_prop_interface = NULL;
-const char *e_connman_prop_ipv4_address = NULL;
-const char *e_connman_prop_ipv4_method = NULL;
+const char *e_connman_prop_ipv4 = NULL;
+const char *e_connman_prop_ipv4_configuration = NULL;
+const char *e_connman_prop_ethernet = NULL;
+const char *e_connman_prop_method = NULL;
 const char *e_connman_prop_address = NULL;
+const char *e_connman_prop_gateway = NULL;
+const char *e_connman_prop_netmask = NULL;
+const char *e_connman_prop_mtu = NULL;
 const char *e_connman_prop_name = NULL;
 const char *e_connman_prop_network = NULL;
 const char *e_connman_prop_networks = NULL;
@@ -295,12 +300,22 @@ e_connman_system_init(E_DBus_Connection *edbus_conn)
      e_connman_prop_devices = eina_stringshare_add("Devices");
    if (e_connman_prop_interface == NULL)
      e_connman_prop_interface = eina_stringshare_add("Interface");
-   if (e_connman_prop_ipv4_address == NULL)
-     e_connman_prop_ipv4_address = eina_stringshare_add("IPv4.Address");
-   if (e_connman_prop_ipv4_method == NULL)
-     e_connman_prop_ipv4_method = eina_stringshare_add("IPv4.Method");
+   if (e_connman_prop_ipv4 == NULL)
+     e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
+   if (e_connman_prop_ipv4_configuration == NULL)
+     e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
+   if (e_connman_prop_ethernet == NULL)
+     e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
+   if (e_connman_prop_method == NULL)
+     e_connman_prop_method = eina_stringshare_add("Method");
    if (e_connman_prop_address == NULL)
      e_connman_prop_address = eina_stringshare_add("Address");
+   if (e_connman_prop_gateway == NULL)
+     e_connman_prop_gateway = eina_stringshare_add("Gateway");
+   if (e_connman_prop_netmask == NULL)
+     e_connman_prop_netmask = eina_stringshare_add("Netmask");
+   if (e_connman_prop_mtu == NULL)
+     e_connman_prop_mtu = eina_stringshare_add("MTU");
    if (e_connman_prop_name == NULL)
      e_connman_prop_name = eina_stringshare_add("Name");
    if (e_connman_prop_network == NULL)
@@ -439,9 +454,14 @@ e_connman_system_shutdown(void)
    _stringshare_del(&e_connman_prop_device);
    _stringshare_del(&e_connman_prop_devices);
    _stringshare_del(&e_connman_prop_interface);
-   _stringshare_del(&e_connman_prop_ipv4_address);
-   _stringshare_del(&e_connman_prop_ipv4_method);
+   _stringshare_del(&e_connman_prop_ipv4);
+   _stringshare_del(&e_connman_prop_ipv4_configuration);
+   _stringshare_del(&e_connman_prop_ethernet);
+   _stringshare_del(&e_connman_prop_method);
    _stringshare_del(&e_connman_prop_address);
+   _stringshare_del(&e_connman_prop_gateway);
+   _stringshare_del(&e_connman_prop_netmask);
+   _stringshare_del(&e_connman_prop_mtu);
    _stringshare_del(&e_connman_prop_name);
    _stringshare_del(&e_connman_prop_network);
    _stringshare_del(&e_connman_prop_networks);
index 8bff37f..a962053 100644 (file)
@@ -9,6 +9,7 @@ typedef struct _E_Connman_Element_Pending E_Connman_Element_Pending;
 typedef struct _E_Connman_Element_Call_Data E_Connman_Element_Call_Data;
 typedef struct _E_Connman_Element_Property E_Connman_Element_Property;
 typedef struct _E_Connman_Element_Listener E_Connman_Element_Listener;
+typedef struct _E_Connman_Element_Dict_Entry E_Connman_Element_Dict_Entry;
 
 struct _E_Connman_Array
 {
@@ -50,6 +51,20 @@ struct _E_Connman_Element_Property
    } value;
 };
 
+struct _E_Connman_Element_Dict_Entry
+{
+   const char *name;
+   int type;
+   union {
+      bool boolean;
+      const char *str;
+      unsigned short u16;
+      unsigned int u32;
+      unsigned char byte;
+      const char *path;
+   } value;
+};
+
 struct _E_Connman_Element_Listener
 {
    EINA_INLIST;
@@ -220,6 +235,131 @@ _e_connman_element_listeners_call(E_Connman_Element *element)
  ***********************************************************************/
 
 static void
+_e_connman_element_dict_entry_free(E_Connman_Element_Dict_Entry *entry)
+{
+   switch (entry->type)
+     {
+      case DBUS_TYPE_BOOLEAN:
+      case DBUS_TYPE_BYTE:
+      case DBUS_TYPE_UINT16:
+      case DBUS_TYPE_UINT32:
+        break;
+      case DBUS_TYPE_OBJECT_PATH:
+        eina_stringshare_del(entry->value.path);
+        break;
+      case DBUS_TYPE_STRING:
+        eina_stringshare_del(entry->value.str);
+        break;
+      default:
+        ERR("don't know how to free dict entry '%s' of type %c (%d)",
+            entry->name, entry->type, entry->type);
+     }
+
+   eina_stringshare_del(entry->name);
+   free(entry);
+}
+
+static E_Connman_Element_Dict_Entry *
+_e_connman_element_dict_entry_new(DBusMessageIter *itr)
+{
+   E_Connman_Element_Dict_Entry *entry;
+   DBusMessageIter e_itr, v_itr;
+   int t;
+   const char *key = NULL;
+   void *value = NULL;
+
+   dbus_message_iter_recurse(itr, &e_itr);
+
+   t = dbus_message_iter_get_arg_type(&e_itr);
+   if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
+     {
+       ERR("invalid format for dict entry. first type not a string: %c (%d)",
+           t, t);
+       return NULL;
+     }
+
+   dbus_message_iter_get_basic(&e_itr, &key);
+   if (!key || !key[0])
+     {
+       ERR("invalid format for dict entry. no key.");
+       return NULL;
+     }
+
+   dbus_message_iter_next(&e_itr);
+   t = dbus_message_iter_get_arg_type(&e_itr);
+   if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT))
+     {
+       ERR("invalid format for dict entry '%s'. "
+           "second type not a variant: %c (%d)",
+           key, t, t);
+       return NULL;
+     }
+
+   dbus_message_iter_recurse(&e_itr, &v_itr);
+
+   t = dbus_message_iter_get_arg_type(&v_itr);
+   if ((t == DBUS_TYPE_INVALID) || (t == DBUS_TYPE_ARRAY))
+     {
+       ERR("invalid type for dict value for entry '%s': %c (%d)",
+           key, t, t);
+       return NULL;
+     }
+
+   entry = calloc(1, sizeof(*entry));
+   if (!entry)
+     {
+       ERR("could not allocate memory for dict entry.");
+       return NULL;
+     }
+
+   dbus_message_iter_get_basic(&v_itr, &value);
+   switch (t)
+     {
+      case DBUS_TYPE_BOOLEAN:
+        entry->value.boolean = (bool)(long)value;
+        break;
+      case DBUS_TYPE_BYTE:
+        entry->value.byte = (unsigned char)(long)value;
+        break;
+      case DBUS_TYPE_UINT16:
+        entry->value.u16 = (unsigned short)(long)value;
+        break;
+      case DBUS_TYPE_UINT32:
+        entry->value.u32 = (unsigned int)(long)value;
+        break;
+      case DBUS_TYPE_STRING:
+        entry->value.str = eina_stringshare_add(value);
+        break;
+      case DBUS_TYPE_OBJECT_PATH:
+        entry->value.path = eina_stringshare_add(value);
+        break;
+      default:
+        ERR("don't know how to create dict entry '%s' for of type %c (%d)",
+            key, t, t);
+        free(entry);
+        return NULL;
+     }
+
+   entry->name = eina_stringshare_add(key);
+   entry->type = t;
+   return entry;
+}
+
+static E_Connman_Element_Dict_Entry *
+_e_connman_element_array_dict_find_stringshared(const E_Connman_Array *array, const char *key)
+{
+   E_Connman_Element_Dict_Entry *entry;
+   Eina_Array_Iterator iterator;
+   unsigned int i;
+
+   EINA_ARRAY_ITER_NEXT(array->array, i, entry, iterator)
+     if (entry->name == key)
+       return entry;
+
+   return NULL;
+}
+
+static void
 _e_connman_element_array_free(E_Connman_Array *array, E_Connman_Array *new __UNUSED__)
 {
    Eina_Array_Iterator iterator;
@@ -231,6 +371,11 @@ _e_connman_element_array_free(E_Connman_Array *array, E_Connman_Array *new __UNU
 
    switch (array->type)
      {
+      case DBUS_TYPE_BOOLEAN:
+      case DBUS_TYPE_BYTE:
+      case DBUS_TYPE_UINT16:
+      case DBUS_TYPE_UINT32:
+        break;
       case DBUS_TYPE_OBJECT_PATH:
         EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
           eina_stringshare_del(item);
@@ -239,7 +384,13 @@ _e_connman_element_array_free(E_Connman_Array *array, E_Connman_Array *new __UNU
         EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
           eina_stringshare_del(item);
         break;
+      case DBUS_TYPE_DICT_ENTRY:
+        EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
+          _e_connman_element_dict_entry_free(item);
+        break;
       default:
+        ERR("don't know how to free array of values of type %c (%d)",
+            array->type, array->type);
         break;
      }
    eina_array_free(array->array);
@@ -296,10 +447,6 @@ _e_connman_element_get_interface(const char *key)
         if (strcmp(tail, "etworks") == 0)
           interface = e_connman_iface_network;
         break;
-      case 'C':
-        if (strcmp(tail, "onnections") == 0)
-          interface = e_connman_iface_connection;
-        break;
       case 'S':
         if (strcmp(tail, "ervices") == 0)
           interface = e_connman_iface_service;
@@ -625,7 +772,7 @@ e_connman_element_strings_array_get_stringshared(const E_Connman_Element *elemen
    return 1;
 }
 
-void
+static void
 _e_connman_element_array_print(FILE *fp, E_Connman_Array *array)
 {
    Eina_Array_Iterator iterator;
@@ -650,7 +797,47 @@ _e_connman_element_array_print(FILE *fp, E_Connman_Array *array)
           fprintf(fp, "%#02hhx (\"%c\"), ", (unsigned char)(long)item,
                   (unsigned char)(long)item);
         break;
-      case DBUS_TYPE_INVALID:
+      case DBUS_TYPE_UINT16:
+        EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
+          fprintf(fp, "%#04hx (%hu), ", (unsigned short)(long)item,
+                  (unsigned short)(long)item);
+        break;
+      case DBUS_TYPE_UINT32:
+        EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
+          fprintf(fp, "%#08x (%u), ", (unsigned int)(long)item,
+                  (unsigned int)(long)item);
+        break;
+      case DBUS_TYPE_DICT_ENTRY:
+        fputs("{ ", fp);
+        EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator)
+          {
+             E_Connman_Element_Dict_Entry *entry = item;
+             fprintf(fp, "%s: ", entry->name);
+             switch (entry->type)
+               {
+                case DBUS_TYPE_OBJECT_PATH:
+                   fprintf(fp, "\"%s\", ", entry->value.path);
+                   break;
+                case DBUS_TYPE_STRING:
+                   fprintf(fp, "\"%s\", ", entry->value.str);
+                   break;
+                case DBUS_TYPE_BYTE:
+                   fprintf(fp, "%#02hhx (\"%c\"), ",
+                           entry->value.byte, entry->value.byte);
+                   break;
+                case DBUS_TYPE_UINT16:
+                   fprintf(fp, "%#04hx (%hu), ",
+                           entry->value.u16, entry->value.u16);
+                   break;
+                case DBUS_TYPE_UINT32:
+                   fprintf(fp, "%#08x (%u), ",
+                           entry->value.u32, entry->value.u32);
+                   break;
+                default:
+                   fprintf(fp, "<UNKNOWN TYPE '%c'>", entry->type);
+               }
+          }
+        fputs("}", fp);
         break;
       default:
         fprintf(fp, "<UNKNOWN ARRAY TYPE '%c'>", array->type);
@@ -940,12 +1127,18 @@ _e_connman_element_iter_get_array(DBusMessageIter *itr, const char *key)
 
    dbus_message_iter_recurse(itr, &e_itr);
    array->type = dbus_message_iter_get_arg_type(&e_itr);
+   if (array->type == DBUS_TYPE_INVALID)
+     {
+       DBG("array %s is of type 'invalid' (empty?)", key);
+       eina_array_free(array->array);
+       free(array);
+       return NULL;
+     }
+
    do
      {
        switch (array->type)
          {
-          case DBUS_TYPE_INVALID:
-             break;
           case DBUS_TYPE_OBJECT_PATH:
             {
                const char *path;
@@ -972,9 +1165,20 @@ _e_connman_element_iter_get_array(DBusMessageIter *itr, const char *key)
                eina_array_push(array->array, (void *)(long)byte);
             }
             break;
+          case DBUS_TYPE_DICT_ENTRY:
+            {
+               E_Connman_Element_Dict_Entry *entry;
+               entry = _e_connman_element_dict_entry_new(&e_itr);
+               if (entry)
+                 eina_array_push(array->array, entry);
+            }
+            break;
           default:
-             ERR("don't know how to get property type %c (%d)",
-                 array->type, array->type);
+             ERR("don't know how to build array '%s' of type %c (%d)",
+                 key, array->type, array->type);
+             eina_array_free(array->array);
+             free(array);
+             return NULL;
          }
      }
    while (dbus_message_iter_next(&e_itr));
@@ -1308,6 +1512,99 @@ e_connman_element_list_properties(const E_Connman_Element *element, bool (*cb)(v
 }
 
 /**
+ * Get dict value given its key inside a dict property.
+ *
+ * This will look into properties for one of type dict that contains
+ * the given key, to find the property.  If no property is found then
+ * 0 is returned.
+ *
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * @param element which element to get the property
+ * @param dict_name property name, must be previously stringshared
+ * @param key key inside dict, must be previously stringshared
+ * @param type if provided it will contain the value type.
+ * @param value where to store the property value, must be a pointer to the
+ *        exact type, (bool *) for booleans, (char **) for strings, and so on.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_element_property_dict_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key, int *type, void *value)
+{
+   const E_Connman_Element_Property *p;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dict_name, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(key, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0);
+
+   EINA_INLIST_FOREACH(element->props, p)
+     {
+       E_Connman_Element_Dict_Entry *entry;
+       E_Connman_Array *array;
+
+       if (p->name != dict_name)
+         continue;
+       if (p->type != DBUS_TYPE_ARRAY)
+         {
+            WRN("element %s (%p) has property \"%s\" is not an array: %c (%d)",
+                element->path, element, dict_name, p->type, p->type);
+            return 0;
+         }
+       array = p->value.array;
+       if ((!array) || (array->type != DBUS_TYPE_DICT_ENTRY))
+         {
+            int t = array ? array->type : DBUS_TYPE_INVALID;
+            WRN("element %s (%p) has property \"%s\" is not a dict: %c (%d)",
+                element->path, element, dict_name, t, t);
+            return 0;
+         }
+       entry = _e_connman_element_array_dict_find_stringshared(array, key);
+       if (!entry)
+         {
+            WRN("element %s (%p) has no dict property with name \"%s\" with "
+                "key \"%s\".",
+                element->path, element, dict_name, key);
+            return 0;
+         }
+
+       if (type) *type = entry->type;
+
+       switch (entry->type)
+         {
+          case DBUS_TYPE_BOOLEAN:
+             *(bool *)value = entry->value.boolean;
+             return 1;
+          case DBUS_TYPE_BYTE:
+             *(unsigned char *)value = entry->value.byte;
+             return 1;
+          case DBUS_TYPE_UINT16:
+             *(unsigned short *)value = entry->value.u16;
+             return 1;
+          case DBUS_TYPE_UINT32:
+             *(unsigned int *)value = entry->value.u32;
+             return 1;
+          case DBUS_TYPE_STRING:
+             *(const char **)value = entry->value.str;
+             return 1;
+          case DBUS_TYPE_OBJECT_PATH:
+             *(const char **)value = entry->value.path;
+             return 1;
+          default:
+             ERR("don't know how to get property %s, key %s type %c (%d)",
+                 dict_name, key, entry->type, entry->type);
+             return 0;
+         }
+     }
+
+   WRN("element %s (%p) has no property with name \"%s\".",
+       element->path, element, dict_name);
+   return 0;
+}
+
+/**
  * Get property value given its name.
  *
  * This will look into properties, to find the property.
index 6f295ea..ebc5fce 100644 (file)
@@ -25,9 +25,14 @@ extern const char *e_connman_prop_default;
 extern const char *e_connman_prop_device;
 extern const char *e_connman_prop_devices;
 extern const char *e_connman_prop_interface;
-extern const char *e_connman_prop_ipv4_address;
-extern const char *e_connman_prop_ipv4_method;
+extern const char *e_connman_prop_ipv4;
+extern const char *e_connman_prop_ipv4_configuration;
+extern const char *e_connman_prop_ethernet;
+extern const char *e_connman_prop_method;
 extern const char *e_connman_prop_address;
+extern const char *e_connman_prop_gateway;
+extern const char *e_connman_prop_netmask;
+extern const char *e_connman_prop_mtu;
 extern const char *e_connman_prop_name;
 extern const char *e_connman_prop_network;
 extern const char *e_connman_prop_networks;
index f820465..b30e58b 100644 (file)
@@ -819,8 +819,8 @@ e_connman_service_roaming_get(const E_Connman_Element *service, bool *roaming)
  * If zero is returned, then this call failed and parameter-returned
  * values shall be considered invalid.
  *
- * The IPv4 configuration method. Possible values here
- * are "dhcp" and "static".
+ * The IPv4 method in use. Possible values here are "dhcp" and
+ * "static".
  *
  * @param service path to get property.
  * @param method where to store the property value, must be a pointer
@@ -835,8 +835,8 @@ e_connman_service_ipv4_method_get(const E_Connman_Element *service, const char *
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0);
-   return e_connman_element_property_get_stringshared
-     (service, e_connman_prop_ipv4_method, NULL, method);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4, e_connman_prop_method, NULL, method);
 }
 
 /**
@@ -846,7 +846,7 @@ e_connman_service_ipv4_method_get(const E_Connman_Element *service, const char *
  * If zero is returned, then this call failed and parameter-returned
  * values shall be considered invalid.
  *
- * The current configured IPv4 address.
+ * The current IPv4 address.
  *
  * @param service path to get property.
  * @param address where to store the property value, must be a pointer
@@ -861,6 +861,283 @@ e_connman_service_ipv4_address_get(const E_Connman_Element *service, const char
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0);
-   return e_connman_element_property_get_stringshared
-     (service, e_connman_prop_ipv4_address, NULL, address);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4, e_connman_prop_address, NULL, address);
+}
+
+/**
+ * Get property "IPv4.Gateway" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current IPv4 gateway.
+ *
+ * @param service path to get property.
+ * @param gateway where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_gateway_get(const E_Connman_Element *service, const char **gateway)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(gateway, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4, e_connman_prop_gateway, NULL, gateway);
+}
+
+/**
+ * Get property "IPv4.Netmask" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current IPv4 netmask.
+ *
+ * @param service path to get property.
+ * @param netmask where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_netmask_get(const E_Connman_Element *service, const char **netmask)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4, e_connman_prop_netmask, NULL, netmask);
+}
+
+/**
+ * Get property "IPv4.Configuration.Method" value.
+ *
+ * Unlike IPv4.Method, this is the user-set value, rather than the
+ * actual value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The IPv4 configured method. Possible values here are "dhcp" and
+ * "static".
+ *
+ * @param service path to get property.
+ * @param method where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_configuration_method_get(const E_Connman_Element *service, const char **method)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4_configuration, e_connman_prop_method,
+      NULL, method);
+}
+
+/**
+ * Get property "IPv4.Configuration.Address" value.
+ *
+ * Unlike IPv4.Address, this is the user-set value, rather than the
+ * actual value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured IPv4 address.
+ *
+ * @param service path to get property.
+ * @param address where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_configuration_address_get(const E_Connman_Element *service, const char **address)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4_configuration, e_connman_prop_address,
+      NULL, address);
+}
+
+/**
+ * Get property "IPv4.Configuration.Gateway" value.
+ *
+ * Unlike IPv4.Gateway, this is the user-set value, rather than the
+ * actual value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured IPv4 gateway.
+ *
+ * @param service path to get property.
+ * @param gateway where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_configuration_gateway_get(const E_Connman_Element *service, const char **gateway)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(gateway, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4_configuration, e_connman_prop_gateway,
+      NULL, gateway);
+}
+
+/**
+ * Get property "IPv4.Configuration.Netmask" value.
+ *
+ * Unlike IPv4.Netmask, this is the user-set value, rather than the
+ * actual value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured IPv4 netmask.
+ *
+ * @param service path to get property.
+ * @param netmask where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ipv4_configuration_netmask_get(const E_Connman_Element *service, const char **netmask)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ipv4_configuration, e_connman_prop_netmask,
+      NULL, netmask);
+}
+
+/**
+ * Get property "Ethernet.Method" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The Ethernet configuration method. Possible values here "auto".
+ *
+ * @param service path to get property.
+ * @param method where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ethernet_method_get(const E_Connman_Element *service, const char **method)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ethernet, e_connman_prop_method, NULL, method);
+}
+
+/**
+ * Get property "Ethernet.Address" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured Ethernet address (mac-address).
+ *
+ * @param service path to get property.
+ * @param address where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ethernet_address_get(const E_Connman_Element *service, const char **address)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ethernet, e_connman_prop_address, NULL, address);
+}
+
+/**
+ * Get property "Ethernet.Gateway" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured Ethernet MTU.
+ *
+ * @param service path to get property.
+ * @param gateway where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ethernet_mtu_get(const E_Connman_Element *service, unsigned short *mtu)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(mtu, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ethernet, e_connman_prop_mtu, NULL, mtu);
+}
+
+/**
+ * Get property "Ethernet.Netmask" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * The current configured Ethernet netmask.
+ *
+ * @param service path to get property.
+ * @param netmask where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_service_ethernet_netmask_get(const E_Connman_Element *service, const char **netmask)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0);
+   return e_connman_element_property_dict_get_stringshared
+     (service, e_connman_prop_ethernet, e_connman_prop_netmask, NULL, netmask);
 }