Commit ed2e112bbc428ce751cd12fc9e1b4cb4e9247f3e

Authored by perry.werneck@gmail.com
1 parent b04b9f4b

Mais funções passam a suportar multi-sessão

src/lib3270/ansi.c
@@ -1021,15 +1021,15 @@ ansi_nop(H3270 *hSession, int ig1 unused, int ig2 unused) @@ -1021,15 +1021,15 @@ ansi_nop(H3270 *hSession, int ig1 unused, int ig2 unused)
1021 } 1021 }
1022 1022
1023 #define PWRAP { \ 1023 #define PWRAP { \
1024 - nc = h3270.cursor_addr + 1; \  
1025 - if (nc < h3270.scroll_bottom * h3270.cols) \  
1026 - cursor_move(&h3270,nc); \ 1024 + nc = hSession->cursor_addr + 1; \
  1025 + if (nc < hSession->scroll_bottom * hSession->cols) \
  1026 + cursor_move(hSession,nc); \
1027 else { \ 1027 else { \
1028 - if (h3270.cursor_addr / h3270.cols >= h3270.scroll_bottom) \  
1029 - cursor_move(&h3270,h3270.cursor_addr / h3270.cols * h3270.cols); \ 1028 + if (hSession->cursor_addr / hSession->cols >= hSession->scroll_bottom) \
  1029 + cursor_move(hSession,hSession->cursor_addr / hSession->cols * hSession->cols); \
1030 else { \ 1030 else { \
1031 - ansi_scroll(&h3270); \  
1032 - cursor_move(&h3270,nc - h3270.cols); \ 1031 + ansi_scroll(hSession); \
  1032 + cursor_move(hSession,nc - hSession->cols); \
1033 } \ 1033 } \
1034 } \ 1034 } \
1035 } 1035 }
src/lib3270/ctlr.c
@@ -463,78 +463,85 @@ void ctlr_erase(H3270 *session, int alt) @@ -463,78 +463,85 @@ void ctlr_erase(H3270 *session, int alt)
463 /* 463 /*
464 * Interpret an incoming 3270 command. 464 * Interpret an incoming 3270 command.
465 */ 465 */
466 -enum pds  
467 -process_ds(unsigned char *buf, int buflen) 466 +enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen)
468 { 467 {
469 enum pds rv; 468 enum pds rv;
470 469
471 if (!buflen) 470 if (!buflen)
472 return PDS_OKAY_NO_OUTPUT; 471 return PDS_OKAY_NO_OUTPUT;
473 472
474 -// scroll_to_bottom();  
475 -  
476 - trace_ds(&h3270,"< "); 473 + trace_ds(hSession,"< ");
477 474
478 - switch (buf[0]) { /* 3270 command */ 475 + switch (buf[0]) /* 3270 command */
  476 + {
479 case CMD_EAU: /* erase all unprotected */ 477 case CMD_EAU: /* erase all unprotected */
480 case SNA_CMD_EAU: 478 case SNA_CMD_EAU:
481 - trace_ds(&h3270,"EraseAllUnprotected\n");  
482 - ctlr_erase_all_unprotected(&h3270); 479 + trace_ds(hSession, "EraseAllUnprotected\n");
  480 + ctlr_erase_all_unprotected(hSession);
483 return PDS_OKAY_NO_OUTPUT; 481 return PDS_OKAY_NO_OUTPUT;
484 break; 482 break;
  483 +
485 case CMD_EWA: /* erase/write alternate */ 484 case CMD_EWA: /* erase/write alternate */
486 case SNA_CMD_EWA: 485 case SNA_CMD_EWA:
487 - trace_ds(&h3270,"EraseWriteAlternate"); 486 + trace_ds(hSession,"EraseWriteAlternate");
488 ctlr_erase(NULL,True); 487 ctlr_erase(NULL,True);
489 if ((rv = ctlr_write(buf, buflen, True)) < 0) 488 if ((rv = ctlr_write(buf, buflen, True)) < 0)
490 return rv; 489 return rv;
491 return PDS_OKAY_NO_OUTPUT; 490 return PDS_OKAY_NO_OUTPUT;
492 break; 491 break;
  492 +
493 case CMD_EW: /* erase/write */ 493 case CMD_EW: /* erase/write */
494 case SNA_CMD_EW: 494 case SNA_CMD_EW:
495 - trace_ds(&h3270,"EraseWrite"); 495 + trace_ds(hSession,"EraseWrite");
496 ctlr_erase(NULL,False); 496 ctlr_erase(NULL,False);
497 if ((rv = ctlr_write(buf, buflen, True)) < 0) 497 if ((rv = ctlr_write(buf, buflen, True)) < 0)
498 return rv; 498 return rv;
499 return PDS_OKAY_NO_OUTPUT; 499 return PDS_OKAY_NO_OUTPUT;
500 break; 500 break;
  501 +
501 case CMD_W: /* write */ 502 case CMD_W: /* write */
502 case SNA_CMD_W: 503 case SNA_CMD_W:
503 - trace_ds(&h3270,"Write"); 504 + trace_ds(hSession,"Write");
504 if ((rv = ctlr_write(buf, buflen, False)) < 0) 505 if ((rv = ctlr_write(buf, buflen, False)) < 0)
505 return rv; 506 return rv;
506 return PDS_OKAY_NO_OUTPUT; 507 return PDS_OKAY_NO_OUTPUT;
507 break; 508 break;
  509 +
508 case CMD_RB: /* read buffer */ 510 case CMD_RB: /* read buffer */
509 case SNA_CMD_RB: 511 case SNA_CMD_RB:
510 - trace_ds(&h3270,"ReadBuffer\n");  
511 - ctlr_read_buffer(&h3270,h3270.aid); 512 + trace_ds(hSession,"ReadBuffer\n");
  513 + ctlr_read_buffer(hSession,hSession->aid);
512 return PDS_OKAY_OUTPUT; 514 return PDS_OKAY_OUTPUT;
513 break; 515 break;
  516 +
514 case CMD_RM: /* read modifed */ 517 case CMD_RM: /* read modifed */
515 case SNA_CMD_RM: 518 case SNA_CMD_RM:
516 - trace_ds(&h3270,"ReadModified\n");  
517 - ctlr_read_modified(h3270.aid, False); 519 + trace_ds(hSession,"ReadModified\n");
  520 + ctlr_read_modified(hSession->aid, False);
518 return PDS_OKAY_OUTPUT; 521 return PDS_OKAY_OUTPUT;
519 break; 522 break;
  523 +
520 case CMD_RMA: /* read modifed all */ 524 case CMD_RMA: /* read modifed all */
521 case SNA_CMD_RMA: 525 case SNA_CMD_RMA:
522 - trace_ds(&h3270,"ReadModifiedAll\n");  
523 - ctlr_read_modified(h3270.aid, True); 526 + trace_ds(hSession,"ReadModifiedAll\n");
  527 + ctlr_read_modified(hSession->aid, True);
524 return PDS_OKAY_OUTPUT; 528 return PDS_OKAY_OUTPUT;
525 break; 529 break;
  530 +
526 case CMD_WSF: /* write structured field */ 531 case CMD_WSF: /* write structured field */
527 case SNA_CMD_WSF: 532 case SNA_CMD_WSF:
528 - trace_ds(&h3270,"WriteStructuredField"); 533 + trace_ds(hSession,"WriteStructuredField");
529 return write_structured_field(buf, buflen); 534 return write_structured_field(buf, buflen);
530 break; 535 break;
  536 +
531 case CMD_NOP: /* no-op */ 537 case CMD_NOP: /* no-op */
532 - trace_ds(&h3270,"NoOp\n"); 538 + trace_ds(hSession,"NoOp\n");
533 return PDS_OKAY_NO_OUTPUT; 539 return PDS_OKAY_NO_OUTPUT;
534 break; 540 break;
  541 +
535 default: 542 default:
536 /* unknown 3270 command */ 543 /* unknown 3270 command */
537 - popup_an_error(&h3270,_( "Unknown 3270 Data Stream command: 0x%X" ),buf[0]); 544 + popup_an_error(hSession,_( "Unknown 3270 Data Stream command: 0x%X" ),buf[0]);
538 return PDS_BAD_CMD; 545 return PDS_BAD_CMD;
539 } 546 }
540 } 547 }
src/lib3270/ctlrc.h
@@ -69,7 +69,7 @@ LIB3270_INTERNAL void ctlr_write_sscp_lu(H3270 *session, unsigned char buf[], in @@ -69,7 +69,7 @@ LIB3270_INTERNAL void ctlr_write_sscp_lu(H3270 *session, unsigned char buf[], in
69 LIB3270_INTERNAL void mdt_clear(int baddr); 69 LIB3270_INTERNAL void mdt_clear(int baddr);
70 LIB3270_INTERNAL void mdt_set(int baddr); 70 LIB3270_INTERNAL void mdt_set(int baddr);
71 LIB3270_INTERNAL int next_unprotected(H3270 *session, int baddr0); 71 LIB3270_INTERNAL int next_unprotected(H3270 *session, int baddr0);
72 -LIB3270_INTERNAL enum pds process_ds(unsigned char *buf, int buflen); 72 +LIB3270_INTERNAL enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen);
73 LIB3270_INTERNAL void ps_process(void); 73 LIB3270_INTERNAL void ps_process(void);
74 74
75 LIB3270_INTERNAL void update_model_info(H3270 *session, int model, int cols, int rows); 75 LIB3270_INTERNAL void update_model_info(H3270 *session, int model, int cols, int rows);
src/lib3270/kybd.c
@@ -594,7 +594,7 @@ LIB3270_ACTION(break) @@ -594,7 +594,7 @@ LIB3270_ACTION(break)
594 if (!IN_3270) 594 if (!IN_3270)
595 return 0; 595 return 0;
596 596
597 - net_break(); 597 + net_break(hSession);
598 598
599 return 0; 599 return 0;
600 } 600 }
@@ -607,7 +607,7 @@ LIB3270_ACTION(attn) @@ -607,7 +607,7 @@ LIB3270_ACTION(attn)
607 if (!IN_3270) 607 if (!IN_3270)
608 return 0; 608 return 0;
609 609
610 - net_interrupt(); 610 + net_interrupt(hSession);
611 611
612 return 0; 612 return 0;
613 } 613 }
@@ -1886,7 +1886,7 @@ LIB3270_ACTION( sysreq ) @@ -1886,7 +1886,7 @@ LIB3270_ACTION( sysreq )
1886 return 0; 1886 return 0;
1887 #if defined(X3270_TN3270E) /*[*/ 1887 #if defined(X3270_TN3270E) /*[*/
1888 if (IN_E) { 1888 if (IN_E) {
1889 - net_abort(); 1889 + net_abort(hSession);
1890 } else 1890 } else
1891 #endif /*]*/ 1891 #endif /*]*/
1892 { 1892 {
src/lib3270/screen.c
@@ -166,7 +166,7 @@ static unsigned short calc_attrs(H3270 *session, int baddr, int fa_addr, int fa) @@ -166,7 +166,7 @@ static unsigned short calc_attrs(H3270 *session, int baddr, int fa_addr, int fa)
166 /* Compute the color. */ 166 /* Compute the color. */
167 167
168 /* Monochrome is easy, and so is color if nothing is specified. */ 168 /* Monochrome is easy, and so is color if nothing is specified. */
169 - if (!h3270.m3279 || 169 + if (!session->m3279 ||
170 (!session->ea_buf[baddr].fg && 170 (!session->ea_buf[baddr].fg &&
171 !session->ea_buf[fa_addr].fg && 171 !session->ea_buf[fa_addr].fg &&
172 !session->ea_buf[baddr].bg && 172 !session->ea_buf[baddr].bg &&
src/lib3270/telnet.c
@@ -1952,8 +1952,7 @@ process_eor(H3270 *hSession) @@ -1952,8 +1952,7 @@ process_eor(H3270 *hSession)
1952 hSession->tn3270e_submode = E_3270; 1952 hSession->tn3270e_submode = E_3270;
1953 check_in3270(hSession); 1953 check_in3270(hSession);
1954 hSession->response_required = h->response_flag; 1954 hSession->response_required = h->response_flag;
1955 - rv = process_ds(hSession->ibuf + EH_SIZE,  
1956 - (hSession->ibptr - hSession->ibuf) - EH_SIZE); 1955 + rv = process_ds(hSession, hSession->ibuf + EH_SIZE,(hSession->ibptr - hSession->ibuf) - EH_SIZE);
1957 if (rv < 0 && 1956 if (rv < 0 &&
1958 hSession->response_required != TN3270E_RSF_NO_RESPONSE) 1957 hSession->response_required != TN3270E_RSF_NO_RESPONSE)
1959 tn3270e_nak(hSession,rv); 1958 tn3270e_nak(hSession,rv);
@@ -2000,7 +1999,7 @@ process_eor(H3270 *hSession) @@ -2000,7 +1999,7 @@ process_eor(H3270 *hSession)
2000 } else 1999 } else
2001 #endif /*]*/ 2000 #endif /*]*/
2002 { 2001 {
2003 - (void) process_ds(hSession->ibuf, hSession->ibptr - hSession->ibuf); 2002 + (void) process_ds(hSession, hSession->ibuf, hSession->ibptr - hSession->ibuf);
2004 } 2003 }
2005 return 0; 2004 return 0;
2006 } 2005 }
@@ -2270,7 +2269,7 @@ static void do_intr(H3270 *hSession, char c) @@ -2270,7 +2269,7 @@ static void do_intr(H3270 *hSession, char c)
2270 } 2269 }
2271 ansi_process_s(ctl_see((int) c)); 2270 ansi_process_s(ctl_see((int) c));
2272 cooked_init(hSession); 2271 cooked_init(hSession);
2273 - net_interrupt(); 2272 + net_interrupt(hSession);
2274 } 2273 }
2275 2274
2276 static void do_quit(H3270 *hSession, char c) 2275 static void do_quit(H3270 *hSession, char c)
@@ -2282,7 +2281,7 @@ static void do_quit(H3270 *hSession, char c) @@ -2282,7 +2281,7 @@ static void do_quit(H3270 *hSession, char c)
2282 } 2281 }
2283 ansi_process_s(ctl_see((int) c)); 2282 ansi_process_s(ctl_see((int) c));
2284 cooked_init(hSession); 2283 cooked_init(hSession);
2285 - net_break(); 2284 + net_break(hSession);
2286 } 2285 }
2287 2286
2288 static void do_cerase(H3270 *hSession, char c) 2287 static void do_cerase(H3270 *hSession, char c)
@@ -2688,8 +2687,8 @@ void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, in @@ -2688,8 +2687,8 @@ void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, in
2688 (void) gettimeofday(&ts, (struct timezone *)NULL); 2687 (void) gettimeofday(&ts, (struct timezone *)NULL);
2689 if (IN_3270) 2688 if (IN_3270)
2690 { 2689 {
2691 - tdiff = ((1.0e6 * (double)(ts.tv_sec - h3270.ds_ts.tv_sec)) +  
2692 - (double)(ts.tv_usec - h3270.ds_ts.tv_usec)) / 1.0e6; 2690 + tdiff = ((1.0e6 * (double)(ts.tv_sec - hSession->ds_ts.tv_sec)) +
  2691 + (double)(ts.tv_usec - hSession->ds_ts.tv_usec)) / 1.0e6;
2693 trace_dsn(hSession,"%c +%gs\n", direction, tdiff); 2692 trace_dsn(hSession,"%c +%gs\n", direction, tdiff);
2694 } 2693 }
2695 2694
@@ -2990,20 +2989,23 @@ net_linemode(void) @@ -2990,20 +2989,23 @@ net_linemode(void)
2990 } 2989 }
2991 */ 2990 */
2992 2991
2993 -void  
2994 -net_charmode(void) 2992 +void net_charmode(H3270 *hSession)
2995 { 2993 {
2996 if (!CONNECTED) 2994 if (!CONNECTED)
2997 return; 2995 return;
2998 - if (!hisopts[TELOPT_ECHO]) { 2996 +
  2997 + if (!hisopts[TELOPT_ECHO])
  2998 + {
2999 do_opt[2] = TELOPT_ECHO; 2999 do_opt[2] = TELOPT_ECHO;
3000 net_rawout(do_opt, sizeof(do_opt)); 3000 net_rawout(do_opt, sizeof(do_opt));
3001 - trace_dsn(&h3270,"SENT %s %s\n", cmd(DO), opt(TELOPT_ECHO)); 3001 + trace_dsn(hSession,"SENT %s %s\n", cmd(DO), opt(TELOPT_ECHO));
3002 } 3002 }
3003 - if (!hisopts[TELOPT_SGA]) { 3003 +
  3004 + if (!hisopts[TELOPT_SGA])
  3005 + {
3004 do_opt[2] = TELOPT_SGA; 3006 do_opt[2] = TELOPT_SGA;
3005 net_rawout(do_opt, sizeof(do_opt)); 3007 net_rawout(do_opt, sizeof(do_opt));
3006 - trace_dsn(&h3270,"SENT %s %s\n", cmd(DO), opt(TELOPT_SGA)); 3008 + trace_dsn(hSession,"SENT %s %s\n", cmd(DO), opt(TELOPT_SGA));
3007 } 3009 }
3008 } 3010 }
3009 #endif /*]*/ 3011 #endif /*]*/
@@ -3014,14 +3016,13 @@ net_charmode(void) @@ -3014,14 +3016,13 @@ net_charmode(void)
3014 * Send telnet break, which is used to implement 3270 ATTN. 3016 * Send telnet break, which is used to implement 3270 ATTN.
3015 * 3017 *
3016 */ 3018 */
3017 -void  
3018 -net_break(void) 3019 +void net_break(H3270 *hSession)
3019 { 3020 {
3020 - static unsigned char buf[] = { IAC, BREAK }; 3021 + static const unsigned char buf[] = { IAC, BREAK };
3021 3022
3022 /* I don't know if we should first send TELNET synch ? */ 3023 /* I don't know if we should first send TELNET synch ? */
3023 - net_rawout(&h3270, buf, sizeof(buf));  
3024 - trace_dsn(&h3270,"SENT BREAK\n"); 3024 + net_rawout(hSession, buf, sizeof(buf));
  3025 + trace_dsn(hSession,"SENT BREAK\n");
3025 } 3026 }
3026 3027
3027 /* 3028 /*
@@ -3029,14 +3030,13 @@ net_break(void) @@ -3029,14 +3030,13 @@ net_break(void)
3029 * Send telnet IP. 3030 * Send telnet IP.
3030 * 3031 *
3031 */ 3032 */
3032 -void  
3033 -net_interrupt(void) 3033 +void net_interrupt(H3270 *hSession)
3034 { 3034 {
3035 - static unsigned char buf[] = { IAC, IP }; 3035 + static const unsigned char buf[] = { IAC, IP };
3036 3036
3037 /* I don't know if we should first send TELNET synch ? */ 3037 /* I don't know if we should first send TELNET synch ? */
3038 - net_rawout(&h3270, buf, sizeof(buf));  
3039 - trace_dsn(&h3270,"SENT IP\n"); 3038 + net_rawout(hSession, buf, sizeof(buf));
  3039 + trace_dsn(hSession,"SENT IP\n");
3040 } 3040 }
3041 3041
3042 /* 3042 /*
@@ -3045,36 +3045,39 @@ net_interrupt(void) @@ -3045,36 +3045,39 @@ net_interrupt(void)
3045 * 3045 *
3046 */ 3046 */
3047 #if defined(X3270_TN3270E) /*[*/ 3047 #if defined(X3270_TN3270E) /*[*/
3048 -void  
3049 -net_abort(void) 3048 +void net_abort(H3270 *hSession)
3050 { 3049 {
3051 - static unsigned char buf[] = { IAC, AO }; 3050 + static const unsigned char buf[] = { IAC, AO };
3052 3051
3053 - if (h3270.e_funcs & E_OPT(TN3270E_FUNC_SYSREQ)) { 3052 + if (hSession->e_funcs & E_OPT(TN3270E_FUNC_SYSREQ))
  3053 + {
3054 /* 3054 /*
3055 * I'm not sure yet what to do here. Should the host respond 3055 * I'm not sure yet what to do here. Should the host respond
3056 * to the AO by sending us SSCP-LU data (and putting us into 3056 * to the AO by sending us SSCP-LU data (and putting us into
3057 * SSCP-LU mode), or should we put ourselves in it? 3057 * SSCP-LU mode), or should we put ourselves in it?
3058 * Time, and testers, will tell. 3058 * Time, and testers, will tell.
3059 */ 3059 */
3060 - switch (h3270.tn3270e_submode) { 3060 + switch (hSession->tn3270e_submode)
  3061 + {
3061 case E_NONE: 3062 case E_NONE:
3062 case E_NVT: 3063 case E_NVT:
3063 break; 3064 break;
  3065 +
3064 case E_SSCP: 3066 case E_SSCP:
3065 - net_rawout(&h3270, buf, sizeof(buf));  
3066 - trace_dsn(&h3270,"SENT AO\n");  
3067 - if (h3270.tn3270e_bound ||  
3068 - !(h3270.e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE))) {  
3069 - h3270.tn3270e_submode = E_3270;  
3070 - check_in3270(&h3270); 3067 + net_rawout(hSession, buf, sizeof(buf));
  3068 + trace_dsn(hSession,"SENT AO\n");
  3069 + if (hSession->tn3270e_bound || !(hSession->e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE)))
  3070 + {
  3071 + hSession->tn3270e_submode = E_3270;
  3072 + check_in3270(hSession);
3071 } 3073 }
3072 break; 3074 break;
  3075 +
3073 case E_3270: 3076 case E_3270:
3074 - net_rawout(&h3270, buf, sizeof(buf));  
3075 - trace_dsn(&h3270,"SENT AO\n");  
3076 - h3270.tn3270e_submode = E_SSCP;  
3077 - check_in3270(&h3270); 3077 + net_rawout(hSession, buf, sizeof(buf));
  3078 + trace_dsn(hSession,"SENT AO\n");
  3079 + hSession->tn3270e_submode = E_SSCP;
  3080 + check_in3270(hSession);
3078 break; 3081 break;
3079 } 3082 }
3080 } 3083 }
src/lib3270/telnetc.h
@@ -29,17 +29,17 @@ struct ctl_char { @@ -29,17 +29,17 @@ struct ctl_char {
29 char value[3]; 29 char value[3];
30 }; 30 };
31 31
32 -LIB3270_INTERNAL void net_abort(void); 32 +LIB3270_INTERNAL void net_abort(H3270 *hSession);
33 LIB3270_INTERNAL Boolean net_add_dummy_tn3270e(void); 33 LIB3270_INTERNAL Boolean net_add_dummy_tn3270e(void);
34 LIB3270_INTERNAL void net_add_eor(unsigned char *buf, int len); 34 LIB3270_INTERNAL void net_add_eor(unsigned char *buf, int len);
35 -LIB3270_INTERNAL void net_break(void);  
36 -LIB3270_INTERNAL void net_charmode(void); 35 +LIB3270_INTERNAL void net_break(H3270 *hSession);
  36 +LIB3270_INTERNAL void net_charmode(H3270 *hSession);
37 LIB3270_INTERNAL int net_connect(H3270 *session, const char *, char *, Boolean, Boolean *, Boolean *); 37 LIB3270_INTERNAL int net_connect(H3270 *session, const char *, char *, Boolean, Boolean *, Boolean *);
38 LIB3270_INTERNAL void net_disconnect(H3270 *session); 38 LIB3270_INTERNAL void net_disconnect(H3270 *session);
39 LIB3270_INTERNAL void net_exception(H3270 *session); 39 LIB3270_INTERNAL void net_exception(H3270 *session);
40 // LIB3270_INTERNAL void net_hexansi_out(unsigned char *buf, int len); 40 // LIB3270_INTERNAL void net_hexansi_out(unsigned char *buf, int len);
41 LIB3270_INTERNAL void net_input(H3270 *session); 41 LIB3270_INTERNAL void net_input(H3270 *session);
42 -LIB3270_INTERNAL void net_interrupt(void); 42 +LIB3270_INTERNAL void net_interrupt(H3270 *hSession);
43 // LIB3270_INTERNAL void net_linemode(void); 43 // LIB3270_INTERNAL void net_linemode(void);
44 // LIB3270_INTERNAL struct ctl_char *net_linemode_chars(void); 44 // LIB3270_INTERNAL struct ctl_char *net_linemode_chars(void);
45 LIB3270_INTERNAL void net_output(H3270 *hSession); 45 LIB3270_INTERNAL void net_output(H3270 *hSession);