/cpw/tomkiewicz/http: 7f67e9178ed9: Fix compilation from clean w...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Sat Oct 20 06:07:30 EDT 2012
Changeset: 7f67e9178ed95d1ae288c947b89e550246dcac10
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2012-10-20 12:07 +0200
Branch: default
URL: http://hg.pidgin.im/cpw/tomkiewicz/http/rev/7f67e9178ed9
Description:
Fix compilation from clean working directory
diffstat:
configure.ac | 3 +
libpurple/plugins/perl/common/Util.xs | 51 -------------
libpurple/plugins/perl/common/module.h | 1 -
libpurple/protocols/gg/Makefile.am | 7 +-
libpurple/protocols/gg/gg.c | 127 +++++++++++++++++++++++++++++++-
5 files changed, 128 insertions(+), 61 deletions(-)
diffs (truncated from 306 to 300 lines):
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -821,6 +821,9 @@ dnl ####################################
PKG_CHECK_MODULES([JSON], [json-glib-1.0], [enable_json="yes"], [enable_json="no"])
+AC_SUBST(JSON_CFLAGS)
+AC_SUBST(JSON_LIBS)
+
dnl #######################################################################
dnl # Check for zlib (required)
dnl #######################################################################
diff --git a/libpurple/plugins/perl/common/Util.xs b/libpurple/plugins/perl/common/Util.xs
--- a/libpurple/plugins/perl/common/Util.xs
+++ b/libpurple/plugins/perl/common/Util.xs
@@ -1,31 +1,5 @@
#include "module.h"
-static void
-purple_perl_util_url_cb(PurpleUtilFetchUrlData *url_data, void *user_data,
- const gchar *url_text, size_t size,
- const gchar *error_message)
-{
- SV *sv = (SV *)user_data;
- dSP;
- ENTER;
- SAVETMPS;
- PUSHMARK(SP);
-
- XPUSHs(sv_2mortal(newSVpvn(url_text, size)));
- PUTBACK;
-
- call_sv(sv, G_EVAL | G_SCALAR);
- SPAGAIN;
-
- /* XXX Make sure this destroys it correctly and that we don't want
- * something like sv_2mortal(sv) or something else here instead. */
- SvREFCNT_dec(sv);
-
- PUTBACK;
- FREETMPS;
- LEAVE;
-}
-
static void markup_find_tag_foreach(GQuark key_id, char *data, HV *hv) {
const char *key = NULL;
key = g_quark_to_string(key_id);
@@ -460,31 +434,6 @@ purple_markup_unescape_entity(text)
MODULE = Purple::Util PACKAGE = Purple::Util PREFIX = purple_util_
PROTOTYPES: ENABLE
- #XXX: expand...
-void
-purple_util_fetch_url(plugin, url, full, user_agent, http11, max_len, cb)
- Purple::Plugin plugin
- const char *url
- gboolean full
- const char *user_agent
- gboolean http11
- gssize max_len
- SV * cb
-PREINIT:
- PurpleUtilFetchUrlData *data;
-PPCODE:
- /* XXX: i don't like this... only plugins can use it... */
- SV *sv = purple_perl_sv_from_fun(plugin, cb);
-
- if (sv != NULL) {
- data = purple_util_fetch_url(url, full, user_agent, http11, max_len,
- purple_perl_util_url_cb, sv);
- XPUSHs(sv_2mortal(purple_perl_bless_object(data, "Purple::Util::FetchUrlData")));
- } else {
- purple_debug_warning("perl", "Callback not a valid type, only strings and coderefs allowed in purple_util_fetch_url.\n");
- XSRETURN_UNDEF;
- }
-
void
purple_util_set_user_dir(dir)
const char *dir
diff --git a/libpurple/plugins/perl/common/module.h b/libpurple/plugins/perl/common/module.h
--- a/libpurple/plugins/perl/common/module.h
+++ b/libpurple/plugins/perl/common/module.h
@@ -271,7 +271,6 @@ typedef PurpleStringref * Purple__Stri
/* util.h */
typedef PurpleInfoFieldFormatCallback Purple__Util__InfoFieldFormatCallback;
-typedef PurpleUtilFetchUrlData Purple__Util__FetchUrlData;
typedef PurpleMenuAction * Purple__Menu__Action;
/* value.h */
diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -1,4 +1,4 @@
-#V=0
+V=1
#GADU_EXTRA_WARNINGS = -Wall -Wextra -Werror
pkgdir = $(libdir)/purple-$(PURPLE_MAJOR_VERSION)
@@ -106,14 +106,14 @@ st = -DPURPLE_STATIC_PRPL $(GADU_CFLAGS)
noinst_LTLIBRARIES = libgg.la
libgg_la_SOURCES = $(GGSOURCES)
libgg_la_CFLAGS = $(AM_CFLAGS)
-libgg_la_LIBADD = $(GADU_LIBS)
+libgg_la_LIBADD = $(GADU_LIBS) $(JSON_LIBS)
else
st = $(GADU_CFLAGS)
pkg_LTLIBRARIES = libgg.la
libgg_la_SOURCES = $(GGSOURCES)
-libgg_la_LIBADD = $(GLIB_LIBS) $(GADU_LIBS)
+libgg_la_LIBADD = $(GLIB_LIBS) $(JSON_LIBS) $(GADU_LIBS)
endif
@@ -121,6 +121,7 @@ AM_CPPFLAGS = \
$(GADU_EXTRA_WARNINGS) \
-I$(top_srcdir)/libpurple \
-I$(top_builddir)/libpurple \
+ $(JSON_CFLAGS)
$(INTGG_CFLAGS) \
$(GLIB_CFLAGS) \
$(DEBUG_CFLAGS)
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -57,6 +57,7 @@
#include <http.h>
#include <obsolete.h>
+#include <json-glib/json-glib.h>
static gchar *ggp_imtoken = NULL;
@@ -93,17 +94,125 @@ uin_t ggp_file_transfer_test_recipient =
const gchar *ggp_file_transfer_test_filename = "plik.txt";
const gchar *ggp_file_transfer_test_file = "ala ma kota";
+gchar *ggp_file_transfer_ticket = NULL;
+gchar *ggp_file_transfer_security_token = NULL;
+PurpleHttpCookieJar *ggp_file_transfer_cookie = NULL;
+
+static void ggp_file_transfer_test_sent(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer user_data)
+{
+ purple_debug_info("gg-test", "offered: %s\n",
+ purple_http_response_get_data(response));
+
+ if (!purple_http_response_is_successfull(response))
+ {
+ purple_debug_error("gg-test", "offer failed\n");
+ return;
+ }
+}
+
+static void ggp_event_json_edisc_ticket_changed(PurpleConnection *gc, const gchar *data)
+{
+ JsonNode *n;
+ JsonParser *parser;
+ JsonObject *change;
+ int i, len;
+ gboolean is_allowed, is_good_ticket;
+ PurpleHttpRequest *req;
+ gchar *upload_url;
+
+ purple_debug_info("gg", "edisc: %s\n", data);
+
+ parser = json_parser_new();
+ if (!json_parser_load_from_data(parser, data, -1, NULL)) {
+ g_object_unref(parser);
+ purple_debug_error("gg", "invalid JSON\n");
+ return;
+ }
+
+ change = json_node_get_object(json_parser_get_root(parser));
+ purple_debug_info("gg", "edisc ticket change: id=[%s] ack_status=[%s] send_status=[%s]\n",
+ json_object_get_string_member(change, "id"),
+ json_object_get_string_member(change, "ack_status"),
+ json_object_get_string_member(change, "send_status"));
+
+ is_allowed = (0 == g_strcmp0("allowed", json_object_get_string_member(
+ change, "ack_status")));
+ is_good_ticket = (0 == g_strcmp0(ggp_file_transfer_ticket,
+ json_object_get_string_member(change, "id")));
+
+ g_object_unref(parser);
+
+ if (!is_allowed || !is_good_ticket) {
+ purple_debug_warning("http", "invalid ticket\n");
+ return;
+ }
+
+ upload_url = g_strdup_printf("https://drive.mpa.gg.pl/me/file/outbox/%s%%2C%s",
+ ggp_file_transfer_ticket,
+ purple_url_encode(ggp_file_transfer_test_filename));
+ req = purple_http_request_new(upload_url);
+ g_free(upload_url);
+
+ purple_http_request_set_method(req, "PUT");
+ purple_http_request_set_cookie_jar(req, ggp_file_transfer_cookie);
+
+ purple_http_request_header_set(req, "X-gged-api-version", "6");
+ purple_http_request_header_set(req, "X-gged-local-revision", "0");
+ purple_http_request_header_set(req, "X-gged-security-token", ggp_file_transfer_security_token);
+ purple_http_request_header_set(req, "X-gged-metadata", "{\"node_type\": \"file\"}");
+
+ purple_http_request_set_contents(req, ggp_file_transfer_test_file, -1);
+
+ purple_http_request(gc,
+ req, ggp_file_transfer_test_sent, NULL);
+ purple_http_request_unref(req);
+
+ ggp_file_transfer_ticket = NULL;
+}
+
+static void ggp_event_json(PurpleConnection *gc, struct gg_event_json_event *ev)
+{
+ if (g_strcmp0("edisc/send_ticket_changed", ev->type) == 0)
+ ggp_event_json_edisc_ticket_changed(gc, ev->data);
+ else
+ purple_debug_info("gg", "unknown json event %s\n", ev->type);
+}
+
static void ggp_file_transfer_test_offered(PurpleHttpConnection *http_conn,
PurpleHttpResponse *response, gpointer user_data)
{
+ JsonParser *parser;
+ JsonObject *change;
+ JsonObject *ticket;
+ const gchar *ticket_id;
+
+ purple_debug_info("gg-test", "offered: %s\n",
+ purple_http_response_get_data(response));
+
if (!purple_http_response_is_successfull(response))
{
purple_debug_error("gg-test", "offer failed\n");
return;
}
- purple_debug_info("gg-test", "offered: %s\n",
- purple_http_response_get_data(response));
+ parser = json_parser_new();
+ if (!json_parser_load_from_data(parser,
+ purple_http_response_get_data(response), -1, NULL)) {
+ g_object_unref(parser);
+ purple_debug_error("gg-test", "invalid JSON\n");
+ return;
+ }
+
+ ticket = json_node_get_object(json_parser_get_root(parser));
+ ticket = json_object_get_object_member(ticket, "result");
+ ticket = json_object_get_object_member(ticket, "send_ticket");
+ ticket_id = json_object_get_string_member(ticket, "id");
+ ggp_file_transfer_ticket = g_strdup(ticket_id);
+
+ purple_debug_info("gg", "ticket id=%s\n", ticket_id);
+
+ g_object_unref(parser);
}
static void ggp_file_transfer_test_signedin(PurpleHttpConnection *http_conn,
@@ -139,14 +248,17 @@ static void ggp_file_transfer_test_signe
purple_debug_misc("gg-test", "security token=%s\n",
security_token);
- //req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket");
- req = purple_http_request_new("http://drive.mpa.gg.pl/send_ticket");
+ req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket");
purple_http_request_set_method(req, "PUT");
purple_http_request_set_cookie_jar(req,
purple_http_conn_get_cookie_jar(http_conn));
+ ggp_file_transfer_cookie = purple_http_conn_get_cookie_jar(http_conn);
+ purple_http_cookie_jar_ref(ggp_file_transfer_cookie);
+
purple_http_request_header_set(req, "X-gged-api-version", "6");
purple_http_request_header_set(req, "X-gged-security-token", security_token);
+ ggp_file_transfer_security_token = g_strdup(security_token);
data = g_strdup_printf("{\"send_ticket\":{"
"\"recipient\":\"%u\","
@@ -261,9 +373,9 @@ static void ggp_action_test_http(PurpleP
{
PurpleConnection *gc = (PurpleConnection *)action->context;
-// ggp_file_transfer_test(gc);
+ ggp_file_transfer_test(gc);
- purple_http_get(gc, "http://wasilczyk.pl/x_ip_ctest.htm", NULL, NULL);
+// purple_http_get(gc, "http://wasilczyk.pl/x_ip_ctest.htm", NULL, NULL);
/* PurpleHttpRequest *request;
//PurpleHttpConnection *hc;
@@ -864,6 +976,9 @@ static void ggp_callback_recv(gpointer _
case GG_EVENT_IMTOKEN:
ggp_imtoken = g_strdup(ev->event.imtoken.imtoken);
break;
More information about the Commits
mailing list