Changeset 8822d23
- Timestamp:
- 2010-05-17T23:23:20Z (15 years ago)
- Branches:
- master
- Children:
- 5d1b3a95
- Parents:
- 553767c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/ft.c
r553767c r8822d23 38 38 PurpleXfer *xfer; 39 39 file_transfer_t *ft; 40 gint ready_timer;41 char * buf;42 int buf_len;40 int fd; 41 char *fn; 42 gboolean ui_wants_data; 43 43 }; 44 44 … … 47 47 struct im_connection *purple_ic_by_pa( PurpleAccount *pa ); 48 48 49 gboolean try_write_to_ui( gpointer data, gint fd, b_input_condition cond ) 50 { 51 struct file_transfer *ft = data; 52 struct prpl_xfer_data *px = ft->data; 53 struct stat fs; 54 off_t tx_bytes; 55 56 fprintf( stderr, "write_to_ui\n" ); 57 58 /* If we don't have the file opened yet, there's no data so wait. */ 59 if( px->fd < 0 || !px->ui_wants_data ) 60 return FALSE; 61 62 tx_bytes = lseek( px->fd, 0, SEEK_CUR ); 63 fstat( px->fd, &fs ); 64 65 fprintf( stderr, "write_to_ui %zd %zd %zd\n", fs.st_size, tx_bytes, px->xfer->size ); 66 67 if( fs.st_size > tx_bytes ) 68 { 69 char buf[1024]; 70 size_t n = MIN( fs.st_size - tx_bytes, sizeof( buf ) ); 71 72 if( read( px->fd, buf, n ) == n && ft->write( ft, buf, n ) ) 73 { 74 fprintf( stderr, "Wrote %zd bytes\n", n ); 75 px->ui_wants_data = FALSE; 76 } 77 else 78 { 79 purple_xfer_cancel_local( px->xfer ); 80 imcb_file_canceled( ft, "Read error" ); 81 } 82 } 83 84 if( lseek( px->fd, 0, SEEK_CUR ) == px->xfer->size ) 85 { 86 purple_xfer_end( px->xfer ); 87 imcb_file_finished( ft ); 88 } 89 90 return FALSE; 91 } 92 93 /* UI calls this when its buffer is empty and wants more data to send to the user. */ 49 94 static gboolean prpl_xfer_write_request( struct file_transfer *ft ) 50 95 { 96 struct prpl_xfer_data *px = ft->data; 97 98 fprintf( stderr, "wrq\n" ); 99 100 px->ui_wants_data = TRUE; 101 try_write_to_ui( ft, 0, 0 ); 102 51 103 return FALSE; 52 104 } … … 54 106 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len ) 55 107 { 56 struct prpl_xfer_data *px = ft->data;57 58 108 return FALSE; 59 109 } … … 78 128 if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE ) 79 129 { 80 /* This should suppress the stupid file dialog. */ 81 purple_xfer_set_local_filename( xfer, "/tmp/wtf123" ); 130 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 131 132 xfer->ui_data = px; 133 px->xfer = xfer; 134 px->fn = mktemp( g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" ) ); 135 px->fd = -1; 136 137 purple_xfer_set_local_filename( xfer, px->fn ); 82 138 83 139 /* Sadly the xfer struct is still empty ATM so come back after … … 90 146 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 91 147 148 px->fd = -1; 92 149 px->ft = next_ft; 93 150 px->ft->data = px; … … 107 164 PurpleXfer *xfer = data; 108 165 struct im_connection *ic = purple_ic_by_pa( xfer->account ); 109 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );166 struct prpl_xfer_data *px = xfer->ui_data; 110 167 PurpleBuddy *buddy; 111 168 const char *who; … … 118 175 px->ft = imcb_file_send_start( ic, (char*) who, xfer->filename, xfer->size ); 119 176 px->ft->data = px; 120 px->xfer = data;121 px->xfer->ui_data = px;122 177 123 178 px->ft->accept = prpl_xfer_accept; … … 128 183 } 129 184 185 static void prplcb_xfer_destroy( PurpleXfer *xfer ) 186 { 187 struct prpl_xfer_data *px = xfer->ui_data; 188 189 g_free( px->fn ); 190 if( px->fd >= 0 ) 191 close( px->fd ); 192 g_free( px ); 193 } 194 130 195 static void prplcb_xfer_progress( PurpleXfer *xfer, double percent ) 131 196 { 132 fprintf( stderr, "prplcb_xfer_dbg 0x%p %f\n", xfer, percent ); 197 struct prpl_xfer_data *px = xfer->ui_data; 198 199 fprintf( stderr, "prplcb_xfer_progress 0x%p %f\n", xfer, percent ); 200 201 if( px->fd == -1 && percent > 0 ) 202 { 203 /* Weeeeeeeee, we're getting data! That means the file exists 204 by now so open it and start sending to the UI. */ 205 px->fd = open( px->fn, O_RDONLY ); 206 207 /* Unlink it now, because we don't need it after this. */ 208 //unlink( px->fn ); 209 } 210 211 if( percent < 1 ) 212 try_write_to_ui( px->ft, 0, 0 ); 213 else 214 b_timeout_add( 0, try_write_to_ui, px->ft ); 215 } 216 217 static void prplcb_xfer_cancel_remote( PurpleXfer *xfer ) 218 { 219 struct prpl_xfer_data *px = xfer->ui_data; 220 221 imcb_file_canceled( px->ft, "Canceled by remote end" ); 133 222 } 134 223 … … 141 230 { 142 231 prplcb_xfer_new, 143 prplcb_xfer_d bg,232 prplcb_xfer_destroy, 144 233 prplcb_xfer_dbg, 145 234 prplcb_xfer_progress, 146 235 prplcb_xfer_dbg, 147 prplcb_xfer_ dbg,236 prplcb_xfer_cancel_remote, 148 237 NULL, 149 238 NULL, … … 151 240 }; 152 241 153 static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond );154 155 242 void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle ) 156 243 {
Note: See TracChangeset
for help on using the changeset viewer.