Commit 528adbf8625feaed3db28d4462eff3617e1581d6
1 parent
65bba395
Exists in
master
and in
5 other branches
Ajustando transferência de arquivos para funcionar em multi-sessão
Showing
5 changed files
with
333 additions
and
264 deletions
Show diff stats
src/include/lib3270/filetransfer.h
@@ -69,9 +69,21 @@ | @@ -69,9 +69,21 @@ | ||
69 | LIB3270_FT_STATE_ABORT_SENT /**< Abort sent; awaiting response */ | 69 | LIB3270_FT_STATE_ABORT_SENT /**< Abort sent; awaiting response */ |
70 | } LIB3270_FT_STATE; | 70 | } LIB3270_FT_STATE; |
71 | 71 | ||
72 | + #define LIB3270_XLATE_NBUF 4 | ||
73 | + | ||
72 | typedef struct _h3270ft | 74 | typedef struct _h3270ft |
73 | { | 75 | { |
74 | unsigned short sz; /**< Size of FT data structure */ | 76 | unsigned short sz; /**< Size of FT data structure */ |
77 | + | ||
78 | + int ft_last_cr : 1; /**< CR was last char in local file */ | ||
79 | + int remap_flag : 1; /**< Remap ASCII<->EBCDIC */ | ||
80 | + int cr_flag : 1; /**< Add crlf to each line */ | ||
81 | + int message_flag : 1; /**< Open Request for msg received */ | ||
82 | + int ascii_flag : 1; /**< Convert to ascii */ | ||
83 | + int ft_is_cut : 1; /**< File transfer is CUT-style */ | ||
84 | + int dft_eof : 1; | ||
85 | + | ||
86 | + | ||
75 | H3270 * host; | 87 | H3270 * host; |
76 | void * widget; /**< File transfer dialog handle */ | 88 | void * widget; /**< File transfer dialog handle */ |
77 | FILE * local_file; /**< File descriptor for local file */ | 89 | FILE * local_file; /**< File descriptor for local file */ |
@@ -86,6 +98,8 @@ | @@ -86,6 +98,8 @@ | ||
86 | int secspace; | 98 | int secspace; |
87 | int dft; | 99 | int dft; |
88 | 100 | ||
101 | + unsigned long ft_length; /**< Length of transfer */ | ||
102 | + | ||
89 | struct timeval starting_time; /**< Starting time */ | 103 | struct timeval starting_time; /**< Starting time */ |
90 | 104 | ||
91 | const char * local; /**< Local filename */ | 105 | const char * local; /**< Local filename */ |
@@ -93,6 +107,19 @@ | @@ -93,6 +107,19 @@ | ||
93 | 107 | ||
94 | // ft_dft.c | 108 | // ft_dft.c |
95 | char * abort_string; | 109 | char * abort_string; |
110 | + unsigned long recnum; | ||
111 | + unsigned char * dft_savebuf; | ||
112 | + int dft_savebuf_len; | ||
113 | + int dft_savebuf_max; | ||
114 | + | ||
115 | + // ft_cut.c | ||
116 | + int quadrant; | ||
117 | + unsigned long expanded_length; | ||
118 | + char * saved_errmsg; | ||
119 | + int xlate_buffered; /**< buffer count */ | ||
120 | + int xlate_buf_ix; /**< buffer index */ | ||
121 | + unsigned char xlate_buf[LIB3270_XLATE_NBUF]; /**< buffer */ | ||
122 | + | ||
96 | 123 | ||
97 | // Callbacks | 124 | // Callbacks |
98 | void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode); | 125 | void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode); |
src/lib3270/ft.c
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
19 | * St, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * | 20 | * |
21 | - * Este programa está nomeado como ft.c e possui 2143 linhas de código. | 21 | + * Este programa está nomeado como ft.c e possui - linhas de código. |
22 | * | 22 | * |
23 | * Contatos: | 23 | * Contatos: |
24 | * | 24 | * |
@@ -26,7 +26,6 @@ | @@ -26,7 +26,6 @@ | ||
26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
27 | * licinio@bb.com.br (Licínio Luis Branco) | 27 | * licinio@bb.com.br (Licínio Luis Branco) |
28 | * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | 28 | * kraucer@bb.com.br (Kraucer Fernandes Mazuco) |
29 | - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | ||
30 | * | 29 | * |
31 | */ | 30 | */ |
32 | 31 | ||
@@ -79,16 +78,16 @@ static void ft_in3270(H3270 *session, int ignored unused, void *unused); | @@ -79,16 +78,16 @@ static void ft_in3270(H3270 *session, int ignored unused, void *unused); | ||
79 | #define BN (Boolean *)NULL | 78 | #define BN (Boolean *)NULL |
80 | 79 | ||
81 | // Globals. | 80 | // Globals. |
82 | -H3270FT *ftsession = NULL; | 81 | +// H3270FT *ftsession = NULL; |
83 | 82 | ||
84 | // enum ft_state ft_state = FT_NONE; // File transfer state | 83 | // enum ft_state ft_state = FT_NONE; // File transfer state |
85 | // char *ft_local_filename; // Local file to transfer to/from | 84 | // char *ft_local_filename; // Local file to transfer to/from |
86 | -Boolean ft_last_cr = False; // CR was last char in local file | ||
87 | -Boolean ascii_flag = True; // Convert to ascii | ||
88 | -Boolean cr_flag = True; // Add crlf to each line | ||
89 | -Boolean remap_flag = True; // Remap ASCII<->EBCDIC | ||
90 | -unsigned long ft_length = 0; // Length of transfer | ||
91 | -static Boolean ft_is_cut; // File transfer is CUT-style | 85 | +// Boolean ft_last_cr = 0; // CR was last char in local file |
86 | +// Boolean ascii_flag = True; // Convert to ascii | ||
87 | +// Boolean cr_flag = True; // Add crlf to each line | ||
88 | +// Boolean remap_flag = True; // Remap ASCII<->EBCDIC | ||
89 | +// unsigned long ft_length = 0; // Length of transfer | ||
90 | +// static Boolean ft_is_cut; // File transfer is CUT-style | ||
92 | 91 | ||
93 | // static struct timeval starting_time; // Starting time | 92 | // static struct timeval starting_time; // Starting time |
94 | 93 | ||
@@ -101,13 +100,19 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -101,13 +100,19 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
101 | 100 | ||
102 | /*---[ Implement ]-------------------------------------------------------------------------------------------------------*/ | 101 | /*---[ Implement ]-------------------------------------------------------------------------------------------------------*/ |
103 | 102 | ||
104 | - static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state) | 103 | + H3270FT * get_ft_handle(H3270 *hSession) |
105 | { | 104 | { |
106 | - CHECK_FT_HANDLE(session); | 105 | + if(!hSession->ft) |
106 | + { | ||
107 | + popup_an_error(hSession,"Unexpected call to %s: No active filetransfer",__FUNCTION__); | ||
108 | + } | ||
109 | + return hSession->ft; | ||
110 | + } | ||
107 | 111 | ||
112 | + static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state) | ||
113 | + { | ||
108 | if(session->state == state) | 114 | if(session->state == state) |
109 | return; | 115 | return; |
110 | - | ||
111 | session->state = state; | 116 | session->state = state; |
112 | session->state_changed(session,state); | 117 | session->state_changed(session,state); |
113 | 118 | ||
@@ -126,10 +131,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -126,10 +131,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
126 | 131 | ||
127 | CHECK_SESSION_HANDLE(hSession); | 132 | CHECK_SESSION_HANDLE(hSession); |
128 | 133 | ||
129 | - ft = (H3270FT *) hSession->ft; | ||
130 | - if(!ft) | ||
131 | - return EINVAL; | ||
132 | - | 134 | + ft = get_ft_handle(hSession); |
133 | 135 | ||
134 | if (ft->state == LIB3270_FT_STATE_RUNNING) | 136 | if (ft->state == LIB3270_FT_STATE_RUNNING) |
135 | { | 137 | { |
@@ -180,7 +182,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -180,7 +182,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
180 | 182 | ||
181 | 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) | 183 | 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) |
182 | { | 184 | { |
183 | - H3270FT * ftHandle = NULL; | 185 | + H3270FT * ftHandle = (H3270FT *) session->ft; |
184 | FILE * ft_local_file = NULL; | 186 | FILE * ft_local_file = NULL; |
185 | // unsigned long length = 0L; | 187 | // unsigned long length = 0L; |
186 | 188 | ||
@@ -192,19 +194,21 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -192,19 +194,21 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
192 | return NULL; | 194 | return NULL; |
193 | } | 195 | } |
194 | 196 | ||
195 | - if(session->ft) | 197 | + if(ftHandle) |
196 | { | 198 | { |
197 | *msg = N_( "File transfer is already active in this session" ); | 199 | *msg = N_( "File transfer is already active in this session" ); |
198 | errno = EBUSY; | 200 | errno = EBUSY; |
199 | return NULL; | 201 | return NULL; |
200 | } | 202 | } |
201 | 203 | ||
204 | +/* | ||
202 | if(ftsession) | 205 | if(ftsession) |
203 | { | 206 | { |
204 | *msg = N_( "File transfer is already active" ); | 207 | *msg = N_( "File transfer is already active" ); |
205 | errno = EBUSY; | 208 | errno = EBUSY; |
206 | return NULL; | 209 | return NULL; |
207 | } | 210 | } |
211 | +*/ | ||
208 | 212 | ||
209 | // Check remote file | 213 | // Check remote file |
210 | if(!*remote) | 214 | if(!*remote) |
@@ -227,14 +231,17 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -227,14 +231,17 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
227 | session->dft_buffersize = dft; | 231 | session->dft_buffersize = dft; |
228 | set_dft_buffersize(session); | 232 | set_dft_buffersize(session); |
229 | 233 | ||
230 | - // Initialize ft control structure. | ||
231 | - ft_last_cr = False; | ||
232 | - ft_is_cut = False; | ||
233 | - | 234 | + // Create & Initialize ft control structure. |
234 | ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); | 235 | ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); |
235 | 236 | ||
236 | ftHandle->sz = sizeof(H3270FT); | 237 | ftHandle->sz = sizeof(H3270FT); |
237 | ftHandle->host = session; | 238 | ftHandle->host = session; |
239 | + | ||
240 | + ftHandle->ft_last_cr = 0; | ||
241 | + ftHandle->remap_flag = 1; // Remap ASCII<->EBCDIC | ||
242 | + ftHandle->cr_flag = 1; | ||
243 | + ftHandle->ascii_flag = 1; | ||
244 | + ftHandle->ft_is_cut = 0; | ||
238 | ftHandle->flags = flags; | 245 | ftHandle->flags = flags; |
239 | ftHandle->local_file = ft_local_file; | 246 | ftHandle->local_file = ft_local_file; |
240 | ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | 247 | ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; |
@@ -249,6 +256,8 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -249,6 +256,8 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
249 | ftHandle->primspace = primspace; | 256 | ftHandle->primspace = primspace; |
250 | ftHandle->secspace = secspace; | 257 | ftHandle->secspace = secspace; |
251 | ftHandle->dft = dft; | 258 | ftHandle->dft = dft; |
259 | + ftHandle->quadrant = -1; | ||
260 | + | ||
252 | 261 | ||
253 | ftHandle->local = (char *) (ftHandle+1); | 262 | ftHandle->local = (char *) (ftHandle+1); |
254 | strcpy((char *) ftHandle->local,local); | 263 | strcpy((char *) ftHandle->local,local); |
@@ -258,7 +267,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -258,7 +267,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
258 | 267 | ||
259 | session->ft = ftHandle; | 268 | session->ft = ftHandle; |
260 | 269 | ||
261 | - return ftsession = ftHandle; | 270 | + return ftHandle; |
262 | } | 271 | } |
263 | 272 | ||
264 | LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession) | 273 | LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession) |
@@ -275,15 +284,15 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -275,15 +284,15 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
275 | 284 | ||
276 | CHECK_SESSION_HANDLE(hSession); | 285 | CHECK_SESSION_HANDLE(hSession); |
277 | 286 | ||
278 | - ft = (H3270FT *) hSession->ft; | 287 | + ft = get_ft_handle(hSession); |
279 | if(!ft) | 288 | if(!ft) |
280 | return EINVAL; | 289 | return EINVAL; |
281 | 290 | ||
282 | recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; | 291 | recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; |
283 | units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; | 292 | units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; |
284 | - ascii_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | ||
285 | - cr_flag = ((ft->flags & LIB3270_FT_OPTION_CRLF) != 0); | ||
286 | - remap_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | 293 | + ft->ascii_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) == 0) ? 1 : 0; |
294 | + ft->cr_flag = ((ft->flags & LIB3270_FT_OPTION_CRLF) == 0) ? 1 : 0; | ||
295 | + ft->remap_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) == 0) ? 1 : 0; | ||
287 | 296 | ||
288 | if(ft->flags & LIB3270_FT_OPTION_RECEIVE) | 297 | if(ft->flags & LIB3270_FT_OPTION_RECEIVE) |
289 | { | 298 | { |
@@ -399,32 +408,30 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -399,32 +408,30 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
399 | * Pop up a message, end the transfer, release resources. | 408 | * Pop up a message, end the transfer, release resources. |
400 | * | 409 | * |
401 | */ | 410 | */ |
402 | -void ft_complete(H3270FT *session, const char *errmsg) | 411 | +void ft_complete(H3270FT *ft, const char *errmsg) |
403 | { | 412 | { |
404 | - double kbytes_sec = 0; | ||
405 | - struct timeval t1; | ||
406 | - | ||
407 | - CHECK_FT_HANDLE(session); | 413 | + double kbytes_sec = 0; |
414 | + struct timeval t1; | ||
408 | 415 | ||
409 | (void) gettimeofday(&t1, (struct timezone *)NULL); | 416 | (void) gettimeofday(&t1, (struct timezone *)NULL); |
410 | - kbytes_sec = (double)ft_length / 1024.0 / | ||
411 | - ((double)(t1.tv_sec - session->starting_time.tv_sec) + | ||
412 | - (double)(t1.tv_usec - session->starting_time.tv_usec) / 1.0e6); | 417 | + kbytes_sec = (double) ft->ft_length / 1024.0 / |
418 | + ((double)(t1.tv_sec - ft->starting_time.tv_sec) + | ||
419 | + (double)(t1.tv_usec - ft->starting_time.tv_usec) / 1.0e6); | ||
413 | 420 | ||
414 | // Close the local file. | 421 | // Close the local file. |
415 | - if(session->local_file) | 422 | + if(ft->local_file) |
416 | { | 423 | { |
417 | - fclose(session->local_file); | ||
418 | - session->local_file = NULL; | 424 | + fclose(ft->local_file); |
425 | + ft->local_file = NULL; | ||
419 | } | 426 | } |
420 | 427 | ||
421 | // Clean up the state. | 428 | // Clean up the state. |
422 | - set_ft_state(session,FT_NONE); | 429 | + set_ft_state(ft,FT_NONE); |
423 | 430 | ||
424 | - ft_update_length(session); | 431 | + ft_update_length(ft); |
425 | 432 | ||
426 | - session->message(session,errmsg); | ||
427 | - session->complete(session,ft_length,kbytes_sec,ft_is_cut ? "CUT" : "DFT"); | 433 | + ft->message(ft,errmsg); |
434 | + ft->complete(ft,ft->ft_length,kbytes_sec,ft->ft_is_cut ? "CUT" : "DFT"); | ||
428 | 435 | ||
429 | } | 436 | } |
430 | 437 | ||
@@ -447,12 +454,12 @@ LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession) | @@ -447,12 +454,12 @@ LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession) | ||
447 | session->local_file = NULL; | 454 | session->local_file = NULL; |
448 | } | 455 | } |
449 | 456 | ||
450 | - if(session == ftsession) | ||
451 | - ftsession = NULL; | 457 | +// if(session == ftsession) |
458 | +// ftsession = NULL; | ||
452 | 459 | ||
453 | hSession->ft = NULL; | 460 | hSession->ft = NULL; |
454 | 461 | ||
455 | - free(session); | 462 | + lib3270_free(session); |
456 | 463 | ||
457 | return 0; | 464 | return 0; |
458 | } | 465 | } |
@@ -462,46 +469,43 @@ void ft_update_length(H3270FT *session) | @@ -462,46 +469,43 @@ void ft_update_length(H3270FT *session) | ||
462 | { | 469 | { |
463 | double kbytes_sec = 0; | 470 | double kbytes_sec = 0; |
464 | 471 | ||
465 | - CHECK_FT_HANDLE(session); | ||
466 | - | ||
467 | - if(ft_length > 1024.0) | 472 | + if(session->ft_length > 1024.0) |
468 | { | 473 | { |
469 | struct timeval t1; | 474 | struct timeval t1; |
470 | 475 | ||
471 | (void) gettimeofday(&t1, (struct timezone *)NULL); | 476 | (void) gettimeofday(&t1, (struct timezone *)NULL); |
472 | - kbytes_sec = (double)ft_length / 1024.0 / | 477 | + kbytes_sec = (double)session->ft_length / 1024.0 / |
473 | ((double)(t1.tv_sec - session->starting_time.tv_sec) + | 478 | ((double)(t1.tv_sec - session->starting_time.tv_sec) + |
474 | (double)(t1.tv_usec - session->starting_time.tv_usec) / 1.0e6); | 479 | (double)(t1.tv_usec - session->starting_time.tv_usec) / 1.0e6); |
475 | } | 480 | } |
476 | 481 | ||
477 | - session->update(session,ft_length,session->length,kbytes_sec); | 482 | + session->update(session,session->ft_length,session->length,kbytes_sec); |
478 | 483 | ||
479 | } | 484 | } |
480 | 485 | ||
481 | -// Process a transfer acknowledgement. | ||
482 | -void ft_running(H3270FT *h, Boolean is_cut) | 486 | +/** |
487 | + * Process a transfer acknowledgement. | ||
488 | + * | ||
489 | + */ | ||
490 | +void ft_running(H3270FT *ft, Boolean is_cut) | ||
483 | { | 491 | { |
484 | - CHECK_FT_HANDLE(h); | ||
485 | - | ||
486 | - ft_is_cut = is_cut; | ||
487 | - ft_length = 0; | 492 | + ft->ft_is_cut = is_cut ? 1 : 0; |
493 | + ft->ft_length = 0; | ||
488 | 494 | ||
489 | - gettimeofday(&h->starting_time, (struct timezone *)NULL); | 495 | + gettimeofday(&ft->starting_time, (struct timezone *)NULL); |
490 | 496 | ||
491 | - if (h->state == FT_AWAIT_ACK) | ||
492 | - set_ft_state(h,FT_RUNNING); | 497 | + if (ft->state == FT_AWAIT_ACK) |
498 | + set_ft_state(ft,FT_RUNNING); | ||
493 | 499 | ||
494 | - h->running(h,is_cut); | 500 | + ft->running(ft,is_cut); |
495 | 501 | ||
496 | - ft_update_length(h); | 502 | + ft_update_length(ft); |
497 | 503 | ||
498 | } | 504 | } |
499 | 505 | ||
500 | // Process a protocol-generated abort. | 506 | // Process a protocol-generated abort. |
501 | void ft_aborting(H3270FT *h) | 507 | void ft_aborting(H3270FT *h) |
502 | { | 508 | { |
503 | - CHECK_FT_HANDLE(h); | ||
504 | - | ||
505 | if (h->state == FT_RUNNING || h->state == FT_ABORT_WAIT) | 509 | if (h->state == FT_RUNNING || h->state == FT_ABORT_WAIT) |
506 | set_ft_state(h,FT_ABORT_SENT); | 510 | set_ft_state(h,FT_ABORT_SENT); |
507 | 511 | ||
@@ -513,14 +517,14 @@ void ft_aborting(H3270FT *h) | @@ -513,14 +517,14 @@ void ft_aborting(H3270FT *h) | ||
513 | static void ft_connected(H3270 *session, int ignored, void *dunno) | 517 | static void ft_connected(H3270 *session, int ignored, void *dunno) |
514 | { | 518 | { |
515 | if (!CONNECTED && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) | 519 | if (!CONNECTED && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) |
516 | - ft_complete(session->ft,_("Host disconnected, transfer cancelled")); | 520 | + ft_complete(get_ft_handle(session),_("Host disconnected, transfer cancelled")); |
517 | } | 521 | } |
518 | 522 | ||
519 | /* Process an abort from no longer being in 3270 mode. */ | 523 | /* Process an abort from no longer being in 3270 mode. */ |
520 | static void ft_in3270(H3270 *session, int ignored, void *dunno) | 524 | static void ft_in3270(H3270 *session, int ignored, void *dunno) |
521 | { | 525 | { |
522 | if (!IN_3270 && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) | 526 | if (!IN_3270 && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) |
523 | - ft_complete(session->ft,_("Not in 3270 mode, transfer cancelled")); | 527 | + ft_complete(get_ft_handle(session),_("Not in 3270 mode, transfer cancelled")); |
524 | } | 528 | } |
525 | 529 | ||
526 | LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session) | 530 | LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session) |
src/lib3270/ft_cut.c
@@ -58,9 +58,9 @@ | @@ -58,9 +58,9 @@ | ||
58 | 58 | ||
59 | /* Data stream conversion tables. */ | 59 | /* Data stream conversion tables. */ |
60 | 60 | ||
61 | -#define NQ 4 /* number of quadrants */ | ||
62 | -#define NE 77 /* number of elements per quadrant */ | ||
63 | -#define OTHER_2 2 /* "OTHER 2" quadrant (includes NULL) */ | 61 | +#define NQ 4 /* number of quadrants */ |
62 | +#define NE 77 /* number of elements per quadrant */ | ||
63 | +#define OTHER_2 2 /* "OTHER 2" quadrant (includes NULL) */ | ||
64 | #define XLATE_NULL 0xc1 /* translation of NULL */ | 64 | #define XLATE_NULL 0xc1 /* translation of NULL */ |
65 | 65 | ||
66 | static const char alphas[NE + 1] = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%&_()<+,-./:>?"; | 66 | static const char alphas[NE + 1] = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%&_()<+,-./:>?"; |
@@ -109,14 +109,14 @@ static const struct | @@ -109,14 +109,14 @@ static const struct | ||
109 | }; | 109 | }; |
110 | static const char table6[] = "abcdefghijklmnopqrstuvwxyz&-.,:+ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; | 110 | static const char table6[] = "abcdefghijklmnopqrstuvwxyz&-.,:+ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; |
111 | 111 | ||
112 | -static int quadrant = -1; | ||
113 | -static unsigned long expanded_length; | ||
114 | -static char *saved_errmsg = CN; | 112 | +// static int quadrant = -1; |
113 | +// static unsigned long expanded_length; | ||
114 | +// static char *saved_errmsg = CN; | ||
115 | 115 | ||
116 | -#define XLATE_NBUF 4 | ||
117 | -static int xlate_buffered = 0; /* buffer count */ | ||
118 | -static int xlate_buf_ix = 0; /* buffer index */ | ||
119 | -static unsigned char xlate_buf[XLATE_NBUF]; /* buffer */ | 116 | +#define XLATE_NBUF LIB3270_XLATE_NBUF |
117 | +// static int xlate_buffered = 0; /* buffer count */ | ||
118 | +// static int xlate_buf_ix = 0; /* buffer index */ | ||
119 | +// static unsigned char xlate_buf[XLATE_NBUF]; /* buffer */ | ||
120 | 120 | ||
121 | static void cut_control_code(H3270 *hSession); | 121 | static void cut_control_code(H3270 *hSession); |
122 | static void cut_data_request(H3270 *hSession); | 122 | static void cut_data_request(H3270 *hSession); |
@@ -127,7 +127,7 @@ static void cut_ack(H3270 *hSession); | @@ -127,7 +127,7 @@ static void cut_ack(H3270 *hSession); | ||
127 | static void cut_abort(H3270 *hSession, unsigned short code, const char *fmt, ...) printflike(3,4); | 127 | static void cut_abort(H3270 *hSession, unsigned short code, const char *fmt, ...) printflike(3,4); |
128 | 128 | ||
129 | static unsigned from6(unsigned char c); | 129 | static unsigned from6(unsigned char c); |
130 | -static int xlate_getc(void); | 130 | +static int xlate_getc(H3270FT *ft); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * Convert a buffer for uploading (host->local). Overwrites the buffer. | 133 | * Convert a buffer for uploading (host->local). Overwrites the buffer. |
@@ -138,8 +138,9 @@ static int xlate_getc(void); | @@ -138,8 +138,9 @@ static int xlate_getc(void); | ||
138 | */ | 138 | */ |
139 | static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | 139 | static int upload_convert(H3270 *hSession, unsigned char *buf, int len) |
140 | { | 140 | { |
141 | - unsigned char *ob0 = buf; | ||
142 | - unsigned char *ob = ob0; | 141 | + unsigned char * ob0 = buf; |
142 | + unsigned char * ob = ob0; | ||
143 | + H3270FT * ft = get_ft_handle(hSession); | ||
143 | 144 | ||
144 | while (len--) | 145 | while (len--) |
145 | { | 146 | { |
@@ -149,15 +150,15 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | @@ -149,15 +150,15 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | ||
149 | // int oq = -1; | 150 | // int oq = -1; |
150 | 151 | ||
151 | retry: | 152 | retry: |
152 | - if (quadrant < 0) | 153 | + if (ft->quadrant < 0) |
153 | { | 154 | { |
154 | /* Find the quadrant. */ | 155 | /* Find the quadrant. */ |
155 | - for (quadrant = 0; quadrant < NQ; quadrant++) | 156 | + for (ft->quadrant = 0; ft->quadrant < NQ; ft->quadrant++) |
156 | { | 157 | { |
157 | - if (c == conv[quadrant].selector) | 158 | + if (c == conv[ft->quadrant].selector) |
158 | break; | 159 | break; |
159 | } | 160 | } |
160 | - if (quadrant >= NQ) | 161 | + if (ft->quadrant >= NQ) |
161 | { | 162 | { |
162 | cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Data conversion error")); | 163 | cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Data conversion error")); |
163 | return -1; | 164 | return -1; |
@@ -178,7 +179,7 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | @@ -178,7 +179,7 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | ||
178 | { | 179 | { |
179 | /* Try a different quadrant. */ | 180 | /* Try a different quadrant. */ |
180 | // oq = quadrant; | 181 | // oq = quadrant; |
181 | - quadrant = -1; | 182 | + ft->quadrant = -1; |
182 | goto retry; | 183 | goto retry; |
183 | } | 184 | } |
184 | ix = ixp - alphas; | 185 | ix = ixp - alphas; |
@@ -187,19 +188,19 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | @@ -187,19 +188,19 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | ||
187 | * See if it's mapped by that quadrant, handling NULLs | 188 | * See if it's mapped by that quadrant, handling NULLs |
188 | * specially. | 189 | * specially. |
189 | */ | 190 | */ |
190 | - if (quadrant != OTHER_2 && c != XLATE_NULL && !conv[quadrant].xlate[ix]) | 191 | + if (ft->quadrant != OTHER_2 && c != XLATE_NULL && !conv[ft->quadrant].xlate[ix]) |
191 | { | 192 | { |
192 | /* Try a different quadrant. */ | 193 | /* Try a different quadrant. */ |
193 | // oq = quadrant; | 194 | // oq = quadrant; |
194 | - quadrant = -1; | 195 | + ft->quadrant = -1; |
195 | goto retry; | 196 | goto retry; |
196 | } | 197 | } |
197 | 198 | ||
198 | /* Map it. */ | 199 | /* Map it. */ |
199 | - c = conv[quadrant].xlate[ix]; | ||
200 | - if (ascii_flag && cr_flag && (c == '\r' || c == 0x1a)) | 200 | + c = conv[ft->quadrant].xlate[ix]; |
201 | + if (ft->ascii_flag && ft->cr_flag && (c == '\r' || c == 0x1a)) | ||
201 | continue; | 202 | continue; |
202 | - if (ascii_flag && remap_flag) | 203 | + if (ft->ascii_flag && ft->remap_flag) |
203 | c = ft2asc[c]; | 204 | c = ft2asc[c]; |
204 | *ob++ = c; | 205 | *ob++ = c; |
205 | } | 206 | } |
@@ -207,60 +208,68 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | @@ -207,60 +208,68 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | ||
207 | return ob - ob0; | 208 | return ob - ob0; |
208 | } | 209 | } |
209 | 210 | ||
210 | -/* Convert a buffer for downloading (local->host). */ | ||
211 | -static int | ||
212 | -download_convert(unsigned const char *buf, unsigned len, unsigned char *xobuf) | 211 | +/** |
212 | + * Convert a buffer for downloading (local->host). | ||
213 | + */ | ||
214 | +static int download_convert(unsigned const char *buf, unsigned len, unsigned char *xobuf) | ||
213 | { | 215 | { |
214 | - unsigned char *ob0 = xobuf; | ||
215 | - unsigned char *ob = ob0; | 216 | + H3270FT * ft = get_ft_handle(&h3270); |
217 | + unsigned char * ob0 = xobuf; | ||
218 | + unsigned char * ob = ob0; | ||
216 | 219 | ||
217 | - while (len--) { | 220 | + while (len--) |
221 | + { | ||
218 | unsigned char c = *buf++; | 222 | unsigned char c = *buf++; |
219 | unsigned char *ixp; | 223 | unsigned char *ixp; |
220 | unsigned ix; | 224 | unsigned ix; |
221 | int oq; | 225 | int oq; |
222 | 226 | ||
223 | /* Handle nulls separately. */ | 227 | /* Handle nulls separately. */ |
224 | - if (!c) { | ||
225 | - if (quadrant != OTHER_2) { | ||
226 | - quadrant = OTHER_2; | ||
227 | - *ob++ = conv[quadrant].selector; | 228 | + if (!c) |
229 | + { | ||
230 | + if (ft->quadrant != OTHER_2) | ||
231 | + { | ||
232 | + ft->quadrant = OTHER_2; | ||
233 | + *ob++ = conv[ft->quadrant].selector; | ||
228 | } | 234 | } |
229 | *ob++ = XLATE_NULL; | 235 | *ob++ = XLATE_NULL; |
230 | continue; | 236 | continue; |
231 | } | 237 | } |
232 | 238 | ||
233 | /* Translate. */ | 239 | /* Translate. */ |
234 | - if (ascii_flag && remap_flag) | 240 | + if (ft->ascii_flag && ft->remap_flag) |
235 | c = asc2ft[c]; | 241 | c = asc2ft[c]; |
236 | 242 | ||
237 | /* Quadrant already defined. */ | 243 | /* Quadrant already defined. */ |
238 | - if (quadrant >= 0) { | ||
239 | - ixp = (unsigned char *)memchr(conv[quadrant].xlate, c, | ||
240 | - NE); | ||
241 | - if (ixp != (unsigned char *)NULL) { | ||
242 | - ix = ixp - conv[quadrant].xlate; | 244 | + if (ft->quadrant >= 0) { |
245 | + ixp = (unsigned char *)memchr(conv[ft->quadrant].xlate, c, NE); | ||
246 | + if (ixp != (unsigned char *)NULL) | ||
247 | + { | ||
248 | + ix = ixp - conv[ft->quadrant].xlate; | ||
243 | *ob++ = asc2ebc[(int)alphas[ix]]; | 249 | *ob++ = asc2ebc[(int)alphas[ix]]; |
244 | continue; | 250 | continue; |
245 | } | 251 | } |
246 | } | 252 | } |
247 | 253 | ||
248 | /* Locate a quadrant. */ | 254 | /* Locate a quadrant. */ |
249 | - oq = quadrant; | ||
250 | - for (quadrant = 0; quadrant < NQ; quadrant++) { | ||
251 | - if (quadrant == oq) | 255 | + oq = ft->quadrant; |
256 | + for (ft->quadrant = 0; ft->quadrant < NQ; ft->quadrant++) | ||
257 | + { | ||
258 | + if (ft->quadrant == oq) | ||
252 | continue; | 259 | continue; |
253 | - ixp = (unsigned char *)memchr(conv[quadrant].xlate, c, | ||
254 | - NE); | 260 | + |
261 | + ixp = (unsigned char *)memchr(conv[ft->quadrant].xlate, c, NE); | ||
262 | + | ||
255 | if (ixp == (unsigned char *)NULL) | 263 | if (ixp == (unsigned char *)NULL) |
256 | continue; | 264 | continue; |
257 | - ix = ixp - conv[quadrant].xlate; | ||
258 | - *ob++ = conv[quadrant].selector; | 265 | + ix = ixp - conv[ft->quadrant].xlate; |
266 | + *ob++ = conv[ft->quadrant].selector; | ||
259 | *ob++ = asc2ebc[(int)alphas[ix]]; | 267 | *ob++ = asc2ebc[(int)alphas[ix]]; |
260 | break; | 268 | break; |
261 | } | 269 | } |
262 | - if (quadrant >= NQ) { | ||
263 | - quadrant = -1; | 270 | + if (ft->quadrant >= NQ) |
271 | + { | ||
272 | + ft->quadrant = -1; | ||
264 | fprintf(stderr, "Oops\n"); | 273 | fprintf(stderr, "Oops\n"); |
265 | continue; | 274 | continue; |
266 | } | 275 | } |
@@ -304,10 +313,11 @@ void ft_cut_data(H3270 *hSession) | @@ -304,10 +313,11 @@ void ft_cut_data(H3270 *hSession) | ||
304 | */ | 313 | */ |
305 | static void cut_control_code(H3270 *hSession) | 314 | static void cut_control_code(H3270 *hSession) |
306 | { | 315 | { |
307 | - unsigned short code; | ||
308 | - char *buf; | ||
309 | - char *bp; | ||
310 | - int i; | 316 | + H3270FT * ft = get_ft_handle(hSession); |
317 | + unsigned short code; | ||
318 | + char * buf; | ||
319 | + char * bp; | ||
320 | + int i; | ||
311 | 321 | ||
312 | trace_ds(hSession,"< FT CONTROL_CODE "); | 322 | trace_ds(hSession,"< FT CONTROL_CODE "); |
313 | code = (hSession->ea_buf[O_CC_STATUS_CODE].cc << 8) | hSession->ea_buf[O_CC_STATUS_CODE + 1].cc; | 323 | code = (hSession->ea_buf[O_CC_STATUS_CODE].cc << 8) | hSession->ea_buf[O_CC_STATUS_CODE + 1].cc; |
@@ -317,18 +327,18 @@ static void cut_control_code(H3270 *hSession) | @@ -317,18 +327,18 @@ static void cut_control_code(H3270 *hSession) | ||
317 | case SC_HOST_ACK: | 327 | case SC_HOST_ACK: |
318 | trace_ds(hSession,"HOST_ACK\n"); | 328 | trace_ds(hSession,"HOST_ACK\n"); |
319 | hSession->cut_xfer_in_progress = 1; | 329 | hSession->cut_xfer_in_progress = 1; |
320 | - expanded_length = 0; | ||
321 | - quadrant = -1; | ||
322 | - xlate_buffered = 0; | 330 | + ft->expanded_length = 0; |
331 | + ft->quadrant = -1; | ||
332 | + ft->xlate_buffered = 0; | ||
323 | cut_ack(hSession); | 333 | cut_ack(hSession); |
324 | - ft_running(NULL,True); | 334 | + ft_running(hSession->ft,True); |
325 | break; | 335 | break; |
326 | 336 | ||
327 | case SC_XFER_COMPLETE: | 337 | case SC_XFER_COMPLETE: |
328 | trace_ds(hSession,"XFER_COMPLETE\n"); | 338 | trace_ds(hSession,"XFER_COMPLETE\n"); |
329 | cut_ack(hSession); | 339 | cut_ack(hSession); |
330 | hSession->cut_xfer_in_progress = 0; | 340 | hSession->cut_xfer_in_progress = 0; |
331 | - ft_complete(NULL,N_( "Complete" ) ); | 341 | + ft_complete(ft,N_( "Complete" ) ); |
332 | break; | 342 | break; |
333 | 343 | ||
334 | case SC_ABORT_FILE: | 344 | case SC_ABORT_FILE: |
@@ -337,10 +347,10 @@ static void cut_control_code(H3270 *hSession) | @@ -337,10 +347,10 @@ static void cut_control_code(H3270 *hSession) | ||
337 | hSession->cut_xfer_in_progress = 0; | 347 | hSession->cut_xfer_in_progress = 0; |
338 | cut_ack(hSession); | 348 | cut_ack(hSession); |
339 | 349 | ||
340 | - if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && saved_errmsg != CN) | 350 | + if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && ft->saved_errmsg != CN) |
341 | { | 351 | { |
342 | - buf = saved_errmsg; | ||
343 | - saved_errmsg = CN; | 352 | + buf = ft->saved_errmsg; |
353 | + ft->saved_errmsg = CN; | ||
344 | } | 354 | } |
345 | else | 355 | else |
346 | { | 356 | { |
@@ -363,7 +373,7 @@ static void cut_control_code(H3270 *hSession) | @@ -363,7 +373,7 @@ static void cut_control_code(H3270 *hSession) | ||
363 | if (!*buf) | 373 | if (!*buf) |
364 | strcpy(buf, N_( "Transfer cancelled by host" ) ); | 374 | strcpy(buf, N_( "Transfer cancelled by host" ) ); |
365 | } | 375 | } |
366 | - ft_complete(NULL,buf); | 376 | + ft_complete(hSession->ft,buf); |
367 | lib3270_free(buf); | 377 | lib3270_free(buf); |
368 | break; | 378 | break; |
369 | 379 | ||
@@ -379,12 +389,13 @@ static void cut_control_code(H3270 *hSession) | @@ -379,12 +389,13 @@ static void cut_control_code(H3270 *hSession) | ||
379 | */ | 389 | */ |
380 | static void cut_data_request(H3270 *hSession) | 390 | static void cut_data_request(H3270 *hSession) |
381 | { | 391 | { |
382 | - unsigned char seq = hSession->ea_buf[O_DR_FRAME_SEQ].cc; | ||
383 | - int count; | ||
384 | - unsigned char cs; | ||
385 | - int c; | ||
386 | - int i; | ||
387 | - unsigned char attr; | 392 | + H3270FT * ft = get_ft_handle(hSession); |
393 | + unsigned char seq = hSession->ea_buf[O_DR_FRAME_SEQ].cc; | ||
394 | + int count; | ||
395 | + unsigned char cs; | ||
396 | + int c; | ||
397 | + int i; | ||
398 | + unsigned char attr; | ||
388 | 399 | ||
389 | trace_ds(hSession,"< FT DATA_REQUEST %u\n", from6(seq)); | 400 | trace_ds(hSession,"< FT DATA_REQUEST %u\n", from6(seq)); |
390 | if (lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) | 401 | if (lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) |
@@ -393,15 +404,18 @@ static void cut_data_request(H3270 *hSession) | @@ -393,15 +404,18 @@ static void cut_data_request(H3270 *hSession) | ||
393 | return; | 404 | return; |
394 | } | 405 | } |
395 | 406 | ||
407 | + | ||
396 | /* Copy data into the screen buffer. */ | 408 | /* Copy data into the screen buffer. */ |
397 | count = 0; | 409 | count = 0; |
398 | - while (count < O_UP_MAX && (c = xlate_getc()) != EOF) { | 410 | + while (count < O_UP_MAX && (c = xlate_getc(hSession->ft)) != EOF) |
411 | + { | ||
399 | ctlr_add(hSession,O_UP_DATA + count, c, 0); | 412 | ctlr_add(hSession,O_UP_DATA + count, c, 0); |
400 | count++; | 413 | count++; |
401 | } | 414 | } |
402 | 415 | ||
403 | /* Check for errors. */ | 416 | /* Check for errors. */ |
404 | - if (ferror(((H3270FT *) hSession->ft)->local_file)) { | 417 | + if (ferror(((H3270FT *) hSession->ft)->local_file)) |
418 | + { | ||
405 | int j; | 419 | int j; |
406 | 420 | ||
407 | /* Clean out any data we may have written. */ | 421 | /* Clean out any data we may have written. */ |
@@ -438,8 +452,8 @@ static void cut_data_request(H3270 *hSession) | @@ -438,8 +452,8 @@ static void cut_data_request(H3270 *hSession) | ||
438 | 452 | ||
439 | /* Send it up to the host. */ | 453 | /* Send it up to the host. */ |
440 | trace_ds(hSession,"> FT DATA %u\n", from6(seq)); | 454 | trace_ds(hSession,"> FT DATA %u\n", from6(seq)); |
441 | - ft_update_length(NULL); | ||
442 | - expanded_length += count; | 455 | + ft_update_length(ft); |
456 | + ft->expanded_length += count; | ||
443 | 457 | ||
444 | lib3270_enter(hSession); | 458 | lib3270_enter(hSession); |
445 | } | 459 | } |
@@ -473,13 +487,14 @@ from6(unsigned char c) | @@ -473,13 +487,14 @@ from6(unsigned char c) | ||
473 | */ | 487 | */ |
474 | static void cut_data(H3270 *hSession) | 488 | static void cut_data(H3270 *hSession) |
475 | { | 489 | { |
490 | + H3270FT *ft = get_ft_handle(hSession); | ||
476 | static unsigned char cvbuf[O_RESPONSE - O_DT_DATA]; | 491 | static unsigned char cvbuf[O_RESPONSE - O_DT_DATA]; |
477 | unsigned short raw_length; | 492 | unsigned short raw_length; |
478 | int conv_length; | 493 | int conv_length; |
479 | register int i; | 494 | register int i; |
480 | 495 | ||
481 | trace_ds(hSession,"< FT DATA\n"); | 496 | trace_ds(hSession,"< FT DATA\n"); |
482 | - if (((H3270FT *) hSession->ft)->state == LIB3270_FT_STATE_ABORT_WAIT) | 497 | + if (ft->state == LIB3270_FT_STATE_ABORT_WAIT) |
483 | { | 498 | { |
484 | cut_abort(hSession,SC_ABORT_FILE,"%s",_("Transfer cancelled by user")); | 499 | cut_abort(hSession,SC_ABORT_FILE,"%s",_("Transfer cancelled by user")); |
485 | return; | 500 | return; |
@@ -510,14 +525,14 @@ static void cut_data(H3270 *hSession) | @@ -510,14 +525,14 @@ static void cut_data(H3270 *hSession) | ||
510 | return; | 525 | return; |
511 | 526 | ||
512 | /* Write it to the file. */ | 527 | /* Write it to the file. */ |
513 | - if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) hSession->ft)->local_file) == 0) | 528 | + if (fwrite((char *)cvbuf, conv_length, 1, ft->local_file) == 0) |
514 | { | 529 | { |
515 | cut_abort(hSession,SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); | 530 | cut_abort(hSession,SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); |
516 | } | 531 | } |
517 | else | 532 | else |
518 | { | 533 | { |
519 | - ft_length += conv_length; | ||
520 | - ft_update_length(NULL); | 534 | + ft->ft_length += conv_length; |
535 | + ft_update_length(ft); | ||
521 | cut_ack(hSession); | 536 | cut_ack(hSession); |
522 | } | 537 | } |
523 | } | 538 | } |
@@ -536,14 +551,15 @@ static void cut_ack(H3270 *hSession) | @@ -536,14 +551,15 @@ static void cut_ack(H3270 *hSession) | ||
536 | */ | 551 | */ |
537 | static void cut_abort(H3270 *hSession, unsigned short reason, const char *fmt, ...) | 552 | static void cut_abort(H3270 *hSession, unsigned short reason, const char *fmt, ...) |
538 | { | 553 | { |
539 | - va_list args; | 554 | + H3270FT * ft = get_ft_handle(hSession); |
555 | + va_list args; | ||
540 | 556 | ||
541 | - if(saved_errmsg) | ||
542 | - lib3270_free(saved_errmsg); | 557 | + if(ft->saved_errmsg) |
558 | + lib3270_free(ft->saved_errmsg); | ||
543 | 559 | ||
544 | /* Save the error message. */ | 560 | /* Save the error message. */ |
545 | va_start(args, fmt); | 561 | va_start(args, fmt); |
546 | - saved_errmsg = lib3270_vsprintf(fmt, args); | 562 | + ft->saved_errmsg = lib3270_vsprintf(fmt, args); |
547 | va_end(args); | 563 | va_end(args); |
548 | 564 | ||
549 | /* Send the abort sequence. */ | 565 | /* Send the abort sequence. */ |
@@ -556,15 +572,15 @@ static void cut_abort(H3270 *hSession, unsigned short reason, const char *fmt, . | @@ -556,15 +572,15 @@ static void cut_abort(H3270 *hSession, unsigned short reason, const char *fmt, . | ||
556 | lib3270_pfkey(hSession,2); | 572 | lib3270_pfkey(hSession,2); |
557 | 573 | ||
558 | /* Update the in-progress pop-up. */ | 574 | /* Update the in-progress pop-up. */ |
559 | - ft_aborting(NULL); | 575 | + ft_aborting(ft); |
560 | } | 576 | } |
561 | 577 | ||
562 | -/* | 578 | +/** |
563 | * Get the next translated character from the local file. | 579 | * Get the next translated character from the local file. |
564 | - * Returns the character (in EBCDIC), or EOF. | 580 | + * |
581 | + * @return the character (in EBCDIC), or EOF. | ||
565 | */ | 582 | */ |
566 | -static int | ||
567 | -xlate_getc(void) | 583 | +static int xlate_getc(H3270FT *ft) |
568 | { | 584 | { |
569 | int r; | 585 | int r; |
570 | int c; | 586 | int c; |
@@ -573,25 +589,29 @@ xlate_getc(void) | @@ -573,25 +589,29 @@ xlate_getc(void) | ||
573 | int nc; | 589 | int nc; |
574 | 590 | ||
575 | /* If there is a data buffered, return it. */ | 591 | /* If there is a data buffered, return it. */ |
576 | - if (xlate_buffered) { | ||
577 | - r = xlate_buf[xlate_buf_ix]; | ||
578 | - xlate_buf_ix++; | ||
579 | - xlate_buffered--; | 592 | + if (ft->xlate_buffered) |
593 | + { | ||
594 | + r = ft->xlate_buf[ft->xlate_buf_ix]; | ||
595 | + ft->xlate_buf_ix++; | ||
596 | + ft->xlate_buffered--; | ||
580 | return r; | 597 | return r; |
581 | } | 598 | } |
582 | 599 | ||
583 | /* Get the next byte from the file. */ | 600 | /* Get the next byte from the file. */ |
584 | - c = fgetc(((H3270FT *) h3270.ft)->local_file); | 601 | + c = fgetc(ft->local_file); |
585 | if (c == EOF) | 602 | if (c == EOF) |
586 | return c; | 603 | return c; |
587 | - ft_length++; | 604 | + ft->ft_length++; |
588 | 605 | ||
589 | /* Expand it. */ | 606 | /* Expand it. */ |
590 | - if (ascii_flag && cr_flag && !ft_last_cr && c == '\n') { | 607 | + if (ft->ascii_flag && ft->cr_flag && !ft->ft_last_cr && c == '\n') |
608 | + { | ||
591 | nc = download_convert((unsigned const char *)"\r", 1, cbuf); | 609 | nc = download_convert((unsigned const char *)"\r", 1, cbuf); |
592 | - } else { | 610 | + } |
611 | + else | ||
612 | + { | ||
593 | nc = 0; | 613 | nc = 0; |
594 | - ft_last_cr = (c == '\r'); | 614 | + ft->ft_last_cr = (c == '\r') ? 1 : 0; |
595 | } | 615 | } |
596 | 616 | ||
597 | /* Convert it. */ | 617 | /* Convert it. */ |
@@ -600,12 +620,13 @@ xlate_getc(void) | @@ -600,12 +620,13 @@ xlate_getc(void) | ||
600 | 620 | ||
601 | /* Return it and buffer what's left. */ | 621 | /* Return it and buffer what's left. */ |
602 | r = cbuf[0]; | 622 | r = cbuf[0]; |
603 | - if (nc > 1) { | 623 | + if (nc > 1) |
624 | + { | ||
604 | int i; | 625 | int i; |
605 | 626 | ||
606 | for (i = 1; i < nc; i++) | 627 | for (i = 1; i < nc; i++) |
607 | - xlate_buf[xlate_buffered++] = cbuf[i]; | ||
608 | - xlate_buf_ix = 0; | 628 | + ft->xlate_buf[ft->xlate_buffered++] = cbuf[i]; |
629 | + ft->xlate_buf_ix = 0; | ||
609 | } | 630 | } |
610 | return r; | 631 | return r; |
611 | } | 632 | } |
src/lib3270/ft_dft.c
@@ -59,34 +59,35 @@ | @@ -59,34 +59,35 @@ | ||
59 | // extern unsigned char aid; | 59 | // extern unsigned char aid; |
60 | 60 | ||
61 | /* Macros. */ | 61 | /* Macros. */ |
62 | -#define OPEN_MSG "FT:MSG" /* Open request for message */ | 62 | +#define OPEN_MSG "FT:MSG" /* Open request for message */ |
63 | #define END_TRANSFER "TRANS03" /* Message for xfer complete */ | 63 | #define END_TRANSFER "TRANS03" /* Message for xfer complete */ |
64 | 64 | ||
65 | #define DFT_MIN_BUF 256 | 65 | #define DFT_MIN_BUF 256 |
66 | #define DFT_MAX_BUF 32768 | 66 | #define DFT_MAX_BUF 32768 |
67 | 67 | ||
68 | /* Typedefs. */ | 68 | /* Typedefs. */ |
69 | -struct data_buffer { | ||
70 | - char sf_length[2]; /* SF length = 0x0023 */ | ||
71 | - char sf_d0; /* 0xD0 */ | ||
72 | - char sf_request_type[2]; /* request type */ | ||
73 | - char compress_indic[2]; /* 0xc080 */ | ||
74 | - char begin_data; /* 0x61 */ | ||
75 | - char data_length[2]; /* Data Length in 3270 byte order+5 */ | ||
76 | - char data[256]; /* The actual data */ | 69 | +struct data_buffer |
70 | +{ | ||
71 | + char sf_length[2]; /**< SF length = 0x0023 */ | ||
72 | + char sf_d0; /**< 0xD0 */ | ||
73 | + char sf_request_type[2]; /**< request type */ | ||
74 | + char compress_indic[2]; /**< 0xc080 */ | ||
75 | + char begin_data; /**< 0x61 */ | ||
76 | + char data_length[2]; /**< Data Length in 3270 byte order+5 */ | ||
77 | + char data[256]; /**< The actual data */ | ||
77 | }; | 78 | }; |
78 | 79 | ||
79 | /* Globals. */ | 80 | /* Globals. */ |
80 | // int dft_buffersize = 0; /* Buffer size (LIMIN, LIMOUT) */ | 81 | // int dft_buffersize = 0; /* Buffer size (LIMIN, LIMOUT) */ |
81 | 82 | ||
82 | /* Statics. */ | 83 | /* Statics. */ |
83 | -static Boolean message_flag = False; /* Open Request for msg received */ | ||
84 | -static int dft_eof; | ||
85 | -static unsigned long recnum; | 84 | +// static Boolean message_flag = False; /* Open Request for msg received */ |
85 | +// static int dft_eof; | ||
86 | +// static unsigned long recnum; | ||
86 | // static char *abort_string = CN; | 87 | // static char *abort_string = CN; |
87 | -static unsigned char *dft_savebuf = NULL; | ||
88 | -static int dft_savebuf_len = 0; | ||
89 | -static int dft_savebuf_max = 0; | 88 | +// static unsigned char *dft_savebuf = NULL; |
89 | +// static int dft_savebuf_len = 0; | ||
90 | +// static int dft_savebuf_max = 0; | ||
90 | 91 | ||
91 | static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...); | 92 | static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...); |
92 | 93 | ||
@@ -158,10 +159,11 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused) | @@ -158,10 +159,11 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused) | ||
158 | /* Process an Open request. */ | 159 | /* Process an Open request. */ |
159 | static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp) | 160 | static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp) |
160 | { | 161 | { |
161 | - char *name = "?"; | ||
162 | - char namebuf[8]; | ||
163 | - char *s; | ||
164 | - unsigned short recsz = 0; | 162 | + H3270FT * ft = get_ft_handle(hSession); |
163 | + char * name = "?"; | ||
164 | + char namebuf[8]; | ||
165 | + char * s; | ||
166 | + unsigned short recsz = 0; | ||
165 | 167 | ||
166 | if (len == 0x23) | 168 | if (len == 0x23) |
167 | { | 169 | { |
@@ -199,15 +201,15 @@ static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char | @@ -199,15 +201,15 @@ static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char | ||
199 | } | 201 | } |
200 | 202 | ||
201 | if (!strcmp(namebuf, OPEN_MSG)) | 203 | if (!strcmp(namebuf, OPEN_MSG)) |
202 | - message_flag = True; | 204 | + ft->message_flag = 1; |
203 | else | 205 | else |
204 | { | 206 | { |
205 | - message_flag = False; | ||
206 | - ft_running(hSession->ft,False); | 207 | + ft->message_flag = 0; |
208 | + ft_running(ft,False); | ||
207 | } | 209 | } |
208 | 210 | ||
209 | - dft_eof = False; | ||
210 | - recnum = 1; | 211 | + ft->dft_eof = 0; |
212 | + ft->recnum = 1; | ||
211 | 213 | ||
212 | /* Acknowledge the Open. */ | 214 | /* Acknowledge the Open. */ |
213 | trace_ds(hSession,"> WriteStructuredField FileTransferData OpenAck\n"); | 215 | trace_ds(hSession,"> WriteStructuredField FileTransferData OpenAck\n"); |
@@ -231,10 +233,11 @@ static void dft_insert_request(H3270 *hSession) | @@ -231,10 +233,11 @@ static void dft_insert_request(H3270 *hSession) | ||
231 | static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | 233 | static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) |
232 | { | 234 | { |
233 | /* Received a data buffer, get the length and process it */ | 235 | /* Received a data buffer, get the length and process it */ |
234 | - int my_length; | ||
235 | - unsigned char *cp; | 236 | + H3270FT * ft = get_ft_handle(hSession); |
237 | + int my_length; | ||
238 | + unsigned char * cp; | ||
236 | 239 | ||
237 | - if(!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) | 240 | + if(!ft->message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) |
238 | { | 241 | { |
239 | dft_abort(hSession,TR_DATA_INSERT, "%s", _("Transfer cancelled by user") ); | 242 | dft_abort(hSession,TR_DATA_INSERT, "%s", _("Transfer cancelled by user") ); |
240 | return; | 243 | return; |
@@ -248,13 +251,13 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -248,13 +251,13 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
248 | /* Adjust for 5 extra count */ | 251 | /* Adjust for 5 extra count */ |
249 | my_length -= 5; | 252 | my_length -= 5; |
250 | 253 | ||
251 | - trace_ds(hSession," Data(rec=%lu) %d bytes\n", recnum, my_length); | 254 | + trace_ds(hSession," Data(rec=%lu) %d bytes\n", ft->recnum, my_length); |
252 | 255 | ||
253 | /* | 256 | /* |
254 | * First, check to see if we have message data or file data. | 257 | * First, check to see if we have message data or file data. |
255 | * Message data will result in a popup. | 258 | * Message data will result in a popup. |
256 | */ | 259 | */ |
257 | - if (message_flag) | 260 | + if (ft->message_flag) |
258 | { | 261 | { |
259 | /* Data is from a message */ | 262 | /* Data is from a message */ |
260 | unsigned char *msgp; | 263 | unsigned char *msgp; |
@@ -281,8 +284,8 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -281,8 +284,8 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
281 | else if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && ((H3270FT *) hSession->ft)->abort_string != CN) | 284 | else if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && ((H3270FT *) hSession->ft)->abort_string != CN) |
282 | { | 285 | { |
283 | lib3270_free(msgp); | 286 | lib3270_free(msgp); |
284 | - ft_complete(hSession->ft,((H3270FT *) hSession->ft)->abort_string); | ||
285 | - lib3270_free(((H3270FT *) hSession->ft)->abort_string); | 287 | + ft_complete(ft,ft->abort_string); |
288 | + lib3270_free(ft->abort_string); | ||
286 | } | 289 | } |
287 | else | 290 | else |
288 | { | 291 | { |
@@ -293,17 +296,20 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -293,17 +296,20 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
293 | /* Write the data out to the file. */ | 296 | /* Write the data out to the file. */ |
294 | int rv = 1; | 297 | int rv = 1; |
295 | 298 | ||
296 | - if (ascii_flag && remap_flag) { | 299 | + if (ft->ascii_flag && ft->remap_flag) |
300 | + { | ||
297 | /* Filter. */ | 301 | /* Filter. */ |
298 | unsigned char *s = (unsigned char *)data_bufr->data; | 302 | unsigned char *s = (unsigned char *)data_bufr->data; |
299 | unsigned len = my_length; | 303 | unsigned len = my_length; |
300 | 304 | ||
301 | - while (len--) { | 305 | + while (len--) |
306 | + { | ||
302 | *s = ft2asc[*s]; | 307 | *s = ft2asc[*s]; |
303 | s++; | 308 | s++; |
304 | } | 309 | } |
305 | } | 310 | } |
306 | - if (ascii_flag && cr_flag) { | 311 | + if (ft->ascii_flag && ft->cr_flag) |
312 | + { | ||
307 | char *s = (char *)data_bufr->data; | 313 | char *s = (char *)data_bufr->data; |
308 | unsigned len = my_length; | 314 | unsigned len = my_length; |
309 | 315 | ||
@@ -316,7 +322,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -316,7 +322,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
316 | rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); | 322 | rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); |
317 | if (rv == 0) | 323 | if (rv == 0) |
318 | break; | 324 | break; |
319 | - ft_length += l; | 325 | + ft->ft_length += l; |
320 | } | 326 | } |
321 | if (l < len) | 327 | if (l < len) |
322 | l++; | 328 | l++; |
@@ -325,7 +331,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -325,7 +331,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
325 | } | 331 | } |
326 | } else { | 332 | } else { |
327 | rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); | 333 | rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); |
328 | - ft_length += my_length; | 334 | + ft->ft_length += my_length; |
329 | } | 335 | } |
330 | 336 | ||
331 | if (!rv) { | 337 | if (!rv) { |
@@ -334,11 +340,11 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -334,11 +340,11 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
334 | } | 340 | } |
335 | 341 | ||
336 | /* Add up amount transferred. */ | 342 | /* Add up amount transferred. */ |
337 | - ft_update_length((H3270FT *) hSession->ft); | 343 | + ft_update_length(ft); |
338 | } | 344 | } |
339 | 345 | ||
340 | /* Send an acknowledgement frame back. */ | 346 | /* Send an acknowledgement frame back. */ |
341 | - trace_ds(hSession,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum); | 347 | + trace_ds(hSession,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", ft->recnum); |
342 | hSession->obptr = hSession->obuf; | 348 | hSession->obptr = hSession->obuf; |
343 | space3270out(hSession,12); | 349 | space3270out(hSession,12); |
344 | *hSession->obptr++ = AID_SF; | 350 | *hSession->obptr++ = AID_SF; |
@@ -346,8 +352,8 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -346,8 +352,8 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
346 | *hSession->obptr++ = SF_TRANSFER_DATA; | 352 | *hSession->obptr++ = SF_TRANSFER_DATA; |
347 | SET16(hSession->obptr, TR_NORMAL_REPLY); | 353 | SET16(hSession->obptr, TR_NORMAL_REPLY); |
348 | SET16(hSession->obptr, TR_RECNUM_HDR); | 354 | SET16(hSession->obptr, TR_RECNUM_HDR); |
349 | - SET32(hSession->obptr, recnum); | ||
350 | - recnum++; | 355 | + SET32(hSession->obptr, ft->recnum); |
356 | + ft->recnum++; | ||
351 | net_output(hSession); | 357 | net_output(hSession); |
352 | } | 358 | } |
353 | 359 | ||
@@ -361,14 +367,15 @@ static void dft_set_cur_req(H3270 *hSession) | @@ -361,14 +367,15 @@ static void dft_set_cur_req(H3270 *hSession) | ||
361 | /* Process a Get request. */ | 367 | /* Process a Get request. */ |
362 | static void dft_get_request(H3270 *hSession) | 368 | static void dft_get_request(H3270 *hSession) |
363 | { | 369 | { |
364 | - int numbytes; | ||
365 | - size_t numread; | ||
366 | - size_t total_read = 0; | ||
367 | - unsigned char *bufptr; | 370 | + int numbytes; |
371 | + size_t numread; | ||
372 | + size_t total_read = 0; | ||
373 | + unsigned char * bufptr; | ||
374 | + H3270FT * ft = get_ft_handle(hSession); | ||
368 | 375 | ||
369 | trace_ds(hSession," Get\n"); | 376 | trace_ds(hSession," Get\n"); |
370 | 377 | ||
371 | - if (!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) | 378 | + if (!ft->message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) |
372 | { | 379 | { |
373 | dft_abort(hSession,TR_GET_REQ, _( "Transfer cancelled by user" ) ); | 380 | dft_abort(hSession,TR_GET_REQ, _( "Transfer cancelled by user" ) ); |
374 | return; | 381 | return; |
@@ -376,43 +383,46 @@ static void dft_get_request(H3270 *hSession) | @@ -376,43 +383,46 @@ static void dft_get_request(H3270 *hSession) | ||
376 | 383 | ||
377 | /* Read a buffer's worth. */ | 384 | /* Read a buffer's worth. */ |
378 | set_dft_buffersize(hSession); | 385 | set_dft_buffersize(hSession); |
379 | - space3270out(hSession,h3270.dft_buffersize); | 386 | + space3270out(hSession,hSession->dft_buffersize); |
380 | numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ | 387 | numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ |
381 | bufptr = h3270.obuf + 17; | 388 | bufptr = h3270.obuf + 17; |
382 | 389 | ||
383 | - while (!dft_eof && numbytes) { | ||
384 | - if (ascii_flag && cr_flag) { | 390 | + while (!ft->dft_eof && numbytes) |
391 | + { | ||
392 | + if (ft->ascii_flag && ft->cr_flag) | ||
393 | + { | ||
385 | int c; | 394 | int c; |
386 | 395 | ||
387 | /* Read one byte and do CR/LF translation. */ | 396 | /* Read one byte and do CR/LF translation. */ |
388 | - c = fgetc(((H3270FT *) h3270.ft)->local_file); | 397 | + c = fgetc(ft->local_file); |
389 | if (c == EOF) { | 398 | if (c == EOF) { |
390 | break; | 399 | break; |
391 | } | 400 | } |
392 | - if (!ft_last_cr && c == '\n') { | 401 | + if (!ft->ft_last_cr && c == '\n') |
402 | + { | ||
393 | if (numbytes < 2) { | 403 | if (numbytes < 2) { |
394 | /* | 404 | /* |
395 | * Not enough room to expand NL to | 405 | * Not enough room to expand NL to |
396 | * CR/LF. | 406 | * CR/LF. |
397 | */ | 407 | */ |
398 | - ungetc(c, ((H3270FT *) h3270.ft)->local_file); | 408 | + ungetc(c, ft->local_file); |
399 | break; | 409 | break; |
400 | } | 410 | } |
401 | *bufptr++ = '\r'; | 411 | *bufptr++ = '\r'; |
402 | numbytes--; | 412 | numbytes--; |
403 | total_read++; | 413 | total_read++; |
404 | } | 414 | } |
405 | - ft_last_cr = (c == '\r'); | ||
406 | - *bufptr++ = remap_flag? asc2ft[c]: c; | 415 | + ft->ft_last_cr = (c == '\r') ? 1 : 0; |
416 | + *bufptr++ = ft->remap_flag? asc2ft[c]: c; | ||
407 | numbytes--; | 417 | numbytes--; |
408 | total_read++; | 418 | total_read++; |
409 | } else { | 419 | } else { |
410 | /* Binary read. */ | 420 | /* Binary read. */ |
411 | - numread = fread(bufptr, 1, numbytes, ((H3270FT *) h3270.ft)->local_file); | 421 | + numread = fread(bufptr, 1, numbytes, ft->local_file); |
412 | if (numread <= 0) { | 422 | if (numread <= 0) { |
413 | break; | 423 | break; |
414 | } | 424 | } |
415 | - if (ascii_flag && remap_flag) { | 425 | + if (ft->ascii_flag && ft->remap_flag) { |
416 | unsigned char *s = bufptr; | 426 | unsigned char *s = bufptr; |
417 | int i = numread; | 427 | int i = numread; |
418 | 428 | ||
@@ -426,7 +436,8 @@ static void dft_get_request(H3270 *hSession) | @@ -426,7 +436,8 @@ static void dft_get_request(H3270 *hSession) | ||
426 | numbytes -= numread; | 436 | numbytes -= numread; |
427 | total_read += numread; | 437 | total_read += numread; |
428 | } | 438 | } |
429 | - if (feof(((H3270FT *) h3270.ft)->local_file) || ferror(((H3270FT *) h3270.ft)->local_file)) { | 439 | + if (feof(ft->local_file) || ferror(ft->local_file)) |
440 | + { | ||
430 | break; | 441 | break; |
431 | } | 442 | } |
432 | } | 443 | } |
@@ -439,55 +450,57 @@ static void dft_get_request(H3270 *hSession) | @@ -439,55 +450,57 @@ static void dft_get_request(H3270 *hSession) | ||
439 | } | 450 | } |
440 | 451 | ||
441 | /* Set up SF header for Data or EOF. */ | 452 | /* Set up SF header for Data or EOF. */ |
442 | - h3270.obptr = h3270.obuf; | ||
443 | - *h3270.obptr++ = AID_SF; | ||
444 | - h3270.obptr += 2; /* skip SF length for now */ | ||
445 | - *h3270.obptr++ = SF_TRANSFER_DATA; | ||
446 | - | ||
447 | - if (total_read) { | ||
448 | - trace_ds(hSession,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) recnum, (int) total_read); | ||
449 | - SET16(h3270.obptr, TR_GET_REPLY); | ||
450 | - SET16(h3270.obptr, TR_RECNUM_HDR); | ||
451 | - SET32(h3270.obptr, recnum); | ||
452 | - recnum++; | ||
453 | - SET16(h3270.obptr, TR_NOT_COMPRESSED); | ||
454 | - *h3270.obptr++ = TR_BEGIN_DATA; | ||
455 | - SET16(h3270.obptr, total_read + 5); | ||
456 | - h3270.obptr += total_read; | ||
457 | - | ||
458 | - ft_length += total_read; | ||
459 | - | ||
460 | - if (feof(((H3270FT *) h3270.ft)->local_file)) | 453 | + hSession->obptr = hSession->obuf; |
454 | + *hSession->obptr++ = AID_SF; | ||
455 | + hSession->obptr += 2; /* skip SF length for now */ | ||
456 | + *hSession->obptr++ = SF_TRANSFER_DATA; | ||
457 | + | ||
458 | + if (total_read) | ||
459 | + { | ||
460 | + trace_ds(hSession,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) ft->recnum, (int) total_read); | ||
461 | + SET16(hSession->obptr, TR_GET_REPLY); | ||
462 | + SET16(hSession->obptr, TR_RECNUM_HDR); | ||
463 | + SET32(hSession->obptr, ft->recnum); | ||
464 | + ft->recnum++; | ||
465 | + SET16(hSession->obptr, TR_NOT_COMPRESSED); | ||
466 | + *hSession->obptr++ = TR_BEGIN_DATA; | ||
467 | + SET16(hSession->obptr, total_read + 5); | ||
468 | + hSession->obptr += total_read; | ||
469 | + | ||
470 | + ft->ft_length += total_read; | ||
471 | + | ||
472 | + if (feof(ft->local_file)) | ||
461 | { | 473 | { |
462 | - dft_eof = True; | 474 | + ft->dft_eof = 1; |
463 | } | 475 | } |
464 | 476 | ||
465 | } else { | 477 | } else { |
466 | trace_ds(hSession,"> WriteStructuredField FileTransferData EOF\n"); | 478 | trace_ds(hSession,"> WriteStructuredField FileTransferData EOF\n"); |
467 | - *h3270.obptr++ = HIGH8(TR_GET_REQ); | ||
468 | - *h3270.obptr++ = TR_ERROR_REPLY; | ||
469 | - SET16(h3270.obptr, TR_ERROR_HDR); | ||
470 | - SET16(h3270.obptr, TR_ERR_EOF); | 479 | + *hSession->obptr++ = HIGH8(TR_GET_REQ); |
480 | + *hSession->obptr++ = TR_ERROR_REPLY; | ||
481 | + SET16(hSession->obptr, TR_ERROR_HDR); | ||
482 | + SET16(hSession->obptr, TR_ERR_EOF); | ||
471 | 483 | ||
472 | - dft_eof = True; | 484 | + ft->dft_eof = 1; |
473 | } | 485 | } |
474 | 486 | ||
475 | /* Set the SF length. */ | 487 | /* Set the SF length. */ |
476 | - bufptr = h3270.obuf + 1; | ||
477 | - SET16(bufptr, h3270.obptr - (h3270.obuf + 1)); | 488 | + bufptr = hSession->obuf + 1; |
489 | + SET16(bufptr, hSession->obptr - (hSession->obuf + 1)); | ||
478 | 490 | ||
479 | /* Save the data. */ | 491 | /* Save the data. */ |
480 | - dft_savebuf_len = h3270.obptr - h3270.obuf; | ||
481 | - if (dft_savebuf_len > dft_savebuf_max) { | ||
482 | - dft_savebuf_max = dft_savebuf_len; | ||
483 | - Replace(dft_savebuf, (unsigned char *)lib3270_malloc(dft_savebuf_max)); | 492 | + ft->dft_savebuf_len = hSession->obptr - hSession->obuf; |
493 | + if (ft->dft_savebuf_len > ft->dft_savebuf_max) | ||
494 | + { | ||
495 | + ft->dft_savebuf_max = ft->dft_savebuf_len; | ||
496 | + Replace(ft->dft_savebuf, (unsigned char *)lib3270_malloc(ft->dft_savebuf_max)); | ||
484 | } | 497 | } |
485 | - (void) memcpy(dft_savebuf, h3270.obuf, dft_savebuf_len); | ||
486 | - h3270.aid = AID_SF; | 498 | + (void) memcpy(ft->dft_savebuf, hSession->obuf, ft->dft_savebuf_len); |
499 | + hSession->aid = AID_SF; | ||
487 | 500 | ||
488 | /* Write the data. */ | 501 | /* Write the data. */ |
489 | net_output(hSession); | 502 | net_output(hSession); |
490 | - ft_update_length((H3270FT *) h3270.ft); | 503 | + ft_update_length(get_ft_handle(hSession)); |
491 | } | 504 | } |
492 | 505 | ||
493 | /* Process a Close request. */ | 506 | /* Process a Close request. */ |
@@ -555,13 +568,15 @@ filter_len(char *s, register int len) | @@ -555,13 +568,15 @@ filter_len(char *s, register int len) | ||
555 | */ | 568 | */ |
556 | void dft_read_modified(H3270 *hSession) | 569 | void dft_read_modified(H3270 *hSession) |
557 | { | 570 | { |
558 | - if (dft_savebuf_len) | 571 | + H3270FT *ft = get_ft_handle(hSession); |
572 | + | ||
573 | + if(ft->dft_savebuf_len) | ||
559 | { | 574 | { |
560 | trace_ds(hSession,"> WriteStructuredField FileTransferData\n"); | 575 | trace_ds(hSession,"> WriteStructuredField FileTransferData\n"); |
561 | hSession->obptr = hSession->obuf; | 576 | hSession->obptr = hSession->obuf; |
562 | - space3270out(hSession,dft_savebuf_len); | ||
563 | - memcpy(hSession->obptr, dft_savebuf, dft_savebuf_len); | ||
564 | - hSession->obptr += dft_savebuf_len; | 577 | + space3270out(hSession,ft->dft_savebuf_len); |
578 | + memcpy(hSession->obptr, ft->dft_savebuf, ft->dft_savebuf_len); | ||
579 | + hSession->obptr += ft->dft_savebuf_len; | ||
565 | net_output(hSession); | 580 | net_output(hSession); |
566 | } | 581 | } |
567 | } | 582 | } |
src/lib3270/ftc.h
@@ -22,22 +22,24 @@ | @@ -22,22 +22,24 @@ | ||
22 | 22 | ||
23 | #include <lib3270/filetransfer.h> | 23 | #include <lib3270/filetransfer.h> |
24 | 24 | ||
25 | - #define CHECK_FT_HANDLE(x) if(!x) x = ftsession; | 25 | +// #define CHECK_FT_HANDLE(x) if(!x) x = ftsession; |
26 | 26 | ||
27 | LIB3270_INTERNAL Boolean ascii_flag; | 27 | LIB3270_INTERNAL Boolean ascii_flag; |
28 | LIB3270_INTERNAL Boolean cr_flag; | 28 | LIB3270_INTERNAL Boolean cr_flag; |
29 | LIB3270_INTERNAL unsigned long ft_length; | 29 | LIB3270_INTERNAL unsigned long ft_length; |
30 | 30 | ||
31 | - LIB3270_INTERNAL H3270FT * ftsession; | 31 | +// LIB3270_INTERNAL H3270FT * ftsession; |
32 | 32 | ||
33 | - LIB3270_INTERNAL Boolean ft_last_cr; | ||
34 | - LIB3270_INTERNAL Boolean remap_flag; | 33 | +// LIB3270_INTERNAL Boolean ft_last_cr; |
34 | +// LIB3270_INTERNAL Boolean remap_flag; | ||
35 | 35 | ||
36 | - LIB3270_INTERNAL void ft_init(H3270 *session); | 36 | + LIB3270_INTERNAL H3270FT * get_ft_handle(H3270 *hSession); |
37 | 37 | ||
38 | - LIB3270_INTERNAL void ft_aborting(H3270FT *h); | ||
39 | - LIB3270_INTERNAL void ft_complete(H3270FT *h, const char *errmsg); | ||
40 | - LIB3270_INTERNAL void ft_running(H3270FT *h, Boolean is_cut); | ||
41 | - LIB3270_INTERNAL void ft_update_length(H3270FT *h); | 38 | + LIB3270_INTERNAL void ft_init(H3270 *hSession); |
39 | + | ||
40 | + LIB3270_INTERNAL void ft_aborting(H3270FT *h); | ||
41 | + LIB3270_INTERNAL void ft_complete(H3270FT *h, const char *errmsg); | ||
42 | + LIB3270_INTERNAL void ft_running(H3270FT *h, Boolean is_cut); | ||
43 | + LIB3270_INTERNAL void ft_update_length(H3270FT *h); | ||
42 | 44 | ||
43 | #endif /*]*/ | 45 | #endif /*]*/ |