[PATCH] util: authconfig: use g_key_file_*

Rafael Fonseca posted 1 patch 4 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200320170635.259413-1-r4f4rfs@gmail.com
src/util/virauthconfig.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
[PATCH] util: authconfig: use g_key_file_*
Posted by Rafael Fonseca 4 years, 1 month ago
Replace libvirt's virKeyFile by glib's GKeyFile.

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
---
 src/util/virauthconfig.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
index fd846ddd4b..473b4c76d6 100644
--- a/src/util/virauthconfig.c
+++ b/src/util/virauthconfig.c
@@ -29,7 +29,7 @@
 #include "viralloc.h"
 
 struct _virAuthConfig {
-    virKeyFilePtr keyfile;
+    GKeyFile *keyfile;
     char *path;
 };
 
@@ -46,10 +46,10 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
 
     auth->path = g_strdup(path);
 
-    if (!(auth->keyfile = virKeyFileNew()))
+    if (!(auth->keyfile = g_key_file_new()))
         goto error;
 
-    if (virKeyFileLoadFile(auth->keyfile, path) < 0)
+    if (!g_key_file_load_from_file(auth->keyfile, path, 0, NULL))
         goto error;
 
     return auth;
@@ -71,10 +71,10 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
 
     auth->path = g_strdup(path);
 
-    if (!(auth->keyfile = virKeyFileNew()))
+    if (!(auth->keyfile = g_key_file_new()))
         goto error;
 
-    if (virKeyFileLoadData(auth->keyfile, path, data, len) < 0)
+    if (!g_key_file_load_from_data(auth->keyfile, data, len, 0, NULL))
         goto error;
 
     return auth;
@@ -90,7 +90,7 @@ void virAuthConfigFree(virAuthConfigPtr auth)
     if (!auth)
         return;
 
-    virKeyFileFree(auth->keyfile);
+    g_key_file_free(auth->keyfile);
     VIR_FREE(auth->path);
     VIR_FREE(auth);
 }
@@ -115,15 +115,15 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
 
     authgroup = g_strdup_printf("auth-%s-%s", service, hostname);
 
-    if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
+    if (!g_key_file_has_group(auth->keyfile, authgroup)) {
        VIR_FREE(authgroup);
        authgroup = g_strdup_printf("auth-%s-%s", service, "default");
     }
 
-    if (!virKeyFileHasGroup(auth->keyfile, authgroup))
+    if (!g_key_file_has_group(auth->keyfile, authgroup))
         return 0;
 
-    if (!(authcred = virKeyFileGetValueString(auth->keyfile, authgroup, "credentials"))) {
+    if (!(authcred = g_key_file_get_string(auth->keyfile, authgroup, "credentials", NULL))) {
         virReportError(VIR_ERR_CONF_SYNTAX,
                        _("Missing item 'credentials' in group '%s' in '%s'"),
                        authgroup, auth->path);
@@ -132,17 +132,14 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
 
     credgroup = g_strdup_printf("credentials-%s", authcred);
 
-    if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
+    if (!g_key_file_has_group(auth->keyfile, credgroup)) {
         virReportError(VIR_ERR_CONF_SYNTAX,
                        _("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
                        authcred, authgroup, auth->path);
         return -1;
     }
 
-    if (!virKeyFileHasValue(auth->keyfile, credgroup, credname))
-        return 0;
-
-    *value = virKeyFileGetValueString(auth->keyfile, credgroup, credname);
+    *value = g_key_file_get_string(auth->keyfile, credgroup, credname, NULL);
 
     return 0;
 }
-- 
2.25.1


Re: [PATCH] util: authconfig: use g_key_file_*
Posted by Michal Prívozník 4 years, 1 month ago
On 20. 3. 2020 18:06, Rafael Fonseca wrote:
> Replace libvirt's virKeyFile by glib's GKeyFile.
> 
> Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
> ---
>  src/util/virauthconfig.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
> index fd846ddd4b..473b4c76d6 100644
> --- a/src/util/virauthconfig.c
> +++ b/src/util/virauthconfig.c
> @@ -29,7 +29,7 @@
>  #include "viralloc.h"
>  
>  struct _virAuthConfig {
> -    virKeyFilePtr keyfile;
> +    GKeyFile *keyfile;
>      char *path;
>  };
>  

There is one difference between virKeyFile format and GKeyFile. Whereas
latter accepts comments only starting with '#', the former also accepts
';' (.ini style comments). However, I don't think anybody sane is using
';' to start a comment, therefore I'm inclined to merge this patch.

If I do, whole src/util/virkeyfile.c module and tests/virkeyfiletest.c
test can be removed too. Do you mind sending v2 where this would be the
first patch and in the second you remove the module, test and
correspodning symbols from src/libvirt_private.syms?

Michal

Re: [PATCH] util: authconfig: use g_key_file_*
Posted by Rafael Fonseca 4 years, 1 month ago
On Mon, Mar 23, 2020 at 1:54 PM Michal Prívozník <mprivozn@redhat.com> wrote:
>
> If I do, whole src/util/virkeyfile.c module and tests/virkeyfiletest.c
> test can be removed too. Do you mind sending v2 where this would be the
> first patch and in the second you remove the module, test and
> correspodning symbols from src/libvirt_private.syms?

Sure, I'll do it.


Att.
-- 
Rafael Fonseca


Re: [PATCH] util: authconfig: use g_key_file_*
Posted by Daniel P. Berrangé 4 years, 1 month ago
On Mon, Mar 23, 2020 at 01:54:07PM +0100, Michal Prívozník wrote:
> On 20. 3. 2020 18:06, Rafael Fonseca wrote:
> > Replace libvirt's virKeyFile by glib's GKeyFile.
> > 
> > Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
> > ---
> >  src/util/virauthconfig.c | 25 +++++++++++--------------
> >  1 file changed, 11 insertions(+), 14 deletions(-)
> > 
> > diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
> > index fd846ddd4b..473b4c76d6 100644
> > --- a/src/util/virauthconfig.c
> > +++ b/src/util/virauthconfig.c
> > @@ -29,7 +29,7 @@
> >  #include "viralloc.h"
> >  
> >  struct _virAuthConfig {
> > -    virKeyFilePtr keyfile;
> > +    GKeyFile *keyfile;
> >      char *path;
> >  };
> >  
> 
> There is one difference between virKeyFile format and GKeyFile. Whereas
> latter accepts comments only starting with '#', the former also accepts
> ';' (.ini style comments). However, I don't think anybody sane is using
> ';' to start a comment, therefore I'm inclined to merge this patch.

Yeah, I'm not concerned by that difference. At the worst, a release
note is needed, and anyone affected can trivially change, not that I
expect anyone will need to.

> If I do, whole src/util/virkeyfile.c module and tests/virkeyfiletest.c
> test can be removed too. Do you mind sending v2 where this would be the
> first patch and in the second you remove the module, test and
> correspodning symbols from src/libvirt_private.syms?

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|