Mercurial > pidgin
changeset 1565:2c66d386be90
[gaim-migrate @ 1575]
http proxy for libyay. yay.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 13 Mar 2001 10:05:45 +0000 |
parents | aa69b15d9403 |
children | e9faf5dfdba0 |
files | ChangeLog plugins/yay/buddy.c plugins/yay/conn.c plugins/yay/internal.h plugins/yay/login.c plugins/yay/rxhandlers.c plugins/yay/yay.c plugins/yay/yay.h |
diffstat | 8 files changed, 160 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Mar 11 12:38:59 2001 +0000 +++ b/ChangeLog Tue Mar 13 10:05:45 2001 +0000 @@ -2,7 +2,7 @@ version 0.11.0-pre7: * Can build RPMs as non-root - * New yahoo library + * New yahoo library (can use HTTP proxy) * Command-line arg to specify config file version 0.11.0-pre6 (03/06/2001):
--- a/plugins/yay/buddy.c Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/buddy.c Tue Mar 13 10:05:45 2001 +0000 @@ -56,7 +56,10 @@ return 0; } - send = g_strconcat("GET /config/set_buddygrp?.bg=", grp, + send = g_strconcat("GET ", + session->proxy_type ? "http://" : "", + session->proxy_type ? YAHOO_DATA_HOST : "", + "/config/set_buddygrp?.bg=", grp, "&.src=bl&.cmd=a&.bdl=", bdy, "&.id=", id, "&.l=", usr, @@ -119,7 +122,10 @@ return 0; } - send = g_strconcat("GET /config/set_buddygrp?.bg=", grp, + send = g_strconcat("GET ", + session->proxy_type ? "http://" : "", + session->proxy_type ? YAHOO_DATA_HOST : "", + "/config/set_buddygrp?.bg=", grp, "&.src=bl&.cmd=d&.bdl=", bdy, "&.id=", id, "&.l=", usr,
--- a/plugins/yay/conn.c Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/conn.c Tue Mar 13 10:05:45 2001 +0000 @@ -34,6 +34,16 @@ return sess; } +void yahoo_set_proxy(struct yahoo_session *session, int proxy_type, char *proxy_host, int proxy_port) +{ + if (!session || !proxy_type || !proxy_host) + return; + + session->proxy_type = proxy_type; + session->proxy_host = g_strdup(proxy_host); + session->proxy_port = proxy_port; +} + static int yahoo_connect_host(struct yahoo_session *sess, const char *host, int port, int *statusret) { struct sockaddr_in sa; @@ -83,6 +93,12 @@ if (host) { conn->socket = yahoo_connect_host(session, host, port, &status); + } else if (session->proxy_type) { + YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "connecting to proxy"); + conn->socket = yahoo_connect_host(session, session->proxy_host, + session->proxy_port, &status); + if (type == YAHOO_CONN_TYPE_MAIN) + conn->type = YAHOO_CONN_TYPE_PROXY; } else { switch (type) { case YAHOO_CONN_TYPE_AUTH: @@ -230,6 +246,8 @@ { if (!session) return 0; + if (session->proxy_host) + g_free(session->proxy_host); g_free(session); return 0; }
--- a/plugins/yay/internal.h Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/internal.h Tue Mar 13 10:05:45 2001 +0000 @@ -39,9 +39,13 @@ char *txqueue; }; -#define YAHOO_CONN_TYPE_AUTH 1 -#define YAHOO_CONN_TYPE_MAIN 2 -#define YAHOO_CONN_TYPE_DUMB 3 +#define YAHOO_CONN_TYPE_AUTH 1 +#define YAHOO_CONN_TYPE_MAIN 2 +#define YAHOO_CONN_TYPE_DUMB 3 +#define YAHOO_CONN_TYPE_PROXY 4 + +#define HTTP_GOODSTRING1 "HTTP/1.0 200 Connection established" +#define HTTP_GOODSTRING2 "HTTP/1.1 200 Connection established" char *yahoo_urlencode(const char *); struct yahoo_conn *yahoo_new_conn(struct yahoo_session *, int, const char *, int);
--- a/plugins/yay/login.c Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/login.c Tue Mar 13 10:05:45 2001 +0000 @@ -42,9 +42,11 @@ } at = g_snprintf(buf, 1024 + strlen(name) + strlen(password), - "GET /config/ncclogin?login=%s&passwd=%s&n=1 HTTP/1.0\r\n" + "GET %s%s/config/ncclogin?login=%s&passwd=%s&n=1 HTTP/1.0\r\n" "User-Agent: " YAHOO_USER_AGENT "\r\n" "Host: " YAHOO_AUTH_HOST "\r\n\r\n", + session->proxy_type ? "http://" : "", + session->proxy_type ? YAHOO_AUTH_HOST "" : " ", a, b); g_free(a);
--- a/plugins/yay/rxhandlers.c Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/rxhandlers.c Tue Mar 13 10:05:45 2001 +0000 @@ -260,6 +260,12 @@ yahoo_write(session, conn, conn->txqueue, strlen(conn->txqueue)); g_free(conn->txqueue); conn->txqueue = NULL; + } else if (conn->type == YAHOO_CONN_TYPE_PROXY) { + char buf[1024]; + g_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n\r\n", + YAHOO_PAGER_HOST, YAHOO_PAGER_PORT); + YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); + yahoo_write(session, conn, buf, strlen(buf)); } return; @@ -312,12 +318,39 @@ while (read(socket, &buf[pos++], 1) == 1); if (pos == 1) { g_free(buf); + yahoo_close(session, conn); YAHOO_PRINT(session, YAHOO_LOG_WARNING, "error reading from listserv"); return; } YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "closing buddy list host connnection"); yahoo_close(session, conn); + g_free(buf); + } else if (conn->type == YAHOO_CONN_TYPE_PROXY) { + char *buf = g_malloc0(5000); + int nlc = 0; + while ((nlc != 2) && (read(socket, &buf[pos++], 1) == 1)) + if (buf[pos-1] == '\n') + nlc++; + if (pos == 1) { + g_free(buf); + yahoo_close(session, conn); + YAHOO_PRINT(session, YAHOO_LOG_ERROR, "error reading from proxy"); + CALLBACK(session, YAHOO_HANDLE_DISCONNECT); + return; + } + YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); + if (!strncasecmp(buf, HTTP_GOODSTRING1, strlen(HTTP_GOODSTRING1)) || + !strncasecmp(buf, HTTP_GOODSTRING2, strlen(HTTP_GOODSTRING2))) { + conn->type = YAHOO_CONN_TYPE_MAIN; + YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "proxy connected successfully"); + CALLBACK(session, YAHOO_HANDLE_MAINCONNECT); + } else { + yahoo_close(session, conn); + YAHOO_PRINT(session, YAHOO_LOG_ERROR, "proxy could not connect"); + CALLBACK(session, YAHOO_HANDLE_DISCONNECT); + } + g_free(buf); } }
--- a/plugins/yay/yay.c Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/yay.c Tue Mar 13 10:05:45 2001 +0000 @@ -48,6 +48,9 @@ #include "pixmaps/cancel.xpm" +#define USEROPT_HTTPHOST 0 +#define USEROPT_HTTPPORT 1 + struct conn { int socket; int type; @@ -345,6 +348,17 @@ yd->current_status = YAHOO_STATUS_AVAILABLE; yd->hash = g_hash_table_new(g_str_hash, g_str_equal); + if (user->proto_opt[USEROPT_HTTPHOST][0]) { + char *finalproxy; + if (user->proto_opt[USEROPT_HTTPPORT][0]) + yahoo_set_proxy(yd->sess, YAHOO_PROXY_HTTP, + user->proto_opt[USEROPT_HTTPHOST], + atoi(user->proto_opt[USEROPT_HTTPPORT])); + else + yahoo_set_proxy(yd->sess, YAHOO_PROXY_HTTP, + user->proto_opt[USEROPT_HTTPHOST], 8080); + } + set_login_progress(gc, 1, "Connecting"); if (!yahoo_connect(yd->sess, NULL, 0)) { @@ -625,6 +639,73 @@ return m; } +static void yahoo_print_option(GtkEntry *entry, struct aim_user *user) { + int entrynum; + + entrynum = (int) gtk_object_get_user_data(GTK_OBJECT(entry)); + + if (entrynum == USEROPT_HTTPHOST) { + g_snprintf(user->proto_opt[USEROPT_HTTPHOST], + sizeof(user->proto_opt[USEROPT_HTTPHOST]), + "%s", gtk_entry_get_text(entry)); + } else if (entrynum == USEROPT_HTTPPORT) { + g_snprintf(user->proto_opt[USEROPT_HTTPPORT], + sizeof(user->proto_opt[USEROPT_HTTPPORT]), + "%s", gtk_entry_get_text(entry)); + } +} + +static void yahoo_user_opts(GtkWidget *book, struct aim_user *user) { + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *entry; + + vbox = gtk_vbox_new(FALSE, 5); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); + gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, + gtk_label_new("Yahoo Options")); + gtk_widget_show(vbox); + + hbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show(hbox); + + label = gtk_label_new("HTTP Proxy Host:"); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + entry = gtk_entry_new(); + gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_HTTPHOST); + gtk_signal_connect(GTK_OBJECT(entry), "changed", + GTK_SIGNAL_FUNC(yahoo_print_option), user); + if (user->proto_opt[USEROPT_HTTPHOST][0]) { + debug_printf("setting text %s\n", user->proto_opt[USEROPT_HTTPHOST]); + gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_HTTPHOST]); + } + gtk_widget_show(entry); + + hbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show(hbox); + + label = gtk_label_new("HTTP Proxy Port:"); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + entry = gtk_entry_new(); + gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_HTTPPORT); + gtk_signal_connect(GTK_OBJECT(entry), "changed", + GTK_SIGNAL_FUNC(yahoo_print_option), user); + if (user->proto_opt[USEROPT_HTTPPORT][0]) { + debug_printf("setting text %s\n", user->proto_opt[USEROPT_HTTPPORT]); + gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_HTTPPORT]); + } + gtk_widget_show(entry); +} + static struct prpl *my_protocol = NULL; void Yahoo_init(struct prpl *ret) { @@ -636,7 +717,7 @@ ret->actions = yahoo_actions; ret->do_action = yahoo_do_action; ret->buddy_menu = yahoo_buddy_menu; - ret->user_opts = NULL; + ret->user_opts = yahoo_user_opts; ret->login = yahoo_login; ret->close = yahoo_close; ret->send_im = yahoo_send_im;
--- a/plugins/yay/yay.h Sun Mar 11 12:38:59 2001 +0000 +++ b/plugins/yay/yay.h Tue Mar 13 10:05:45 2001 +0000 @@ -34,6 +34,9 @@ struct yahoo_session; +#define YAHOO_PROXY_NONE 0 +#define YAHOO_PROXY_HTTP 1 + #define YAHOO_AUTH_HOST "msg.edit.yahoo.com" #define YAHOO_AUTH_PORT 80 #define YAHOO_PAGER_HOST "cs.yahoo.com" @@ -58,6 +61,7 @@ }; struct yahoo_session *yahoo_new(); +void yahoo_set_proxy(struct yahoo_session *session, int proxy_type, char *proxy_host, int proxy_port); int yahoo_connect(struct yahoo_session *session, const char *host, int port); int yahoo_send_login(struct yahoo_session *session, const char *name, const char *password); int yahoo_major_connect(struct yahoo_session *session, const char *host, int port); @@ -120,6 +124,10 @@ void *user_data; struct callback callbacks[YAHOO_HANDLE_MAX]; + int proxy_type; + char *proxy_host; + int proxy_port; + char *name; char *cookie;