[gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 265/331] Keep macaroon so that progress updates don't prompt all the time
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 265/331] Keep macaroon so that progress updates don't prompt all the time
- Date: Wed, 4 May 2016 14:20:48 +0000 (UTC)
commit 4c1ac0bc500efb2047d3a2bbf2d1bf68735df17b
Author: William Hua <william hua canonical com>
Date: Mon Apr 18 00:32:57 2016 -0400
Keep macaroon so that progress updates don't prompt all the time
src/plugins/gs-plugin-snappy.c | 13 ++++--
src/plugins/gs-ubuntu-snapd.c | 85 +++++++++++++-----------------------
src/plugins/gs-ubuntu-snapd.h | 23 +++++-----
src/plugins/gs-ubuntuone-dialog.c | 7 ++-
4 files changed, 55 insertions(+), 73 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snappy.c b/src/plugins/gs-plugin-snappy.c
index 9d5be37..a5a4ace 100644
--- a/src/plugins/gs-plugin-snappy.c
+++ b/src/plugins/gs-plugin-snappy.c
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
#include <json-glib/json-glib.h>
#include "gs-ubuntu-snapd.h"
+#include "gs-ubuntuone.h"
// snapd API documentation is at https://github.com/ubuntu-core/snappy/blob/master/docs/rest.md
@@ -122,7 +123,7 @@ refine_app (GsPlugin *plugin, GsApp *app, JsonObject *package)
g_autofree gchar *icon_response = NULL;
gsize icon_response_length;
- if (send_snapd_request (TRUE, TRUE, "GET", icon_url, NULL, NULL, NULL, NULL, &icon_response,
&icon_response_length, NULL)) {
+ if (send_snapd_request ("GET", icon_url, NULL, TRUE, NULL, TRUE, NULL, NULL, NULL,
&icon_response, &icon_response_length, NULL)) {
g_autoptr(GdkPixbufLoader) loader = NULL;
loader = gdk_pixbuf_loader_new ();
@@ -190,7 +191,7 @@ get_apps (GsPlugin *plugin, const gchar *sources, gchar **search_terms, GList **
g_string_append (path, fields);
}
g_ptr_array_free (query_fields, TRUE);
- if (!send_snapd_request (TRUE, TRUE, "GET", path->str, NULL, &status_code, &reason_phrase,
&response_type, &response, NULL, error))
+ if (!send_snapd_request ("GET", path->str, NULL, TRUE, NULL, TRUE, &status_code, &reason_phrase,
&response_type, &response, NULL, error))
return FALSE;
if (status_code != SOUP_STATUS_OK) {
@@ -283,7 +284,7 @@ get_app (GsPlugin *plugin, GsApp *app, GError **error)
JsonObject *root, *result;
path = g_strdup_printf ("/v2/snaps/%s", gs_app_get_id (app));
- if (!send_snapd_request (TRUE, TRUE, "GET", path, NULL, &status_code, &reason_phrase, &response_type,
&response, NULL, error))
+ if (!send_snapd_request ("GET", path, NULL, TRUE, NULL, TRUE, &status_code, &reason_phrase,
&response_type, &response, NULL, error))
return FALSE;
if (status_code != SOUP_STATUS_OK) {
@@ -380,10 +381,12 @@ send_package_action (GsPlugin *plugin, GsApp *app, const char *id, const gchar *
const gchar *resource_path;
const gchar *type;
const gchar *change_id;
+ g_autoptr(GVariant) macaroon = NULL;
+ macaroon = gs_ubuntuone_get_macaroon (TRUE, TRUE, NULL);
content = g_strdup_printf ("{\"action\": \"%s\"}", action);
path = g_strdup_printf ("/v2/snaps/%s", id);
- if (!send_snapd_request (TRUE, TRUE, "POST", path, content, &status_code, &reason_phrase,
&response_type, &response, NULL, error))
+ if (!send_snapd_request ("POST", path, content, TRUE, macaroon, TRUE, &status_code, &reason_phrase,
&response_type, &response, NULL, error))
return FALSE;
if (status_code != SOUP_STATUS_ACCEPTED) {
@@ -412,7 +415,7 @@ send_package_action (GsPlugin *plugin, GsApp *app, const char *id, const gchar *
/* Wait for a little bit before polling */
g_usleep (100 * 1000);
- if (!send_snapd_request (TRUE, TRUE, "GET", resource_path, NULL,
+ if (!send_snapd_request ("GET", resource_path, NULL, TRUE, macaroon, TRUE,
&status_code, &status_reason_phrase, &status_response_type,
&status_response, NULL, error)) {
return FALSE;
diff --git a/src/plugins/gs-ubuntu-snapd.c b/src/plugins/gs-ubuntu-snapd.c
index 2e839de..29e2967 100644
--- a/src/plugins/gs-ubuntu-snapd.c
+++ b/src/plugins/gs-ubuntu-snapd.c
@@ -72,18 +72,19 @@ read_from_snapd (GSocket *socket, gchar *buffer, gsize buffer_length, gsize *rea
return TRUE;
}
-static gboolean
-real_send_snapd_request (GVariant *macaroon,
- gboolean retry_after_login,
- const gchar *method,
- const gchar *path,
- const gchar *content,
- guint *status_code,
- gchar **reason_phrase,
- gchar **response_type,
- gchar **response,
- gsize *response_length,
- GError **error)
+gboolean
+send_snapd_request (const gchar *method,
+ const gchar *path,
+ const gchar *content,
+ gboolean authenticate,
+ GVariant *macaroon,
+ gboolean retry_after_login,
+ guint *status_code,
+ gchar **reason_phrase,
+ gchar **response_type,
+ gchar **response,
+ gsize *response_length,
+ GError **error)
{
g_autoptr (GSocket) socket = NULL;
g_autoptr (GString) request = NULL;
@@ -91,6 +92,7 @@ real_send_snapd_request (GVariant *macaroon,
gsize max_data_length = 65535, data_length = 0, header_length;
gchar data[max_data_length + 1], *body = NULL;
g_autoptr (SoupMessageHeaders) headers = NULL;
+ g_autoptr(GVariant) auto_macaroon = NULL;
gsize chunk_length, n_required;
gchar *chunk_start = NULL;
const gchar *root;
@@ -99,6 +101,11 @@ real_send_snapd_request (GVariant *macaroon,
guint code;
gboolean ret;
+ if (macaroon == NULL && authenticate) {
+ auto_macaroon = gs_ubuntuone_get_macaroon (TRUE, FALSE, NULL);
+ macaroon = auto_macaroon;
+ }
+
// NOTE: Would love to use libsoup but it doesn't support unix sockets
// https://bugzilla.gnome.org/show_bug.cgi?id=727563
@@ -175,17 +182,18 @@ real_send_snapd_request (GVariant *macaroon,
return FALSE;
}
- ret = real_send_snapd_request (macaroon,
- FALSE,
- method,
- path,
- content,
- status_code,
- reason_phrase,
- response_type,
- response,
- response_length,
- error);
+ ret = send_snapd_request (method,
+ path,
+ content,
+ TRUE,
+ macaroon,
+ FALSE,
+ status_code,
+ reason_phrase,
+ response_type,
+ response,
+ response_length,
+ error);
g_variant_unref (macaroon);
@@ -253,34 +261,3 @@ real_send_snapd_request (GVariant *macaroon,
return TRUE;
}
-
-gboolean
-send_snapd_request (gboolean authenticate,
- gboolean retry_after_login,
- const gchar *method,
- const gchar *path,
- const gchar *content,
- guint *status_code,
- gchar **reason_phrase,
- gchar **response_type,
- gchar **response,
- gsize *response_length,
- GError **error)
-{
- g_autoptr(GVariant) macaroon = NULL;
-
- if (authenticate)
- macaroon = gs_ubuntuone_get_macaroon (TRUE, FALSE, NULL);
-
- return real_send_snapd_request (macaroon,
- retry_after_login,
- method,
- path,
- content,
- status_code,
- reason_phrase,
- response_type,
- response,
- response_length,
- error);
-}
diff --git a/src/plugins/gs-ubuntu-snapd.h b/src/plugins/gs-ubuntu-snapd.h
index 29d8d9e..34e8b0c 100644
--- a/src/plugins/gs-ubuntu-snapd.h
+++ b/src/plugins/gs-ubuntu-snapd.h
@@ -24,16 +24,17 @@
#include <gio/gio.h>
-gboolean send_snapd_request (gboolean authenticate,
- gboolean retry_after_login,
- const gchar *method,
- const gchar *path,
- const gchar *content,
- guint *status_code,
- gchar **reason_phrase,
- gchar **response_type,
- gchar **response,
- gsize *response_length,
- GError **error);
+gboolean send_snapd_request (const gchar *method,
+ const gchar *path,
+ const gchar *content,
+ gboolean authenticate,
+ GVariant *macaroon,
+ gboolean retry_after_login,
+ guint *status_code,
+ gchar **reason_phrase,
+ gchar **response_type,
+ gchar **response,
+ gsize *response_length,
+ GError **error);
#endif /* __GS_UBUNTU_SNAPD_H__ */
diff --git a/src/plugins/gs-ubuntuone-dialog.c b/src/plugins/gs-ubuntuone-dialog.c
index b806a6b..54d4666 100644
--- a/src/plugins/gs-ubuntuone-dialog.c
+++ b/src/plugins/gs-ubuntuone-dialog.c
@@ -409,11 +409,12 @@ send_login_request (GsUbuntuoneDialog *self)
password);
}
- if (send_snapd_request (FALSE,
- FALSE,
- SOUP_METHOD_POST,
+ if (send_snapd_request (SOUP_METHOD_POST,
"/v2/login",
content,
+ FALSE,
+ NULL,
+ FALSE,
&status_code,
&reason_phrase,
&response_type,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]