| 18 * along with this program; if not, write to the Free Software |
18 * along with this program; if not, write to the Free Software |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 20 */ |
20 */ |
| 21 |
21 |
| 22 #include <json-glib/json-glib.h> |
22 #include <json-glib/json-glib.h> |
| |
23 #include <libsoup/soup.h> |
| 23 #include <stdarg.h> |
24 #include <stdarg.h> |
| 24 #include <string.h> |
25 #include <string.h> |
| 25 |
26 |
| 26 #include "glibcompat.h" |
27 #include "glibcompat.h" |
| 27 |
28 |
| 180 { |
181 { |
| 181 FbApiData *fata; |
182 FbApiData *fata; |
| 182 FbApiPrivate *priv = FB_API(obj)->priv; |
183 FbApiPrivate *priv = FB_API(obj)->priv; |
| 183 GHashTableIter iter; |
184 GHashTableIter iter; |
| 184 |
185 |
| 185 fb_http_conns_cancel_all(priv->cons); |
186 soup_session_abort(priv->cons); |
| 186 g_hash_table_iter_init(&iter, priv->data); |
187 g_hash_table_iter_init(&iter, priv->data); |
| 187 |
188 |
| 188 while (g_hash_table_iter_next(&iter, NULL, (gpointer) &fata)) { |
189 while (g_hash_table_iter_next(&iter, NULL, (gpointer) &fata)) { |
| 189 fata->func(fata->data); |
190 fata->func(fata->data); |
| 190 g_free(fata); |
191 g_free(fata); |
| 192 |
193 |
| 193 if (G_UNLIKELY(priv->mqtt != NULL)) { |
194 if (G_UNLIKELY(priv->mqtt != NULL)) { |
| 194 g_object_unref(priv->mqtt); |
195 g_object_unref(priv->mqtt); |
| 195 } |
196 } |
| 196 |
197 |
| 197 fb_http_conns_free(priv->cons); |
198 g_object_unref(priv->cons); |
| 198 g_hash_table_destroy(priv->data); |
199 g_hash_table_destroy(priv->data); |
| 199 g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free); |
200 g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free); |
| 200 |
201 |
| 201 g_free(priv->cid); |
202 g_free(priv->cid); |
| 202 g_free(priv->did); |
203 g_free(priv->did); |
| 684 |
685 |
| 685 return TRUE; |
686 return TRUE; |
| 686 } |
687 } |
| 687 |
688 |
| 688 static gboolean |
689 static gboolean |
| 689 fb_api_http_chk(FbApi *api, PurpleHttpConnection *con, PurpleHttpResponse *res, |
690 fb_api_http_chk(FbApi *api, SoupMessage *res, JsonNode **root) |
| 690 JsonNode **root) |
|
| 691 { |
691 { |
| 692 const gchar *data; |
692 const gchar *data; |
| 693 const gchar *msg; |
693 const gchar *msg; |
| 694 FbApiPrivate *priv = api->priv; |
|
| 695 gchar *emsg; |
|
| 696 GError *err = NULL; |
694 GError *err = NULL; |
| 697 gint code; |
695 gint code; |
| 698 gsize size; |
696 gsize size; |
| 699 |
697 |
| 700 if (fb_http_conns_is_canceled(priv->cons)) { |
698 msg = res->reason_phrase; |
| 701 return FALSE; |
699 code = res->status_code; |
| 702 } |
700 data = res->response_body->data; |
| 703 |
701 size = res->response_body->length; |
| 704 msg = purple_http_response_get_error(res); |
702 |
| 705 code = purple_http_response_get_code(res); |
703 fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Response (%p):", res); |
| 706 data = purple_http_response_get_data(res, &size); |
|
| 707 fb_http_conns_remove(priv->cons, con); |
|
| 708 |
|
| 709 if (msg != NULL) { |
704 if (msg != NULL) { |
| 710 emsg = g_strdup_printf("%s (%d)", msg, code); |
705 fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %s (%d)", msg, |
| |
706 code); |
| 711 } else { |
707 } else { |
| 712 emsg = g_strdup_printf("%d", code); |
708 fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %d", code); |
| 713 } |
709 } |
| 714 |
|
| 715 fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Response (%p):", con); |
|
| 716 fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Error: %s", emsg); |
|
| 717 g_free(emsg); |
|
| 718 |
710 |
| 719 if (G_LIKELY(size > 0)) { |
711 if (G_LIKELY(size > 0)) { |
| 720 fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Data: %.*s", |
712 fb_util_debug(FB_UTIL_DEBUG_INFO, " Response Data: %.*s", |
| 721 (gint) size, data); |
713 (gint) size, data); |
| 722 } |
714 } |
| 740 |
732 |
| 741 FB_API_ERROR_EMIT(api, err, return FALSE); |
733 FB_API_ERROR_EMIT(api, err, return FALSE); |
| 742 return TRUE; |
734 return TRUE; |
| 743 } |
735 } |
| 744 |
736 |
| 745 static PurpleHttpConnection * |
737 static SoupMessage * |
| 746 fb_api_http_req(FbApi *api, const gchar *url, const gchar *name, |
738 fb_api_http_req(FbApi *api, const gchar *url, const gchar *name, |
| 747 const gchar *method, FbHttpParams *params, |
739 const gchar *method, FbHttpParams *params, |
| 748 PurpleHttpCallback callback) |
740 SoupSessionCallback callback) |
| 749 { |
741 { |
| 750 FbApiPrivate *priv = api->priv; |
742 FbApiPrivate *priv = api->priv; |
| 751 gchar *data; |
743 gchar *data; |
| 752 gchar *key; |
744 gchar *key; |
| 753 gchar *val; |
745 gchar *val; |
| 754 GList *keys; |
746 GList *keys; |
| 755 GList *l; |
747 GList *l; |
| 756 GString *gstr; |
748 GString *gstr; |
| 757 PurpleHttpConnection *ret; |
749 SoupMessage *msg; |
| 758 PurpleHttpRequest *req; |
|
| 759 |
750 |
| 760 fb_http_params_set_str(params, "api_key", FB_API_KEY); |
751 fb_http_params_set_str(params, "api_key", FB_API_KEY); |
| 761 fb_http_params_set_str(params, "device_id", priv->did); |
752 fb_http_params_set_str(params, "device_id", priv->did); |
| 762 fb_http_params_set_str(params, "fb_api_req_friendly_name", name); |
753 fb_http_params_set_str(params, "fb_api_req_friendly_name", name); |
| 763 fb_http_params_set_str(params, "format", "json"); |
754 fb_http_params_set_str(params, "format", "json"); |
| 765 |
756 |
| 766 val = fb_util_get_locale(); |
757 val = fb_util_get_locale(); |
| 767 fb_http_params_set_str(params, "locale", val); |
758 fb_http_params_set_str(params, "locale", val); |
| 768 g_free(val); |
759 g_free(val); |
| 769 |
760 |
| 770 req = purple_http_request_new(url); |
761 msg = soup_message_new("POST", url); |
| 771 purple_http_request_set_max_len(req, -1); |
|
| 772 purple_http_request_set_method(req, "POST"); |
|
| 773 |
762 |
| 774 /* Ensure an old signature is not computed */ |
763 /* Ensure an old signature is not computed */ |
| 775 g_hash_table_remove(params, "sig"); |
764 g_hash_table_remove(params, "sig"); |
| 776 |
765 |
| 777 gstr = g_string_new(NULL); |
766 gstr = g_string_new(NULL); |
| 792 g_list_free(keys); |
781 g_list_free(keys); |
| 793 g_free(data); |
782 g_free(data); |
| 794 |
783 |
| 795 if (priv->token != NULL) { |
784 if (priv->token != NULL) { |
| 796 data = g_strdup_printf("OAuth %s", priv->token); |
785 data = g_strdup_printf("OAuth %s", priv->token); |
| 797 purple_http_request_header_set(req, "Authorization", data); |
786 soup_message_headers_replace(msg->request_headers, "Authorization", |
| |
787 data); |
| 798 g_free(data); |
788 g_free(data); |
| 799 } |
789 } |
| 800 |
790 |
| 801 purple_http_request_header_set(req, "User-Agent", FB_API_AGENT); |
791 soup_message_headers_replace(msg->request_headers, "User-Agent", |
| 802 purple_http_request_header_set(req, "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); |
792 FB_API_AGENT); |
| 803 |
793 |
| 804 data = fb_http_params_close(params, NULL); |
794 data = fb_http_params_close(params, NULL); |
| 805 purple_http_request_set_contents(req, data, -1); |
795 soup_message_set_request(msg, |
| 806 ret = purple_http_request(priv->gc, req, callback, api); |
796 "application/x-www-form-urlencoded; charset=utf-8", |
| 807 fb_http_conns_add(priv->cons, ret); |
797 SOUP_MEMORY_TAKE, data, -1); |
| 808 purple_http_request_unref(req); |
798 soup_session_queue_message(priv->cons, msg, callback, api); |
| 809 |
799 |
| 810 fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", ret); |
800 fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", msg); |
| 811 fb_util_debug(FB_UTIL_DEBUG_INFO, " Request URL: %s", url); |
801 fb_util_debug(FB_UTIL_DEBUG_INFO, " Request URL: %s", url); |
| 812 fb_util_debug(FB_UTIL_DEBUG_INFO, " Request Data: %s", data); |
802 fb_util_debug(FB_UTIL_DEBUG_INFO, " Request Data: %s", data); |
| 813 |
803 |
| 814 g_free(data); |
804 return msg; |
| 815 return ret; |
805 } |
| 816 } |
806 |
| 817 |
807 static SoupMessage * |
| 818 static PurpleHttpConnection * |
|
| 819 fb_api_http_query(FbApi *api, gint64 query, JsonBuilder *builder, |
808 fb_api_http_query(FbApi *api, gint64 query, JsonBuilder *builder, |
| 820 PurpleHttpCallback hcb) |
809 SoupSessionCallback hcb) |
| 821 { |
810 { |
| 822 const gchar *name; |
811 const gchar *name; |
| 823 FbHttpParams *prms; |
812 FbHttpParams *prms; |
| 824 gchar *json; |
813 gchar *json; |
| 825 |
814 |
| 863 |
852 |
| 864 return fb_api_http_req(api, FB_API_URL_GQL, name, "get", prms, hcb); |
853 return fb_api_http_req(api, FB_API_URL_GQL, name, "get", prms, hcb); |
| 865 } |
854 } |
| 866 |
855 |
| 867 static void |
856 static void |
| 868 fb_api_cb_http_bool(PurpleHttpConnection *con, PurpleHttpResponse *res, |
857 fb_api_cb_http_bool(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 869 gpointer data) |
858 gpointer data) |
| 870 { |
859 { |
| 871 const gchar *hata; |
|
| 872 FbApi *api = data; |
860 FbApi *api = data; |
| 873 |
861 |
| 874 if (!fb_api_http_chk(api, con, res, NULL)) { |
862 if (!fb_api_http_chk(api, res, NULL)) { |
| 875 return; |
863 return; |
| 876 } |
864 } |
| 877 |
865 |
| 878 hata = purple_http_response_get_data(res, NULL); |
866 if (!purple_strequal(res->response_body->data, "true")) { |
| 879 |
|
| 880 if (!purple_strequal(hata, "true")) { |
|
| 881 fb_api_error_literal(api, FB_API_ERROR, |
867 fb_api_error_literal(api, FB_API_ERROR, |
| 882 _("Failed generic API operation")); |
868 _("Failed generic API operation")); |
| 883 } |
869 } |
| 884 } |
870 } |
| 885 |
871 |
| 1055 fb_util_debug_info("Reconnected the MQTT stream"); |
1041 fb_util_debug_info("Reconnected the MQTT stream"); |
| 1056 } |
1042 } |
| 1057 } |
1043 } |
| 1058 |
1044 |
| 1059 static void |
1045 static void |
| 1060 fb_api_cb_seqid(PurpleHttpConnection *con, PurpleHttpResponse *res, |
1046 fb_api_cb_seqid(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 1061 gpointer data) |
1047 gpointer data) |
| 1062 { |
1048 { |
| 1063 const gchar *str; |
1049 const gchar *str; |
| 1064 FbApi *api = data; |
1050 FbApi *api = data; |
| 1065 FbApiPrivate *priv = api->priv; |
1051 FbApiPrivate *priv = api->priv; |
| 1066 FbJsonValues *values; |
1052 FbJsonValues *values; |
| 1067 GError *err = NULL; |
1053 GError *err = NULL; |
| 1068 JsonNode *root; |
1054 JsonNode *root; |
| 1069 |
1055 |
| 1070 if (!fb_api_http_chk(api, con, res, &root)) { |
1056 if (!fb_api_http_chk(api, res, &root)) { |
| 1071 return; |
1057 return; |
| 1072 } |
1058 } |
| 1073 |
1059 |
| 1074 values = fb_json_values_new(root); |
1060 values = fb_json_values_new(root); |
| 1075 fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, |
1061 fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, |
| 2081 guint i; |
2067 guint i; |
| 2082 JsonNode *root; |
2068 JsonNode *root; |
| 2083 |
2069 |
| 2084 static const gchar *imgexts[] = {".jpg", ".png", ".gif"}; |
2070 static const gchar *imgexts[] = {".jpg", ".png", ".gif"}; |
| 2085 |
2071 |
| 2086 if (!fb_api_http_chk(api, con, res, &root)) { |
2072 if (!fb_api_http_chk(api, res, &root)) { |
| 2087 return; |
2073 return; |
| 2088 } |
2074 } |
| 2089 |
2075 |
| 2090 values = fb_json_values_new(root); |
2076 values = fb_json_values_new(root); |
| 2091 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.filename"); |
2077 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.filename"); |
| 2096 g_object_unref(values); |
2082 g_object_unref(values); |
| 2097 json_node_free(root); |
2083 json_node_free(root); |
| 2098 return; |
2084 return; |
| 2099 ); |
2085 ); |
| 2100 |
2086 |
| 2101 msg = fb_api_data_take(api, con); |
2087 msg = fb_api_data_take(api, res); |
| 2102 str = fb_json_values_next_str(values, NULL); |
2088 str = fb_json_values_next_str(values, NULL); |
| 2103 name = g_ascii_strdown(str, -1); |
2089 name = g_ascii_strdown(str, -1); |
| 2104 |
2090 |
| 2105 for (i = 0; i < G_N_ELEMENTS(imgexts); i++) { |
2091 for (i = 0; i < G_N_ELEMENTS(imgexts); i++) { |
| 2106 if (g_str_has_suffix(name, imgexts[i])) { |
2092 if (g_str_has_suffix(name, imgexts[i])) { |
| 2122 |
2108 |
| 2123 static void |
2109 static void |
| 2124 fb_api_attach(FbApi *api, FbId aid, const gchar *msgid, FbApiMessage *msg) |
2110 fb_api_attach(FbApi *api, FbId aid, const gchar *msgid, FbApiMessage *msg) |
| 2125 { |
2111 { |
| 2126 FbHttpParams *prms; |
2112 FbHttpParams *prms; |
| 2127 PurpleHttpConnection *http; |
2113 SoupMessage *http; |
| 2128 |
2114 |
| 2129 prms = fb_http_params_new(); |
2115 prms = fb_http_params_new(); |
| 2130 fb_http_params_set_str(prms, "mid", msgid); |
2116 fb_http_params_set_str(prms, "mid", msgid); |
| 2131 fb_http_params_set_strf(prms, "aid", "%" FB_ID_FORMAT, aid); |
2117 fb_http_params_set_strf(prms, "aid", "%" FB_ID_FORMAT, aid); |
| 2132 |
2118 |
| 2135 fb_api_cb_attach); |
2121 fb_api_cb_attach); |
| 2136 fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free); |
2122 fb_api_data_set(api, http, msg, (GDestroyNotify) fb_api_message_free); |
| 2137 } |
2123 } |
| 2138 |
2124 |
| 2139 static void |
2125 static void |
| 2140 fb_api_cb_auth(PurpleHttpConnection *con, PurpleHttpResponse *res, |
2126 fb_api_cb_auth(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 2141 gpointer data) |
2127 gpointer data) |
| 2142 { |
2128 { |
| 2143 FbApi *api = data; |
2129 FbApi *api = data; |
| 2144 FbApiPrivate *priv = api->priv; |
2130 FbApiPrivate *priv = api->priv; |
| 2145 FbJsonValues *values; |
2131 FbJsonValues *values; |
| 2146 GError *err = NULL; |
2132 GError *err = NULL; |
| 2147 JsonNode *root; |
2133 JsonNode *root; |
| 2148 |
2134 |
| 2149 if (!fb_api_http_chk(api, con, res, &root)) { |
2135 if (!fb_api_http_chk(api, res, &root)) { |
| 2150 return; |
2136 return; |
| 2151 } |
2137 } |
| 2152 |
2138 |
| 2153 values = fb_json_values_new(root); |
2139 values = fb_json_values_new(root); |
| 2154 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.access_token"); |
2140 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.access_token"); |
| 2203 |
2189 |
| 2204 return csum; |
2190 return csum; |
| 2205 } |
2191 } |
| 2206 |
2192 |
| 2207 static void |
2193 static void |
| 2208 fb_api_cb_contact(PurpleHttpConnection *con, PurpleHttpResponse *res, |
2194 fb_api_cb_contact(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 2209 gpointer data) |
2195 gpointer data) |
| 2210 { |
2196 { |
| 2211 const gchar *str; |
2197 const gchar *str; |
| 2212 FbApi *api = data; |
2198 FbApi *api = data; |
| 2213 FbApiUser user; |
2199 FbApiUser user; |
| 2214 FbJsonValues *values; |
2200 FbJsonValues *values; |
| 2215 GError *err = NULL; |
2201 GError *err = NULL; |
| 2216 JsonNode *node; |
2202 JsonNode *node; |
| 2217 JsonNode *root; |
2203 JsonNode *root; |
| 2218 |
2204 |
| 2219 if (!fb_api_http_chk(api, con, res, &root)) { |
2205 if (!fb_api_http_chk(api, res, &root)) { |
| 2220 return; |
2206 return; |
| 2221 } |
2207 } |
| 2222 |
2208 |
| 2223 node = fb_json_node_get_nth(root, 0); |
2209 node = fb_json_node_get_nth(root, 0); |
| 2224 |
2210 |
| 2373 GSList *users = NULL; |
2359 GSList *users = NULL; |
| 2374 JsonNode *root; |
2360 JsonNode *root; |
| 2375 JsonNode *croot; |
2361 JsonNode *croot; |
| 2376 JsonNode *node; |
2362 JsonNode *node; |
| 2377 |
2363 |
| 2378 if (!fb_api_http_chk(api, con, res, &root)) { |
2364 if (!fb_api_http_chk(api, res, &root)) { |
| 2379 return; |
2365 return; |
| 2380 } |
2366 } |
| 2381 |
2367 |
| 2382 croot = fb_json_node_get(root, "$.viewer.messenger_contacts.deltas", NULL); |
2368 croot = fb_json_node_get(root, "$.viewer.messenger_contacts.deltas", NULL); |
| 2383 is_delta = (croot != NULL); |
2369 is_delta = (croot != NULL); |
| 2816 g_object_unref(values); |
2802 g_object_unref(values); |
| 2817 json_node_free(root); |
2803 json_node_free(root); |
| 2818 } |
2804 } |
| 2819 |
2805 |
| 2820 static void |
2806 static void |
| 2821 fb_api_cb_unread(PurpleHttpConnection *con, PurpleHttpResponse *res, |
2807 fb_api_cb_unread(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 2822 gpointer data) |
2808 gpointer data) |
| 2823 { |
2809 { |
| 2824 const gchar *id; |
2810 const gchar *id; |
| 2825 FbApi *api = data; |
2811 FbApi *api = data; |
| 2826 FbJsonValues *values; |
2812 FbJsonValues *values; |
| 2827 GError *err = NULL; |
2813 GError *err = NULL; |
| 2828 gint64 count; |
2814 gint64 count; |
| 2829 JsonBuilder *bldr; |
2815 JsonBuilder *bldr; |
| 2830 JsonNode *root; |
2816 JsonNode *root; |
| 2831 |
2817 |
| 2832 if (!fb_api_http_chk(api, con, res, &root)) { |
2818 if (!fb_api_http_chk(api, res, &root)) { |
| 2833 return; |
2819 return; |
| 2834 } |
2820 } |
| 2835 |
2821 |
| 2836 values = fb_json_values_new(root); |
2822 values = fb_json_values_new(root); |
| 2837 fb_json_values_add(values, FB_JSON_TYPE_INT, TRUE, "$.unread_count"); |
2823 fb_json_values_add(values, FB_JSON_TYPE_INT, TRUE, "$.unread_count"); |
| 2897 fb_api_http_query(api, FB_API_QUERY_THREADS, bldr, |
2883 fb_api_http_query(api, FB_API_QUERY_THREADS, bldr, |
| 2898 fb_api_cb_unread); |
2884 fb_api_cb_unread); |
| 2899 } |
2885 } |
| 2900 |
2886 |
| 2901 static void |
2887 static void |
| 2902 fb_api_cb_sticker(PurpleHttpConnection *con, PurpleHttpResponse *res, |
2888 fb_api_cb_sticker(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 2903 gpointer data) |
2889 gpointer data) |
| 2904 { |
2890 { |
| 2905 FbApi *api = data; |
2891 FbApi *api = data; |
| 2906 FbApiMessage *msg; |
2892 FbApiMessage *msg; |
| 2907 FbJsonValues *values; |
2893 FbJsonValues *values; |
| 2908 GError *err = NULL; |
2894 GError *err = NULL; |
| 2909 GSList *msgs = NULL; |
2895 GSList *msgs = NULL; |
| 2910 JsonNode *node; |
2896 JsonNode *node; |
| 2911 JsonNode *root; |
2897 JsonNode *root; |
| 2912 |
2898 |
| 2913 if (!fb_api_http_chk(api, con, res, &root)) { |
2899 if (!fb_api_http_chk(api, res, &root)) { |
| 2914 return; |
2900 return; |
| 2915 } |
2901 } |
| 2916 |
2902 |
| 2917 node = fb_json_node_get_nth(root, 0); |
2903 node = fb_json_node_get_nth(root, 0); |
| 2918 values = fb_json_values_new(node); |
2904 values = fb_json_values_new(node); |
| 2924 g_object_unref(values); |
2910 g_object_unref(values); |
| 2925 json_node_free(root); |
2911 json_node_free(root); |
| 2926 return; |
2912 return; |
| 2927 ); |
2913 ); |
| 2928 |
2914 |
| 2929 msg = fb_api_data_take(api, con); |
2915 msg = fb_api_data_take(api, res); |
| 2930 msg->flags |= FB_API_MESSAGE_FLAG_IMAGE; |
2916 msg->flags |= FB_API_MESSAGE_FLAG_IMAGE; |
| 2931 msg->text = fb_json_values_next_str_dup(values, NULL); |
2917 msg->text = fb_json_values_next_str_dup(values, NULL); |
| 2932 msgs = g_slist_prepend(msgs, msg); |
2918 msgs = g_slist_prepend(msgs, msg); |
| 2933 |
2919 |
| 2934 g_signal_emit_by_name(api, "messages", msgs); |
2920 g_signal_emit_by_name(api, "messages", msgs); |
| 2939 |
2925 |
| 2940 static void |
2926 static void |
| 2941 fb_api_sticker(FbApi *api, FbId sid, FbApiMessage *msg) |
2927 fb_api_sticker(FbApi *api, FbId sid, FbApiMessage *msg) |
| 2942 { |
2928 { |
| 2943 JsonBuilder *bldr; |
2929 JsonBuilder *bldr; |
| 2944 PurpleHttpConnection *http; |
2930 SoupMessage *http; |
| 2945 |
2931 |
| 2946 bldr = fb_json_bldr_new(JSON_NODE_OBJECT); |
2932 bldr = fb_json_bldr_new(JSON_NODE_OBJECT); |
| 2947 fb_json_bldr_arr_begin(bldr, "0"); |
2933 fb_json_bldr_arr_begin(bldr, "0"); |
| 2948 fb_json_bldr_add_strf(bldr, NULL, "%" FB_ID_FORMAT, sid); |
2934 fb_json_bldr_add_strf(bldr, NULL, "%" FB_ID_FORMAT, sid); |
| 2949 fb_json_bldr_arr_end(bldr); |
2935 fb_json_bldr_arr_end(bldr); |
| 3026 g_object_unref(values); |
3012 g_object_unref(values); |
| 3027 return TRUE; |
3013 return TRUE; |
| 3028 } |
3014 } |
| 3029 |
3015 |
| 3030 static void |
3016 static void |
| 3031 fb_api_cb_thread(PurpleHttpConnection *con, PurpleHttpResponse *res, |
3017 fb_api_cb_thread(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 3032 gpointer data) |
3018 gpointer data) |
| 3033 { |
3019 { |
| 3034 FbApi *api = data; |
3020 FbApi *api = data; |
| 3035 FbApiThread thrd; |
3021 FbApiThread thrd; |
| 3036 GError *err = NULL; |
3022 GError *err = NULL; |
| 3037 JsonNode *node; |
3023 JsonNode *node; |
| 3038 JsonNode *root; |
3024 JsonNode *root; |
| 3039 |
3025 |
| 3040 if (!fb_api_http_chk(api, con, res, &root)) { |
3026 if (!fb_api_http_chk(api, res, &root)) { |
| 3041 return; |
3027 return; |
| 3042 } |
3028 } |
| 3043 |
3029 |
| 3044 node = fb_json_node_get_nth(root, 0); |
3030 node = fb_json_node_get_nth(root, 0); |
| 3045 |
3031 |
| 3086 fb_json_bldr_add_str(bldr, "13", "false"); |
3072 fb_json_bldr_add_str(bldr, "13", "false"); |
| 3087 fb_api_http_query(api, FB_API_QUERY_THREAD, bldr, fb_api_cb_thread); |
3073 fb_api_http_query(api, FB_API_QUERY_THREAD, bldr, fb_api_cb_thread); |
| 3088 } |
3074 } |
| 3089 |
3075 |
| 3090 static void |
3076 static void |
| 3091 fb_api_cb_thread_create(PurpleHttpConnection *con, PurpleHttpResponse *res, |
3077 fb_api_cb_thread_create(G_GNUC_UNUSED SoupSession *session, SoupMessage *res, |
| 3092 gpointer data) |
3078 gpointer data) |
| 3093 { |
3079 { |
| 3094 const gchar *str; |
3080 const gchar *str; |
| 3095 FbApi *api = data; |
3081 FbApi *api = data; |
| 3096 FbId tid; |
3082 FbId tid; |
| 3097 FbJsonValues *values; |
3083 FbJsonValues *values; |
| 3098 GError *err = NULL; |
3084 GError *err = NULL; |
| 3099 JsonNode *root; |
3085 JsonNode *root; |
| 3100 |
3086 |
| 3101 if (!fb_api_http_chk(api, con, res, &root)) { |
3087 if (!fb_api_http_chk(api, res, &root)) { |
| 3102 return; |
3088 return; |
| 3103 } |
3089 } |
| 3104 |
3090 |
| 3105 values = fb_json_values_new(root); |
3091 values = fb_json_values_new(root); |
| 3106 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.id"); |
3092 fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.id"); |