comparison src/protocols/jabber/jabber.c @ 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 f98467b35b95
children d9b6b5ae34e4
comparison
equal deleted inserted replaced
4914:10a0917c1c0f 4915:0230df73f56a
80 #define UC_CHAT 0x04 80 #define UC_CHAT 0x04
81 #define UC_XA (0x08 | UC_UNAVAILABLE) 81 #define UC_XA (0x08 | UC_UNAVAILABLE)
82 #define UC_DND (0x10 | UC_UNAVAILABLE) 82 #define UC_DND (0x10 | UC_UNAVAILABLE)
83 #define UC_ERROR (0x20 | UC_UNAVAILABLE) 83 #define UC_ERROR (0x20 | UC_UNAVAILABLE)
84 84
85 #define DEFAULT_SERVER "jabber.org"
86 #define DEFAULT_GROUPCHAT "conference.jabber.org" 85 #define DEFAULT_GROUPCHAT "conference.jabber.org"
87 #define DEFAULT_PORT 5222 86 #define DEFAULT_PORT 5222
87 #define DEFAULT_RESOURCE "Gaim"
88 88
89 #define USEROPT_PORT 0 89 #define USEROPT_PORT 0
90 #define USEROPT_CONN_SERVER 1 90 #define USEROPT_CONN_SERVER 1
91 91
92 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */ 92 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */
246 static char *jabber_normalize(const char *s); 246 static char *jabber_normalize(const char *s);
247 247
248 static char *create_valid_jid(const char *given, char *server, char *resource) 248 static char *create_valid_jid(const char *given, char *server, char *resource)
249 { 249 {
250 char *valid; 250 char *valid;
251 251 char *tmp;
252 if (!strchr(given, '@')) 252
253 if (!(tmp = strchr(given, '@')))
253 valid = g_strdup_printf("%s@%s/%s", given, server, resource); 254 valid = g_strdup_printf("%s@%s/%s", given, server, resource);
254 else if (!strchr(strchr(given, '@'), '/')) 255 else if (!strchr(tmp, '/'))
255 valid = g_strdup_printf("%s/%s", given, resource); 256 valid = g_strdup_printf("%s/%s", given, resource);
257 else
258 valid = g_strdup(given);
259
260 return valid;
261 }
262
263 /* checks the username of a GC is a valid JID and appends *
264 * the resource if necessary. returns NULL for invalid JID. *
265 * for jabber_login and jabber_register_user */
266 static char *create_login_name(struct gaim_connection *gc)
267 {
268 char *given = gc->account->username;
269 char *valid;
270 char *tmp;
271
272 if (!(tmp = strchr(given, '@')))
273 valid = NULL;
274 else if (!strchr(tmp, '/'))
275 valid = g_strdup_printf("%s/%s", given, DEFAULT_RESOURCE);
256 else 276 else
257 valid = g_strdup(given); 277 valid = g_strdup(given);
258 278
259 return valid; 279 return valid;
260 } 280 }
2265 2285
2266 static void jabber_login(struct gaim_account *account) 2286 static void jabber_login(struct gaim_account *account)
2267 { 2287 {
2268 struct gaim_connection *gc = new_gaim_conn(account); 2288 struct gaim_connection *gc = new_gaim_conn(account);
2269 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 2289 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
2270 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim"); 2290 char *loginname = create_login_name(gc);
2291
2292 if (!loginname) {
2293 hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
2294 signoff(gc);
2295 return;
2296 }
2271 2297
2272 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); 2298 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
2273 jd->chats = NULL; /* we have no chats yet */ 2299 jd->chats = NULL; /* we have no chats yet */
2274 2300
2275 set_login_progress(gc, 1, _("Connecting")); 2301 set_login_progress(gc, 1, _("Connecting"));
4122 */ 4148 */
4123 void jabber_register_user(struct gaim_account *account) 4149 void jabber_register_user(struct gaim_account *account)
4124 { 4150 {
4125 struct gaim_connection *gc = new_gaim_conn(account); 4151 struct gaim_connection *gc = new_gaim_conn(account);
4126 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 4152 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
4127 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim"); 4153 char *loginname = create_login_name(gc);
4154
4155 if (!loginname) {
4156 hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
4157 signoff(gc);
4158 return;
4159 }
4128 4160
4129 /* 4161 /*
4130 * These do nothing during registration 4162 * These do nothing during registration
4131 */ 4163 */
4132 jd->buddies = NULL; 4164 jd->buddies = NULL;
4230 ret->convo_closed = jabber_convo_closed; 4262 ret->convo_closed = jabber_convo_closed;
4231 ret->rename_group = jabber_rename_group; 4263 ret->rename_group = jabber_rename_group;
4232 4264
4233 puo = g_new0(struct proto_user_opt, 1); 4265 puo = g_new0(struct proto_user_opt, 1);
4234 puo->label = g_strdup(_("Port:")); 4266 puo->label = g_strdup(_("Port:"));
4235 puo->def = g_strdup("5222"); 4267 puo->def = g_strdup_printf("%d", DEFAULT_PORT);
4236 puo->pos = USEROPT_PORT; 4268 puo->pos = USEROPT_PORT;
4237 ret->user_opts = g_list_append(ret->user_opts, puo); 4269 ret->user_opts = g_list_append(ret->user_opts, puo);
4238 4270
4239 puo = g_new0(struct proto_user_opt, 1); 4271 puo = g_new0(struct proto_user_opt, 1);
4240 puo->label = g_strdup(_("Connect Server:")); 4272 puo->label = g_strdup(_("Connect Server:\n(optional)"));
4241 puo->def = g_strdup(""); 4273 puo->def = g_strdup("");
4242 puo->pos = USEROPT_CONN_SERVER; 4274 puo->pos = USEROPT_CONN_SERVER;
4243 ret->user_opts = g_list_append(ret->user_opts, puo); 4275 ret->user_opts = g_list_append(ret->user_opts, puo);
4244 4276
4245 my_protocol = ret; 4277 my_protocol = ret;