/dev/tomkiewicz/gg11: fa2313e5f320: Gadu-Gadu: use our own proxy...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Aug 29 05:48:26 EDT 2013
Changeset: fa2313e5f320f2446303b5f28ba13b1ab8787ea0
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2013-08-29 11:48 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/gg11/rev/fa2313e5f320
Description:
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
diffstat:
libpurple/protocols/gg/Makefile.am | 2 +
libpurple/protocols/gg/Makefile.mingw | 1 +
libpurple/protocols/gg/gg.c | 11 ++-
libpurple/protocols/gg/gg.h | 2 +
libpurple/protocols/gg/purplew.c | 14 +--
libpurple/protocols/gg/tcpsocket.c | 103 ++++++++++++++++++++++++++++++++++
libpurple/protocols/gg/tcpsocket.h | 13 ++++
7 files changed, 134 insertions(+), 12 deletions(-)
diffs (232 lines):
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
@@ -92,6 +92,8 @@ GGSOURCES = \
servconn.h \
status.c \
status.h \
+ tcpsocket.c \
+ tcpsocket.h \
utils.c \
utils.h \
validator.c \
diff --git a/libpurple/protocols/gg/Makefile.mingw b/libpurple/protocols/gg/Makefile.mingw
--- a/libpurple/protocols/gg/Makefile.mingw
+++ b/libpurple/protocols/gg/Makefile.mingw
@@ -78,6 +78,7 @@ C_SRC = \
roster.c \
servconn.c \
status.c \
+ tcpsocket.c \
utils.c \
validator.c \
xml.c
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
@@ -51,6 +51,7 @@
#include "multilogon.h"
#include "status.h"
#include "servconn.h"
+#include "tcpsocket.h"
#include "pubdir-prpl.h"
#include "message-prpl.h"
#include "html.h"
@@ -396,7 +397,7 @@ static void ggp_callback_recv(gpointer _
gg_free_event(ev);
}
-static void ggp_async_login_handler(gpointer _gc, gint fd, PurpleInputCondition cond)
+void ggp_async_login_handler(gpointer _gc, gint fd, PurpleInputCondition cond)
{
PurpleConnection *gc = _gc;
GGPInfo *info;
@@ -648,6 +649,7 @@ static void ggp_login(PurpleAccount *acc
purple_connection_set_protocol_data(gc, info);
+ ggp_tcpsocket_setup(gc, glp);
ggp_image_setup(gc);
ggp_avatar_setup(gc);
ggp_roster_setup(gc);
@@ -732,8 +734,11 @@ static void ggp_login(PurpleAccount *acc
_("Connection failed"));
return;
}
- info->inpa = purple_input_add(info->session->fd, PURPLE_INPUT_READ,
- ggp_async_login_handler, gc);
+
+ if (info->session->fd > 0) {
+ info->inpa = purple_input_add(info->session->fd,
+ PURPLE_INPUT_READ, ggp_async_login_handler, gc);
+ }
}
static void ggp_close(PurpleConnection *gc)
diff --git a/libpurple/protocols/gg/gg.h b/libpurple/protocols/gg/gg.h
--- a/libpurple/protocols/gg/gg.h
+++ b/libpurple/protocols/gg/gg.h
@@ -70,4 +70,6 @@ const gchar * ggp_get_imtoken(PurpleConn
uin_t ggp_own_uin(PurpleConnection *gc);
+void ggp_async_login_handler(gpointer _gc, gint fd, PurpleInputCondition cond);
+
#endif /* _PURPLE_GG_H */
diff --git a/libpurple/protocols/gg/purplew.c b/libpurple/protocols/gg/purplew.c
--- a/libpurple/protocols/gg/purplew.c
+++ b/libpurple/protocols/gg/purplew.c
@@ -32,22 +32,18 @@
#include <request.h>
#include <debug.h>
+#include "tcpsocket.h"
+
guint ggp_purplew_http_input_add(struct gg_http *http_req,
PurpleInputFunction func, gpointer user_data)
{
- PurpleInputCondition cond = 0;
- int check = http_req->check;
-
- if (check & GG_CHECK_READ)
- cond |= PURPLE_INPUT_READ;
- if (check & GG_CHECK_WRITE)
- cond |= PURPLE_INPUT_WRITE;
-
//TODO: verbose mode
//purple_debug_misc("gg", "ggp_purplew_http_input_add: "
// "[req=%x, fd=%d, cond=%d]\n",
// (unsigned int)http_req, http_req->fd, cond);
- return purple_input_add(http_req->fd, cond, func, user_data);
+ return purple_input_add(http_req->fd,
+ ggp_tcpsocket_inputcond_gg_to_purple(http_req->check),
+ func, user_data);
}
static void ggp_purplew_request_processing_cancel(
diff --git a/libpurple/protocols/gg/tcpsocket.c b/libpurple/protocols/gg/tcpsocket.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/gg/tcpsocket.c
@@ -0,0 +1,103 @@
+#include "tcpsocket.h"
+
+#include "gg.h"
+
+#include "debug.h"
+#include "purple-socket.h"
+
+static void
+ggp_tcpsocket_connected(PurpleSocket *ps, const gchar *error, gpointer priv_gg)
+{
+ PurpleConnection *gc = purple_socket_get_connection(ps);
+ GGPInfo *info = purple_connection_get_protocol_data(gc);
+ int fd = -1;
+
+ if (error == NULL)
+ fd = purple_socket_get_fd(ps);
+
+ if (!gg_socket_manager_connected(ps, priv_gg, fd)) {
+ purple_debug_error("gg", "socket not handled");
+ purple_socket_destroy(ps);
+ return;
+ }
+
+ if (info->inpa > 0)
+ purple_input_remove(info->inpa);
+ info->inpa = purple_input_add(fd, ggp_tcpsocket_inputcond_gg_to_purple(
+ info->session->check), ggp_async_login_handler, gc);
+}
+
+static void*
+ggp_tcpsocket_connect(void *_gc, const char *host, int port, int is_tls,
+ int is_async, void *priv)
+{
+ PurpleConnection *gc = _gc;
+ PurpleSocket *ps;
+
+ g_return_val_if_fail(host != NULL, NULL);
+ g_return_val_if_fail(is_async, NULL);
+
+ purple_debug_misc("gg",
+ "ggp_socket_manager_connect(%p, %s:%d, %s, %p)",
+ gc, host, port, is_tls ? "tls" : "tcp", priv);
+
+ ps = purple_socket_new(gc);
+ purple_socket_set_tls(ps, is_tls);
+ purple_socket_set_host(ps, host);
+ purple_socket_set_port(ps, port);
+ if (!purple_socket_connect(ps, ggp_tcpsocket_connected, priv)) {
+ purple_socket_destroy(ps);
+ return NULL;
+ }
+
+ return ps;
+}
+
+static void
+ggp_tcpsocket_close(void *_gc, void *_ps)
+{
+ PurpleSocket *ps = _ps;
+
+ purple_socket_destroy(ps);
+}
+
+static ssize_t
+ggp_tcpsocket_read(void *_gc, void *_ps, unsigned char *buffer, size_t bufsize)
+{
+ PurpleSocket *ps = _ps;
+
+ return purple_socket_read(ps, buffer, bufsize);
+}
+
+static ssize_t
+ggp_tcpsocket_write(void *_gc, void *_ps, const unsigned char *data, size_t len)
+{
+ PurpleSocket *ps = _ps;
+
+ return purple_socket_write(ps, data, len);
+}
+
+void
+ggp_tcpsocket_setup(PurpleConnection *gc, struct gg_login_params *glp)
+{
+ glp->socket_manager_type = purple_ssl_is_supported() ?
+ GG_SOCKET_MANAGER_TYPE_TLS : GG_SOCKET_MANAGER_TYPE_TCP;
+ glp->socket_manager.cb_data = gc;
+ glp->socket_manager.connect = ggp_tcpsocket_connect;
+ glp->socket_manager.close = ggp_tcpsocket_close;
+ glp->socket_manager.read = ggp_tcpsocket_read;
+ glp->socket_manager.write = ggp_tcpsocket_write;
+}
+
+PurpleInputCondition
+ggp_tcpsocket_inputcond_gg_to_purple(enum gg_check_t check)
+{
+ PurpleInputCondition cond = 0;
+
+ if (check & GG_CHECK_READ)
+ cond |= PURPLE_INPUT_READ;
+ if (check & GG_CHECK_WRITE)
+ cond |= PURPLE_INPUT_WRITE;
+
+ return cond;
+}
diff --git a/libpurple/protocols/gg/tcpsocket.h b/libpurple/protocols/gg/tcpsocket.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/gg/tcpsocket.h
@@ -0,0 +1,13 @@
+#ifndef _GGP_TCPSOCKET_H
+#define _GGP_TCPSOCKET_H
+
+#include <internal.h>
+#include <libgadu.h>
+
+void
+ggp_tcpsocket_setup(PurpleConnection *gc, struct gg_login_params *glp);
+
+PurpleInputCondition
+ggp_tcpsocket_inputcond_gg_to_purple(enum gg_check_t check);
+
+#endif /* _GGP_TCPSOCKET_H */
More information about the Commits
mailing list