From 0b280c57589410d9631cf74dae2aafdc50fb9868 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 30 Jul 2012 19:30:39 +0000 Subject: [PATCH] Migrando mais funções da API para a versão multi-sessão --- pw3270.cbp | 1 + src/lib3270/ctlr.c | 40 ++++++++++++++++++++-------------------- src/lib3270/ft_dft.c | 27 ++++++++++++++------------- src/lib3270/rpq.c | 2 +- src/lib3270/sf.c | 24 ++++++++++++------------ src/lib3270/telnet.c | 376 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/lib3270/telnetc.h | 4 ++-- src/pw3270/common/config.c | 2 +- 8 files changed, 261 insertions(+), 215 deletions(-) diff --git a/pw3270.cbp b/pw3270.cbp index 50057b7..2a02ae5 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -52,6 +52,7 @@ + diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 9bc88a8..e296102 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -547,7 +547,7 @@ static void insert_sa1(H3270 *hSession, unsigned char attr, unsigned char value, if (value == *currentp) return; *currentp = value; - space3270out(3); + space3270out(hSession,3); *hSession->obptr++ = ORDER_SA; *hSession->obptr++ = attr; *hSession->obptr++ = value; @@ -633,7 +633,7 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) switch (aid_byte) { case AID_SYSREQ: /* test request */ - space3270out(4); + space3270out(&h3270,4); *h3270.obptr++ = 0x01; /* soh */ *h3270.obptr++ = 0x5b; /* % */ *h3270.obptr++ = 0x61; /* / */ @@ -656,7 +656,7 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) default: /* ordinary AID */ if (!IN_SSCP) { - space3270out(3); + space3270out(&h3270,3); *h3270.obptr++ = aid_byte; trace_ds("%s",see_aid(aid_byte)); if (short_read) @@ -664,7 +664,7 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) ENCODE_BADDR(h3270.obptr, h3270.cursor_addr); trace_ds("%s",rcba(&h3270,h3270.cursor_addr)); } else { - space3270out(1); /* just in case */ + space3270out(&h3270,1); /* just in case */ } break; } @@ -683,7 +683,7 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) Boolean any = False; INC_BA(baddr); - space3270out(3); + space3270out(&h3270,3); *h3270.obptr++ = ORDER_SBA; ENCODE_BADDR(h3270.obptr, baddr); trace_ds(" SetBufferAddress%s (Cols: %d Rows: %d)", rcba(&h3270,baddr), h3270.cols, h3270.rows); @@ -693,14 +693,14 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) h3270.ea_buf[baddr].cc) { insert_sa(&h3270,baddr,¤t_fg,¤t_bg,¤t_gr,¤t_cs,&any); if (h3270.ea_buf[baddr].cs & CS_GE) { - space3270out(1); + space3270out(&h3270,1); *h3270.obptr++ = ORDER_GE; if (any) trace_ds("'"); trace_ds(" GraphicEscape"); any = False; } - space3270out(1); + space3270out(&h3270,1); *h3270.obptr++ = h3270.ea_buf[baddr].cc; if (!any) trace_ds(" '"); @@ -733,14 +733,14 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) if (h3270.ea_buf[baddr].cc) { insert_sa(&h3270,baddr,¤t_fg,¤t_bg,¤t_gr,¤t_cs,&any); if (h3270.ea_buf[baddr].cs & CS_GE) { - space3270out(1); + space3270out(&h3270,1); *h3270.obptr++ = ORDER_GE; if (any) trace_ds("' "); trace_ds(" GraphicEscape "); any = False; } - space3270out(1); + space3270out(&h3270,1); *h3270.obptr++ = h3270.ea_buf[baddr].cc; if (!any) trace_ds("%s","'"); @@ -763,7 +763,7 @@ ctlr_read_modified(unsigned char aid_byte, Boolean all) rm_done: trace_ds("\n"); - net_output(); + net_output(&h3270); } /* @@ -791,7 +791,7 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) trace_ds("> "); hSession->obptr = hSession->obuf; - space3270out(3); + space3270out(hSession,3); *hSession->obptr++ = aid_byte; ENCODE_BADDR(hSession->obptr, hSession->cursor_addr); trace_ds("%s%s", see_aid(aid_byte), rcba(hSession,hSession->cursor_addr)); @@ -802,12 +802,12 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) { if (hSession->reply_mode == SF_SRM_FIELD) { - space3270out(2); + space3270out(hSession,2); *hSession->obptr++ = ORDER_SF; } else { - space3270out(4); + space3270out(hSession,4); *hSession->obptr++ = ORDER_SFE; attr_count = hSession->obptr - hSession->obuf; *hSession->obptr++ = 1; /* for now */ @@ -825,21 +825,21 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) if (hSession->reply_mode != SF_SRM_FIELD) { if (hSession->ea_buf[baddr].fg) { - space3270out(2); + space3270out(hSession,2); *hSession->obptr++ = XA_FOREGROUND; *hSession->obptr++ = hSession->ea_buf[baddr].fg; trace_ds("%s", see_efa(XA_FOREGROUND, hSession->ea_buf[baddr].fg)); (*(hSession->obuf + attr_count))++; } if (hSession->ea_buf[baddr].bg) { - space3270out(2); + space3270out(hSession,2); *hSession->obptr++ = XA_BACKGROUND; *hSession->obptr++ = hSession->ea_buf[baddr].bg; trace_ds("%s", see_efa(XA_BACKGROUND, hSession->ea_buf[baddr].bg)); (*(hSession->obuf + attr_count))++; } if (hSession->ea_buf[baddr].gr) { - space3270out(2); + space3270out(hSession,2); *hSession->obptr++ = XA_HIGHLIGHTING; *hSession->obptr++ = hSession->ea_buf[baddr].gr | 0xf0; trace_ds("%s", see_efa(XA_HIGHLIGHTING, @@ -847,7 +847,7 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) (*(hSession->obuf + attr_count))++; } if (hSession->ea_buf[baddr].cs & CS_MASK) { - space3270out(2); + space3270out(hSession,2); *hSession->obptr++ = XA_CHARSET; *hSession->obptr++ = host_cs(hSession->ea_buf[baddr].cs); trace_ds("%s", see_efa(XA_CHARSET,host_cs(hSession->ea_buf[baddr].cs))); @@ -858,14 +858,14 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) } else { insert_sa(hSession,baddr,¤t_fg,¤t_bg,¤t_gr,¤t_cs,&any); if (hSession->ea_buf[baddr].cs & CS_GE) { - space3270out(1); + space3270out(hSession,1); *hSession->obptr++ = ORDER_GE; if (any) trace_ds("'"); trace_ds(" GraphicEscape"); any = False; } - space3270out(1); + space3270out(hSession,1); *hSession->obptr++ = hSession->ea_buf[baddr].cc; if (hSession->ea_buf[baddr].cc <= 0x3f || hSession->ea_buf[baddr].cc == 0xff) { @@ -887,7 +887,7 @@ void ctlr_read_buffer(H3270 *hSession, unsigned char aid_byte) trace_ds("'"); trace_ds("\n"); - net_output(); + net_output(hSession); } #if defined(X3270_TRACE) /*[*/ diff --git a/src/lib3270/ft_dft.c b/src/lib3270/ft_dft.c index 8be86b4..6f63413 100644 --- a/src/lib3270/ft_dft.c +++ b/src/lib3270/ft_dft.c @@ -192,12 +192,12 @@ dft_open_request(unsigned short len, unsigned char *cp) /* Acknowledge the Open. */ trace_ds("> WriteStructuredField FileTransferData OpenAck\n"); h3270.obptr = h3270.obuf; - space3270out(6); + space3270out(&h3270,6); *h3270.obptr++ = AID_SF; SET16(h3270.obptr, 5); *h3270.obptr++ = SF_TRANSFER_DATA; SET16(h3270.obptr, 9); - net_output(); + net_output(&h3270); } /* Process an Insert request. */ @@ -317,7 +317,7 @@ dft_data_insert(struct data_buffer *data_bufr) /* Send an acknowledgement frame back. */ trace_ds("> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum); h3270.obptr = h3270.obuf; - space3270out(12); + space3270out(&h3270,12); *h3270.obptr++ = AID_SF; SET16(h3270.obptr, 11); *h3270.obptr++ = SF_TRANSFER_DATA; @@ -325,7 +325,7 @@ dft_data_insert(struct data_buffer *data_bufr) SET16(h3270.obptr, TR_RECNUM_HDR); SET32(h3270.obptr, recnum); recnum++; - net_output(); + net_output(&h3270); } /* Process a Set Cursor request. */ @@ -354,7 +354,7 @@ dft_get_request(void) /* Read a buffer's worth. */ set_dft_buffersize(); - space3270out(dft_buffersize); + space3270out(&h3270,dft_buffersize); numbytes = dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ bufptr = h3270.obuf + 17; while (!dft_eof && numbytes) { @@ -464,7 +464,7 @@ dft_get_request(void) h3270.aid = AID_SF; /* Write the data. */ - net_output(); + net_output(&h3270); ft_update_length((H3270FT *) h3270.ft); } @@ -479,12 +479,12 @@ dft_close_request(void) trace_ds(" Close\n"); trace_ds("> WriteStructuredField FileTransferData CloseAck\n"); h3270.obptr = h3270.obuf; - space3270out(6); + space3270out(&h3270,6); *h3270.obptr++ = AID_SF; SET16(h3270.obptr, 5); /* length */ *h3270.obptr++ = SF_TRANSFER_DATA; SET16(h3270.obptr, TR_CLOSE_REPLY); - net_output(); + net_output(&h3270); } /* Abort a transfer. */ @@ -502,7 +502,7 @@ static void dft_abort(unsigned short code, const char *fmt, ...) trace_ds("> WriteStructuredField FileTransferData Error\n"); h3270.obptr = h3270.obuf; - space3270out(10); + space3270out(&h3270,10); *h3270.obptr++ = AID_SF; SET16(h3270.obptr, 9); /* length */ *h3270.obptr++ = SF_TRANSFER_DATA; @@ -510,7 +510,7 @@ static void dft_abort(unsigned short code, const char *fmt, ...) *h3270.obptr++ = TR_ERROR_REPLY; SET16(h3270.obptr, TR_ERROR_HDR); SET16(h3270.obptr, TR_ERR_CMDFAIL); - net_output(); + net_output(&h3270); /* Update the pop-up and state. */ ft_aborting((H3270FT *) h3270.ft); @@ -533,13 +533,14 @@ filter_len(char *s, register int len) void dft_read_modified(void) { - if (dft_savebuf_len) { + if (dft_savebuf_len) + { trace_ds("> WriteStructuredField FileTransferData\n"); h3270.obptr = h3270.obuf; - space3270out(dft_savebuf_len); + space3270out(&h3270,dft_savebuf_len); memcpy(h3270.obptr, dft_savebuf, dft_savebuf_len); h3270.obptr += dft_savebuf_len; - net_output(); + net_output(&h3270); } } diff --git a/src/lib3270/rpq.c b/src/lib3270/rpq.c index fb4cdea..dc61d1b 100644 --- a/src/lib3270/rpq.c +++ b/src/lib3270/rpq.c @@ -140,7 +140,7 @@ void do_qr_rpqnames(void) * By pre-allocating the space I don't have to worry about the * possibility of addresses changing. */ - space3270out(4+4+1+remaining); /* Maximum space for an RPQNAME item */ + space3270out(&h3270,4+4+1+remaining); /* Maximum space for an RPQNAME item */ SET32(h3270.obptr, 0); /* Device number, 0 = All */ SET32(h3270.obptr, 0); /* Model number, 0 = All */ diff --git a/src/lib3270/sf.c b/src/lib3270/sf.c index 3e3fbba..32c130a 100644 --- a/src/lib3270/sf.c +++ b/src/lib3270/sf.c @@ -654,7 +654,7 @@ static void query_reply_start(void) { h3270.obptr = h3270.obuf; - space3270out(1); + space3270out(&h3270,1); *h3270.obptr++ = AID_SF; qr_in_progress = True; } @@ -684,7 +684,7 @@ do_query_reply(unsigned char code) int obptr0 = h3270.obptr - h3270.obuf; Boolean full = True; - space3270out(4); + space3270out(&h3270,4); h3270.obptr += 2; /* skip length for now */ *h3270.obptr++ = SFID_QREPLY; *h3270.obptr++ = code; @@ -723,7 +723,7 @@ do_qr_summary(void) const char *comma = ""; trace_ds("> QueryReply(Summary("); - space3270out(NSR); + space3270out(&h3270,NSR); for (i = 0; i < NSR; i++) { #if defined(X3270_DBCS) /*[*/ if (dbcs || replies[i].code != QR_DBCS_ASIA) { @@ -744,7 +744,7 @@ do_qr_usable_area(void) unsigned short num, denom; trace_ds("> QueryReply(UsableArea)\n"); - space3270out(19); + space3270out(&h3270,19); *h3270.obptr++ = 0x01; /* 12/14-bit addressing */ *h3270.obptr++ = 0x00; /* no special character features */ SET16(h3270.obptr, h3270.maxCOLS); /* usable width */ @@ -781,7 +781,7 @@ do_qr_color(void) color_max = h3270.color8 ? 8: 16; /* report on 8 or 16 colors */ - space3270out(4 + 2*15); + space3270out(&h3270,4 + 2*15); *h3270.obptr++ = 0x00; /* no options */ *h3270.obptr++ = color_max; /* report on 8 or 16 colors */ *h3270.obptr++ = 0x00; /* default color: */ @@ -812,7 +812,7 @@ static void do_qr_highlighting(void) { trace_ds("> QueryReply(Highlighting)\n"); - space3270out(11); + space3270out(&h3270,11); *h3270.obptr++ = 5; /* report on 5 pairs */ *h3270.obptr++ = XAH_DEFAULT; /* default: */ *h3270.obptr++ = XAH_NORMAL; /* normal */ @@ -830,7 +830,7 @@ static void do_qr_reply_modes(void) { trace_ds("> QueryReply(ReplyModes)\n"); - space3270out(3); + space3270out(&h3270,3); *h3270.obptr++ = SF_SRM_FIELD; *h3270.obptr++ = SF_SRM_XFIELD; *h3270.obptr++ = SF_SRM_CHAR; @@ -857,7 +857,7 @@ static void do_qr_alpha_part(void) { trace_ds("> QueryReply(AlphanumericPartitions)\n"); - space3270out(4); + space3270out(&h3270,4); *h3270.obptr++ = 0; /* 1 partition */ SET16(h3270.obptr, h3270.maxROWS * h3270.maxCOLS); /* buffer space */ *h3270.obptr++ = 0; /* no special features */ @@ -867,7 +867,7 @@ static void do_qr_charsets(void) { trace_ds("> QueryReply(CharacterSets)\n"); - space3270out(64); + space3270out(&h3270,64); #if defined(X3270_DBCS) /*[*/ if (dbcs) *h3270.obptr++ = 0x8e; /* flags: GE, CGCSGID, DBCS */ @@ -953,7 +953,7 @@ do_qr_ddm(void) set_dft_buffersize(); trace_ds("> QueryReply(DistributedDataManagement)\n"); - space3270out(8); + space3270out(&h3270,8); SET16(h3270.obptr,0); /* set reserved field to 0 */ SET16(h3270.obptr, dft_buffersize); /* set inbound length limit INLIM */ SET16(h3270.obptr, dft_buffersize); /* set outbound length limit OUTLIM */ @@ -965,7 +965,7 @@ static void do_qr_imp_part(void) { trace_ds("> QueryReply(ImplicitPartition)\n"); - space3270out(13); + space3270out(&h3270,13); *h3270.obptr++ = 0x0; /* reserved */ *h3270.obptr++ = 0x0; *h3270.obptr++ = 0x0b; /* length of display size */ @@ -980,6 +980,6 @@ do_qr_imp_part(void) static void query_reply_end(void) { - net_output(); + net_output(&h3270); kybd_inhibit(&h3270,True); } diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 3e86322..971c653 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -231,7 +231,7 @@ static void tn3270e_nak(H3270 *hSession, enum pds); #endif /*]*/ #if defined(X3270_ANSI) /*[*/ -static void do_data(char c); +static void do_data(H3270 *hSession, char c); static void do_intr(H3270 *hSession, char c); static void do_quit(H3270 *hSession, char c); static void do_cerase(H3270 *hSession, char c); @@ -756,21 +756,21 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo #undef close_fail /* Set up the LU list. */ -static void -setup_lus(void) +static void setup_lus(H3270 *hSession) { char *lu; char *comma; int n_lus = 1; int i; - h3270.connected_lu = CN; - h3270.connected_type = CN; + hSession->connected_lu = CN; + hSession->connected_type = CN; - if (!h3270.luname[0]) { - Replace(h3270.lus, NULL); - h3270.curr_lu = (char **)NULL; - h3270.try_lu = CN; + if (!hSession->luname[0]) + { + Replace(hSession->lus, NULL); + hSession->curr_lu = (char **)NULL; + hSession->try_lu = CN; return; } @@ -778,8 +778,9 @@ setup_lus(void) * Count the commas in the LU name. That plus one is the * number of LUs to try. */ - lu = h3270.luname; - while ((comma = strchr(lu, ',')) != CN) { + lu = hSession->luname; + while ((comma = strchr(lu, ',')) != CN) + { n_lus++; lu++; } @@ -788,23 +789,27 @@ setup_lus(void) * Allocate enough memory to construct an argv[] array for * the LUs. */ - Replace(h3270.lus,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(h3270.luname) + 1)); + Replace(hSession->lus,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(hSession->luname) + 1)); /* Copy each LU into the array. */ - lu = (char *)(h3270.lus + n_lus + 1); - (void) strcpy(lu, h3270.luname); + lu = (char *)(hSession->lus + n_lus + 1); + (void) strcpy(lu, hSession->luname); + i = 0; - do { - h3270.lus[i++] = lu; + do + { + hSession->lus[i++] = lu; comma = strchr(lu, ','); - if (comma != CN) { + if (comma != CN) + { *comma = '\0'; lu = comma + 1; } } while (comma != CN); - h3270.lus[i] = CN; - h3270.curr_lu = h3270.lus; - h3270.try_lu = *h3270.curr_lu; + + hSession->lus[i] = CN; + hSession->curr_lu = hSession->lus; + hSession->try_lu = *hSession->curr_lu; } static void net_connected(H3270 *session) @@ -895,7 +900,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *session) need_tls_follows = False; #endif /*]*/ session->telnet_state = TNS_DATA; - session->ibptr = h3270.ibuf; + session->ibptr = session->ibuf; /* clear statistics and flags */ time(&session->ns_time); @@ -908,7 +913,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *session) session->tn3270e_submode = E_NONE; session->tn3270e_bound = 0; - setup_lus(); + setup_lus(session); check_linemode(session,True); @@ -1444,7 +1449,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) check_linemode(session,False); } if (c == TELOPT_NAWS) - send_naws(&h3270); + send_naws(session); #if defined(HAVE_LIBSSL) /*[*/ if (c == TELOPT_STARTTLS) { static unsigned char follows_msg[] = { @@ -1456,8 +1461,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) * Send IAC SB STARTTLS FOLLOWS IAC SE * to announce that what follows is TLS. */ - net_rawout(&h3270, follows_msg, - sizeof(follows_msg)); + net_rawout(session, follows_msg, sizeof(follows_msg)); trace_dsn("SENT %s %s FOLLOWS %s\n", cmd(SB), opt(TELOPT_STARTTLS), @@ -1469,53 +1473,57 @@ static int telnet_fsm(H3270 *session, unsigned char c) default: wont: wont_opt[2] = c; - net_rawout(&h3270, wont_opt, sizeof(wont_opt)); + net_rawout(session, wont_opt, sizeof(wont_opt)); trace_dsn("SENT %s %s\n", cmd(WONT), opt(c)); break; } - h3270.telnet_state = TNS_DATA; + session->telnet_state = TNS_DATA; break; case TNS_DONT: /* telnet PLEASE DON'T DO OPTION command */ trace_dsn("%s\n", opt(c)); - if (h3270.myopts[c]) { - h3270.myopts[c] = 0; + if (session->myopts[c]) { + session->myopts[c] = 0; wont_opt[2] = c; - net_rawout(&h3270, wont_opt, sizeof(wont_opt)); + net_rawout(session, wont_opt, sizeof(wont_opt)); trace_dsn("SENT %s %s\n", cmd(WONT), opt(c)); - check_in3270(&h3270); - check_linemode(&h3270,False); + check_in3270(session); + check_linemode(session,False); } - h3270.telnet_state = TNS_DATA; + session->telnet_state = TNS_DATA; break; case TNS_SB: /* telnet sub-option string command */ if (c == IAC) - h3270.telnet_state = TNS_SB_IAC; + session->telnet_state = TNS_SB_IAC; else - *h3270.sbptr++ = c; + *session->sbptr++ = c; break; case TNS_SB_IAC: /* telnet sub-option string command */ - *h3270.sbptr++ = c; + *session->sbptr++ = c; if (c == SE) { - h3270.telnet_state = TNS_DATA; - if (session->sbbuf[0] == TELOPT_TTYPE && - session->sbbuf[1] == TELQUAL_SEND) { + session->telnet_state = TNS_DATA; + if (session->sbbuf[0] == TELOPT_TTYPE && session->sbbuf[1] == TELQUAL_SEND) + { int tt_len, tb_len; char *tt_out; - trace_dsn("%s %s\n", opt(session->sbbuf[0]), - telquals[session->sbbuf[1]]); - if (session->lus != (char **)NULL && h3270.try_lu == CN) { + trace_dsn("%s %s\n", opt(session->sbbuf[0]),telquals[session->sbbuf[1]]); + + if (session->lus != (char **)NULL && session->try_lu == CN) + { /* None of the LUs worked. */ popup_an_error(NULL,"Cannot connect to specified LU"); return -1; } tt_len = strlen(session->termtype); - if (h3270.try_lu != CN && *h3270.try_lu) { - tt_len += strlen(h3270.try_lu) + 1; - session->connected_lu = h3270.try_lu; - } else + if (session->try_lu != CN && *session->try_lu) + { + tt_len += strlen(session->try_lu) + 1; + session->connected_lu = session->try_lu; + } + else session->connected_lu = CN; + status_lu(session,session->connected_lu); tb_len = 4 + tt_len + 2; @@ -1523,10 +1531,10 @@ static int telnet_fsm(H3270 *session, unsigned char c) (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_IS, session->termtype, - (h3270.try_lu != CN && *h3270.try_lu) ? "@" : "", - (h3270.try_lu != CN && *h3270.try_lu) ? h3270.try_lu : "", + (session->try_lu != CN && *session->try_lu) ? "@" : "", + (session->try_lu != CN && *session->try_lu) ? session->try_lu : "", IAC, SE); - net_rawout(&h3270, (unsigned char *)tt_out, tb_len); + net_rawout(session, (unsigned char *)tt_out, tb_len); trace_dsn("SENT %s %s %s %.*s %s\n", cmd(SB), opt(TELOPT_TTYPE), @@ -1536,25 +1544,24 @@ static int telnet_fsm(H3270 *session, unsigned char c) lib3270_free(tt_out); /* Advance to the next LU name. */ - next_lu(&h3270); + next_lu(session); } #if defined(X3270_TN3270E) /*[*/ - else if (h3270.myopts[TELOPT_TN3270E] && - h3270.sbbuf[0] == TELOPT_TN3270E) { - if (tn3270e_negotiate(&h3270)) + else if (session->myopts[TELOPT_TN3270E] && session->sbbuf[0] == TELOPT_TN3270E) + { + if (tn3270e_negotiate(session)) return -1; } #endif /*]*/ #if defined(HAVE_LIBSSL) /*[*/ - else if (need_tls_follows && - h3270.myopts[TELOPT_STARTTLS] && - h3270.sbbuf[0] == TELOPT_STARTTLS) { - continue_tls(h3270.sbbuf, h3270.sbptr - h3270.sbbuf); + else if (need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) + { + continue_tls(session->sbbuf, session->sbptr - session->sbbuf); } #endif /*]*/ } else { - h3270.telnet_state = TNS_SB; + session->telnet_state = TNS_SB; } break; } @@ -1563,39 +1570,38 @@ static int telnet_fsm(H3270 *session, unsigned char c) #if defined(X3270_TN3270E) /*[*/ /* Send a TN3270E terminal type request. */ -static void -tn3270e_request(void) +static void tn3270e_request(H3270 *hSession) { int tt_len, tb_len; char *tt_out; char *t; - tt_len = strlen(h3270.termtype); - if (h3270.try_lu != CN && *h3270.try_lu) - tt_len += strlen(h3270.try_lu) + 1; + tt_len = strlen(hSession->termtype); + if (hSession->try_lu != CN && *hSession->try_lu) + tt_len += strlen(hSession->try_lu) + 1; tb_len = 5 + tt_len + 2; tt_out = lib3270_malloc(tb_len + 1); t = tt_out; t += sprintf(tt_out, "%c%c%c%c%c%s", IAC, SB, TELOPT_TN3270E, TN3270E_OP_DEVICE_TYPE, - TN3270E_OP_REQUEST, h3270.termtype); + TN3270E_OP_REQUEST, hSession->termtype); /* Convert 3279 to 3278, per the RFC. */ if (tt_out[12] == '9') tt_out[12] = '8'; - if (h3270.try_lu != CN && *h3270.try_lu) - t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, h3270.try_lu); + if (hSession->try_lu != CN && *hSession->try_lu) + t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, hSession->try_lu); (void) sprintf(t, "%c%c", IAC, SE); - net_rawout(&h3270, (unsigned char *)tt_out, tb_len); + net_rawout(hSession, (unsigned char *)tt_out, tb_len); trace_dsn("SENT %s %s DEVICE-TYPE REQUEST %.*s%s%s %s\n", - cmd(SB), opt(TELOPT_TN3270E), (int) strlen(h3270.termtype), tt_out + 5, - (h3270.try_lu != CN && *h3270.try_lu) ? " CONNECT " : "", - (h3270.try_lu != CN && *h3270.try_lu) ? h3270.try_lu : "", + cmd(SB), opt(TELOPT_TN3270E), (int) strlen(hSession->termtype), tt_out + 5, + (hSession->try_lu != CN && *hSession->try_lu) ? " CONNECT " : "", + (hSession->try_lu != CN && *hSession->try_lu) ? hSession->try_lu : "", cmd(SE)); lib3270_free(tt_out); @@ -1604,22 +1610,21 @@ tn3270e_request(void) /* * Back off of TN3270E. */ -static void -backoff_tn3270e(const char *why) +static void backoff_tn3270e(H3270 *hSession, const char *why) { trace_dsn("Aborting TN3270E: %s\n", why); /* Tell the host 'no'. */ wont_opt[2] = TELOPT_TN3270E; - net_rawout(&h3270, wont_opt, sizeof(wont_opt)); + net_rawout(hSession, wont_opt, sizeof(wont_opt)); trace_dsn("SENT %s %s\n", cmd(WONT), opt(TELOPT_TN3270E)); /* Restore the LU list; we may need to run it again in TN3270 mode. */ - setup_lus(); + setup_lus(hSession); /* Reset our internal state. */ - h3270.myopts[TELOPT_TN3270E] = 0; - check_in3270(&h3270); + hSession->myopts[TELOPT_TN3270E] = 0; + check_in3270(hSession); } /* @@ -1652,7 +1657,7 @@ static int tn3270e_negotiate(H3270 *hSession) /* Host wants us to send our device type. */ trace_dsn("SEND DEVICE-TYPE SE\n"); - tn3270e_request(); + tn3270e_request(hSession); } else { trace_dsn("SEND ??%u SE\n", hSession->sbbuf[2]); } @@ -1711,19 +1716,24 @@ static int tn3270e_negotiate(H3270 *hSession) trace_dsn("REJECT REASON %s SE\n", rsn(hSession->sbbuf[4])); if (hSession->sbbuf[4] == TN3270E_REASON_INV_DEVICE_TYPE || hSession->sbbuf[4] == TN3270E_REASON_UNSUPPORTED_REQ) { - backoff_tn3270e(_( "Host rejected device type or request type" )); + backoff_tn3270e(hSession,_( "Host rejected device type or request type" )); break; } next_lu(hSession); - if (hSession->try_lu != CN) { + if (hSession->try_lu != CN) + { /* Try the next LU. */ - tn3270e_request(); - } else if (hSession->lus != (char **)NULL) { + tn3270e_request(hSession); + } + else if (hSession->lus != (char **)NULL) + { /* No more LUs to try. Give up. */ - backoff_tn3270e(_("Host rejected resource(s)")); - } else { - backoff_tn3270e(_("Device type rejected")); + backoff_tn3270e(hSession,_("Host rejected resource(s)")); + } + else + { + backoff_tn3270e(hSession,_("Device type rejected")); } break; @@ -1782,7 +1792,7 @@ static int tn3270e_negotiate(H3270 *hSession) * They've added something. Abandon * TN3270E, they're brain dead. */ - backoff_tn3270e("Host illegally added function(s)"); + backoff_tn3270e(hSession,_( "Host illegally added function(s)" )); break; } } @@ -2191,11 +2201,11 @@ static void net_cookout(H3270 *hSession, const char *buf, int len) else if (c == 0x08 || c == 0x7f) /* Yes, a hack. */ do_cerase(hSession,c); else - do_data(c); + do_data(hSession,c); } return; } else - net_cookedout(&h3270, buf, len); + net_cookedout(hSession, buf, len); } @@ -2219,35 +2229,36 @@ ansi_process_s(const char *data) ansi_process((unsigned int) *data++); } -static void -forward_data(void) +static void forward_data(H3270 *hSession) { - net_cookedout(&h3270, (char *) h3270.lbuf, h3270.lbptr - h3270.lbuf); - cooked_init(&h3270); + net_cookedout(hSession, (char *) hSession->lbuf, hSession->lbptr - hSession->lbuf); + cooked_init(hSession); } -static void -do_data(char c) +static void do_data(H3270 *hSession, char c) { - if (h3270.lbptr+1 < h3270.lbuf + BUFSZ) { - *h3270.lbptr++ = c; + if (hSession->lbptr+1 < hSession->lbuf + BUFSZ) + { + *hSession->lbptr++ = c; if (c == '\r') - *h3270.lbptr++ = '\0'; + *hSession->lbptr++ = '\0'; if (c == '\t') ansi_process((unsigned int) c); else ansi_process_s(ctl_see((int) c)); - } else + } + else ansi_process_s("\007"); - h3270.lnext = 0; - h3270.backslashed = 0; + + hSession->lnext = 0; + hSession->backslashed = 0; } static void do_intr(H3270 *hSession, char c) { if (hSession->lnext) { - do_data(c); + do_data(hSession,c); return; } ansi_process_s(ctl_see((int) c)); @@ -2259,7 +2270,7 @@ static void do_quit(H3270 *hSession, char c) { if (hSession->lnext) { - do_data(c); + do_data(hSession,c); return; } ansi_process_s(ctl_see((int) c)); @@ -2275,14 +2286,16 @@ static void do_cerase(H3270 *hSession, char c) { hSession->lbptr--; ansi_process_s("\b"); - do_data(c); + do_data(hSession,c); return; } + if (hSession->lnext) { - do_data(c); + do_data(hSession,c); return; } + if (hSession->lbptr > hSession->lbuf) { len = strlen(ctl_see((int) *--hSession->lbptr)); @@ -2297,10 +2310,12 @@ static void do_werase(H3270 *hSession, char c) int any = 0; int len; - if (hSession->lnext) { - do_data(c); + if (hSession->lnext) + { + do_data(hSession,c); return; } + while (hSession->lbptr > hSession->lbuf) { char ch; @@ -2327,14 +2342,18 @@ static void do_kill(H3270 *hSession, char c) if (hSession->backslashed) { hSession->lbptr--; ansi_process_s("\b"); - do_data(c); + do_data(hSession,c); return; } - if (hSession->lnext) { - do_data(c); + + if (hSession->lnext) + { + do_data(hSession,c); return; } - while (hSession->lbptr > hSession->lbuf) { + + while (hSession->lbptr > hSession->lbuf) + { len = strlen(ctl_see((int) *--hSession->lbptr)); for (i = 0; i < len; i++) @@ -2346,10 +2365,12 @@ static void do_rprnt(H3270 *hSession, char c) { unsigned char *p; - if (hSession->lnext) { - do_data(c); + if (hSession->lnext) + { + do_data(hSession,c); return; } + ansi_process_s(ctl_see((int) c)); ansi_process_s("\r\n"); for (p = hSession->lbuf; p < hSession->lbptr; p++) @@ -2358,40 +2379,49 @@ static void do_rprnt(H3270 *hSession, char c) static void do_eof(H3270 *hSession, char c) { - if (hSession->backslashed) { + if (hSession->backslashed) + { hSession->lbptr--; ansi_process_s("\b"); - do_data(c); + do_data(hSession,c); return; } - if (hSession->lnext) { - do_data(c); + + if (hSession->lnext) + { + do_data(hSession,c); return; } - do_data(c); - forward_data(); + + do_data(hSession,c); + forward_data(hSession); } static void do_eol(H3270 *hSession, char c) { - if (hSession->lnext) { - do_data(c); + if (hSession->lnext) + { + do_data(hSession,c); return; } - if (hSession->lbptr+2 >= hSession->lbuf + BUFSZ) { + + if (hSession->lbptr+2 >= hSession->lbuf + BUFSZ) + { ansi_process_s("\007"); return; } + *hSession->lbptr++ = '\r'; *hSession->lbptr++ = '\n'; ansi_process_s("\r\n"); - forward_data(); + forward_data(hSession); } static void do_lnext(H3270 *hSession, char c) { - if (hSession->lnext) { - do_data(c); + if (hSession->lnext) + { + do_data(hSession,c); return; } hSession->lnext = 1; @@ -2519,29 +2549,34 @@ static void store3270in(H3270 *hSession, unsigned char c) *hSession->ibptr++ = c; } -/* - * space3270out - * Ensure that more characters will fit in the 3270 output buffer. - * Allocates the buffer in BUFSIZ chunks. - * Allocates hidden space at the front of the buffer for TN3270E. +/** + * Ensure that more characters will fit in the 3270 output buffer. + * + * Allocates the buffer in BUFSIZ chunks. + * Allocates hidden space at the front of the buffer for TN3270E. + * + * @param hSession 3270 session handle. + * @param n Number of characters to set. */ -void space3270out(int n) +void space3270out(H3270 *hSession, int n) { unsigned nc = 0; /* amount of data currently in obuf */ unsigned more = 0; - if (h3270.obuf_size) - nc = h3270.obptr - h3270.obuf; + if (hSession->obuf_size) + nc = hSession->obptr - hSession->obuf; - while ((nc + n + EH_SIZE) > (h3270.obuf_size + more)) { + while ((nc + n + EH_SIZE) > (hSession->obuf_size + more)) + { more += BUFSIZ; } - if (more) { - h3270.obuf_size += more; - h3270.obuf_base = (unsigned char *)Realloc((char *) h3270.obuf_base,h3270.obuf_size); - h3270.obuf = h3270.obuf_base + EH_SIZE; - h3270.obptr = h3270.obuf + nc; + if (more) + { + hSession->obuf_size += more; + hSession->obuf_base = (unsigned char *)Realloc((char *) hSession->obuf_base,hSession->obuf_size); + hSession->obuf = hSession->obuf_base + EH_SIZE; + hSession->obptr = hSession->obuf + nc; } } @@ -2660,66 +2695,75 @@ void trace_netdata(char direction, unsigned const char *buf, int len) #endif // X3270_TRACE -/* - * net_output - * Send 3270 output over the network: +/** + * Send 3270 output over the network. + * + * Send 3270 output over the network: * - Prepend TN3270E header * - Expand IAC to IAC IAC * - Append IAC EOR + * + * @param hSession Session handle + * */ -void -net_output(void) +void net_output(H3270 *hSession) { static unsigned char *xobuf = NULL; static int xobuf_len = 0; int need_resize = 0; unsigned char *nxoptr, *xoptr; -#if defined(X3270_TN3270E) /*[*/ -#define BSTART ((IN_TN3270E || IN_SSCP) ? h3270.obuf_base : h3270.obuf) -#else /*][*/ -#define BSTART obuf -#endif /*]*/ +#if defined(X3270_TN3270E) + #define BSTART ((IN_TN3270E || IN_SSCP) ? hSession->obuf_base : hSession->obuf) +#else + #define BSTART obuf +#endif #if defined(X3270_TN3270E) /*[*/ /* Set the TN3720E header. */ - if (IN_TN3270E || IN_SSCP) { - tn3270e_header *h = (tn3270e_header *) h3270.obuf_base; + if (IN_TN3270E || IN_SSCP) + { + tn3270e_header *h = (tn3270e_header *) hSession->obuf_base; /* Check for sending a TN3270E response. */ - if (h3270.response_required == TN3270E_RSF_ALWAYS_RESPONSE) { - tn3270e_ack(&h3270); - h3270.response_required = TN3270E_RSF_NO_RESPONSE; + if (hSession->response_required == TN3270E_RSF_ALWAYS_RESPONSE) + { + tn3270e_ack(hSession); + hSession->response_required = TN3270E_RSF_NO_RESPONSE; } /* Set the outbound TN3270E header. */ - h->data_type = IN_TN3270E ? - TN3270E_DT_3270_DATA : TN3270E_DT_SSCP_LU_DATA; + h->data_type = IN_TN3270E ? TN3270E_DT_3270_DATA : TN3270E_DT_SSCP_LU_DATA; h->request_flag = 0; h->response_flag = 0; - h->seq_number[0] = (h3270.e_xmit_seq >> 8) & 0xff; - h->seq_number[1] = h3270.e_xmit_seq & 0xff; + h->seq_number[0] = (hSession->e_xmit_seq >> 8) & 0xff; + h->seq_number[1] = hSession->e_xmit_seq & 0xff; - trace_dsn("SENT TN3270E(%s NO-RESPONSE %u)\n",IN_TN3270E ? "3270-DATA" : "SSCP-LU-DATA", h3270.e_xmit_seq); - if (h3270.e_funcs & E_OPT(TN3270E_FUNC_RESPONSES)) - h3270.e_xmit_seq = (h3270.e_xmit_seq + 1) & 0x7fff; + trace_dsn("SENT TN3270E(%s NO-RESPONSE %u)\n",IN_TN3270E ? "3270-DATA" : "SSCP-LU-DATA", hSession->e_xmit_seq); + if (hSession->e_funcs & E_OPT(TN3270E_FUNC_RESPONSES)) + hSession->e_xmit_seq = (hSession->e_xmit_seq + 1) & 0x7fff; } #endif /*]*/ /* Reallocate the expanded output buffer. */ - while (xobuf_len < (h3270.obptr - BSTART + 1) * 2) { + while (xobuf_len < (hSession->obptr - BSTART + 1) * 2) + { xobuf_len += BUFSZ; need_resize++; } - if (need_resize) { + + if (need_resize) + { Replace(xobuf, (unsigned char *)lib3270_malloc(xobuf_len)); } /* Copy and expand IACs. */ xoptr = xobuf; nxoptr = BSTART; - while (nxoptr < h3270.obptr) { - if ((*xoptr++ = *nxoptr++) == IAC) { + while (nxoptr < hSession->obptr) + { + if ((*xoptr++ = *nxoptr++) == IAC) + { *xoptr++ = IAC; } } @@ -2727,10 +2771,10 @@ net_output(void) /* Append the IAC EOR and transmit. */ *xoptr++ = IAC; *xoptr++ = EOR; - net_rawout(&h3270,xobuf, xoptr - xobuf); + net_rawout(hSession,xobuf, xoptr - xobuf); trace_dsn("SENT EOR\n"); - h3270.ns_rsent++; + hSession->ns_rsent++; #undef BSTART } @@ -2808,7 +2852,7 @@ net_add_dummy_tn3270e(void) if (!IN_E || h3270.tn3270e_submode == E_NONE) return False; - space3270out(EH_SIZE); + space3270out(&h3270,EH_SIZE); h = (tn3270e_header *)h3270.obptr; switch (h3270.tn3270e_submode) { diff --git a/src/lib3270/telnetc.h b/src/lib3270/telnetc.h index 9acfffe..d4ef4fe 100644 --- a/src/lib3270/telnetc.h +++ b/src/lib3270/telnetc.h @@ -42,7 +42,7 @@ LIB3270_INTERNAL void net_input(H3270 *session); LIB3270_INTERNAL void net_interrupt(void); // LIB3270_INTERNAL void net_linemode(void); // LIB3270_INTERNAL struct ctl_char *net_linemode_chars(void); -LIB3270_INTERNAL void net_output(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); @@ -53,7 +53,7 @@ LIB3270_INTERNAL void net_send_erase(void); LIB3270_INTERNAL void net_send_kill(void); LIB3270_INTERNAL void net_send_werase(void); // LIB3270_INTERNAL Boolean net_snap_options(void); -LIB3270_INTERNAL void space3270out(int n); +LIB3270_INTERNAL void space3270out(H3270 *hSession, int n); // LIB3270_INTERNAL const char *tn3270e_current_opts(void); // LIB3270_INTERNAL char *net_proxy_type(void); //LIB3270_INTERNAL char *net_proxy_host(void); diff --git a/src/pw3270/common/config.c b/src/pw3270/common/config.c index 1efc3dc..4fe2f87 100644 --- a/src/pw3270/common/config.c +++ b/src/pw3270/common/config.c @@ -18,7 +18,7 @@ * 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 config.c e possui 389 linhas de código. + * Este programa está nomeado como config.c e possui - linhas de código. * * Contatos: * -- libgit2 0.21.2