Mercurial > pidgin
comparison libpurple/ft.c @ 29819:10bf97a36be0
propagate from branch 'im.pidgin.pidgin' (head 96b27a20c7250b87761a8bd4f5540bf1fa32b6f4)
to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head 230fd6c21fdf1ed459a653bcd9808880a36204c3)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 09 Mar 2010 21:41:55 +0000 |
parents | 1e8dc177415e 1b861e13ae45 |
children | 25a53c299713 |
comparison
equal
deleted
inserted
replaced
29818:fd354d0bfbc0 | 29819:10bf97a36be0 |
---|---|
620 return; | 620 return; |
621 | 621 |
622 type = purple_xfer_get_type(xfer); | 622 type = purple_xfer_get_type(xfer); |
623 account = purple_xfer_get_account(xfer); | 623 account = purple_xfer_get_account(xfer); |
624 | 624 |
625 purple_debug_misc("xfer", "request accepted for %p\n", xfer); | 625 purple_debug_misc("xfer", "request accepted for %p\n", xfer); |
626 | 626 |
627 if (!filename && type == PURPLE_XFER_RECEIVE) { | 627 if (!filename && type == PURPLE_XFER_RECEIVE) { |
628 xfer->status = PURPLE_XFER_STATUS_ACCEPTED; | 628 xfer->status = PURPLE_XFER_STATUS_ACCEPTED; |
629 xfer->ops.init(xfer); | 629 xfer->ops.init(xfer); |
630 return; | 630 return; |
1126 purple_xfer_cancel_remote(xfer); | 1126 purple_xfer_cancel_remote(xfer); |
1127 g_free(buffer); | 1127 g_free(buffer); |
1128 return; | 1128 return; |
1129 } | 1129 } |
1130 } else if (xfer->type == PURPLE_XFER_SEND) { | 1130 } else if (xfer->type == PURPLE_XFER_SEND) { |
1131 size_t result; | 1131 size_t result = 0; |
1132 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size); | 1132 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size); |
1133 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer); | 1133 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer); |
1134 gboolean read = TRUE; | |
1134 | 1135 |
1135 /* this is so the prpl can keep the connection open | 1136 /* this is so the prpl can keep the connection open |
1136 if it needs to for some odd reason. */ | 1137 if it needs to for some odd reason. */ |
1137 if (s == 0) { | 1138 if (s == 0) { |
1138 if (xfer->watcher) { | 1139 if (xfer->watcher) { |
1140 xfer->watcher = 0; | 1141 xfer->watcher = 0; |
1141 } | 1142 } |
1142 return; | 1143 return; |
1143 } | 1144 } |
1144 | 1145 |
1145 if (ui_ops && ui_ops->ui_read) { | 1146 if (priv->buffer) { |
1146 gssize tmp = ui_ops->ui_read(xfer, &buffer, s); | 1147 if (priv->buffer->len < s) { |
1147 if (tmp == 0) { | 1148 s -= priv->buffer->len; |
1148 /* | 1149 read = TRUE; |
1149 * The UI claimed it was ready, but didn't have any data for | 1150 } else { |
1150 * us... It will call purple_xfer_ui_ready when ready, which | 1151 read = FALSE; |
1151 * sets back up this watcher. | 1152 } |
1152 */ | 1153 } |
1153 if (xfer->watcher != 0) { | 1154 |
1154 purple_input_remove(xfer->watcher); | 1155 if (read) { |
1155 xfer->watcher = 0; | 1156 if (ui_ops && ui_ops->ui_read) { |
1157 gssize tmp = ui_ops->ui_read(xfer, &buffer, s); | |
1158 if (tmp == 0) { | |
1159 /* | |
1160 * The UI claimed it was ready, but didn't have any data for | |
1161 * us... It will call purple_xfer_ui_ready when ready, which | |
1162 * sets back up this watcher. | |
1163 */ | |
1164 if (xfer->watcher != 0) { | |
1165 purple_input_remove(xfer->watcher); | |
1166 xfer->watcher = 0; | |
1167 } | |
1168 | |
1169 /* Need to indicate the prpl is still ready... */ | |
1170 priv->ready |= PURPLE_XFER_READY_PRPL; | |
1171 | |
1172 g_return_if_reached(); | |
1173 } else if (tmp < 0) { | |
1174 purple_debug_error("filetransfer", "Unable to read whole buffer.\n"); | |
1175 purple_xfer_cancel_local(xfer); | |
1176 return; | |
1156 } | 1177 } |
1157 | 1178 |
1158 /* Need to indicate the prpl is still ready... */ | 1179 result = tmp; |
1159 priv->ready |= PURPLE_XFER_READY_PRPL; | 1180 } else { |
1160 | 1181 buffer = g_malloc(s); |
1161 /* | 1182 result = fread(buffer, 1, s, xfer->dest_fp); |
1162 * if we requested 0 bytes it's only normal that end up here | 1183 if (result != s) { |
1163 * we shouldn't return as we still have something to | 1184 purple_debug_error("filetransfer", "Unable to read whole buffer.\n"); |
1164 * write in priv->buffer | 1185 purple_xfer_cancel_local(xfer); |
1165 */ | 1186 g_free(buffer); |
1166 if (s != 0) | 1187 return; |
1167 g_return_if_reached(); | 1188 } |
1168 } else if (tmp < 0) { | |
1169 purple_debug_error("filetransfer", "Unable to read whole buffer.\n"); | |
1170 purple_xfer_cancel_local(xfer); | |
1171 return; | |
1172 } | 1189 } |
1173 | 1190 } |
1174 result = tmp; | 1191 |
1175 } else { | |
1176 buffer = g_malloc0(s); | |
1177 result = fread(buffer, 1, s, xfer->dest_fp); | |
1178 if (result != s) { | |
1179 purple_debug_error("filetransfer", "Unable to read whole buffer.\n"); | |
1180 purple_xfer_cancel_local(xfer); | |
1181 g_free(buffer); | |
1182 return; | |
1183 } | |
1184 } | |
1185 | |
1186 if (priv->buffer) { | 1192 if (priv->buffer) { |
1187 priv->buffer = g_byte_array_append(priv->buffer, buffer, result); | 1193 priv->buffer = g_byte_array_append(priv->buffer, buffer, result); |
1188 g_free(buffer); | 1194 g_free(buffer); |
1189 buffer = priv->buffer->data; | 1195 buffer = priv->buffer->data; |
1190 result = priv->buffer->len; | 1196 result = priv->buffer->len; |
1191 } | 1197 } |
1192 | 1198 |
1193 r = purple_xfer_write(xfer, buffer, result); | 1199 r = purple_xfer_write(xfer, buffer, result); |
1194 | 1200 |
1195 if (r == -1) { | 1201 if (r == -1) { |
1196 purple_xfer_cancel_remote(xfer); | 1202 purple_xfer_cancel_remote(xfer); |
1197 g_free(buffer); | 1203 g_free(buffer); |
1202 * network is fast and our buffer is too small, so make it | 1208 * network is fast and our buffer is too small, so make it |
1203 * bigger. | 1209 * bigger. |
1204 */ | 1210 */ |
1205 purple_xfer_increase_buffer_size(xfer); | 1211 purple_xfer_increase_buffer_size(xfer); |
1206 } else { | 1212 } else { |
1207 if (ui_ops && ui_ops->data_not_sent) | 1213 if (ui_ops && ui_ops->data_not_sent) |
1208 ui_ops->data_not_sent(xfer, buffer + r, result -r); | 1214 ui_ops->data_not_sent(xfer, buffer + r, result - r); |
1209 } | 1215 } |
1210 | 1216 |
1211 if (priv->buffer) { | 1217 if (priv->buffer) { |
1212 /* | 1218 /* |
1213 * Remove what we wrote | 1219 * Remove what we wrote |
1214 * If we wrote the whole buffer the byte array will be empty | 1220 * If we wrote the whole buffer the byte array will be empty |
1215 * Otherwise we'll kee what wasn't sent for next time. | 1221 * Otherwise we'll kee what wasn't sent for next time. |
1216 */ | 1222 */ |
1217 buffer = NULL; | 1223 buffer = NULL; |