comparison src/protocols/jabber/jabber.c @ 4917:c0c6efda8151

[gaim-migrate @ 5251] Note: Although sometimes it seems as if I'm just ignoring patches for no good reason, sometimes I'm ignoring them for good reasons. Either way, I tend not to appreciate people going over my head to get them committed. Thank you. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Mon, 31 Mar 2003 07:51:01 +0000
parents d9b6b5ae34e4
children d5c136474f26
comparison
equal deleted inserted replaced
4916:d9b6b5ae34e4 4917:c0c6efda8151
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 15 * GNU General Public License for more details.
17 * 16 *
80 #define UC_CHAT 0x04 79 #define UC_CHAT 0x04
81 #define UC_XA (0x08 | UC_UNAVAILABLE) 80 #define UC_XA (0x08 | UC_UNAVAILABLE)
82 #define UC_DND (0x10 | UC_UNAVAILABLE) 81 #define UC_DND (0x10 | UC_UNAVAILABLE)
83 #define UC_ERROR (0x20 | UC_UNAVAILABLE) 82 #define UC_ERROR (0x20 | UC_UNAVAILABLE)
84 83
84 #define DEFAULT_SERVER "jabber.org"
85 #define DEFAULT_GROUPCHAT "conference.jabber.org" 85 #define DEFAULT_GROUPCHAT "conference.jabber.org"
86 #define DEFAULT_PORT 5222 86 #define DEFAULT_PORT 5222
87 #define DEFAULT_RESOURCE "Gaim"
88 87
89 #define USEROPT_PORT 0 88 #define USEROPT_PORT 0
90 #define USEROPT_CONN_SERVER 1 89 #define USEROPT_CONN_SERVER 1
91 90
92 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */ 91 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */
246 static char *jabber_normalize(const char *s); 245 static char *jabber_normalize(const char *s);
247 246
248 static char *create_valid_jid(const char *given, char *server, char *resource) 247 static char *create_valid_jid(const char *given, char *server, char *resource)
249 { 248 {
250 char *valid; 249 char *valid;
251 char *tmp; 250
252 251 if (!strchr(given, '@'))
253 if (!(tmp = strchr(given, '@')))
254 valid = g_strdup_printf("%s@%s/%s", given, server, resource); 252 valid = g_strdup_printf("%s@%s/%s", given, server, resource);
255 else if (!strchr(tmp, '/')) 253 else if (!strchr(strchr(given, '@'), '/'))
256 valid = g_strdup_printf("%s/%s", given, resource); 254 valid = g_strdup_printf("%s/%s", given, resource);
257 else 255 else
258 valid = g_strdup(given); 256 valid = g_strdup(given);
259 257
260 return valid; 258 return valid;
261 } 259 }
262 260
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);
276 else
277 valid = g_strdup(given);
278
279 return valid;
280 }
281 261
282 /* 262 /*
283 * Dispose of a gaim_jid_struct 263 * Dispose of a gaim_jid_struct
284 */ 264 */
285 static void gaim_jid_free(gaim_jid gjid) 265 static void gaim_jid_free(gaim_jid gjid)
2285 2265
2286 static void jabber_login(struct gaim_account *account) 2266 static void jabber_login(struct gaim_account *account)
2287 { 2267 {
2288 struct gaim_connection *gc = new_gaim_conn(account); 2268 struct gaim_connection *gc = new_gaim_conn(account);
2289 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 2269 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
2290 char *loginname = create_login_name(gc); 2270 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
2291
2292 if (!loginname) {
2293 hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
2294 signoff(gc);
2295 return;
2296 }
2297 2271
2298 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); 2272 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
2299 jd->chats = NULL; /* we have no chats yet */ 2273 jd->chats = NULL; /* we have no chats yet */
2300 2274
2301 set_login_progress(gc, 1, _("Connecting")); 2275 set_login_progress(gc, 1, _("Connecting"));
4139 */ 4113 */
4140 void jabber_register_user(struct gaim_account *account) 4114 void jabber_register_user(struct gaim_account *account)
4141 { 4115 {
4142 struct gaim_connection *gc = new_gaim_conn(account); 4116 struct gaim_connection *gc = new_gaim_conn(account);
4143 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 4117 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
4144 char *loginname = create_login_name(gc); 4118 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
4145
4146 if (!loginname) {
4147 hide_login_progress(gc, _("Jabber IDs must be of the form user@server"));
4148 signoff(gc);
4149 return;
4150 }
4151 4119
4152 /* 4120 /*
4153 * These do nothing during registration 4121 * These do nothing during registration
4154 */ 4122 */
4155 jd->buddies = NULL; 4123 jd->buddies = NULL;
4253 ret->convo_closed = jabber_convo_closed; 4221 ret->convo_closed = jabber_convo_closed;
4254 ret->rename_group = jabber_rename_group; 4222 ret->rename_group = jabber_rename_group;
4255 4223
4256 puo = g_new0(struct proto_user_opt, 1); 4224 puo = g_new0(struct proto_user_opt, 1);
4257 puo->label = g_strdup(_("Port:")); 4225 puo->label = g_strdup(_("Port:"));
4258 puo->def = g_strdup_printf("%d", DEFAULT_PORT); 4226 puo->def = g_strdup_printf("%d", "5222");
4259 puo->pos = USEROPT_PORT; 4227 puo->pos = USEROPT_PORT;
4260 ret->user_opts = g_list_append(ret->user_opts, puo); 4228 ret->user_opts = g_list_append(ret->user_opts, puo);
4261 4229
4262 puo = g_new0(struct proto_user_opt, 1); 4230 puo = g_new0(struct proto_user_opt, 1);
4263 puo->label = g_strdup(_("Connect Server:\n(optional)")); 4231 puo->label = g_strdup(_("Connect Server:"));
4264 puo->def = g_strdup(""); 4232 puo->def = g_strdup("");
4265 puo->pos = USEROPT_CONN_SERVER; 4233 puo->pos = USEROPT_CONN_SERVER;
4266 ret->user_opts = g_list_append(ret->user_opts, puo); 4234 ret->user_opts = g_list_append(ret->user_opts, puo);
4267 4235
4268 my_protocol = ret; 4236 my_protocol = ret;