Commit c7743bf8efbd18454545f7f1625bcabba161d1c2
1 parent
e48d6f69
Exists in
master
and in
3 other branches
Finalizando diálogo de transferência de arquivos
Showing
3 changed files
with
115 additions
and
85 deletions
Show diff stats
| ... | ... | @@ -160,11 +160,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
| 160 | 160 | return 0; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - static void def_complete(H3270FT *ft, const char *errmsg,unsigned long length,double kbytes_sec,const char *mode) | |
| 163 | + static void def_complete(H3270FT *ft,unsigned long length,double kbytes_sec,const char *mode) | |
| 164 | 164 | { |
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | + static void def_message(H3270FT *ft, const char *errmsg) | |
| 169 | + { | |
| 170 | + lib3270_write_log(ft->host,"ft","%s",errmsg); | |
| 171 | + } | |
| 172 | + | |
| 168 | 173 | static void def_update(H3270FT *ft, unsigned long current, unsigned long length, double kbytes_sec) |
| 169 | 174 | { |
| 170 | 175 | |
| ... | ... | @@ -189,20 +194,9 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
| 189 | 194 | LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *session, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft, const char **msg) |
| 190 | 195 | { |
| 191 | 196 | H3270FT * ftHandle = NULL; |
| 192 | - static const char * rec = "fvu"; | |
| 193 | - static const char * un[] = { "tracks", "cylinders", "avblock" }; | |
| 194 | - | |
| 195 | - unsigned short recfm = (flags & FT_RECORD_FORMAT_MASK) >> 8; | |
| 196 | - unsigned short units = (flags & FT_ALLOCATION_UNITS_MASK) >> 12; | |
| 197 | - | |
| 198 | 197 | FILE * ft_local_file = NULL; |
| 199 | 198 | unsigned long ft_length = 0L; |
| 200 | 199 | |
| 201 | - char op[4096]; | |
| 202 | - char buffer[4096]; | |
| 203 | - | |
| 204 | - unsigned int flen; | |
| 205 | - | |
| 206 | 200 | // trace("%s(%s)",__FUNCTION__,local); |
| 207 | 201 | if(!lib3270_connected(session)) |
| 208 | 202 | { |
| ... | ... | @@ -246,62 +240,112 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
| 246 | 240 | dft_buffersize = dft; |
| 247 | 241 | set_dft_buffersize(); |
| 248 | 242 | |
| 249 | - ascii_flag = ((flags & LIB3270_FT_OPTION_ASCII) != 0); | |
| 250 | - cr_flag = ((flags & LIB3270_FT_OPTION_CRLF) != 0); | |
| 251 | - remap_flag = ((flags & LIB3270_FT_OPTION_ASCII) != 0); | |
| 243 | + // Initialize ft control structure. | |
| 244 | + ft_last_cr = False; | |
| 245 | + ft_is_cut = False; | |
| 246 | + | |
| 247 | + ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); | |
| 248 | + | |
| 249 | + ftHandle->sz = sizeof(H3270FT); | |
| 250 | + ftHandle->host = session; | |
| 251 | + ftHandle->flags = flags; | |
| 252 | + ftHandle->local_file = ft_local_file; | |
| 253 | + ftHandle->length = ft_length; | |
| 254 | + ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | |
| 255 | + ftHandle->complete = def_complete; | |
| 256 | + ftHandle->message = def_message; | |
| 257 | + ftHandle->update = def_update; | |
| 258 | + ftHandle->running = def_running; | |
| 259 | + ftHandle->aborting = def_aborting; | |
| 260 | + ftHandle->state_changed = def_state_changed; | |
| 261 | + ftHandle->lrecl = lrecl; | |
| 262 | + ftHandle->blksize = blksize; | |
| 263 | + ftHandle->primspace = primspace; | |
| 264 | + ftHandle->secspace = secspace; | |
| 265 | + ftHandle->dft = dft; | |
| 266 | + | |
| 267 | + ftHandle->local = (char *) (ftHandle+1); | |
| 268 | + strcpy((char *) ftHandle->local,local); | |
| 269 | + | |
| 270 | + ftHandle->remote = ftHandle->local + strlen(ftHandle->local)+1; | |
| 271 | + strcpy((char *) ftHandle->remote,remote); | |
| 272 | + | |
| 273 | + session->ft = ftHandle; | |
| 274 | + | |
| 275 | + return ftsession = ftHandle; | |
| 276 | + } | |
| 252 | 277 | |
| 253 | - if(flags & LIB3270_FT_OPTION_RECEIVE) | |
| 278 | + LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft) | |
| 279 | + { | |
| 280 | + static const char * rec = "fvu"; | |
| 281 | + static const char * un[] = { "tracks", "cylinders", "avblock" }; | |
| 282 | + | |
| 283 | + char op[4096]; | |
| 284 | + char buffer[4096]; | |
| 285 | + unsigned int flen; | |
| 286 | + unsigned short recfm; | |
| 287 | + unsigned short units; | |
| 288 | + | |
| 289 | + CHECK_FT_HANDLE(ft); | |
| 290 | + | |
| 291 | + recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; | |
| 292 | + units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; | |
| 293 | + ascii_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | |
| 294 | + cr_flag = ((ft->flags & LIB3270_FT_OPTION_CRLF) != 0); | |
| 295 | + remap_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | |
| 296 | + | |
| 297 | + if(ft->flags & LIB3270_FT_OPTION_RECEIVE) | |
| 254 | 298 | { |
| 255 | 299 | // Receiving file |
| 256 | - lib3270_write_log(session,"ft","Receiving file %s",local); | |
| 300 | + lib3270_write_log(ft->host,"ft","Receiving file %s",ft->local); | |
| 257 | 301 | } |
| 258 | 302 | else |
| 259 | 303 | { |
| 260 | 304 | // Sending file |
| 261 | - if(fseek(ft_local_file,0L,SEEK_END) < 0) | |
| 305 | + if(fseek(ft->local_file,0L,SEEK_END) < 0) | |
| 262 | 306 | { |
| 263 | - *msg = N_( "Can't get file size" ); | |
| 264 | - return NULL; | |
| 307 | + ft_complete(ft,N_( "Can't get file size" )); | |
| 308 | + return errno ? errno : -1; | |
| 265 | 309 | } |
| 266 | 310 | |
| 267 | - ft_length = ftell(ft_local_file); | |
| 311 | + ft_length = ftell(ft->local_file); | |
| 268 | 312 | |
| 269 | - lib3270_write_log(session,"ft","Sending file %s (%ld bytes)",local,ft_length); | |
| 270 | - rewind(ft_local_file); | |
| 313 | + lib3270_write_log(ft->host,"ft","Sending file %s (%ld bytes)",ft->local,ft_length); | |
| 314 | + rewind(ft->local_file); | |
| 271 | 315 | } |
| 272 | 316 | |
| 273 | 317 | /* Build the ind$file command */ |
| 274 | 318 | snprintf(op,4095,"%s%s%s", |
| 275 | - (flags & LIB3270_FT_OPTION_ASCII) ? " ASCII" : "", | |
| 276 | - (flags & LIB3270_FT_OPTION_CRLF) ? " CRLF" : "", | |
| 277 | - (flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" | |
| 319 | + (ft->flags & LIB3270_FT_OPTION_ASCII) ? " ASCII" : "", | |
| 320 | + (ft->flags & LIB3270_FT_OPTION_CRLF) ? " CRLF" : "", | |
| 321 | + (ft->flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" | |
| 278 | 322 | ); |
| 279 | 323 | |
| 280 | - if(!(flags & LIB3270_FT_OPTION_RECEIVE)) | |
| 324 | + if(!(ft->flags & LIB3270_FT_OPTION_RECEIVE)) | |
| 281 | 325 | { |
| 282 | - if(flags & LIB3270_FT_OPTION_TSO) | |
| 326 | + if(ft->flags & LIB3270_FT_OPTION_TSO) | |
| 283 | 327 | { |
| 284 | 328 | // TSO Host |
| 285 | 329 | if(recfm > 0) |
| 286 | 330 | { |
| 287 | 331 | snconcat(op,4096," recfm(%c)",rec[recfm-1]); |
| 288 | 332 | |
| 289 | - if(lrecl > 0) | |
| 290 | - snconcat(op,4096," lrecl(%d)",lrecl); | |
| 333 | + if(ft->lrecl > 0) | |
| 334 | + snconcat(op,4096," lrecl(%d)",ft->lrecl); | |
| 291 | 335 | |
| 292 | - if(blksize > 0) | |
| 293 | - snconcat(op,4096," blksize(%d)", blksize); | |
| 336 | + if(ft->blksize > 0) | |
| 337 | + snconcat(op,4096," blksize(%d)", ft->blksize); | |
| 294 | 338 | } |
| 295 | 339 | |
| 296 | 340 | if(units > 0) |
| 297 | 341 | { |
| 298 | 342 | snconcat(op,4096," %s",un[units-1]); |
| 299 | 343 | |
| 300 | - if(primspace > 0) | |
| 344 | + if(ft->primspace > 0) | |
| 301 | 345 | { |
| 302 | - snconcat(op,4096," space(%d",primspace); | |
| 303 | - if(secspace) | |
| 304 | - snconcat(op,4096,",%d",secspace); | |
| 346 | + snconcat(op,4096," space(%d",ft->primspace); | |
| 347 | + if(ft->secspace) | |
| 348 | + snconcat(op,4096,",%d",ft->secspace); | |
| 305 | 349 | snconcat(op,4096,"%s",")"); |
| 306 | 350 | } |
| 307 | 351 | } |
| ... | ... | @@ -313,20 +357,20 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
| 313 | 357 | { |
| 314 | 358 | snconcat(op,4096," recfm %c",rec[recfm-1]); |
| 315 | 359 | |
| 316 | - if(lrecl > 0) | |
| 317 | - snconcat(op,4096," lrecl %d",lrecl); | |
| 360 | + if(ft->lrecl > 0) | |
| 361 | + snconcat(op,4096," lrecl %d",ft->lrecl); | |
| 318 | 362 | |
| 319 | 363 | } |
| 320 | 364 | } |
| 321 | 365 | } |
| 322 | 366 | |
| 323 | 367 | snprintf(buffer,4095,"%s %s %s", "IND$FILE", |
| 324 | - (flags & LIB3270_FT_OPTION_RECEIVE) ? "GET" : "PUT", | |
| 325 | - remote ); | |
| 368 | + (ft->flags & LIB3270_FT_OPTION_RECEIVE) ? "GET" : "PUT", | |
| 369 | + ft->remote ); | |
| 326 | 370 | |
| 327 | 371 | if(*op) |
| 328 | 372 | { |
| 329 | - if(flags & LIB3270_FT_OPTION_TSO) | |
| 373 | + if(ft->flags & LIB3270_FT_OPTION_TSO) | |
| 330 | 374 | snconcat(buffer,4095," %s",op+1); |
| 331 | 375 | else |
| 332 | 376 | snconcat(buffer,4095," (%s)",op+1); |
| ... | ... | @@ -338,40 +382,25 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
| 338 | 382 | flen = kybd_prime(); |
| 339 | 383 | if (!flen || flen < strlen(buffer) - 1) |
| 340 | 384 | { |
| 341 | - lib3270_write_log(session, "Unable to send command \"%s\" (flen=%d szBuffer=%d)",buffer,flen,strlen(buffer)); | |
| 342 | - fclose(ft_local_file); | |
| 343 | - *msg = _( "Unable to send file-transfer request" ); | |
| 344 | - errno = EINVAL; | |
| 345 | - return NULL; | |
| 385 | + lib3270_write_log(ft->host, "Unable to send command \"%s\" (flen=%d szBuffer=%d)",buffer,flen,strlen(buffer)); | |
| 386 | + ft_complete(ft,N_( "Unable to send file-transfer request" )); | |
| 387 | + return errno = EINVAL; | |
| 346 | 388 | } |
| 347 | 389 | |
| 348 | 390 | trace_event("Sending FT request:\n%s\n",buffer); |
| 349 | 391 | |
| 350 | - (void) lib3270_emulate_input(NULL, buffer, strlen(buffer), False); | |
| 351 | - | |
| 352 | - // Get this thing started. | |
| 353 | - | |
| 354 | - ft_last_cr = False; | |
| 355 | - ft_is_cut = False; | |
| 392 | + lib3270_emulate_input(ft->host, buffer, strlen(buffer), False); | |
| 356 | 393 | |
| 357 | - ftHandle = lib3270_malloc(sizeof(H3270FT)); | |
| 358 | - | |
| 359 | - ftHandle->sz = sizeof(H3270FT); | |
| 360 | - ftHandle->host = session; | |
| 361 | - ftHandle->ft_local_file = ft_local_file; | |
| 362 | - ftHandle->length = ft_length; | |
| 363 | - ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | |
| 364 | - ftHandle->complete = def_complete; | |
| 365 | - ftHandle->update = def_update; | |
| 366 | - ftHandle->running = def_running; | |
| 367 | - ftHandle->aborting = def_aborting; | |
| 368 | - ftHandle->state_changed = def_state_changed; | |
| 394 | + if(ft->flags & LIB3270_FT_OPTION_RECEIVE) | |
| 395 | + ft->message(ft,N_( "Waiting for GET response" )); | |
| 396 | + else | |
| 397 | + ft->message(ft,N_( "Waiting for PUT response" )); | |
| 369 | 398 | |
| 370 | - session->ft = ftHandle; | |
| 399 | + return 0; | |
| 371 | 400 | |
| 372 | - return ftsession = ftHandle; | |
| 373 | 401 | } |
| 374 | 402 | |
| 403 | + | |
| 375 | 404 | /* External entry points called by ft_dft and ft_cut. */ |
| 376 | 405 | |
| 377 | 406 | /** |
| ... | ... | @@ -391,10 +420,10 @@ void ft_complete(H3270FT *session, const char *errmsg) |
| 391 | 420 | (double)(t1.tv_usec - starting_time.tv_usec) / 1.0e6); |
| 392 | 421 | |
| 393 | 422 | // Close the local file. |
| 394 | - if(session->ft_local_file) | |
| 423 | + if(session->local_file) | |
| 395 | 424 | { |
| 396 | - fclose(session->ft_local_file); | |
| 397 | - session->ft_local_file = NULL; | |
| 425 | + fclose(session->local_file); | |
| 426 | + session->local_file = NULL; | |
| 398 | 427 | } |
| 399 | 428 | |
| 400 | 429 | // Clean up the state. |
| ... | ... | @@ -402,7 +431,8 @@ void ft_complete(H3270FT *session, const char *errmsg) |
| 402 | 431 | |
| 403 | 432 | ft_update_length(session); |
| 404 | 433 | |
| 405 | - session->complete(session,errmsg,ft_length,kbytes_sec,ft_is_cut ? "CUT" : "DFT"); | |
| 434 | + session->message(session,errmsg); | |
| 435 | + session->complete(session,ft_length,kbytes_sec,ft_is_cut ? "CUT" : "DFT"); | |
| 406 | 436 | |
| 407 | 437 | } |
| 408 | 438 | |
| ... | ... | @@ -413,10 +443,10 @@ LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) |
| 413 | 443 | if (session->state != LIB3270_FT_STATE_NONE) |
| 414 | 444 | lib3270_ft_cancel(session,1); |
| 415 | 445 | |
| 416 | - if(session->ft_local_file) | |
| 446 | + if(session->local_file) | |
| 417 | 447 | { |
| 418 | - fclose(session->ft_local_file); | |
| 419 | - session->ft_local_file = NULL; | |
| 448 | + fclose(session->local_file); | |
| 449 | + session->local_file = NULL; | |
| 420 | 450 | } |
| 421 | 451 | |
| 422 | 452 | if(session == ftsession) | ... | ... |
ft_cut.c
| ... | ... | @@ -398,7 +398,7 @@ cut_data_request(void) |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /* Check for errors. */ |
| 401 | - if (ferror(((H3270FT *) h3270.ft)->ft_local_file)) { | |
| 401 | + if (ferror(((H3270FT *) h3270.ft)->local_file)) { | |
| 402 | 402 | int j; |
| 403 | 403 | |
| 404 | 404 | /* Clean out any data we may have written. */ |
| ... | ... | @@ -411,7 +411,7 @@ cut_data_request(void) |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /* Send special data for EOF. */ |
| 414 | - if (!count && feof(((H3270FT *) h3270.ft)->ft_local_file)) { | |
| 414 | + if (!count && feof(((H3270FT *) h3270.ft)->local_file)) { | |
| 415 | 415 | ctlr_add(O_UP_DATA, EOF_DATA1, 0); |
| 416 | 416 | ctlr_add(O_UP_DATA+1, EOF_DATA2, 0); |
| 417 | 417 | count = 2; |
| ... | ... | @@ -502,7 +502,7 @@ cut_data(void) |
| 502 | 502 | return; |
| 503 | 503 | |
| 504 | 504 | /* Write it to the file. */ |
| 505 | - if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) h3270.ft)->ft_local_file) == 0) { | |
| 505 | + if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) h3270.ft)->local_file) == 0) { | |
| 506 | 506 | cut_abort(SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); |
| 507 | 507 | } else { |
| 508 | 508 | ft_length += conv_length; |
| ... | ... | @@ -570,7 +570,7 @@ xlate_getc(void) |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /* Get the next byte from the file. */ |
| 573 | - c = fgetc(((H3270FT *) h3270.ft)->ft_local_file); | |
| 573 | + c = fgetc(((H3270FT *) h3270.ft)->local_file); | |
| 574 | 574 | if (c == EOF) |
| 575 | 575 | return c; |
| 576 | 576 | ft_length++; | ... | ... |
ft_dft.c
| ... | ... | @@ -291,7 +291,7 @@ dft_data_insert(struct data_buffer *data_bufr) |
| 291 | 291 | |
| 292 | 292 | if (l) |
| 293 | 293 | { |
| 294 | - rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->ft_local_file); | |
| 294 | + rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); | |
| 295 | 295 | if (rv == 0) |
| 296 | 296 | break; |
| 297 | 297 | ft_length += l; |
| ... | ... | @@ -302,7 +302,7 @@ dft_data_insert(struct data_buffer *data_bufr) |
| 302 | 302 | len -= l; |
| 303 | 303 | } |
| 304 | 304 | } else { |
| 305 | - rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->ft_local_file); | |
| 305 | + rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); | |
| 306 | 306 | ft_length += my_length; |
| 307 | 307 | } |
| 308 | 308 | |
| ... | ... | @@ -363,7 +363,7 @@ dft_get_request(void) |
| 363 | 363 | int c; |
| 364 | 364 | |
| 365 | 365 | /* Read one byte and do CR/LF translation. */ |
| 366 | - c = fgetc(((H3270FT *) h3270.ft)->ft_local_file); | |
| 366 | + c = fgetc(((H3270FT *) h3270.ft)->local_file); | |
| 367 | 367 | if (c == EOF) { |
| 368 | 368 | break; |
| 369 | 369 | } |
| ... | ... | @@ -373,7 +373,7 @@ dft_get_request(void) |
| 373 | 373 | * Not enough room to expand NL to |
| 374 | 374 | * CR/LF. |
| 375 | 375 | */ |
| 376 | - ungetc(c, ((H3270FT *) h3270.ft)->ft_local_file); | |
| 376 | + ungetc(c, ((H3270FT *) h3270.ft)->local_file); | |
| 377 | 377 | break; |
| 378 | 378 | } |
| 379 | 379 | *bufptr++ = '\r'; |
| ... | ... | @@ -386,7 +386,7 @@ dft_get_request(void) |
| 386 | 386 | total_read++; |
| 387 | 387 | } else { |
| 388 | 388 | /* Binary read. */ |
| 389 | - numread = fread(bufptr, 1, numbytes, ((H3270FT *) h3270.ft)->ft_local_file); | |
| 389 | + numread = fread(bufptr, 1, numbytes, ((H3270FT *) h3270.ft)->local_file); | |
| 390 | 390 | if (numread <= 0) { |
| 391 | 391 | break; |
| 392 | 392 | } |
| ... | ... | @@ -404,13 +404,13 @@ dft_get_request(void) |
| 404 | 404 | numbytes -= numread; |
| 405 | 405 | total_read += numread; |
| 406 | 406 | } |
| 407 | - if (feof(((H3270FT *) h3270.ft)->ft_local_file) || ferror(((H3270FT *) h3270.ft)->ft_local_file)) { | |
| 407 | + if (feof(((H3270FT *) h3270.ft)->local_file) || ferror(((H3270FT *) h3270.ft)->local_file)) { | |
| 408 | 408 | break; |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /* Check for read error. */ |
| 413 | - if (ferror(((H3270FT *) h3270.ft)->ft_local_file)) | |
| 413 | + if (ferror(((H3270FT *) h3270.ft)->local_file)) | |
| 414 | 414 | { |
| 415 | 415 | dft_abort(TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); |
| 416 | 416 | return; |
| ... | ... | @@ -436,7 +436,7 @@ dft_get_request(void) |
| 436 | 436 | |
| 437 | 437 | ft_length += total_read; |
| 438 | 438 | |
| 439 | - if (feof(((H3270FT *) h3270.ft)->ft_local_file)) | |
| 439 | + if (feof(((H3270FT *) h3270.ft)->local_file)) | |
| 440 | 440 | { |
| 441 | 441 | dft_eof = True; |
| 442 | 442 | } | ... | ... |