pidgin/pidgin

Merged in default (pull request #601)

2019-10-15, Gary Kramlich
0b2985712d3b
Merged in default (pull request #601)

Convert Facebook to libsoup

Approved-by: Gary Kramlich
--- a/libpurple/protocols/facebook/api.c Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/api.c Tue Oct 15 03:58:49 2019 +0000
@@ -20,6 +20,7 @@
*/
#include <json-glib/json-glib.h>
+#include <libsoup/soup.h>
#include <stdarg.h>
#include <string.h>
@@ -31,8 +32,6 @@
#include "thrift.h"
#include "util.h"
-typedef struct _FbApiData FbApiData;
-
enum
{
PROP_0,
@@ -50,9 +49,8 @@
typedef struct
{
FbMqtt *mqtt;
- FbHttpConns *cons;
+ SoupSession *cons;
PurpleConnection *gc;
- GHashTable *data;
gboolean retrying;
FbId uid;
@@ -81,12 +79,6 @@
FbApiPrivate *priv;
};
-struct _FbApiData
-{
- gpointer data;
- GDestroyNotify func;
-};
-
static void fb_api_error_literal(FbApi *api, FbApiError error,
const gchar *msg);
@@ -178,24 +170,15 @@
static void
fb_api_dispose(GObject *obj)
{
- FbApiData *fata;
FbApiPrivate *priv = FB_API(obj)->priv;
- GHashTableIter iter;
-
- fb_http_conns_cancel_all(priv->cons);
- g_hash_table_iter_init(&iter, priv->data);
-
- while (g_hash_table_iter_next(&iter, NULL, (gpointer) &fata)) {
- fata->func(fata->data);
- g_free(fata);
- }
+
+ soup_session_abort(priv->cons);
if (G_UNLIKELY(priv->mqtt != NULL)) {
g_object_unref(priv->mqtt);
}
- fb_http_conns_free(priv->cons);
- g_hash_table_destroy(priv->data);
+ g_object_unref(priv->cons);
g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
g_free(priv->cid);
@@ -521,13 +504,9 @@
fb_api_init(FbApi *api)
{
FbApiPrivate *priv = fb_api_get_instance_private(api);
-
api->priv = priv;
- priv->cons = fb_http_conns_new();
priv->msgs = g_queue_new();
- priv->data = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- NULL, NULL);
}
GQuark
@@ -542,38 +521,6 @@
return q;
}
-static void
-fb_api_data_set(FbApi *api, gpointer handle, gpointer data,
- GDestroyNotify func)
-{
- FbApiData *fata;
- FbApiPrivate *priv = api->priv;
-
- fata = g_new0(FbApiData, 1);
- fata->data = data;
- fata->func = func;
- g_hash_table_replace(priv->data, handle, fata);
-}
-
-static gpointer
-fb_api_data_take(FbApi *api, gconstpointer handle)
-{
- FbApiData *fata;
- FbApiPrivate *priv = api->priv;
- gpointer data;
-
- fata = g_hash_table_lookup(priv->data, handle);
-
- if (fata == NULL) {
- return NULL;
- }
-
- data = fata->data;
- g_hash_table_remove(priv->data, handle);
- g_free(fata);
- return data;
-}
-
static gboolean
fb_api_json_chk(FbApi *api, gconstpointer data, gssize size, JsonNode **node)
{
@@ -686,36 +633,27 @@
}
static gboolean
-fb_api_http_chk(FbApi *api, PurpleHttpConnection *con, PurpleHttpResponse *res,
- JsonNode **root)
+fb_api_http_chk(FbApi *api, SoupMessage *res, JsonNode **root)
{
const gchar *data;
const gchar *msg;
- FbApiPrivate *priv = api->priv;
- gchar *emsg;
GError *err = NULL;
gint code;
gsize size;
- if (fb_http_conns_is_canceled(priv->cons)) {
- return FALSE;
+ msg = res->reason_phrase;
+ code = res->status_code;
+ data = res->response_body->data;
+ size = res->response_body->length;
+
+ fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Response (%p):", res);
+ if (msg != NULL) {
+ fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %s (%d)", msg,
+ code);
+ } else {
+ fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %d", code);
}
- msg = purple_http_response_get_error(res);
- code = purple_http_response_get_code(res);
- data = purple_http_response_get_data(res, &size);
- fb_http_conns_remove(priv->cons, con);
-
- if (msg != NULL) {
- emsg = g_strdup_printf("%s (%d)", msg, code);
- } else {
- emsg = g_strdup_printf("%d", code);
- }
-
- fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Response (%p):", con);
- fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %s", emsg);
- g_free(emsg);
-
if (G_LIKELY(size > 0)) {
fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Data: %.*s",
(gint) size, data);
@@ -742,10 +680,10 @@
return TRUE;
}
-static PurpleHttpConnection *
+static SoupMessage *
fb_api_http_req(FbApi *api, const gchar *url, const gchar *name,
const gchar *method, FbHttpParams *params,
- PurpleHttpCallback callback)
+ SoupSessionCallback callback)
{
FbApiPrivate *priv = api->priv;
gchar *data;
@@ -754,8 +692,7 @@
GList *keys;
GList *l;
GString *gstr;
- PurpleHttpConnection *ret;
- PurpleHttpRequest *req;
+ SoupMessage *msg;
fb_http_params_set_str(params, "api_key", FB_API_KEY);
fb_http_params_set_str(params, "device_id", priv->did);
@@ -767,10 +704,6 @@
fb_http_params_set_str(params, "locale", val);
g_free(val);
- req = purple_http_request_new(url);
- purple_http_request_set_max_len(req, -1);
- purple_http_request_set_method(req, "POST");
-
/* Ensure an old signature is not computed */
g_hash_table_remove(params, "sig");
@@ -792,32 +725,28 @@
g_list_free(keys);
g_free(data);
+ msg = soup_form_request_new_from_hash("POST", url, params);
+ fb_http_params_free(params);
+
if (priv->token != NULL) {
data = g_strdup_printf("OAuth %s", priv->token);
- purple_http_request_header_set(req, "Authorization", data);
+ soup_message_headers_replace(msg->request_headers, "Authorization",
+ data);
g_free(data);
}
- purple_http_request_header_set(req, "User-Agent", FB_API_AGENT);
- purple_http_request_header_set(req, "Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
-
- data = fb_http_params_close(params, NULL);
- purple_http_request_set_contents(req, data, -1);
- ret = purple_http_request(priv->gc, req, callback, api);
- fb_http_conns_add(priv->cons, ret);
- purple_http_request_unref(req);
-
- fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", ret);
+ soup_session_queue_message(priv->cons, msg, callback, api);
+
+ fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", msg);
fb_util_debug(FB_UTIL_DEBUG_INFO, " Request URL: %s", url);
fb_util_debug(FB_UTIL_DEBUG_INFO, " Request Data: %s", data);
- g_free(data);
- return ret;
+ return msg;
}
-static PurpleHttpConnection *
+static SoupMessage *
fb_api_http_query(FbApi *api, gint64 query, JsonBuilder *builder,
- PurpleHttpCallback hcb)
+ SoupSessionCallback hcb)
{
const gchar *name;
FbHttpParams *prms;
@@ -865,19 +794,16 @@
}
static void
-fb_api_cb_http_bool(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_http_bool(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
- const gchar *hata;
FbApi *api = data;
- if (!fb_api_http_chk(api, con, res, NULL)) {
+ if (!fb_api_http_chk(api, res, NULL)) {
return;
}
- hata = purple_http_response_get_data(res, NULL);
-
- if (!purple_strequal(hata, "true")) {
+ if (!purple_strequal(res->response_body->data, "true")) {
fb_api_error_literal(api, FB_API_ERROR,
_("Failed generic API operation"));
}
@@ -1057,7 +983,7 @@
}
static void
-fb_api_cb_seqid(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_seqid(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *str;
@@ -1067,7 +993,7 @@
GError *err = NULL;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -1962,7 +1888,7 @@
}
FbApi *
-fb_api_new(PurpleConnection *gc)
+fb_api_new(PurpleConnection *gc, GProxyResolver *resolver)
{
FbApi *api;
FbApiPrivate *priv;
@@ -1971,6 +1897,9 @@
priv = api->priv;
priv->gc = gc;
+ priv->cons = soup_session_new_with_options(
+ SOUP_SESSION_PROXY_RESOLVER, resolver, SOUP_SESSION_USER_AGENT,
+ FB_API_AGENT, NULL);
priv->mqtt = fb_mqtt_new(gc);
g_signal_connect(priv->mqtt,
@@ -2068,7 +1997,7 @@
}
static void
-fb_api_cb_attach(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_attach(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *str;
@@ -2083,7 +2012,7 @@
static const gchar *imgexts[] = {".jpg", ".png", ".gif"};
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2098,7 +2027,7 @@
return;
);
- msg = fb_api_data_take(api, con);
+ msg = g_object_steal_data(G_OBJECT(res), "fb-api-msg");
str = fb_json_values_next_str(values, NULL);
name = g_ascii_strdown(str, -1);
@@ -2124,7 +2053,7 @@
fb_api_attach(FbApi *api, FbId aid, const gchar *msgid, FbApiMessage *msg)
{
FbHttpParams *prms;
- PurpleHttpConnection *http;
+ SoupMessage *http;
prms = fb_http_params_new();
fb_http_params_set_str(prms, "mid", msgid);
@@ -2133,11 +2062,12 @@
http = fb_api_http_req(api, FB_API_URL_ATTACH, "getAttachment",
"messaging.getAttachment", prms,
fb_api_cb_attach);
- fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free);
+ g_object_set_data_full(G_OBJECT(http), "fb-api-msg", msg,
+ (GDestroyNotify)fb_api_message_free);
}
static void
-fb_api_cb_auth(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_auth(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
FbApi *api = data;
@@ -2146,7 +2076,7 @@
GError *err = NULL;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2205,7 +2135,7 @@
}
static void
-fb_api_cb_contact(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_contact(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *str;
@@ -2216,7 +2146,7 @@
JsonNode *node;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2358,7 +2288,7 @@
}
static void
-fb_api_cb_contacts(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_contacts(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *cursor;
@@ -2375,7 +2305,7 @@
JsonNode *croot;
JsonNode *node;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2686,7 +2616,7 @@
}
static void
-fb_api_cb_unread_msgs(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_unread_msgs(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *body;
@@ -2704,7 +2634,7 @@
JsonNode *root;
JsonNode *xode;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2818,7 +2748,7 @@
}
static void
-fb_api_cb_unread(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_unread(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *id;
@@ -2829,7 +2759,7 @@
JsonBuilder *bldr;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2899,7 +2829,7 @@
}
static void
-fb_api_cb_sticker(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_sticker(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
FbApi *api = data;
@@ -2910,7 +2840,7 @@
JsonNode *node;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -2926,7 +2856,7 @@
return;
);
- msg = fb_api_data_take(api, con);
+ msg = g_object_steal_data(G_OBJECT(res), "fb-api-msg");
msg->flags |= FB_API_MESSAGE_FLAG_IMAGE;
msg->text = fb_json_values_next_str_dup(values, NULL);
msgs = g_slist_prepend(msgs, msg);
@@ -2941,7 +2871,7 @@
fb_api_sticker(FbApi *api, FbId sid, FbApiMessage *msg)
{
JsonBuilder *bldr;
- PurpleHttpConnection *http;
+ SoupMessage *http;
bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
fb_json_bldr_arr_begin(bldr, "0");
@@ -2950,7 +2880,8 @@
http = fb_api_http_query(api, FB_API_QUERY_STICKER, bldr,
fb_api_cb_sticker);
- fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free);
+ g_object_set_data_full(G_OBJECT(http), "fb-api-msg", msg,
+ (GDestroyNotify)fb_api_message_free);
}
static gboolean
@@ -3028,8 +2959,8 @@
}
static void
-fb_api_cb_thread(PurpleHttpConnection *con, PurpleHttpResponse *res,
- gpointer data)
+fb_api_cb_thread(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
+ gpointer data)
{
FbApi *api = data;
FbApiThread thrd;
@@ -3037,7 +2968,7 @@
JsonNode *node;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -3088,7 +3019,7 @@
}
static void
-fb_api_cb_thread_create(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_thread_create(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
const gchar *str;
@@ -3098,7 +3029,7 @@
GError *err = NULL;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
@@ -3222,7 +3153,7 @@
}
static void
-fb_api_cb_threads(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_api_cb_threads(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
FbApi *api = data;
@@ -3235,7 +3166,7 @@
JsonArray *arr;
JsonNode *root;
- if (!fb_api_http_chk(api, con, res, &root)) {
+ if (!fb_api_http_chk(api, res, &root)) {
return;
}
--- a/libpurple/protocols/facebook/api.h Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/api.h Tue Oct 15 03:58:49 2019 +0000
@@ -551,14 +551,14 @@
/**
* fb_api_new:
* @gc: The #PurpleConnection.
+ * @resolver: The proxy resolver to use from the account.
*
* Creates a new #FbApi. The returned #FbApi should be freed with
* #g_object_unref() when no longer needed.
*
* Returns: The new #FbApi.
*/
-FbApi *
-fb_api_new(PurpleConnection *gc);
+FbApi *fb_api_new(PurpleConnection *gc, GProxyResolver *resolver);
/**
* fb_api_rehash:
--- a/libpurple/protocols/facebook/data.c Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/data.c Tue Oct 15 03:58:49 2019 +0000
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
+#include <libsoup/soup.h>
#include <string.h>
#include "account.h"
@@ -30,7 +31,7 @@
typedef struct
{
FbApi *api;
- FbHttpConns *cons;
+ SoupSession *cons;
PurpleConnection *gc;
PurpleRoomlist *roomlist;
GQueue *msgs;
@@ -91,7 +92,7 @@
GHashTableIter iter;
gpointer ptr;
- fb_http_conns_cancel_all(priv->cons);
+ soup_session_abort(priv->cons);
g_hash_table_iter_init(&iter, priv->evs);
while (g_hash_table_iter_next(&iter, NULL, &ptr)) {
@@ -102,7 +103,7 @@
g_object_unref(priv->api);
}
- fb_http_conns_free(priv->cons);
+ g_object_unref(priv->cons);
g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
g_hash_table_destroy(priv->imgs);
@@ -124,7 +125,6 @@
FbDataPrivate *priv = fb_data_get_instance_private(fata);
fata->priv = priv;
- priv->cons = fb_http_conns_new();
priv->msgs = g_queue_new();
priv->imgs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
@@ -166,7 +166,7 @@
}
FbData *
-fb_data_new(PurpleConnection *gc)
+fb_data_new(PurpleConnection *gc, GProxyResolver *resolver)
{
FbData *fata;
FbDataPrivate *priv;
@@ -174,7 +174,9 @@
fata = g_object_new(FB_TYPE_DATA, NULL);
priv = fata->priv;
- priv->api = fb_api_new(gc);
+ priv->cons = soup_session_new_with_options(SOUP_SESSION_PROXY_RESOLVER,
+ resolver, NULL);
+ priv->api = fb_api_new(gc, resolver);
priv->gc = gc;
return fata;
@@ -553,22 +555,17 @@
}
static void
-fb_data_image_cb(PurpleHttpConnection *con, PurpleHttpResponse *res,
+fb_data_image_cb(G_GNUC_UNUSED SoupSession *session, SoupMessage *res,
gpointer data)
{
FbDataImage *img = data;
FbDataImagePrivate *priv = img->priv;
- FbDataPrivate *driv = priv->fata->priv;
GError *err = NULL;
- if (fb_http_conns_is_canceled(driv->cons)) {
- return;
- }
-
- fb_http_conns_remove(driv->cons, con);
fb_http_error_chk(res, &err);
- priv->image = (guint8 *) purple_http_response_get_data(res, &priv->size);
+ priv->image = (guint8 *)res->response_body->data;
+ priv->size = res->response_body->length;
priv->func(img, err);
if (G_LIKELY(err == NULL)) {
@@ -588,7 +585,6 @@
FbDataPrivate *priv;
GHashTableIter iter;
guint active = 0;
- PurpleHttpConnection *con;
g_return_if_fail(FB_IS_DATA(fata));
priv = fata->priv;
@@ -607,7 +603,7 @@
g_hash_table_iter_init(&iter, priv->imgs);
while (g_hash_table_iter_next(&iter, (gpointer *) &img, NULL)) {
- PurpleHttpRequest *req;
+ SoupMessage *msg;
if (fb_data_image_get_active(img)) {
continue;
@@ -616,12 +612,9 @@
img->priv->active = TRUE;
url = fb_data_image_get_url(img);
- req = purple_http_request_new(url);
- purple_http_request_set_max_len(req, FB_DATA_ICON_SIZE_MAX);
- con = purple_http_request(priv->gc, req,
- fb_data_image_cb, img);
- fb_http_conns_add(priv->cons, con);
- purple_http_request_unref(req);
+ msg = soup_message_new("GET", url);
+ // purple_http_request_set_max_len(req, FB_DATA_ICON_SIZE_MAX);
+ soup_session_queue_message(priv->cons, msg, fb_data_image_cb, img);
if (++active >= FB_DATA_ICON_MAX) {
break;
--- a/libpurple/protocols/facebook/data.h Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/data.h Tue Oct 15 03:58:49 2019 +0000
@@ -83,14 +83,14 @@
/**
* fb_data_new:
* @gc: The #PurpleConnection.
+ * @resolver: The proxy resolver to use from the account.
*
* Creates a new #FbData. The returned #FbData should be freed with
* #g_object_unref() when no longer needed.
*
* Returns: The new #FbData.
*/
-FbData *
-fb_data_new(PurpleConnection *gc);
+FbData *fb_data_new(PurpleConnection *gc, GProxyResolver *resolver);
/**
* fb_data_load:
--- a/libpurple/protocols/facebook/facebook.c Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/facebook.c Tue Oct 15 03:58:49 2019 +0000
@@ -994,10 +994,20 @@
FbData *fata;
gpointer convh;
PurpleConnection *gc;
+ GProxyResolver *resolver;
+ GError *error = NULL;
gc = purple_account_get_connection(acct);
- fata = fb_data_new(gc);
+ resolver = purple_proxy_get_proxy_resolver(acct, &error);
+ if (resolver == NULL) {
+ fb_util_debug_error("Unable to get account proxy resolver: %s",
+ error->message);
+ purple_connection_g_error(gc, error);
+ return;
+ }
+
+ fata = fb_data_new(gc, resolver);
api = fb_data_get_api(fata);
convh = purple_conversations_get_handle();
purple_connection_set_protocol_data(gc, fata);
--- a/libpurple/protocols/facebook/http.c Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/http.c Tue Oct 15 03:58:49 2019 +0000
@@ -25,12 +25,6 @@
#include "http.h"
-struct _FbHttpConns
-{
- GHashTable *cons;
- gboolean canceled;
-};
-
GQuark
fb_http_error_quark(void)
{
@@ -43,87 +37,15 @@
return q;
}
-FbHttpConns *
-fb_http_conns_new(void)
-{
- FbHttpConns *cons;
-
- cons = g_new0(FbHttpConns, 1);
- cons->cons = g_hash_table_new(g_direct_hash, g_direct_equal);
- return cons;
-}
-
-void
-fb_http_conns_free(FbHttpConns *cons)
-{
- g_return_if_fail(cons != NULL);
-
- g_hash_table_destroy(cons->cons);
- g_free(cons);
-}
-
-void
-fb_http_conns_cancel_all(FbHttpConns *cons)
+gboolean
+fb_http_error_chk(SoupMessage *res, GError **error)
{
- GHashTableIter iter;
- gpointer con;
-
- g_return_if_fail(cons != NULL);
- g_return_if_fail(!cons->canceled);
-
- cons->canceled = TRUE;
- g_hash_table_iter_init(&iter, cons->cons);
-
- while (g_hash_table_iter_next(&iter, &con, NULL)) {
- g_hash_table_iter_remove(&iter);
- purple_http_conn_cancel(con);
- }
-}
-
-gboolean
-fb_http_conns_is_canceled(FbHttpConns *cons)
-{
- g_return_val_if_fail(cons != NULL, TRUE);
- return cons->canceled;
-}
-
-void
-fb_http_conns_add(FbHttpConns *cons, PurpleHttpConnection *con)
-{
- g_return_if_fail(cons != NULL);
- g_return_if_fail(!cons->canceled);
- g_hash_table_replace(cons->cons, con, con);
-}
-
-void
-fb_http_conns_remove(FbHttpConns *cons, PurpleHttpConnection *con)
-{
- g_return_if_fail(cons != NULL);
- g_return_if_fail(!cons->canceled);
- g_hash_table_remove(cons->cons, con);
-}
-
-void
-fb_http_conns_reset(FbHttpConns *cons)
-{
- g_return_if_fail(cons != NULL);
- cons->canceled = FALSE;
- g_hash_table_remove_all(cons->cons);
-}
-
-gboolean
-fb_http_error_chk(PurpleHttpResponse *res, GError **error)
-{
- const gchar *msg;
- gint code;
-
- if (purple_http_response_is_successful(res)) {
+ if (SOUP_STATUS_IS_SUCCESSFUL(res->status_code)) {
return TRUE;
}
- msg = purple_http_response_get_error(res);
- code = purple_http_response_get_code(res);
- g_set_error(error, FB_HTTP_ERROR, code, "%s", msg);
+ g_set_error(error, FB_HTTP_ERROR, res->status_code, "%s",
+ res->reason_phrase);
return FALSE;
}
@@ -136,56 +58,29 @@
FbHttpParams *
fb_http_params_new_parse(const gchar *data, gboolean isurl)
{
- const gchar *tail;
- gchar *key;
- gchar **ps;
- gchar *val;
- guint i;
+ SoupURI *uri = NULL;
FbHttpParams *params;
- params = fb_http_params_new();
-
if (data == NULL) {
- return params;
+ return fb_http_params_new();
}
if (isurl) {
- data = strchr(data, '?');
+ uri = soup_uri_new(data);
- if (data == NULL) {
- return params;
+ if (uri == NULL) {
+ return fb_http_params_new();
}
- tail = strchr(++data, '#');
-
- if (tail != NULL) {
- data = g_strndup(data, tail - data);
- } else {
- data = g_strdup(data);
- }
+ data = uri->query;
}
- ps = g_strsplit(data, "&", 0);
-
- for (i = 0; ps[i] != NULL; i++) {
- key = ps[i];
- val = strchr(ps[i], '=');
+ params = soup_form_decode(data);
- if (val == NULL) {
- continue;
- }
-
- *(val++) = 0;
- key = g_uri_unescape_string(key, NULL);
- val = g_uri_unescape_string(val, NULL);
- g_hash_table_replace(params, key, val);
+ if (isurl) {
+ soup_uri_free(uri);
}
- if (isurl) {
- g_free((gchar *) data);
- }
-
- g_strfreev(ps);
return params;
}
@@ -195,41 +90,6 @@
g_hash_table_destroy(params);
}
-gchar *
-fb_http_params_close(FbHttpParams *params, const gchar *url)
-{
- GHashTableIter iter;
- gpointer key;
- gpointer val;
- GString *ret;
-
- g_hash_table_iter_init(&iter, params);
- ret = g_string_new(NULL);
-
- while (g_hash_table_iter_next(&iter, &key, &val)) {
- if (val == NULL) {
- g_hash_table_iter_remove(&iter);
- continue;
- }
-
- if (ret->len > 0) {
- g_string_append_c(ret, '&');
- }
-
- g_string_append_uri_escaped(ret, key, NULL, TRUE);
- g_string_append_c(ret, '=');
- g_string_append_uri_escaped(ret, val, NULL, TRUE);
- }
-
- if (url != NULL) {
- g_string_prepend_c(ret, '?');
- g_string_prepend(ret, url);
- }
-
- fb_http_params_free(params);
- return g_string_free(ret, FALSE);
-}
-
static const gchar *
fb_http_params_get(FbHttpParams *params, const gchar *name, GError **error)
{
@@ -372,25 +232,9 @@
gboolean
fb_http_urlcmp(const gchar *url1, const gchar *url2, gboolean protocol)
{
- const gchar *str1;
- const gchar *str2;
+ SoupURI *uri1;
+ SoupURI *uri2;
gboolean ret = TRUE;
- gint int1;
- gint int2;
- guint i;
- PurpleHttpURL *purl1;
- PurpleHttpURL *purl2;
-
- static const gchar * (*funcs[]) (const PurpleHttpURL *url) = {
- /* Always first so it can be skipped */
- purple_http_url_get_protocol,
-
- purple_http_url_get_fragment,
- purple_http_url_get_host,
- purple_http_url_get_password,
- purple_http_url_get_path,
- purple_http_url_get_username
- };
if ((url1 == NULL) || (url2 == NULL)) {
return url1 == url2;
@@ -400,39 +244,28 @@
return TRUE;
}
- purl1 = purple_http_url_parse(url1);
+ uri1 = soup_uri_new(url1);
- if (purl1 == NULL) {
+ if (uri1 == NULL) {
return g_ascii_strcasecmp(url1, url2) == 0;
}
- purl2 = purple_http_url_parse(url2);
+ uri2 = soup_uri_new(url2);
- if (purl2 == NULL) {
- purple_http_url_free(purl1);
+ if (uri2 == NULL) {
+ soup_uri_free(uri1);
return g_ascii_strcasecmp(url1, url2) == 0;
}
- for (i = protocol ? 0 : 1; i < G_N_ELEMENTS(funcs); i++) {
- str1 = funcs[i](purl1);
- str2 = funcs[i](purl2);
-
- if (!purple_strequal(str1, str2)) {
- ret = FALSE;
- break;
- }
+ if (!protocol) {
+ /* Force the same scheme (and same port). */
+ soup_uri_set_scheme(uri1, SOUP_URI_SCHEME_HTTPS);
+ soup_uri_set_scheme(uri2, SOUP_URI_SCHEME_HTTPS);
}
- if (ret && protocol) {
- int1 = purple_http_url_get_port(purl1);
- int2 = purple_http_url_get_port(purl2);
+ ret = soup_uri_equal(uri1, uri2);
- if (int1 != int2) {
- ret = FALSE;
- }
- }
-
- purple_http_url_free(purl1);
- purple_http_url_free(purl2);
+ soup_uri_free(uri1);
+ soup_uri_free(uri2);
return ret;
}
--- a/libpurple/protocols/facebook/http.h Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/http.h Tue Oct 15 03:58:49 2019 +0000
@@ -32,6 +32,7 @@
*/
#include <glib.h>
+#include <libsoup/soup.h>
#include <libpurple/http.h>
@@ -43,13 +44,6 @@
#define FB_HTTP_ERROR fb_http_error_quark()
/**
- * FbHttpConns:
- *
- * Represents a set of #PurpleHttpConnection.
- */
-typedef struct _FbHttpConns FbHttpConns;
-
-/**
* FbHttpParams:
*
* Represents a set of key/value HTTP parameters.
@@ -80,89 +74,16 @@
fb_http_error_quark(void);
/**
- * fb_http_conns_new:
- *
- * Creates a new #FbHttpConns. The returned #FbHttpConns should be
- * freed with #fb_http_conns_free() when no longer needed.
- *
- * Returns: The new #FbHttpConns.
- */
-FbHttpConns *
-fb_http_conns_new(void);
-
-/**
- * fb_http_conns_free:
- * @cons: The #FbHttpConns.
- *
- * Frees all memory used by the #FbHttpConns. This will *not* cancel
- * the any of the added #PurpleHttpConnection.
- */
-void
-fb_http_conns_free(FbHttpConns *cons);
-
-/**
- * fb_http_conns_cancel_all:
- * @cons: The #FbHttpConns.
- *
- * Cancels each #PurpleHttpConnection in the #FbHttpConns.
- */
-void
-fb_http_conns_cancel_all(FbHttpConns *cons);
-
-/**
- * fb_http_conns_is_canceled:
- * @cons: The #FbHttpConns.
- *
- * Determines if the #FbHttpConns has been canceled.
- *
- * Returns: #TRUE if it has been canceled, otherwise #FALSE.
- */
-gboolean
-fb_http_conns_is_canceled(FbHttpConns *cons);
-
-/**
- * fb_http_conns_add:
- * @cons: The #FbHttpConns.
- * @con: The #PurpleHttpConnection.
- *
- * Adds a #PurpleHttpConnection to the #FbHttpConns.
- */
-void
-fb_http_conns_add(FbHttpConns *cons, PurpleHttpConnection *con);
-
-/**
- * fb_http_conns_remove:
- * @cons: The #FbHttpConns.
- * @con: The #PurpleHttpConnection.
- *
- * Removes a #PurpleHttpConnection from the #FbHttpConns.
- */
-void
-fb_http_conns_remove(FbHttpConns *cons, PurpleHttpConnection *con);
-
-/**
- * fb_http_conns_reset:
- * @cons: The #FbHttpConns.
- *
- * Resets the #FbHttpConns. This removes each #PurpleHttpConnection
- * from the #FbHttpConns *without* canceling it. This allows the the
- * #FbHttpConns to be reused.
- */
-void
-fb_http_conns_reset(FbHttpConns *cons);
-
-/**
* fb_http_error_chk:
- * @res: The #PurpleHttpResponse.
+ * @res: The #SoupMessage.
* @error: The return location for the #GError or #NULL.
*
- * Checks a #PurpleHttpResponse for success. This optionally assigns an
+ * Checks a #SoupMessage for success. This optionally assigns an
* appropriate #GError upon failure.
*
* Returns: #TRUE if the request was successful, otherwise #FALSE.
*/
-gboolean
-fb_http_error_chk(PurpleHttpResponse *res, GError **error);
+gboolean fb_http_error_chk(SoupMessage *res, GError **error);
/**
* fb_http_params_new:
@@ -203,21 +124,6 @@
fb_http_params_free(FbHttpParams *params);
/**
- * fb_http_params_close:
- * @params: The #FbHttpParams.
- * @url: The URL or #NULL.
- *
- * Closes the #FbHttpParams by returning a string representing the HTTP
- * parameters. If @url is non-#NULL, then the parameters are appended
- * to the value of @url. This frees the #FbHttpParams. The returned
- * string should be freed with #g_free() when no longer needed.
- *
- * Returns: The string representation of the HTTP parameters.
- */
-gchar *
-fb_http_params_close(FbHttpParams *params, const gchar *url);
-
-/**
* fb_http_params_get_bool:
* @params: The #FbHttpParams.
* @name: The parameter name.
--- a/libpurple/protocols/facebook/meson.build Sat Oct 12 22:49:37 2019 -0400
+++ b/libpurple/protocols/facebook/meson.build Tue Oct 15 03:58:49 2019 +0000
@@ -20,7 +20,7 @@
if DYNAMIC_FACEBOOK
facebook_prpl = shared_library('facebook', FACEBOOKSOURCES,
- dependencies : [json, libpurple_dep, glib],
+ dependencies : [json, libpurple_dep, libsoup, glib],
install : true, install_dir : PURPLE_PLUGINDIR)
# Used to produce docs.