From c830115161b02f8972afc1481d86f38ddfe2db45 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 3 Aug 2012 14:58:04 +0000 Subject: [PATCH] Mais funções recebem handle da sessão --- src/lib3270/ansi.c | 22 +++++++++++----------- src/lib3270/ctlr.c | 62 +++++++++++++++++++++++++++++++------------------------------- src/lib3270/ft_cut.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------- src/lib3270/ft_cutc.h | 39 +++++++++++++++++++++++++++------------ src/lib3270/telnet.c | 60 +++++++++++++++++++++++++++++++----------------------------- 5 files changed, 221 insertions(+), 186 deletions(-) diff --git a/src/lib3270/ansi.c b/src/lib3270/ansi.c index 5795c6a..dab165a 100644 --- a/src/lib3270/ansi.c +++ b/src/lib3270/ansi.c @@ -1870,9 +1870,9 @@ static int dbcs_process(H3270 *hSession, int ch, unsigned char ebc[]) // See if we have too many. if (mb_pending >= MB_MAX) { - trace_ds(&h3270,"Multi-byte character "); + trace_ds(hSession,"Multi-byte character "); trace_pending_mb(hSession); - trace_ds(&h3270," too long, dropping\n"); + trace_ds(hSession," too long, dropping\n"); mb_pending = 0; return 0; } @@ -1893,9 +1893,9 @@ static int dbcs_process(H3270 *hSession, int ch, unsigned char ebc[]) mb_pending = 0; return 2; } else { - trace_ds(&h3270,"Can't map multi-byte character"); - trace_pending_mb(&h3270); - trace_ds(&h3270," -> U+%04x to SBCS or DBCS, dropping\n", + trace_ds(hSession,"Can't map multi-byte character"); + trace_pending_mb(hSession); + trace_ds(hSession," -> U+%04x to SBCS or DBCS, dropping\n", Ubuf[0] & 0xffff); mb_pending = 0; return 0; @@ -1909,14 +1909,14 @@ static int dbcs_process(H3270 *hSession, int ch, unsigned char ebc[]) return 0; case U_INVALID_CHAR_FOUND: case U_ILLEGAL_CHAR_FOUND: - trace_ds(&h3270,"Invalid multi-byte character"); - trace_pending_mb(&h3270); - trace_ds(&h3270,", dropping\n"); + trace_ds(hSession,"Invalid multi-byte character"); + trace_pending_mb(hSession); + trace_ds(hSession,", dropping\n"); break; default: - trace_ds(&h3270,"Unexpected ICU error %d translating multi-type character", (int)err); - trace_pending_mb(&h3270); - trace_ds(&h3270,", dropping\n"); + trace_ds(hSession,"Unexpected ICU error %d translating multi-type character", (int)err); + trace_pending_mb(hSession); + trace_ds(hSession,", dropping\n"); break; } mb_pending = 0; diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 98ea830..2c162ce 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -771,13 +771,13 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) } #endif /*]*/ - trace_ds(&h3270,"> "); + trace_ds(hSession,"> "); hSession->obptr = hSession->obuf; space3270out(hSession,3); *hSession->obptr++ = aid_byte; ENCODE_BADDR(hSession->obptr, hSession->cursor_addr); - trace_ds(&h3270,"%s%s", see_aid(aid_byte), rcba(hSession,hSession->cursor_addr)); + trace_ds(hSession,"%s%s", see_aid(aid_byte), rcba(hSession,hSession->cursor_addr)); baddr = 0; do { @@ -1213,7 +1213,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } add_c1 = *cp; if (add_c1) - trace_ds(&h3270,"'"); + trace_ds(hSession,"'"); trace_ds(hSession,"%s", see_ebc(add_c1)); if (add_c1) @@ -1400,7 +1400,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er case ORDER_SFE: /* start field extended */ END_TEXT("StartFieldExtended"); if (previous != SBA) - trace_ds(&h3270,"%s",rcba(&h3270,h3270.buffer_addr)); + trace_ds(hSession,"%s",rcba(&h3270,h3270.buffer_addr)); previous = ORDER; cp++; /* skip order */ na = *cp; @@ -1413,26 +1413,26 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er for (i = 0; i < (int)na; i++) { cp++; if (*cp == XA_3270) { - trace_ds(&h3270," 3270"); + trace_ds(hSession," 3270"); cp++; START_FIELD(*cp); any_fa++; } else if (*cp == XA_FOREGROUND) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; if (h3270.m3279) efa_fg = *cp; } else if (*cp == XA_BACKGROUND) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; if (h3270.m3279) efa_bg = *cp; } else if (*cp == XA_HIGHLIGHTING) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; efa_gr = *cp & 0x07; } else if (*cp == XA_CHARSET) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; if (*cp == 0xf1) efa_cs = CS_APL; @@ -1441,15 +1441,15 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er else efa_cs = CS_BASE; } else if (*cp == XA_ALL) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; } else if (*cp == XA_INPUT_CONTROL) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); - if (h3270.dbcs) + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); + if (hSession->dbcs) efa_ic = (*(cp + 1) == 1); cp++; } else { - trace_ds(&h3270,"%s[unsupported]", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s[unsupported]", see_efa(*cp, *(cp + 1))); cp++; } } @@ -1469,25 +1469,25 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er previous = ORDER; cp++; if (*cp == XA_FOREGROUND) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); if (h3270.m3279) h3270.default_fg = *(cp + 1); } else if (*cp == XA_BACKGROUND) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); if (h3270.m3279) h3270.default_bg = *(cp + 1); } else if (*cp == XA_HIGHLIGHTING) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); h3270.default_gr = *(cp + 1) & 0x0f; } else if (*cp == XA_ALL) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); h3270.default_fg = 0; h3270.default_bg = 0; h3270.default_gr = 0; h3270.default_cs = 0; h3270.default_ic = 0; } else if (*cp == XA_CHARSET) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); switch (*(cp + 1)) { case 0xf1: h3270.default_cs = CS_APL; @@ -1500,13 +1500,13 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er break; } } else if (*cp == XA_INPUT_CONTROL) { - trace_ds(&h3270,"%s", see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); if (*(cp + 1) == 1) h3270.default_ic = 1; else h3270.default_ic = 0; } else - trace_ds(&h3270,"%s[unsupported]",see_efa(*cp, *(cp + 1))); + trace_ds(hSession,"%s[unsupported]",see_efa(*cp, *(cp + 1))); cp++; last_cmd = True; last_zpt = False; @@ -1630,7 +1630,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er cp--; break; default: - trace_ds(&h3270," [invalid DBCS control character X'%02x%02x'; write aborted]",add_c1, add_c2); + trace_ds(hSession," [invalid DBCS control character X'%02x%02x'; write aborted]",add_c1, add_c2); ABORT_WRITEx; break; } @@ -1660,14 +1660,14 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er default: /* enter character */ if (*cp <= 0x3F) { END_TEXT("UnsupportedOrder"); - trace_ds(&h3270,"(%02X)", *cp); + trace_ds(hSession,"(%02X)", *cp); previous = ORDER; last_cmd = True; last_zpt = False; break; } if (previous != TEXT) - trace_ds(&h3270," '"); + trace_ds(hSession," '"); previous = TEXT; #if defined(X3270_DBCS) /*[*/ add_dbcs = False; @@ -1684,7 +1684,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er add_c2 = *cp; if (add_c1 < 0x40 || add_c1 > 0xfe || add_c2 < 0x40 || add_c2 > 0xfe) { - trace_ds(&h3270," [invalid DBCS character X'%02x%02x'; write aborted]",add_c1, add_c2); + trace_ds(hSession," [invalid DBCS character X'%02x%02x'; write aborted]",add_c1, add_c2); ABORT_WRITEx; } add_dbcs = True; @@ -1693,7 +1693,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } else { #endif /*]*/ add_c1 = *cp; - trace_ds(&h3270,"%s", see_ebc(*cp)); + trace_ds(hSession,"%s", see_ebc(*cp)); #if defined(X3270_DBCS) /*[*/ } #endif /*]*/ @@ -1720,7 +1720,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } set_formatted(hSession); END_TEXT0; - trace_ds(&h3270,"\n"); + trace_ds(hSession,"\n"); if (wcc_keyboard_restore) { h3270.aid = AID_NO; do_reset(&h3270,False); @@ -1773,7 +1773,7 @@ void ctlr_write_sscp_lu(H3270 *hSession, unsigned char buf[], int buflen) * we display other control codes as spaces. */ - trace_ds(&h3270,"SSCP-LU data\n"); + trace_ds(hSession,"SSCP-LU data\n"); for (i = 0; i < buflen; cp++, i++) { switch (*cp) { case FCORDER_NL: @@ -1797,7 +1797,7 @@ void ctlr_write_sscp_lu(H3270 *hSession, unsigned char buf[], int buflen) /* Some hosts forget they're talking SSCP-LU. */ cp++; i++; - trace_ds(&h3270," StartField%s %s [translated to space]\n",rcba(hSession,hSession->buffer_addr), see_attr(*cp)); + trace_ds(hSession," StartField%s %s [translated to space]\n",rcba(hSession,hSession->buffer_addr), see_attr(*cp)); ctlr_add(hSession,hSession->buffer_addr, EBC_space, hSession->default_cs); ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); @@ -1807,12 +1807,12 @@ void ctlr_write_sscp_lu(H3270 *hSession, unsigned char buf[], int buflen) break; case ORDER_IC: - trace_ds(&h3270," InsertCursor%s [ignored]\n",rcba(hSession,hSession->buffer_addr)); + trace_ds(hSession," InsertCursor%s [ignored]\n",rcba(hSession,hSession->buffer_addr)); break; case ORDER_SBA: // baddr = DECODE_BADDR(*(cp+1), *(cp+2)); - trace_ds(&h3270," SetBufferAddress%s [ignored]\n", rcba(hSession,DECODE_BADDR(*(cp+1), *(cp+2)))); + trace_ds(hSession," SetBufferAddress%s [ignored]\n", rcba(hSession,DECODE_BADDR(*(cp+1), *(cp+2)))); cp += 2; i += 2; break; @@ -2148,7 +2148,7 @@ void ps_process(H3270 *hSession) /* magic field */ hSession->ea_buf[1919].fa && FA_IS_SKIP(hSession->ea_buf[1919].fa)) { - ft_cut_data(); + ft_cut_data(hSession); } #endif } diff --git a/src/lib3270/ft_cut.c b/src/lib3270/ft_cut.c index de63f2c..947513c 100644 --- a/src/lib3270/ft_cut.c +++ b/src/lib3270/ft_cut.c @@ -119,57 +119,64 @@ static int xlate_buffered = 0; /* buffer count */ static int xlate_buf_ix = 0; /* buffer index */ static unsigned char xlate_buf[XLATE_NBUF]; /* buffer */ -static void cut_control_code(void); -static void cut_data_request(void); -static void cut_retransmit(void); -static void cut_data(void); +static void cut_control_code(H3270 *hSession); +static void cut_data_request(H3270 *hSession); +static void cut_retransmit(H3270 *hSession); +static void cut_data(H3270 *hSession); -static void cut_ack(void); -static void cut_abort(unsigned short code, const char *fmt, ...); +static void cut_ack(H3270 *hSession); +static void cut_abort(H3270 *hSession, unsigned short code, const char *fmt, ...) printflike(3,4); static unsigned from6(unsigned char c); static int xlate_getc(void); -/* - * Convert a buffer for uploading (host->local). Overwrites the buffer. - * Returns the length of the converted data. +/** + * Convert a buffer for uploading (host->local). Overwrites the buffer. + * * If there is a conversion error, calls cut_abort() and returns -1. + * + * @return the length of the converted data. */ -static int -upload_convert(unsigned char *buf, int len) +static int upload_convert(H3270 *hSession, unsigned char *buf, int len) { unsigned char *ob0 = buf; unsigned char *ob = ob0; - while (len--) { + while (len--) + { unsigned char c = *buf++; char *ixp; int ix; // int oq = -1; retry: - if (quadrant < 0) { + if (quadrant < 0) + { /* Find the quadrant. */ - for (quadrant = 0; quadrant < NQ; quadrant++) { + for (quadrant = 0; quadrant < NQ; quadrant++) + { if (c == conv[quadrant].selector) break; } - if (quadrant >= NQ) { - cut_abort(SC_ABORT_XMIT, "%s", _("Data conversion error")); + if (quadrant >= NQ) + { + cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Data conversion error")); return -1; } continue; } /* Make sure it's in a valid range. */ - if (c < 0x40 || c > 0xf9) { - cut_abort(SC_ABORT_XMIT, "%s", _("Data conversion error")); + if (c < 0x40 || c > 0xf9) + { + cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Data conversion error")); return -1; } /* Translate to a quadrant index. */ ixp = strchr(alphas, ebc2asc[c]); - if (ixp == (char *)NULL) { + if (ixp == (char *)NULL) + { /* Try a different quadrant. */ // oq = quadrant; quadrant = -1; @@ -181,8 +188,8 @@ upload_convert(unsigned char *buf, int len) * See if it's mapped by that quadrant, handling NULLs * specially. */ - if (quadrant != OTHER_2 && c != XLATE_NULL && - !conv[quadrant].xlate[ix]) { + if (quadrant != OTHER_2 && c != XLATE_NULL && !conv[quadrant].xlate[ix]) + { /* Try a different quadrant. */ // oq = quadrant; quadrant = -1; @@ -266,25 +273,29 @@ download_convert(unsigned const char *buf, unsigned len, unsigned char *xobuf) * Main entry point from ctlr.c. * We have received what looks like an appropriate message from the host. */ -void -ft_cut_data(void) +void ft_cut_data(H3270 *hSession) { - switch (h3270.ea_buf[O_FRAME_TYPE].cc) { - case FT_CONTROL_CODE: - cut_control_code(); + switch (hSession->ea_buf[O_FRAME_TYPE].cc) + { + case FT_CONTROL_CODE: + cut_control_code(hSession); break; - case FT_DATA_REQUEST: - cut_data_request(); + + case FT_DATA_REQUEST: + cut_data_request(hSession); break; - case FT_RETRANSMIT: - cut_retransmit(); + + case FT_RETRANSMIT: + cut_retransmit(hSession); break; - case FT_DATA: - cut_data(); + + case FT_DATA: + cut_data(hSession); break; - default: - trace_ds(&h3270,"< FT unknown 0x%02x\n", h3270.ea_buf[O_FRAME_TYPE].cc); - cut_abort(SC_ABORT_XMIT, "%s", _("Unknown frame type from host")); + + default: + trace_ds(hSession,"< FT unknown 0x%02x\n", hSession->ea_buf[O_FRAME_TYPE].cc); + cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Unknown frame type from host")); break; } } @@ -292,42 +303,42 @@ ft_cut_data(void) /* * Process a control code from the host. */ -static void -cut_control_code(void) +static void cut_control_code(H3270 *hSession) { unsigned short code; char *buf; char *bp; int i; - trace_ds(&h3270,"< FT CONTROL_CODE "); - code = (h3270.ea_buf[O_CC_STATUS_CODE].cc << 8) | h3270.ea_buf[O_CC_STATUS_CODE + 1].cc; + trace_ds(hSession,"< FT CONTROL_CODE "); + code = (hSession->ea_buf[O_CC_STATUS_CODE].cc << 8) | hSession->ea_buf[O_CC_STATUS_CODE + 1].cc; + switch (code) { case SC_HOST_ACK: - trace_ds(&h3270,"HOST_ACK\n"); + trace_ds(hSession,"HOST_ACK\n"); cut_xfer_in_progress = True; expanded_length = 0; quadrant = -1; xlate_buffered = 0; - cut_ack(); + cut_ack(hSession); ft_running(NULL,True); break; case SC_XFER_COMPLETE: - trace_ds(&h3270,"XFER_COMPLETE\n"); - cut_ack(); + trace_ds(hSession,"XFER_COMPLETE\n"); + cut_ack(hSession); cut_xfer_in_progress = False; ft_complete(NULL,N_( "Complete" ) ); break; case SC_ABORT_FILE: case SC_ABORT_XMIT: - trace_ds(&h3270,"ABORT\n"); + trace_ds(hSession,"ABORT\n"); cut_xfer_in_progress = False; - cut_ack(); + cut_ack(hSession); - if (lib3270_get_ft_state(&h3270) == FT_ABORT_SENT && saved_errmsg != CN) + if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && saved_errmsg != CN) { buf = saved_errmsg; saved_errmsg = CN; @@ -337,7 +348,7 @@ cut_control_code(void) bp = buf = lib3270_malloc(81); for (i = 0; i < 80; i++) - *bp++ = ebc2asc[h3270.ea_buf[O_CC_MESSAGE + i].cc]; + *bp++ = ebc2asc[hSession->ea_buf[O_CC_MESSAGE + i].cc]; *bp-- = '\0'; @@ -358,8 +369,8 @@ cut_control_code(void) break; default: - trace_ds(&h3270,"unknown 0x%04x\n", code); - cut_abort(SC_ABORT_XMIT, "%s", _("Unknown FT control code from host")); + trace_ds(hSession,"unknown 0x%04x\n", code); + cut_abort(hSession,SC_ABORT_XMIT, "%s", _("Unknown FT control code from host")); break; } } @@ -367,80 +378,80 @@ cut_control_code(void) /* * Process a data request from the host. */ -static void -cut_data_request(void) +static void cut_data_request(H3270 *hSession) { - unsigned char seq = h3270.ea_buf[O_DR_FRAME_SEQ].cc; + unsigned char seq = hSession->ea_buf[O_DR_FRAME_SEQ].cc; int count; unsigned char cs; int c; int i; unsigned char attr; - trace_ds(&h3270,"< FT DATA_REQUEST %u\n", from6(seq)); - if (lib3270_get_ft_state(&h3270) == FT_ABORT_WAIT) + trace_ds(hSession,"< FT DATA_REQUEST %u\n", from6(seq)); + if (lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) { - cut_abort(SC_ABORT_FILE,"%s",N_("Transfer cancelled by user")); + cut_abort(hSession,SC_ABORT_FILE,"%s", N_("Transfer cancelled by user") ); return; } /* Copy data into the screen buffer. */ count = 0; while (count < O_UP_MAX && (c = xlate_getc()) != EOF) { - ctlr_add(&h3270,O_UP_DATA + count, c, 0); + ctlr_add(hSession,O_UP_DATA + count, c, 0); count++; } /* Check for errors. */ - if (ferror(((H3270FT *) h3270.ft)->local_file)) { + if (ferror(((H3270FT *) hSession->ft)->local_file)) { int j; /* Clean out any data we may have written. */ for (j = 0; j < count; j++) - ctlr_add(&h3270,O_UP_DATA + j, 0, 0); + ctlr_add(hSession,O_UP_DATA + j, 0, 0); /* Abort the transfer. */ - cut_abort(SC_ABORT_FILE,_( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); + cut_abort(hSession,SC_ABORT_FILE,_( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); return; } /* Send special data for EOF. */ - if (!count && feof(((H3270FT *) h3270.ft)->local_file)) { - ctlr_add(&h3270,O_UP_DATA, EOF_DATA1, 0); - ctlr_add(&h3270,O_UP_DATA+1, EOF_DATA2, 0); + if (!count && feof(((H3270FT *) hSession->ft)->local_file)) + { + ctlr_add(hSession,O_UP_DATA, EOF_DATA1, 0); + ctlr_add(hSession,O_UP_DATA+1, EOF_DATA2, 0); count = 2; } /* Compute the other fields. */ - ctlr_add(&h3270,O_UP_FRAME_SEQ, seq, 0); + ctlr_add(hSession,O_UP_FRAME_SEQ, seq, 0); cs = 0; for (i = 0; i < count; i++) - cs ^= h3270.ea_buf[O_UP_DATA + i].cc; - ctlr_add(&h3270,O_UP_CSUM, asc2ebc[(int)table6[cs & 0x3f]], 0); - ctlr_add(&h3270,O_UP_LEN, asc2ebc[(int)table6[(count >> 6) & 0x3f]], 0); - ctlr_add(&h3270,O_UP_LEN+1, asc2ebc[(int)table6[count & 0x3f]], 0); + cs ^= hSession->ea_buf[O_UP_DATA + i].cc; + + ctlr_add(hSession,O_UP_CSUM, asc2ebc[(int)table6[cs & 0x3f]], 0); + ctlr_add(hSession,O_UP_LEN, asc2ebc[(int)table6[(count >> 6) & 0x3f]], 0); + ctlr_add(hSession,O_UP_LEN+1, asc2ebc[(int)table6[count & 0x3f]], 0); /* XXX: Change the data field attribute so it doesn't display. */ - attr = h3270.ea_buf[O_DR_SF].fa; + attr = hSession->ea_buf[O_DR_SF].fa; attr = (attr & ~FA_INTENSITY) | FA_INT_ZERO_NSEL; - ctlr_add_fa(&h3270,O_DR_SF, attr, 0); + ctlr_add_fa(hSession,O_DR_SF, attr, 0); /* Send it up to the host. */ - trace_ds(&h3270,"> FT DATA %u\n", from6(seq)); + trace_ds(hSession,"> FT DATA %u\n", from6(seq)); ft_update_length(NULL); expanded_length += count; - lib3270_enter(&h3270); + lib3270_enter(hSession); } /* * (Improperly) process a retransmit from the host. */ -static void -cut_retransmit(void) +static void cut_retransmit(H3270 *hSession) { - trace_ds(&h3270,"< FT RETRANSMIT\n"); - cut_abort(SC_ABORT_XMIT,"%s",_("Transmission error")); + trace_ds(hSession,"< FT RETRANSMIT\n"); + cut_abort(hSession,SC_ABORT_XMIT,"%s",_("Transmission error")); } /* @@ -461,63 +472,70 @@ from6(unsigned char c) /* * Process data from the host. */ -static void -cut_data(void) +static void cut_data(H3270 *hSession) { static unsigned char cvbuf[O_RESPONSE - O_DT_DATA]; unsigned short raw_length; int conv_length; register int i; - trace_ds(&h3270,"< FT DATA\n"); - if (((H3270FT *) h3270.ft)->state == LIB3270_FT_STATE_ABORT_WAIT) + trace_ds(hSession,"< FT DATA\n"); + if (((H3270FT *) hSession->ft)->state == LIB3270_FT_STATE_ABORT_WAIT) { - cut_abort(SC_ABORT_FILE,"%s",_("Transfer cancelled by user")); + cut_abort(hSession,SC_ABORT_FILE,"%s",_("Transfer cancelled by user")); return; } /* Copy and convert the data. */ - raw_length = from6(h3270.ea_buf[O_DT_LEN].cc) << 6 | - from6(h3270.ea_buf[O_DT_LEN + 1].cc); - if ((int)raw_length > O_RESPONSE - O_DT_DATA) { - cut_abort(SC_ABORT_XMIT,"%s",_("Illegal frame length")); + raw_length = from6(hSession->ea_buf[O_DT_LEN].cc) << 6 | + from6(hSession->ea_buf[O_DT_LEN + 1].cc); + + if ((int)raw_length > O_RESPONSE - O_DT_DATA) + { + cut_abort(hSession,SC_ABORT_XMIT,"%s",_("Illegal frame length")); return; } + for (i = 0; i < (int)raw_length; i++) - cvbuf[i] = h3270.ea_buf[O_DT_DATA + i].cc; + cvbuf[i] = hSession->ea_buf[O_DT_DATA + i].cc; - if (raw_length == 2 && cvbuf[0] == EOF_DATA1 && cvbuf[1] == EOF_DATA2) { - trace_ds(&h3270,"< FT EOF\n"); - cut_ack(); + if (raw_length == 2 && cvbuf[0] == EOF_DATA1 && cvbuf[1] == EOF_DATA2) + { + trace_ds(hSession,"< FT EOF\n"); + cut_ack(hSession); return; } - conv_length = upload_convert(cvbuf, raw_length); + + conv_length = upload_convert(hSession, cvbuf, raw_length); if (conv_length < 0) return; /* Write it to the file. */ - if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) h3270.ft)->local_file) == 0) { - cut_abort(SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); - } else { + if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) hSession->ft)->local_file) == 0) + { + cut_abort(hSession,SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); + } + else + { ft_length += conv_length; ft_update_length(NULL); - cut_ack(); + cut_ack(hSession); } } /* * Acknowledge a host command. */ -static void cut_ack(void) +static void cut_ack(H3270 *hSession) { - trace_ds(&h3270,"> FT ACK\n"); - lib3270_enter(&h3270); + trace_ds(hSession,"> FT ACK\n"); + lib3270_enter(hSession); } /* * Abort a transfer in progress. */ -static void cut_abort(unsigned short reason, const char *fmt, ...) +static void cut_abort(H3270 *hSession, unsigned short reason, const char *fmt, ...) { va_list args; @@ -530,13 +548,13 @@ static void cut_abort(unsigned short reason, const char *fmt, ...) va_end(args); /* Send the abort sequence. */ - ctlr_add(&h3270,RO_FRAME_TYPE, RFT_CONTROL_CODE, 0); - ctlr_add(&h3270,RO_FRAME_SEQ, h3270.ea_buf[O_DT_FRAME_SEQ].cc, 0); - ctlr_add(&h3270,RO_REASON_CODE, HIGH8(reason), 0); - ctlr_add(&h3270,RO_REASON_CODE+1, LOW8(reason), 0); - trace_ds(&h3270,"> FT CONTROL_CODE ABORT\n"); + ctlr_add(hSession,RO_FRAME_TYPE, RFT_CONTROL_CODE, 0); + ctlr_add(hSession,RO_FRAME_SEQ, hSession->ea_buf[O_DT_FRAME_SEQ].cc, 0); + ctlr_add(hSession,RO_REASON_CODE, HIGH8(reason), 0); + ctlr_add(hSession,RO_REASON_CODE+1, LOW8(reason), 0); + trace_ds(hSession,"> FT CONTROL_CODE ABORT\n"); - lib3270_pfkey(&h3270,2); + lib3270_pfkey(hSession,2); /* Update the in-progress pop-up. */ ft_aborting(NULL); diff --git a/src/lib3270/ft_cutc.h b/src/lib3270/ft_cutc.h index 5eb0b02..ba7692a 100644 --- a/src/lib3270/ft_cutc.h +++ b/src/lib3270/ft_cutc.h @@ -1,15 +1,30 @@ /* - * Copyright 1996, 1999, 2000 by Paul Mattes. - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation. - * - * x3270, c3270, s3270 and tcl3270 are distributed in the hope that they will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file LICENSE - * for more details. + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como ft_cutc.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * */ -LIB3270_INTERNAL void ft_cut_data(void); +LIB3270_INTERNAL void ft_cut_data(H3270 *hSession); diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 593c28f..9b5c52d 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -882,56 +882,58 @@ static void net_connected(H3270 *session) * * Called just after a sucessfull connect to setup tn3270 state. * - * @param session 3270 session to setup. + * @param hSession 3270 session to setup. * */ -LIB3270_EXPORT void lib3270_setup_session(H3270 *session) +LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) { - (void) memset((char *) session->myopts, 0, sizeof(session->myopts)); - (void) memset((char *) session->hisopts, 0, sizeof(session->hisopts)); + (void) memset((char *) hSession->myopts, 0, sizeof(hSession->myopts)); + (void) memset((char *) hSession->hisopts, 0, sizeof(hSession->hisopts)); #if defined(X3270_TN3270E) /*[*/ - session->e_funcs = E_OPT(TN3270E_FUNC_BIND_IMAGE) | E_OPT(TN3270E_FUNC_RESPONSES) | E_OPT(TN3270E_FUNC_SYSREQ); - session->e_xmit_seq = 0; - session->response_required = TN3270E_RSF_NO_RESPONSE; + hSession->e_funcs = E_OPT(TN3270E_FUNC_BIND_IMAGE) | E_OPT(TN3270E_FUNC_RESPONSES) | E_OPT(TN3270E_FUNC_SYSREQ); + hSession->e_xmit_seq = 0; + hSession->response_required = TN3270E_RSF_NO_RESPONSE; #endif /*]*/ #if defined(HAVE_LIBSSL) /*[*/ need_tls_follows = False; #endif /*]*/ - session->telnet_state = TNS_DATA; - session->ibptr = session->ibuf; + hSession->telnet_state = TNS_DATA; + hSession->ibptr = hSession->ibuf; /* clear statistics and flags */ - time(&session->ns_time); - session->ns_brcvd = 0; - session->ns_rrcvd = 0; - session->ns_bsent = 0; - session->ns_rsent = 0; - session->syncing = 0; - session->tn3270e_negotiated = 0; - session->tn3270e_submode = E_NONE; - session->tn3270e_bound = 0; + time(&hSession->ns_time); + hSession->ns_brcvd = 0; + hSession->ns_rrcvd = 0; + hSession->ns_bsent = 0; + hSession->ns_rsent = 0; + hSession->syncing = 0; + hSession->tn3270e_negotiated = 0; + hSession->tn3270e_submode = E_NONE; + hSession->tn3270e_bound = 0; - setup_lus(session); + setup_lus(hSession); - check_linemode(session,True); + check_linemode(hSession,True); /* write out the passthru hostname and port nubmer */ - if (session->passthru_host) + if (hSession->passthru_host) { - unsigned char *buffer = (unsigned char *) xs_buffer("%s %d\r\n", session->hostname, session->current_port); - session->write(session, buffer, strlen((char *) buffer)); + unsigned char *buffer = (unsigned char *) xs_buffer("%s %d\r\n", hSession->hostname, hSession->current_port); + hSession->write(hSession, buffer, strlen((char *) buffer)); lib3270_free(buffer); - trace_ds(&h3270,"SENT HOSTNAME %s:%d\n", session->hostname, session->current_port); + trace_ds(hSession,"SENT HOSTNAME %s:%d\n", hSession->hostname, hSession->current_port); } } -/* - * connection_complete - * The connection appears to be complete (output is possible or input - * appeared ready but recv() returned EWOULDBLOCK). Complete the - * connection-completion processing. +/** + * Connection_complete. + * + * The connection appears to be complete (output is possible or input + * appeared ready but recv() returned EWOULDBLOCK). Complete the + * connection-completion processing. + * */ static void connection_complete(H3270 *session) { -- libgit2 0.21.2