comparison libpurple/protocols/irc/dcc_send.c @ 32449:b6defcebfe4b

Steps toward hiding PurpleXfer. To convert prpls as they are now, lot of new accessors are needed (for stuff that maybe shouldn't be exposed directly). To convert prpls so that they don't keep re-implementing the same type of stuff, a lot of error-prone changes are needed.
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 29 Aug 2011 22:55:51 +0000
parents 0fbcb00e2731
children cf796628b2c0
comparison
equal deleted inserted replaced
32448:011abe09b264 32449:b6defcebfe4b
32 * Functions related to receiving files via DCC SEND 32 * Functions related to receiving files via DCC SEND
33 ***************************************************************************/ 33 ***************************************************************************/
34 34
35 struct irc_xfer_rx_data { 35 struct irc_xfer_rx_data {
36 gchar *ip; 36 gchar *ip;
37 unsigned int remote_port;
37 }; 38 };
38 39
39 static void irc_dccsend_recv_destroy(PurpleXfer *xfer) 40 static void irc_dccsend_recv_destroy(PurpleXfer *xfer)
40 { 41 {
41 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer); 42 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer);
49 * It sends the acknowledgement (in the form of a total byte count as an 50 * It sends the acknowledgement (in the form of a total byte count as an
50 * unsigned 4 byte integer in network byte order) 51 * unsigned 4 byte integer in network byte order)
51 */ 52 */
52 static void irc_dccsend_recv_ack(PurpleXfer *xfer, const guchar *data, size_t size) { 53 static void irc_dccsend_recv_ack(PurpleXfer *xfer, const guchar *data, size_t size) {
53 guint32 l; 54 guint32 l;
54 size_t result; 55 gssize result;
55 56
56 l = htonl(xfer->bytes_sent); 57 l = htonl(purple_xfer_get_bytes_sent(xfer));
57 result = write(xfer->fd, &l, sizeof(l)); 58 result = purple_xfer_write(xfer, (guchar *)&l, sizeof(l));
58 if (result != sizeof(l)) { 59 if (result != sizeof(l)) {
59 purple_debug_error("irc", "unable to send acknowledgement: %s\n", g_strerror(errno)); 60 purple_debug_error("irc", "unable to send acknowledgement: %s\n", g_strerror(errno));
60 /* TODO: We should probably close the connection here or something. */ 61 /* TODO: We should probably close the connection here or something. */
61 } 62 }
62 } 63 }
63 64
64 static void irc_dccsend_recv_init(PurpleXfer *xfer) { 65 static void irc_dccsend_recv_init(PurpleXfer *xfer) {
65 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer); 66 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer);
66 67
67 purple_xfer_start(xfer, -1, xd->ip, xfer->remote_port); 68 purple_xfer_start(xfer, -1, xd->ip, xd->remote_port);
68 g_free(xd->ip); 69 g_free(xd->ip);
69 xd->ip = NULL; 70 xd->ip = NULL;
70 } 71 }
71 72
72 /* This function makes the necessary arrangements for receiving files */ 73 /* This function makes the necessary arrangements for receiving files */
115 { 116 {
116 xd = g_new0(struct irc_xfer_rx_data, 1); 117 xd = g_new0(struct irc_xfer_rx_data, 1);
117 purple_xfer_set_protocol_data(xfer, xd); 118 purple_xfer_set_protocol_data(xfer, xd);
118 119
119 purple_xfer_set_filename(xfer, filename->str); 120 purple_xfer_set_filename(xfer, filename->str);
120 xfer->remote_port = atoi(token[i+1]); 121 xd->remote_port = atoi(token[i+1]);
121 122
122 nip = strtoul(token[i], NULL, 10); 123 nip = strtoul(token[i], NULL, 10);
123 if (nip) { 124 if (nip) {
124 addr.s_addr = htonl(nip); 125 addr.s_addr = htonl(nip);
125 xd->ip = g_strdup(inet_ntoa(addr)); 126 xd->ip = g_strdup(inet_ntoa(addr));
226 } 227 }
227 228
228 static gssize irc_dccsend_send_write(const guchar *buffer, size_t size, PurpleXfer *xfer) 229 static gssize irc_dccsend_send_write(const guchar *buffer, size_t size, PurpleXfer *xfer)
229 { 230 {
230 gssize s; 231 gssize s;
231 int ret; 232 gssize ret;
232 233
233 s = MIN(purple_xfer_get_bytes_remaining(xfer), size); 234 s = MIN(purple_xfer_get_bytes_remaining(xfer), size);
234 if (!s) 235 if (!s)
235 return 0; 236 return 0;
236 237
237 ret = write(xfer->fd, buffer, s); 238 ret = purple_xfer_write(xfer, buffer, s);
238 239
239 if (ret < 0 && errno == EAGAIN) 240 if (ret < 0 && errno == EAGAIN)
240 ret = 0; 241 ret = 0;
241 242
242 return ret; 243 return ret;
314 /* Monitor the listening socket */ 315 /* Monitor the listening socket */
315 xfer->watcher = purple_input_add(sock, PURPLE_INPUT_READ, 316 xfer->watcher = purple_input_add(sock, PURPLE_INPUT_READ,
316 irc_dccsend_send_connected, xfer); 317 irc_dccsend_send_connected, xfer);
317 318
318 /* Send the intended recipient the DCC request */ 319 /* Send the intended recipient the DCC request */
319 arg[0] = xfer->who; 320 arg[0] = purple_xfer_get_remote_user(xfer);
320 inet_aton(purple_network_get_my_ip(irc->fd), &addr); 321 inet_aton(purple_network_get_my_ip(irc->fd), &addr);
321 arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %" G_GSIZE_FORMAT "\001", 322 arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %" G_GSIZE_FORMAT "\001",
322 xfer->filename, ntohl(addr.s_addr), 323 purple_xfer_get_filename(xfer), ntohl(addr.s_addr),
323 port, xfer->size); 324 port, purple_xfer_get_size(xfer));
324 325
325 irc_cmd_privmsg(gc->proto_data, "msg", NULL, arg); 326 irc_cmd_privmsg(gc->proto_data, "msg", NULL, arg);
326 g_free(tmp); 327 g_free(tmp);
327 } 328 }
328 329
331 */ 332 */
332 static void irc_dccsend_send_init(PurpleXfer *xfer) { 333 static void irc_dccsend_send_init(PurpleXfer *xfer) {
333 PurpleConnection *gc = purple_account_get_connection(purple_xfer_get_account(xfer)); 334 PurpleConnection *gc = purple_account_get_connection(purple_xfer_get_account(xfer));
334 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer); 335 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
335 336
336 xfer->filename = g_path_get_basename(xfer->local_filename); 337 purple_xfer_set_filename(xfer, g_path_get_basename(purple_xfer_get_local_filename(xfer)));
337 338
338 purple_xfer_ref(xfer); 339 purple_xfer_ref(xfer);
339 340
340 /* Create a listening socket */ 341 /* Create a listening socket */
341 xd->listen_data = purple_network_listen_range(0, 0, SOCK_STREAM, 342 xd->listen_data = purple_network_listen_range(0, 0, SOCK_STREAM,