changeset 5707:b69400aa008e

[gaim-migrate @ 6128] Proxy information is now loaded and saved. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 03 Jun 2003 10:57:53 +0000
parents 8e618a7111a5
children 1d5c5acfc846
files src/account.c
diffstat 1 files changed, 105 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Tue Jun 03 10:46:21 2003 +0000
+++ b/src/account.c	Tue Jun 03 10:57:53 2003 +0000
@@ -44,7 +44,10 @@
 	TAG_ALIAS,
 	TAG_USERINFO,
 	TAG_BUDDYICON,
-	TAG_SETTING
+	TAG_SETTING,
+	TAG_TYPE,
+	TAG_HOST,
+	TAG_PORT
 
 } AccountParserTag;
 
@@ -68,6 +71,7 @@
 
 	GaimAccount *account;
 	GaimProtocol protocol;
+	GaimProxyInfo *proxy_info;
 	char *protocol_id;
 
 	GString *buffer;
@@ -75,6 +79,8 @@
 	GaimPrefType setting_type;
 	char *setting_name;
 
+	gboolean in_proxy;
+
 } AccountParserData;
 
 static GList   *accounts = NULL;
@@ -549,7 +555,7 @@
 
 	if (!strcmp(element_name, "protocol"))
 		data->tag = TAG_PROTOCOL;
-	else if (!strcmp(element_name, "name"))
+	else if (!strcmp(element_name, "name") || !strcmp(element_name, "username"))
 		data->tag = TAG_NAME;
 	else if (!strcmp(element_name, "password"))
 		data->tag = TAG_PASSWORD;
@@ -559,6 +565,17 @@
 		data->tag = TAG_USERINFO;
 	else if (!strcmp(element_name, "buddyicon"))
 		data->tag = TAG_BUDDYICON;
+	else if (!strcmp(element_name, "proxy")) {
+		data->in_proxy = TRUE;
+
+		data->proxy_info = gaim_proxy_info_new();
+	}
+	else if (!strcmp(element_name, "type"))
+		data->tag = TAG_TYPE;
+	else if (!strcmp(element_name, "host"))
+		data->tag = TAG_HOST;
+	else if (!strcmp(element_name, "port"))
+		data->tag = TAG_PORT;
 	else if (!strcmp(element_name, "setting")) {
 		data->tag = TAG_SETTING;
 
@@ -613,14 +630,24 @@
 		}
 	}
 	else if (data->tag == TAG_NAME) {
-		data->account = gaim_account_new(buffer, data->protocol);
-		data->account->protocol_id = data->protocol_id;
+		if (data->in_proxy) {
+			gaim_proxy_info_set_username(data->proxy_info, buffer);
+		}
+		else {
+			data->account = gaim_account_new(buffer, data->protocol);
+			data->account->protocol_id = data->protocol_id;
 
-		data->protocol_id = NULL;
+			data->protocol_id = NULL;
+		}
 	}
 	else if (data->tag == TAG_PASSWORD) {
-		gaim_account_set_password(data->account, buffer);
-		gaim_account_set_remember_password(data->account, TRUE);
+		if (data->in_proxy) {
+			gaim_proxy_info_set_password(data->proxy_info, buffer);
+		}
+		else {
+			gaim_account_set_password(data->account, buffer);
+			gaim_account_set_remember_password(data->account, TRUE);
+		}
 	}
 	else if (data->tag == TAG_ALIAS)
 		gaim_account_set_alias(data->account, buffer);
@@ -628,6 +655,34 @@
 		gaim_account_set_user_info(data->account, buffer);
 	else if (data->tag == TAG_BUDDYICON)
 		gaim_account_set_buddy_icon(data->account, buffer);
+	else if (data->tag == TAG_TYPE) {
+		if (data->in_proxy) {
+			if (!strcmp(buffer, "global"))
+				gaim_proxy_info_set_type(data->proxy_info,
+										 GAIM_PROXY_USE_GLOBAL);
+			else if (!strcmp(buffer, "http"))
+				gaim_proxy_info_set_type(data->proxy_info, GAIM_PROXY_HTTP);
+			else if (!strcmp(buffer, "socks4"))
+				gaim_proxy_info_set_type(data->proxy_info, GAIM_PROXY_SOCKS4);
+			else if (!strcmp(buffer, "socks5"))
+				gaim_proxy_info_set_type(data->proxy_info, GAIM_PROXY_SOCKS5);
+			else
+				gaim_debug(GAIM_DEBUG_ERROR, "account",
+						   "Invalid proxy type found when loading account "
+						   "information for %s\n",
+						   gaim_account_get_username(data->account));
+		}
+	}
+	else if (data->tag == TAG_HOST) {
+		if (data->in_proxy) {
+			gaim_proxy_info_set_host(data->proxy_info, buffer);
+		}
+	}
+	else if (data->tag == TAG_PORT) {
+		if (data->in_proxy) {
+			gaim_proxy_info_set_port(data->proxy_info, atoi(buffer));
+		}
+	}
 	else if (data->tag == TAG_SETTING) {
 		if (data->setting_type == GAIM_PREF_STRING)
 			gaim_account_set_string(data->account, data->setting_name,
@@ -642,6 +697,17 @@
 		g_free(data->setting_name);
 		data->setting_name = NULL;
 	}
+	else if (!strcmp(element_name, "proxy")) {
+		data->in_proxy = FALSE;
+
+		if (gaim_proxy_info_get_type(data->proxy_info) == GAIM_PROXY_NONE) {
+			gaim_proxy_info_destroy(data->proxy_info);
+			data->proxy_info = NULL;
+		}
+		else {
+			gaim_account_set_proxy_info(data->account, data->proxy_info);
+		}
+	}
 
 	data->tag = TAG_NONE;
 
@@ -761,6 +827,8 @@
 static void
 gaim_accounts_write(FILE *fp, GaimAccount *account)
 {
+	GaimProxyInfo *proxy_info;
+	GaimProxyType proxy_type;
 	const char *password, *alias, *user_info, *buddy_icon;
 	char *esc;
 
@@ -799,6 +867,36 @@
 	g_hash_table_foreach(account->settings, __write_setting, fp);
 	fprintf(fp, "  </settings>\n");
 
+	if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL &&
+		(proxy_type = gaim_proxy_info_get_type(proxy_info)) != GAIM_PROXY_NONE)
+	{
+		const char *value;
+		int int_value;
+
+		fprintf(fp, "  <proxy>\n");
+		fprintf(fp, "   <type>%s</type>\n",
+				(proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" :
+				 proxy_type == GAIM_PROXY_HTTP       ? "http"   :
+				 proxy_type == GAIM_PROXY_SOCKS4     ? "socks4" :
+				 proxy_type == GAIM_PROXY_SOCKS5     ? "socks5" : "unknown"));
+
+		if (proxy_type != GAIM_PROXY_USE_GLOBAL) {
+			if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
+				fprintf(fp, "   <host>%s</host>\n", value);
+
+			if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0)
+				fprintf(fp, "   <port>%d</port>\n", int_value);
+
+			if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
+				fprintf(fp, "   <username>%s</username>\n", value);
+
+			if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
+				fprintf(fp, "   <password>%s</password>\n", value);
+		}
+
+		fprintf(fp, "  </proxy>\n");
+	}
+
 	fprintf(fp, " </account>\n");
 }