| 177 |
168 |
| 178 |
169 |
| 179 static void |
170 static void |
| 180 fb_api_dispose(GObject *obj) |
171 fb_api_dispose(GObject *obj) |
| 181 { |
172 { |
| 182 FbApiData *fata; |
|
| 183 FbApiPrivate *priv = FB_API(obj)->priv; |
173 FbApiPrivate *priv = FB_API(obj)->priv; |
| 184 GHashTableIter iter; |
|
| 185 |
174 |
| 186 soup_session_abort(priv->cons); |
175 soup_session_abort(priv->cons); |
| 187 g_hash_table_iter_init(&iter, priv->data); |
|
| 188 |
|
| 189 while (g_hash_table_iter_next(&iter, NULL, (gpointer) &fata)) { |
|
| 190 fata->func(fata->data); |
|
| 191 g_free(fata); |
|
| 192 } |
|
| 193 |
176 |
| 194 if (G_UNLIKELY(priv->mqtt != NULL)) { |
177 if (G_UNLIKELY(priv->mqtt != NULL)) { |
| 195 g_object_unref(priv->mqtt); |
178 g_object_unref(priv->mqtt); |
| 196 } |
179 } |
| 197 |
180 |
| 198 g_object_unref(priv->cons); |
181 g_object_unref(priv->cons); |
| 199 g_hash_table_destroy(priv->data); |
|
| 200 g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free); |
182 g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free); |
| 201 |
183 |
| 202 g_free(priv->cid); |
184 g_free(priv->cid); |
| 203 g_free(priv->did); |
185 g_free(priv->did); |
| 204 g_free(priv->stoken); |
186 g_free(priv->stoken); |
| 537 if (G_UNLIKELY(q == 0)) { |
517 if (G_UNLIKELY(q == 0)) { |
| 538 q = g_quark_from_static_string("fb-api-error-quark"); |
518 q = g_quark_from_static_string("fb-api-error-quark"); |
| 539 } |
519 } |
| 540 |
520 |
| 541 return q; |
521 return q; |
| 542 } |
|
| 543 |
|
| 544 static void |
|
| 545 fb_api_data_set(FbApi *api, gpointer handle, gpointer data, |
|
| 546 GDestroyNotify func) |
|
| 547 { |
|
| 548 FbApiData *fata; |
|
| 549 FbApiPrivate *priv = api->priv; |
|
| 550 |
|
| 551 fata = g_new0(FbApiData, 1); |
|
| 552 fata->data = data; |
|
| 553 fata->func = func; |
|
| 554 g_hash_table_replace(priv->data, handle, fata); |
|
| 555 } |
|
| 556 |
|
| 557 static gpointer |
|
| 558 fb_api_data_take(FbApi *api, gconstpointer handle) |
|
| 559 { |
|
| 560 FbApiData *fata; |
|
| 561 FbApiPrivate *priv = api->priv; |
|
| 562 gpointer data; |
|
| 563 |
|
| 564 fata = g_hash_table_lookup(priv->data, handle); |
|
| 565 |
|
| 566 if (fata == NULL) { |
|
| 567 return NULL; |
|
| 568 } |
|
| 569 |
|
| 570 data = fata->data; |
|
| 571 g_hash_table_remove(priv->data, handle); |
|
| 572 g_free(fata); |
|
| 573 return data; |
|
| 574 } |
522 } |
| 575 |
523 |
| 576 static gboolean |
524 static gboolean |
| 577 fb_api_json_chk(FbApi *api, gconstpointer data, gssize size, JsonNode **node) |
525 fb_api_json_chk(FbApi *api, gconstpointer data, gssize size, JsonNode **node) |
| 578 { |
526 { |
| 2082 g_object_unref(values); |
2030 g_object_unref(values); |
| 2083 json_node_free(root); |
2031 json_node_free(root); |
| 2084 return; |
2032 return; |
| 2085 ); |
2033 ); |
| 2086 |
2034 |
| 2087 msg = fb_api_data_take(api, res); |
2035 msg = g_object_steal_data(G_OBJECT(res), "fb-api-msg"); |
| 2088 str = fb_json_values_next_str(values, NULL); |
2036 str = fb_json_values_next_str(values, NULL); |
| 2089 name = g_ascii_strdown(str, -1); |
2037 name = g_ascii_strdown(str, -1); |
| 2090 |
2038 |
| 2091 for (i = 0; i < G_N_ELEMENTS(imgexts); i++) { |
2039 for (i = 0; i < G_N_ELEMENTS(imgexts); i++) { |
| 2092 if (g_str_has_suffix(name, imgexts[i])) { |
2040 if (g_str_has_suffix(name, imgexts[i])) { |
| 2117 fb_http_params_set_strf(prms, "aid", "%" FB_ID_FORMAT, aid); |
2065 fb_http_params_set_strf(prms, "aid", "%" FB_ID_FORMAT, aid); |
| 2118 |
2066 |
| 2119 http = fb_api_http_req(api, FB_API_URL_ATTACH, "getAttachment", |
2067 http = fb_api_http_req(api, FB_API_URL_ATTACH, "getAttachment", |
| 2120 "messaging.getAttachment", prms, |
2068 "messaging.getAttachment", prms, |
| 2121 fb_api_cb_attach); |
2069 fb_api_cb_attach); |
| 2122 fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free); |
2070 g_object_set_data_full(G_OBJECT(http), "fb-api-msg", msg, |
| |
2071 (GDestroyNotify)fb_api_message_free); |
| 2123 } |
2072 } |
| 2124 |
2073 |
| 2125 static void |
2074 static void |
| 2126 fb_api_cb_auth(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
2075 fb_api_cb_auth(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 2127 gpointer data) |
2076 gpointer data) |
| 2910 g_object_unref(values); |
2859 g_object_unref(values); |
| 2911 json_node_free(root); |
2860 json_node_free(root); |
| 2912 return; |
2861 return; |
| 2913 ); |
2862 ); |
| 2914 |
2863 |
| 2915 msg = fb_api_data_take(api, res); |
2864 msg = g_object_steal_data(G_OBJECT(res), "fb-api-msg"); |
| 2916 msg->flags |= FB_API_MESSAGE_FLAG_IMAGE; |
2865 msg->flags |= FB_API_MESSAGE_FLAG_IMAGE; |
| 2917 msg->text = fb_json_values_next_str_dup(values, NULL); |
2866 msg->text = fb_json_values_next_str_dup(values, NULL); |
| 2918 msgs = g_slist_prepend(msgs, msg); |
2867 msgs = g_slist_prepend(msgs, msg); |
| 2919 |
2868 |
| 2920 g_signal_emit_by_name(api, "messages", msgs); |
2869 g_signal_emit_by_name(api, "messages", msgs); |
| 2934 fb_json_bldr_add_strf(bldr, NULL, "%" FB_ID_FORMAT, sid); |
2883 fb_json_bldr_add_strf(bldr, NULL, "%" FB_ID_FORMAT, sid); |
| 2935 fb_json_bldr_arr_end(bldr); |
2884 fb_json_bldr_arr_end(bldr); |
| 2936 |
2885 |
| 2937 http = fb_api_http_query(api, FB_API_QUERY_STICKER, bldr, |
2886 http = fb_api_http_query(api, FB_API_QUERY_STICKER, bldr, |
| 2938 fb_api_cb_sticker); |
2887 fb_api_cb_sticker); |
| 2939 fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free); |
2888 g_object_set_data_full(G_OBJECT(http), "fb-api-msg", msg, |
| |
2889 (GDestroyNotify)fb_api_message_free); |
| 2940 } |
2890 } |
| 2941 |
2891 |
| 2942 static gboolean |
2892 static gboolean |
| 2943 fb_api_thread_parse(FbApi *api, FbApiThread *thrd, JsonNode *root, |
2893 fb_api_thread_parse(FbApi *api, FbApiThread *thrd, JsonNode *root, |
| 2944 GError **error) |
2894 GError **error) |