comparison src/protocols/irc/irc.c @ 5585:f6650bfe4f51

[gaim-migrate @ 5989] Rather than figuring out why this won't compile (I'm somewhat stumped), I'll go to bed and let someone else figure it out tomorrow. But not before thanking Robert "Chamber of Secrets" McQueen for writing much of this patch. In case you're watching these commits, heeding our advice to stay away, and wondering what we're doing, Good night. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 31 May 2003 05:56:30 +0000
parents cce2d7868c78
children a569fef2a6b1
comparison
equal deleted inserted replaced
5584:cade2082f760 5585:f6650bfe4f51
69 #endif 69 #endif
70 70
71 /* Datastructs */ 71 /* Datastructs */
72 struct dcc_chat 72 struct dcc_chat
73 { 73 {
74 struct gaim_connection *gc; 74 GaimConnection *gc;
75 char ip_address[INET6_ADDRSTRLEN]; 75 char ip_address[INET6_ADDRSTRLEN];
76 int port; 76 int port;
77 int fd; 77 int fd;
78 int inpa; 78 int inpa;
79 char nick[80]; 79 char nick[80];
110 GString *liststr; 110 GString *liststr;
111 GSList *file_transfers; 111 GSList *file_transfers;
112 }; 112 };
113 113
114 /* Prototypes */ 114 /* Prototypes */
115 static void irc_start_chat(struct gaim_connection *gc, const char *who); 115 static void irc_start_chat(GaimConnection *gc, const char *who);
116 static void irc_ctcp_clientinfo(struct gaim_connection *gc, const char *who); 116 static void irc_ctcp_clientinfo(GaimConnection *gc, const char *who);
117 static void irc_ctcp_userinfo(struct gaim_connection *gc, const char *who); 117 static void irc_ctcp_userinfo(GaimConnection *gc, const char *who);
118 static void irc_ctcp_version(struct gaim_connection *gc, const char *who); 118 static void irc_ctcp_version(GaimConnection *gc, const char *who);
119 static void irc_ctcp_ping(struct gaim_connection *gc, const char *who); 119 static void irc_ctcp_ping(GaimConnection *gc, const char *who);
120 120
121 static void irc_send_privmsg(struct gaim_connection *gc, const char *who, const char *what, gboolean fragment); 121 static void irc_send_privmsg(GaimConnection *gc, const char *who, const char *what, gboolean fragment);
122 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what); 122 static void irc_send_notice(GaimConnection *gc, char *who, char *what);
123 123
124 static char *irc_send_convert(struct gaim_connection *gc, const char *string, int maxlen, int *done); 124 static char *irc_send_convert(GaimConnection *gc, const char *string, int maxlen, int *done);
125 static char *irc_recv_convert(struct gaim_connection *gc, char *string); 125 static char *irc_recv_convert(GaimConnection *gc, char *string);
126 static void irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, 126 static void irc_parse_notice(GaimConnection *gc, char *nick, char *ex,
127 char *word[], char *word_eol[]); 127 char *word[], char *word_eol[]);
128 static void irc_parse_join(struct gaim_connection *gc, char *nick, 128 static void irc_parse_join(GaimConnection *gc, char *nick,
129 char *word[], char *word_eol[]); 129 char *word[], char *word_eol[]);
130 static gboolean irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd, 130 static gboolean irc_parse_part(GaimConnection *gc, char *nick, char *cmd,
131 char *word[], char *word_eol[]); 131 char *word[], char *word_eol[]);
132 static void irc_parse_topic(struct gaim_connection *gc, char *nick, 132 static void irc_parse_topic(GaimConnection *gc, char *nick,
133 char *word[], char *word_eol[]); 133 char *word[], char *word_eol[]);
134 134
135 static void dcc_chat_cancel(struct dcc_chat *); 135 static void dcc_chat_cancel(struct dcc_chat *);
136 136
137 /* Global variables */ 137 /* Global variables */
138 GSList *dcc_chat_list = NULL; 138 GSList *dcc_chat_list = NULL;
139 139
140 struct dcc_chat * 140 struct dcc_chat *
141 find_dcc_chat (struct gaim_connection *gc, const char *nick) 141 find_dcc_chat (GaimConnection *gc, const char *nick)
142 { 142 {
143 GSList *tmp; 143 GSList *tmp;
144 struct dcc_chat *data; 144 struct dcc_chat *data;
145 tmp = dcc_chat_list; 145 tmp = dcc_chat_list;
146 while (tmp != NULL) 146 while (tmp != NULL)
164 gaim_debug(GAIM_DEBUG_MISC, "irc", "C: %s", data); 164 gaim_debug(GAIM_DEBUG_MISC, "irc", "C: %s", data);
165 return write(fd, data, len); 165 return write(fd, data, len);
166 } 166 }
167 167
168 static char * 168 static char *
169 irc_send_convert(struct gaim_connection *gc, const char *string, int maxlen, int *done) 169 irc_send_convert(GaimConnection *gc, const char *string, int maxlen, int *done)
170 { 170 {
171 char *converted = g_malloc(maxlen + 1); 171 char *converted = g_malloc(maxlen + 1);
172 gchar *inptr = (gchar*)string, *outptr = converted; 172 gchar *inptr = (gchar*)string, *outptr = converted;
173 int inleft = strlen(string), outleft = maxlen; 173 int inleft = strlen(string), outleft = maxlen;
174 GIConv conv; 174 GIConv conv;
175 175
176 conv = g_iconv_open(gc->account->proto_opt[USEROPT_CHARSET], "UTF-8"); 176 conv = g_iconv_open(gaim_account_get_string(gaim_connection_get_account(gc), "charset", "UTF-8") , "UTF-8");
177 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { 177 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) {
178 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Charset conversion error\n"); 178 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Charset conversion error\n");
179 gaim_debug(GAIM_DEBUG_ERROR, "irc", 179 gaim_debug(GAIM_DEBUG_ERROR, "irc",
180 "Sending as UTF-8 (this is a hack!)\n"); 180 "Sending as UTF-8 (this is a hack!)\n");
181 g_free(converted); 181 g_free(converted);
187 *outptr = '\0'; 187 *outptr = '\0';
188 return(converted); 188 return(converted);
189 } 189 }
190 190
191 static char * 191 static char *
192 irc_recv_convert(struct gaim_connection *gc, char *string) 192 irc_recv_convert(GaimConnection *gc, char *string)
193 { 193 {
194 char *utf8; 194 char *utf8;
195 GError *err = NULL; 195 GError *err = NULL;
196 196
197 utf8 = g_convert(string, strlen(string), "UTF-8", 197 utf8 = g_convert(string, strlen(string), "UTF-8",
198 gc->account->proto_opt[USEROPT_CHARSET], NULL, NULL, &err); 198 gaim_account_get_string(gaim_connection_get_account(gc), "charset", "UTF-8") , NULL, NULL, &err);
199 if (err) { 199 if (err) {
200 gaim_debug(GAIM_DEBUG_ERROR, "irc", 200 gaim_debug(GAIM_DEBUG_ERROR, "irc",
201 "recv conversion error: %s\n", err->message); 201 "recv conversion error: %s\n", err->message);
202 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); 202 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)"));
203 } 203 }
204 204
205 return (utf8); 205 return (utf8);
206 } 206 }
207 207
208 static struct gaim_conversation * 208 static struct gaim_conversation *
209 irc_find_chat(struct gaim_connection *gc, const char *name) 209 irc_find_chat(GaimConnection *gc, const char *name)
210 { 210 {
211 GSList *bcs = gc->buddy_chats; 211 GSList *bcs = gc->buddy_chats;
212 212
213 while (bcs) { 213 while (bcs) {
214 struct gaim_conversation *b = bcs->data; 214 struct gaim_conversation *b = bcs->data;
271 cmd++; 271 cmd++;
272 } 272 }
273 } 273 }
274 274
275 static void 275 static void
276 handle_005(struct gaim_connection *gc, char *word[], char *word_eol[]) 276 handle_005(GaimConnection *gc, char *word[], char *word_eol[])
277 { 277 {
278 int w = 4; 278 int w = 4;
279 struct irc_data *id = gc->proto_data; 279 struct irc_data *id = gc->proto_data;
280 280
281 while (w < PDIWORDS && *word[w]) { 281 while (w < PDIWORDS && *word[w]) {
462 str = g_string_append(str, cur); 462 str = g_string_append(str, cur);
463 return str; 463 return str;
464 } 464 }
465 465
466 static void 466 static void
467 irc_got_im(struct gaim_connection *gc, char *who, char *what, int flags, time_t t) 467 irc_got_im(GaimConnection *gc, char *who, char *what, int flags, time_t t)
468 { 468 {
469 char *utf8 = irc_recv_convert(gc, what); 469 char *utf8 = irc_recv_convert(gc, what);
470 GString *str = decode_html(utf8); 470 GString *str = decode_html(utf8);
471 serv_got_im(gc, who, str->str, flags, t, -1); 471 serv_got_im(gc, who, str->str, flags, t, -1);
472 g_string_free(str, TRUE); 472 g_string_free(str, TRUE);
562 gaim_input_remove(chat->inpa); 562 gaim_input_remove(chat->inpa);
563 chat->inpa = gaim_input_add(source, GAIM_INPUT_READ, dcc_chat_in, chat); 563 chat->inpa = gaim_input_add(source, GAIM_INPUT_READ, dcc_chat_in, chat);
564 } 564 }
565 565
566 static void 566 static void
567 irc_got_chat_in(struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t t) 567 irc_got_chat_in(GaimConnection *gc, int id, char *who, int whisper, char *msg, time_t t)
568 { 568 {
569 char *utf8 = irc_recv_convert(gc, msg); 569 char *utf8 = irc_recv_convert(gc, msg);
570 GString *str = decode_html(utf8); 570 GString *str = decode_html(utf8);
571 serv_got_chat_in(gc, id, who, whisper, str->str, t); 571 serv_got_chat_in(gc, id, who, whisper, str->str, t);
572 g_string_free(str, TRUE); 572 g_string_free(str, TRUE);
573 g_free(utf8); 573 g_free(utf8);
574 } 574 }
575 575
576 static void 576 static void
577 handle_list(struct gaim_connection *gc, char *list) 577 handle_list(GaimConnection *gc, char *list)
578 { 578 {
579 struct irc_data *id = gc->proto_data; 579 struct irc_data *id = gc->proto_data;
580 char *tmp; 580 char *tmp;
581 GaimBlistNode *gnode, *bnode; 581 GaimBlistNode *gnode, *bnode;
582 582
617 } 617 }
618 618
619 static gboolean 619 static gboolean
620 irc_request_buddy_update(gpointer data) 620 irc_request_buddy_update(gpointer data)
621 { 621 {
622 struct gaim_connection *gc = data; 622 GaimConnection *gc = data;
623 struct irc_data *id = gc->proto_data; 623 struct irc_data *id = gc->proto_data;
624 char buf[500]; 624 char buf[500];
625 int n = g_snprintf(buf, sizeof(buf), "ISON"); 625 int n = g_snprintf(buf, sizeof(buf), "ISON");
626 gboolean found = FALSE; 626 gboolean found = FALSE;
627 627
659 659
660 return TRUE; 660 return TRUE;
661 } 661 }
662 662
663 static void 663 static void
664 handle_names(struct gaim_connection *gc, char *chan, char *names) 664 handle_names(GaimConnection *gc, char *chan, char *names)
665 { 665 {
666 struct gaim_conversation *c = irc_find_chat(gc, chan); 666 struct gaim_conversation *c = irc_find_chat(gc, chan);
667 struct gaim_chat *chat; 667 struct gaim_chat *chat;
668 char **buf, **tmp; 668 char **buf, **tmp;
669 669
679 679
680 g_strfreev(buf); 680 g_strfreev(buf);
681 } 681 }
682 682
683 static void 683 static void
684 handle_notopic(struct gaim_connection *gc, char *text) 684 handle_notopic(GaimConnection *gc, char *text)
685 { 685 {
686 struct gaim_conversation *c; 686 struct gaim_conversation *c;
687 687
688 if ((c = irc_find_chat(gc, text))) { 688 if ((c = irc_find_chat(gc, text))) {
689 char buf[IRC_BUF_LEN]; 689 char buf[IRC_BUF_LEN];
693 gaim_chat_set_topic(GAIM_CHAT(c), NULL, buf); 693 gaim_chat_set_topic(GAIM_CHAT(c), NULL, buf);
694 } 694 }
695 } 695 }
696 696
697 static void 697 static void
698 handle_topic(struct gaim_connection *gc, char *text) 698 handle_topic(GaimConnection *gc, char *text)
699 { 699 {
700 struct gaim_conversation *c; 700 struct gaim_conversation *c;
701 char *po = strchr(text, ' '), *buf; 701 char *po = strchr(text, ' '), *buf;
702 702
703 if (!po) 703 if (!po)
715 g_free(po); 715 g_free(po);
716 } 716 }
717 } 717 }
718 718
719 static gboolean 719 static gboolean
720 mode_has_arg(struct gaim_connection *gc, char sign, char mode) 720 mode_has_arg(GaimConnection *gc, char sign, char mode)
721 { 721 {
722 struct irc_data *id = gc->proto_data; 722 struct irc_data *id = gc->proto_data;
723 char *cm = id->chanmodes; 723 char *cm = id->chanmodes;
724 int type = 0; 724 int type = 0;
725 725
746 746
747 return FALSE; 747 return FALSE;
748 } 748 }
749 749
750 static void 750 static void
751 irc_chan_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *argstr, char *who) 751 irc_chan_mode(GaimConnection *gc, char *room, char sign, char mode, char *argstr, char *who)
752 { 752 {
753 struct gaim_conversation *c = irc_find_chat(gc, room); 753 struct gaim_conversation *c = irc_find_chat(gc, room);
754 char buf[IRC_BUF_LEN]; 754 char buf[IRC_BUF_LEN];
755 char *nick = g_strndup(who, strchr(who, '!') - who); 755 char *nick = g_strndup(who, strchr(who, '!') - who);
756 756
761 761
762 gaim_conversation_write(c, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); 762 gaim_conversation_write(c, NULL, buf, -1, WFLAG_SYSTEM, time(NULL));
763 } 763 }
764 764
765 static void 765 static void
766 irc_user_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *nick) 766 irc_user_mode(GaimConnection *gc, char *room, char sign, char mode, char *nick)
767 { 767 {
768 struct gaim_conversation *c = irc_find_chat(gc, room); 768 struct gaim_conversation *c = irc_find_chat(gc, room);
769 GList *r; 769 GList *r;
770 770
771 if (mode != 'o' && mode != 'v' && mode != 'h') 771 if (mode != 'o' && mode != 'v' && mode != 'h')
829 r = r->next; 829 r = r->next;
830 } 830 }
831 } 831 }
832 832
833 static void 833 static void
834 handle_mode(struct gaim_connection *gc, char *word[], char *word_eol[], gboolean n324) 834 handle_mode(GaimConnection *gc, char *word[], char *word_eol[], gboolean n324)
835 { 835 {
836 struct irc_data *id = gc->proto_data; 836 struct irc_data *id = gc->proto_data;
837 int offset = n324 ? 4 : 3; 837 int offset = n324 ? 4 : 3;
838 char *chan = word[offset]; 838 char *chan = word[offset];
839 struct gaim_conversation *c = irc_find_chat(gc, chan); 839 struct gaim_conversation *c = irc_find_chat(gc, chan);
871 modes++; 871 modes++;
872 } 872 }
873 } 873 }
874 874
875 static void 875 static void
876 handle_version(struct gaim_connection *gc, char *word[], char *word_eol[], int num) 876 handle_version(GaimConnection *gc, char *word[], char *word_eol[], int num)
877 { 877 {
878 struct irc_data *id = gc->proto_data; 878 struct irc_data *id = gc->proto_data;
879 GString *str; 879 GString *str;
880 880
881 id->liststr = g_string_new(""); 881 id->liststr = g_string_new("");
889 g_string_free(id->liststr, TRUE); 889 g_string_free(id->liststr, TRUE);
890 id->liststr = NULL; 890 id->liststr = NULL;
891 } 891 }
892 892
893 static void 893 static void
894 handle_who(struct gaim_connection *gc, char *word[], char *word_eol[], int num) 894 handle_who(GaimConnection *gc, char *word[], char *word_eol[], int num)
895 { 895 {
896 struct irc_data *id = gc->proto_data; 896 struct irc_data *id = gc->proto_data;
897 char buf[IRC_BUF_LEN]; 897 char buf[IRC_BUF_LEN];
898 898
899 if (!id->in_whois) { 899 if (!id->in_whois) {
913 /* Handle our whois stuff here. You know what, I have a sore throat. You know 913 /* Handle our whois stuff here. You know what, I have a sore throat. You know
914 * what I think about that? I'm not too pleased with it. Perhaps I should take 914 * what I think about that? I'm not too pleased with it. Perhaps I should take
915 * some medicine, or perhaps I should go to bed? Blah!! */ 915 * some medicine, or perhaps I should go to bed? Blah!! */
916 916
917 static void 917 static void
918 handle_whois(struct gaim_connection *gc, char *word[], char *word_eol[], int num) 918 handle_whois(GaimConnection *gc, char *word[], char *word_eol[], int num)
919 { 919 {
920 struct irc_data *id = gc->proto_data; 920 struct irc_data *id = gc->proto_data;
921 char tmp[1024]; 921 char tmp[1024];
922 922
923 if (!id->in_whois) { 923 if (!id->in_whois) {
979 else 979 else
980 id->liststr = g_string_append(id->liststr, word_eol[5]); 980 id->liststr = g_string_append(id->liststr, word_eol[5]);
981 } 981 }
982 982
983 static void 983 static void
984 handle_roomlist(struct gaim_connection *gc, char *word[], char *word_eol[]) 984 handle_roomlist(GaimConnection *gc, char *word[], char *word_eol[])
985 { 985 {
986 struct irc_data *id = gc->proto_data; 986 struct irc_data *id = gc->proto_data;
987 987
988 if (!id->in_list) { 988 if (!id->in_list) {
989 id->in_list = TRUE; 989 id->in_list = TRUE;
996 id->liststr = g_string_append(id->liststr, word_eol[4]); 996 id->liststr = g_string_append(id->liststr, word_eol[4]);
997 } 997 }
998 998
999 static void 999 static void
1000 irc_change_nick(void *a, const char *b) { 1000 irc_change_nick(void *a, const char *b) {
1001 struct gaim_connection *gc = a; 1001 GaimConnection *gc = a;
1002 struct irc_data *id = gc->proto_data; 1002 struct irc_data *id = gc->proto_data;
1003 char buf[IRC_BUF_LEN]; 1003 char buf[IRC_BUF_LEN];
1004 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", b); 1004 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", b);
1005 irc_write(id->fd, buf, strlen(buf)); 1005 irc_write(id->fd, buf, strlen(buf));
1006 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", b); 1006 gaim_connection_set_display_name(gc, b);
1007 } 1007 }
1008 1008
1009 static void 1009 static void
1010 process_numeric(struct gaim_connection *gc, char *word[], char *word_eol[]) 1010 process_numeric(GaimConnection *gc, char *word[], char *word_eol[])
1011 { 1011 {
1012 const char *displayname = gaim_connection_get_display_name(gc);
1012 struct irc_data *id = gc->proto_data; 1013 struct irc_data *id = gc->proto_data;
1013 char *text = word_eol[3]; 1014 char *text = word_eol[3];
1014 int n = atoi(word[2]); 1015 int n = atoi(word[2]);
1015 char tmp[1024]; 1016 char tmp[1024];
1016 1017
1017 if (!g_ascii_strncasecmp(gc->displayname, text, strlen(gc->displayname))) 1018 if (!g_ascii_strncasecmp(displayname, text, strlen(displayname)))
1018 text += strlen(gc->displayname) + 1; 1019 text += strlen(displayname) + 1;
1019 if (*text == ':') 1020 if (*text == ':')
1020 text++; 1021 text++;
1021 1022
1022 /* RPL_ and ERR_ */ 1023 /* RPL_ and ERR_ */
1023 switch (n) { 1024 switch (n) {
1111 _("IRC Error")); 1112 _("IRC Error"));
1112 break; 1113 break;
1113 case 433: 1114 case 433:
1114 gaim_request_input(gc, NULL, _("That nick is already in use. " 1115 gaim_request_input(gc, NULL, _("That nick is already in use. "
1115 "Please enter a new nick"), 1116 "Please enter a new nick"),
1116 NULL, gc->displayname, FALSE, 1117 NULL, gaim_connection_get_display_name(gc), FALSE,
1117 _("OK"), G_CALLBACK(irc_change_nick), 1118 _("OK"), G_CALLBACK(irc_change_nick),
1118 _("Cancel"), NULL, gc); 1119 _("Cancel"), NULL, gc);
1119 break; 1120 break;
1120 default: 1121 default:
1121 /* Other error messages */ 1122 /* Other error messages */
1134 break; 1135 break;
1135 } 1136 }
1136 } 1137 }
1137 1138
1138 static gboolean 1139 static gboolean
1139 is_channel(struct gaim_connection *gc, const char *name) 1140 is_channel(GaimConnection *gc, const char *name)
1140 { 1141 {
1141 struct irc_data *id = gc->proto_data; 1142 struct irc_data *id = gc->proto_data;
1142 if (strchr(id->chantypes, *name)) 1143 if (strchr(id->chantypes, *name))
1143 return TRUE; 1144 return TRUE;
1144 return FALSE; 1145 return FALSE;
1145 } 1146 }
1146 1147
1147 static void 1148 static void
1148 irc_rem_chat_bud(struct gaim_connection *gc, char *nick, struct gaim_conversation *b, char *reason) 1149 irc_rem_chat_bud(GaimConnection *gc, char *nick, struct gaim_conversation *b, char *reason)
1149 { 1150 {
1150 1151
1151 struct gaim_chat *chat; 1152 struct gaim_chat *chat;
1152 1153
1153 if (b) { 1154 if (b) {
1180 } 1181 }
1181 } 1182 }
1182 } 1183 }
1183 1184
1184 static void 1185 static void
1185 irc_change_name(struct gaim_connection *gc, char *old, char *new) 1186 irc_change_name(GaimConnection *gc, char *old, char *new)
1186 { 1187 {
1187 GSList *bcs = gc->buddy_chats; 1188 GSList *bcs = gc->buddy_chats;
1188 char buf[IRC_BUF_LEN]; 1189 char buf[IRC_BUF_LEN];
1189 1190
1190 while (bcs) { 1191 while (bcs) {
1218 bcs = bcs->next; 1219 bcs = bcs->next;
1219 } 1220 }
1220 } 1221 }
1221 1222
1222 static void 1223 static void
1223 handle_privmsg(struct gaim_connection *gc, char *to, char *nick, char *msg) 1224 handle_privmsg(GaimConnection *gc, char *to, char *nick, char *msg)
1224 { 1225 {
1225 if (is_channel(gc, to)) { 1226 if (is_channel(gc, to)) {
1226 struct gaim_conversation *c = irc_find_chat(gc, to); 1227 struct gaim_conversation *c = irc_find_chat(gc, to);
1227 if (!c) 1228 if (!c)
1228 return; 1229 return;
1262 } 1263 }
1263 g_free(data); 1264 g_free(data);
1264 } 1265 }
1265 1266
1266 static void 1267 static void
1267 irc_convo_closed(struct gaim_connection *gc, char *who) 1268 irc_convo_closed(GaimConnection *gc, char *who)
1268 { 1269 {
1269 struct dcc_chat *dchat = find_dcc_chat(gc, who); 1270 struct dcc_chat *dchat = find_dcc_chat(gc, who);
1270 if (!dchat) 1271 if (!dchat)
1271 return; 1272 return;
1272 1273
1386 1387
1387 return best; 1388 return best;
1388 } 1389 }
1389 1390
1390 static void 1391 static void
1391 handle_ctcp(struct gaim_connection *gc, char *to, char *nick, 1392 handle_ctcp(GaimConnection *gc, char *to, char *nick,
1392 char *msg, char *word[], char *word_eol[]) 1393 char *msg, char *word[], char *word_eol[])
1393 { 1394 {
1394 struct irc_data *id = gc->proto_data; 1395 struct irc_data *id = gc->proto_data;
1395 char buf[IRC_BUF_LEN]; 1396 char buf[IRC_BUF_LEN];
1396 char out[IRC_BUF_LEN]; 1397 char out[IRC_BUF_LEN];
1531 gaim_xfer_request(xfer); 1532 gaim_xfer_request(xfer);
1532 } 1533 }
1533 } 1534 }
1534 1535
1535 static gboolean 1536 static gboolean
1536 irc_parse(struct gaim_connection *gc, char *buf) 1537 irc_parse(GaimConnection *gc, char *buf)
1537 { 1538 {
1538 struct irc_data *idata = gc->proto_data; 1539 struct irc_data *idata = gc->proto_data;
1539 gchar outbuf[IRC_BUF_LEN]; 1540 gchar outbuf[IRC_BUF_LEN];
1540 char *word[PDIWORDS], *word_eol[PDIWORDS]; 1541 char *word[PDIWORDS], *word_eol[PDIWORDS];
1541 char pdibuf[522]; 1542 char pdibuf[522];
1549 buf += 7; 1550 buf += 7;
1550 if (!strncmp(buf, "PING ", 5)) { 1551 if (!strncmp(buf, "PING ", 5)) {
1551 int r = FALSE; 1552 int r = FALSE;
1552 g_snprintf(outbuf, sizeof(outbuf), "PONG %s\r\n", buf + 5); 1553 g_snprintf(outbuf, sizeof(outbuf), "PONG %s\r\n", buf + 5);
1553 if (irc_write(idata->fd, outbuf, strlen(outbuf)) < 0) { 1554 if (irc_write(idata->fd, outbuf, strlen(outbuf)) < 0) {
1554 hide_login_progress(gc, _("Unable to write")); 1555 gaim_connection_error(gc, _("Unable to write"));
1555 signoff(gc);
1556 r = TRUE; 1556 r = TRUE;
1557 } 1557 }
1558 return r; 1558 return r;
1559 } 1559 }
1560 /* XXX doesn't handle ERROR */ 1560 /* XXX doesn't handle ERROR */
1561 return FALSE; 1561 return FALSE;
1562 } 1562 }
1563 1563
1564 if (!idata->online) { 1564 if (!idata->online) {
1565 /* Now lets sign ourselves on */ 1565 /* Now lets sign ourselves on */
1566 account_online(gc); 1566 gaim_connection_set_state(gc, GAIM_CONNECTED);
1567 serv_finish_login(gc); 1567 serv_finish_login(gc);
1568 1568
1569 /* we don't call this now because otherwise some IRC servers might not like us */ 1569 /* we don't call this now because otherwise some IRC servers might not like us */
1570 idata->timer = g_timeout_add(20000, irc_request_buddy_update, gc); 1570 idata->timer = g_timeout_add(20000, irc_request_buddy_update, gc);
1571 idata->online = TRUE; 1571 idata->online = TRUE;
1606 1606
1607 serv_got_chat_invite(gc, word[4] + 1, nick, NULL, components); 1607 serv_got_chat_invite(gc, word[4] + 1, nick, NULL, components);
1608 } else if (!strcmp(cmd, "JOIN")) { 1608 } else if (!strcmp(cmd, "JOIN")) {
1609 irc_parse_join(gc, nick, word, word_eol); 1609 irc_parse_join(gc, nick, word, word_eol);
1610 } else if (!strcmp(cmd, "KICK")) { 1610 } else if (!strcmp(cmd, "KICK")) {
1611 if (!strcmp(gc->displayname, word[4])) { 1611 if (!strcmp(gaim_connection_get_display_name(gc), word[4])) {
1612 struct gaim_conversation *c = irc_find_chat(gc, word[3]); 1612 struct gaim_conversation *c = irc_find_chat(gc, word[3]);
1613 if (!c) 1613 if (!c)
1614 return FALSE; 1614 return FALSE;
1615 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); 1615 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c);
1616 gaim_conversation_set_account(c, NULL); 1616 gaim_conversation_set_account(c, NULL);
1627 } else if (!strcmp(cmd, "KILL")) { /* */ 1627 } else if (!strcmp(cmd, "KILL")) { /* */
1628 } else if (!strcmp(cmd, "MODE")) { 1628 } else if (!strcmp(cmd, "MODE")) {
1629 handle_mode(gc, word, word_eol, FALSE); 1629 handle_mode(gc, word, word_eol, FALSE);
1630 } else if (!strcmp(cmd, "NICK")) { 1630 } else if (!strcmp(cmd, "NICK")) {
1631 char *new = *word_eol[3] == ':' ? word_eol[3] + 1 : word_eol[3]; 1631 char *new = *word_eol[3] == ':' ? word_eol[3] + 1 : word_eol[3];
1632 if (!strcmp(gc->displayname, nick)) 1632 if (!strcmp(gaim_connection_get_display_name(gc), nick))
1633 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", new); 1633 gaim_connection_set_display_name(gc, new);
1634 irc_change_name(gc, nick, new); 1634 irc_change_name(gc, nick, new);
1635 } else if (!strcmp(cmd, "NOTICE")) { 1635 } else if (!strcmp(cmd, "NOTICE")) {
1636 irc_parse_notice(gc, nick, ex, word, word_eol); 1636 irc_parse_notice(gc, nick, ex, word, word_eol);
1637 } else if (!strcmp(cmd, "PART")) { 1637 } else if (!strcmp(cmd, "PART")) {
1638 if (!irc_parse_part(gc, nick, cmd, word, word_eol)) 1638 if (!irc_parse_part(gc, nick, cmd, word, word_eol))
1664 return FALSE; 1664 return FALSE;
1665 } 1665 }
1666 1666
1667 /* CTCP by jonas@birme.se */ 1667 /* CTCP by jonas@birme.se */
1668 static void 1668 static void
1669 irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, 1669 irc_parse_notice(GaimConnection *gc, char *nick, char *ex,
1670 char *word[], char *word_eol[]) 1670 char *word[], char *word_eol[])
1671 { 1671 {
1672 char buf[IRC_BUF_LEN]; 1672 char buf[IRC_BUF_LEN];
1673 1673
1674 if (!g_ascii_strcasecmp(word[4], ":\001CLIENTINFO")) { 1674 if (!g_ascii_strcasecmp(word[4], ":\001CLIENTINFO")) {
1724 irc_got_im(gc, nick, word_eol[4], 0, time(NULL)); 1724 irc_got_im(gc, nick, word_eol[4], 0, time(NULL));
1725 } 1725 }
1726 } 1726 }
1727 1727
1728 static void 1728 static void
1729 irc_parse_join(struct gaim_connection *gc, char *nick, 1729 irc_parse_join(GaimConnection *gc, char *nick,
1730 char *word[], char *word_eol[]) 1730 char *word[], char *word_eol[])
1731 { 1731 {
1732 char *chan = *word[3] == ':' ? word[3] + 1 : word[3]; 1732 char *chan = *word[3] == ':' ? word[3] + 1 : word[3];
1733 static int id = 1; 1733 static int id = 1;
1734 struct gaim_conversation *c; 1734 struct gaim_conversation *c;
1735 char *hostmask, *p; 1735 char *hostmask, *p;
1736 1736
1737 if (!gaim_utf8_strcasecmp(gc->displayname, nick)) { 1737 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), nick)) {
1738 serv_got_joined_chat(gc, id++, chan); 1738 serv_got_joined_chat(gc, id++, chan);
1739 } else { 1739 } else {
1740 c = irc_find_chat(gc, chan); 1740 c = irc_find_chat(gc, chan);
1741 if (c) { 1741 if (c) {
1742 hostmask = g_strdup(word[1]); 1742 hostmask = g_strdup(word[1]);
1754 } 1754 }
1755 } 1755 }
1756 } 1756 }
1757 1757
1758 static void 1758 static void
1759 irc_parse_topic(struct gaim_connection *gc, char *nick, 1759 irc_parse_topic(GaimConnection *gc, char *nick,
1760 char *word[], char *word_eol[]) 1760 char *word[], char *word_eol[])
1761 { 1761 {
1762 struct gaim_conversation *c = irc_find_chat(gc, word[3]); 1762 struct gaim_conversation *c = irc_find_chat(gc, word[3]);
1763 char *topic = irc_recv_convert(gc, *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]); 1763 char *topic = irc_recv_convert(gc, *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]);
1764 char buf[IRC_BUF_LEN]; 1764 char buf[IRC_BUF_LEN];
1772 } 1772 }
1773 g_free(topic); 1773 g_free(topic);
1774 } 1774 }
1775 1775
1776 static gboolean 1776 static gboolean
1777 irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd, 1777 irc_parse_part(GaimConnection *gc, char *nick, char *cmd,
1778 char *word[], char *word_eol[]) 1778 char *word[], char *word_eol[])
1779 { 1779 {
1780 char *chan = cmd + 5; 1780 char *chan = cmd + 5;
1781 struct gaim_conversation *c; 1781 struct gaim_conversation *c;
1782 struct gaim_chat *chat; 1782 struct gaim_chat *chat;
1787 chan++; 1787 chan++;
1788 if (*reason == ':') 1788 if (*reason == ':')
1789 reason++; 1789 reason++;
1790 if (!(c = irc_find_chat(gc, chan))) 1790 if (!(c = irc_find_chat(gc, chan)))
1791 return FALSE; 1791 return FALSE;
1792 if (!strcmp(nick, gc->displayname)) { 1792 if (!strcmp(nick, gaim_connection_get_display_name(gc))) {
1793 serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(c))); 1793 serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(c)));
1794 return FALSE; 1794 return FALSE;
1795 } 1795 }
1796 1796
1797 chat = GAIM_CHAT(c); 1797 chat = GAIM_CHAT(c);
1816 } 1816 }
1817 1817
1818 static void 1818 static void
1819 irc_callback(gpointer data, gint source, GaimInputCondition condition) 1819 irc_callback(gpointer data, gint source, GaimInputCondition condition)
1820 { 1820 {
1821 struct gaim_connection *gc = data; 1821 GaimConnection *gc = data;
1822 struct irc_data *idata = gc->proto_data; 1822 struct irc_data *idata = gc->proto_data;
1823 int i = 0; 1823 int i = 0;
1824 gchar buf[1024]; 1824 gchar buf[1024];
1825 gboolean off; 1825 gboolean off;
1826 1826
1827 i = read(idata->fd, buf, 1024); 1827 i = read(idata->fd, buf, 1024);
1828 if (i <= 0) { 1828 if (i <= 0) {
1829 hide_login_progress_error(gc, "Read error"); 1829 gaim_connection_error(gc, "Read error");
1830 signoff(gc);
1831 return; 1830 return;
1832 } 1831 }
1833 1832
1834 idata->rxqueue = g_realloc(idata->rxqueue, i + idata->rxlen + 1); 1833 idata->rxqueue = g_realloc(idata->rxqueue, i + idata->rxlen + 1);
1835 memcpy(idata->rxqueue + idata->rxlen, buf, i); 1834 memcpy(idata->rxqueue + idata->rxlen, buf, i);
1871 } 1870 }
1872 1871
1873 static void 1872 static void
1874 irc_login_callback(gpointer data, gint source, GaimInputCondition condition) 1873 irc_login_callback(gpointer data, gint source, GaimInputCondition condition)
1875 { 1874 {
1876 struct gaim_connection *gc = data; 1875 GaimConnection *gc = data;
1876 GaimAccount *account = gaim_connection_get_account(gc);
1877 struct irc_data *idata; 1877 struct irc_data *idata;
1878 char hostname[256]; 1878 char hostname[256];
1879 char buf[IRC_BUF_LEN]; 1879 char buf[IRC_BUF_LEN];
1880 char *test; 1880 char *test;
1881 const char *charset = gaim_account_get_string(account, "charset", "UTF-8");
1881 GError *err = NULL; 1882 GError *err = NULL;
1882 1883
1883 if (!g_slist_find(connections, gc)) { 1884 if (!g_slist_find(connections, gc)) {
1884 close(source); 1885 close(source);
1885 return; 1886 return;
1886 } 1887 }
1887 1888
1888 idata = gc->proto_data; 1889 idata = gc->proto_data;
1889 1890
1890 if (source < 0) { 1891 if (source < 0) {
1891 hide_login_progress(gc, "Write error"); 1892 gaim_connection_error(gc, "Write error");
1892 signoff(gc);
1893 return; 1893 return;
1894 } 1894 }
1895 idata->fd = source; 1895 idata->fd = source;
1896 1896
1897 /* Try a quick conversion to see if the specified encoding is OK */ 1897 /* Try a quick conversion to see if the specified encoding is OK */
1898 test = g_convert("test", strlen("test"), gc->account->proto_opt[USEROPT_CHARSET], 1898 test = g_convert("test", strlen("test"), charset,
1899 "UTF-8", NULL, NULL, &err); 1899 "UTF-8", NULL, NULL, &err);
1900 if (err) { 1900 if (err) {
1901 gaim_debug(GAIM_DEBUG_ERROR, "irc", 1901 gaim_debug(GAIM_DEBUG_ERROR, "irc",
1902 "Couldn't initialize %s for IRC charset conversion, using ISO-8859-1\n", 1902 "Couldn't initialize %s for IRC charset conversion, using ISO-8859-1\n",
1903 gc->account->proto_opt[USEROPT_CHARSET]); 1903 charset);
1904 strcpy(gc->account->proto_opt[USEROPT_CHARSET], "ISO-8859-1"); 1904 gaim_account_set_string(account, "charset", "UTF-8");
1905 } 1905 }
1906 1906
1907 g_free(test); 1907 g_free(test);
1908 1908
1909 gethostname(hostname, sizeof(hostname) - 1); 1909 gethostname(hostname, sizeof(hostname) - 1);
1910 hostname[sizeof(hostname) - 1] = 0; 1910 hostname[sizeof(hostname) - 1] = 0;
1911 if (!*hostname) 1911 if (!*hostname)
1912 g_snprintf(hostname, sizeof(hostname), "localhost"); 1912 g_snprintf(hostname, sizeof(hostname), "localhost");
1913 1913
1914 if (*gc->account->password) { 1914 if (*gc->account->password) {
1915 g_snprintf(buf, sizeof(buf), "PASS %s\r\n", gc->account->password); 1915 g_snprintf(buf, sizeof(buf), "PASS %s\r\n", gaim_account_get_password(account));
1916 1916
1917 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { 1917 if (irc_write(idata->fd, buf, strlen(buf)) < 0) {
1918 hide_login_progress(gc, "Write error"); 1918 gaim_connection_error(gc, "Write error");
1919 signoff(gc);
1920 return; 1919 return;
1921 } 1920 }
1922 }
1923 1921
1924 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", 1922 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n",
1925 g_get_user_name(), hostname, 1923 g_get_user_name(), hostname,
1926 idata->server, 1924 idata->server,
1927 *gc->account->alias ? gc->account->alias : "gaim"); 1925 *gc->account->alias ? gc->account->alias : "gaim");
1928 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { 1926 if (irc_write(idata->fd, buf, strlen(buf)) < 0) {
1929 hide_login_progress(gc, "Write error"); 1927 gaim_connection_error(gc, "Write error");
1930 signoff(gc);
1931 return; 1928 return;
1932 } 1929 }
1933 1930
1934 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->displayname); 1931 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gaim_connection_get_display_name(gc));
1935 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { 1932 if (irc_write(idata->fd, buf, strlen(buf)) < 0) {
1936 hide_login_progress(gc, "Write error"); 1933 gaim_connection_error(gc, "Write error");
1937 signoff(gc);
1938 return; 1934 return;
1939 } 1935 }
1940 1936
1941 gc->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); 1937 gc->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc);
1942 } 1938 }
1943 1939
1944 static void 1940 static void
1945 irc_login(struct gaim_account *account) 1941 irc_login(GaimAccount *account)
1946 { 1942 {
1943 const char *username = gaim_account_get_username(account);
1947 char buf[IRC_BUF_LEN]; 1944 char buf[IRC_BUF_LEN];
1948 int rc; 1945 int rc;
1949 1946
1950 struct gaim_connection *gc; 1947 GaimConnection *gc;
1951 struct irc_data *idata; 1948 struct irc_data *idata;
1952 char **parts; 1949 char **parts;
1953 if(!strrchr(account->username, '@')) { 1950
1954 char *username = g_strdup(account->username); 1951 if(!strrchr(username, '@')) {
1955 g_snprintf(account->username, sizeof(account->username), "%s@%s", 1952 char *tmp = g_strdup_printf("%s@%s", username,
1956 username, *account->proto_opt[USEROPT_SERV] ? 1953 gaim_account_get_string(account, "server", DEFAULT_SERVER));
1957 account->proto_opt[USEROPT_SERV] : DEFAULT_SERVER); 1954 gaim_account_set_username(account, tmp);
1958 g_free(username); 1955 /* XXX: delete function required */
1959 strcpy(account->proto_opt[USEROPT_SERV], ""); 1956 gaim_account_set_string(account, "server", NULL);
1960 save_prefs(); 1957 g_free(tmp);
1961 } 1958 }
1962 1959
1963 gc = new_gaim_conn(account); 1960 gc = gaim_account_get_connection(account);
1964 idata = gc->proto_data = g_new0(struct irc_data, 1); 1961 idata = gc->proto_data = g_new0(struct irc_data, 1);
1965 1962
1966 parts = g_strsplit(gc->username, "@", 2); 1963 parts = g_strsplit(username, "@", 2);
1967 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", parts[0]); 1964 gaim_connection_set_display_name(gc, parts[0]);
1968 idata->server = g_strdup(parts[1]); 1965 idata->server = g_strdup(parts[1]);
1969 g_strfreev(parts); 1966 g_strfreev(parts);
1970 1967
1971 g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); 1968 g_snprintf(buf, sizeof(buf), _("Signon: %s"), username);
1972 set_login_progress(gc, 2, buf); 1969 gaim_connection_update_progress(gc, buf, 1, 2);
1973 1970
1974 idata->chantypes = g_strdup("#&!+"); 1971 idata->chantypes = g_strdup("#&!+");
1975 idata->chanmodes = g_strdup("beI,k,lnt"); 1972 idata->chanmodes = g_strdup("beI,k,lnt");
1976 idata->nickmodes = g_strdup("ohv"); 1973 idata->nickmodes = g_strdup("ohv");
1977 idata->str = g_string_new(""); 1974 idata->str = g_string_new("");
1978 idata->fd = -1; 1975 idata->fd = -1;
1979 1976
1980 rc = proxy_connect(account, idata->server, 1977 rc = proxy_connect(account, idata->server,
1981 account->proto_opt[USEROPT_PORT][0] ? 1978 gaim_account_get_int(account, "port", 6667),
1982 atoi(account->proto_opt[USEROPT_PORT]) : 6667, 1979 irc_login_callback, gc);
1983 irc_login_callback, gc); 1980
1984 if (!account->gc || (rc != 0)) { 1981 if (!account->gc || (rc != 0)) {
1985 hide_login_progress(gc, "Unable to create socket"); 1982 gaim_connection_error(gc, "Unable to create socket");
1986 signoff(gc);
1987 return; 1983 return;
1988 } 1984 }
1989 } 1985 }
1990 1986
1991 static void 1987 static void
1992 irc_close(struct gaim_connection *gc) 1988 irc_close(GaimConnection *gc)
1993 { 1989 {
1994 struct irc_data *idata = (struct irc_data *)gc->proto_data; 1990 struct irc_data *idata = (struct irc_data *)gc->proto_data;
1995 1991
1996 gchar buf[IRC_BUF_LEN]; 1992 gchar buf[IRC_BUF_LEN];
1997 1993
2040 close(idata->fd); 2036 close(idata->fd);
2041 g_free(gc->proto_data); 2037 g_free(gc->proto_data);
2042 } 2038 }
2043 2039
2044 static void 2040 static void
2045 set_mode_3(struct gaim_connection *gc, const char *who, int sign, int mode, 2041 set_mode_3(GaimConnection *gc, const char *who, int sign, int mode,
2046 int start, int end, char *word[]) 2042 int start, int end, char *word[])
2047 { 2043 {
2048 struct irc_data *id = gc->proto_data; 2044 struct irc_data *id = gc->proto_data;
2049 char buf[IRC_BUF_LEN]; 2045 char buf[IRC_BUF_LEN];
2050 int left; 2046 int left;
2077 return; 2073 return;
2078 } 2074 }
2079 } 2075 }
2080 2076
2081 static void 2077 static void
2082 set_mode_6(struct gaim_connection *gc, const char *who, int sign, int mode, 2078 set_mode_6(GaimConnection *gc, const char *who, int sign, int mode,
2083 int start, int end, char *word[]) 2079 int start, int end, char *word[])
2084 { 2080 {
2085 struct irc_data *id = gc->proto_data; 2081 struct irc_data *id = gc->proto_data;
2086 char buf[IRC_BUF_LEN]; 2082 char buf[IRC_BUF_LEN];
2087 int left; 2083 int left;
2134 return; 2130 return;
2135 } 2131 }
2136 } 2132 }
2137 2133
2138 static void 2134 static void
2139 set_mode(struct gaim_connection *gc, const char *who, int sign, int mode, char *word[]) 2135 set_mode(GaimConnection *gc, const char *who, int sign, int mode, char *word[])
2140 { 2136 {
2141 struct irc_data *id = gc->proto_data; 2137 struct irc_data *id = gc->proto_data;
2142 int i = 2; 2138 int i = 2;
2143 2139
2144 while (1) { 2140 while (1) {
2154 i++; 2150 i++;
2155 } 2151 }
2156 } 2152 }
2157 2153
2158 static void 2154 static void
2159 set_chan_mode(struct gaim_connection *gc, const char *chan, const char *mode_str) 2155 set_chan_mode(GaimConnection *gc, const char *chan, const char *mode_str)
2160 { 2156 {
2161 struct irc_data *id = gc->proto_data; 2157 struct irc_data *id = gc->proto_data;
2162 char buf[IRC_BUF_LEN]; 2158 char buf[IRC_BUF_LEN];
2163 2159
2164 if ((mode_str[0] == '-') || (mode_str[0] == '+')) { 2160 if ((mode_str[0] == '-') || (mode_str[0] == '+')) {
2166 irc_write(id->fd, buf, strlen(buf)); 2162 irc_write(id->fd, buf, strlen(buf));
2167 } 2163 }
2168 } 2164 }
2169 2165
2170 static int 2166 static int
2171 handle_command(struct gaim_connection *gc, const char *who, const char *in_what) 2167 handle_command(GaimConnection *gc, const char *who, const char *in_what)
2172 { 2168 {
2173 char buf[IRC_BUF_LEN]; 2169 char buf[IRC_BUF_LEN];
2174 char pdibuf[IRC_BUF_LEN]; 2170 char pdibuf[IRC_BUF_LEN];
2175 char *word[PDIWORDS], *word_eol[PDIWORDS]; 2171 char *word[PDIWORDS], *word_eol[PDIWORDS];
2176 char *tmp = g_strdup(in_what); 2172 char *tmp = g_strdup(in_what);
2440 g_free(what); 2436 g_free(what);
2441 return 0; 2437 return 0;
2442 } 2438 }
2443 2439
2444 static int 2440 static int
2445 send_msg(struct gaim_connection *gc, const char *who, const char *what) 2441 send_msg(GaimConnection *gc, const char *who, const char *what)
2446 { 2442 {
2447 char *cr = strchr(what, '\n'); 2443 char *cr = strchr(what, '\n');
2448 if (cr) { 2444 if (cr) {
2449 int ret = 0; 2445 int ret = 0;
2450 while (TRUE) { 2446 while (TRUE) {
2463 } else 2459 } else
2464 return handle_command(gc, who, what); 2460 return handle_command(gc, who, what);
2465 } 2461 }
2466 2462
2467 static void 2463 static void
2468 irc_chat_invite(struct gaim_connection *gc, int idn, const char *message, const char *name) { 2464 irc_chat_invite(GaimConnection *gc, int idn, const char *message, const char *name) {
2469 char buf[IRC_BUF_LEN]; 2465 char buf[IRC_BUF_LEN];
2470 struct irc_data *id = gc->proto_data; 2466 struct irc_data *id = gc->proto_data;
2471 struct gaim_conversation *c = gaim_find_chat(gc, idn); 2467 struct gaim_conversation *c = gaim_find_chat(gc, idn);
2472 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); 2468 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name);
2473 irc_write(id->fd, buf, strlen(buf)); 2469 irc_write(id->fd, buf, strlen(buf));
2474 } 2470 }
2475 2471
2476 static int 2472 static int
2477 irc_send_im(struct gaim_connection *gc, const char *who, const char *what, int len, int flags) 2473 irc_send_im(GaimConnection *gc, const char *who, const char *what, int len, int flags)
2478 { 2474 {
2479 if (*who == '@' || *who == '%' || *who == '+') 2475 if (*who == '@' || *who == '%' || *who == '+')
2480 return send_msg(gc, who + 1, what); 2476 return send_msg(gc, who + 1, what);
2481 return send_msg(gc, who, what); 2477 return send_msg(gc, who, what);
2482 } 2478 }
2483 2479
2484 /* IRC doesn't have a buddy list, but we can still figure out who's online with ISON */ 2480 /* IRC doesn't have a buddy list, but we can still figure out who's online with ISON */
2485 static void 2481 static void
2486 irc_add_buddy(struct gaim_connection *gc, const char *who) {} 2482 irc_add_buddy(GaimConnection *gc, const char *who) {}
2487 static void 2483 static void
2488 irc_remove_buddy(struct gaim_connection *gc, char *who, char *group) {} 2484 irc_remove_buddy(GaimConnection *gc, char *who, char *group) {}
2489 2485
2490 static GList * 2486 static GList *
2491 irc_chat_info(struct gaim_connection *gc) 2487 irc_chat_info(GaimConnection *gc)
2492 { 2488 {
2493 GList *m = NULL; 2489 GList *m = NULL;
2494 struct proto_chat_entry *pce; 2490 struct proto_chat_entry *pce;
2495 2491
2496 pce = g_new0(struct proto_chat_entry, 1); 2492 pce = g_new0(struct proto_chat_entry, 1);
2505 2501
2506 return m; 2502 return m;
2507 } 2503 }
2508 2504
2509 static void 2505 static void
2510 irc_join_chat(struct gaim_connection *gc, GHashTable *data) 2506 irc_join_chat(GaimConnection *gc, GHashTable *data)
2511 { 2507 {
2512 struct irc_data *id = gc->proto_data; 2508 struct irc_data *id = gc->proto_data;
2513 char buf[IRC_BUF_LEN]; 2509 char buf[IRC_BUF_LEN];
2514 char *name, *pass; 2510 char *name, *pass;
2515 2511
2524 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", name); 2520 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", name);
2525 irc_write(id->fd, buf, strlen(buf)); 2521 irc_write(id->fd, buf, strlen(buf));
2526 } 2522 }
2527 2523
2528 static void 2524 static void
2529 irc_chat_leave(struct gaim_connection *gc, int id) 2525 irc_chat_leave(GaimConnection *gc, int id)
2530 { 2526 {
2531 struct irc_data *idata = gc->proto_data; 2527 struct irc_data *idata = gc->proto_data;
2532 struct gaim_conversation *c = gaim_find_chat(gc, id); 2528 struct gaim_conversation *c = gaim_find_chat(gc, id);
2533 char buf[IRC_BUF_LEN]; 2529 char buf[IRC_BUF_LEN];
2534 2530
2537 g_snprintf(buf, sizeof(buf), "PART %s\r\n", c->name); 2533 g_snprintf(buf, sizeof(buf), "PART %s\r\n", c->name);
2538 irc_write(idata->fd, buf, strlen(buf)); 2534 irc_write(idata->fd, buf, strlen(buf));
2539 } 2535 }
2540 2536
2541 static int 2537 static int
2542 irc_chat_send(struct gaim_connection *gc, int id, char *what) 2538 irc_chat_send(GaimConnection *gc, int id, char *what)
2543 { 2539 {
2544 struct gaim_conversation *c = gaim_find_chat(gc, id); 2540 struct gaim_conversation *c = gaim_find_chat(gc, id);
2545 if (!c) 2541 if (!c)
2546 return -EINVAL; 2542 return -EINVAL;
2547 if (send_msg(gc, c->name, what) > 0) 2543 if (send_msg(gc, c->name, what) > 0)
2548 serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), 2544 serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)),
2549 gc->displayname, 0, what, time(NULL)); 2545 gaim_connection_get_display_name(gc), 0, what, time(NULL));
2550 return 0; 2546 return 0;
2551 } 2547 }
2552 2548
2553 static GList * 2549 static GList *
2554 irc_away_states(struct gaim_connection *gc) 2550 irc_away_states(GaimConnection *gc)
2555 { 2551 {
2556 return g_list_append(NULL, GAIM_AWAY_CUSTOM); 2552 return g_list_append(NULL, GAIM_AWAY_CUSTOM);
2557 } 2553 }
2558 2554
2559 static void 2555 static void
2560 irc_set_away(struct gaim_connection *gc, char *state, char *msg) 2556 irc_set_away(GaimConnection *gc, char *state, char *msg)
2561 { 2557 {
2562 struct irc_data *idata = gc->proto_data; 2558 struct irc_data *idata = gc->proto_data;
2563 char buf[IRC_BUF_LEN]; 2559 char buf[IRC_BUF_LEN];
2564 2560
2565 if (gc->away) { 2561 if (gc->away) {
2575 2571
2576 irc_write(idata->fd, buf, strlen(buf)); 2572 irc_write(idata->fd, buf, strlen(buf));
2577 } 2573 }
2578 2574
2579 static const char * 2575 static const char *
2580 irc_list_icon(struct gaim_account *a, struct buddy *b) 2576 irc_list_icon(GaimAccount *a, struct buddy *b)
2581 { 2577 {
2582 return "irc"; 2578 return "irc";
2583 } 2579 }
2584 2580
2585 static void irc_list_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne) 2581 static void irc_list_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne)
2643 "Chat with %s established\n", chat->nick); 2639 "Chat with %s established\n", chat->nick);
2644 dcc_chat_list = g_slist_append (dcc_chat_list, chat); 2640 dcc_chat_list = g_slist_append (dcc_chat_list, chat);
2645 } 2641 }
2646 #if 0 2642 #if 0
2647 static void 2643 static void
2648 irc_ask_send_file(struct gaim_connection *gc, char *destsn) { 2644 irc_ask_send_file(GaimConnection *gc, char *destsn) {
2649 struct irc_data *id = (struct irc_data *)gc->proto_data; 2645 struct irc_data *id = (struct irc_data *)gc->proto_data;
2650 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); 2646 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1);
2651 char *localip = (char *)malloc(12); 2647 char *localip = (char *)malloc(12);
2652 2648
2653 if (getlocalip(localip) == -1) { 2649 if (getlocalip(localip) == -1) {
2663 2659
2664 ift->xfer = transfer_out_add(gc, ift->sn); 2660 ift->xfer = transfer_out_add(gc, ift->sn);
2665 } 2661 }
2666 2662
2667 static struct 2663 static struct
2668 irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, 2664 irc_file_transfer *find_ift_by_xfer(GaimConnection *gc,
2669 struct file_transfer *xfer) { 2665 struct file_transfer *xfer) {
2670 2666
2671 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers; 2667 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers;
2672 struct irc_file_transfer *f = NULL; 2668 struct irc_file_transfer *f = NULL;
2673 2669
2681 2677
2682 return f; 2678 return f;
2683 } 2679 }
2684 2680
2685 static void 2681 static void
2686 irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) { 2682 irc_file_transfer_data_chunk(GaimConnection *gc, struct file_transfer *xfer, const char *data, int len) {
2687 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2683 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2688 guint32 pos; 2684 guint32 pos;
2689 2685
2690 ift->cur += len; 2686 ift->cur += len;
2691 pos = htonl(ift->cur); 2687 pos = htonl(ift->cur);
2694 // FIXME: You should check to verify that they received the data when 2690 // FIXME: You should check to verify that they received the data when
2695 // you are sending a file ... 2691 // you are sending a file ...
2696 } 2692 }
2697 2693
2698 static void 2694 static void
2699 irc_file_transfer_cancel (struct gaim_connection *gc, struct file_transfer *xfer) { 2695 irc_file_transfer_cancel (GaimConnection *gc, struct file_transfer *xfer) {
2700 struct irc_data *id = (struct irc_data *)gc->proto_data; 2696 struct irc_data *id = (struct irc_data *)gc->proto_data;
2701 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2697 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2702 2698
2703 printf("Our shit got canceled, yo!\n"); 2699 printf("Our shit got canceled, yo!\n");
2704 2700
2715 2711
2716 g_free(ift); 2712 g_free(ift);
2717 } 2713 }
2718 2714
2719 static void 2715 static void
2720 irc_file_transfer_done(struct gaim_connection *gc, struct file_transfer *xfer) { 2716 irc_file_transfer_done(GaimConnection *gc, struct file_transfer *xfer) {
2721 struct irc_data *id = (struct irc_data *)gc->proto_data; 2717 struct irc_data *id = (struct irc_data *)gc->proto_data;
2722 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2718 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2723 2719
2724 2720
2725 printf("Our shit be done, yo.\n"); 2721 printf("Our shit be done, yo.\n");
2737 2733
2738 g_free(ift); 2734 g_free(ift);
2739 } 2735 }
2740 2736
2741 static void 2737 static void
2742 irc_file_transfer_out (struct gaim_connection *gc, struct file_transfer *xfer, const char *name, int totfiles, int totsize) { 2738 irc_file_transfer_out (GaimConnection *gc, struct file_transfer *xfer, const char *name, int totfiles, int totsize) {
2743 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2739 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2744 struct sockaddr_in addr; 2740 struct sockaddr_in addr;
2745 char buf[IRC_BUF_LEN]; 2741 char buf[IRC_BUF_LEN];
2746 int len; 2742 int len;
2747 2743
2765 printf("Trying: %s\n", buf); 2761 printf("Trying: %s\n", buf);
2766 irc_send_im (gc, ift->sn, buf, -1, 0); 2762 irc_send_im (gc, ift->sn, buf, -1, 0);
2767 } 2763 }
2768 2764
2769 static void 2765 static void
2770 irc_file_transfer_in(struct gaim_connection *gc, 2766 irc_file_transfer_in(GaimConnection *gc,
2771 struct file_transfer *xfer, int offset) { 2767 struct file_transfer *xfer, int offset) {
2772 2768
2773 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2769 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2774 2770
2775 ift->xfer = xfer; 2771 ift->xfer = xfer;
2776 proxy_connect(gc->account, ift->ip, ift->port, dcc_recv_callback, ift); 2772 proxy_connect(gc->account, ift->ip, ift->port, dcc_recv_callback, ift);
2777 } 2773 }
2778 #endif 2774 #endif
2779 2775
2780 static void 2776 static void
2781 irc_ctcp_clientinfo(struct gaim_connection *gc, const char *who) 2777 irc_ctcp_clientinfo(GaimConnection *gc, const char *who)
2782 { 2778 {
2783 char buf[IRC_BUF_LEN]; 2779 char buf[IRC_BUF_LEN];
2784 2780
2785 snprintf (buf, sizeof buf, "\001CLIENTINFO\001"); 2781 snprintf (buf, sizeof buf, "\001CLIENTINFO\001");
2786 irc_send_privmsg(gc, who, buf, FALSE); 2782 irc_send_privmsg(gc, who, buf, FALSE);
2787 } 2783 }
2788 2784
2789 static void 2785 static void
2790 irc_ctcp_userinfo(struct gaim_connection *gc, const char *who) 2786 irc_ctcp_userinfo(GaimConnection *gc, const char *who)
2791 { 2787 {
2792 char buf[IRC_BUF_LEN]; 2788 char buf[IRC_BUF_LEN];
2793 2789
2794 snprintf (buf, sizeof buf, "\001USERINFO\001"); 2790 snprintf (buf, sizeof buf, "\001USERINFO\001");
2795 irc_send_privmsg(gc, who, buf, FALSE); 2791 irc_send_privmsg(gc, who, buf, FALSE);
2796 } 2792 }
2797 2793
2798 static void 2794 static void
2799 irc_ctcp_version(struct gaim_connection *gc, const char *who) 2795 irc_ctcp_version(GaimConnection *gc, const char *who)
2800 { 2796 {
2801 char buf[IRC_BUF_LEN]; 2797 char buf[IRC_BUF_LEN];
2802 2798
2803 snprintf (buf, sizeof buf, "\001VERSION\001"); 2799 snprintf (buf, sizeof buf, "\001VERSION\001");
2804 irc_send_privmsg(gc, who, buf, FALSE); 2800 irc_send_privmsg(gc, who, buf, FALSE);
2805 } 2801 }
2806 2802
2807 static void 2803 static void
2808 irc_ctcp_ping(struct gaim_connection *gc, const char *who) 2804 irc_ctcp_ping(GaimConnection *gc, const char *who)
2809 { 2805 {
2810 char buf[IRC_BUF_LEN]; 2806 char buf[IRC_BUF_LEN];
2811 struct timeval now; 2807 struct timeval now;
2812 2808
2813 gettimeofday(&now, NULL); 2809 gettimeofday(&now, NULL);
2815 now.tv_usec/1000); 2811 now.tv_usec/1000);
2816 irc_send_privmsg(gc, who, buf, FALSE); 2812 irc_send_privmsg(gc, who, buf, FALSE);
2817 } 2813 }
2818 2814
2819 static void 2815 static void
2820 irc_send_notice(struct gaim_connection *gc, char *who, char *what) 2816 irc_send_notice(GaimConnection *gc, char *who, char *what)
2821 { 2817 {
2822 char buf[IRC_BUF_LEN], *intl; 2818 char buf[IRC_BUF_LEN], *intl;
2823 struct irc_data *id = gc->proto_data; 2819 struct irc_data *id = gc->proto_data;
2824 int len; 2820 int len;
2825 2821
2844 * to NINETY-THREE chars on dancer, which seems to be a pretty liberal 2840 * to NINETY-THREE chars on dancer, which seems to be a pretty liberal
2845 * ircd. My rough calculation for now is ":<nick>!~<user>@<host> ", 2841 * ircd. My rough calculation for now is ":<nick>!~<user>@<host> ",
2846 * where <host> is a max of an (uncalculated) 63 chars. Thanks to 2842 * where <host> is a max of an (uncalculated) 63 chars. Thanks to
2847 * trelane and #freenode for giving a hand here. */ 2843 * trelane and #freenode for giving a hand here. */
2848 static void 2844 static void
2849 irc_send_privmsg(struct gaim_connection *gc, const char *who, const char *what, gboolean fragment) 2845 irc_send_privmsg(GaimConnection *gc, const char *who, const char *what, gboolean fragment)
2850 { 2846 {
2851 char buf[IRC_BUF_LEN], *intl; 2847 char buf[IRC_BUF_LEN], *intl;
2852 struct irc_data *id = gc->proto_data; 2848 struct irc_data *id = gc->proto_data;
2853 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ 2849 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */
2854 int nicklen = (gc->account->alias && strlen(gc->account->alias)) ? strlen(gc->account->alias) : 4; 2850 int nicklen = (gc->account->alias && strlen(gc->account->alias)) ? strlen(gc->account->alias) : 4;
2866 what += len; 2862 what += len;
2867 } while (fragment && strlen(what)); 2863 } while (fragment && strlen(what));
2868 } 2864 }
2869 2865
2870 static void 2866 static void
2871 irc_start_chat(struct gaim_connection *gc, const char *who) { 2867 irc_start_chat(GaimConnection *gc, const char *who) {
2872 struct dcc_chat *chat; 2868 struct dcc_chat *chat;
2873 int len; 2869 int len;
2874 struct sockaddr_in addr; 2870 struct sockaddr_in addr;
2875 char buf[IRC_BUF_LEN]; 2871 char buf[IRC_BUF_LEN];
2876 2872
2899 chat->ip_address, chat->port); 2895 chat->ip_address, chat->port);
2900 irc_send_im (gc, who, buf, -1, 0); 2896 irc_send_im (gc, who, buf, -1, 0);
2901 } 2897 }
2902 2898
2903 static void 2899 static void
2904 irc_get_info(struct gaim_connection *gc, const char *who) 2900 irc_get_info(GaimConnection *gc, const char *who)
2905 { 2901 {
2906 struct irc_data *idata = gc->proto_data; 2902 struct irc_data *idata = gc->proto_data;
2907 char buf[IRC_BUF_LEN]; 2903 char buf[IRC_BUF_LEN];
2908 2904
2909 if (*who == '@') 2905 if (*who == '@')
2916 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", who); 2912 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", who);
2917 irc_write(idata->fd, buf, strlen(buf)); 2913 irc_write(idata->fd, buf, strlen(buf));
2918 } 2914 }
2919 2915
2920 static GList * 2916 static GList *
2921 irc_buddy_menu(struct gaim_connection *gc, const char *who) 2917 irc_buddy_menu(GaimConnection *gc, const char *who)
2922 { 2918 {
2923 GList *m = NULL; 2919 GList *m = NULL;
2924 struct proto_buddy_menu *pbm; 2920 struct proto_buddy_menu *pbm;
2925 2921
2926 pbm = g_new0(struct proto_buddy_menu, 1); 2922 pbm = g_new0(struct proto_buddy_menu, 1);