comparison libpurple/protocols/irc/dcc_send.c @ 31961:0fbcb00e2731

Convert the irc prpl to use the new API.
author andrew.victor@mxit.com
date Fri, 26 Aug 2011 18:25:12 +0000
parents a8cc50c2279f
children b6defcebfe4b
comparison
equal deleted inserted replaced
31960:0a166ca06445 31961:0fbcb00e2731
36 gchar *ip; 36 gchar *ip;
37 }; 37 };
38 38
39 static void irc_dccsend_recv_destroy(PurpleXfer *xfer) 39 static void irc_dccsend_recv_destroy(PurpleXfer *xfer)
40 { 40 {
41 struct irc_xfer_rx_data *xd = xfer->data; 41 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer);
42 42
43 g_free(xd->ip); 43 g_free(xd->ip);
44 g_free(xd); 44 g_free(xd);
45 } 45 }
46 46
60 /* TODO: We should probably close the connection here or something. */ 60 /* TODO: We should probably close the connection here or something. */
61 } 61 }
62 } 62 }
63 63
64 static void irc_dccsend_recv_init(PurpleXfer *xfer) { 64 static void irc_dccsend_recv_init(PurpleXfer *xfer) {
65 struct irc_xfer_rx_data *xd = xfer->data; 65 struct irc_xfer_rx_data *xd = purple_xfer_get_protocol_data(xfer);
66 66
67 purple_xfer_start(xfer, -1, xd->ip, xfer->remote_port); 67 purple_xfer_start(xfer, -1, xd->ip, xfer->remote_port);
68 g_free(xd->ip); 68 g_free(xd->ip);
69 xd->ip = NULL; 69 xd->ip = NULL;
70 } 70 }
112 112
113 xfer = purple_xfer_new(irc->account, PURPLE_XFER_RECEIVE, from); 113 xfer = purple_xfer_new(irc->account, PURPLE_XFER_RECEIVE, from);
114 if (xfer) 114 if (xfer)
115 { 115 {
116 xd = g_new0(struct irc_xfer_rx_data, 1); 116 xd = g_new0(struct irc_xfer_rx_data, 1);
117 xfer->data = xd; 117 purple_xfer_set_protocol_data(xfer, xd);
118 118
119 purple_xfer_set_filename(xfer, filename->str); 119 purple_xfer_set_filename(xfer, filename->str);
120 xfer->remote_port = atoi(token[i+1]); 120 xfer->remote_port = atoi(token[i+1]);
121 121
122 nip = strtoul(token[i], NULL, 10); 122 nip = strtoul(token[i], NULL, 10);
155 guint rxlen; 155 guint rxlen;
156 }; 156 };
157 157
158 static void irc_dccsend_send_destroy(PurpleXfer *xfer) 158 static void irc_dccsend_send_destroy(PurpleXfer *xfer)
159 { 159 {
160 struct irc_xfer_send_data *xd = xfer->data; 160 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
161 161
162 if (xd == NULL) 162 if (xd == NULL)
163 return; 163 return;
164 164
165 if (xd->listen_data != NULL) 165 if (xd->listen_data != NULL)
176 176
177 /* just in case you were wondering, this is why DCC is gay */ 177 /* just in case you were wondering, this is why DCC is gay */
178 static void irc_dccsend_send_read(gpointer data, int source, PurpleInputCondition cond) 178 static void irc_dccsend_send_read(gpointer data, int source, PurpleInputCondition cond)
179 { 179 {
180 PurpleXfer *xfer = data; 180 PurpleXfer *xfer = data;
181 struct irc_xfer_send_data *xd = xfer->data; 181 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
182 char buffer[64]; 182 char buffer[64];
183 int len; 183 int len;
184 184
185 len = read(source, buffer, sizeof(buffer)); 185 len = read(source, buffer, sizeof(buffer));
186 186
242 return ret; 242 return ret;
243 } 243 }
244 244
245 static void irc_dccsend_send_connected(gpointer data, int source, PurpleInputCondition cond) { 245 static void irc_dccsend_send_connected(gpointer data, int source, PurpleInputCondition cond) {
246 PurpleXfer *xfer = (PurpleXfer *) data; 246 PurpleXfer *xfer = (PurpleXfer *) data;
247 struct irc_xfer_send_data *xd = xfer->data; 247 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
248 int conn, flags; 248 int conn, flags;
249 249
250 conn = accept(xd->fd, NULL, 0); 250 conn = accept(xd->fd, NULL, 0);
251 if (conn == -1) { 251 if (conn == -1) {
252 /* Accepting the connection failed. This could just be related 252 /* Accepting the connection failed. This could just be related
283 const char *arg[2]; 283 const char *arg[2];
284 char *tmp; 284 char *tmp;
285 struct in_addr addr; 285 struct in_addr addr;
286 unsigned short int port; 286 unsigned short int port;
287 287
288 xd = xfer->data; 288 xd = purple_xfer_get_protocol_data(xfer);
289 xd->listen_data = NULL; 289 xd->listen_data = NULL;
290 290
291 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL 291 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL
292 || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) { 292 || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) {
293 purple_xfer_unref(xfer); 293 purple_xfer_unref(xfer);
294 return; 294 return;
295 } 295 }
296 296
297 xd = xfer->data; 297 xd = purple_xfer_get_protocol_data(xfer);
298 gc = purple_account_get_connection(purple_xfer_get_account(xfer)); 298 gc = purple_account_get_connection(purple_xfer_get_account(xfer));
299 irc = gc->proto_data; 299 irc = gc->proto_data;
300 300
301 purple_xfer_unref(xfer); 301 purple_xfer_unref(xfer);
302 302
329 /* 329 /*
330 * This function is called after the user has selected a file to send. 330 * This function is called after the user has selected a file to send.
331 */ 331 */
332 static void irc_dccsend_send_init(PurpleXfer *xfer) { 332 static void irc_dccsend_send_init(PurpleXfer *xfer) {
333 PurpleConnection *gc = purple_account_get_connection(purple_xfer_get_account(xfer)); 333 PurpleConnection *gc = purple_account_get_connection(purple_xfer_get_account(xfer));
334 struct irc_xfer_send_data *xd = xfer->data; 334 struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
335 335
336 xfer->filename = g_path_get_basename(xfer->local_filename); 336 xfer->filename = g_path_get_basename(xfer->local_filename);
337 337
338 purple_xfer_ref(xfer); 338 purple_xfer_ref(xfer);
339 339
357 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, who); 357 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, who);
358 if (xfer) 358 if (xfer)
359 { 359 {
360 xd = g_new0(struct irc_xfer_send_data, 1); 360 xd = g_new0(struct irc_xfer_send_data, 1);
361 xd->fd = -1; 361 xd->fd = -1;
362 xfer->data = xd; 362 purple_xfer_set_protocol_data(xfer, xd);
363 363
364 /* Setup our I/O op functions */ 364 /* Setup our I/O op functions */
365 purple_xfer_set_init_fnc(xfer, irc_dccsend_send_init); 365 purple_xfer_set_init_fnc(xfer, irc_dccsend_send_init);
366 purple_xfer_set_write_fnc(xfer, irc_dccsend_send_write); 366 purple_xfer_set_write_fnc(xfer, irc_dccsend_send_write);
367 purple_xfer_set_end_fnc(xfer, irc_dccsend_send_destroy); 367 purple_xfer_set_end_fnc(xfer, irc_dccsend_send_destroy);