--- a/libpurple/http.c Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/http.c Mon Dec 21 21:34:55 2015 -0500
@@ -1748,13 +1748,6 @@
"related to gc=%p (it shouldn't happen)\n", gc);
-gboolean purple_http_conn_is_cancelling(PurpleHttpConnection *http_conn)
- return http_conn->is_cancelling;
gboolean purple_http_conn_is_running(PurpleHttpConnection *http_conn)
--- a/libpurple/http.h Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/http.h Mon Dec 21 21:34:55 2015 -0500
@@ -222,16 +222,6 @@
void purple_http_conn_cancel_all(PurpleConnection *gc);
- * purple_http_conn_is_cancelling:
- * @http_conn: The HTTP connection (may be invalid pointer).
- * Checks, if provided HTTP request is cancelling.
- * Returns: TRUE, if provided connection is currently cancelling.
-gboolean purple_http_conn_is_cancelling(PurpleHttpConnection *http_conn);
* purple_http_conn_is_running:
* @http_conn: The HTTP connection (may be invalid pointer).
--- a/libpurple/protocols/facebook/api.c Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/protocols/facebook/api.c Mon Dec 21 21:34:55 2015 -0500
@@ -50,8 +50,9 @@
@@ -160,6 +161,7 @@
FbApiPrivate *priv = FB_API(obj)->priv;
+ 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)) {
@@ -167,14 +169,11 @@
- if (G_LIKELY(priv->gc != NULL)) {
- purple_http_conn_cancel_all(priv->gc);
if (G_UNLIKELY(priv->mqtt != NULL)) {
g_object_unref(priv->mqtt);
+ fb_http_conns_free(priv->cons); g_hash_table_destroy(priv->data);
g_hash_table_destroy(priv->mids);
@@ -485,6 +484,7 @@
priv = G_TYPE_INSTANCE_GET_PRIVATE(api, FB_TYPE_API, FbApiPrivate);
+ priv->cons = fb_http_conns_new(); priv->data = g_hash_table_new_full(g_direct_hash, g_direct_equal,
priv->mids = g_hash_table_new_full(g_int64_hash, g_int64_equal,
@@ -646,19 +646,20 @@
+ FbApiPrivate *priv = api->priv; - if (G_UNLIKELY(purple_http_conn_is_cancelling(con))) {
- /* Ignore canceling HTTP requests */
+ if (fb_http_conns_is_canceled(priv->cons)) { 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); emsg = g_strdup_printf("%s (%d)", msg, code);
@@ -755,6 +756,7 @@
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);
--- a/libpurple/protocols/facebook/data.c Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/protocols/facebook/data.c Mon Dec 21 21:34:55 2015 -0500
@@ -30,6 +30,7 @@
PurpleRoomlist *roomlist;
@@ -67,6 +68,7 @@
+ fb_http_conns_cancel_all(priv->cons); g_hash_table_iter_init(&iter, priv->evs);
while (g_hash_table_iter_next(&iter, NULL, &ptr)) {
@@ -77,6 +79,7 @@
g_object_unref(priv->api);
+ fb_http_conns_free(priv->cons); g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
g_hash_table_destroy(priv->imgs);
@@ -101,7 +104,9 @@
priv = G_TYPE_INSTANCE_GET_PRIVATE(fata, FB_TYPE_DATA, FbDataPrivate);
+ priv->cons = fb_http_conns_new(); priv->msgs = g_queue_new();
priv->imgs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
priv->unread = g_hash_table_new_full(fb_id_hash, fb_id_equal,
@@ -528,22 +533,25 @@
FbDataImagePrivate *priv = img->priv;
+ FbDataPrivate *driv = priv->fata->priv; - if (G_UNLIKELY(purple_http_conn_is_cancelling(con))) {
- /* Ignore canceling HTTP requests */
+ if (fb_http_conns_is_canceled(driv->cons)) { + fb_http_conns_remove(driv->cons, con); fb_http_error_chk(res, &err);
priv->image = (guint8*) purple_http_response_get_data(res, &priv->size);
- if (G_UNLIKELY(err != NULL)) {
+ if (G_LIKELY(err == NULL)) { + fb_data_image_queue(priv->fata); - fb_data_image_queue(priv->fata);
@@ -555,6 +563,7 @@
+ PurpleHttpConnection *con; g_return_if_fail(FB_IS_DATA(fata));
@@ -579,7 +588,8 @@
img->priv->active = TRUE;
url = fb_data_image_get_url(img);
- purple_http_get(priv->gc, fb_data_image_cb, img, url);
+ con = purple_http_get(priv->gc, fb_data_image_cb, img, url); + fb_http_conns_add(priv->cons, con); if (++active >= FB_DATA_ICON_MAX) {
--- a/libpurple/protocols/facebook/http.c Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/protocols/facebook/http.c Mon Dec 21 21:34:55 2015 -0500
@@ -25,6 +25,12 @@
fb_http_error_quark(void)
@@ -37,6 +43,74 @@
+ cons = g_new0(FbHttpConns, 1); + cons->cons = g_hash_table_new(g_direct_hash, g_direct_equal); +fb_http_conns_free(FbHttpConns *cons) + g_return_if_fail(cons != NULL); + g_hash_table_destroy(cons->cons); +fb_http_conns_cancel_all(FbHttpConns *cons) + g_return_if_fail(cons != NULL); + g_return_if_fail(!cons->canceled); + 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); +fb_http_conns_is_canceled(FbHttpConns *cons) + g_return_val_if_fail(cons != NULL, TRUE); +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); +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); +fb_http_conns_reset(FbHttpConns *cons) + g_return_if_fail(cons != NULL); + cons->canceled = FALSE; + g_hash_table_remove_all(cons->cons); fb_http_error_chk(PurpleHttpResponse *res, GError **error)
--- a/libpurple/protocols/facebook/http.h Mon Dec 21 21:08:54 2015 -0500
+++ b/libpurple/protocols/facebook/http.h Mon Dec 21 21:34:55 2015 -0500
@@ -43,6 +43,13 @@
#define FB_HTTP_ERROR fb_http_error_quark()
+ * Represents a set of #PurpleHttpConnection. +typedef struct _FbHttpConns FbHttpConns; * Represents a set of key/value HTTP parameters.
@@ -73,6 +80,78 @@
fb_http_error_quark(void);
+ * Creates a new #FbHttpConns. The returned #FbHttpConns should be + * freed with #fb_http_conns_free() when no longer needed. + * Returns: The new #FbHttpConns. +fb_http_conns_new(void); + * @cons: The #FbHttpConns. + * Frees all memory used by the #FbHttpConns. This will *not* cancel + * the any of the added #PurpleHttpConnection. +fb_http_conns_free(FbHttpConns *cons); + * fb_http_conns_cancel_all: + * @cons: The #FbHttpConns. + * Cancels each #PurpleHttpConnection in the #FbHttpConns. +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. +fb_http_conns_is_canceled(FbHttpConns *cons); + * @cons: The #FbHttpConns. + * @con: The #PurpleHttpConnection. + * Adds a #PurpleHttpConnection to the #FbHttpConns. +fb_http_conns_add(FbHttpConns *cons, PurpleHttpConnection *con); + * fb_http_conns_remove: + * @cons: The #FbHttpConns. + * @con: The #PurpleHttpConnection. + * Removes a #PurpleHttpConnection from the #FbHttpConns. +fb_http_conns_remove(FbHttpConns *cons, PurpleHttpConnection *con); + * @cons: The #FbHttpConns. + * Resets the #FbHttpConns. This removes each #PurpleHttpConnection + * from the #FbHttpConns *without* canceling it. This allows the the + * #FbHttpConns to be reused. +fb_http_conns_reset(FbHttpConns *cons); * @res: The #PurpleHttpResponse.
* @error: The return location for the #GError or #NULL.