Commit 6c517eb68a49480fe96f86b6ef1f9dd810d726bb

Authored by perry.werneck@gmail.com
1 parent 6cdb6a5a

Mais ajustes para multi-sessao

src/include/lib3270.h
1 1 /*
2   - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3 3 * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4 4 * aplicativos mainframe. Registro no INPI sob o nome G3270.
5 5 *
... ... @@ -23,7 +23,7 @@
23 23 * Contatos:
24 24 *
25 25 * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26   - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27 27 * licinio@bb.com.br (Licínio Luis Branco)
28 28 * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29 29 *
... ...
src/lib3270/hostc.h
1 1 /*
2   - * Copyright 1995, 1996, 1999, 2000, 2001, 2002, 2003, 2005 by Paul Mattes.
3   - * Permission to use, copy, modify, and distribute this software and its
4   - * documentation for any purpose and without fee is hereby granted,
5   - * provided that the above copyright notice appear in all copies and that
6   - * both that copyright notice and this permission notice appear in
7   - * supporting documentation.
8   - *
9   - * x3270, c3270, s3270 and tcl3270 are distributed in the hope that they will
10   - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file LICENSE
12   - * for more details.
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como hostc.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
13 30 */
14 31  
15 32 /*
... ... @@ -19,7 +36,7 @@
19 36  
20 37 #include "api.h"
21 38  
22   - #define st_changed(tx,mode) lib3270_st_changed(NULL,tx,mode)
  39 +// #define st_changed(tx,mode) lib3270_st_changed(NULL,tx,mode)
23 40  
24 41 LIB3270_INTERNAL void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode);
25 42 LIB3270_INTERNAL void host_connected(H3270 *session);
... ...
src/lib3270/telnet.c
... ... @@ -210,8 +210,8 @@ static char vlnext;
210 210 static int telnet_fsm(H3270 *session, unsigned char c);
211 211 static void net_rawout(H3270 *session, unsigned const char *buf, int len);
212 212 static void check_in3270(H3270 *session);
213   -static void store3270in(unsigned char c);
214   -static void check_linemode(Boolean init);
  213 +static void store3270in(H3270 *hSession, unsigned char c);
  214 +static void check_linemode(H3270 *hSession, Boolean init);
215 215 static int non_blocking(H3270 *session, Boolean on);
216 216 static void net_connected(H3270 *session);
217 217 #if defined(X3270_TN3270E) /*[*/
... ... @@ -898,7 +898,7 @@ static void net_connected(H3270 *session)
898 898  
899 899 setup_lus();
900 900  
901   - check_linemode(True);
  901 + check_linemode(session,True);
902 902  
903 903 /* write out the passthru hostname and port nubmer */
904 904 if (session->passthru_host)
... ... @@ -1231,7 +1231,7 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1231 1231 }
1232 1232 #endif /*]*/
1233 1233 } else {
1234   - store3270in(c);
  1234 + store3270in(session,c);
1235 1235 }
1236 1236 break;
1237 1237 case TNS_IAC: /* process a telnet command */
... ... @@ -1254,37 +1254,36 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1254 1254 }
1255 1255 trace_dsn("%s",see_chr);
1256 1256 ansi_process((unsigned int) c);
1257   -// sms_store(c);
1258 1257 #endif /*]*/
1259 1258 } else
1260   - store3270in(c);
1261   - h3270.telnet_state = TNS_DATA;
  1259 + store3270in(session,c);
  1260 + session->telnet_state = TNS_DATA;
1262 1261 break;
1263 1262 case EOR: /* eor, process accumulated input */
1264   - if (IN_3270 || (IN_E && h3270.tn3270e_negotiated)) {
1265   - h3270.ns_rrcvd++;
  1263 + if (IN_3270 || (IN_E && session->tn3270e_negotiated)) {
  1264 + session->ns_rrcvd++;
1266 1265 if (process_eor())
1267 1266 return -1;
1268 1267 } else
1269   - Warning(NULL, _( "EOR received when not in 3270 mode, ignored." ));
  1268 + Warning(session, _( "EOR received when not in 3270 mode, ignored." ));
1270 1269 trace_dsn("RCVD EOR\n");
1271   - h3270.ibptr = h3270.ibuf;
1272   - h3270.telnet_state = TNS_DATA;
  1270 + session->ibptr = session->ibuf;
  1271 + session->telnet_state = TNS_DATA;
1273 1272 break;
1274 1273 case WILL:
1275   - h3270.telnet_state = TNS_WILL;
  1274 + session->telnet_state = TNS_WILL;
1276 1275 break;
1277 1276 case WONT:
1278   - h3270.telnet_state = TNS_WONT;
  1277 + session->telnet_state = TNS_WONT;
1279 1278 break;
1280 1279 case DO:
1281   - h3270.telnet_state = TNS_DO;
  1280 + session->telnet_state = TNS_DO;
1282 1281 break;
1283 1282 case DONT:
1284   - h3270.telnet_state = TNS_DONT;
  1283 + session->telnet_state = TNS_DONT;
1285 1284 break;
1286 1285 case SB:
1287   - h3270.telnet_state = TNS_SB;
  1286 + session->telnet_state = TNS_SB;
1288 1287 if (session->sbbuf == (unsigned char *)NULL)
1289 1288 session->sbbuf = (unsigned char *)lib3270_malloc(1024);
1290 1289 session->sbptr = session->sbbuf;
... ... @@ -1296,16 +1295,16 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1296 1295 session->syncing = 0;
1297 1296 x_except_on(session);
1298 1297 }
1299   - h3270.telnet_state = TNS_DATA;
  1298 + session->telnet_state = TNS_DATA;
1300 1299 break;
1301 1300 case GA:
1302 1301 case NOP:
1303 1302 trace_dsn("\n");
1304   - h3270.telnet_state = TNS_DATA;
  1303 + session->telnet_state = TNS_DATA;
1305 1304 break;
1306 1305 default:
1307 1306 trace_dsn("???\n");
1308   - h3270.telnet_state = TNS_DATA;
  1307 + session->telnet_state = TNS_DATA;
1309 1308 break;
1310 1309 }
1311 1310 break;
... ... @@ -1320,11 +1319,11 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1320 1319 #if defined(X3270_TN3270E) /*[*/
1321 1320 case TELOPT_TN3270E:
1322 1321 #endif /*]*/
1323   - if (c != TELOPT_TN3270E || !h3270.non_tn3270e_host) {
1324   - if (!h3270.hisopts[c]) {
1325   - h3270.hisopts[c] = 1;
  1322 + if (c != TELOPT_TN3270E || !session->non_tn3270e_host) {
  1323 + if (!session->hisopts[c]) {
  1324 + session->hisopts[c] = 1;
1326 1325 do_opt[2] = c;
1327   - net_rawout(&h3270,do_opt, sizeof(do_opt));
  1326 + net_rawout(session,do_opt, sizeof(do_opt));
1328 1327 trace_dsn("SENT %s %s\n",
1329 1328 cmd(DO), opt(c));
1330 1329  
... ... @@ -1332,27 +1331,25 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1332 1331 * For UTS, volunteer to do EOR when
1333 1332 * they do.
1334 1333 */
1335   - if (c == TELOPT_EOR && !h3270.myopts[c]) {
1336   - h3270.myopts[c] = 1;
  1334 + if (c == TELOPT_EOR && !session->myopts[c]) {
  1335 + session->myopts[c] = 1;
1337 1336 will_opt[2] = c;
1338   - net_rawout(&h3270,will_opt,
1339   - sizeof(will_opt));
1340   - trace_dsn("SENT %s %s\n",
1341   - cmd(WILL), opt(c));
  1337 + net_rawout(session,will_opt,sizeof(will_opt));
  1338 + trace_dsn("SENT %s %s\n",cmd(WILL), opt(c));
1342 1339 }
1343 1340  
1344   - check_in3270(&h3270);
1345   - check_linemode(False);
  1341 + check_in3270(session);
  1342 + check_linemode(session,False);
1346 1343 }
1347 1344 break;
1348 1345 }
1349 1346 default:
1350 1347 dont_opt[2] = c;
1351   - net_rawout(&h3270,dont_opt, sizeof(dont_opt));
  1348 + net_rawout(session,dont_opt, sizeof(dont_opt));
1352 1349 trace_dsn("SENT %s %s\n", cmd(DONT), opt(c));
1353 1350 break;
1354 1351 }
1355   - h3270.telnet_state = TNS_DATA;
  1352 + session->telnet_state = TNS_DATA;
1356 1353 break;
1357 1354 case TNS_WONT: /* telnet WONT DO OPTION command */
1358 1355 trace_dsn("%s\n", opt(c));
... ... @@ -1362,7 +1359,7 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1362 1359 net_rawout(&h3270, dont_opt, sizeof(dont_opt));
1363 1360 trace_dsn("SENT %s %s\n", cmd(DONT), opt(c));
1364 1361 check_in3270(&h3270);
1365   - check_linemode(False);
  1362 + check_linemode(&h3270,False);
1366 1363 }
1367 1364 h3270.telnet_state = TNS_DATA;
1368 1365 break;
... ... @@ -1393,7 +1390,7 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1393 1390 net_rawout(&h3270, will_opt, sizeof(will_opt));
1394 1391 trace_dsn("SENT %s %s\n", cmd(WILL), opt(c));
1395 1392 check_in3270(&h3270);
1396   - check_linemode(False);
  1393 + check_linemode(&h3270,False);
1397 1394 }
1398 1395 if (c == TELOPT_NAWS)
1399 1396 send_naws();
... ... @@ -1435,7 +1432,7 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1435 1432 net_rawout(&h3270, wont_opt, sizeof(wont_opt));
1436 1433 trace_dsn("SENT %s %s\n", cmd(WONT), opt(c));
1437 1434 check_in3270(&h3270);
1438   - check_linemode(False);
  1435 + check_linemode(&h3270,False);
1439 1436 }
1440 1437 h3270.telnet_state = TNS_DATA;
1441 1438 break;
... ... @@ -2507,16 +2504,15 @@ check_in3270(H3270 *session)
2507 2504 * Store a character in the 3270 input buffer, checking for buffer
2508 2505 * overflow and reallocating ibuf if necessary.
2509 2506 */
2510   -static void
2511   -store3270in(unsigned char c)
  2507 +static void store3270in(H3270 *hSession, unsigned char c)
2512 2508 {
2513   - if (h3270.ibptr - h3270.ibuf >= h3270.ibuf_size)
  2509 + if(hSession->ibptr - hSession->ibuf >= hSession->ibuf_size)
2514 2510 {
2515   - h3270.ibuf_size += BUFSIZ;
2516   - h3270.ibuf = (unsigned char *) lib3270_realloc((char *) h3270.ibuf, h3270.ibuf_size);
2517   - h3270.ibptr = h3270.ibuf + h3270.ibuf_size - BUFSIZ;
  2511 + hSession->ibuf_size += BUFSIZ;
  2512 + hSession->ibuf = (unsigned char *) lib3270_realloc((char *) hSession->ibuf, hSession->ibuf_size);
  2513 + hSession->ibptr = hSession->ibuf + hSession->ibuf_size - BUFSIZ;
2518 2514 }
2519   - *h3270.ibptr++ = c;
  2515 + *hSession->ibptr++ = c;
2520 2516 }
2521 2517  
2522 2518 /*
... ... @@ -2546,15 +2542,13 @@ void space3270out(int n)
2546 2542 }
2547 2543  
2548 2544  
2549   -/*
2550   - * check_linemode
2551   - * Set the global variable 'linemode', which says whether we are in
  2545 +/**
  2546 + * Set the session variable 'linemode', which says whether we are in
2552 2547 * character-by-character mode or line mode.
2553 2548 */
2554   -static void
2555   -check_linemode(Boolean init)
  2549 +static void check_linemode(H3270 *hSession, Boolean init)
2556 2550 {
2557   - int wasline = h3270.linemode;
  2551 + int wasline = hSession->linemode;
2558 2552  
2559 2553 /*
2560 2554 * The next line is a deliberate kluge to effectively ignore the SGA
... ... @@ -2570,17 +2564,17 @@ check_linemode(Boolean init)
2570 2564 * mode" properly by asking for both SGA and ECHO to be off or on, but
2571 2565 * we basically ignore the reply for SGA.
2572 2566 */
2573   - h3270.linemode = h3270.hisopts[TELOPT_ECHO] ? 0 : 1 /* && !hisopts[TELOPT_SGA] */;
  2567 + hSession->linemode = hSession->hisopts[TELOPT_ECHO] ? 0 : 1 /* && !hisopts[TELOPT_SGA] */;
2574 2568  
2575   - if (init || h3270.linemode != wasline)
  2569 + if (init || hSession->linemode != wasline)
2576 2570 {
2577   - st_changed(LIB3270_STATE_LINE_MODE, h3270.linemode);
  2571 + lib3270_st_changed(hSession,LIB3270_STATE_LINE_MODE, hSession->linemode);
2578 2572 if (!init)
2579 2573 {
2580   - trace_dsn("Operating in %s mode.\n",h3270.linemode ? "line" : "character-at-a-time");
  2574 + trace_dsn("Operating in %s mode.\n",hSession->linemode ? "line" : "character-at-a-time");
2581 2575 }
2582 2576 #if defined(X3270_ANSI) /*[*/
2583   - if (IN_ANSI && h3270.linemode)
  2577 + if (IN_ANSI && hSession->linemode)
2584 2578 cooked_init();
2585 2579 #endif /*]*/
2586 2580 }
... ...