comparison libpurple/protocols/irc/parse.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 8c81db398f56
children 6447865b2d08
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file parse.c 2 * @file parse.c
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> 6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
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
42 static char *irc_mirc_colors[16] = { 42 static char *irc_mirc_colors[16] = {
43 "white", "black", "blue", "dark green", "red", "brown", "purple", 43 "white", "black", "blue", "dark green", "red", "brown", "purple",
44 "orange", "yellow", "green", "teal", "cyan", "light blue", 44 "orange", "yellow", "green", "teal", "cyan", "light blue",
45 "pink", "grey", "light grey" }; 45 "pink", "grey", "light grey" };
46 46
47 extern GaimPlugin *_irc_plugin; 47 extern PurplePlugin *_irc_plugin;
48 48
49 /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/ 49 /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/
50 static struct _irc_msg { 50 static struct _irc_msg {
51 char *name; 51 char *name;
52 char *format; 52 char *format;
149 { "wallops", ":", irc_cmd_wallops, N_("wallops &lt;message&gt;: If you don't know what this is, you probably can't use it.") }, 149 { "wallops", ":", irc_cmd_wallops, N_("wallops &lt;message&gt;: If you don't know what this is, you probably can't use it.") },
150 { "whois", "tt", irc_cmd_whois, N_("whois [server] &lt;nick&gt;: Get information on a user.") }, 150 { "whois", "tt", irc_cmd_whois, N_("whois [server] &lt;nick&gt;: Get information on a user.") },
151 { NULL, NULL, NULL, NULL } 151 { NULL, NULL, NULL, NULL }
152 }; 152 };
153 153
154 static GaimCmdRet irc_parse_gaim_cmd(GaimConversation *conv, const gchar *cmd, 154 static PurpleCmdRet irc_parse_purple_cmd(PurpleConversation *conv, const gchar *cmd,
155 gchar **args, gchar **error, void *data) 155 gchar **args, gchar **error, void *data)
156 { 156 {
157 GaimConnection *gc; 157 PurpleConnection *gc;
158 struct irc_conn *irc; 158 struct irc_conn *irc;
159 struct _irc_user_cmd *cmdent; 159 struct _irc_user_cmd *cmdent;
160 160
161 gc = gaim_conversation_get_gc(conv); 161 gc = purple_conversation_get_gc(conv);
162 if (!gc) 162 if (!gc)
163 return GAIM_CMD_RET_FAILED; 163 return PURPLE_CMD_RET_FAILED;
164 164
165 irc = gc->proto_data; 165 irc = gc->proto_data;
166 166
167 if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) 167 if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL)
168 return GAIM_CMD_RET_FAILED; 168 return PURPLE_CMD_RET_FAILED;
169 169
170 (cmdent->cb)(irc, cmd, gaim_conversation_get_name(conv), (const char **)args); 170 (cmdent->cb)(irc, cmd, purple_conversation_get_name(conv), (const char **)args);
171 171
172 return GAIM_CMD_RET_OK; 172 return PURPLE_CMD_RET_OK;
173 } 173 }
174 174
175 static void irc_register_command(struct _irc_user_cmd *c) 175 static void irc_register_command(struct _irc_user_cmd *c)
176 { 176 {
177 GaimCmdFlag f; 177 PurpleCmdFlag f;
178 char args[10]; 178 char args[10];
179 char *format; 179 char *format;
180 size_t i; 180 size_t i;
181 181
182 f = GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY 182 f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY
183 | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS; 183 | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS;
184 184
185 format = c->format; 185 format = c->format;
186 186
187 for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++) 187 for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++)
188 switch (*format) { 188 switch (*format) {
198 break; 198 break;
199 } 199 }
200 200
201 args[i] = '\0'; 201 args[i] = '\0';
202 202
203 gaim_cmd_register(c->name, args, GAIM_CMD_P_PRPL, f, "prpl-irc", 203 purple_cmd_register(c->name, args, PURPLE_CMD_P_PRPL, f, "prpl-irc",
204 irc_parse_gaim_cmd, _(c->help), NULL); 204 irc_parse_purple_cmd, _(c->help), NULL);
205 } 205 }
206 206
207 void irc_register_commands(void) 207 void irc_register_commands(void)
208 { 208 {
209 struct _irc_user_cmd *c; 209 struct _irc_user_cmd *c;
217 char *utf8; 217 char *utf8;
218 GError *err = NULL; 218 GError *err = NULL;
219 gchar **encodings; 219 gchar **encodings;
220 const gchar *enclist; 220 const gchar *enclist;
221 221
222 enclist = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); 222 enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
223 encodings = g_strsplit(enclist, ",", 2); 223 encodings = g_strsplit(enclist, ",", 2);
224 224
225 if (encodings[0] == NULL || !strcasecmp("UTF-8", encodings[0])) { 225 if (encodings[0] == NULL || !strcasecmp("UTF-8", encodings[0])) {
226 g_strfreev(encodings); 226 g_strfreev(encodings);
227 return g_strdup(string); 227 return g_strdup(string);
228 } 228 }
229 229
230 utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err); 230 utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err);
231 if (err) { 231 if (err) {
232 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); 232 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message);
233 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]); 233 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]);
234 utf8 = g_strdup(string); 234 utf8 = g_strdup(string);
235 g_error_free(err); 235 g_error_free(err);
236 } 236 }
237 g_strfreev(encodings); 237 g_strfreev(encodings);
238 238
244 char *utf8 = NULL; 244 char *utf8 = NULL;
245 const gchar *charset, *enclist; 245 const gchar *charset, *enclist;
246 gchar **encodings; 246 gchar **encodings;
247 int i; 247 int i;
248 248
249 enclist = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); 249 enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
250 encodings = g_strsplit(enclist, ",", -1); 250 encodings = g_strsplit(enclist, ",", -1);
251 251
252 if (encodings[0] == NULL) { 252 if (encodings[0] == NULL) {
253 g_strfreev(encodings); 253 g_strfreev(encodings);
254 return gaim_utf8_salvage(string); 254 return purple_utf8_salvage(string);
255 } 255 }
256 256
257 for (i = 0; encodings[i] != NULL; i++) { 257 for (i = 0; encodings[i] != NULL; i++) {
258 charset = encodings[i]; 258 charset = encodings[i];
259 while (*charset == ' ') 259 while (*charset == ' ')
271 return utf8; 271 return utf8;
272 } 272 }
273 } 273 }
274 g_strfreev(encodings); 274 g_strfreev(encodings);
275 275
276 return gaim_utf8_salvage(string); 276 return purple_utf8_salvage(string);
277 } 277 }
278 278
279 /* XXX tag closings are not necessarily correctly nested here! If we 279 /* XXX tag closings are not necessarily correctly nested here! If we
280 * get a ^O or reach the end of the string and there are open 280 * get a ^O or reach the end of the string and there are open
281 * tags, they are closed in a fixed order ... this means, for 281 * tags, they are closed in a fixed order ... this means, for
379 decoded = g_string_append(decoded, "</U>"); 379 decoded = g_string_append(decoded, "</U>");
380 if (font) 380 if (font)
381 decoded = g_string_append(decoded, "</FONT>"); 381 decoded = g_string_append(decoded, "</FONT>");
382 break; 382 break;
383 default: 383 default:
384 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur); 384 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur);
385 } 385 }
386 } while (*cur); 386 } while (*cur);
387 387
388 return g_string_free(decoded, FALSE); 388 return g_string_free(decoded, FALSE);
389 } 389 }
415 return (string[0] == '#' || string[0] == '&'); 415 return (string[0] == '#' || string[0] == '&');
416 } 416 }
417 417
418 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) 418 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice)
419 { 419 {
420 GaimConnection *gc; 420 PurpleConnection *gc;
421 const char *cur = msg + 1; 421 const char *cur = msg + 1;
422 char *buf, *ctcp; 422 char *buf, *ctcp;
423 time_t timestamp; 423 time_t timestamp;
424 424
425 /* Note that this is NOT correct w.r.t. multiple CTCPs in one 425 /* Note that this is NOT correct w.r.t. multiple CTCPs in one
436 return buf; 436 return buf;
437 } else if (!strncmp(cur, "PING ", 5)) { 437 } else if (!strncmp(cur, "PING ", 5)) {
438 if (notice) { /* reply */ 438 if (notice) { /* reply */
439 /* TODO: Should this read in the timestamp as a double? */ 439 /* TODO: Should this read in the timestamp as a double? */
440 sscanf(cur, "PING %lu", &timestamp); 440 sscanf(cur, "PING %lu", &timestamp);
441 gc = gaim_account_get_connection(irc->account); 441 gc = purple_account_get_connection(irc->account);
442 if (!gc) 442 if (!gc)
443 return NULL; 443 return NULL;
444 buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); 444 buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp);
445 gaim_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); 445 purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf);
446 g_free(buf); 446 g_free(buf);
447 return NULL; 447 return NULL;
448 } else { 448 } else {
449 buf = irc_format(irc, "vt:", "NOTICE", from, msg); 449 buf = irc_format(irc, "vt:", "NOTICE", from, msg);
450 irc_send(irc, buf); 450 irc_send(irc, buf);
451 g_free(buf); 451 g_free(buf);
452 } 452 }
453 } else if (!strncmp(cur, "VERSION", 7) && !notice) { 453 } else if (!strncmp(cur, "VERSION", 7) && !notice) {
454 buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Gaim IRC\001"); 454 buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Purple IRC\001");
455 irc_send(irc, buf); 455 irc_send(irc, buf);
456 g_free(buf); 456 g_free(buf);
457 } else if (!strncmp(cur, "DCC SEND ", 9)) { 457 } else if (!strncmp(cur, "DCC SEND ", 9)) {
458 irc_dccsend_recv(irc, from, msg + 10); 458 irc_dccsend_recv(irc, from, msg + 10);
459 return NULL; 459 return NULL;
469 void irc_msg_table_build(struct irc_conn *irc) 469 void irc_msg_table_build(struct irc_conn *irc)
470 { 470 {
471 int i; 471 int i;
472 472
473 if (!irc || !irc->msgs) { 473 if (!irc || !irc->msgs) {
474 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n"); 474 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n");
475 return; 475 return;
476 } 476 }
477 477
478 for (i = 0; _irc_msgs[i].name; i++) { 478 for (i = 0; _irc_msgs[i].name; i++) {
479 g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]); 479 g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]);
483 void irc_cmd_table_build(struct irc_conn *irc) 483 void irc_cmd_table_build(struct irc_conn *irc)
484 { 484 {
485 int i; 485 int i;
486 486
487 if (!irc || !irc->cmds) { 487 if (!irc || !irc->cmds) {
488 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n"); 488 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n");
489 return; 489 return;
490 } 490 }
491 491
492 for (i = 0; _irc_cmds[i].name ; i++) { 492 for (i = 0; _irc_cmds[i].name ; i++) {
493 g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]); 493 g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]);
520 tmp = irc_send_convert(irc, tok); 520 tmp = irc_send_convert(irc, tok);
521 g_string_append(string, tmp); 521 g_string_append(string, tmp);
522 g_free(tmp); 522 g_free(tmp);
523 break; 523 break;
524 default: 524 default:
525 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur); 525 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur);
526 break; 526 break;
527 } 527 }
528 } 528 }
529 va_end(ap); 529 va_end(ap);
530 g_string_append(string, "\r\n"); 530 g_string_append(string, "\r\n");
542 /* 542 /*
543 * The data passed to irc-receiving-text is the raw protocol data. 543 * The data passed to irc-receiving-text is the raw protocol data.
544 * TODO: It should be passed as an array of bytes and a length 544 * TODO: It should be passed as an array of bytes and a length
545 * instead of a null terminated string. 545 * instead of a null terminated string.
546 */ 546 */
547 gaim_signal_emit(_irc_plugin, "irc-receiving-text", gaim_account_get_connection(irc->account), &input); 547 purple_signal_emit(_irc_plugin, "irc-receiving-text", purple_account_get_connection(irc->account), &input);
548 548
549 if (!strncmp(input, "PING ", 5)) { 549 if (!strncmp(input, "PING ", 5)) {
550 msg = irc_format(irc, "vv", "PONG", input + 5); 550 msg = irc_format(irc, "vv", "PONG", input + 5);
551 irc_send(irc, msg); 551 irc_send(irc, msg);
552 g_free(msg); 552 g_free(msg);
553 return; 553 return;
554 } else if (!strncmp(input, "ERROR ", 6)) { 554 } else if (!strncmp(input, "ERROR ", 6)) {
555 if (g_utf8_validate(input, -1, NULL)) { 555 if (g_utf8_validate(input, -1, NULL)) {
556 char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input); 556 char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input);
557 gaim_connection_error(gaim_account_get_connection(irc->account), tmp); 557 purple_connection_error(purple_account_get_connection(irc->account), tmp);
558 g_free(tmp); 558 g_free(tmp);
559 } else 559 } else
560 gaim_connection_error(gaim_account_get_connection(irc->account), _("Disconnected.")); 560 purple_connection_error(purple_account_get_connection(irc->account), _("Disconnected."));
561 return; 561 return;
562 } 562 }
563 563
564 if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) { 564 if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) {
565 irc_parse_error_cb(irc, input); 565 irc_parse_error_cb(irc, input);
609 case '*': 609 case '*':
610 args[i] = g_strdup(cur); 610 args[i] = g_strdup(cur);
611 cur = cur + strlen(cur); 611 cur = cur + strlen(cur);
612 break; 612 break;
613 default: 613 default:
614 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]); 614 purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]);
615 break; 615 break;
616 } 616 }
617 } 617 }
618 tmp = irc_recv_convert(irc, from); 618 tmp = irc_recv_convert(irc, from);
619 (msgent->cb)(irc, msgent->name, tmp, args); 619 (msgent->cb)(irc, msgent->name, tmp, args);
625 g_free(from); 625 g_free(from);
626 } 626 }
627 627
628 static void irc_parse_error_cb(struct irc_conn *irc, char *input) 628 static void irc_parse_error_cb(struct irc_conn *irc, char *input)
629 { 629 {
630 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unrecognized string: %s\n", input); 630 purple_debug(PURPLE_DEBUG_WARNING, "irc", "Unrecognized string: %s\n", input);
631 } 631 }