Mercurial > pidgin
comparison src/protocols/irc/irc.c @ 3630:9682c0e022c6
[gaim-migrate @ 3753]
Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk.
committer: Tailor Script <tailor@pidgin.im>
| author | Rob Flynn <gaim@robflynn.com> |
|---|---|
| date | Fri, 11 Oct 2002 03:14:01 +0000 |
| parents | 159f624c617d |
| children | c084394b86de |
comparison
equal
deleted
inserted
replaced
| 3629:afc5bb164c5a | 3630:9682c0e022c6 |
|---|---|
| 23 * | 23 * |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include <config.h> | 26 #include <config.h> |
| 27 | 27 |
| 28 #ifndef _WIN32 | |
| 29 #include <unistd.h> | |
| 30 #else | |
| 31 #include <winsock.h> | |
| 32 #endif | |
| 33 | |
| 28 #include <fcntl.h> | 34 #include <fcntl.h> |
| 29 #include <unistd.h> | |
| 30 #include <errno.h> | 35 #include <errno.h> |
| 31 #include <string.h> | 36 #include <string.h> |
| 32 #include <stdlib.h> | 37 #include <stdlib.h> |
| 33 #include <stdio.h> | 38 #include <stdio.h> |
| 34 #include <time.h> | 39 #include <time.h> |
| 37 #include "multi.h" | 42 #include "multi.h" |
| 38 #include "prpl.h" | 43 #include "prpl.h" |
| 39 #include "gaim.h" | 44 #include "gaim.h" |
| 40 #include "proxy.h" | 45 #include "proxy.h" |
| 41 | 46 |
| 47 #ifdef _WIN32 | |
| 48 #include "win32dep.h" | |
| 49 #endif | |
| 50 | |
| 42 #include "pixmaps/protocols/irc/irc_icon.xpm" | 51 #include "pixmaps/protocols/irc/irc_icon.xpm" |
| 43 | 52 |
| 44 #define IRC_BUF_LEN 4096 | 53 #define IRC_BUF_LEN 4096 |
| 45 #define PDIWORDS 32 | 54 #define PDIWORDS 32 |
| 46 | 55 |
| 47 #define USEROPT_SERV 0 | 56 #define USEROPT_SERV 0 |
| 48 #define USEROPT_PORT 1 | 57 #define USEROPT_PORT 1 |
| 58 | |
| 59 /* for win32 compatability */ | |
| 60 G_MODULE_IMPORT GSList *connections; | |
| 61 | |
| 49 | 62 |
| 50 struct dcc_chat | 63 struct dcc_chat |
| 51 { | 64 { |
| 52 struct gaim_connection *gc; | 65 struct gaim_connection *gc; |
| 53 char ip_address[12]; | 66 char ip_address[12]; |
| 62 struct file_transfer *xfer; | 75 struct file_transfer *xfer; |
| 63 char *sn; | 76 char *sn; |
| 64 char *name; | 77 char *name; |
| 65 int len; | 78 int len; |
| 66 int watcher; | 79 int watcher; |
| 80 int awatcher; | |
| 67 char ip[12]; | 81 char ip[12]; |
| 68 int port; | 82 int port; |
| 69 int fd; | 83 int fd; |
| 70 int cur; | 84 int cur; |
| 71 struct gaim_connection *gc; | 85 struct gaim_connection *gc; |
| 117 } | 131 } |
| 118 | 132 |
| 119 static int irc_write(int fd, char *data, int len) | 133 static int irc_write(int fd, char *data, int len) |
| 120 { | 134 { |
| 121 debug_printf("IRC C: %s", data); | 135 debug_printf("IRC C: %s", data); |
| 136 #ifndef _WIN32 | |
| 122 return write(fd, data, len); | 137 return write(fd, data, len); |
| 138 #else | |
| 139 return send(fd, data, len, 0); | |
| 140 #endif | |
| 123 } | 141 } |
| 124 | 142 |
| 125 static struct conversation *irc_find_chat(struct gaim_connection *gc, char *name) | 143 static struct conversation *irc_find_chat(struct gaim_connection *gc, char *name) |
| 126 { | 144 { |
| 127 GSList *bcs = gc->buddy_chats; | 145 GSList *bcs = gc->buddy_chats; |
| 433 gchar buffer[IRC_BUF_LEN]; | 451 gchar buffer[IRC_BUF_LEN]; |
| 434 gchar buf[128]; | 452 gchar buf[128]; |
| 435 int n = 0, l; | 453 int n = 0, l; |
| 436 struct conversation *convo; | 454 struct conversation *convo; |
| 437 debug_printf("THIS IS TOO MUCH EFFORT\n"); | 455 debug_printf("THIS IS TOO MUCH EFFORT\n"); |
| 456 #ifndef _WIN32 | |
| 438 n = read (chat->fd, buffer, IRC_BUF_LEN); | 457 n = read (chat->fd, buffer, IRC_BUF_LEN); |
| 458 #else | |
| 459 n = recv (chat->fd, buffer, IRC_BUF_LEN, 0); | |
| 460 #endif | |
| 439 if (n > 0) | 461 if (n > 0) |
| 440 { | 462 { |
| 441 | 463 |
| 442 /* Strip the terminating \n */ | 464 /* Strip the terminating \n */ |
| 443 l = 0; | 465 l = 0; |
| 459 dcc_chat_cancel (NULL,chat); | 481 dcc_chat_cancel (NULL,chat); |
| 460 } | 482 } |
| 461 } | 483 } |
| 462 | 484 |
| 463 static void irc_file_transfer_do(struct gaim_connection *gc, struct irc_file_transfer *ift) { | 485 static void irc_file_transfer_do(struct gaim_connection *gc, struct irc_file_transfer *ift) { |
| 464 struct irc_data *id = (struct irc_data *)gc->proto_data; | |
| 465 | |
| 466 /* Ok, we better be receiving some crap here boyeee */ | 486 /* Ok, we better be receiving some crap here boyeee */ |
| 467 if (transfer_in_do(ift->xfer, ift->fd, ift->name, ift->len)) { | 487 if (transfer_in_do(ift->xfer, ift->fd, ift->name, ift->len)) { |
| 468 gaim_input_remove(ift->watcher); | 488 gaim_input_remove(ift->watcher); |
| 469 ift->watcher = 0; | 489 ift->watcher = 0; |
| 470 } | 490 } |
| 471 } | 491 } |
| 472 | 492 |
| 493 | |
| 494 void irc_read_dcc_ack (gpointer data, gint source, GaimInputCondition condition) { | |
| 495 struct irc_file_transfer *ift = data; | |
| 496 struct irc_data *id = (struct irc_data *)ift->gc->proto_data; | |
| 497 int len; | |
| 498 guint32 ack; | |
| 499 | |
| 500 printf("I got here.\n"); | |
| 501 len = recv(source, (char *)&ack, 4, MSG_PEEK); | |
| 502 printf("Len is: %d\n", len); | |
| 503 printf("Ack is: %d\n", ack); | |
| 504 recv(source, (char *)&ack, 4, 0); | |
| 505 } | |
| 473 | 506 |
| 474 void dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) { | 507 void dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) { |
| 475 struct irc_file_transfer *ift = data; | 508 struct irc_file_transfer *ift = data; |
| 476 struct irc_data *id = (struct irc_data *)ift->gc->proto_data; | 509 struct irc_data *id = (struct irc_data *)ift->gc->proto_data; |
| 477 struct sockaddr_in addr; | 510 struct sockaddr_in addr; |
| 485 if (!ift->fd) { | 518 if (!ift->fd) { |
| 486 /* FIXME: Handle this gracefully XXX */ | 519 /* FIXME: Handle this gracefully XXX */ |
| 487 printf("Something bad happened here, bubba!"); | 520 printf("Something bad happened here, bubba!"); |
| 488 return; | 521 return; |
| 489 } | 522 } |
| 523 | |
| 524 // ift->awatcher = gaim_input_add(ift->fd, GAIM_INPUT_READ, irc_read_dcc_ack, ift); | |
| 490 | 525 |
| 491 if (transfer_out_do(ift->xfer, ift->fd, 0)) { | 526 if (transfer_out_do(ift->xfer, ift->fd, 0)) { |
| 492 gaim_input_remove(ift->watcher); | 527 gaim_input_remove(ift->watcher); |
| 493 ift->watcher = 0; | 528 ift->watcher = 0; |
| 494 } | 529 } |
| 1321 struct irc_data *idata = gc->proto_data; | 1356 struct irc_data *idata = gc->proto_data; |
| 1322 int i = 0; | 1357 int i = 0; |
| 1323 gchar buf[1024]; | 1358 gchar buf[1024]; |
| 1324 gboolean off; | 1359 gboolean off; |
| 1325 | 1360 |
| 1361 #ifndef _WIN32 | |
| 1326 i = read(idata->fd, buf, 1024); | 1362 i = read(idata->fd, buf, 1024); |
| 1363 #else | |
| 1364 i = recv(idata->fd, buf, 1024, 0); | |
| 1365 #endif | |
| 1327 if (i <= 0) { | 1366 if (i <= 0) { |
| 1328 hide_login_progress_error(gc, "Read error"); | 1367 hide_login_progress_error(gc, "Read error"); |
| 1329 signoff(gc); | 1368 signoff(gc); |
| 1330 return; | 1369 return; |
| 1331 } | 1370 } |
| 1372 struct irc_data *idata; | 1411 struct irc_data *idata; |
| 1373 char hostname[256]; | 1412 char hostname[256]; |
| 1374 char buf[IRC_BUF_LEN]; | 1413 char buf[IRC_BUF_LEN]; |
| 1375 | 1414 |
| 1376 if (!g_slist_find(connections, gc)) { | 1415 if (!g_slist_find(connections, gc)) { |
| 1416 #ifndef _WIN32 | |
| 1377 close(source); | 1417 close(source); |
| 1418 #else | |
| 1419 closesocket(source); | |
| 1420 #endif | |
| 1378 return; | 1421 return; |
| 1379 } | 1422 } |
| 1380 | 1423 |
| 1381 idata = gc->proto_data; | 1424 idata = gc->proto_data; |
| 1382 | 1425 |
| 1488 g_source_remove(idata->timer); | 1531 g_source_remove(idata->timer); |
| 1489 | 1532 |
| 1490 if (gc->inpa) | 1533 if (gc->inpa) |
| 1491 gaim_input_remove(gc->inpa); | 1534 gaim_input_remove(gc->inpa); |
| 1492 | 1535 |
| 1536 #ifndef _WIN32 | |
| 1493 close(idata->fd); | 1537 close(idata->fd); |
| 1538 #else | |
| 1539 closesocket(idata->fd); | |
| 1540 #endif | |
| 1494 g_free(gc->proto_data); | 1541 g_free(gc->proto_data); |
| 1495 } | 1542 } |
| 1496 | 1543 |
| 1497 static void set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode, | 1544 static void set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode, |
| 1498 int start, int end, char *word[]) | 1545 int start, int end, char *word[]) |
| 2009 id->file_transfers = g_slist_append(id->file_transfers, ift); | 2056 id->file_transfers = g_slist_append(id->file_transfers, ift); |
| 2010 | 2057 |
| 2011 ift->xfer = transfer_out_add(gc, ift->sn); | 2058 ift->xfer = transfer_out_add(gc, ift->sn); |
| 2012 } | 2059 } |
| 2013 | 2060 |
| 2014 | |
| 2015 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, | 2061 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, |
| 2016 struct file_transfer *xfer) { | 2062 struct file_transfer *xfer) { |
| 2017 | 2063 |
| 2018 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers; | 2064 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers; |
| 2019 struct irc_file_transfer *f = NULL; | 2065 struct irc_file_transfer *f = NULL; |
| 2028 | 2074 |
| 2029 return f; | 2075 return f; |
| 2030 } | 2076 } |
| 2031 | 2077 |
| 2032 static void irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) { | 2078 static void irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) { |
| 2033 struct irc_data *id = (struct irc_data *)gc->proto_data; | |
| 2034 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | 2079 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
| 2035 guint32 pos; | 2080 guint32 pos; |
| 2036 | 2081 |
| 2037 ift->cur += len; | 2082 ift->cur += len; |
| 2038 pos = htonl(ift->cur); | 2083 pos = htonl(ift->cur); |
| 2111 } | 2156 } |
| 2112 | 2157 |
| 2113 static void irc_file_transfer_in(struct gaim_connection *gc, | 2158 static void irc_file_transfer_in(struct gaim_connection *gc, |
| 2114 struct file_transfer *xfer, int offset) { | 2159 struct file_transfer *xfer, int offset) { |
| 2115 | 2160 |
| 2116 struct irc_data *id = (struct irc_data *)gc->proto_data; | |
| 2117 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | 2161 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
| 2118 struct sockaddr_in addr; | |
| 2119 char *ip = (char *)malloc(32); | |
| 2120 | 2162 |
| 2121 ift->xfer = xfer; | 2163 ift->xfer = xfer; |
| 2122 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); | 2164 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); |
| 2123 } | 2165 } |
| 2124 | 2166 |
| 2147 chat->port = ntohs (addr.sin_port); | 2189 chat->port = ntohs (addr.sin_port); |
| 2148 getlocalip(chat->ip_address); | 2190 getlocalip(chat->ip_address); |
| 2149 chat->inpa = | 2191 chat->inpa = |
| 2150 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected, | 2192 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected, |
| 2151 chat); | 2193 chat); |
| 2152 snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n", | 2194 g_snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n", |
| 2153 chat->ip_address, chat->port); | 2195 chat->ip_address, chat->port); |
| 2154 irc_send_im (gc, who, buf, -1, 0); | 2196 irc_send_im (gc, who, buf, -1, 0); |
| 2155 } | 2197 } |
| 2156 | 2198 |
| 2157 static void irc_get_info(struct gaim_connection *gc, char *who) | 2199 static void irc_get_info(struct gaim_connection *gc, char *who) |
| 2194 return m; | 2236 return m; |
| 2195 } | 2237 } |
| 2196 | 2238 |
| 2197 static struct prpl *my_protocol = NULL; | 2239 static struct prpl *my_protocol = NULL; |
| 2198 | 2240 |
| 2199 void irc_init(struct prpl *ret) | 2241 G_MODULE_EXPORT void irc_init(struct prpl *ret) |
| 2200 { | 2242 { |
| 2201 struct proto_user_opt *puo; | 2243 struct proto_user_opt *puo; |
| 2202 ret->protocol = PROTO_IRC; | 2244 ret->protocol = PROTO_IRC; |
| 2203 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD; | 2245 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD; |
| 2204 ret->name = g_strdup("IRC"); | 2246 ret->name = g_strdup("IRC"); |
| 2238 | 2280 |
| 2239 my_protocol = ret; | 2281 my_protocol = ret; |
| 2240 } | 2282 } |
| 2241 | 2283 |
| 2242 #ifndef STATIC | 2284 #ifndef STATIC |
| 2243 | 2285 G_MODULE_EXPORT void gaim_prpl_init(struct prpl* prpl) |
| 2244 void *gaim_prpl_init(struct prpl* prpl) | |
| 2245 { | 2286 { |
| 2246 irc_init(prpl); | 2287 irc_init(prpl); |
| 2247 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | 2288 prpl->plug->desc.api_version = PLUGIN_API_VERSION; |
| 2248 } | 2289 } |
| 2249 | 2290 |
