changeset 4915:0230df73f56a

[gaim-migrate @ 5249] (21:35:04) Robot101: now we have a confusing optional jabber server option (21:36:00) Robot101: it becomes infinitely confusing to append jabber.org to someone's username when they've specified a server further down in the same dialog committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 31 Mar 2003 02:38:44 +0000
parents 10a0917c1c0f
children d9b6b5ae34e4
files src/protocols/jabber/jabber.c
diffstat 1 files changed, 40 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/jabber.c	Sun Mar 30 23:14:57 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Mon Mar 31 02:38:44 2003 +0000
@@ -82,9 +82,9 @@
 #define UC_DND    (0x10 | UC_UNAVAILABLE)
 #define UC_ERROR  (0x20 | UC_UNAVAILABLE)
 
-#define DEFAULT_SERVER "jabber.org"
 #define DEFAULT_GROUPCHAT "conference.jabber.org"
 #define DEFAULT_PORT 5222
+#define DEFAULT_RESOURCE "Gaim"
 
 #define USEROPT_PORT 0
 #define USEROPT_CONN_SERVER 1
@@ -248,10 +248,11 @@
 static char *create_valid_jid(const char *given, char *server, char *resource)
 {
 	char *valid;
-
-	if (!strchr(given, '@'))
+	char *tmp;
+
+	if (!(tmp = strchr(given, '@')))
 		valid = g_strdup_printf("%s@%s/%s", given, server, resource);
-	else if (!strchr(strchr(given, '@'), '/'))
+	else if (!strchr(tmp, '/'))
 		valid = g_strdup_printf("%s/%s", given, resource);
 	else
 		valid = g_strdup(given);
@@ -259,6 +260,25 @@
 	return valid;
 }
 
+/* checks the username of a GC is a valid JID and appends   *
+ * the resource if necessary. returns NULL for invalid JID. *
+ * for jabber_login and jabber_register_user                */
+static char *create_login_name(struct gaim_connection *gc)
+{
+	char *given = gc->account->username;
+	char *valid;
+	char *tmp;
+
+	if (!(tmp = strchr(given, '@')))
+		valid = NULL;
+	else if (!strchr(tmp, '/'))
+		valid = g_strdup_printf("%s/%s", given, DEFAULT_RESOURCE);
+	else
+		valid = g_strdup(given);
+
+	return valid;
+}
+
 /*
  * Dispose of a gaim_jid_struct
  */
@@ -2267,7 +2287,13 @@
 {
 	struct gaim_connection *gc = new_gaim_conn(account);
 	struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
-	char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
+	char *loginname = create_login_name(gc);
+
+	if (!loginname) {
+		hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
+		signoff(gc);
+		return;
+	}
 
 	jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
 	jd->chats = NULL;	/* we have no chats yet */
@@ -4124,7 +4150,13 @@
 {
 	struct gaim_connection *gc = new_gaim_conn(account);
 	struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
-	char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
+	char *loginname = create_login_name(gc);
+
+	if (!loginname) {
+		hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
+		signoff(gc);
+		return;
+	}
 
 	/*
 	 * These do nothing during registration
@@ -4232,12 +4264,12 @@
 
 	puo = g_new0(struct proto_user_opt, 1);
 	puo->label = g_strdup(_("Port:"));
-	puo->def = g_strdup("5222");
+	puo->def = g_strdup_printf("%d", DEFAULT_PORT);
 	puo->pos = USEROPT_PORT;
 	ret->user_opts = g_list_append(ret->user_opts, puo);
 
 	puo = g_new0(struct proto_user_opt, 1);
-	puo->label = g_strdup(_("Connect Server:"));
+	puo->label = g_strdup(_("Connect Server:\n(optional)"));
 	puo->def = g_strdup("");
 	puo->pos = USEROPT_CONN_SERVER;
 	ret->user_opts = g_list_append(ret->user_opts, puo);