comparison src/protocols/irc/irc.c @ 4201:511c2b63caa4

[gaim-migrate @ 4432] Some code cleanups to remove warnings and fix up indenting a little. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 04 Jan 2003 21:01:32 +0000
parents 474265997752
children 9e2336d5bdee
comparison
equal deleted inserted replaced
4200:c8fb43808a4b 4201:511c2b63caa4
1443 } 1443 }
1444 1444
1445 /* CTCP by jonas@birme.se */ 1445 /* CTCP by jonas@birme.se */
1446 static void 1446 static void
1447 irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, 1447 irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex,
1448 char *word[], char *word_eol[]) 1448 char *word[], char *word_eol[])
1449 { 1449 {
1450 char buf[IRC_BUF_LEN]; 1450 char buf[IRC_BUF_LEN];
1451 1451
1452 if (!g_strcasecmp(word[4], ":\001CLIENTINFO")) { 1452 if (!g_strcasecmp(word[4], ":\001CLIENTINFO")) {
1453 char *p = g_strrstr(word_eol[5], "\001"); 1453 char *p = g_strrstr(word_eol[5], "\001");
1454 *p = 0; 1454 *p = 0;
1455 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", 1455 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", word_eol[5]);
1456 word_eol[5]); 1456 do_error_dialog(buf, _("CTCP ClientInfo"), GAIM_INFO);
1457 do_error_dialog(buf, _("CTCP ClientInfo"), GAIM_INFO); 1457
1458 } else if (!g_strcasecmp(word[4], ":\001USERINFO")) { 1458 } else if (!g_strcasecmp(word[4], ":\001USERINFO")) {
1459 char *p = g_strrstr(word_eol[5], "\001"); 1459 char *p = g_strrstr(word_eol[5], "\001");
1460 *p = 0; 1460 *p = 0;
1461 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", 1461 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", word_eol[5]);
1462 word_eol[5]); 1462 do_error_dialog(buf, _("CTCP UserInfo"), GAIM_INFO);
1463 do_error_dialog(buf, _("CTCP UserInfo"), GAIM_INFO); 1463
1464 } else if (!g_strcasecmp(word[4], ":\001VERSION")) { 1464 } else if (!g_strcasecmp(word[4], ":\001VERSION")) {
1465 char *p = g_strrstr(word_eol[5], "\001"); 1465 char *p = g_strrstr(word_eol[5], "\001");
1466 *p = 0; 1466 *p = 0;
1467 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", 1467 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", word_eol[5]);
1468 word_eol[5]); 1468 do_error_dialog(buf, _("CTCP Version"), GAIM_INFO);
1469 do_error_dialog(buf, _("CTCP Version"), GAIM_INFO); 1469
1470 } else if (!g_strcasecmp(word[4], ":\001PING")) { 1470 } else if (!g_strcasecmp(word[4], ":\001PING")) {
1471 char *p = g_strrstr(word_eol[5], "\001"); 1471 char *p = g_strrstr(word_eol[5], "\001");
1472 struct timeval ping_time; 1472 struct timeval ping_time;
1473 struct timeval now; 1473 struct timeval now;
1474 gchar **vector; 1474 gchar **vector;
1475 if (p) 1475
1476 *p = 0; 1476 if (p)
1477 vector = g_strsplit(word_eol[5], " ", 2); 1477 *p = 0;
1478 if (gettimeofday(&now, NULL) == 0 && vector != NULL) { 1478
1479 if (now.tv_usec - atol(vector[1]) < 0) { 1479 vector = g_strsplit(word_eol[5], " ", 2);
1480 ping_time.tv_sec = now.tv_sec - atol(vector[0]) - 1; 1480
1481 ping_time.tv_usec = now.tv_usec - atol(vector[1]) + 1000000; 1481 if (gettimeofday(&now, NULL) == 0 && vector != NULL) {
1482 } else { 1482 if (now.tv_usec - atol(vector[1]) < 0) {
1483 ping_time.tv_sec = now.tv_sec - atol(vector[0]); 1483 ping_time.tv_sec = now.tv_sec - atol(vector[0]) - 1;
1484 ping_time.tv_usec = now.tv_usec - atol(vector[1]); 1484 ping_time.tv_usec = now.tv_usec - atol(vector[1]) + 1000000;
1485 } 1485
1486 g_snprintf(buf, sizeof(buf), 1486 } else {
1487 "CTCP Ping reply from %s: %lu.%.03lu seconds", 1487 ping_time.tv_sec = now.tv_sec - atol(vector[0]);
1488 nick, ping_time.tv_sec, (ping_time.tv_usec/1000)); 1488 ping_time.tv_usec = now.tv_usec - atol(vector[1]);
1489 do_error_dialog(buf, _("CTCP Ping"), GAIM_INFO); 1489 }
1490 g_strfreev(vector); 1490
1491 } 1491 g_snprintf(buf, sizeof(buf),
1492 } else { 1492 "CTCP Ping reply from %s: %lu.%.03lu seconds",
1493 if (*word_eol[4] == ':') word_eol[4]++; 1493 nick, ping_time.tv_sec, (ping_time.tv_usec/1000));
1494 if (ex) 1494
1495 irc_got_im(gc, nick, word_eol[4], 0, 1495 do_error_dialog(buf, _("CTCP Ping"), GAIM_INFO);
1496 time(NULL)); 1496 g_strfreev(vector);
1497 } 1497 }
1498 1498 } else {
1499 if (*word_eol[4] == ':') word_eol[4]++;
1500 if (ex)
1501 irc_got_im(gc, nick, word_eol[4], 0, time(NULL));
1502 }
1499 } 1503 }
1500 1504
1501 static void 1505 static void
1502 irc_parse_join(struct gaim_connection *gc, char *nick, 1506 irc_parse_join(struct gaim_connection *gc, char *nick,
1503 char *word[], char *word_eol[]) 1507 char *word[], char *word_eol[])
1504 { 1508 {
1505 char *chan = *word[3] == ':' ? word[3] + 1 : word[3]; 1509 char *chan = *word[3] == ':' ? word[3] + 1 : word[3];
1506 static int id = 1; 1510 static int id = 1;
1507 struct conversation *c; 1511 struct conversation *c;
1508 char *hostmask, *p; 1512 char *hostmask, *p;
1509 1513
1510 if (!g_strcasecmp(gc->displayname, nick)) { 1514 if (!g_strcasecmp(gc->displayname, nick)) {
1511 serv_got_joined_chat(gc, id++, chan); 1515 serv_got_joined_chat(gc, id++, chan);
1512 } else { 1516 } else {
1513 c = irc_find_chat(gc, chan); 1517 c = irc_find_chat(gc, chan);
1514 if (c) { 1518 if (c) {
1515 hostmask = g_strdup(word[1]); 1519 hostmask = g_strdup(word[1]);
1516 p = strchr(hostmask, '!'); 1520 p = strchr(hostmask, '!');
1517 if (p) { 1521 if (p) {
1518 char *pend = strchr(p, ' '); 1522 char *pend = strchr(p, ' ');
1519 if (pend) { 1523 if (pend) {
1520 *pend = 0; 1524 *pend = 0;
1521 } 1525 }
1522 add_chat_buddy(c, nick, p+1); 1526 add_chat_buddy(c, nick, p+1);
1523 g_free(hostmask); 1527 g_free(hostmask);
1524 } 1528 }
1525 } 1529 }
1526 } 1530 }
1527 } 1531 }
1528 1532
1529 static void 1533 static void
1530 irc_parse_topic(struct gaim_connection *gc, char *nick, 1534 irc_parse_topic(struct gaim_connection *gc, char *nick,
1531 char *word[], char *word_eol[]) 1535 char *word[], char *word_eol[])
1532 { 1536 {
1533 struct conversation *c = irc_find_chat(gc, word[3]); 1537 struct conversation *c = irc_find_chat(gc, word[3]);
1534 char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; 1538 char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4];
1535 char buf[IRC_BUF_LEN]; 1539 char buf[IRC_BUF_LEN];
1536 1540
1537 if (c) { 1541 if (c) {
1538 chat_set_topic(c, nick, topic); 1542 chat_set_topic(c, nick, topic);
1539 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"), 1543 g_snprintf(buf, sizeof(buf),
1540 nick, topic); 1544 _("<B>%s has changed the topic to: %s</B>"), nick, topic);
1541 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); 1545 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1);
1542 } 1546 }
1543 } 1547 }
1544 1548
1545 static gboolean 1549 static gboolean
1546 irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd, 1550 irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd,
1547 char *word[], char *word_eol[]) 1551 char *word[], char *word_eol[])
1548 { 1552 {
1549 char *chan = cmd + 5; 1553 char *chan = cmd + 5;
1550 struct conversation *c; 1554 struct conversation *c;
1551 char *reason = word_eol[4]; 1555 char *reason = word_eol[4];
1552 GList *r; 1556 GList *r;
1553 1557
1554 if (*chan == ':') 1558 if (*chan == ':')
1555 chan++; 1559 chan++;
1556 if (*reason == ':') 1560 if (*reason == ':')
1557 reason++; 1561 reason++;
1558 if (!(c = irc_find_chat(gc, chan))) 1562 if (!(c = irc_find_chat(gc, chan)))
1559 return FALSE; 1563 return FALSE;
1560 if (!strcmp(nick, gc->displayname)) { 1564 if (!strcmp(nick, gc->displayname)) {
1561 serv_got_chat_left(gc, c->id); 1565 serv_got_chat_left(gc, c->id);
1562 return FALSE; 1566 return FALSE;
1563 } 1567 }
1564 r = c->in_room; 1568 r = c->in_room;
1565 while (r) { 1569 while (r) {
1566 char *who = r->data; 1570 char *who = r->data;
1567 if (*who == '@') 1571 if (*who == '@')
1568 who++; 1572 who++;
1569 if (*who == '+') 1573 if (*who == '+')
1570 who++; 1574 who++;
1571 if (!g_strcasecmp(who, nick)) { 1575 if (!g_strcasecmp(who, nick)) {
1572 char *tmp = g_strdup(r->data); 1576 char *tmp = g_strdup(r->data);
1573 remove_chat_buddy(c, tmp, reason); 1577 remove_chat_buddy(c, tmp, reason);
1574 g_free(tmp); 1578 g_free(tmp);
1575 break; 1579 break;
1576 } 1580 }
1577 r = r->next; 1581 r = r->next;
1578 } 1582 }
1579 return TRUE; 1583 return TRUE;
1580 } 1584 }
1581 1585
1582 static void 1586 static void
1583 irc_callback(gpointer data, gint source, 1587 irc_callback(gpointer data, gint source, GaimInputCondition condition)
1584 GaimInputCondition condition)
1585 { 1588 {
1586 struct gaim_connection *gc = data; 1589 struct gaim_connection *gc = data;
1587 struct irc_data *idata = gc->proto_data; 1590 struct irc_data *idata = gc->proto_data;
1588 int i = 0; 1591 int i = 0;
1589 gchar buf[1024]; 1592 gchar buf[1024];