Changeset e7dc02a
- Timestamp:
- 2010-05-19T00:57:58Z (15 years ago)
- Branches:
- master
- Children:
- 75c3ff7
- Parents:
- 31fc06fb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/ft.c
r31fc06fb re7dc02a 38 38 PurpleXfer *xfer; 39 39 file_transfer_t *ft; 40 struct im_connection *ic; 40 41 int fd; 41 char *fn ;42 char *fn, *orig_fn, *handle; 42 43 gboolean ui_wants_data; 43 44 }; … … 83 84 else 84 85 { 85 /* 86 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 87 88 px->fd = -1; 89 px->ft = next_ft; 90 px->ft->data = px; 86 struct file_transfer *ft = next_ft; 87 struct prpl_xfer_data *px = ft->data; 88 89 xfer->ui_data = px; 91 90 px->xfer = xfer; 92 px->xfer->ui_data = px; 93 94 purple_xfer_set_filename( xfer, px->ft->file_name ); 95 purple_xfer_set_size( xfer, px->ft->file_size ); 91 92 purple_xfer_set_filename( xfer, px->orig_fn ); 93 purple_xfer_set_local_filename( xfer, px->fn ); 96 94 97 95 next_ft = NULL; 98 */99 96 } 100 97 } … … 180 177 181 178 g_free( px->fn ); 179 g_free( px->orig_fn ); 180 g_free( px->handle ); 182 181 if( px->fd >= 0 ) 183 182 close( px->fd ); … … 188 187 { 189 188 struct prpl_xfer_data *px = xfer->ui_data; 189 190 if( px == NULL ) 191 return; 192 193 if( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND ) 194 { 195 if( *px->fn ) 196 { 197 //unlink( px->fn ); 198 *px->fn = '\0'; 199 } 200 201 return; 202 } 190 203 191 204 if( px->fd == -1 && percent > 0 ) … … 216 229 } 217 230 231 static void prplcb_xfer_add( PurpleXfer *xfer ) 232 { 233 if( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND ) 234 { 235 struct prpl_xfer_data *px = xfer->ui_data; 236 237 purple_xfer_set_filename( xfer, px->orig_fn ); 238 } 239 } 240 218 241 static void prplcb_xfer_dbg( PurpleXfer *xfer ) 219 242 { … … 223 246 224 247 /* Sending files (UI->IM): */ 225 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len ) 226 { 227 return FALSE; 228 } 248 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len ); 249 static gboolean purple_transfer_request_cb( gpointer data, gint fd, b_input_condition cond ); 229 250 230 251 void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle ) 231 252 { 232 PurpleAccount *pa = ic->proto_data; 233 struct prpl_xfer_data *px; 253 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 254 255 ft->data = px; 256 px->ft = ft; 257 px->fn = g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" ); 258 px->fd = mkstemp( px->fn ); 259 260 px->ic = ic; 261 px->handle = g_strdup( handle ); 262 px->orig_fn = g_strdup( ft->file_name ); 263 264 imcb_log( ic, "Due to libpurple limitations, the file has to be cached locally before proceeding with the actual file transfer. Please wait..." ); 265 266 b_timeout_add( 0, purple_transfer_request_cb, ft ); 267 } 268 269 static void purple_transfer_forward( struct file_transfer *ft ) 270 { 271 struct prpl_xfer_data *px = ft->data; 272 PurpleAccount *pa = px->ic->proto_data; 234 273 235 274 /* xfer_new() will pick up this variable. It's a hack but we're not 236 275 multi-threaded anyway. */ 237 276 next_ft = ft; 238 serv_send_file( purple_account_get_connection( pa ), handle, ft->file_name ); 239 240 ft->write = prpl_xfer_write; 241 242 px = ft->data; 243 imcb_file_recv_start( ft ); 244 } 245 277 serv_send_file( purple_account_get_connection( pa ), px->handle, px->fn ); 278 } 279 280 static gboolean purple_transfer_request_cb( gpointer data, gint fd, b_input_condition cond ) 281 { 282 file_transfer_t *ft = data; 283 284 if( ft->write == NULL ) 285 { 286 ft->write = prpl_xfer_write; 287 imcb_file_recv_start( ft ); 288 } 289 290 ft->write_request( ft ); 291 292 return FALSE; 293 } 294 295 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len ) 296 { 297 struct prpl_xfer_data *px = ft->data; 298 299 if( write( px->fd, buffer, len ) != len ) 300 { 301 imcb_file_canceled( ft, "Error while writing temporary file" ); 302 return FALSE; 303 } 304 305 if( lseek( px->fd, 0, SEEK_CUR ) >= ft->file_size ) 306 { 307 close( px->fd ); 308 px->fd = -1; 309 310 purple_transfer_forward( ft ); 311 imcb_file_finished( ft ); 312 px->ft = NULL; 313 } 314 else 315 b_timeout_add( 0, purple_transfer_request_cb, ft ); 316 317 return TRUE; 318 } 246 319 247 320 … … 251 324 prplcb_xfer_new, 252 325 prplcb_xfer_destroy, 253 prplcb_xfer_ dbg,326 prplcb_xfer_add, 254 327 prplcb_xfer_progress, 255 328 prplcb_xfer_dbg,
Note: See TracChangeset
for help on using the changeset viewer.