Mercurial > pidgin.yaz
comparison src/protocols/irc/irc.c @ 3622:2ef75915a13c
[gaim-migrate @ 3743]
I haven't tested this thoroughly, but neither does Sean before he commits his code.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 10 Oct 2002 06:54:08 +0000 |
parents | a19850d6e718 |
children | 159f624c617d |
comparison
equal
deleted
inserted
replaced
3621:e9f66d245253 | 3622:2ef75915a13c |
---|---|
469 ift->watcher = 0; | 469 ift->watcher = 0; |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 | 473 |
474 void dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) { | |
475 struct irc_file_transfer *ift = data; | |
476 struct irc_data *id = (struct irc_data *)ift->gc->proto_data; | |
477 struct sockaddr_in addr; | |
478 int len = sizeof(addr); | |
479 | |
480 addr.sin_family = AF_INET; | |
481 addr.sin_port = htons(ift->port); | |
482 addr.sin_addr.s_addr = INADDR_ANY; | |
483 | |
484 ift->fd = accept(ift->fd, (struct sockaddr *)&addr, &len); | |
485 if (!ift->fd) { | |
486 /* FIXME: Handle this gracefully XXX */ | |
487 printf("Something bad happened here, bubba!"); | |
488 return; | |
489 } | |
490 | |
491 if (transfer_out_do(ift->xfer, ift->fd, 0)) { | |
492 gaim_input_remove(ift->watcher); | |
493 ift->watcher = 0; | |
494 } | |
495 } | |
496 | |
474 void dcc_recv_callback (gpointer data, gint source, GaimInputCondition condition) { | 497 void dcc_recv_callback (gpointer data, gint source, GaimInputCondition condition) { |
475 struct irc_file_transfer *ift = data; | 498 struct irc_file_transfer *ift = data; |
476 | 499 |
477 ift->fd = source; | 500 ift->fd = source; |
478 | |
479 printf("WELL, we should be doing something then, should we not?\n"); | |
480 | |
481 irc_file_transfer_do(ift->gc, ift); | 501 irc_file_transfer_do(ift->gc, ift); |
482 } | 502 } |
483 | 503 |
484 void dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { | 504 void dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { |
485 struct dcc_chat *chat = data; | 505 struct dcc_chat *chat = data; |
1973 } | 1993 } |
1974 | 1994 |
1975 static void irc_ask_send_file(struct gaim_connection *gc, char *destsn) { | 1995 static void irc_ask_send_file(struct gaim_connection *gc, char *destsn) { |
1976 struct irc_data *id = (struct irc_data *)gc->proto_data; | 1996 struct irc_data *id = (struct irc_data *)gc->proto_data; |
1977 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); | 1997 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); |
1998 char *localip = (char *)malloc(12); | |
1999 | |
2000 if (getlocalip(localip) == -1) { | |
2001 free(localip); | |
2002 return; | |
2003 } | |
1978 | 2004 |
1979 ift->type = IFT_SENDFILE_OUT; | 2005 ift->type = IFT_SENDFILE_OUT; |
1980 ift->sn = g_strdup(destsn); | 2006 ift->sn = g_strdup(destsn); |
1981 ift->gc = gc; | 2007 ift->gc = gc; |
2008 snprintf(ift->ip, sizeof(ift->ip), "%s", localip); | |
1982 id->file_transfers = g_slist_append(id->file_transfers, ift); | 2009 id->file_transfers = g_slist_append(id->file_transfers, ift); |
2010 | |
1983 ift->xfer = transfer_out_add(gc, ift->sn); | 2011 ift->xfer = transfer_out_add(gc, ift->sn); |
1984 } | 2012 } |
1985 | 2013 |
1986 | 2014 |
1987 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, | 2015 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, |
2008 | 2036 |
2009 ift->cur += len; | 2037 ift->cur += len; |
2010 pos = htonl(ift->cur); | 2038 pos = htonl(ift->cur); |
2011 write(ift->fd, (char *)&pos, 4); | 2039 write(ift->fd, (char *)&pos, 4); |
2012 | 2040 |
2013 printf("Cheap-O Progress Bar (%s) %d of %d: %2.0f\%\n", ift->name, ift->cur, ift->len, ((float)ift->cur/(float)ift->len) * 100); | 2041 // printf("Cheap-O Progress Bar (%s) %d of %d: %2.0f\%\n", ift->name, ift->cur, ift->len, ((float)ift->cur/(float)ift->len) * 100); |
2014 } | 2042 } |
2015 | 2043 |
2016 static void irc_file_transfer_cancel (struct gaim_connection *gc, struct file_transfer *xfer) { | 2044 static void irc_file_transfer_cancel (struct gaim_connection *gc, struct file_transfer *xfer) { |
2017 struct irc_data *id = (struct irc_data *)gc->proto_data; | 2045 struct irc_data *id = (struct irc_data *)gc->proto_data; |
2018 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | 2046 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
2052 g_free(ift->name); | 2080 g_free(ift->name); |
2053 | 2081 |
2054 g_free(ift); | 2082 g_free(ift); |
2055 } | 2083 } |
2056 | 2084 |
2085 static void irc_file_transfer_out (struct gaim_connection *gc, struct file_transfer *xfer, const char *name, int totfiles, int totsize) { | |
2086 struct irc_data *id = (struct irc_data *)gc->proto_data; | |
2087 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | |
2088 struct sockaddr_in addr; | |
2089 char buf[IRC_BUF_LEN]; | |
2090 int len; | |
2091 | |
2092 | |
2093 ift->fd = socket (AF_INET, SOCK_STREAM, 0); | |
2094 addr.sin_family = AF_INET; | |
2095 addr.sin_port = 0; | |
2096 addr.sin_addr.s_addr = INADDR_ANY; | |
2097 bind (ift->fd, (struct sockaddr *) &addr, sizeof(addr)); | |
2098 listen(ift->fd, 1); | |
2099 | |
2100 len = sizeof(addr); | |
2101 getsockname (ift->fd, (struct sockaddr *) &addr, &len); | |
2102 | |
2103 ift->port = ntohs(addr.sin_port); | |
2104 | |
2105 ift->watcher = gaim_input_add (ift->fd, GAIM_INPUT_READ, dcc_send_callback, ift); | |
2106 | |
2107 snprintf(buf, sizeof(buf), "\001DCC SEND %s %s %d %d\001\n", name, ift->ip, ift->port, totsize); | |
2108 printf("Trying: %s\n", buf); | |
2109 irc_send_im (gc, ift->sn, buf, -1, 0); | |
2110 } | |
2111 | |
2057 static void irc_file_transfer_in(struct gaim_connection *gc, | 2112 static void irc_file_transfer_in(struct gaim_connection *gc, |
2058 struct file_transfer *xfer, int offset) { | 2113 struct file_transfer *xfer, int offset) { |
2059 | 2114 |
2060 struct irc_data *id = (struct irc_data *)gc->proto_data; | 2115 struct irc_data *id = (struct irc_data *)gc->proto_data; |
2061 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | 2116 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
2062 struct sockaddr_in addr; | 2117 struct sockaddr_in addr; |
2063 char *ip = (char *)malloc(32); | 2118 char *ip = (char *)malloc(32); |
2064 | 2119 |
2065 ift->xfer = xfer; | 2120 ift->xfer = xfer; |
2066 printf("You, I should be getting a file or some shit, hehe\n"); | |
2067 printf("Connecting to: %s %d\n", ift->ip, ift->port); | |
2068 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); | 2121 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); |
2069 } | 2122 } |
2070 | 2123 |
2071 static void irc_start_chat(struct gaim_connection *gc, char *who) { | 2124 static void irc_start_chat(struct gaim_connection *gc, char *who) { |
2072 struct dcc_chat *chat; | 2125 struct dcc_chat *chat; |
2129 pbm->label = _("DCC Chat"); | 2182 pbm->label = _("DCC Chat"); |
2130 pbm->callback = irc_start_chat; | 2183 pbm->callback = irc_start_chat; |
2131 pbm->gc = gc; | 2184 pbm->gc = gc; |
2132 m = g_list_append(m, pbm); | 2185 m = g_list_append(m, pbm); |
2133 | 2186 |
2134 /* | |
2135 pbm = g_new0(struct proto_buddy_menu, 1); | 2187 pbm = g_new0(struct proto_buddy_menu, 1); |
2136 pbm->label = _("DCC Send"); | 2188 pbm->label = _("DCC Send"); |
2137 pbm->callback = irc_ask_send_file; | 2189 pbm->callback = irc_ask_send_file; |
2138 pbm->gc = gc; | 2190 pbm->gc = gc; |
2139 m = g_list_append(m, pbm); | 2191 m = g_list_append(m, pbm); |
2140 */ | |
2141 | 2192 |
2142 return m; | 2193 return m; |
2143 } | 2194 } |
2144 | 2195 |
2145 static struct prpl *my_protocol = NULL; | 2196 static struct prpl *my_protocol = NULL; |
2164 ret->set_away = irc_set_away; | 2215 ret->set_away = irc_set_away; |
2165 ret->get_info = irc_get_info; | 2216 ret->get_info = irc_get_info; |
2166 ret->buddy_menu = irc_buddy_menu; | 2217 ret->buddy_menu = irc_buddy_menu; |
2167 ret->chat_invite = irc_chat_invite; | 2218 ret->chat_invite = irc_chat_invite; |
2168 ret->convo_closed = irc_convo_closed; | 2219 ret->convo_closed = irc_convo_closed; |
2169 ret->file_transfer_out = NULL; /* Implement me */ | 2220 ret->file_transfer_out = irc_file_transfer_out; |
2170 ret->file_transfer_in = irc_file_transfer_in; | 2221 ret->file_transfer_in = irc_file_transfer_in; |
2171 ret->file_transfer_data_chunk = irc_file_transfer_data_chunk; | 2222 ret->file_transfer_data_chunk = irc_file_transfer_data_chunk; |
2172 ret->file_transfer_done = irc_file_transfer_done; | 2223 ret->file_transfer_done = irc_file_transfer_done; |
2173 ret->file_transfer_cancel =irc_file_transfer_cancel; | 2224 ret->file_transfer_cancel =irc_file_transfer_cancel; |
2174 | 2225 |