Mercurial > pidgin
comparison src/protocols/irc/irc.c @ 3735:242e52b37a78
[gaim-migrate @ 3873]
"I have fixed the CTCP PING request and realised that the other CTCP
funcntions didn't work, so I have fixed that too." -- birme
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 18 Oct 2002 02:13:10 +0000 |
parents | a20bf3d247ff |
children | e25577506dec |
comparison
equal
deleted
inserted
replaced
3734:9497635473f2 | 3735:242e52b37a78 |
---|---|
62 | 62 |
63 static void irc_start_chat(struct gaim_connection *gc, char *who); | 63 static void irc_start_chat(struct gaim_connection *gc, char *who); |
64 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who); | 64 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who); |
65 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who); | 65 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who); |
66 static void irc_ctcp_version(struct gaim_connection *gc, char *who); | 66 static void irc_ctcp_version(struct gaim_connection *gc, char *who); |
67 static void irc_ctcp_ping(struct gaim_connection *gc, char *who); | |
68 | |
69 static void irc_send_privmsg(struct gaim_connection *gc, char *who, char *what); | |
70 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what); | |
67 | 71 |
68 struct dcc_chat | 72 struct dcc_chat |
69 { | 73 { |
70 struct gaim_connection *gc; | 74 struct gaim_connection *gc; |
71 char ip_address[12]; | 75 char ip_address[12]; |
1132 static void handle_ctcp(struct gaim_connection *gc, char *to, char *nick, | 1136 static void handle_ctcp(struct gaim_connection *gc, char *to, char *nick, |
1133 char *msg, char *word[], char *word_eol[]) | 1137 char *msg, char *word[], char *word_eol[]) |
1134 { | 1138 { |
1135 struct irc_data *id = gc->proto_data; | 1139 struct irc_data *id = gc->proto_data; |
1136 char buf[IRC_BUF_LEN]; | 1140 char buf[IRC_BUF_LEN]; |
1141 char out[IRC_BUF_LEN]; | |
1137 | 1142 |
1138 if (!g_strncasecmp(msg, "VERSION", 7)) { | 1143 if (!g_strncasecmp(msg, "VERSION", 7)) { |
1139 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001VERSION Gaim " VERSION ": The Penguin Pimpin' " | 1144 g_snprintf(buf, sizeof(buf), "\001VERSION Gaim " VERSION ": The Penguin Pimpin' " |
1140 "Multi-protocol Messaging Client: " WEBSITE "\001\r\n", nick); | 1145 "Multi-protocol Messaging Client: " WEBSITE "\001"); |
1141 irc_write(id->fd, buf, strlen(buf)); | 1146 irc_send_notice (gc, nick, buf); |
1147 g_snprintf(out, sizeof(out), ">> CTCP VERSION requested from %s", nick); | |
1148 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
1142 } | 1149 } |
1143 if (!g_strncasecmp(msg, "CLIENTINFO", 10)) { | 1150 if (!g_strncasecmp(msg, "CLIENTINFO", 10)) { |
1144 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001CLIENTINFO USERINFO CLIENTINFO VERSION\001\r\n", nick); | 1151 g_snprintf(buf, sizeof(buf), "\001CLIENTINFO USERINFO CLIENTINFO VERSION\001"); |
1145 irc_write(id->fd, buf, strlen(buf)); | 1152 irc_send_notice (gc, nick, buf); |
1153 g_snprintf(out, sizeof(out), ">> CTCP CLIENTINFO requested from %s", nick); | |
1154 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
1146 } | 1155 } |
1147 if (!g_strncasecmp(msg, "USERINFO", 8)) { | 1156 if (!g_strncasecmp(msg, "USERINFO", 8)) { |
1148 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001USERINFO Alias: %s\001\r\n", nick, gc->user->alias); | 1157 g_snprintf(buf, sizeof(buf), "\001USERINFO Alias: %s\001", gc->user->alias); |
1149 irc_write(id->fd, buf, strlen(buf)); | 1158 irc_send_notice (gc, nick, buf); |
1159 g_snprintf(out, sizeof(out), ">> CTCP USERINFO requested from %s", nick); | |
1160 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
1150 } | 1161 } |
1151 if (!g_strncasecmp(msg, "ACTION", 6)) { | 1162 if (!g_strncasecmp(msg, "ACTION", 6)) { |
1152 char *po = strchr(msg + 6, 1); | 1163 char *po = strchr(msg + 6, 1); |
1153 char *tmp; | 1164 char *tmp; |
1154 if (po) *po = 0; | 1165 if (po) *po = 0; |
1155 tmp = g_strconcat("/me", msg + 6, NULL); | 1166 tmp = g_strconcat("/me", msg + 6, NULL); |
1156 handle_privmsg(gc, to, nick, tmp); | 1167 handle_privmsg(gc, to, nick, tmp); |
1157 g_free(tmp); | 1168 g_free(tmp); |
1169 } | |
1170 if (!g_strncasecmp(msg, "PING", 4)) { | |
1171 g_snprintf(buf, sizeof(buf), "\001%s\001", msg); | |
1172 irc_send_notice (gc, nick, buf); | |
1173 g_snprintf(out, sizeof(out), ">> CTCP PING requested from %s", nick); | |
1174 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
1158 } | 1175 } |
1159 if (!g_strncasecmp(msg, "DCC CHAT", 8)) { | 1176 if (!g_strncasecmp(msg, "DCC CHAT", 8)) { |
1160 char **chat_args = g_strsplit(msg, " ", 5); | 1177 char **chat_args = g_strsplit(msg, " ", 5); |
1161 char ask[1024]; | 1178 char ask[1024]; |
1162 struct dcc_chat *dccchat = g_new0(struct dcc_chat, 1); | 1179 struct dcc_chat *dccchat = g_new0(struct dcc_chat, 1); |
1186 | 1203 |
1187 id->file_transfers = g_slist_append(id->file_transfers, ift); | 1204 id->file_transfers = g_slist_append(id->file_transfers, ift); |
1188 | 1205 |
1189 ift->xfer = transfer_in_add(gc, nick, ift->name, ift->len, 1, NULL); | 1206 ift->xfer = transfer_in_add(gc, nick, ift->name, ift->len, 1, NULL); |
1190 } | 1207 } |
1191 | 1208 |
1192 /* XXX should probably write_to_conv or something here */ | 1209 /*write_to_conv(c, out, WFLAG_SYSTEM, NULL, time(NULL), -1);*/ |
1193 } | 1210 } |
1194 | 1211 |
1195 static gboolean irc_parse(struct gaim_connection *gc, char *buf) | 1212 static gboolean irc_parse(struct gaim_connection *gc, char *buf) |
1196 { | 1213 { |
1197 struct irc_data *idata = gc->proto_data; | 1214 struct irc_data *idata = gc->proto_data; |
1326 char *p = strrchr(word_eol[5], '\001'); | 1343 char *p = strrchr(word_eol[5], '\001'); |
1327 *p = 0; | 1344 *p = 0; |
1328 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", | 1345 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", |
1329 word_eol[5]); | 1346 word_eol[5]); |
1330 do_error_dialog(buf, _("CTCP Version"), GAIM_INFO); | 1347 do_error_dialog(buf, _("CTCP Version"), GAIM_INFO); |
1348 } else if (!g_strcasecmp(word[4], ":\001PING")) { | |
1349 char *p = strrchr(word_eol[5], '\001'); | |
1350 time_t ping_time; | |
1351 if (p) | |
1352 *p = 0; | |
1353 ping_time = time(NULL) - atol(word_eol[5]); | |
1354 g_snprintf(buf, sizeof(buf), "CTCP Ping reply from %s; %d seconds", | |
1355 word[3], ping_time); | |
1356 do_error_dialog(buf, _("CTCP Ping"), GAIM_INFO); | |
1331 } else { | 1357 } else { |
1332 if (*word_eol[4] == ':') word_eol[4]++; | 1358 if (*word_eol[4] == ':') word_eol[4]++; |
1333 if (ex) | 1359 if (ex) |
1334 irc_got_im(gc, nick, word_eol[4], 0, | 1360 irc_got_im(gc, nick, word_eol[4], 0, |
1335 time(NULL)); | 1361 time(NULL)); |
1724 g_snprintf(buf, sizeof(buf), "%s\r\n", what); | 1750 g_snprintf(buf, sizeof(buf), "%s\r\n", what); |
1725 irc_write(dccchat->fd, buf, strlen(buf)); | 1751 irc_write(dccchat->fd, buf, strlen(buf)); |
1726 g_string_free(str, TRUE); | 1752 g_string_free(str, TRUE); |
1727 return 1; | 1753 return 1; |
1728 } | 1754 } |
1729 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, what); | 1755 /*g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, what); |
1730 irc_write(id->fd, buf, strlen(buf)); | 1756 irc_write(id->fd, buf, strlen(buf));*/ |
1757 irc_send_privmsg (gc, who, what); | |
1731 what[max] = t; | 1758 what[max] = t; |
1732 what = what + max; | 1759 what = what + max; |
1733 } | 1760 } |
1734 if (dccchat) { | 1761 if (dccchat) { |
1735 g_snprintf(buf, sizeof(buf), "%s\r\n", what); | 1762 g_snprintf(buf, sizeof(buf), "%s\r\n", what); |
1736 irc_write(dccchat->fd, buf, strlen(buf)); | 1763 irc_write(dccchat->fd, buf, strlen(buf)); |
1737 g_string_free(str, TRUE); | 1764 g_string_free(str, TRUE); |
1738 return 1; | 1765 return 1; |
1739 } | 1766 } |
1767 /* | |
1740 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, what); | 1768 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, what); |
1741 irc_write(id->fd, buf, strlen(buf)); | 1769 irc_write(id->fd, buf, strlen(buf));*/ |
1770 irc_send_privmsg (gc, who, what); | |
1742 g_string_free(str, TRUE); | 1771 g_string_free(str, TRUE); |
1743 return 1; | 1772 return 1; |
1744 } | 1773 } |
1745 | 1774 |
1746 process_data_init(pdibuf, what + 1, word, word_eol, TRUE); | 1775 process_data_init(pdibuf, what + 1, word, word_eol, TRUE); |
1750 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001\r\n", word_eol[2]); | 1779 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001\r\n", word_eol[2]); |
1751 irc_write(dccchat->fd, buf, strlen(buf)); | 1780 irc_write(dccchat->fd, buf, strlen(buf)); |
1752 g_free(what); | 1781 g_free(what); |
1753 return 1; | 1782 return 1; |
1754 } | 1783 } |
1784 /* | |
1755 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :\001ACTION %s\001\r\n", who, word_eol[2]); | 1785 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :\001ACTION %s\001\r\n", who, word_eol[2]); |
1756 irc_write(id->fd, buf, strlen(buf)); | 1786 irc_write(id->fd, buf, strlen(buf));*/ |
1787 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001", word_eol[2]); | |
1788 irc_send_privmsg (gc, who, buf); | |
1757 g_free(what); | 1789 g_free(what); |
1758 return 1; | 1790 return 1; |
1759 } else if (!g_strcasecmp(pdibuf, "INVITE")) { | 1791 } else if (!g_strcasecmp(pdibuf, "INVITE")) { |
1760 char buf[IRC_BUF_LEN]; | 1792 char buf[IRC_BUF_LEN]; |
1761 g_snprintf(buf, sizeof(buf), "INVITE %s\r\n", word_eol[2]); | 1793 g_snprintf(buf, sizeof(buf), "INVITE %s\r\n", word_eol[2]); |
1798 } else if (!g_strcasecmp(pdibuf, "SAY")) { | 1830 } else if (!g_strcasecmp(pdibuf, "SAY")) { |
1799 if (!*word_eol[2]) { | 1831 if (!*word_eol[2]) { |
1800 g_free(what); | 1832 g_free(what); |
1801 return -EINVAL; | 1833 return -EINVAL; |
1802 } | 1834 } |
1803 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, word_eol[2]); | 1835 /*g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, word_eol[2]); |
1804 irc_write(id->fd, buf, strlen(buf)); | 1836 irc_write(id->fd, buf, strlen(buf));*/ |
1837 irc_send_privmsg (gc, who, word_eol[2]); | |
1805 return 1; | 1838 return 1; |
1806 } else if (!g_strcasecmp(pdibuf, "MSG")) { | 1839 } else if (!g_strcasecmp(pdibuf, "MSG")) { |
1807 if (!*word[2]) { | 1840 if (!*word[2]) { |
1808 g_free(what); | 1841 g_free(what); |
1809 return -EINVAL; | 1842 return -EINVAL; |
1810 } | 1843 } |
1811 if (!*word_eol[3]) { | 1844 if (!*word_eol[3]) { |
1812 g_free(what); | 1845 g_free(what); |
1813 return -EINVAL; | 1846 return -EINVAL; |
1814 } | 1847 } |
1848 /* | |
1815 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", word[2], word_eol[3]); | 1849 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", word[2], word_eol[3]); |
1816 irc_write(id->fd, buf, strlen(buf)); | 1850 irc_write(id->fd, buf, strlen(buf));*/ |
1851 irc_send_privmsg (gc, word[2], word_eol[3]); | |
1817 } else if (!g_strcasecmp(pdibuf, "KICK")) { | 1852 } else if (!g_strcasecmp(pdibuf, "KICK")) { |
1818 if (!*word[2]) { | 1853 if (!*word[2]) { |
1819 g_free(what); | 1854 g_free(what); |
1820 return -EINVAL; | 1855 return -EINVAL; |
1821 } | 1856 } |
1886 if (word[3]) | 1921 if (word[3]) |
1887 irc_ctcp_userinfo(gc, word[3]); | 1922 irc_ctcp_userinfo(gc, word[3]); |
1888 } else if (!g_strcasecmp(word[2], "VERSION")) { | 1923 } else if (!g_strcasecmp(word[2], "VERSION")) { |
1889 if (word[3]) | 1924 if (word[3]) |
1890 irc_ctcp_version(gc, word[3]); | 1925 irc_ctcp_version(gc, word[3]); |
1926 | |
1927 } else if (!g_strcasecmp(word[2], "PING")) { | |
1928 if (word[3]) | |
1929 irc_ctcp_ping(gc, word[3]); | |
1891 } | 1930 } |
1892 } else if (!g_strcasecmp(pdibuf, "DCC")) { | 1931 } else if (!g_strcasecmp(pdibuf, "DCC")) { |
1893 struct conversation *c = NULL; | 1932 struct conversation *c = NULL; |
1894 if (!g_strcasecmp(word[2], "CHAT")) { | 1933 if (!g_strcasecmp(word[2], "CHAT")) { |
1895 if (word[3]) | 1934 if (word[3]) |
1923 WFLAG_NOLOG, NULL, time(NULL), -1); | 1962 WFLAG_NOLOG, NULL, time(NULL), -1); |
1924 } else if (!g_strcasecmp(word[2], "CTCP")) { | 1963 } else if (!g_strcasecmp(word[2], "CTCP")) { |
1925 write_to_conv(c, "<B>CTCP commands:<BR>" | 1964 write_to_conv(c, "<B>CTCP commands:<BR>" |
1926 "CLIENTINFO <nick><BR>" | 1965 "CLIENTINFO <nick><BR>" |
1927 "USERINFO <nick><BR>" | 1966 "USERINFO <nick><BR>" |
1928 "VERSION <nick></B>", | 1967 "VERSION <nick><BR>" |
1968 "PING <nick></B><BR>", | |
1929 WFLAG_NOLOG, NULL, time(NULL), -1); | 1969 WFLAG_NOLOG, NULL, time(NULL), -1); |
1930 } else if (!g_strcasecmp(word[2], "DCC")) { | 1970 } else if (!g_strcasecmp(word[2], "DCC")) { |
1931 write_to_conv(c, "<B>DCC commands:<BR>" | 1971 write_to_conv(c, "<B>DCC commands:<BR>" |
1932 "CHAT <nick></B>", | 1972 "CHAT <nick></B>", |
1933 WFLAG_NOLOG, NULL, time(NULL), -1); | 1973 WFLAG_NOLOG, NULL, time(NULL), -1); |
1935 write_to_conv(c, "<B>Currently supported commands:<BR>" | 1975 write_to_conv(c, "<B>Currently supported commands:<BR>" |
1936 "WHOIS INVITE NICK LIST<BR>" | 1976 "WHOIS INVITE NICK LIST<BR>" |
1937 "JOIN PART TOPIC KICK<BR>" | 1977 "JOIN PART TOPIC KICK<BR>" |
1938 "OP DEOP VOICE DEVOICE<BR>" | 1978 "OP DEOP VOICE DEVOICE<BR>" |
1939 "ME MSG QUOTE SAY QUIT<BR>" | 1979 "ME MSG QUOTE SAY QUIT<BR>" |
1940 "MODE VERSION W WHOWAS</B><BR>" | 1980 "MODE VERSION W WHOWAS<BR>" |
1941 "Type /HELP OPER for operator commands<BR>" | 1981 "Type /HELP OPER for operator commands<BR>" |
1942 "Type /HELP CTCP for CTCP commands<BR>" | 1982 "Type /HELP CTCP for CTCP commands<BR>" |
1943 "Type /HELP DCC for DCC commands", | 1983 "Type /HELP DCC for DCC commands", |
1944 WFLAG_NOLOG, NULL, time(NULL), -1); | 1984 WFLAG_NOLOG, NULL, time(NULL), -1); |
1945 } | 1985 } |
2259 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); | 2299 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); |
2260 } | 2300 } |
2261 | 2301 |
2262 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who) | 2302 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who) |
2263 { | 2303 { |
2264 char buf[200]; | 2304 char buf[IRC_BUF_LEN]; |
2305 | |
2265 snprintf (buf, sizeof buf, "\001CLIENTINFO\001\n"); | 2306 snprintf (buf, sizeof buf, "\001CLIENTINFO\001\n"); |
2266 irc_send_im (gc, who, buf, -1, 0); | 2307 irc_send_privmsg(gc, who, buf); |
2267 } | 2308 } |
2268 | 2309 |
2269 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who) | 2310 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who) |
2270 { | 2311 { |
2271 char buf[200]; | 2312 char buf[IRC_BUF_LEN]; |
2313 | |
2272 snprintf (buf, sizeof buf, "\001USERINFO\001\n"); | 2314 snprintf (buf, sizeof buf, "\001USERINFO\001\n"); |
2273 irc_send_im (gc, who, buf, -1, 0); | 2315 irc_send_privmsg(gc, who, buf); |
2274 } | 2316 } |
2275 | 2317 |
2276 static void irc_ctcp_version(struct gaim_connection *gc, char *who) | 2318 static void irc_ctcp_version(struct gaim_connection *gc, char *who) |
2277 { | 2319 { |
2278 char buf[200]; | 2320 char buf[IRC_BUF_LEN]; |
2321 | |
2279 snprintf (buf, sizeof buf, "\001VERSION\001\n"); | 2322 snprintf (buf, sizeof buf, "\001VERSION\001\n"); |
2280 irc_send_im (gc, who, buf, -1, 0); | 2323 irc_send_privmsg(gc, who, buf); |
2324 } | |
2325 | |
2326 static void irc_ctcp_ping(struct gaim_connection *gc, char *who) | |
2327 { | |
2328 char buf[IRC_BUF_LEN]; | |
2329 | |
2330 g_snprintf (buf, sizeof(buf), "\001PING %ul\001\n", time(NULL)); | |
2331 irc_send_privmsg(gc, who, buf); | |
2332 } | |
2333 | |
2334 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what) | |
2335 { | |
2336 char buf[IRC_BUF_LEN]; | |
2337 struct irc_data *id = gc->proto_data; | |
2338 | |
2339 g_snprintf(buf, sizeof(buf), "NOTICE %s :%s\r\n", who, what); | |
2340 irc_write(id->fd, buf, strlen(buf)); | |
2341 } | |
2342 | |
2343 static void irc_send_privmsg(struct gaim_connection *gc, char *who, char *what) | |
2344 { | |
2345 char buf[IRC_BUF_LEN]; | |
2346 struct irc_data *id = gc->proto_data; | |
2347 | |
2348 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, what); | |
2349 irc_write(id->fd, buf, strlen(buf)); | |
2281 } | 2350 } |
2282 | 2351 |
2283 static void irc_start_chat(struct gaim_connection *gc, char *who) { | 2352 static void irc_start_chat(struct gaim_connection *gc, char *who) { |
2284 struct dcc_chat *chat; | 2353 struct dcc_chat *chat; |
2285 int len; | 2354 int len; |
2286 struct sockaddr_in addr; | 2355 struct sockaddr_in addr; |
2287 char buf[200]; | 2356 char buf[IRC_BUF_LEN]; |
2288 | 2357 |
2289 /* Create a socket */ | 2358 /* Create a socket */ |
2290 chat = g_new0 (struct dcc_chat, 1); | 2359 chat = g_new0 (struct dcc_chat, 1); |
2291 chat->fd = socket (AF_INET, SOCK_STREAM, 0); | 2360 chat->fd = socket (AF_INET, SOCK_STREAM, 0); |
2292 chat->gc = gc; | 2361 chat->gc = gc; |
2363 m = g_list_append(m, pbm); | 2432 m = g_list_append(m, pbm); |
2364 | 2433 |
2365 pbm = g_new0(struct proto_buddy_menu, 1); | 2434 pbm = g_new0(struct proto_buddy_menu, 1); |
2366 pbm->label = _("CTCP Version"); | 2435 pbm->label = _("CTCP Version"); |
2367 pbm->callback = irc_ctcp_version; | 2436 pbm->callback = irc_ctcp_version; |
2437 pbm->gc = gc; | |
2438 m = g_list_append(m, pbm); | |
2439 | |
2440 pbm = g_new0(struct proto_buddy_menu, 1); | |
2441 pbm->label = _("CTCP Ping"); | |
2442 pbm->callback = irc_ctcp_ping; | |
2368 pbm->gc = gc; | 2443 pbm->gc = gc; |
2369 m = g_list_append(m, pbm); | 2444 m = g_list_append(m, pbm); |
2370 | 2445 |
2371 return m; | 2446 return m; |
2372 } | 2447 } |