| 177 char *converted = g_malloc(maxlen + 1); |
177 char *converted = g_malloc(maxlen + 1); |
| 178 gchar *inptr = string, *outptr = converted; |
178 gchar *inptr = string, *outptr = converted; |
| 179 int inleft = strlen(string), outleft = maxlen; |
179 int inleft = strlen(string), outleft = maxlen; |
| 180 GIConv conv; |
180 GIConv conv; |
| 181 |
181 |
| 182 conv = g_iconv_open(gc->user->proto_opt[USEROPT_CHARSET], "UTF-8"); |
182 conv = g_iconv_open(gc->account->proto_opt[USEROPT_CHARSET], "UTF-8"); |
| 183 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { |
183 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { |
| 184 debug_printf("IRC charset conversion error\n"); |
184 debug_printf("IRC charset conversion error\n"); |
| 185 debug_printf("Sending as UTF-8 (this is a hack!)\n"); |
185 debug_printf("Sending as UTF-8 (this is a hack!)\n"); |
| 186 g_free(converted); |
186 g_free(converted); |
| 187 *done = maxlen; |
187 *done = maxlen; |
| 198 { |
198 { |
| 199 char *utf8; |
199 char *utf8; |
| 200 GError *err = NULL; |
200 GError *err = NULL; |
| 201 |
201 |
| 202 utf8 = g_convert(string, strlen(string), "UTF-8", |
202 utf8 = g_convert(string, strlen(string), "UTF-8", |
| 203 gc->user->proto_opt[USEROPT_CHARSET], NULL, NULL, &err); |
203 gc->account->proto_opt[USEROPT_CHARSET], NULL, NULL, &err); |
| 204 if (err) { |
204 if (err) { |
| 205 debug_printf("IRC recv conversion error: %s\n", err->message); |
205 debug_printf("IRC recv conversion error: %s\n", err->message); |
| 206 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
206 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
| 207 } |
207 } |
| 208 |
208 |
| 503 } |
503 } |
| 504 } |
504 } |
| 505 else { |
505 else { |
| 506 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), |
506 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), |
| 507 chat->nick); |
507 chat->nick); |
| 508 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->user, |
508 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->account, |
| 509 chat->nick); |
509 chat->nick); |
| 510 gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, |
510 gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, |
| 511 time(NULL)); |
511 time(NULL)); |
| 512 dcc_chat_cancel (chat); |
512 dcc_chat_cancel (chat); |
| 513 } |
513 } |
| 566 dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { |
566 dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { |
| 567 struct dcc_chat *chat = data; |
567 struct dcc_chat *chat = data; |
| 568 struct gaim_conversation *convo; |
568 struct gaim_conversation *convo; |
| 569 char buf[IRC_BUF_LEN]; |
569 char buf[IRC_BUF_LEN]; |
| 570 |
570 |
| 571 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->user, chat->nick); |
571 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->account, chat->nick); |
| 572 |
572 |
| 573 chat->fd = source; |
573 chat->fd = source; |
| 574 g_snprintf (buf, sizeof buf, |
574 g_snprintf (buf, sizeof buf, |
| 575 _("DCC Chat with %s established"), |
575 _("DCC Chat with %s established"), |
| 576 chat->nick); |
576 chat->nick); |
| 607 gr = groups; |
607 gr = groups; |
| 608 while (gr) { |
608 while (gr) { |
| 609 GSList *m = ((struct group *)gr->data)->members; |
609 GSList *m = ((struct group *)gr->data)->members; |
| 610 while (m) { |
610 while (m) { |
| 611 struct buddy *b = m->data; |
611 struct buddy *b = m->data; |
| 612 if(b->user->gc == gc) { |
612 if(b->account->gc == gc) { |
| 613 char *tmp = g_strdup(b->name); |
613 char *tmp = g_strdup(b->name); |
| 614 char *x, *l; |
614 char *x, *l; |
| 615 g_strdown(tmp); |
615 g_strdown(tmp); |
| 616 x = strstr(id->str->str, tmp); |
616 x = strstr(id->str->str, tmp); |
| 617 l = x + strlen(b->name); |
617 l = x + strlen(b->name); |
| 647 while (gr) { |
647 while (gr) { |
| 648 struct group *g = gr->data; |
648 struct group *g = gr->data; |
| 649 GSList *m = g->members; |
649 GSList *m = g->members; |
| 650 while (m) { |
650 while (m) { |
| 651 struct buddy *b = m->data; |
651 struct buddy *b = m->data; |
| 652 if(b->user->gc == gc) { |
652 if(b->account->gc == gc) { |
| 653 if (n + strlen(b->name) + 2 > sizeof(buf)) { |
653 if (n + strlen(b->name) + 2 > sizeof(buf)) { |
| 654 g_snprintf(buf + n, sizeof(buf) - n, "\r\n"); |
654 g_snprintf(buf + n, sizeof(buf) - n, "\r\n"); |
| 655 irc_write(id->fd, buf, n); |
655 irc_write(id->fd, buf, n); |
| 656 id->bc++; |
656 id->bc++; |
| 657 n = g_snprintf(buf, sizeof(buf), "ISON"); |
657 n = g_snprintf(buf, sizeof(buf), "ISON"); |
| 1260 irc_send_notice (gc, nick, buf); |
1260 irc_send_notice (gc, nick, buf); |
| 1261 g_snprintf(out, sizeof(out), ">> CTCP CLIENTINFO requested from %s", nick); |
1261 g_snprintf(out, sizeof(out), ">> CTCP CLIENTINFO requested from %s", nick); |
| 1262 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); |
1262 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); |
| 1263 } |
1263 } |
| 1264 if (!g_strncasecmp(msg, "USERINFO", 8)) { |
1264 if (!g_strncasecmp(msg, "USERINFO", 8)) { |
| 1265 g_snprintf(buf, sizeof(buf), "\001USERINFO Alias: %s\001", gc->user->alias); |
1265 g_snprintf(buf, sizeof(buf), "\001USERINFO Alias: %s\001", gc->account->alias); |
| 1266 irc_send_notice (gc, nick, buf); |
1266 irc_send_notice (gc, nick, buf); |
| 1267 g_snprintf(out, sizeof(out), ">> CTCP USERINFO requested from %s", nick); |
1267 g_snprintf(out, sizeof(out), ">> CTCP USERINFO requested from %s", nick); |
| 1268 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); |
1268 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); |
| 1269 } |
1269 } |
| 1270 if (!g_strncasecmp(msg, "ACTION", 6)) { |
1270 if (!g_strncasecmp(msg, "ACTION", 6)) { |
| 1391 if (!strcmp(gc->displayname, word[4])) { |
1391 if (!strcmp(gc->displayname, word[4])) { |
| 1392 struct gaim_conversation *c = irc_find_chat(gc, word[3]); |
1392 struct gaim_conversation *c = irc_find_chat(gc, word[3]); |
| 1393 if (!c) |
1393 if (!c) |
| 1394 return FALSE; |
1394 return FALSE; |
| 1395 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
1395 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
| 1396 gaim_conversation_set_user(c, NULL); |
1396 gaim_conversation_set_account(c, NULL); |
| 1397 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"), |
1397 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"), |
| 1398 word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]); |
1398 word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]); |
| 1399 do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR); |
1399 do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR); |
| 1400 } else { |
1400 } else { |
| 1401 char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]; |
1401 char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]; |
| 1671 return; |
1671 return; |
| 1672 } |
1672 } |
| 1673 idata->fd = source; |
1673 idata->fd = source; |
| 1674 |
1674 |
| 1675 /* Try a quick conversion to see if the specified encoding is OK */ |
1675 /* Try a quick conversion to see if the specified encoding is OK */ |
| 1676 test = g_convert("test", strlen("test"), gc->user->proto_opt[USEROPT_CHARSET], |
1676 test = g_convert("test", strlen("test"), gc->account->proto_opt[USEROPT_CHARSET], |
| 1677 "UTF-8", NULL, NULL, &err); |
1677 "UTF-8", NULL, NULL, &err); |
| 1678 if (err) { |
1678 if (err) { |
| 1679 debug_printf("Couldn't initialize %s for IRC charset conversion, using ISO-8859-1\n", |
1679 debug_printf("Couldn't initialize %s for IRC charset conversion, using ISO-8859-1\n", |
| 1680 gc->user->proto_opt[USEROPT_CHARSET]); |
1680 gc->account->proto_opt[USEROPT_CHARSET]); |
| 1681 strcpy(gc->user->proto_opt[USEROPT_CHARSET], "ISO-8859-1"); |
1681 strcpy(gc->account->proto_opt[USEROPT_CHARSET], "ISO-8859-1"); |
| 1682 } |
1682 } |
| 1683 |
1683 |
| 1684 g_free(test); |
1684 g_free(test); |
| 1685 |
1685 |
| 1686 gethostname(hostname, sizeof(hostname) - 1); |
1686 gethostname(hostname, sizeof(hostname) - 1); |
| 1687 hostname[sizeof(hostname) - 1] = 0; |
1687 hostname[sizeof(hostname) - 1] = 0; |
| 1688 if (!*hostname) |
1688 if (!*hostname) |
| 1689 g_snprintf(hostname, sizeof(hostname), "localhost"); |
1689 g_snprintf(hostname, sizeof(hostname), "localhost"); |
| 1690 |
1690 |
| 1691 if (*gc->user->password) { |
1691 if (*gc->account->password) { |
| 1692 g_snprintf(buf, sizeof(buf), "PASS %s\r\n", gc->user->password); |
1692 g_snprintf(buf, sizeof(buf), "PASS %s\r\n", gc->account->password); |
| 1693 |
1693 |
| 1694 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
1694 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
| 1695 hide_login_progress(gc, "Write error"); |
1695 hide_login_progress(gc, "Write error"); |
| 1696 signoff(gc); |
1696 signoff(gc); |
| 1697 return; |
1697 return; |
| 1698 } |
1698 } |
| 1699 } |
1699 } |
| 1700 |
1700 |
| 1701 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", |
1701 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", |
| 1702 g_get_user_name(), hostname, |
1702 g_get_user_name(), hostname, |
| 1703 gc->user->proto_opt[USEROPT_SERV], |
1703 gc->account->proto_opt[USEROPT_SERV], |
| 1704 gc->user->alias && strlen(gc->user->alias) ? gc->user->alias : "gaim"); |
1704 gc->account->alias && strlen(gc->account->alias) ? gc->account->alias : "gaim"); |
| 1705 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
1705 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
| 1706 hide_login_progress(gc, "Write error"); |
1706 hide_login_progress(gc, "Write error"); |
| 1707 signoff(gc); |
1707 signoff(gc); |
| 1708 return; |
1708 return; |
| 1709 } |
1709 } |
| 1717 |
1717 |
| 1718 gc->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); |
1718 gc->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); |
| 1719 } |
1719 } |
| 1720 |
1720 |
| 1721 static void |
1721 static void |
| 1722 irc_login(struct aim_user *user) |
1722 irc_login(struct gaim_account *account) |
| 1723 { |
1723 { |
| 1724 char buf[IRC_BUF_LEN]; |
1724 char buf[IRC_BUF_LEN]; |
| 1725 int rc; |
1725 int rc; |
| 1726 |
1726 |
| 1727 struct gaim_connection *gc = new_gaim_conn(user); |
1727 struct gaim_connection *gc = new_gaim_conn(account); |
| 1728 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); |
1728 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); |
| 1729 |
1729 |
| 1730 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", gc->username); |
1730 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", gc->username); |
| 1731 |
1731 |
| 1732 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
1732 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
| 1736 idata->chanmodes = g_strdup("beI,k,lnt"); |
1736 idata->chanmodes = g_strdup("beI,k,lnt"); |
| 1737 idata->nickmodes = g_strdup("ohv"); |
1737 idata->nickmodes = g_strdup("ohv"); |
| 1738 idata->str = g_string_new(""); |
1738 idata->str = g_string_new(""); |
| 1739 idata->fd = -1; |
1739 idata->fd = -1; |
| 1740 |
1740 |
| 1741 rc = proxy_connect(user->proto_opt[USEROPT_SERV], |
1741 rc = proxy_connect(account->proto_opt[USEROPT_SERV], |
| 1742 user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : |
1742 account->proto_opt[USEROPT_PORT][0] ? |
| 1743 6667, irc_login_callback, gc); |
1743 atoi(account->proto_opt[USEROPT_PORT]) : 6667, |
| 1744 if (!user->gc || (rc != 0)) { |
1744 irc_login_callback, gc); |
| |
1745 if (!account->gc || (rc != 0)) { |
| 1745 hide_login_progress(gc, "Unable to create socket"); |
1746 hide_login_progress(gc, "Unable to create socket"); |
| 1746 signoff(gc); |
1747 signoff(gc); |
| 1747 return; |
1748 return; |
| 1748 } |
1749 } |
| 1749 } |
1750 } |
| 2079 } else |
2080 } else |
| 2080 g_snprintf(buf, sizeof(buf), "PART %s\r\n", chan); |
2081 g_snprintf(buf, sizeof(buf), "PART %s\r\n", chan); |
| 2081 irc_write(id->fd, buf, strlen(buf)); |
2082 irc_write(id->fd, buf, strlen(buf)); |
| 2082 if (c) { |
2083 if (c) { |
| 2083 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
2084 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
| 2084 gaim_conversation_set_user(c, NULL); |
2085 gaim_conversation_set_account(c, NULL); |
| 2085 g_snprintf(buf, sizeof(buf), _("You have left %s"), chan); |
2086 g_snprintf(buf, sizeof(buf), _("You have left %s"), chan); |
| 2086 do_error_dialog(buf, _("IRC Part"), GAIM_INFO); |
2087 do_error_dialog(buf, _("IRC Part"), GAIM_INFO); |
| 2087 } |
2088 } |
| 2088 } else if (!g_strcasecmp(pdibuf, "WHOIS")) { |
2089 } else if (!g_strcasecmp(pdibuf, "WHOIS")) { |
| 2089 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", word_eol[2]); |
2090 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", word_eol[2]); |
| 2376 addr.sin_port = htons (chat->port); |
2377 addr.sin_port = htons (chat->port); |
| 2377 addr.sin_addr.s_addr = INADDR_ANY; |
2378 addr.sin_addr.s_addr = INADDR_ANY; |
| 2378 chat->fd = accept (chat->fd, (struct sockaddr *) (&addr), &addrlen); |
2379 chat->fd = accept (chat->fd, (struct sockaddr *) (&addr), &addrlen); |
| 2379 if (!chat->fd) { |
2380 if (!chat->fd) { |
| 2380 dcc_chat_cancel (chat); |
2381 dcc_chat_cancel (chat); |
| 2381 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->user, |
2382 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->account, |
| 2382 chat->nick); |
2383 chat->nick); |
| 2383 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), |
2384 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), |
| 2384 chat->nick); |
2385 chat->nick); |
| 2385 gaim_conversation_write(convo, NULL, buf, -1, |
2386 gaim_conversation_write(convo, NULL, buf, -1, |
| 2386 WFLAG_SYSTEM, time(NULL)); |
2387 WFLAG_SYSTEM, time(NULL)); |
| 2387 return; |
2388 return; |
| 2388 } |
2389 } |
| 2389 chat->inpa = |
2390 chat->inpa = |
| 2390 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_in, chat); |
2391 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_in, chat); |
| 2391 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->user, chat->nick); |
2392 convo = gaim_conversation_new(GAIM_CONV_IM, chat->gc->account, chat->nick); |
| 2392 g_snprintf (buf, sizeof buf, _("DCC Chat with %s established"), |
2393 g_snprintf (buf, sizeof buf, _("DCC Chat with %s established"), |
| 2393 chat->nick); |
2394 chat->nick); |
| 2394 gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); |
2395 gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); |
| 2395 debug_printf ("Chat with %s established\n", chat->nick); |
2396 debug_printf ("Chat with %s established\n", chat->nick); |
| 2396 dcc_chat_list = g_slist_append (dcc_chat_list, chat); |
2397 dcc_chat_list = g_slist_append (dcc_chat_list, chat); |
| 2597 irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment) |
2598 irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment) |
| 2598 { |
2599 { |
| 2599 char buf[IRC_BUF_LEN], *intl; |
2600 char buf[IRC_BUF_LEN], *intl; |
| 2600 struct irc_data *id = gc->proto_data; |
2601 struct irc_data *id = gc->proto_data; |
| 2601 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ |
2602 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ |
| 2602 int nicklen = (gc->user->alias && strlen(gc->user->alias)) ? strlen(gc->user->alias) : 4; |
2603 int nicklen = (gc->account->alias && strlen(gc->account->alias)) ? strlen(gc->account->alias) : 4; |
| 2603 int max = 444 - strlen(who) - strlen(g_get_user_name()) - nicklen; |
2604 int max = 444 - strlen(who) - strlen(g_get_user_name()) - nicklen; |
| 2604 |
2605 |
| 2605 int len; |
2606 int len; |
| 2606 |
2607 |
| 2607 do { |
2608 do { |