changeset 1879:6497ee3751cf

[gaim-migrate @ 1889] yahoo can do the proxy_connect stuff now. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 22 May 2001 10:58:26 +0000
parents 75643b9f4261
children b8245bcce7e6
files ChangeLog plugins/yay/conn.c plugins/yay/yay.c plugins/yay/yay.h
diffstat 4 files changed, 233 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue May 22 09:05:21 2001 +0000
+++ b/ChangeLog	Tue May 22 10:58:26 2001 +0000
@@ -14,7 +14,7 @@
 	  packet logs, aechols)
 	* More IRC improvements [colors, etc] (Thanks Sean Egan)
 	* Improved proxy options for TOC, IRC, MSN, Jabber, Oscar,
-	  Napster
+	  Napster, Yahoo
 	* Fixed a small issue with HTML not being stripped from
 	  log files properly (Thanks, faceprint)
 
--- a/plugins/yay/conn.c	Tue May 22 09:05:21 2001 +0000
+++ b/plugins/yay/conn.c	Tue May 22 10:58:26 2001 +0000
@@ -23,6 +23,7 @@
 
 void (*yahoo_socket_notify)(struct yahoo_session *, int, int, gboolean) = NULL;
 void (*yahoo_print)(struct yahoo_session *, int, const char *) = NULL;
+int (*yahoo_connector)(struct yahoo_session *, const char *, int, gpointer) = NULL;
 
 struct yahoo_session *yahoo_new()
 {
@@ -80,6 +81,41 @@
 	return fd;
 }
 
+int yahoo_connected(struct yahoo_session *session, gpointer data, int fd)
+{
+	struct yahoo_conn *conn = data;
+
+	if (fd < 0) {
+		YAHOO_PRINT(session, YAHOO_LOG_WARNING, "connect failed");
+		session->connlist = g_list_remove(session->connlist, conn);
+		g_free(conn);
+		return 0;
+	}
+
+	YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "connect succeeded");
+	conn->socket = fd;
+	conn->connected = TRUE;
+	if (conn->type == YAHOO_CONN_TYPE_AUTH) {
+		if (session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function)
+			(*session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function)(session);
+	} else if (conn->type == YAHOO_CONN_TYPE_MAIN) {
+		if (session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)
+			(*session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)(session);
+	} else if (conn->type == YAHOO_CONN_TYPE_DUMB) {
+		YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "sending to buddy list host");
+		yahoo_write(session, conn, conn->txqueue, strlen(conn->txqueue));
+		g_free(conn->txqueue);
+		conn->txqueue = NULL;
+	}
+
+	if (yahoo_socket_notify)
+		(*yahoo_socket_notify)(session, conn->socket, YAHOO_SOCKET_READ, TRUE);
+	else
+		YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "yahoo_socket_notify not set up");
+
+	return 1;
+}
+
 struct yahoo_conn *yahoo_new_conn(struct yahoo_session *session, int type, const char *host, int port)
 {
 	struct yahoo_conn *conn;
@@ -91,6 +127,34 @@
 	conn = g_new0(struct yahoo_conn, 1);
 	conn->type = type;
 
+	if (yahoo_connector) {
+		const char *realhost = host;
+		YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "Connecting using user-specified connect routine");
+		if (!host) {
+			switch (type) {
+				case YAHOO_CONN_TYPE_AUTH:
+					realhost = YAHOO_AUTH_HOST;
+					port = YAHOO_AUTH_PORT;
+					break;
+				case YAHOO_CONN_TYPE_MAIN:
+					realhost = YAHOO_PAGER_HOST;
+					port = YAHOO_PAGER_PORT;
+					break;
+				case YAHOO_CONN_TYPE_DUMB:
+					realhost = YAHOO_DATA_HOST;
+					port = YAHOO_DATA_PORT;
+					break;
+			}
+		}
+		if ((*yahoo_connector)(session, realhost, port, conn) < 0) {
+			YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "connect failed");
+			g_free(conn);
+			return NULL;
+		}
+		session->connlist = g_list_append(session->connlist, conn);
+		return conn;
+	}
+
 	if (host) {
 		conn->socket = yahoo_connect_host(session, host, port, &status);
 	} else if (session->proxy_type) {
--- a/plugins/yay/yay.c	Tue May 22 09:05:21 2001 +0000
+++ b/plugins/yay/yay.c	Tue May 22 10:58:26 2001 +0000
@@ -41,6 +41,7 @@
 #include "prpl.h"
 #include "gaim.h"
 #include "yay.h"
+#include "proxy.h"
 
 #include "pixmaps/status-away.xpm"
 #include "pixmaps/status-here.xpm"
@@ -48,8 +49,11 @@
 
 #include "pixmaps/cancel.xpm"
 
-#define USEROPT_HTTPHOST 0
-#define USEROPT_HTTPPORT 1
+#define USEROPT_PROXYHOST 2
+#define USEROPT_PROXYPORT 3
+#define USEROPT_PROXYTYPE 4
+#define USEROPT_USER      5
+#define USEROPT_PASS      6
 
 struct conn {
 	int socket;
@@ -57,6 +61,11 @@
 	int inpa;
 };
 
+struct connect {
+	struct yahoo_session *sess;
+	gpointer data;
+};
+
 struct yahoo_data {
 	struct yahoo_session *sess;
 	int current_status;
@@ -357,6 +366,37 @@
 	}
 }
 
+static void yahoo_got_connected(gpointer data, gint source, GdkInputCondition cond) {
+	struct connect *con = data;
+
+	debug_printf("got connected (possibly)\n");
+	yahoo_connected(con->sess, con->data, source);
+
+	g_free(con);
+}
+
+static int yahoo_connect_to(struct yahoo_session *sess, const char *host, int port, gpointer data) {
+	struct connect *con = g_new0(struct connect, 1);
+	struct gaim_connection *gc = sess->user_data;
+	int fd;
+
+	con->sess = sess;
+	con->data = data;
+	fd = proxy_connect((char *)host, port,
+				gc->user->proto_opt[USEROPT_PROXYHOST],
+				atoi(gc->user->proto_opt[USEROPT_PROXYPORT]),
+				atoi(gc->user->proto_opt[USEROPT_PROXYTYPE]),
+				gc->user->proto_opt[USEROPT_USER],
+				gc->user->proto_opt[USEROPT_PASS],
+				yahoo_got_connected, con);
+	if (fd < 0) {
+		g_free(con);
+		return -1;
+	}
+
+	return fd;
+}
+
 static void yahoo_debug(struct yahoo_session *sess, int level, const char *string) {
 	debug_printf("Level %d: %s\n", level, string);
 }
@@ -370,20 +410,9 @@
 	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]) {
-		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)) {
-		yahoo_delete(yd->sess);
 		hide_login_progress(gc, "Connection problem");
 		signoff(gc);
 		return;
@@ -660,50 +689,144 @@
 	return m;
 }
 
-static void yahoo_print_option(GtkEntry *entry, struct aim_user *user) {
+static void yahoo_print_option(GtkEntry *entry, struct aim_user *user)
+{
 	int entrynum;
 
-	entrynum = (int) gtk_object_get_user_data(GTK_OBJECT(entry));
+	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));
+	if (entrynum == USEROPT_PROXYHOST) {
+		g_snprintf(user->proto_opt[USEROPT_PROXYHOST],
+			sizeof(user->proto_opt[USEROPT_PROXYHOST]), "%s", gtk_entry_get_text(entry));
+	} else if (entrynum == USEROPT_PROXYPORT) {
+		g_snprintf(user->proto_opt[USEROPT_PROXYPORT],
+			sizeof(user->proto_opt[USEROPT_PROXYPORT]), "%s", gtk_entry_get_text(entry));
+	} else if (entrynum == USEROPT_USER) {
+		g_snprintf(user->proto_opt[USEROPT_USER],
+			   sizeof(user->proto_opt[USEROPT_USER]), "%s", gtk_entry_get_text(entry));
+	} else if (entrynum == USEROPT_PASS) {
+		g_snprintf(user->proto_opt[USEROPT_PASS],
+			   sizeof(user->proto_opt[USEROPT_PASS]), "%s", gtk_entry_get_text(entry));
 	}
 }
 
-static void yahoo_user_opts(GtkWidget *book, struct aim_user *user) {
+static void yahoo_print_optionrad(GtkRadioButton * entry, struct aim_user *user)
+{
+	int entrynum;
+
+	entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry));
+
+	g_snprintf(user->proto_opt[USEROPT_PROXYTYPE],
+			sizeof(user->proto_opt[USEROPT_PROXYTYPE]), "%d", entrynum);
+}
+
+static void yahoo_user_opts(GtkWidget * book, struct aim_user *user)
+{
+	/* so here, we create the new notebook page */
 	GtkWidget *vbox;
 	GtkWidget *hbox;
 	GtkWidget *label;
 	GtkWidget *entry;
+	GtkWidget *first, *opt;
 
 	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_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Yahoo Options"));
 	gtk_widget_show(vbox);
 
-	hbox = gtk_hbox_new(FALSE, 5);
+	hbox = gtk_hbox_new(TRUE, 0);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 	gtk_widget_show(hbox);
 
-	label = gtk_label_new("HTTP Proxy Host:");
+	first = gtk_radio_button_new_with_label(NULL, "No proxy");
+	gtk_box_pack_start(GTK_BOX(hbox), first, FALSE, FALSE, 0);
+	gtk_object_set_user_data(GTK_OBJECT(first), (void *)PROXY_NONE);
+	gtk_signal_connect(GTK_OBJECT(first), "clicked", GTK_SIGNAL_FUNC(yahoo_print_optionrad), user);
+	gtk_widget_show(first);
+	if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_NONE)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(first), TRUE);
+
+	opt =
+	    gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 4");
+	gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
+	gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS4);
+	gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(yahoo_print_optionrad), user);
+	gtk_widget_show(opt);
+	if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS4)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
+
+	hbox = gtk_hbox_new(TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	opt =
+	    gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 5");
+	gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
+	gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS5);
+	gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(yahoo_print_optionrad), user);
+	gtk_widget_show(opt);
+	if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS5)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
+
+	opt = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "HTTP");
+	gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0);
+	gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_HTTP);
+	gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(yahoo_print_optionrad), user);
+	gtk_widget_show(opt);
+	if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_HTTP)
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
+
+	hbox = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	label = gtk_label_new("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_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYHOST);
+	gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(yahoo_print_option), user);
+	if (user->proto_opt[USEROPT_PROXYHOST][0]) {
+		debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYHOST]);
+		gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYHOST]);
+	}
+	gtk_widget_show(entry);
+
+	hbox = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	label = gtk_label_new("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_PROXYPORT);
+	gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(yahoo_print_option), user);
+	if (user->proto_opt[USEROPT_PROXYPORT][0]) {
+		debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYPORT]);
+		gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYPORT]);
+	}
+	gtk_widget_show(entry);
+
+	hbox = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	label = gtk_label_new("Proxy User:");
+	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_USER);
+	gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(yahoo_print_option), user);
+	if (user->proto_opt[USEROPT_USER][0]) {
+		debug_printf("setting text %s\n", user->proto_opt[USEROPT_USER]);
+		gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_USER]);
 	}
 	gtk_widget_show(entry);
 
@@ -711,18 +834,18 @@
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 	gtk_widget_show(hbox);
 
-	label = gtk_label_new("HTTP Proxy Port:");
+	label = gtk_label_new("Proxy Password:");
 	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_entry_set_visibility(GTK_ENTRY(entry), FALSE);
+	gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PASS);
+	gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(yahoo_print_option), user);
+	if (user->proto_opt[USEROPT_PASS][0]) {
+		debug_printf("setting text %s\n", user->proto_opt[USEROPT_PASS]);
+		gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PASS]);
 	}
 	gtk_widget_show(entry);
 }
@@ -775,6 +898,7 @@
 	load_protocol(Yahoo_init, sizeof(struct prpl));
 	yahoo_socket_notify = yahoo_notify;
 	yahoo_print = yahoo_debug;
+	yahoo_connector = yahoo_connect_to;
 	return NULL;
 }
 
--- a/plugins/yay/yay.h	Tue May 22 09:05:21 2001 +0000
+++ b/plugins/yay/yay.h	Tue May 22 10:58:26 2001 +0000
@@ -94,6 +94,9 @@
 #define YAHOO_LOG_ERROR    1
 #define YAHOO_LOG_CRITICAL 0
 
+extern int (*yahoo_connector)(struct yahoo_session *session, const char *host, int port, gpointer data);
+int yahoo_connected(struct yahoo_session *session, gpointer data, int fd);
+
 typedef int (*yahoo_callback)(struct yahoo_session *session, ...);
 void yahoo_add_handler(struct yahoo_session *session, int type, yahoo_callback function);
 #define YAHOO_HANDLE_DISCONNECT   0