comparison src/protocols/irc/irc.c @ 3033:1143524a2eaf

[gaim-migrate @ 3046] Laying the ground work for image send. Also an IRC fix. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 12 Mar 2002 17:21:46 +0000
parents e40c30cf7572
children 22c84cbcd5a6
comparison
equal deleted inserted replaced
3032:d3536105d581 3033:1143524a2eaf
1460 irc_write(id->fd, buf, strlen(buf)); 1460 irc_write(id->fd, buf, strlen(buf));
1461 g_string_free(str, TRUE); 1461 g_string_free(str, TRUE);
1462 return 1; 1462 return 1;
1463 } 1463 }
1464 1464
1465 what++; 1465 process_data_init(pdibuf, what + 1, word, word_eol, TRUE);
1466 process_data_init(pdibuf, what, word, word_eol, TRUE); 1466 g_string_free(str, FALSE);
1467 g_string_free(str, TRUE);
1468 if (!g_strcasecmp(pdibuf, "ME")) { 1467 if (!g_strcasecmp(pdibuf, "ME")) {
1469 if (dccchat) { 1468 if (dccchat) {
1470 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001\r\n", word_eol[2]); 1469 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001\r\n", word_eol[2]);
1471 irc_write(dccchat->fd, buf, strlen(buf)); 1470 irc_write(dccchat->fd, buf, strlen(buf));
1471 g_free(what);
1472 return 1; 1472 return 1;
1473 } 1473 }
1474 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :\001ACTION %s\001\r\n", who, word_eol[2]); 1474 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :\001ACTION %s\001\r\n", who, word_eol[2]);
1475 irc_write(id->fd, buf, strlen(buf)); 1475 irc_write(id->fd, buf, strlen(buf));
1476 g_free(what);
1476 return 1; 1477 return 1;
1477 } else if (!g_strcasecmp(pdibuf, "INVITE")) { 1478 } else if (!g_strcasecmp(pdibuf, "INVITE")) {
1478 char buf[IRC_BUF_LEN]; 1479 char buf[IRC_BUF_LEN];
1479 g_snprintf(buf, sizeof(buf), "INVITE %s\r\n", word_eol[2]); 1480 g_snprintf(buf, sizeof(buf), "INVITE %s\r\n", word_eol[2]);
1480 irc_write(id->fd, buf, strlen(buf)); 1481 irc_write(id->fd, buf, strlen(buf));
1481 } else if (!g_strcasecmp(pdibuf, "TOPIC")) { 1482 } else if (!g_strcasecmp(pdibuf, "TOPIC")) {
1482 if (!*word_eol[2]) 1483 if (!*word_eol[2]) {
1484 g_free(what);
1483 return -EINVAL; 1485 return -EINVAL;
1486 }
1484 g_snprintf(buf, sizeof(buf), "TOPIC %s :%s\r\n", who, word_eol[2]); 1487 g_snprintf(buf, sizeof(buf), "TOPIC %s :%s\r\n", who, word_eol[2]);
1485 irc_write(id->fd, buf, strlen(buf)); 1488 irc_write(id->fd, buf, strlen(buf));
1486 } else if (!g_strcasecmp(pdibuf, "NICK")) { 1489 } else if (!g_strcasecmp(pdibuf, "NICK")) {
1487 if (!*word_eol[2]) 1490 if (!*word_eol[2]) {
1491 g_free(what);
1488 return -EINVAL; 1492 return -EINVAL;
1493 }
1489 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", word_eol[2]); 1494 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", word_eol[2]);
1490 irc_write(id->fd, buf, strlen(buf)); 1495 irc_write(id->fd, buf, strlen(buf));
1491 } else if (!g_strcasecmp(pdibuf, "OP")) { 1496 } else if (!g_strcasecmp(pdibuf, "OP")) {
1492 set_mode(gc, who, '+', 'o', word); 1497 set_mode(gc, who, '+', 'o', word);
1493 } else if (!g_strcasecmp(pdibuf, "DEOP")) { 1498 } else if (!g_strcasecmp(pdibuf, "DEOP")) {
1495 } else if (!g_strcasecmp(pdibuf, "VOICE")) { 1500 } else if (!g_strcasecmp(pdibuf, "VOICE")) {
1496 set_mode(gc, who, '+', 'v', word); 1501 set_mode(gc, who, '+', 'v', word);
1497 } else if (!g_strcasecmp(pdibuf, "DEVOICE")) { 1502 } else if (!g_strcasecmp(pdibuf, "DEVOICE")) {
1498 set_mode(gc, who, '-', 'v', word); 1503 set_mode(gc, who, '-', 'v', word);
1499 } else if (!g_strcasecmp(pdibuf, "QUOTE")) { 1504 } else if (!g_strcasecmp(pdibuf, "QUOTE")) {
1500 if (!*word_eol[2]) 1505 if (!*word_eol[2]) {
1506 g_free(what);
1501 return -EINVAL; 1507 return -EINVAL;
1508 }
1502 g_snprintf(buf, sizeof(buf), "%s\r\n", word_eol[2]); 1509 g_snprintf(buf, sizeof(buf), "%s\r\n", word_eol[2]);
1503 irc_write(id->fd, buf, strlen(buf)); 1510 irc_write(id->fd, buf, strlen(buf));
1504 } else if (!g_strcasecmp(pdibuf, "SAY")) { 1511 } else if (!g_strcasecmp(pdibuf, "SAY")) {
1505 if (!*word_eol[2]) 1512 if (!*word_eol[2]) {
1513 g_free(what);
1506 return -EINVAL; 1514 return -EINVAL;
1515 }
1507 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, word_eol[2]); 1516 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, word_eol[2]);
1508 irc_write(id->fd, buf, strlen(buf)); 1517 irc_write(id->fd, buf, strlen(buf));
1509 return 1; 1518 return 1;
1510 } else if (!g_strcasecmp(pdibuf, "MSG")) { 1519 } else if (!g_strcasecmp(pdibuf, "MSG")) {
1511 if (!*word[2]) 1520 if (!*word[2]) {
1521 g_free(what);
1512 return -EINVAL; 1522 return -EINVAL;
1513 if (!*word_eol[3]) 1523 }
1524 if (!*word_eol[3]) {
1525 g_free(what);
1514 return -EINVAL; 1526 return -EINVAL;
1527 }
1515 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", word[2], word_eol[3]); 1528 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", word[2], word_eol[3]);
1516 irc_write(id->fd, buf, strlen(buf)); 1529 irc_write(id->fd, buf, strlen(buf));
1517 } else if (!g_strcasecmp(pdibuf, "KICK")) { 1530 } else if (!g_strcasecmp(pdibuf, "KICK")) {
1518 if (!*word[2]) 1531 if (!*word[2]) {
1532 g_free(what);
1519 return -EINVAL; 1533 return -EINVAL;
1534 }
1520 if (*word_eol[3]) 1535 if (*word_eol[3])
1521 g_snprintf(buf, sizeof(buf), "KICK %s %s :%s\r\n", who, word[2], word_eol[3]); 1536 g_snprintf(buf, sizeof(buf), "KICK %s %s :%s\r\n", who, word[2], word_eol[3]);
1522 else 1537 else
1523 g_snprintf(buf, sizeof(buf), "KICK %s %s\r\n", who, word[2]); 1538 g_snprintf(buf, sizeof(buf), "KICK %s %s\r\n", who, word[2]);
1524 irc_write(id->fd, buf, strlen(buf)); 1539 irc_write(id->fd, buf, strlen(buf));
1525 } else if (!g_strcasecmp(pdibuf, "JOIN") || !g_strcasecmp(pdibuf, "J")) { 1540 } else if (!g_strcasecmp(pdibuf, "JOIN") || !g_strcasecmp(pdibuf, "J")) {
1526 if (!*word[2]) 1541 if (!*word[2]) {
1542 g_free(what);
1527 return -EINVAL; 1543 return -EINVAL;
1544 }
1528 if (*word[3]) 1545 if (*word[3])
1529 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", word[2], word[3]); 1546 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", word[2], word[3]);
1530 else 1547 else
1531 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", word[2]); 1548 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", word[2]);
1532 irc_write(id->fd, buf, strlen(buf)); 1549 irc_write(id->fd, buf, strlen(buf));
1533 } else if (!g_strcasecmp(pdibuf, "PART")) { 1550 } else if (!g_strcasecmp(pdibuf, "PART")) {
1534 char *chan = *word[2] ? word[2] : who; 1551 char *chan = *word[2] ? word[2] : who;
1535 char *reason = word_eol[3]; 1552 char *reason = word_eol[3];
1536 struct conversation *c; 1553 struct conversation *c;
1537 if (!is_channel(gc, chan)) 1554 if (!is_channel(gc, chan)) {
1555 g_free(what);
1538 return -EINVAL; 1556 return -EINVAL;
1557 }
1539 c = irc_find_chat(gc, chan); 1558 c = irc_find_chat(gc, chan);
1540 g_snprintf(buf, sizeof(buf), "PART %s%s%s\r\n", chan, 1559 g_snprintf(buf, sizeof(buf), "PART %s%s%s\r\n", chan,
1541 *reason ? " :" : "", 1560 *reason ? " :" : "",
1542 *reason ? reason : ""); 1561 *reason ? reason : "");
1543 irc_write(id->fd, buf, strlen(buf)); 1562 irc_write(id->fd, buf, strlen(buf));
1558 if (is_channel(gc, who)) { 1577 if (is_channel(gc, who)) {
1559 c = irc_find_chat(gc, who); 1578 c = irc_find_chat(gc, who);
1560 } else { 1579 } else {
1561 c = find_conversation(who); 1580 c = find_conversation(who);
1562 } 1581 }
1563 if (!c) 1582 if (!c) {
1583 g_free(what);
1564 return -EINVAL; 1584 return -EINVAL;
1585 }
1565 write_to_conv(c, "<B>Currently supported commands:<BR>" 1586 write_to_conv(c, "<B>Currently supported commands:<BR>"
1566 "WHOIS INVITE NICK LIST<BR>" 1587 "WHOIS INVITE NICK LIST<BR>"
1567 "JOIN PART TOPIC KICK<BR>" 1588 "JOIN PART TOPIC KICK<BR>"
1568 "OP DEOP VOICE DEVOICE<BR>" 1589 "OP DEOP VOICE DEVOICE<BR>"
1569 "ME MSG QUOTE SAY</B>", 1590 "ME MSG QUOTE SAY</B>",
1573 if (is_channel(gc, who)) { 1594 if (is_channel(gc, who)) {
1574 c = irc_find_chat(gc, who); 1595 c = irc_find_chat(gc, who);
1575 } else { 1596 } else {
1576 c = find_conversation(who); 1597 c = find_conversation(who);
1577 } 1598 }
1578 if (!c) 1599 if (!c) {
1600 g_free(what);
1579 return -EINVAL; 1601 return -EINVAL;
1602 }
1580 write_to_conv(c, "<B>Unknown command</B>", WFLAG_NOLOG, NULL, time(NULL), -1); 1603 write_to_conv(c, "<B>Unknown command</B>", WFLAG_NOLOG, NULL, time(NULL), -1);
1581 } 1604 }
1582 1605 g_free(what);
1583 return 0; 1606 return 0;
1584 } 1607 }
1585 1608
1586 static int send_msg(struct gaim_connection *gc, char *who, char *what) 1609 static int send_msg(struct gaim_connection *gc, char *who, char *what)
1587 { 1610 {
1611 struct conversation *c = irc_find_chat_by_id(gc, idn); 1634 struct conversation *c = irc_find_chat_by_id(gc, idn);
1612 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); 1635 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name);
1613 irc_write(id->fd, buf, strlen(buf)); 1636 irc_write(id->fd, buf, strlen(buf));
1614 } 1637 }
1615 1638
1616 static int irc_send_im(struct gaim_connection *gc, char *who, char *what, int flags) 1639 static int irc_send_im(struct gaim_connection *gc, char *who, char *what, int len, int flags)
1617 { 1640 {
1618 if (*who == '@' || *who == '+') 1641 if (*who == '@' || *who == '+')
1619 return send_msg(gc, who + 1, what); 1642 return send_msg(gc, who + 1, what);
1620 return send_msg(gc, who, what); 1643 return send_msg(gc, who, what);
1621 } 1644 }
1785 chat->inpa = 1808 chat->inpa =
1786 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected, 1809 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected,
1787 chat); 1810 chat);
1788 snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n", 1811 snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n",
1789 chat->ip_address, chat->port); 1812 chat->ip_address, chat->port);
1790 irc_send_im (gc, who, buf, 0); 1813 irc_send_im (gc, who, buf, -1, 0);
1791 } 1814 }
1792 1815
1793 static void irc_get_info(struct gaim_connection *gc, char *who) 1816 static void irc_get_info(struct gaim_connection *gc, char *who)
1794 { 1817 {
1795 struct irc_data *idata = gc->proto_data; 1818 struct irc_data *idata = gc->proto_data;