[virt-tools-list] [PATCH virt-viewer 2/2] Change collect_credentials() to return a boolean

Fabiano Fidêncio fabiano at fidencio.org
Tue Aug 12 23:48:21 UTC 2014


On Tue, Aug 12, 2014 at 6:10 PM, Jonathon Jongsma <jjongsma at redhat.com>
wrote:

> Instead of returning 0 for success and -1 for failure, change to a
> boolean success value to be more consistent with the rest of the
> virt-viewer code.
> ---
>  src/remote-viewer.c           |  5 +++--
>  src/virt-viewer-auth.c        |  4 ++--
>  src/virt-viewer-auth.h        | 10 +++++-----
>  src/virt-viewer-session-vnc.c | 10 +++++-----
>  4 files changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index 1f2fa0d..e5c97f0 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -707,13 +707,14 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED
> RestProxyAuth *auth,
>      gchar *username = NULL;
>      gchar *password = NULL;
>      VirtViewerWindow *window;
> +    gboolean success = FALSE;
>
>      g_object_get(proxy,
>                   "username", &username,
>                   NULL);
>
>      window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
> -    int ret =
> virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
> +    success =
> virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
>                                                     "oVirt",
>                                                     NULL,
>                                                     &username, &password);
> @@ -726,7 +727,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED
> RestProxyAuth *auth,
>
>      g_free(username);
>      g_free(password);
> -    return (ret == 0);
> +    return success;
>  }
>
>
> diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
> index a796619..556a10b 100644
> --- a/src/virt-viewer-auth.c
> +++ b/src/virt-viewer-auth.c
> @@ -36,7 +36,7 @@
>   * field will be pre-filled with this value. The existing string will be
> freed
>   * before setting the output parameter to the user-entered value.
>   */
> -int
> +gboolean
>  virt_viewer_auth_collect_credentials(GtkWindow *window,
>                                       const char *type,
>                                       const char *address,
> @@ -102,7 +102,7 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
>      gtk_widget_destroy(GTK_WIDGET(dialog));
>      g_object_unref(G_OBJECT(creds));
>
> -    return response == GTK_RESPONSE_OK ? 0 : -1;
> +    return response == GTK_RESPONSE_OK;
>  }
>
>  /*
> diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
> index ad932c5..85e3bbc 100644
> --- a/src/virt-viewer-auth.h
> +++ b/src/virt-viewer-auth.h
> @@ -32,11 +32,11 @@
>  #include "virt-viewer-session.h"
>  #include "virt-viewer-util.h"
>
> -int virt_viewer_auth_collect_credentials(GtkWindow *window,
> -                                         const char *type,
> -                                         const char *address,
> -                                         char **username,
> -                                         char **password);
> +gboolean virt_viewer_auth_collect_credentials(GtkWindow *window,
> +                                              const char *type,
> +                                              const char *address,
> +                                              char **username,
> +                                              char **password);
>
>  #endif
>  /*
> diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
> index e2f90f2..8de39d4 100644
> --- a/src/virt-viewer-session-vnc.c
> +++ b/src/virt-viewer-session-vnc.c
> @@ -294,12 +294,12 @@ virt_viewer_session_vnc_auth_credential(GtkWidget
> *src G_GNUC_UNUSED,
>      }
>
>      if (wantUsername || wantPassword) {
> -        int ret =
> virt_viewer_auth_collect_credentials(self->priv->main_window,
> -                                                       "VNC", NULL,
> -                                                       wantUsername ?
> &username : NULL,
> -                                                       wantPassword ?
> &password : NULL);
> +        gboolean ret =
> virt_viewer_auth_collect_credentials(self->priv->main_window,
> +                                                            "VNC", NULL,
> +                                                            wantUsername
> ? &username : NULL,
> +                                                            wantPassword
> ? &password : NULL);
>
> -        if (ret < 0) {
> +        if (!ret) {
>              vnc_display_close(self->priv->vnc);
>              goto cleanup;
>          }
> --
> 1.9.3
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
>


ACK!
-- 
Fabiano Fidêncio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20140813/86715b3e/attachment.htm>


More information about the virt-tools-list mailing list