From 7492b29e9f69491f398b08c5ab44d032be46701c Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Thu, 2 Aug 2012 11:57:17 +0000 Subject: [PATCH] Incluindo suporte multi-sessão em mais funções --- src/lib3270/ansi.c | 44 ++++++++++++++++++++++---------------------- src/lib3270/ctlr.c | 59 +++++------------------------------------------------------ src/lib3270/ctlrc.h | 2 +- src/lib3270/kybd.c | 26 ++++++++++++++------------ src/lib3270/sf.c | 4 ++-- src/lib3270/telnet.c | 240 +++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/lib3270/telnetc.h | 22 +++++++++++----------- 7 files changed, 96 insertions(+), 301 deletions(-) diff --git a/src/lib3270/ansi.c b/src/lib3270/ansi.c index 20c9c89..f1e6c10 100644 --- a/src/lib3270/ansi.c +++ b/src/lib3270/ansi.c @@ -1312,11 +1312,10 @@ ansi_reverse_index(H3270 *hSession, int ig1 unused, int ig2 unused) return DATA; } -static enum lib3270_ansi_state -ansi_send_attributes(H3270 *hSession, int nn, int ig2 unused) +static enum lib3270_ansi_state ansi_send_attributes(H3270 *hSession, int nn, int ig2 unused) { if (!nn) - net_sends("\033[?1;2c"); + net_sends(hSession,"\033[?1;2c"); return DATA; } @@ -1361,14 +1360,15 @@ ansi_status_report(H3270 *hSession, int nn, int ig2 unused) { static char cpr[11]; - switch (nn) { - case 5: - net_sends("\033[0n"); + switch (nn) + { + case 5: + net_sends(hSession,"\033[0n"); break; - case 6: - (void) sprintf(cpr, "\033[%d;%dR", - (hSession->cursor_addr/hSession->cols) + 1, (hSession->cursor_addr%hSession->cols) + 1); - net_sends(cpr); + + case 6: + (void) sprintf(cpr, "\033[%d;%dR",(hSession->cursor_addr/hSession->cols) + 1, (hSession->cursor_addr%hSession->cols) + 1); + net_sends(hSession,cpr); break; } return DATA; @@ -1771,48 +1771,48 @@ void ansi_send_up(H3270 *hSession) { if (hSession->appl_cursor) - net_sends("\033OA"); + net_sends(hSession,"\033OA"); else - net_sends("\033[A"); + net_sends(hSession,"\033[A"); } void ansi_send_down(H3270 *hSession) { if (hSession->appl_cursor) - net_sends("\033OB"); + net_sends(hSession,"\033OB"); else - net_sends("\033[B"); + net_sends(hSession,"\033[B"); } void ansi_send_right(H3270 *hSession) { if (hSession->appl_cursor) - net_sends("\033OC"); + net_sends(hSession,"\033OC"); else - net_sends("\033[C"); + net_sends(hSession,"\033[C"); } void ansi_send_left(H3270 *hSession) { if (hSession->appl_cursor) - net_sends("\033OD"); + net_sends(hSession,"\033OD"); else - net_sends("\033[D"); + net_sends(hSession,"\033[D"); } void ansi_send_home(H3270 *hSession) { - net_sends("\033[H"); + net_sends(hSession,"\033[H"); } void ansi_send_clear(H3270 *hSession) { - net_sends("\033[2K"); + net_sends(hSession,"\033[2K"); } void @@ -1838,7 +1838,7 @@ ansi_send_pf(H3270 *hSession, int nn) if (nn < 1 || nn > sizeof(code)/sizeof(code[0])) return; (void) sprintf(fn_buf, "\033[%d~", code[nn-1]); - net_sends(fn_buf); + net_sends(hSession,fn_buf); } void @@ -1850,7 +1850,7 @@ ansi_send_pa(H3270 *hSession, int nn) if (nn < 1 || nn > 4) return; (void) sprintf(fn_buf, "\033O%c", code[nn-1]); - net_sends(fn_buf); + net_sends(hSession,fn_buf); } void toggle_lineWrap(H3270 *hSession, struct lib3270_toggle *t unused, LIB3270_TOGGLE_TYPE type unused) diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index d7ab65b..3863541 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -353,53 +353,6 @@ unsigned char get_field_attribute(H3270 *h, int baddr) } /* - * Find the field attribute for the given buffer address, bounded by another - * buffer address. Return the attribute in a parameter. - * - * Returns True if an attribute is found, False if boundary hit. - */ /* -Boolean -get_bounded_field_attribute(register int baddr, register int bound, - unsigned char *fa_out) -{ - int sbaddr; - - if (!h3270.formatted) { - *fa_out = h3270.ea_buf[-1].fa; - return True; - } - - sbaddr = baddr; - do { - if (h3270.ea_buf[baddr].fa) { - *fa_out = h3270.ea_buf[baddr].fa; - return True; - } - DEC_BA(baddr); - } while (baddr != sbaddr && baddr != bound); - - // Screen is unformatted (and 'formatted' is inaccurate). - if (baddr == sbaddr) { - *fa_out = h3270.ea_buf[-1].fa; - return True; - } - - // Wrapped to boundary. - return False; -} */ - -/* - * Given the address of a field attribute, return the address of the - * extended attribute structure. - */ /* -struct ea * -fa2ea(int baddr) -{ - return &h3270.ea_buf[baddr]; -} -*/ - -/* * Find the next unprotected field. Returns the address following the * unprotected attribute byte, or 0 if no nonzero-width unprotected field * can be found. @@ -517,14 +470,14 @@ enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen) case CMD_RM: /* read modifed */ case SNA_CMD_RM: trace_ds(hSession,"ReadModified\n"); - ctlr_read_modified(hSession->aid, False); + ctlr_read_modified(hSession, hSession->aid, False); return PDS_OKAY_OUTPUT; break; case CMD_RMA: /* read modifed all */ case SNA_CMD_RMA: trace_ds(hSession,"ReadModifiedAll\n"); - ctlr_read_modified(hSession->aid, True); + ctlr_read_modified(hSession, hSession->aid, True); return PDS_OKAY_OUTPUT; break; @@ -609,12 +562,10 @@ static void insert_sa(H3270 *hSession, int baddr, unsigned char *current_fgp, un } -/* - * Process a 3270 Read-Modified command and transmit the data back to the - * host. +/** + * Process a 3270 Read-Modified command and transmit the data back to the host. */ -void -ctlr_read_modified(unsigned char aid_byte, Boolean all) +void ctlr_read_modified(H3270 *hSession, unsigned char aid_byte, Boolean all) { register int baddr, sbaddr; Boolean send_data = True; diff --git a/src/lib3270/ctlrc.h b/src/lib3270/ctlrc.h index 70a7175..5a671d1 100644 --- a/src/lib3270/ctlrc.h +++ b/src/lib3270/ctlrc.h @@ -54,7 +54,7 @@ LIB3270_INTERNAL void ctlr_clear(H3270 *hSession, Boolean can_snap); LIB3270_INTERNAL void ctlr_erase_all_unprotected(H3270 *hSession); LIB3270_INTERNAL void ctlr_init(H3270 *session, unsigned cmask); LIB3270_INTERNAL void ctlr_read_buffer(H3270 *session, unsigned char aid_byte); -LIB3270_INTERNAL void ctlr_read_modified(unsigned char aid_byte, Boolean all); +LIB3270_INTERNAL void ctlr_read_modified(H3270 *hSession, unsigned char aid_byte, Boolean all); LIB3270_INTERNAL void ctlr_reinit(H3270 *session, unsigned cmask); LIB3270_INTERNAL void ctlr_scroll(H3270 *hSession); // LIB3270_INTERNAL void ctlr_shrink(void); diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 1f391d1..a76f5e9 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -502,7 +502,7 @@ static void key_AID(H3270 *hSession, unsigned char aid_code) trace("aid_code: %02x IN_ANSI: %d",aid_code,IN_ANSI); if (aid_code == AID_ENTER) { - net_sendc('\r'); + net_sendc(hSession, '\r'); return; } for (i = 0; i < PF_SZ; i++) @@ -551,7 +551,7 @@ static void key_AID(H3270 *hSession, unsigned char aid_code) kybdlock_set(hSession,KL_OIA_TWAIT | KL_OIA_LOCKED); } hSession->aid = aid_code; - ctlr_read_modified(hSession->aid, False); + ctlr_read_modified(hSession, hSession->aid, False); ticking_start(hSession,False); status_ctlr_done(hSession); } @@ -990,7 +990,7 @@ void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Bo #if defined(X3270_ANSI) /*[*/ else if (IN_ANSI) { - net_sendc((char) c); + net_sendc(&h3270,(char) c); } #endif /*]*/ else @@ -1017,8 +1017,9 @@ LIB3270_ACTION( nextfield ) } } #if defined(X3270_ANSI) /*[*/ - if (IN_ANSI) { - net_sendc('\t'); + if (IN_ANSI) + { + net_sendc(hSession,'\t'); return 0; } #endif /*]*/ @@ -1344,8 +1345,9 @@ LIB3270_ACTION( delete ) return 0; } #if defined(X3270_ANSI) /*[*/ - if (IN_ANSI) { - net_sendc('\177'); + if (IN_ANSI) + { + net_sendc(hSession,'\177'); return 0; } #endif /*]*/ @@ -1376,7 +1378,7 @@ LIB3270_ACTION( backspace ) } #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - net_send_erase(); + net_send_erase(hSession); return 0; } #endif /*]*/ @@ -1472,7 +1474,7 @@ LIB3270_ACTION( erase ) #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - net_send_erase(); + net_send_erase(hSession); return 0; } #endif /*]*/ @@ -1798,7 +1800,7 @@ LIB3270_CURSOR_ACTION( newline ) #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - net_sendc('\n'); + net_sendc(hSession,'\n'); return 0; } #endif /*]*/ @@ -2125,7 +2127,7 @@ LIB3270_ACTION( deleteword ) } #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - net_send_werase(); + net_send_werase(hSession); return 0; } #endif /*]*/ @@ -2193,7 +2195,7 @@ LIB3270_ACTION( deletefield ) } #if defined(X3270_ANSI) /*[*/ if (IN_ANSI) { - net_send_kill(); + net_send_kill(hSession); return 0; } #endif /*]*/ diff --git a/src/lib3270/sf.c b/src/lib3270/sf.c index b3c699a..e113628 100644 --- a/src/lib3270/sf.c +++ b/src/lib3270/sf.c @@ -357,7 +357,7 @@ sf_read_part(unsigned char buf[], unsigned buflen) return PDS_BAD_CMD; } trace_ds(&h3270,"\n"); - ctlr_read_modified(AID_QREPLY, True); + ctlr_read_modified(&h3270, AID_QREPLY, True); break; case SNA_CMD_RB: trace_ds(&h3270," ReadBuffer"); @@ -375,7 +375,7 @@ sf_read_part(unsigned char buf[], unsigned buflen) return PDS_BAD_CMD; } trace_ds(&h3270,"\n"); - ctlr_read_modified(AID_QREPLY, False); + ctlr_read_modified(&h3270, AID_QREPLY, False); break; default: trace_ds(&h3270," unknown type 0x%02x\n", buf[4]); diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 9a92f05..c4cc117 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -2850,8 +2850,9 @@ static void tn3270e_nak(H3270 *hSession, enum pds rv) net_rawout(hSession, rsp_buf, rsp_len); } -#if defined(X3270_TRACE) /*[*/ -/* Add a dummy TN3270E header to the output buffer. */ +/* +#if defined(X3270_TRACE) +// Add a dummy TN3270E header to the output buffer. Boolean net_add_dummy_tn3270e(void) { @@ -2883,7 +2884,8 @@ net_add_dummy_tn3270e(void) h3270.obptr += EH_SIZE; return True; } -#endif /*]*/ +#endif +*/ #endif /*]*/ #if defined(X3270_TRACE) /*[*/ @@ -2900,94 +2902,66 @@ net_add_eor(unsigned char *buf, int len) #if defined(X3270_ANSI) /*[*/ -/* - * net_sendc - * Send a character of user data over the network in ANSI mode. +/** + * Send a character of user data over the network in ANSI mode. + * + * @param hSession Session handle. + * @param c Character to send. + * */ void -net_sendc(char c) +net_sendc(H3270 *hSession, char c) { - if (c == '\r' && !h3270.linemode -/* -#if defined(LOCAL_PROCESS) - && !local_process -#endif -*/ - ) { + if (c == '\r' && !hSession->linemode) + { /* CR must be quoted */ - net_cookout(&h3270,"\r\0", 2); - } else { - net_cookout(&h3270,&c, 1); + net_cookout(hSession,"\r\0", 2); + } + else + { + net_cookout(hSession,&c, 1); } } - -/* - * net_sends - * Send a null-terminated string of user data in ANSI mode. +/** + * Send a null-terminated string of user data in ANSI mode. + * + * @param hSession Session handle. + * @param s String to send. */ -void -net_sends(const char *s) +void net_sends(H3270 *hSession,const char *s) { - net_cookout(&h3270, s, strlen(s)); + net_cookout(hSession, s, strlen(s)); } - -/* - * net_send_erase - * Sends the KILL character in ANSI mode. +/** + * Sends the ERASE character in ANSI mode. + * */ -void -net_send_erase(void) +void net_send_erase(H3270 *hSession) { - net_cookout(&h3270, &verase, 1); + net_cookout(hSession, &verase, 1); } - -/* - * net_send_kill +/** * Sends the KILL character in ANSI mode. */ -void -net_send_kill(void) +void net_send_kill(H3270 *hSession) { - net_cookout(&h3270, &vkill, 1); + net_cookout(hSession, &vkill, 1); } - -/* - * net_send_werase - * Sends the WERASE character in ANSI mode. +/** + * Sends the WERASE character in ANSI mode. */ -void -net_send_werase(void) +void net_send_werase(H3270 *hSession) { - net_cookout(&h3270, &vwerase, 1); + net_cookout(hSession, &vwerase, 1); } #endif /*]*/ - -#if defined(X3270_MENUS) /*[*/ /* - * External entry points to negotiate line or character mode. - */ /* -void -net_linemode(void) -{ - if (!CONNECTED) - return; - if (hisopts[TELOPT_ECHO]) { - dont_opt[2] = TELOPT_ECHO; - net_rawout(dont_opt, sizeof(dont_opt)); - trace_dsn(&h3270,"SENT %s %s\n", cmd(DONT), opt(TELOPT_ECHO)); - } - if (hisopts[TELOPT_SGA]) { - dont_opt[2] = TELOPT_SGA; - net_rawout(dont_opt, sizeof(dont_opt)); - trace_dsn(&h3270,"SENT %s %s\n", cmd(DONT), opt(TELOPT_SGA)); - } -} -*/ +#if defined(X3270_MENUS) void net_charmode(H3270 *hSession) { @@ -3008,9 +2982,9 @@ void net_charmode(H3270 *hSession) trace_dsn(hSession,"SENT %s %s\n", cmd(DO), opt(TELOPT_SGA)); } } -#endif /*]*/ +#endif +*/ - /* * net_break * Send telnet break, which is used to implement 3270 ATTN. @@ -3107,138 +3081,6 @@ parse_ctlchar(char *s) } #endif /*]*/ -#if (defined(X3270_MENUS) || defined(C3270)) && defined(X3270_ANSI) /*[*/ -/* - * net_linemode_chars - * Report line-mode characters. - */ /* -struct ctl_char * -net_linemode_chars(void) -{ - static struct ctl_char c[9]; - - c[0].name = "intr"; (void) strcpy(c[0].value, ctl_see(vintr)); - c[1].name = "quit"; (void) strcpy(c[1].value, ctl_see(vquit)); - c[2].name = "erase"; (void) strcpy(c[2].value, ctl_see(verase)); - c[3].name = "kill"; (void) strcpy(c[3].value, ctl_see(vkill)); - c[4].name = "eof"; (void) strcpy(c[4].value, ctl_see(veof)); - c[5].name = "werase"; (void) strcpy(c[5].value, ctl_see(vwerase)); - c[6].name = "rprnt"; (void) strcpy(c[6].value, ctl_see(vrprnt)); - c[7].name = "lnext"; (void) strcpy(c[7].value, ctl_see(vlnext)); - c[8].name = 0; - - return c; -} */ -#endif /*]*/ - -#if defined(X3270_TRACE) /*[*/ -/* - * Construct a string to reproduce the current TELNET options. - * Returns a Boolean indicating whether it is necessary. - */ /* -Boolean -net_snap_options(void) -{ - Boolean any = False; - int i; - static unsigned char ttype_str[] = { - IAC, DO, TELOPT_TTYPE, - IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE - }; - - if (!CONNECTED) - return False; - - h3270.obptr = h3270.obuf; - - // Do TTYPE first. - if (h3270.myopts[TELOPT_TTYPE]) { - unsigned j; - - space3270out(sizeof(ttype_str)); - for (j = 0; j < sizeof(ttype_str); j++) - *h3270.obptr++ = ttype_str[j]; - } - - // Do the other options. - for (i = 0; i < LIB3270_TELNET_N_OPTS; i++) { - space3270out(6); - if (i == TELOPT_TTYPE) - continue; - if (h3270.hisopts[i]) { - *h3270.obptr++ = IAC; - *h3270.obptr++ = WILL; - *h3270.obptr++ = (unsigned char)i; - any = True; - } - if (h3270.myopts[i]) { - *h3270.obptr++ = IAC; - *h3270.obptr++ = DO; - *h3270.obptr++ = (unsigned char)i; - any = True; - } - } - -#if defined(X3270_TN3270E) - // If we're in TN3270E mode, snap the subnegotations as well. - if (h3270.myopts[TELOPT_TN3270E]) { - any = True; - - space3270out(5 + - ((h3270.connected_type != CN) ? strlen(h3270.connected_type) : 0) + - ((h3270.connected_lu != CN) ? + strlen(h3270.connected_lu) : 0) + - 2); - *h3270.obptr++ = IAC; - *h3270.obptr++ = SB; - *h3270.obptr++ = TELOPT_TN3270E; - *h3270.obptr++ = TN3270E_OP_DEVICE_TYPE; - *h3270.obptr++ = TN3270E_OP_IS; - if (h3270.connected_type != CN) { - (void) memcpy(h3270.obptr, h3270.connected_type,strlen(h3270.connected_type)); - h3270.obptr += strlen(h3270.connected_type); - } - if (h3270.connected_lu != CN) { - *h3270.obptr++ = TN3270E_OP_CONNECT; - (void) memcpy(h3270.obptr, h3270.connected_lu,strlen(h3270.connected_lu)); - h3270.obptr += strlen(h3270.connected_lu); - } - *h3270.obptr++ = IAC; - *h3270.obptr++ = SE; - - space3270out(38); - (void) memcpy(h3270.obptr, functions_req, 4); - h3270.obptr += 4; - *h3270.obptr++ = TN3270E_OP_IS; - for (i = 0; i < 32; i++) { - if (h3270.e_funcs & E_OPT(i)) - *h3270.obptr++ = i; - } - *h3270.obptr++ = IAC; - *h3270.obptr++ = SE; - - if (h3270.tn3270e_bound) { - tn3270e_header *h; - - space3270out(EH_SIZE + 3); - h = (tn3270e_header *)h3270.obptr; - h->data_type = TN3270E_DT_BIND_IMAGE; - h->request_flag = 0; - h->response_flag = 0; - h->seq_number[0] = 0; - h->seq_number[1] = 0; - h3270.obptr += EH_SIZE; - *h3270.obptr++ = 1; // dummy - *h3270.obptr++ = IAC; - *h3270.obptr++ = EOR; - } - } -#endif - return any; -} -*/ -#endif - - /* * Set blocking/non-blocking mode on the socket. On error, pops up an error * message, but does not close the socket. diff --git a/src/lib3270/telnetc.h b/src/lib3270/telnetc.h index 6f014ab..ed4942a 100644 --- a/src/lib3270/telnetc.h +++ b/src/lib3270/telnetc.h @@ -30,10 +30,10 @@ struct ctl_char { }; LIB3270_INTERNAL void net_abort(H3270 *hSession); -LIB3270_INTERNAL Boolean net_add_dummy_tn3270e(void); +// LIB3270_INTERNAL Boolean net_add_dummy_tn3270e(H3270 *hSession); LIB3270_INTERNAL void net_add_eor(unsigned char *buf, int len); LIB3270_INTERNAL void net_break(H3270 *hSession); -LIB3270_INTERNAL void net_charmode(H3270 *hSession); +// LIB3270_INTERNAL void net_charmode(H3270 *hSession); LIB3270_INTERNAL int net_connect(H3270 *session, const char *, char *, Boolean, Boolean *, Boolean *); LIB3270_INTERNAL void net_disconnect(H3270 *session); LIB3270_INTERNAL void net_exception(H3270 *session); @@ -43,15 +43,15 @@ LIB3270_INTERNAL void net_interrupt(H3270 *hSession); // LIB3270_INTERNAL void net_linemode(void); // LIB3270_INTERNAL struct ctl_char *net_linemode_chars(void); LIB3270_INTERNAL void net_output(H3270 *hSession); -LIB3270_INTERNAL const char *net_query_bind_plu_name(void); -LIB3270_INTERNAL const char *net_query_connection_state(void); -LIB3270_INTERNAL const char *net_query_host(void); -LIB3270_INTERNAL const char *net_query_lu_name(void); -LIB3270_INTERNAL void net_sendc(char c); -LIB3270_INTERNAL void net_sends(const char *s); -LIB3270_INTERNAL void net_send_erase(void); -LIB3270_INTERNAL void net_send_kill(void); -LIB3270_INTERNAL void net_send_werase(void); +//LIB3270_INTERNAL const char *net_query_bind_plu_name(void); +//LIB3270_INTERNAL const char *net_query_connection_state(void); +//LIB3270_INTERNAL const char *net_query_host(void); +//LIB3270_INTERNAL const char *net_query_lu_name(void); +LIB3270_INTERNAL void net_sendc(H3270 *hSession, char c); +LIB3270_INTERNAL void net_sends(H3270 *hSession, const char *s); +LIB3270_INTERNAL void net_send_erase(H3270 *hSession); +LIB3270_INTERNAL void net_send_kill(H3270 *hSession); +LIB3270_INTERNAL void net_send_werase(H3270 *hSession); // LIB3270_INTERNAL Boolean net_snap_options(void); LIB3270_INTERNAL void space3270out(H3270 *hSession, int n); // LIB3270_INTERNAL const char *tn3270e_current_opts(void); -- libgit2 0.21.2