Mercurial > pidgin
comparison src/protocols/yahoo/yahoo_filexfer.c @ 7710:45fd907e1d48
[gaim-migrate @ 8355]
" It cleaned it up slightly, removing some redundent prpl
specific stuff that the core has a copy of anyway.
Also, I had Simguy make sure I didn't break win32, and
I didn't." --Tim Ringenbach (marv_sf)
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 03 Dec 2003 01:21:49 +0000 |
parents | d9caaddaa56d |
children | 5f0bb52c0609 |
comparison
equal
deleted
inserted
replaced
7709:a1d913ecd0f6 | 7710:45fd907e1d48 |
---|---|
39 gchar *path; | 39 gchar *path; |
40 int port; | 40 int port; |
41 GaimConnection *gc; | 41 GaimConnection *gc; |
42 long expires; | 42 long expires; |
43 gboolean started; | 43 gboolean started; |
44 guint length; | |
45 gchar *rxqueue; | 44 gchar *rxqueue; |
46 guint rxlen; | 45 guint rxlen; |
47 guint bytes_in; | |
48 }; | 46 }; |
49 | 47 |
50 static void yahoo_xfer_data_free(struct yahoo_xfer_data *xd) | 48 static void yahoo_xfer_data_free(struct yahoo_xfer_data *xd) |
51 { | 49 { |
52 if (xd->host) | 50 if (xd->host) |
247 } | 245 } |
248 | 246 |
249 | 247 |
250 size_t yahoo_xfer_read(char **buffer, GaimXfer *xfer) | 248 size_t yahoo_xfer_read(char **buffer, GaimXfer *xfer) |
251 { | 249 { |
252 gchar buf[1024]; | 250 gchar buf[4096]; |
253 ssize_t len; | 251 ssize_t len; |
254 gchar *start = NULL; | 252 gchar *start = NULL; |
255 gchar *length; | 253 gchar *length; |
256 gchar *end; | 254 gchar *end; |
255 int filelen; | |
257 struct yahoo_xfer_data *xd = xfer->data; | 256 struct yahoo_xfer_data *xd = xfer->data; |
258 | 257 |
259 if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { | 258 if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { |
260 return 0; | 259 return 0; |
261 } | 260 } |
262 | 261 |
263 len = read(xfer->fd, buf, sizeof(buf)); | 262 len = read(xfer->fd, buf, sizeof(buf)); |
264 | 263 |
265 if (len <= 0) { | 264 if (len <= 0) { |
266 if (xd->length && (xd->length == xd->bytes_in)) | 265 if ((gaim_xfer_get_size(xfer) > 0) && |
266 (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer))) | |
267 gaim_xfer_set_completed(xfer, TRUE); | 267 gaim_xfer_set_completed(xfer, TRUE); |
268 else | 268 else |
269 gaim_xfer_cancel_remote(xfer); | 269 gaim_xfer_cancel_remote(xfer); |
270 return 0; | 270 return 0; |
271 } | 271 } |
279 length = g_strstr_len(xd->rxqueue, len, "Content-length:"); | 279 length = g_strstr_len(xd->rxqueue, len, "Content-length:"); |
280 if (length) { | 280 if (length) { |
281 end = g_strstr_len(length, length - xd->rxqueue, "\r\n"); | 281 end = g_strstr_len(length, length - xd->rxqueue, "\r\n"); |
282 if (!end) | 282 if (!end) |
283 return 0; | 283 return 0; |
284 if ((xd->length = calculate_length(length, len - (length - xd->rxqueue)))) | 284 if ((filelen = calculate_length(length, len - (length - xd->rxqueue)))) |
285 gaim_xfer_set_size(xfer, xd->length); | 285 gaim_xfer_set_size(xfer, filelen); |
286 } | 286 } |
287 start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); | 287 start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); |
288 if (start) | 288 if (start) |
289 start += 4; | 289 start += 4; |
290 if (!start || start > (xd->rxqueue + len)) | 290 if (!start || start > (xd->rxqueue + len)) |
301 } else { | 301 } else { |
302 *buffer = g_malloc(len); | 302 *buffer = g_malloc(len); |
303 memcpy(*buffer, buf, len); | 303 memcpy(*buffer, buf, len); |
304 } | 304 } |
305 | 305 |
306 xd->bytes_in += len; | |
307 return len; | 306 return len; |
308 } | 307 } |
309 | 308 |
310 size_t yahoo_xfer_write(const char *buffer, size_t size, GaimXfer *xfer) | 309 size_t yahoo_xfer_write(const char *buffer, size_t size, GaimXfer *xfer) |
311 { | 310 { |
312 size_t len; | 311 ssize_t len; |
313 struct yahoo_xfer_data *xd = xfer->data; | 312 struct yahoo_xfer_data *xd = xfer->data; |
314 | 313 |
315 if (!xd) | 314 if (!xd) |
316 return 0; | 315 return 0; |
317 | 316 |
319 return 0; | 318 return 0; |
320 } | 319 } |
321 | 320 |
322 len = write(xfer->fd, buffer, size); | 321 len = write(xfer->fd, buffer, size); |
323 | 322 |
324 xd->bytes_in += len; | 323 if (len == -1) { |
325 if (xd->bytes_in >= gaim_xfer_get_size(xfer)) | 324 if (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer)) |
325 gaim_xfer_set_completed(xfer, TRUE); | |
326 if ((errno != EAGAIN) && (errno != EINTR)) | |
327 gaim_xfer_cancel_remote(xfer); | |
328 return 0; | |
329 } | |
330 | |
331 if ((gaim_xfer_get_bytes_sent(xfer) + len) >= gaim_xfer_get_size(xfer)) | |
326 gaim_xfer_set_completed(xfer, TRUE); | 332 gaim_xfer_set_completed(xfer, TRUE); |
327 | 333 |
328 return len; | 334 return len; |
329 | |
330 } | 335 } |
331 | 336 |
332 static void yahoo_xfer_cancel_send(GaimXfer *xfer) | 337 static void yahoo_xfer_cancel_send(GaimXfer *xfer) |
333 { | 338 { |
334 GaimAccount *account; | 339 GaimAccount *account; |