[libvirt] [dbus PATCH v2 3/9] Abandon usage of all *TypeToString functions in network.c

2018-05-04 Thread Katerina Koukiou
Converting ENUMS to str can be user friendly though
it can be problematic in matters of backward compatibility.

In particular when some ENUM in libvirt API will introduce a
new constant, libvirt-dbus will fail with:

size of array ‘_GStaticAssertCompileTimeAssertion_5’ is negative

So using ints is preferable to avoid the previous issue.

Signed-off-by: Katerina Koukiou 
---
 data/org.libvirt.Network.xml |  6 ++--
 src/network.c| 66 +++-
 tests/test_network.py|  2 +-
 3 files changed, 8 insertions(+), 66 deletions(-)

diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
index cf05062..e8c1506 100644
--- a/data/org.libvirt.Network.xml
+++ b/data/org.libvirt.Network.xml
@@ -43,7 +43,7 @@
Empty string will be returned in output for NULL variables."/>
   
   
-  
+  
 
 
   
   https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate"/>
-  
-  
+  
+  
   
   
   
diff --git a/src/network.c b/src/network.c
index 4d00dfe..256940f 100644
--- a/src/network.c
+++ b/src/network.c
@@ -3,38 +3,6 @@
 
 #include 
 
-VIRT_DBUS_ENUM_DECL(virtDBusNetworkIPAddr)
-VIRT_DBUS_ENUM_IMPL(virtDBusNetworkIPAddr,
-VIR_IP_ADDR_TYPE_LAST,
-"ipv4",
-"ipv6")
-
-VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateCommand)
-VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateCommand,
-VIR_NETWORK_UPDATE_COMMAND_LAST,
-"none",
-"modify",
-"delete",
-"add-last",
-"add-first")
-
-VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateSection)
-VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateSection,
-VIR_NETWORK_SECTION_LAST,
-"none",
-"bridge",
-"domain",
-"ip",
-"ip-dhcp-host",
-"ip-dhcp-range",
-"forward",
-"forward-interface",
-"forward-pf",
-"portgroup",
-"dns-host",
-"dns-txt",
-"dns-srv")
-
 static void
 virtDBusNetworkDHCPLeaseListFree(virNetworkDHCPLeasePtr *leases)
 {
@@ -284,20 +252,11 @@ virtDBusNetworkGetDHCPLeases(GVariant *inArgs,
 
 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(stuss)"));
 for (gint i = 0; i < nleases; i++) {
-const gchar *typeStr;
-
 virNetworkDHCPLeasePtr lease = leases[i];
 
-typeStr = virtDBusNetworkIPAddrTypeToString(lease->type);
-if (!typeStr) {
-g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
-"Can't format virIPAddrType '%d' to string.", 
lease->type);
-return;
-}
-
-g_variant_builder_add(&builder, "(stuss)",
+g_variant_builder_add(&builder, "(stusssuss)",
   lease->iface, lease->expirytime,
-  typeStr, lease->mac,
+  lease->type, lease->mac,
   lease->iaid ? lease->iaid : "" ,
   lease->ipaddr, lease->prefix,
   lease->hostname ? lease->hostname : "",
@@ -366,33 +325,16 @@ virtDBusNetworkUpdate(GVariant *inArgs,
 {
 virtDBusConnect *connect = userData;
 g_autoptr(virNetwork) network = NULL;
-const gchar *commandStr;
 gint command;
-const gchar *sectionStr;
 gint section;
 gint parentIndex;
 const gchar *xml;
 guint flags;
 
-g_variant_get(inArgs, "(&s&si&su)",
-  &commandStr, §ionStr,
+g_variant_get(inArgs, "(uui&su)",
+  &command, §ion,
   &parentIndex, &xml, &flags);
 
-command = virtDBusNetworkUpdateCommandTypeFromString(commandStr);
-if (command < 0) {
-g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
-"Can't get valid virNetworkUpdateCommand from string 
'%s'.",
-commandStr);
-return;
-}
-section = virtDBusNetworkUpdateSectionTypeFromString(sectionStr);
-if (section < 0) {
-g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
-"Can't get valid virNetworkUpdateSection from string 
'%s'.",
-sectionStr);
-return;
-}
-
 network = virtDBusNetworkGetVirNetwork(connect, objectPath, error);
 if (!network)
 return;
diff --git a/tests/test_network.py b/tests/test_network.py
index 2c1bd21..1340d95 100755
--- a/tests/test_network.py
+++ b/tests/test_network.py
@@ -80,7 +80,7 @@ class TestNetwork(libvirttest.BaseTestClass):
 self.main_loop()
 
 @pytest.mark.parametrize("command, section, parentIndex, xml_str, flags", [
-('add-first', 'ip-dhcp-hos

Re: [libvirt] [dbus PATCH v2 3/9] Abandon usage of all *TypeToString functions in network.c

2018-05-04 Thread Pavel Hrdina
On Fri, May 04, 2018 at 10:38:29AM +0200, Katerina Koukiou wrote:
> Converting ENUMS to str can be user friendly though
> it can be problematic in matters of backward compatibility.
> 
> In particular when some ENUM in libvirt API will introduce a
> new constant, libvirt-dbus will fail with:
> 
> size of array ‘_GStaticAssertCompileTimeAssertion_5’ is negative
> 
> So using ints is preferable to avoid the previous issue.
> 
> Signed-off-by: Katerina Koukiou 
> ---
>  data/org.libvirt.Network.xml |  6 ++--
>  src/network.c| 66 
> +++-
>  tests/test_network.py|  2 +-
>  3 files changed, 8 insertions(+), 66 deletions(-)

Reviewed-by: Pavel Hrdina 


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list