summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@gnome.org>2021-04-29 22:32:23 +0000
committerMichael Catanzaro <mcatanzaro@gnome.org>2021-04-29 22:32:23 +0000
commit63e559a00201f97f3446d2829abc0d7468993969 (patch)
tree419a6c1af0541f91db1036b364621c31946782a7
parent440fe3c55fb87aa5ad80b624984066c90e4a41a6 (diff)
downloadepiphany-63e559a00201f97f3446d2829abc0d7468993969.tar.gz
Revert "Add support for soup3"
This reverts commit 440fe3c55fb87aa5ad80b624984066c90e4a41a6
-rw-r--r--lib/safe-browsing/ephy-gsb-service.c186
-rw-r--r--lib/sync/debug/ephy-sync-debug.c129
-rw-r--r--lib/sync/ephy-sync-service.c576
-rw-r--r--meson.build16
-rw-r--r--meson_options.txt6
-rw-r--r--src/ephy-suggestion-model.c35
-rw-r--r--tests/ephy-web-view-test.c41
7 files changed, 178 insertions, 811 deletions
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index f118fff63..701a361f9 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -51,8 +51,6 @@ struct _EphyGSBService {
gint64 back_off_exit_time;
gint64 back_off_num_fails;
- GThread *update_thread;
- GMainLoop *update_loop;
SoupSession *session;
};
@@ -170,18 +168,11 @@ ephy_gsb_service_schedule_update (EphyGSBService *self)
LOG ("Next update scheduled in %ld seconds", interval);
}
-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)
+static void
+ephy_gsb_service_update_thread (GTask *task,
+ EphyGSBService *self,
+ gpointer task_data,
+ GCancellable *cancellable)
{
JsonNode *body_node = NULL;
JsonObject *body_obj;
@@ -190,12 +181,6 @@ ephy_gsb_service_update_in_thread (EphyGSBService *self)
GList *threat_lists = NULL;
char *url = NULL;
char *body;
- g_autoptr (GBytes) response_body = NULL;
- guint status_code;
-#if SOUP_CHECK_VERSION (2, 99, 4)
- g_autoptr (GBytes) bytes = NULL;
- g_autoptr (GError) error = NULL;
-#endif
g_assert (EPHY_IS_GSB_SERVICE (self));
@@ -220,28 +205,12 @@ ephy_gsb_service_update_in_thread (EphyGSBService *self)
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, 4)
- bytes = g_bytes_new_take (body, strlen (body));
- soup_message_set_request_body_from_bytes (msg, "application/json", bytes);
- response_body = soup_session_send_and_read (self->session, msg, NULL, &error);
- if (!response_body) {
- LOG ("Cannot update threat lists: %s", error->message);
- 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 (status_code != 200) {
- LOG ("Cannot update threat lists, got: %u, %s", status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ if (msg->status_code != 200) {
+ LOG ("Cannot update threat lists, got: %u, %s", msg->status_code, msg->response_body->data);
ephy_gsb_service_update_back_off_mode (self);
self->next_list_updates_time = self->back_off_exit_time;
goto out;
@@ -250,7 +219,7 @@ ephy_gsb_service_update_in_thread (EphyGSBService *self)
/* Successful response, reset back-off mode. */
ephy_gsb_service_reset_back_off_mode (self);
- body_node = json_from_string (g_bytes_get_data (response_body, NULL), NULL);
+ body_node = json_from_string (msg->response_body->data, NULL);
if (!body_node || !JSON_NODE_HOLDS_OBJECT (body_node)) {
g_warning ("Response is not a valid JSON object");
goto out;
@@ -333,46 +302,33 @@ out:
ephy_gsb_storage_set_metadata (self->storage, "next_list_updates_time", self->next_list_updates_time);
- 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;
+ g_object_unref (self);
}
-static gpointer
-run_update_thread (EphyGSBService *self)
+static void
+ephy_gsb_service_update_finished_cb (EphyGSBService *self,
+ GAsyncResult *result,
+ gpointer user_data)
{
- 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;
+ g_atomic_int_set (&self->is_updating, FALSE);
+ g_signal_emit (self, signals[UPDATE_FINISHED], 0);
+ ephy_gsb_service_schedule_update (self);
}
static gboolean
ephy_gsb_service_update (EphyGSBService *self)
{
- GSource *source;
+ GTask *task;
g_assert (EPHY_IS_GSB_SERVICE (self));
g_assert (ephy_gsb_storage_is_operable (self->storage));
g_atomic_int_set (&self->is_updating, TRUE);
- 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);
+ 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);
return G_SOURCE_REMOVE;
}
@@ -427,9 +383,6 @@ 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);
}
@@ -439,12 +392,10 @@ 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);
}
@@ -490,11 +441,8 @@ ephy_gsb_service_constructed (GObject *object)
static void
ephy_gsb_service_init (EphyGSBService *self)
{
- 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);
+ self->session = soup_session_new ();
+ g_object_set (self->session, "user-agent", ephy_user_agent_get (), NULL);
}
static void
@@ -553,17 +501,10 @@ ephy_gsb_service_new (const char *api_key,
#endif
}
-typedef struct {
- EphyGSBService *self;
- GList *prefixes;
- GMutex mutex;
- GCond condition;
-} UpdateFullHashesData;
-
-static gboolean
-ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
+static void
+ephy_gsb_service_update_full_hashes_sync (EphyGSBService *self,
+ GList *prefixes)
{
- EphyGSBService *self = data->self;
SoupMessage *msg;
GList *threat_lists;
JsonNode *body_node;
@@ -573,60 +514,36 @@ ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
char *url;
char *body;
double duration;
- g_autoptr (GBytes) response_body = NULL;
- guint status_code;
-#if SOUP_CHECK_VERSION (2, 99, 4)
- g_autoptr (GBytes) bytes = NULL;
- g_autoptr (GError) error = NULL;
-#endif
g_assert (EPHY_IS_GSB_SERVICE (self));
g_assert (ephy_gsb_storage_is_operable (self->storage));
- g_assert (data->prefixes);
-
- g_mutex_lock (&data->mutex);
+ g_assert (prefixes);
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);
- goto unlock;
+ return;
}
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);
- goto unlock;
+ return;
}
threat_lists = ephy_gsb_storage_get_threat_lists (self->storage);
if (!threat_lists)
- goto unlock;
+ return;
- body = ephy_gsb_utils_make_full_hashes_request (threat_lists, data->prefixes);
+ body = ephy_gsb_utils_make_full_hashes_request (threat_lists, 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, 4)
- bytes = g_bytes_new_take (body, strlen (body));
- soup_message_set_request_body_from_bytes (msg, "application/json", bytes);
- response_body = soup_session_send_and_read (self->session, msg, NULL, &error);
- if (!response_body) {
- LOG ("Cannot update full hashes: %s", error->message);
- 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 (status_code != 200) {
- LOG ("Cannot update full hashes, got: %u, %s", status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ if (msg->status_code != 200) {
+ LOG ("Cannot update full hashes, got: %u, %s", msg->status_code, msg->response_body->data);
ephy_gsb_service_update_back_off_mode (self);
goto out;
}
@@ -634,7 +551,7 @@ ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
/* Successful response, reset back-off mode. */
ephy_gsb_service_reset_back_off_mode (self);
- body_node = json_from_string (g_bytes_get_data (response_body, NULL), NULL);
+ body_node = json_from_string (msg->response_body->data, NULL);
if (!body_node || !JSON_NODE_HOLDS_OBJECT (body_node)) {
g_warning ("Response is not a valid JSON object");
goto out;
@@ -675,7 +592,7 @@ ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
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 = data->prefixes; l && l->data; l = l->next)
+ for (GList *l = prefixes; l && l->data; l = l->next)
ephy_gsb_storage_update_hash_prefix_expiration (self->storage, l->data, floor (duration));
/* Handle minimum wait duration. */
@@ -691,34 +608,7 @@ ephy_gsb_service_update_full_hashes_in_thread (UpdateFullHashesData *data)
out:
g_free (url);
g_list_free_full (threat_lists, (GDestroyNotify)ephy_gsb_threat_list_free);
- g_clear_object (&msg);
-
-unlock:
- 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);
+ g_object_unref (msg);
}
static void
diff --git a/lib/sync/debug/ephy-sync-debug.c b/lib/sync/debug/ephy-sync-debug.c
index 892ffeabf..2eb266770 100644
--- a/lib/sync/debug/ephy-sync-debug.c
+++ b/lib/sync/debug/ephy-sync-debug.c
@@ -225,7 +225,6 @@ 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);
@@ -237,33 +236,18 @@ ephy_sync_debug_prepare_soup_message (const char *url,
msg = soup_message_new (method, url);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- request_headers = soup_message_get_request_headers (msg);
-#else
- request_headers = msg->request_headers;
-#endif
-
if (body) {
-#if SOUP_CHECK_VERSION (2, 99, 4)
- g_autoptr (GBytes) bytes = NULL;
-#endif
-
options = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, body, NULL);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- bytes = g_bytes_new (body, strlen (body));
- soup_message_set_request_body_from_bytes (msg, content_type, 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 (request_headers, "content-type", content_type);
+ soup_message_headers_append (msg->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 (request_headers, "authorization", header->header);
+ soup_message_headers_append (msg->request_headers, "authorization", header->header);
ephy_sync_crypto_hawk_header_free (header);
if (options)
@@ -283,7 +267,7 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
JsonObject *json;
JsonObject *public_key;
JsonObject *json_body;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
guint8 *id;
guint8 *key;
guint8 *tmp;
@@ -295,7 +279,6 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
char *e;
guint status_code;
g_autofree char *accounts_server = NULL;
- g_autoptr (GBytes) response_body = NULL;
g_assert (session_token);
g_assert (keypair);
@@ -321,27 +304,17 @@ 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, 4)
- response_body = soup_session_send_and_read (session, msg, NULL, &error);
- if (!response_body) {
- LOG ("Failed to get signed certificate: %s", error->message);
- 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", (const char *)g_bytes_get_data (response_body, NULL));
+ LOG ("Failed to get signed certificate: %s", msg->response_body->data);
goto free_session;
}
- response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ response = json_from_string (msg->response_body->data, &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
+ g_error_free (error);
goto free_session;
}
@@ -377,7 +350,7 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
JsonNode *response;
JsonObject *secrets;
JsonObject *json;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
char *certificate;
char *audience;
char *assertion;
@@ -387,8 +360,6 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
guint8 *kb;
const char *session_token;
guint status_code;
- SoupMessageHeaders *request_headers;
- g_autoptr (GBytes) response_body = NULL;
gboolean success = FALSE;
g_autofree char *token_server = NULL;
@@ -410,35 +381,20 @@ 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);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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);
+ soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
+ soup_message_headers_append (msg->request_headers, "authorization", authorization);
session = soup_session_new ();
-#if SOUP_CHECK_VERSION (2, 99, 4)
- response_body = soup_session_send_and_read (session, msg, NULL, &error);
- if (!response_body) {
- LOG ("Failed to get storage credentials: %s", error->message);
- 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", (const char *)g_bytes_get_data (response_body, NULL));
+ LOG ("Failed to get storage credentials: %s", msg->response_body->data);
goto free_session;
}
- response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ response = json_from_string (msg->response_body->data, &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
+ g_error_free (error);
goto free_session;
}
@@ -474,12 +430,11 @@ ephy_sync_debug_send_request (const char *endpoint,
SoupSession *session;
SoupMessage *msg;
char *response = NULL;
- char *storage_endpoint = NULL;
- char *storage_id = NULL;
- char *storage_key = NULL;
+ char *storage_endpoint;
+ char *storage_id;
+ char *storage_key;
char *url;
guint status_code;
- g_autoptr (GBytes) response_body = NULL;
g_assert (endpoint);
g_assert (method);
@@ -498,20 +453,12 @@ 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, 4)
- response_body = soup_session_send_and_read (session, msg, NULL, NULL);
- 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 (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));
- }
+ if (status_code == 200)
+ response = g_strdup (msg->response_body->data);
+ else
+ LOG ("Failed to send storage request: %s", msg->response_body->data);
g_free (url);
g_free (storage_endpoint);
@@ -656,7 +603,7 @@ ephy_sync_debug_view_record (const char *collection,
g_assert (collection);
g_assert (id);
- id_safe = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
response = ephy_sync_debug_send_request (endpoint, "GET", NULL);
@@ -724,7 +671,7 @@ ephy_sync_debug_upload_record (const char *collection,
if (!bundle)
return;
- id_safe = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
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);
@@ -777,7 +724,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 = g_uri_escape_string (id, NULL, TRUE);
+ char *id_safe = soup_uri_encode (id, NULL);
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);
@@ -825,7 +772,7 @@ ephy_sync_debug_delete_record (const char *collection,
if (!bundle)
return;
- id_safe = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
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);
@@ -892,7 +839,7 @@ ephy_sync_debug_erase_record (const char *collection,
g_assert (collection);
g_assert (id);
- id_safe = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
response = ephy_sync_debug_send_request (endpoint, "DELETE", NULL);
@@ -1082,7 +1029,6 @@ ephy_sync_debug_view_connected_devices (void)
char *url;
const char *session_token;
g_autofree char *accounts_server = NULL;
- g_autoptr (GBytes) response_body = NULL;
secrets = ephy_sync_debug_load_secrets ();
if (!secrets)
@@ -1096,15 +1042,9 @@ 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, 4)
- 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
- if (response_body)
- LOG ("%s", (const char *)g_bytes_get_data (response_body, NULL));
+ LOG ("%s", msg->response_body->data);
g_object_unref (session);
g_object_unref (msg);
@@ -1134,7 +1074,7 @@ ephy_sync_debug_get_current_device (void)
JsonArray *array;
SoupSession *session;
SoupMessage *msg;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
guint8 *id;
guint8 *key;
guint8 *tmp;
@@ -1143,7 +1083,6 @@ ephy_sync_debug_get_current_device (void)
const char *session_token;
guint status_code;
g_autofree char *accounts_server = NULL;
- g_autoptr (GBytes) response_body = NULL;
secrets = ephy_sync_debug_load_secrets ();
if (!secrets)
@@ -1157,27 +1096,17 @@ 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, 4)
- response_body = soup_session_send_and_read (session, msg, NULL, &error);
- if (!response_body) {
- LOG ("Failed to GET account devices: %s", error->message);
- 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", (const char *)g_bytes_get_data (response_body, NULL));
+ LOG ("Failed to GET account devices: %s", msg->response_body->data);
goto free_session;
}
- response = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ response = json_from_string (msg->response_body->data, &error);
if (error) {
LOG ("Response is not a valid JSON: %s", error->message);
+ g_error_free (error);
goto free_session;
}
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 265443b52..a9eec409d 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -97,12 +97,6 @@ enum {
static guint signals[LAST_SIGNAL];
-#if SOUP_CHECK_VERSION (2, 99, 4)
-typedef void (*SoupSessionCallback) (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data);
-#endif
-
typedef struct {
char *endpoint;
char *method;
@@ -185,72 +179,6 @@ storage_request_async_data_free (StorageRequestAsyncData *data)
g_free (data);
}
-#if SOUP_CHECK_VERSION (2, 99, 4)
-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,
@@ -535,13 +463,9 @@ 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, 4)
- g_autoptr (GBytes) bytes = NULL;
-#endif
g_assert (EPHY_IS_SYNC_SERVICE (self));
g_assert (endpoint);
@@ -552,29 +476,16 @@ 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, 4)
- bytes = g_bytes_new (request_body, strlen (request_body));
- soup_message_set_request_body_from_bytes (msg, content_type, 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 (request_headers, "authorization", header->header);
- soup_message_headers_append (request_headers, "content-type", content_type);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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_message_headers_append (msg->request_headers, "authorization", header->header);
+ soup_message_headers_append (msg->request_headers, "content-type", content_type);
soup_session_queue_message (self->session, msg, callback, user_data);
-#endif
g_free (url);
ephy_sync_crypto_hawk_options_free (options);
@@ -592,7 +503,6 @@ ephy_sync_service_fxa_hawk_get (EphySyncService *self,
{
SyncCryptoHawkHeader *header;
SoupMessage *msg;
- SoupMessageHeaders *request_headers;
char *url;
g_autofree char *accounts_server = NULL;
@@ -605,19 +515,8 @@ 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);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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, 4)
- 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_message_headers_append (msg->request_headers, "authorization", header->header);
soup_session_queue_message (self->session, msg, callback, user_data);
-#endif
g_free (url);
ephy_sync_crypto_hawk_header_free (header);
@@ -630,7 +529,6 @@ 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;
@@ -643,39 +541,24 @@ 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, 4)
- g_autoptr (GBytes) bytes = NULL;
-#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, 4)
- bytes = g_bytes_new (data->request_body, strlen (data->request_body));
- soup_message_set_request_body_from_bytes (msg, content_type, 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, 4)
- 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 (request_headers, "content-type", content_type);
+ soup_message_headers_append (msg->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 (request_headers, "X-If-Modified-Since", if_modified_since);
+ soup_message_headers_append (msg->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 (request_headers, "X-If-Unmodified-Since", if_unmodified_since);
+ soup_message_headers_append (msg->request_headers, "X-If-Unmodified-Since", if_unmodified_since);
}
header = ephy_sync_crypto_hawk_header_new (url, data->method,
@@ -683,15 +566,8 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
(guint8 *)self->storage_credentials_key,
strlen (self->storage_credentials_key),
options);
- soup_message_headers_append (request_headers, "authorization", header->header);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
- (GAsyncReadyCallback)storage_request_async_ready_cb,
- data);
-#else
+ soup_message_headers_append (msg->request_headers, "authorization", header->header);
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);
@@ -699,6 +575,7 @@ 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
@@ -854,47 +731,14 @@ destroy_session_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+ if (msg->status_code != 200) {
g_warning ("Failed to destroy session. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
} else {
LOG ("Successfully destroyed session");
}
}
-#if SOUP_CHECK_VERSION (2, 99, 4)
-static void
-destroy_session_send_and_read_ready_cb (SoupSession *session,
- GAsyncResult *result,
- gpointer user_data)
-{
- GBytes *bytes;
- SoupMessage *msg;
- g_autoptr (GError) error = NULL;
-
- bytes = soup_session_send_and_read_finish (session, result, &error);
- if (!bytes)
- g_warning ("Failed to send request: %s", error->message);
-
- 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)
@@ -902,7 +746,6 @@ 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;
@@ -911,9 +754,6 @@ 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, 4)
- g_autoptr (GBytes) bytes = NULL;
-#endif
g_assert (EPHY_IS_SYNC_SERVICE (self));
if (!session_token)
@@ -928,29 +768,16 @@ 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, 4)
- bytes = g_bytes_new_static (request_body, strlen (request_body));
- soup_message_set_request_body_from_bytes (msg, content_type, 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 (request_headers, "authorization", header->header);
- soup_message_headers_append (request_headers, "content-type", content_type);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
- (GAsyncReadyCallback)destroy_session_send_and_read_ready_cb,
- NULL);
-#else
+ soup_message_headers_append (msg->request_headers, "authorization", header->header);
+ soup_message_headers_append (msg->request_headers, "content-type", content_type);
soup_session_queue_message (self->session, msg, destroy_session_cb, NULL);
-#endif
g_free (token_id_hex);
g_free (token_id);
@@ -996,23 +823,13 @@ get_storage_credentials_cb (SoupSession *session,
const char *message;
const char *suggestion;
int duration;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to obtain storage credentials. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out_error;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -1059,33 +876,10 @@ out:
g_error_free (error);
}
-#if SOUP_CHECK_VERSION (2, 99, 4)
-static void
-get_storage_credentials_ready_cb (SoupSession *session,
- GAsyncResult *result,
- gpointer user_data)
-{
- GBytes *bytes;
- SoupMessage *msg;
- g_autoptr (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);
-
- 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;
@@ -1108,23 +902,12 @@ 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, 4)
- 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 (request_headers, "X-Client-State", client_state);
- soup_message_headers_append (request_headers, "authorization", authorization);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- soup_session_send_and_read_async (self->session, msg, G_PRIORITY_DEFAULT, NULL,
- (GAsyncReadyCallback)get_storage_credentials_ready_cb,
- self);
-#else
+ soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
+ soup_message_headers_append (msg->request_headers, "authorization", authorization);
soup_session_queue_message (self->session, msg, get_storage_credentials_cb, self);
-#endif
g_free (kb);
g_free (hashed_kb);
@@ -1146,18 +929,8 @@ get_signed_certificate_cb (SoupSession *session,
const char *suggestion = NULL;
const char *message = NULL;
const char *certificate = NULL;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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);
+
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -1168,7 +941,7 @@ get_signed_certificate_cb (SoupSession *session,
goto out_error;
}
- if (status_code == 200) {
+ if (msg->status_code == 200) {
certificate = json_object_get_string_member (json, "cert");
if (!certificate) {
g_warning ("JSON object has missing or invalid 'cert' member");
@@ -1198,7 +971,7 @@ get_signed_certificate_cb (SoupSession *session,
}
g_warning ("Failed to sign certificate. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
out_error:
message = message ? message : _("Failed to obtain signed certificate.");
@@ -1327,22 +1100,11 @@ delete_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+ if (msg->status_code == 200) {
LOG ("Successfully deleted from server");
} else {
g_warning ("Failed to delete object. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
}
}
@@ -1376,7 +1138,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 = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
node = json_node_new (JSON_NODE_OBJECT);
@@ -1418,23 +1180,13 @@ download_synchronizable_cb (SoupSession *session,
GType type;
const char *collection;
gboolean is_deleted;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to download object. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON");
goto out;
@@ -1492,7 +1244,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 = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
data = sync_async_data_new (self, manager, synchronizable);
@@ -1512,31 +1264,21 @@ upload_synchronizable_cb (SoupSession *session,
{
SyncAsyncData *data = (SyncAsyncData *)user_data;
gint64 time_modified;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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 (status_code == 412) {
+ if (msg->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 (status_code == 200) {
+ } else if (msg->status_code == 200) {
LOG ("Successfully uploaded to server");
- time_modified = ceil (g_ascii_strtod (g_bytes_get_data (response_body, NULL), NULL));
+ time_modified = ceil (g_ascii_strtod (msg->response_body->data, 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",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
}
sync_async_data_free (data);
@@ -1573,7 +1315,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 = g_uri_escape_string (id, NULL, TRUE);
+ id_safe = soup_uri_encode (id, NULL);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id_safe);
data = sync_async_data_new (self, manager, synchronizable);
body = json_to_string (bso, FALSE);
@@ -1643,27 +1385,14 @@ commit_batch_cb (SoupSession *session,
{
BatchUploadAsyncData *data = user_data;
const char *last_modified;
- guint status_code;
- SoupMessageHeaders *response_headers;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to commit batch. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
} else {
LOG ("Successfully committed batches");
/* Update sync time. */
- last_modified = soup_message_headers_get_one (response_headers, "X-Last-Modified");
+ last_modified = soup_message_headers_get_one (msg->response_headers, "X-Last-Modified");
ephy_synchronizable_manager_set_sync_time (data->manager, g_ascii_strtod (last_modified, NULL));
}
@@ -1680,21 +1409,11 @@ upload_batch_cb (SoupSession *session,
BatchUploadAsyncData *data = user_data;
const char *collection;
char *endpoint = NULL;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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 (status_code != 202) {
+ if (msg->status_code != 202) {
g_warning ("Failed to upload batch. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
} else {
LOG ("Successfully uploaded batch");
}
@@ -1726,36 +1445,26 @@ start_batch_upload_cb (SoupSession *session,
GPtrArray *batches = NULL;
JsonNode *node = NULL;
JsonObject *object;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
const char *collection;
char *endpoint = NULL;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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 (status_code != 202) {
+ if (msg->status_code != 202) {
g_warning ("Failed to start batch upload. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
+ g_error_free (error);
goto out;
}
object = json_node_get_object (node);
- data->batch_id = g_uri_escape_string (json_object_get_string_member (object, "batch"),
- NULL, TRUE);
+ data->batch_id = soup_uri_encode (json_object_get_string_member (object, "batch"), NULL);
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
endpoint = g_strdup_printf ("storage/%s?batch=%s", collection, data->batch_id);
@@ -1827,29 +1536,19 @@ sync_collection_cb (SoupSession *session,
SyncCryptoKeyBundle *bundle = NULL;
JsonNode *node = NULL;
JsonArray *array = NULL;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
GType type;
const char *collection;
gboolean is_deleted;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+ if (msg->status_code != 200) {
g_warning ("Failed to get records in collection %s. Status code: %u, response: %s",
- collection, status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ collection, msg->status_code, msg->response_body->data);
goto out_error;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -1898,6 +1597,8 @@ out_no_error:
ephy_sync_crypto_key_bundle_free (bundle);
if (node)
json_node_unref (node);
+ if (error)
+ g_error_free (error);
}
static void
@@ -2166,20 +1867,10 @@ upload_client_record_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to upload client record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
if (self->is_signing_in)
ephy_sync_service_report_sign_in_error (self, _("Failed to upload client record."), NULL, TRUE);
} else {
@@ -2375,20 +2066,10 @@ upload_crypto_keys_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to upload crypto/keys record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
ephy_sync_service_report_sign_in_error (self,
_("Failed to upload crypto/keys record."),
NULL, TRUE);
@@ -2448,34 +2129,24 @@ get_crypto_keys_cb (SoupSession *session,
SyncCryptoKeyBundle *bundle = NULL;
JsonNode *node = NULL;
JsonObject *json = NULL;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
const char *payload;
char *crypto_keys = NULL;
guint8 *kb = NULL;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code == 404) {
LOG ("crypto/keys record not found, uploading new one...");
ephy_sync_service_upload_crypto_keys (self);
return;
}
- if (status_code != 200) {
+ if (msg->status_code != 200) {
g_warning ("Failed to get crypto/keys record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out_error;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2514,6 +2185,8 @@ out_no_error:
ephy_sync_crypto_key_bundle_free (bundle);
if (node)
json_node_unref (node);
+ if (error)
+ g_error_free (error);
g_free (crypto_keys);
g_free (kb);
}
@@ -2551,20 +2224,10 @@ upload_meta_global_cb (SoupSession *session,
gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to upload meta/global record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
ephy_sync_service_report_sign_in_error (self,
_("Failed to upload meta/global record."),
NULL, TRUE);
@@ -2633,35 +2296,25 @@ verify_storage_version_cb (SoupSession *session,
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
JsonParser *parser = NULL;
JsonObject *json = NULL;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
char *payload = NULL;
char *message = NULL;
int storage_version;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code == 404) {
LOG ("meta/global record not found, uploading new one...");
ephy_sync_service_upload_meta_global (self);
return;
}
- if (status_code != 200) {
+ if (msg->status_code != 200) {
g_warning ("Failed to get meta/global record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out_error;
}
parser = json_parser_new ();
- json_parser_load_from_data (parser, g_bytes_get_data (response_body, NULL), -1, &error);
+ json_parser_load_from_data (parser, msg->response_body->data, -1, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2709,6 +2362,8 @@ out_error:
out_no_error:
if (parser)
g_object_unref (parser);
+ if (error)
+ g_error_free (error);
g_free (payload);
g_free (message);
}
@@ -2732,27 +2387,18 @@ upload_fxa_device_cb (SoupSession *session,
EphySyncService *self = user_data;
JsonNode *node;
JsonObject *object;
- g_autoptr (GError) error = NULL;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+ GError *error = NULL;
+
+ if (msg->status_code != 200) {
g_warning ("Failed to upload device info on FxA Server. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
goto out_error;
}
- node = json_from_string (g_bytes_get_data (response_body, NULL), &error);
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
+ g_error_free (error);
goto out_error;
}
@@ -2880,20 +2526,10 @@ get_account_keys_cb (SoupSession *session,
SignInAsyncData *data = (SignInAsyncData *)user_data;
JsonNode *node = NULL;
JsonObject *json = NULL;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
const char *bundle;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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);
+
+ node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -2904,7 +2540,7 @@ get_account_keys_cb (SoupSession *session,
goto out_error;
}
- if (status_code == 200) {
+ if (msg->status_code == 200) {
bundle = json_object_get_string_member (json, "bundle");
if (!bundle) {
g_warning ("JSON object has invalid or missing 'bundle' member");
@@ -2927,7 +2563,7 @@ get_account_keys_cb (SoupSession *session,
}
g_warning ("Failed to get /account/keys. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
out_error:
ephy_sync_service_report_sign_in_error (data->service,
@@ -2937,6 +2573,8 @@ out_error:
out_no_error:
if (node)
json_node_unref (node);
+ if (error)
+ g_error_free (error);
}
void
@@ -3083,20 +2721,10 @@ delete_open_tabs_record_cb (SoupSession *session,
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
const char *session_token;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to delete open tabs record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
} else {
LOG ("Successfully deleted open tabs record");
}
@@ -3120,20 +2748,10 @@ delete_client_record_cb (SoupSession *session,
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
char *endpoint;
char *device_bso_id;
- guint status_code;
- g_autoptr (GBytes) response_body = NULL;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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) {
+
+ if (msg->status_code != 200) {
g_warning ("Failed to delete client record. Status code: %u, response: %s",
- status_code, (const char *)g_bytes_get_data (response_body, NULL));
+ msg->status_code, msg->response_body->data);
} else {
LOG ("Successfully deleted client record");
}
diff --git a/meson.build b/meson.build
index b8c1a3741..ddb4346c9 100644
--- a/meson.build
+++ b/meson.build
@@ -75,6 +75,7 @@ conf.set10('ENABLE_GSB', gsb_api_key != '')
glib_requirement = '>= 2.67.1'
gtk_requirement = '>= 3.24.0'
nettle_requirement = '>= 3.4'
+webkitgtk_requirement = '>= 2.31.2'
cairo_dep = dependency('cairo', version: '>= 1.2')
gcr_dep = dependency('gcr-3', version: '>= 3.5.5')
@@ -93,22 +94,13 @@ libarchive_dep = dependency('libarchive')
libdazzle_dep = dependency('libdazzle-1.0', version: '>= 3.37.1')
libhandy_dep = dependency('libhandy-1', version: '>= 1.1.0')
libsecret_dep = dependency('libsecret-1', version: '>= 0.19.0')
+libsoup_dep = dependency('libsoup-2.4', version: '>= 2.48.0')
libxml_dep = dependency('libxml-2.0', version: '>= 2.6.12')
nettle_dep = dependency('nettle', version: nettle_requirement)
portal_dep = dependency('libportal', version: '>= 0.0.2', required: get_option('libportal'))
sqlite3_dep = dependency('sqlite3', version: '>= 3.22')
-
-if get_option('soup2').enabled()
- webkitgtk_requirement = '>= 2.31.2'
- libsoup_dep = dependency('libsoup-2.4', version: '>= 2.48.0')
- webkit2gtk_dep = dependency('webkit2gtk-4.0', version: webkitgtk_requirement)
- webkit2gtk_web_extension_dep = dependency('webkit2gtk-web-extension-4.0', version: webkitgtk_requirement)
-else
- webkitgtk_requirement = '>= 2.33.0'
- libsoup_dep = dependency('libsoup-3.0', version: '>= 2.99.4')
- webkit2gtk_dep = dependency('webkit2gtk-4.1', version: webkitgtk_requirement)
- webkit2gtk_web_extension_dep = dependency('webkit2gtk-web-extension-4.1', version: webkitgtk_requirement)
-endif
+webkit2gtk_dep = dependency('webkit2gtk-4.0', version: webkitgtk_requirement)
+webkit2gtk_web_extension_dep = dependency('webkit2gtk-web-extension-4.0', version: webkitgtk_requirement)
conf.set10('USE_LIBPORTAL', portal_dep.found())
diff --git a/meson_options.txt b/meson_options.txt
index 87586e78b..dc59c0b78 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -39,9 +39,3 @@ 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 74976fc99..b8d8803d4 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -638,17 +638,10 @@ history_query_completed_cb (EphyHistoryService *service,
query_collection_done (self, g_steal_pointer (&task));
}
-#if SOUP_CHECK_VERSION (2, 99, 4)
-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);
@@ -660,33 +653,17 @@ google_search_suggestions_cb (SoupSession *session,
JsonArray *suggestions;
char *engine;
int added = 0;
- g_autoptr (GBytes) body = NULL;
-#if SOUP_CHECK_VERSION (2, 99, 4)
- SoupMessage *msg;
-
- body = soup_session_send_and_read_finish (session, result, NULL);
- if (!body)
- goto out;
- msg = soup_session_get_async_result_message (session, result);
- if (soup_message_get_status (msg) != 200)
- 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 (g_bytes_get_data (body, NULL), NULL);
+ node = json_from_string (msg->response_body->data, NULL);
if (!node || !JSON_NODE_HOLDS_ARRAY (node)) {
- g_warning ("Google search suggestion response is not a valid JSON object: %s", (const char *)g_bytes_get_data (body, NULL));
+ g_warning ("Google search suggestion response is not a valid JSON object: %s", msg->response_body->data);
goto out;
}
@@ -732,14 +709,8 @@ 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, 4)
- 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 05b6558aa..22a473011 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -38,14 +38,6 @@
#define HTML_STRING "testing-ephy-web-view"
#define SERVER_PORT 12321
-#if SOUP_CHECK_VERSION (2, 99, 4)
-static void
-server_callback (SoupServer *server,
- SoupServerMessage *msg,
- const char *path,
- GHashTable *query,
- gpointer data)
-#else
static void
server_callback (SoupServer *server,
SoupMessage *msg,
@@ -53,39 +45,20 @@ server_callback (SoupServer *server,
GHashTable *query,
SoupClientContext *context,
gpointer data)
-#endif
{
- SoupMessageHeaders *response_headers;
- SoupMessageBody *response_body;
-
-#if SOUP_CHECK_VERSION (2, 99, 4)
- 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, 4)
- soup_server_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY, NULL);
-#else
+ if (!strcmp (path, "/cancelled"))
+ soup_message_set_status (msg, SOUP_STATUS_CANT_CONNECT);
+ else if (!strcmp (path, "/redirect")) {
soup_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY);
-#endif
- soup_message_headers_append (response_headers, "Location", "/redirect-result");
- } else {
-#if SOUP_CHECK_VERSION (2, 99, 4)
- soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
-#else
+ soup_message_headers_append (msg->response_headers, "Location", "/redirect-result");
+ } else
soup_message_set_status (msg, SOUP_STATUS_OK);
-#endif
- }
- soup_message_body_append (response_body, SOUP_MEMORY_STATIC,
+ soup_message_body_append (msg->response_body, SOUP_MEMORY_STATIC,
HTML_STRING, strlen (HTML_STRING));
- soup_message_body_complete (response_body);
+ soup_message_body_complete (msg->response_body);
}
static void