comparison libpurple/ft.c @ 29832:2ab17571bf42

propagate from branch 'im.pidgin.pidgin' (head 7850267e7626c94b519fd5f1c959c79f0624d34e) to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head 3845c5c2ec11e409fd1891793e73ab3d934001f9)
author Marcus Lundblad <ml@update.uu.se>
date Sat, 24 Apr 2010 14:59:13 +0000
parents 6671b5e92c28 6797736dbe37
children 834038426c38
comparison
equal deleted inserted replaced
29831:816041183dda 29832:2ab17571bf42
55 enum { 55 enum {
56 PURPLE_XFER_READY_NONE = 0x0, 56 PURPLE_XFER_READY_NONE = 0x0,
57 PURPLE_XFER_READY_UI = 0x1, 57 PURPLE_XFER_READY_UI = 0x1,
58 PURPLE_XFER_READY_PRPL = 0x2, 58 PURPLE_XFER_READY_PRPL = 0x2,
59 } ready; 59 } ready;
60
61 /* TODO: Should really use a PurpleCircBuffer for this. */
60 GByteArray *buffer; 62 GByteArray *buffer;
61 63
62 gpointer thumbnail_data; /**< thumbnail image */ 64 gpointer thumbnail_data; /**< thumbnail image */
63 gsize thumbnail_size; 65 gsize thumbnail_size;
64 gchar *thumbnail_mimetype; 66 gchar *thumbnail_mimetype;
1197 } 1199 }
1198 } 1200 }
1199 } 1201 }
1200 1202
1201 if (priv->buffer) { 1203 if (priv->buffer) {
1202 priv->buffer = g_byte_array_append(priv->buffer, buffer, result); 1204 g_byte_array_append(priv->buffer, buffer, result);
1203 g_free(buffer); 1205 g_free(buffer);
1204 buffer = priv->buffer->data; 1206 buffer = priv->buffer->data;
1205 result = priv->buffer->len; 1207 result = priv->buffer->len;
1206 } 1208 }
1207 1209
1208 r = purple_xfer_write(xfer, buffer, result); 1210 r = purple_xfer_write(xfer, buffer, result);
1209 1211
1210 if (r == -1) { 1212 if (r == -1) {
1211 purple_xfer_cancel_remote(xfer); 1213 purple_xfer_cancel_remote(xfer);
1212 g_free(buffer); 1214 if (!priv->buffer)
1215 /* We don't free buffer if priv->buffer is set, because in
1216 that case buffer doesn't belong to us. */
1217 g_free(buffer);
1213 return; 1218 return;
1214 } else if (r == result) { 1219 } else if (r == result) {
1215 /* 1220 /*
1216 * We managed to write the entire buffer. This means our 1221 * We managed to write the entire buffer. This means our
1217 * network is fast and our buffer is too small, so make it 1222 * network is fast and our buffer is too small, so make it
1225 1230
1226 if (priv->buffer) { 1231 if (priv->buffer) {
1227 /* 1232 /*
1228 * Remove what we wrote 1233 * Remove what we wrote
1229 * If we wrote the whole buffer the byte array will be empty 1234 * If we wrote the whole buffer the byte array will be empty
1230 * Otherwise we'll kee what wasn't sent for next time. 1235 * Otherwise we'll keep what wasn't sent for next time.
1231 */ 1236 */
1232 buffer = NULL; 1237 buffer = NULL;
1233 priv->buffer = g_byte_array_remove_range(priv->buffer, 0, r); 1238 g_byte_array_remove_range(priv->buffer, 0, r);
1234 } 1239 }
1235 } 1240 }
1236 1241
1237 if (r > 0) { 1242 if (r > 0) {
1238 if (purple_xfer_get_size(xfer) > 0) 1243 if (purple_xfer_get_size(xfer) > 0)