# HG changeset patch # User Christian Hammond # Date 1054605633 0 # Node ID 514fbc5374dc9f0fac3e8b65e4304bfad2bd7bdf # Parent fcf222b89d650b9b122e2f0e8aab18472e20408d [gaim-migrate @ 6100] Rewrote the proxy code. It should now work with the new prefs, and it has a namespace and API too! diff -r fcf222b89d65 -r 514fbc5374dc src/account.c --- a/src/account.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/account.c Tue Jun 03 02:00:33 2003 +0000 @@ -298,6 +298,16 @@ } void +gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info) +{ + g_return_if_fail(account != NULL); + + account->proxy_info = info; + + schedule_accounts_save(); +} + +void gaim_account_set_int(GaimAccount *account, const char *name, int value) { GaimAccountSetting *setting; @@ -433,6 +443,14 @@ return account->check_mail; } +GaimProxyInfo * +gaim_account_get_proxy_info(const GaimAccount *account) +{ + g_return_val_if_fail(account != NULL, NULL); + + return account->proxy_info; +} + int gaim_account_get_int(const GaimAccount *account, const char *name, int default_value) diff -r fcf222b89d65 -r 514fbc5374dc src/account.h --- a/src/account.h Mon Jun 02 22:30:25 2003 +0000 +++ b/src/account.h Tue Jun 03 02:00:33 2003 +0000 @@ -26,6 +26,7 @@ typedef struct _GaimAccount GaimAccount; #include "connection.h" +#include "proxy.h" #include "prpl.h" struct _GaimAccount @@ -47,7 +48,7 @@ GHashTable *settings; /**< Protocol-specific settings. */ - struct gaim_proxy_info *gpi; /**< Proxy information. */ + GaimProxyInfo *proxy_info; /**< Proxy information. */ GSList *permit; /**< Permit list. */ GSList *deny; /**< Deny list. */ @@ -160,6 +161,14 @@ void gaim_account_set_check_mail(GaimAccount *account, gboolean value); /** + * Sets the account's proxy information. + * + * @param account The account. + * @param info The proxy information. + */ +void gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info); + +/** * Sets a protocol-specific integer setting for an account. * * @param account The account. @@ -280,6 +289,15 @@ gboolean gaim_account_get_check_mail(const GaimAccount *account); /** + * Returns the account's proxy information. + * + * @param account The account. + * + * @return The proxy information. + */ +GaimProxyInfo *gaim_account_get_proxy_info(const GaimAccount *account); + +/** * Returns a protocol-specific integer setting for an account. * * @param account The account. diff -r fcf222b89d65 -r 514fbc5374dc src/ft.c --- a/src/ft.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/ft.c Tue Jun 03 02:00:33 2003 +0000 @@ -602,8 +602,8 @@ xfer->remote_port = port; /* Establish a file descriptor. */ - proxy_connect(xfer->account, xfer->remote_ip, xfer->remote_port, - connect_cb, xfer); + gaim_proxy_connect(xfer->account, xfer->remote_ip, + xfer->remote_port, connect_cb, xfer); return; } diff -r fcf222b89d65 -r 514fbc5374dc src/gaimrc.c --- a/src/gaimrc.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/gaimrc.c Tue Jun 03 02:00:33 2003 +0000 @@ -660,16 +660,15 @@ if (strcmp(p->option, "proxy_opts")) return account; - if(atoi(p->value[0]) != PROXY_USE_GLOBAL) { - account->gpi = g_new0(struct gaim_proxy_info, 1); - account->gpi->proxytype = atoi(p->value[0]); - g_snprintf(account->gpi->proxyhost, sizeof(account->gpi->proxyhost), - "%s", p->value[1]); - account->gpi->proxyport = atoi(p->value[2]); - g_snprintf(account->gpi->proxyuser, sizeof(account->gpi->proxyuser), - "%s", p->value[3]); - g_snprintf(account->gpi->proxypass, sizeof(account->gpi->proxypass), - "%s", p->value[4]); + if(atoi(p->value[0]) != GAIM_PROXY_USE_GLOBAL) { + GaimProxyInfo *info; + + info = gaim_proxy_info_new(); + gaim_proxy_info_set_type(info, atoi(p->value[0])); + gaim_proxy_info_set_host(info, p->value[1]); + gaim_proxy_info_set_port(info, atoi(p->value[2])); + gaim_proxy_info_set_username(info, p->value[3]); + gaim_proxy_info_set_password(info, p->value[4]); } return account; @@ -1143,6 +1142,8 @@ static gboolean gaimrc_parse_proxy_uri(const char *proxy) { + GaimProxyInfo *info; + char *c, *d; char buffer[2048]; @@ -1221,27 +1222,20 @@ } /* NOTE: HTTP_PROXY takes precendence. */ - if (host[0]) - strcpy(global_proxy_info.proxyhost, host); - else - *global_proxy_info.proxyhost = '\0'; + info = gaim_global_proxy_get_info(); - if (user[0]) - strcpy(global_proxy_info.proxyuser, user); - else - *global_proxy_info.proxyuser = '\0'; + if (*host) gaim_proxy_info_set_host(info, host); + if (*user) gaim_proxy_info_set_username(info, user); + if (*pass) gaim_proxy_info_set_password(info, pass); - if (pass[0]) - strcpy(global_proxy_info.proxypass, pass); - else - *global_proxy_info.proxypass = '\0'; - - global_proxy_info.proxyport = port; + gaim_proxy_info_set_port(info, port); gaim_debug(GAIM_DEBUG_MISC, "gaimrc", "Host: '%s', User: '%s', Password: '%s', Port: %d\n", - global_proxy_info.proxyhost, global_proxy_info.proxyuser, - global_proxy_info.proxypass, global_proxy_info.proxyport); + gaim_proxy_info_get_host(info), + gaim_proxy_info_get_username(info), + gaim_proxy_info_get_password(info), + gaim_proxy_info_get_port(info)); return TRUE; } @@ -1251,9 +1245,11 @@ char buf[2048]; struct parse parse_buffer; struct parse *p; + GaimProxyInfo *info; + + info = gaim_global_proxy_get_info(); buf[0] = 0; - global_proxy_info.proxyhost[0] = 0; gaim_debug(GAIM_DEBUG_MISC, "gaimrc", "gaimrc_read_proxy\n"); while (buf[0] != '}') { @@ -1266,78 +1262,60 @@ p = parse_line(buf, &parse_buffer); if (!strcmp(p->option, "host")) { - g_snprintf(global_proxy_info.proxyhost, - sizeof(global_proxy_info.proxyhost), "%s", p->value[0]); + gaim_proxy_info_set_host(info, p->value[0]); gaim_debug(GAIM_DEBUG_MISC, "gaimrc", - "Set proxyhost %s\n", global_proxy_info.proxyhost); + "Set proxyhost %s\n", p->value[0]); } else if (!strcmp(p->option, "port")) { - global_proxy_info.proxyport = atoi(p->value[0]); + gaim_proxy_info_set_port(info, atoi(p->value[0])); } else if (!strcmp(p->option, "type")) { - global_proxy_info.proxytype = atoi(p->value[0]); + gaim_proxy_info_set_type(info, atoi(p->value[0])); } else if (!strcmp(p->option, "user")) { - g_snprintf(global_proxy_info.proxyuser, - sizeof(global_proxy_info.proxyuser), "%s", p->value[0]); + gaim_proxy_info_set_username(info, p->value[0]); } else if (!strcmp(p->option, "pass")) { - g_snprintf(global_proxy_info.proxypass, - sizeof(global_proxy_info.proxypass), "%s", p->value[0]); + gaim_proxy_info_set_password(info, p->value[0]); } } - if (global_proxy_info.proxyhost[0]) - proxy_info_is_from_gaimrc = 1; + + if (gaim_proxy_info_get_host(info) != NULL) + gaim_global_proxy_set_from_prefs(TRUE); else { + const char *host; gboolean getVars = TRUE; - proxy_info_is_from_gaimrc = 0; - if (g_getenv("HTTP_PROXY")) - g_snprintf(global_proxy_info.proxyhost, - sizeof(global_proxy_info.proxyhost), "%s", - g_getenv("HTTP_PROXY")); - else if (g_getenv("http_proxy")) - g_snprintf(global_proxy_info.proxyhost, - sizeof(global_proxy_info.proxyhost), "%s", - g_getenv("http_proxy")); - else if (g_getenv("HTTPPROXY")) - g_snprintf(global_proxy_info.proxyhost, - sizeof(global_proxy_info.proxyhost), "%s", - g_getenv("HTTPPROXY")); + if ((host = g_getenv("HTTP_PROXY")) != NULL || + (host = g_getenv("http_proxy")) != NULL || + (host = g_getenv("HTTPPROXY")) != NULL) { - if (*global_proxy_info.proxyhost != '\0') - getVars = !gaimrc_parse_proxy_uri(global_proxy_info.proxyhost); + gaim_proxy_info_set_host(info, host); + } + + if (gaim_proxy_info_get_host(info) != NULL) + getVars = !gaimrc_parse_proxy_uri(gaim_proxy_info_get_host(info)); if (getVars) { - if (g_getenv("HTTP_PROXY_PORT")) - global_proxy_info.proxyport = atoi(g_getenv("HTTP_PROXY_PORT")); - else if (g_getenv("http_proxy_port")) - global_proxy_info.proxyport = atoi(g_getenv("http_proxy_port")); - else if (g_getenv("HTTPPROXYPORT")) - global_proxy_info.proxyport = atoi(g_getenv("HTTPPROXYPORT")); + const char *port_str, *user, *pass; + + if ((port_str = g_getenv("HTTP_PROXY_PORT")) != NULL || + (port_str = g_getenv("http_proxy_port")) != NULL || + (port_str = g_getenv("HTTPPROXYPORT")) != NULL) { + + gaim_proxy_info_set_port(info, atoi(port_str)); + } - if (g_getenv("HTTP_PROXY_USER")) - g_snprintf(global_proxy_info.proxyuser, - sizeof(global_proxy_info.proxyuser), "%s", - g_getenv("HTTP_PROXY_USER")); - else if (g_getenv("http_proxy_user")) - g_snprintf(global_proxy_info.proxyuser, - sizeof(global_proxy_info.proxyuser), "%s", - g_getenv("http_proxy_user")); - else if (g_getenv("HTTPPROXYUSER")) - g_snprintf(global_proxy_info.proxyuser, - sizeof(global_proxy_info.proxyuser), "%s", - g_getenv("HTTPPROXYUSER")); + if ((user = g_getenv("HTTP_PROXY_USER")) != NULL || + (user = g_getenv("http_proxy_user")) != NULL || + (user = g_getenv("HTTPPROXYUSER")) != NULL) { + + gaim_proxy_info_set_username(info, user); + } - if (g_getenv("HTTP_PROXY_PASS")) - g_snprintf(global_proxy_info.proxypass, - sizeof(global_proxy_info.proxypass), "%s", - g_getenv("HTTP_PROXY_PASS")); - else if (g_getenv("http_proxy_pass")) - g_snprintf(global_proxy_info.proxypass, - sizeof(global_proxy_info.proxypass), "%s", - g_getenv("http_proxy_pass")); - else if (g_getenv("HTTPPROXYPASS")) - g_snprintf(global_proxy_info.proxypass, - sizeof(global_proxy_info.proxypass), "%s", - g_getenv("HTTPPROXYPASS")); + if ((pass = g_getenv("HTTP_PROXY_PASS")) != NULL || + (pass = g_getenv("http_proxy_pass")) != NULL || + (pass = g_getenv("HTTPPROXYPASS")) != NULL) { + + gaim_proxy_info_set_password(info, pass); + } } } } diff -r fcf222b89d65 -r 514fbc5374dc src/gtkaccount.c --- a/src/gtkaccount.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/gtkaccount.c Tue Jun 03 02:00:33 2003 +0000 @@ -99,6 +99,9 @@ GtkWidget *protocol_frame; GtkWidget *register_check; + /* Proxy Options */ + GtkWidget *proxy_frame; + GtkSizeGroup *sg; } AccountPrefsDialog; @@ -490,6 +493,14 @@ } static void +__add_proxy_options_frame(AccountPrefsDialog *dialog, GtkWidget *parent) +{ + if (dialog->proxy_frame != NULL) + gtk_widget_destroy(dialog->proxy_frame); + +} + +static void __show_account_prefs(AccountPrefsDialogType type, GaimAccount *account) { AccountPrefsDialog *dialog; diff -r fcf222b89d65 -r 514fbc5374dc src/gtkconv.c --- a/src/gtkconv.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/gtkconv.c Tue Jun 03 02:00:33 2003 +0000 @@ -5297,7 +5297,7 @@ gaim_conversation_foreach(gaim_gtkconv_update_buddy_icon); } -void +static void chat_button_type_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) { diff -r fcf222b89d65 -r 514fbc5374dc src/gtkprefs.c --- a/src/gtkprefs.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/gtkprefs.c Tue Jun 03 02:00:33 2003 +0000 @@ -393,16 +393,19 @@ static void proxy_print_option(GtkEntry *entry, int entrynum) { + GaimProxyInfo *info = gaim_global_proxy_get_info(); + if (entrynum == PROXYHOST) - g_snprintf(global_proxy_info.proxyhost, sizeof(global_proxy_info.proxyhost), "%s", gtk_entry_get_text(entry)); + gaim_proxy_info_set_host(info, gtk_entry_get_text(entry)); else if (entrynum == PROXYPORT) - global_proxy_info.proxyport = atoi(gtk_entry_get_text(entry)); + gaim_proxy_info_set_port(info, atoi(gtk_entry_get_text(entry))); else if (entrynum == PROXYUSER) - g_snprintf(global_proxy_info.proxyuser, sizeof(global_proxy_info.proxyuser), "%s", gtk_entry_get_text(entry)); + gaim_proxy_info_set_username(info, gtk_entry_get_text(entry)); else if (entrynum == PROXYPASS) - g_snprintf(global_proxy_info.proxypass, sizeof(global_proxy_info.proxypass), "%s", gtk_entry_get_text(entry)); - proxy_info_is_from_gaimrc = 1; /* If the user specifies it, we want - to save it */ + gaim_proxy_info_set_password(info, gtk_entry_get_text(entry)); + + /* If the user specifies it, we want to save it. */ + gaim_global_proxy_set_from_prefs(TRUE); } /* OK, Apply and Cancel */ @@ -1127,6 +1130,7 @@ GtkWidget *label; GtkWidget *hbox; GtkWidget *table; + GaimProxyInfo *proxy_info; ret = gtk_vbox_new(FALSE, 18); gtk_container_set_border_width (GTK_CONTAINER (ret), 12); @@ -1143,8 +1147,13 @@ vbox = gaim_gtk_make_frame(ret, _("Proxy Server")); prefs_proxy_frame = vbox; - if (global_proxy_info.proxytype == PROXY_NONE) + proxy_info = gaim_global_proxy_get_info(); + + if (proxy_info == NULL || + gaim_proxy_info_get_type(proxy_info) == GAIM_PROXY_NONE) { + gtk_widget_set_sensitive(GTK_WIDGET(vbox), FALSE); + } table = gtk_table_new(2, 4, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 5); @@ -1162,7 +1171,10 @@ gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_FILL, 0, 0, 0); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(proxy_print_option), (void *)PROXYHOST); - gtk_entry_set_text(GTK_ENTRY(entry), global_proxy_info.proxyhost); + + if (proxy_info != NULL && gaim_proxy_info_get_host(proxy_info)) + gtk_entry_set_text(GTK_ENTRY(entry), + gaim_proxy_info_get_host(proxy_info)); hbox = gtk_hbox_new(TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); @@ -1177,9 +1189,11 @@ g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(proxy_print_option), (void *)PROXYPORT); - if (global_proxy_info.proxyport) { + if (proxy_info != NULL && gaim_proxy_info_get_port(proxy_info) != 0) { char buf[128]; - g_snprintf(buf, sizeof(buf), "%d", global_proxy_info.proxyport); + g_snprintf(buf, sizeof(buf), "%d", + gaim_proxy_info_get_port(proxy_info)); + gtk_entry_set_text(GTK_ENTRY(entry), buf); } @@ -1192,7 +1206,10 @@ gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 2, 3, GTK_FILL, 0, 0, 0); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(proxy_print_option), (void *)PROXYUSER); - gtk_entry_set_text(GTK_ENTRY(entry), global_proxy_info.proxyuser); + + if (proxy_info != NULL && gaim_proxy_info_get_username(proxy_info) != NULL) + gtk_entry_set_text(GTK_ENTRY(entry), + gaim_proxy_info_get_username(proxy_info)); hbox = gtk_hbox_new(TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); @@ -1207,7 +1224,10 @@ gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(proxy_print_option), (void *)PROXYPASS); - gtk_entry_set_text(GTK_ENTRY(entry), global_proxy_info.proxypass); + + if (proxy_info != NULL && gaim_proxy_info_get_password(proxy_info) != NULL) + gtk_entry_set_text(GTK_ENTRY(entry), + gaim_proxy_info_get_password(proxy_info)); gtk_widget_show_all(ret); return ret; diff -r fcf222b89d65 -r 514fbc5374dc src/html.c --- a/src/html.c Mon Jun 02 22:30:25 2003 +0000 +++ b/src/html.c Tue Jun 03 02:00:33 2003 +0000 @@ -314,8 +314,9 @@ gunk->website = parse_url(url); gunk->full = full; - if ((sock = proxy_connect(NULL, gunk->website->address, gunk->website->port, - grab_url_callback, gunk)) < 0) { + if ((sock = gaim_proxy_connect(NULL, gunk->website->address, + gunk->website->port, grab_url_callback,