[epiphany/carlosgc/libsoup3: 2/2] wip: add support for soup3
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/carlosgc/libsoup3: 2/2] wip: add support for soup3
- Date: Mon, 8 Mar 2021 13:50:12 +0000 (UTC)
commit 74bf881dd935e311ec5aa6de2ab1b98d93a2718a
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Mar 1 15:16:29 2021 +0100
wip: add support for soup3
lib/safe-browsing/ephy-gsb-service.c | 192 +++++++++---
lib/sync/debug/ephy-sync-debug.c | 127 ++++++--
lib/sync/ephy-sync-service.c | 580 ++++++++++++++++++++++++++++++-----
meson.build | 6 +
meson_options.txt | 6 +
src/ephy-suggestion-model.c | 30 +-
tests/ephy-web-view-test.c | 41 ++-
7 files changed, 833 insertions(+), 149 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index 701a361f9..f3c7f0d65 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -51,6 +51,8 @@ struct _EphyGSBService {
gint64 back_off_exit_time;
gint64 back_off_num_fails;
+ GThread *update_thread;
+ GMainLoop *update_loop;
SoupSession *session;
};
@@ -168,11 +170,18 @@ ephy_gsb_service_schedule_update (EphyGSBService *self)
LOG ("Next update scheduled in %ld seconds", interval);
}
-static void
-ephy_gsb_service_update_thread (GTask *task,
- EphyGSBService *self,
- gpointer task_data,
- GCancellable *cancellable)
+static gboolean
+ephy_gsb_service_update_finished_cb (EphyGSBService *self)
+{
+ g_atomic_int_set (&self->is_updating, FALSE);
+ g_signal_emit (self, signals[UPDATE_FINISHED], 0);
+ ephy_gsb_service_schedule_update (self);
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+ephy_gsb_service_update_in_thread (EphyGSBService *self)
{
JsonNode *body_node = NULL;
JsonObject *body_obj;
@@ -181,6 +190,12 @@ ephy_gsb_service_update_thread (GTask *task,
GList *threat_lists = NULL;
char *url = NULL;
char *body;
+ GBytes *response_body = NULL;
+ guint status_code;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+ GError *error = NULL;
+#endif
g_assert (EPHY_IS_GSB_SERVICE (self));
@@ -205,12 +220,30 @@ ephy_gsb_service_update_thread (GTask *task,
body = ephy_gsb_utils_make_list_updates_request (threat_lists);
url = g_strdup_printf ("%sthreatListUpdates:fetch?key=%s", API_PREFIX, self->api_key);
msg = soup_message_new (SOUP_METHOD_POST, url);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new_take (body, strlen (body));
+ soup_message_set_request_body_from_bytes (msg, "application/json", bytes);
+ g_bytes_unref (bytes);
+ response_body = soup_session_send_and_read (self->session, msg, NULL, &error);
+ if (!response_body) {
+ LOG ("Cannot update threat lists: %s", error->message);
+ g_error_free (error);
+ ephy_gsb_service_update_back_off_mode (self);
+ self->next_list_updates_time = self->back_off_exit_time;
+ goto out;
+ }
+
+ status_code = soup_message_get_status (msg);
+#else
soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, body, strlen (body));
soup_session_send_message (self->session, msg);
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
/* Handle unsuccessful responses. */
- if (msg->status_code != 200) {
- LOG ("Cannot update threat lists, got: %u, %s", msg->status_code, msg->response_body->data);
+ if (status_code != 200) {
+ LOG ("Cannot update threat lists, got: %u, %s", status_code, (const char *)g_bytes_get_data
(response_body, NULL));
ephy_gsb_service_update_back_off_mode (self);
self->next_list_updates_time = self->back_off_exit_time;
goto out;
@@ -219,7 +252,7 @@ ephy_gsb_service_update_thread (GTask *task,
/* Successful response, reset back-off mode. */
ephy_gsb_service_reset_back_off_mode (self);
- body_node = json_from_string (msg->response_body->data, NULL);
+ body_node = json_from_string (g_bytes_get_data (response_body, NULL), NULL);
if (!body_node || !JSON_NODE_HOLDS_OBJECT (body_node)) {
g_warning ("Response is not a valid JSON object");
goto out;
@@ -294,6 +327,7 @@ ephy_gsb_service_update_thread (GTask *task,
out:
g_free (url);
+ g_clear_pointer (&response_body, g_bytes_unref);
if (msg)
g_object_unref (msg);
if (body_node)
@@ -302,33 +336,46 @@ out:
ephy_gsb_storage_set_metadata (self->storage, "next_list_updates_time", self->next_list_updates_time);
- g_object_unref (self);
+ g_idle_add_full (G_PRIORITY_DEFAULT,
+ (GSourceFunc)ephy_gsb_service_update_finished_cb,
+ g_object_ref (self),
+ (GDestroyNotify)g_object_unref);
+
+ return G_SOURCE_REMOVE;
}
-static void
-ephy_gsb_service_update_finished_cb (EphyGSBService *self,
- GAsyncResult *result,
- gpointer user_data)
+static gpointer
+run_update_thread (EphyGSBService *self)
{
- g_atomic_int_set (&self->is_updating, FALSE);
- g_signal_emit (self, signals[UPDATE_FINISHED], 0);
- ephy_gsb_service_schedule_update (self);
+ GMainContext *context;
+
+ context = g_main_loop_get_context (self->update_loop);
+ g_main_context_push_thread_default (context);
+ self->session = soup_session_new_with_options ("user-agent", ephy_user_agent_get (), NULL);
+ g_main_loop_run (self->update_loop);
+ g_object_unref (self->session);
+ g_main_context_pop_thread_default (context);
+
+ return NULL;
}
static gboolean
ephy_gsb_service_update (EphyGSBService *self)
{
- GTask *task;
+ GSource *source;
g_assert (EPHY_IS_GSB_SERVICE (self));
g_assert (ephy_gsb_storage_is_operable (self->storage));
g_atomic_int_set (&self->is_updating, TRUE);
- task = g_task_new (g_object_ref (self), NULL,
- (GAsyncReadyCallback)ephy_gsb_service_update_finished_cb,
- NULL);
- g_task_run_in_thread (task, (GTaskThreadFunc)ephy_gsb_service_update_thread);
- g_object_unref (task);
+ source = g_timeout_source_new (0);
+ g_source_set_name (source, "[epiphany] gsb_service_update_in_thread");
+ g_source_set_callback (source,
+ (GSourceFunc)ephy_gsb_service_update_in_thread,
+ g_object_ref (self),
+ (GDestroyNotify)g_object_unref);
+ g_source_attach (source, g_main_loop_get_context (self->update_loop));
+ g_source_unref (source);
return G_SOURCE_REMOVE;
}
@@ -383,6 +430,9 @@ ephy_gsb_service_finalize (GObject *object)
g_free (self->api_key);
+ g_thread_join (self->update_thread);
+ g_main_loop_unref (self->update_loop);
+
G_OBJECT_CLASS (ephy_gsb_service_parent_class)->finalize (object);
}
@@ -392,10 +442,12 @@ ephy_gsb_service_dispose (GObject *object)
EphyGSBService *self = EPHY_GSB_SERVICE (object);
g_clear_object (&self->storage);
- g_clear_object (&self->session);
g_clear_handle_id (&self->source_id, g_source_remove);
+ if (g_main_loop_is_running (self->update_loop))
+ g_main_loop_quit (self->update_loop);
+
G_OBJECT_CLASS (ephy_gsb_service_parent_class)->dispose (object);
}
@@ -441,8 +493,11 @@ ephy_gsb_service_constructed (GObject *object)
static void
ephy_gsb_service_init (EphyGSBService *self)
{
- self->session = soup_session_new ();
- g_object_set (self->session, "user-agent", ephy_user_agent_get (), NULL);
+ GMainContext *context = g_main_context_new ();
+
+ self->update_loop = g_main_loop_new (context, FALSE);
+ self->update_thread = g_thread_new ("EphyGSBService", (GThreadFunc)run_update_thread, self);
+ g_object_unref (context);
}
static void
@@ -501,10 +556,18 @@ ephy_gsb_service_new (const char *api_key,
#endif
}
-static void
-ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
- GList *prefixes)
+typedef struct {
+ EphyGSBService *self;
+ GList *prefixes;
+ GMutex mutex;
+ GCond condition;
+
+} UpdateFullHashesData;
+
+static gboolean
+ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
{
+ EphyGSBService *self = data->self;
SoupMessage *msg;
GList *threat_lists;
JsonNode *body_node;
@@ -514,36 +577,62 @@ ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
char *url;
char *body;
double duration;
+ GBytes *response_body = NULL;
+ guint status_code;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+ GError *error = NULL;
+#endif
g_assert (EPHY_IS_GSB_SERVICE (self));
g_assert (ephy_gsb_storage_is_operable (self->storage));
- g_assert (prefixes);
+ g_assert (data->prefixes);
+
+ g_mutex_lock (&data->mutex);
if (self->next_full_hashes_time > CURRENT_TIME) {
LOG ("Cannot send fullHashes:find request. Requests are restricted for %ld seconds",
self->next_full_hashes_time - CURRENT_TIME);
- return;
+ goto out;
}
if (ephy_gsb_service_is_back_off_mode (self)) {
LOG ("Cannot send fullHashes:find request. Back-off mode is enabled for %ld seconds",
self->back_off_exit_time - CURRENT_TIME);
- return;
+ goto out;
}
threat_lists = ephy_gsb_storage_get_threat_lists (self->storage);
if (!threat_lists)
- return;
+ goto out;
- body = ephy_gsb_utils_make_full_hashes_request (threat_lists, prefixes);
+ body = ephy_gsb_utils_make_full_hashes_request (threat_lists, data->prefixes);
url = g_strdup_printf ("%sfullHashes:find?key=%s", API_PREFIX, self->api_key);
msg = soup_message_new (SOUP_METHOD_POST, url);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new_take (body, strlen (body));
+ soup_message_set_request_body_from_bytes (msg, "application/json", bytes);
+ g_bytes_unref (bytes);
+ response_body = soup_session_send_and_read (self->session, msg, NULL, &error);
+ if (!response_body) {
+ LOG ("Cannot update full hashes: %s", error->message);
+ g_error_free (error);
+ ephy_gsb_service_update_back_off_mode (self);
+ self->next_list_updates_time = self->back_off_exit_time;
+ goto out;
+ }
+
+ status_code = soup_message_get_status (msg);
+#else
soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, body, strlen (body));
soup_session_send_message (self->session, msg);
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
/* Handle unsuccessful responses. */
- if (msg->status_code != 200) {
- LOG ("Cannot update full hashes, got: %u, %s", msg->status_code, msg->response_body->data);
+ if (status_code != 200) {
+ LOG ("Cannot update full hashes, got: %u, %s", status_code, (const char *)g_bytes_get_data
(response_body, NULL));
ephy_gsb_service_update_back_off_mode (self);
goto out;
}
@@ -551,7 +640,7 @@ ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
/* Successful response, reset back-off mode. */
ephy_gsb_service_reset_back_off_mode (self);
- body_node = json_from_string (msg->response_body->data, NULL);
+ body_node = json_from_string (g_bytes_get_data (response_body, NULL), NULL);
if (!body_node || !JSON_NODE_HOLDS_OBJECT (body_node)) {
g_warning ("Response is not a valid JSON object");
goto out;
@@ -592,7 +681,7 @@ ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
duration_str = json_object_get_string_member (body_obj, "negativeCacheDuration");
/* g_ascii_strtod() ignores trailing characters, i.e. 's' character. */
duration = g_ascii_strtod (duration_str, NULL);
- for (GList *l = prefixes; l && l->data; l = l->next)
+ for (GList *l = data->prefixes; l && l->data; l = l->next)
ephy_gsb_storage_update_hash_prefix_expiration (self->storage, l->data, floor (duration));
/* Handle minimum wait duration. */
@@ -607,8 +696,35 @@ ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
json_node_unref (body_node);
out:
g_free (url);
+ g_clear_pointer (&response_body, g_bytes_unref);
g_list_free_full (threat_lists, (GDestroyNotify)ephy_gsb_threat_list_free);
- g_object_unref (msg);
+ g_clear_object (&msg);
+
+ g_cond_signal (&data->condition);
+ g_mutex_unlock (&data->mutex);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
+ GList *prefixes)
+{
+ UpdateFullHashesData data = { self, prefixes, { }, { } };
+ GSource *source;
+
+ g_mutex_lock (&data.mutex);
+
+ source = g_timeout_source_new (0);
+ g_source_set_name (source, "[epiphany] gsb_service_update_full_hashes_in_thread");
+ g_source_set_callback (source,
+ (GSourceFunc)ephy_gsb_service_update_full_hashes_in_thread,
+ &data, NULL);
+ g_source_attach (source, g_main_loop_get_context (self->update_loop));
+ g_source_unref (source);
+
+ g_cond_wait (&data.condition, &data.mutex);
+ g_mutex_unlock (&data.mutex);
}
static void
diff --git a/lib/sync/debug/ephy-sync-debug.c b/lib/sync/debug/ephy-sync-debug.c
index 2eb266770..43edf5dc9 100644
--- a/lib/sync/debug/ephy-sync-debug.c
+++ b/lib/sync/debug/ephy-sync-debug.c
@@ -225,6 +225,7 @@ ephy_sync_debug_prepare_soup_message (const char *url,
SyncCryptoHawkOptions *options = NULL;
SyncCryptoHawkHeader *header;
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
const char *content_type = "application/json";
g_assert (url);
@@ -236,18 +237,34 @@ ephy_sync_debug_prepare_soup_message (const char *url,
msg = soup_message_new (method, url);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ request_headers = soup_message_get_request_headers (msg);
+#else
+ request_headers = msg->request_headers;
+#endif
+
if (body) {
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+#endif
+
options = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, body, NULL);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new (body, strlen (body));
+ soup_message_set_request_body_from_bytes (msg, content_type, bytes);
+ g_bytes_unref (bytes);
+#else
soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY, body, strlen (body));
+#endif
}
if (!g_strcmp0 (method, "PUT") || !g_strcmp0 (method, "POST"))
- soup_message_headers_append (msg->request_headers, "content-type", content_type);
+ soup_message_headers_append (request_headers, "content-type", content_type);
header = ephy_sync_crypto_hawk_header_new (url, method, hawk_id,
hawk_key, hawk_key_len, options);
- soup_message_headers_append (msg->request_headers, "authorization", header->header);
+ soup_message_headers_append (request_headers, "authorization", header->header);
ephy_sync_crypto_hawk_header_free (header);
if (options)
@@ -279,6 +296,7 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
char *e;
guint status_code;
g_autofree char *accounts_server = NULL;
+ GBytes *response_body = NULL;
g_assert (session_token);
g_assert (keypair);
@@ -304,14 +322,26 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
msg = ephy_sync_debug_prepare_soup_message (url, "POST", body,
id_hex, key, 32);
session = soup_session_new ();
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_body = soup_session_send_and_read (session, msg, NULL, &error);
+ if (!response_body) {
+ LOG ("Failed to get signed certificate: %s", error->message);
+ g_error_free (error);
+ goto free_session;
+ }
+
+ status_code = soup_message_get_status (msg);
+#else
status_code = soup_session_send_message (session, msg);
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
if (status_code != 200) {
- LOG ("Failed to get signed certificate: %s", msg->response_body->data);
+ LOG ("Failed to get signed certificate: %s", (const char *)g_bytes_get_data (response_body, NULL));
goto free_session;
}
- response = json_from_string (msg->response_body->data, &error);
+ response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
g_error_free (error);
@@ -325,6 +355,7 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
free_session:
g_object_unref (session);
g_object_unref (msg);
+ g_clear_pointer (&response_body, g_bytes_unref);
g_free (url);
g_free (body);
json_node_unref (node);
@@ -360,6 +391,8 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
guint8 *kb;
const char *session_token;
guint status_code;
+ SoupMessageHeaders *request_headers;
+ GBytes *response_body = NULL;
gboolean success = FALSE;
g_autofree char *token_server = NULL;
@@ -381,17 +414,34 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
client_state = g_strndup (hashed_kb, 32);
authorization = g_strdup_printf ("BrowserID %s", assertion);
msg = soup_message_new ("GET", token_server);
- soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
- soup_message_headers_append (msg->request_headers, "authorization", authorization);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ request_headers = soup_message_get_request_headers (msg);
+#else
+ request_headers = msg->request_headers;
+#endif
+ soup_message_headers_append (request_headers, "X-Client-State", client_state);
+ soup_message_headers_append (request_headers, "authorization", authorization);
session = soup_session_new ();
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_body = soup_session_send_and_read (session, msg, NULL, &error);
+ if (!response_body) {
+ LOG ("Failed to get storage credentials: %s", error->message);
+ g_error_free (error);
+ goto free_session;
+ }
+
+ status_code = soup_message_get_status (msg);
+#else
status_code = soup_session_send_message (session, msg);
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
if (status_code != 200) {
- LOG ("Failed to get storage credentials: %s", msg->response_body->data);
+ LOG ("Failed to get storage credentials: %s", (const char *)g_bytes_get_data (response_body, NULL));
goto free_session;
}
- response = json_from_string (msg->response_body->data, &error);
+ response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
g_error_free (error);
@@ -408,6 +458,7 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
free_session:
g_object_unref (session);
g_object_unref (msg);
+ g_clear_pointer (&response_body, g_bytes_unref);
g_free (authorization);
g_free (client_state);
g_free (hashed_kb);
@@ -435,6 +486,10 @@ ephy_sync_debug_send_request (const char *endpoint,
char *storage_key;
char *url;
guint status_code;
+ GBytes *response_body = NULL;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GError *error = NULL;
+#endif
g_assert (endpoint);
g_assert (method);
@@ -453,12 +508,22 @@ ephy_sync_debug_send_request (const char *endpoint,
(const guint8 *)storage_key,
strlen (storage_key));
session = soup_session_new ();
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_body = soup_session_send_and_read (session, msg, NULL, &error);
+ status_code = soup_message_get_status (msg);
+#else
status_code = soup_session_send_message (session, msg);
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
- if (status_code == 200)
- response = g_strdup (msg->response_body->data);
- else
- LOG ("Failed to send storage request: %s", msg->response_body->data);
+ if (response_body) {
+ if (status_code == 200)
+ response = g_strdup (g_bytes_get_data (response_body, NULL));
+ else
+ LOG ("Failed to send storage request: %s", (const char *)g_bytes_get_data (response_body, NULL));
+ g_bytes_unref (response_body);
+ }
g_free (url);
g_free (storage_endpoint);
@@ -603,7 +668,7 @@ ephy_sync_debug_view_record (const char *collection,
g_assert (collection);
g_assert (id);
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
response = ephy_sync_debug_send_request (endpoint, "GET", NULL);
@@ -671,7 +736,7 @@ ephy_sync_debug_upload_record (const char *collection,
if (!bundle)
return;
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
body = ephy_sync_debug_make_upload_body (id, record, bundle);
response = ephy_sync_debug_send_request (endpoint, "PUT", body);
@@ -724,7 +789,7 @@ ephy_sync_debug_delete_collection (const char *collection)
array = json_node_get_array (node);
for (guint i = 0; i < json_array_get_length (array); i++) {
const char *id = json_array_get_string_element (array, i);
- char *id_safe = soup_uri_encode (id, NULL);
+ char *id_safe = g_uri_escape_string (id, NULL, TRUE);
char *body = ephy_sync_debug_make_delete_body (id, bundle);
char *to = g_strdup_printf ("storage/%s/%s", collection, id_safe);
char *resp = ephy_sync_debug_send_request (to, "PUT", body);
@@ -772,7 +837,7 @@ ephy_sync_debug_delete_record (const char *collection,
if (!bundle)
return;
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
body = ephy_sync_debug_make_delete_body (id, bundle);
response = ephy_sync_debug_send_request (endpoint, "PUT", body);
@@ -839,7 +904,7 @@ ephy_sync_debug_erase_record (const char *collection,
g_assert (collection);
g_assert (id);
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
response = ephy_sync_debug_send_request (endpoint, "DELETE", NULL);
@@ -1029,6 +1094,7 @@ ephy_sync_debug_view_connected_devices (void)
char *url;
const char *session_token;
g_autofree char *accounts_server = NULL;
+ GBytes *response_body = NULL;
secrets = ephy_sync_debug_load_secrets ();
if (!secrets)
@@ -1042,12 +1108,19 @@ ephy_sync_debug_view_connected_devices (void)
id_hex = ephy_sync_utils_encode_hex (id, 32);
msg = ephy_sync_debug_prepare_soup_message (url, "GET", NULL, id_hex, key, 32);
session = soup_session_new ();
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_body = soup_session_send_and_read (session, msg, NULL, NULL);
+#else
soup_session_send_message (session, msg);
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
- LOG ("%s", msg->response_body->data);
+ if (response_body)
+ LOG ("%s", (const char *)g_bytes_get_data (response_body, NULL));
g_object_unref (session);
g_object_unref (msg);
+ g_clear_pointer (&response_body, g_bytes_unref);
g_free (id_hex);
g_free (url);
g_free (id);
@@ -1083,6 +1156,7 @@ ephy_sync_debug_get_current_device (void)
const char *session_token;
guint status_code;
g_autofree char *accounts_server = NULL;
+ GBytes *response_body = NULL;
secrets = ephy_sync_debug_load_secrets ();
if (!secrets)
@@ -1096,14 +1170,26 @@ ephy_sync_debug_get_current_device (void)
id_hex = ephy_sync_utils_encode_hex (id, 32);
msg = ephy_sync_debug_prepare_soup_message (url, "GET", NULL, id_hex, key, 32);
session = soup_session_new ();
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_body = soup_session_send_and_read (session, msg, NULL, &error);
+ if (!response_body) {
+ LOG ("Failed to GET account devices: %s", error->message);
+ g_error_free (error);
+ goto free_session;
+ }
+
+ status_code = soup_message_get_status (msg);
+#else
status_code = soup_session_send_message (session, msg);
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
if (status_code != 200) {
- LOG ("Failed to GET account devices: %s", msg->response_body->data);
+ LOG ("Failed to GET account devices: %s", (const char *)g_bytes_get_data (response_body, NULL));
goto free_session;
}
- response = json_from_string (msg->response_body->data, &error);
+ response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
g_error_free (error);
@@ -1124,6 +1210,7 @@ ephy_sync_debug_get_current_device (void)
free_session:
g_object_unref (session);
g_object_unref (msg);
+ g_clear_pointer (&response_body, g_bytes_unref);
g_free (id_hex);
g_free (url);
g_free (id);
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index a9eec409d..8fb40d675 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -97,6 +97,12 @@ enum {
static guint signals[LAST_SIGNAL];
+#if SOUP_CHECK_VERSION (2, 99, 1)
+typedef void (*SoupSessionCallback) (SoupSession *session,
+ SoupMessage *msg,
+ gpointer user_data);
+#endif
+
typedef struct {
char *endpoint;
char *method;
@@ -179,6 +185,72 @@ storage_request_async_data_free (StorageRequestAsyncData *data)
g_free (data);
}
+#if SOUP_CHECK_VERSION (2, 99, 1)
+typedef struct {
+ SoupSessionCallback callback;
+ gpointer user_data;
+} SendAndReadAsyncData;
+
+static SendAndReadAsyncData *
+send_and_read_async_data_new (SoupSessionCallback callback,
+ gpointer user_data)
+{
+ SendAndReadAsyncData *data;
+
+ data = g_new (SendAndReadAsyncData, 1);
+ data->callback = callback;
+ data->user_data = user_data;
+
+ return data;
+}
+
+static void
+send_and_read_async_ready_cb (SoupSession *session,
+ GAsyncResult *result,
+ SendAndReadAsyncData *data)
+{
+ GBytes *bytes;
+ SoupMessage *msg;
+ GError *error = NULL;
+
+ bytes = soup_session_send_and_read_finish (session, result, &error);
+ if (!bytes) {
+ g_warning ("Failed to send request: %s", error->message);
+ g_error_free (error);
+ }
+
+ msg = soup_session_get_async_result_message (session, result);
+ g_object_set_data_full (G_OBJECT (msg),
+ "ephy-request-body", bytes ? bytes : g_bytes_new (NULL, 0),
+ (GDestroyNotify)g_bytes_unref);
+ data->callback (session, msg, data->user_data);
+ g_free (data);
+}
+
+static void
+storage_request_async_ready_cb (SoupSession *session,
+ GAsyncResult *result,
+ StorageRequestAsyncData *data)
+{
+ GBytes *bytes;
+ SoupMessage *msg;
+ GError *error = NULL;
+
+ bytes = soup_session_send_and_read_finish (session, result, &error);
+ if (!bytes) {
+ g_warning ("Failed to send storage request: %s", error->message);
+ g_error_free (error);
+ }
+
+ msg = soup_session_get_async_result_message (session, result);
+ g_object_set_data_full (G_OBJECT (msg),
+ "ephy-request-body", bytes ? bytes : g_bytes_new (NULL, 0),
+ (GDestroyNotify)g_bytes_unref);
+ data->callback (session, msg, data->user_data);
+ storage_request_async_data_free (data);
+}
+#endif
+
static SignInAsyncData *
sign_in_async_data_new (EphySyncService *service,
const char *email,
@@ -463,9 +535,13 @@ ephy_sync_service_fxa_hawk_post (EphySyncService *self,
SyncCryptoHawkOptions *options;
SyncCryptoHawkHeader *header;
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
char *url;
const char *content_type = "application/json; charset=utf-8";
g_autofree char *accounts_server = NULL;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+#endif
g_assert (EPHY_IS_SYNC_SERVICE (self));
g_assert (endpoint);
@@ -476,16 +552,30 @@ ephy_sync_service_fxa_hawk_post (EphySyncService *self,
accounts_server = ephy_sync_utils_get_accounts_server ();
url = g_strdup_printf ("%s/%s", accounts_server, endpoint);
msg = soup_message_new (SOUP_METHOD_POST, url);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new (request_body, strlen (request_body));
+ soup_message_set_request_body_from_bytes (msg, content_type, bytes);
+ g_bytes_unref (bytes);
+ request_headers = soup_message_get_request_headers (msg);
+#else
soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
request_body, strlen (request_body));
+ request_headers = msg->request_headers;
+#endif
options = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, request_body,
NULL);
header = ephy_sync_crypto_hawk_header_new (url, "POST", id, key, key_len, options);
- soup_message_headers_append (msg->request_headers, "authorization", header->header);
- soup_message_headers_append (msg->request_headers, "content-type", content_type);
+ soup_message_headers_append (request_headers, "authorization", header->header);
+ soup_message_headers_append (request_headers, "content-type", content_type);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)send_and_read_async_ready_cb,
+ send_and_read_async_data_new (callback, user_data));
+#else
soup_session_queue_message (self->session, msg, callback, user_data);
+#endif
g_free (url);
ephy_sync_crypto_hawk_options_free (options);
@@ -503,6 +593,7 @@ ephy_sync_service_fxa_hawk_get (EphySyncService *self,
{
SyncCryptoHawkHeader *header;
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
char *url;
g_autofree char *accounts_server = NULL;
@@ -515,8 +606,19 @@ ephy_sync_service_fxa_hawk_get (EphySyncService *self,
url = g_strdup_printf ("%s/%s", accounts_server, endpoint);
msg = soup_message_new (SOUP_METHOD_GET, url);
header = ephy_sync_crypto_hawk_header_new (url, "GET", id, key, key_len, NULL);
- soup_message_headers_append (msg->request_headers, "authorization", header->header);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ request_headers = soup_message_get_request_headers (msg);
+#else
+ request_headers = msg->request_headers;
+#endif
+ soup_message_headers_append (request_headers, "authorization", header->header);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)send_and_read_async_ready_cb,
+ send_and_read_async_data_new (callback, user_data));
+#else
soup_session_queue_message (self->session, msg, callback, user_data);
+#endif
g_free (url);
ephy_sync_crypto_hawk_header_free (header);
@@ -529,6 +631,7 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
SyncCryptoHawkOptions *options = NULL;
SyncCryptoHawkHeader *header;
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
char *url;
char *if_modified_since = NULL;
char *if_unmodified_since = NULL;
@@ -541,24 +644,40 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
msg = soup_message_new (data->method, url);
if (data->request_body) {
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+#endif
options = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, data->request_body,
NULL);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new (data->request_body, strlen (data->request_body));
+ soup_message_set_request_body_from_bytes (msg, content_type, bytes);
+ g_bytes_unref (bytes);
+#else
soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
data->request_body, strlen (data->request_body));
+#endif
}
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ request_headers = soup_message_get_request_headers (msg);
+#else
+ request_headers = msg->request_headers;
+#endif
+
+
if (!g_strcmp0 (data->method, SOUP_METHOD_PUT) || !g_strcmp0 (data->method, SOUP_METHOD_POST))
- soup_message_headers_append (msg->request_headers, "content-type", content_type);
+ soup_message_headers_append (request_headers, "content-type", content_type);
if (data->modified_since >= 0) {
if_modified_since = g_strdup_printf ("%" PRId64, data->modified_since);
- soup_message_headers_append (msg->request_headers, "X-If-Modified-Since", if_modified_since);
+ soup_message_headers_append (request_headers, "X-If-Modified-Since", if_modified_since);
}
if (data->unmodified_since >= 0) {
if_unmodified_since = g_strdup_printf ("%" PRId64, data->unmodified_since);
- soup_message_headers_append (msg->request_headers, "X-If-Unmodified-Since", if_unmodified_since);
+ soup_message_headers_append (request_headers, "X-If-Unmodified-Since", if_unmodified_since);
}
header = ephy_sync_crypto_hawk_header_new (url, data->method,
@@ -566,8 +685,15 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
(guint8 *)self->storage_credentials_key,
strlen (self->storage_credentials_key),
options);
- soup_message_headers_append (msg->request_headers, "authorization", header->header);
+ soup_message_headers_append (request_headers, "authorization", header->header);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)storage_request_async_ready_cb,
+ data);
+#else
soup_session_queue_message (self->session, msg, data->callback, data->user_data);
+ storage_request_async_data_free (data);
+#endif
g_free (url);
g_free (if_modified_since);
@@ -575,7 +701,6 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
ephy_sync_crypto_hawk_header_free (header);
if (options)
ephy_sync_crypto_hawk_options_free (options);
- storage_request_async_data_free (data);
}
static void
@@ -731,14 +856,49 @@ destroy_session_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to destroy session. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
} else {
LOG ("Successfully destroyed session");
}
}
+#if SOUP_CHECK_VERSION (2, 99, 1)
+static void
+destroy_session_send_and_read_ready_cb (SoupSession *session,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GBytes *bytes;
+ SoupMessage *msg;
+ GError *error = NULL;
+
+ bytes = soup_session_send_and_read_finish (session, result, &error);
+ if (!bytes) {
+ g_warning ("Failed to send request: %s", error->message);
+ g_error_free (error);
+ }
+
+ msg = soup_session_get_async_result_message (session, result);
+ g_object_set_data_full (G_OBJECT (msg),
+ "ephy-request-body", bytes ? bytes : g_bytes_new (NULL, 0),
+ (GDestroyNotify)g_bytes_unref);
+ destroy_session_cb (session, msg, user_data);
+}
+#endif
+
static void
ephy_sync_service_destroy_session (EphySyncService *self,
const char *session_token)
@@ -746,6 +906,7 @@ ephy_sync_service_destroy_session (EphySyncService *self,
SyncCryptoHawkOptions *options;
SyncCryptoHawkHeader *header;
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
guint8 *token_id;
guint8 *req_hmac_key;
guint8 *tmp;
@@ -754,6 +915,9 @@ ephy_sync_service_destroy_session (EphySyncService *self,
const char *content_type = "application/json; charset=utf-8";
const char *request_body = "{}";
g_autofree char *accounts_server = NULL;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ GBytes *bytes;
+#endif
g_assert (EPHY_IS_SYNC_SERVICE (self));
if (!session_token)
@@ -768,16 +932,30 @@ ephy_sync_service_destroy_session (EphySyncService *self,
token_id_hex = ephy_sync_utils_encode_hex (token_id, 32);
msg = soup_message_new (SOUP_METHOD_POST, url);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ bytes = g_bytes_new_static (request_body, strlen (request_body));
+ soup_message_set_request_body_from_bytes (msg, content_type, bytes);
+ g_bytes_unref (bytes);
+ request_headers = soup_message_get_request_headers (msg);
+#else
soup_message_set_request (msg, content_type, SOUP_MEMORY_STATIC,
request_body, strlen (request_body));
+ request_headers = msg->request_headers;
+#endif
options = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, request_body,
NULL);
header = ephy_sync_crypto_hawk_header_new (url, "POST", token_id_hex,
req_hmac_key, 32, options);
- soup_message_headers_append (msg->request_headers, "authorization", header->header);
- soup_message_headers_append (msg->request_headers, "content-type", content_type);
+ soup_message_headers_append (request_headers, "authorization", header->header);
+ soup_message_headers_append (request_headers, "content-type", content_type);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)destroy_session_send_and_read_ready_cb,
+ NULL);
+#else
soup_session_queue_message (self->session, msg, destroy_session_cb, NULL);
+#endif
g_free (token_id_hex);
g_free (token_id);
@@ -823,13 +1001,23 @@ get_storage_credentials_cb (SoupSession *session,
const char *message;
const char *suggestion;
int duration;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to obtain storage credentials. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out_error;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -876,10 +1064,35 @@ out:
g_error_free (error);
}
+#if SOUP_CHECK_VERSION (2, 99, 1)
+static void
+get_storage_credentials_ready_cb (SoupSession *session,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GBytes *bytes;
+ SoupMessage *msg;
+ GError *error = NULL;
+
+ bytes = soup_session_send_and_read_finish (session, result, &error);
+ if (!bytes) {
+ g_warning ("Failed to send store credentials request: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ msg = soup_session_get_async_result_message (session, result);
+ g_object_set_data_full (G_OBJECT (msg),
+ "ephy-request-body", bytes ? bytes : g_bytes_new (NULL, 0),
+ (GDestroyNotify)g_bytes_unref);
+ get_storage_credentials_cb (session, msg, user_data);
+}
+#endif
+
static void
ephy_sync_service_trade_browserid_assertion (EphySyncService *self)
{
SoupMessage *msg;
+ SoupMessageHeaders *request_headers;
guint8 *kb;
char *hashed_kb;
char *client_state;
@@ -902,12 +1115,23 @@ ephy_sync_service_trade_browserid_assertion (EphySyncService *self)
authorization = g_strdup_printf ("BrowserID %s", assertion);
msg = soup_message_new (SOUP_METHOD_GET, token_server);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ request_headers = soup_message_get_request_headers (msg);
+#else
+ request_headers = msg->request_headers;
+#endif
/* We need to add the X-Client-State header so that the Token Server will
* recognize accounts that were previously used to sync Firefox data too.
*/
- soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
- soup_message_headers_append (msg->request_headers, "authorization", authorization);
+ soup_message_headers_append (request_headers, "X-Client-State", client_state);
+ soup_message_headers_append (request_headers, "authorization", authorization);
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)get_storage_credentials_ready_cb,
+ self);
+#else
soup_session_queue_message (self->session, msg, get_storage_credentials_cb, self);
+#endif
g_free (kb);
g_free (hashed_kb);
@@ -929,8 +1153,18 @@ get_signed_certificate_cb (SoupSession *session,
const char *suggestion = NULL;
const char *message = NULL;
const char *certificate = NULL;
-
- node = json_from_string (msg->response_body->data, &error);
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -941,7 +1175,7 @@ get_signed_certificate_cb (SoupSession *session,
goto out_error;
}
- if (msg->status_code == 200) {
+ if (status_code == 200) {
certificate = json_object_get_string_member (json, "cert");
if (!certificate) {
g_warning ("JSON object has missing or invalid 'cert' member");
@@ -971,7 +1205,7 @@ get_signed_certificate_cb (SoupSession *session,
}
g_warning ("Failed to sign certificate. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
out_error:
message = message ? message : _("Failed to obtain signed certificate.");
@@ -990,6 +1224,7 @@ out_no_error:
json_node_unref (node);
if (error)
g_error_free (error);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1100,12 +1335,25 @@ delete_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- if (msg->status_code == 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code == 200) {
LOG ("Successfully deleted from server");
} else {
g_warning ("Failed to delete object. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
}
+
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1138,7 +1386,7 @@ ephy_sync_service_delete_synchronizable (EphySyncService *self,
/* Firefox uses UUIDs with curly braces as IDs for saved passwords records.
* Curly braces are unsafe characters in URLs so they must be encoded.
*/
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
node = json_node_new (JSON_NODE_OBJECT);
@@ -1180,13 +1428,23 @@ download_synchronizable_cb (SoupSession *session,
GType type;
const char *collection;
gboolean is_deleted;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to download object. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON");
goto out;
@@ -1220,6 +1478,7 @@ out:
g_error_free (error);
if (bundle)
ephy_sync_crypto_key_bundle_free (bundle);
+ g_clear_pointer (&response_body, g_bytes_unref);
sync_async_data_free (data);
}
@@ -1244,7 +1503,7 @@ ephy_sync_service_download_synchronizable (EphySyncService *self,
/* Firefox uses UUIDs with curly braces as IDs for saved passwords records.
* Curly braces are unsafe characters in URLs so they must be encoded.
*/
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
data = sync_async_data_new (self, manager, synchronizable);
@@ -1264,23 +1523,34 @@ upload_synchronizable_cb (SoupSession *session,
{
SyncAsyncData *data = (SyncAsyncData *)user_data;
gint64 time_modified;
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
/* Code 412 means that there is a more recent version on the server.
* Download it.
*/
- if (msg->status_code == 412) {
+ if (status_code == 412) {
LOG ("Found a newer version of the object on the server, downloading it...");
ephy_sync_service_download_synchronizable (data->service, data->manager, data->synchronizable);
- } else if (msg->status_code == 200) {
+ } else if (status_code == 200) {
LOG ("Successfully uploaded to server");
- time_modified = ceil (g_ascii_strtod (msg->response_body->data, NULL));
+ time_modified = ceil (g_ascii_strtod (g_bytes_get_data (response_body, NULL), NULL));
ephy_synchronizable_set_server_time_modified (data->synchronizable, time_modified);
ephy_synchronizable_manager_save (data->manager, data->synchronizable);
} else {
g_warning ("Failed to upload object. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
}
+ g_clear_pointer (&response_body, g_bytes_unref);
sync_async_data_free (data);
}
@@ -1315,7 +1585,7 @@ ephy_sync_service_upload_synchronizable (EphySyncService *self,
/* Firefox uses UUIDs with curly braces as IDs for saved passwords records.
* Curly braces are unsafe characters in URLs so they must be encoded.
*/
- id_safe = soup_uri_encode (id, NULL);
+ id_safe = g_uri_escape_string (id, NULL, TRUE);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
data = sync_async_data_new (self, manager, synchronizable);
body = json_to_string (bso, FALSE);
@@ -1385,20 +1655,34 @@ commit_batch_cb (SoupSession *session,
{
BatchUploadAsyncData *data = user_data;
const char *last_modified;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ SoupMessageHeaders *response_headers;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_headers = soup_message_get_response_headers (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_headers = msg->response_headers;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to commit batch. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
} else {
LOG ("Successfully committed batches");
/* Update sync time. */
- last_modified = soup_message_headers_get_one (msg->response_headers, "X-Last-Modified");
+ last_modified = soup_message_headers_get_one (response_headers, "X-Last-Modified");
ephy_synchronizable_manager_set_sync_time (data->manager, g_ascii_strtod (last_modified, NULL));
}
if (data->sync_done)
g_signal_emit (data->service, signals[SYNC_FINISHED], 0);
batch_upload_async_data_free (data);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1409,11 +1693,21 @@ upload_batch_cb (SoupSession *session,
BatchUploadAsyncData *data = user_data;
const char *collection;
char *endpoint = NULL;
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
/* Note: "202 Accepted" status code. */
- if (msg->status_code != 202) {
+ if (status_code != 202) {
g_warning ("Failed to upload batch. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
} else {
LOG ("Successfully uploaded batch");
}
@@ -1434,6 +1728,7 @@ out:
if (data->batch_is_last)
g_ptr_array_unref (data->synchronizables);
batch_upload_async_data_free (data);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1448,15 +1743,25 @@ start_batch_upload_cb (SoupSession *session,
GError *error = NULL;
const char *collection;
char *endpoint = NULL;
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
/* Note: "202 Accepted" status code. */
- if (msg->status_code != 202) {
+ if (status_code != 202) {
g_warning ("Failed to start batch upload. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
g_error_free (error);
@@ -1464,7 +1769,8 @@ start_batch_upload_cb (SoupSession *session,
}
object = json_node_get_object (node);
- data->batch_id = soup_uri_encode (json_object_get_string_member (object, "batch"), NULL);
+ data->batch_id = g_uri_escape_string (json_object_get_string_member (object, "batch"),
+ NULL, TRUE);
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
endpoint = g_strdup_printf ("storage/%s?batch=%s", collection, data->batch_id);
@@ -1489,6 +1795,7 @@ out:
if (batches)
g_ptr_array_unref (batches);
batch_upload_async_data_free (data);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1540,15 +1847,25 @@ sync_collection_cb (SoupSession *session,
GType type;
const char *collection;
gboolean is_deleted;
+ guint status_code;
+ GBytes *response_body;
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
- if (msg->status_code != 200) {
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to get records in collection %s. Status code: %u, response: %s",
- collection, msg->status_code, msg->response_body->data);
+ collection, status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out_error;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -1599,6 +1916,7 @@ out_no_error:
json_node_unref (node);
if (error)
g_error_free (error);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -1867,10 +2185,20 @@ upload_client_record_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to upload client record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
if (self->is_signing_in)
ephy_sync_service_report_sign_in_error (self, _("Failed to upload client record."), NULL, TRUE);
} else {
@@ -1878,6 +2206,7 @@ upload_client_record_cb (SoupSession *session,
if (self->is_signing_in)
ephy_sync_service_store_secrets (self);
}
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2066,10 +2395,20 @@ upload_crypto_keys_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to upload crypto/keys record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
ephy_sync_service_report_sign_in_error (self,
_("Failed to upload crypto/keys record."),
NULL, TRUE);
@@ -2080,6 +2419,7 @@ upload_crypto_keys_cb (SoupSession *session,
}
g_clear_pointer (&self->crypto_keys, g_free);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2133,20 +2473,31 @@ get_crypto_keys_cb (SoupSession *session,
const char *payload;
char *crypto_keys = NULL;
guint8 *kb = NULL;
-
- if (msg->status_code == 404) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code == 404) {
LOG ("crypto/keys record not found, uploading new one...");
ephy_sync_service_upload_crypto_keys (self);
+ g_clear_pointer (&response_body, g_bytes_unref);
return;
}
- if (msg->status_code != 200) {
+ if (status_code != 200) {
g_warning ("Failed to get crypto/keys record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out_error;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2189,6 +2540,7 @@ out_no_error:
g_error_free (error);
g_free (crypto_keys);
g_free (kb);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2224,10 +2576,20 @@ upload_meta_global_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to upload meta/global record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
ephy_sync_service_report_sign_in_error (self,
_("Failed to upload meta/global record."),
NULL, TRUE);
@@ -2235,6 +2597,8 @@ upload_meta_global_cb (SoupSession *session,
LOG ("Successfully uploaded meta/global record");
ephy_sync_service_get_crypto_keys (self);
}
+
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2300,21 +2664,32 @@ verify_storage_version_cb (SoupSession *session,
char *payload = NULL;
char *message = NULL;
int storage_version;
-
- if (msg->status_code == 404) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code == 404) {
LOG ("meta/global record not found, uploading new one...");
ephy_sync_service_upload_meta_global (self);
+ g_clear_pointer (&response_body, g_bytes_unref);
return;
}
- if (msg->status_code != 200) {
+ if (status_code != 200) {
g_warning ("Failed to get meta/global record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out_error;
}
parser = json_parser_new ();
- json_parser_load_from_data (parser, msg->response_body->data, -1, &error);
+ json_parser_load_from_data (parser, g_bytes_get_data (response_body, NULL), -1, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2366,6 +2741,7 @@ out_no_error:
g_error_free (error);
g_free (payload);
g_free (message);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2388,14 +2764,24 @@ upload_fxa_device_cb (SoupSession *session,
JsonNode *node;
JsonObject *object;
GError *error = NULL;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to upload device info on FxA Server. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
goto out_error;
}
- node = json_from_string (msg->response_body->data, &error);
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
g_error_free (error);
@@ -2528,8 +2914,18 @@ get_account_keys_cb (SoupSession *session,
JsonObject *json = NULL;
GError *error = NULL;
const char *bundle;
-
- node = json_from_string (msg->response_body->data, &error);
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2540,7 +2936,7 @@ get_account_keys_cb (SoupSession *session,
goto out_error;
}
- if (msg->status_code == 200) {
+ if (status_code == 200) {
bundle = json_object_get_string_member (json, "bundle");
if (!bundle) {
g_warning ("JSON object has invalid or missing 'bundle' member");
@@ -2563,7 +2959,7 @@ get_account_keys_cb (SoupSession *session,
}
g_warning ("Failed to get /account/keys. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
out_error:
ephy_sync_service_report_sign_in_error (data->service,
@@ -2721,10 +3117,20 @@ delete_open_tabs_record_cb (SoupSession *session,
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
const char *session_token;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to delete open tabs record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
} else {
LOG ("Successfully deleted open tabs record");
}
@@ -2738,6 +3144,7 @@ delete_open_tabs_record_cb (SoupSession *session,
ephy_sync_service_forget_secrets (self);
ephy_sync_utils_set_device_id (NULL);
ephy_sync_utils_set_sync_user (NULL);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
@@ -2748,10 +3155,20 @@ delete_client_record_cb (SoupSession *session,
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
char *endpoint;
char *device_bso_id;
-
- if (msg->status_code != 200) {
+ guint status_code;
+ GBytes *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ status_code = soup_message_get_status (msg);
+ response_body = g_bytes_ref (g_object_get_data (G_OBJECT (msg), "ephy-request-body"));
+#else
+ status_code = msg->status_code;
+ response_body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
+ if (status_code != 200) {
g_warning ("Failed to delete client record. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
+ status_code, (const char *)g_bytes_get_data (response_body, NULL));
} else {
LOG ("Successfully deleted client record");
}
@@ -2765,6 +3182,7 @@ delete_client_record_cb (SoupSession *session,
delete_open_tabs_record_cb, self);
g_free (endpoint);
g_free (device_bso_id);
+ g_clear_pointer (&response_body, g_bytes_unref);
}
static void
diff --git a/meson.build b/meson.build
index 0adf8f4f2..699c248e4 100644
--- a/meson.build
+++ b/meson.build
@@ -102,6 +102,12 @@ sqlite3_dep = dependency('sqlite3', version: '>= 3.22')
webkit2gtk_dep = dependency('webkit2gtk-4.0', version: webkitgtk_requirement)
webkit2gtk_web_extension_dep = dependency('webkit2gtk-web-extension-4.0', version: webkitgtk_requirement)
+if get_option('soup2').enabled()
+ libsoup_dep = dependency('libsoup-2.4', version: '>= 2.48.0')
+else
+ libsoup_dep = dependency('libsoup-3.0', version: '>= 2.99.1')
+endif
+
conf.set10('USE_LIBPORTAL', portal_dep.found())
config_h = declare_dependency(
diff --git a/meson_options.txt b/meson_options.txt
index dc59c0b78..87586e78b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -39,3 +39,9 @@ option('gsb_api_key',
value: '',
description: 'The API key used to access the Google Safe Browsing API v4'
)
+
+option('soup2',
+ type: 'feature',
+ value: 'enabled',
+ description: 'Use libsoup2'
+)
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index edc465491..102c707e3 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -608,10 +608,17 @@ history_query_completed_cb (EphyHistoryService *service,
query_collection_done (self, g_steal_pointer (&task));
}
+#if SOUP_CHECK_VERSION (2, 99, 1)
+static void
+google_search_suggestions_cb (SoupSession *session,
+ GAsyncResult *result,
+ gpointer user_data)
+#else
static void
google_search_suggestions_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
+#endif
{
GTask *task = G_TASK (user_data);
EphySuggestionModel *self = g_task_get_source_object (task);
@@ -623,17 +630,28 @@ google_search_suggestions_cb (SoupSession *session,
JsonArray *suggestions;
char *engine;
int added = 0;
+ g_autoptr (GBytes) body = NULL;
+#if SOUP_CHECK_VERSION (2, 99, 1)
+
+ body = soup_session_send_and_read_finish (session, result, NULL);
+ if (!body)
+ goto out;
+ /* FIXME: we don't have a way to get the status code */
+#else
if (msg->status_code != 200)
goto out;
+ body = g_bytes_new_static (msg->response_body->data, msg->response_body->length);
+#endif
+
shell = ephy_embed_shell_get_default ();
manager = ephy_embed_shell_get_search_engine_manager (shell);
engine = ephy_search_engine_manager_get_default_engine (manager);
- node = json_from_string (msg->response_body->data, NULL);
+ node = json_from_string (g_bytes_get_data (body, NULL), NULL);
if (!node || !JSON_NODE_HOLDS_ARRAY (node)) {
- g_warning ("Google search suggestion response is not a valid JSON object: %s", msg->response_body->data);
+ g_warning ("Google search suggestion response is not a valid JSON object: %s", (const char
*)g_bytes_get_data (body, NULL));
goto out;
}
@@ -679,8 +697,14 @@ google_search_suggestions_query (EphySuggestionModel *self,
escaped_query = g_markup_escape_text (query, -1);
url = g_strdup_printf ("http://suggestqueries.google.com/complete/search?client=firefox&q=%s",
escaped_query);
msg = soup_message_new (SOUP_METHOD_GET, url);
-
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)google_search_suggestions_cb,
+ g_steal_pointer (&task));
+ g_object_unref (msg);
+#else
soup_session_queue_message (self->session, g_steal_pointer (&msg), google_search_suggestions_cb,
g_steal_pointer (&task));
+#endif
}
void
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index 22a473011..96da8e75e 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -38,6 +38,14 @@
#define HTML_STRING "testing-ephy-web-view"
#define SERVER_PORT 12321
+#if SOUP_CHECK_VERSION (2, 99, 1)
+static void
+server_callback (SoupServer *server,
+ SoupServerMessage *msg,
+ const char *path,
+ GHashTable *query,
+ gpointer data)
+#else
static void
server_callback (SoupServer *server,
SoupMessage *msg,
@@ -45,20 +53,39 @@ server_callback (SoupServer *server,
GHashTable *query,
SoupClientContext *context,
gpointer data)
+#endif
{
- if (!strcmp (path, "/cancelled"))
- soup_message_set_status (msg, SOUP_STATUS_CANT_CONNECT);
- else if (!strcmp (path, "/redirect")) {
+ SoupMessageHeaders *response_headers;
+ SoupMessageBody *response_body;
+
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ response_headers = soup_server_message_get_response_headers (msg);
+ response_body = soup_server_message_get_response_body (msg);
+#else
+ response_headers = msg->response_headers;
+ response_body = msg->response_body;
+#endif
+
+ if (!strcmp (path, "/redirect")) {
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_server_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY, NULL);
+#else
soup_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY);
- soup_message_headers_append (msg->response_headers, "Location", "/redirect-result");
- } else
+#endif
+ soup_message_headers_append (response_headers, "Location", "/redirect-result");
+ } else {
+#if SOUP_CHECK_VERSION (2, 99, 1)
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#else
soup_message_set_status (msg, SOUP_STATUS_OK);
+#endif
+ }
- soup_message_body_append (msg->response_body, SOUP_MEMORY_STATIC,
+ soup_message_body_append (response_body, SOUP_MEMORY_STATIC,
HTML_STRING, strlen (HTML_STRING));
- soup_message_body_complete (msg->response_body);
+ soup_message_body_complete (response_body);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]