comparison libpurple/protocols/irc/irc.c @ 26237:eb21f65728c0

propagate from branch 'im.pidgin.pidgin' (head bc80dc424bc7a7e274901f9124173538e5b43f41) to branch 'im.pidgin.soc.2008.yahoo' (head 42700e96e9188523e8d99406abde695abf97caf5)
author Sulabh Mahajan <sulabh@soc.pidgin.im>
date Wed, 12 Nov 2008 10:18:49 +0000
parents c204239bef48
children 125cac3e24ee 32ad012ef6ac bcad7dc4b453 6ecfc6b9667c
comparison
equal deleted inserted replaced
26236:618d122af044 26237:eb21f65728c0
60 static gboolean irc_nick_equal(const char *nick1, const char *nick2); 60 static gboolean irc_nick_equal(const char *nick1, const char *nick2);
61 static void irc_buddy_free(struct irc_buddy *ib); 61 static void irc_buddy_free(struct irc_buddy *ib);
62 62
63 PurplePlugin *_irc_plugin = NULL; 63 PurplePlugin *_irc_plugin = NULL;
64 64
65 static const char *status_chars = "@+%&";
66
67 static void irc_view_motd(PurplePluginAction *action) 65 static void irc_view_motd(PurplePluginAction *action)
68 { 66 {
69 PurpleConnection *gc = (PurpleConnection *) action->context; 67 PurpleConnection *gc = (PurpleConnection *) action->context;
70 struct irc_conn *irc; 68 struct irc_conn *irc;
71 char *title; 69 char *title;
358 } 356 }
359 } 357 }
360 358
361 static gboolean do_login(PurpleConnection *gc) { 359 static gboolean do_login(PurpleConnection *gc) {
362 char *buf, *tmp = NULL; 360 char *buf, *tmp = NULL;
363 char hostname[256]; 361 char *hostname, *server;
362 const char *hosttmp;
364 const char *username, *realname; 363 const char *username, *realname;
365 struct irc_conn *irc = gc->proto_data; 364 struct irc_conn *irc = gc->proto_data;
366 const char *pass = purple_connection_get_password(gc); 365 const char *pass = purple_connection_get_password(gc);
367 int ret;
368 366
369 if (pass && *pass) { 367 if (pass && *pass) {
370 buf = irc_format(irc, "vv", "PASS", pass); 368 buf = irc_format(irc, "vv", "PASS", pass);
371 if (irc_send(irc, buf) < 0) { 369 if (irc_send(irc, buf) < 0) {
372 g_free(buf); 370 g_free(buf);
373 return FALSE; 371 return FALSE;
374 } 372 }
375 g_free(buf); 373 g_free(buf);
376 } 374 }
377 375
378
379 ret = gethostname(hostname, sizeof(hostname));
380 hostname[sizeof(hostname) - 1] = '\0';
381 if (ret < 0 || hostname[0] == '\0') {
382 purple_debug_warning("irc", "gethostname() failed -- is your hostname set?");
383 strcpy(hostname, "localhost");
384 }
385 realname = purple_account_get_string(irc->account, "realname", ""); 376 realname = purple_account_get_string(irc->account, "realname", "");
386 username = purple_account_get_string(irc->account, "username", ""); 377 username = purple_account_get_string(irc->account, "username", "");
387 378
388 if (username == NULL || *username == '\0') { 379 if (username == NULL || *username == '\0') {
389 username = g_get_user_name(); 380 username = g_get_user_name();
394 while ((buf = strchr(tmp, ' ')) != NULL) { 385 while ((buf = strchr(tmp, ' ')) != NULL) {
395 *buf = '_'; 386 *buf = '_';
396 } 387 }
397 } 388 }
398 389
399 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server, 390 hosttmp = purple_get_host_name();
400 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); 391 if (*hosttmp == ':') {
392 /* This is either an IPv6 address, or something which
393 * doesn't belong here. Either way, we need to escape
394 * it. */
395 hostname = g_strdup_printf("0%s", hosttmp);
396 } else {
397 /* Ugly, I know. */
398 hostname = g_strdup(hosttmp);
399 }
400
401 if (*irc->server == ':') {
402 /* Same as hostname, above. */
403 server = g_strdup_printf("0%s", irc->server);
404 } else {
405 server = g_strdup(irc->server);
406 }
407
408 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, server,
409 strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
401 g_free(tmp); 410 g_free(tmp);
411 g_free(hostname);
412 g_free(server);
402 if (irc_send(irc, buf) < 0) { 413 if (irc_send(irc, buf) < 0) {
403 g_free(buf); 414 g_free(buf);
404 return FALSE; 415 return FALSE;
405 } 416 }
406 g_free(buf); 417 g_free(buf);
503 { 514 {
504 struct irc_conn *irc = gc->proto_data; 515 struct irc_conn *irc = gc->proto_data;
505 char *plain; 516 char *plain;
506 const char *args[2]; 517 const char *args[2];
507 518
508 if (strchr(status_chars, *who) != NULL) 519 args[0] = irc_nick_skip_mode(irc, who);
509 args[0] = who + 1;
510 else
511 args[0] = who;
512 520
513 purple_markup_html_to_xhtml(what, NULL, &plain); 521 purple_markup_html_to_xhtml(what, NULL, &plain);
514 args[1] = plain; 522 args[1] = plain;
515 523
516 irc_cmd_privmsg(irc, "msg", NULL, args); 524 irc_cmd_privmsg(irc, "msg", NULL, args);
974 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 982 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
975 983
976 option = purple_account_option_string_new(_("Encodings"), "encoding", IRC_DEFAULT_CHARSET); 984 option = purple_account_option_string_new(_("Encodings"), "encoding", IRC_DEFAULT_CHARSET);
977 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 985 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
978 986
987 option = purple_account_option_bool_new(_("Auto-detect incoming UTF-8"), "autodetect_utf8", IRC_DEFAULT_AUTODETECT);
988 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
989
979 option = purple_account_option_string_new(_("Username"), "username", ""); 990 option = purple_account_option_string_new(_("Username"), "username", "");
980 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 991 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
981 992
982 option = purple_account_option_string_new(_("Real name"), "realname", ""); 993 option = purple_account_option_string_new(_("Real name"), "realname", "");
983 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 994 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);