Commit d1509eb6d15bd8e166c67f4382b56001232b89f3

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

Movendo mais campos para a estrutura de sessão, acertando dependências no Makefile

Showing 3 changed files with 42 additions and 35 deletions   Show diff stats
@@ -37,7 +37,7 @@ LDFLAGS=@LDFLAGS@ @@ -37,7 +37,7 @@ LDFLAGS=@LDFLAGS@
37 LIBS=@LIBS@ @LIBSSL_LIBS@ @INTL_LIBS@ @SOCKET_LIBS@ 37 LIBS=@LIBS@ @LIBSSL_LIBS@ @INTL_LIBS@ @SOCKET_LIBS@
38 38
39 DEBUG_CFLAGS=-DDEBUG=1 -g 39 DEBUG_CFLAGS=-DDEBUG=1 -g
40 -DEPENDS ?= *.h ../include/*.h Makefile 40 +DEPENDS ?= *.h ../include/*.h ../include/lib3270/*.h Makefile
41 41
42 #---[ Paths ]------------------------------------------------------------------ 42 #---[ Paths ]------------------------------------------------------------------
43 43
@@ -68,15 +68,17 @@ void lib3270_session_free(H3270 *h) @@ -68,15 +68,17 @@ void lib3270_session_free(H3270 *h)
68 } 68 }
69 69
70 // Release memory 70 // Release memory
71 - lib3270_free(h->charset);  
72 - lib3270_free(h->paste_buffer);  
73 - h->charset = NULL;  
74 - h->paste_buffer = NULL; 71 + #define release_pointer(x) lib3270_free(x); x = NULL;
  72 +
  73 + release_pointer(h->charset);
  74 + release_pointer(h->paste_buffer);
  75 +
  76 + release_pointer(h->ibuf);
  77 + h->ibuf_size = 0;
75 78
76 for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++) 79 for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++)
77 { 80 {
78 - lib3270_free(h->buffer[f]);  
79 - h->buffer[f] = NULL; 81 + release_pointer(h->buffer[f]);
80 } 82 }
81 83
82 } 84 }
@@ -149,20 +149,23 @@ extern struct timeval ds_ts; @@ -149,20 +149,23 @@ extern struct timeval ds_ts;
149 //#endif /*]*/ 149 //#endif /*]*/
150 150
151 static unsigned char myopts[N_OPTS], hisopts[N_OPTS]; 151 static unsigned char myopts[N_OPTS], hisopts[N_OPTS];
152 - /* telnet option flags */  
153 -static unsigned char *ibuf = (unsigned char *) NULL;  
154 - /* 3270 input buffer */ 152 +
  153 +/* telnet option flags */
  154 +// static unsigned char *ibuf = (unsigned char *) NULL;
  155 +// static int ibuf_size = 0; /* size of ibuf */
  156 +
  157 +/* 3270 input buffer */
155 static unsigned char *ibptr; 158 static unsigned char *ibptr;
156 -static int ibuf_size = 0; /* size of ibuf */  
157 static unsigned char *obuf_base = (unsigned char *)NULL; 159 static unsigned char *obuf_base = (unsigned char *)NULL;
158 static int obuf_size = 0; 160 static int obuf_size = 0;
159 static unsigned char *netrbuf = (unsigned char *)NULL; 161 static unsigned char *netrbuf = (unsigned char *)NULL;
160 - /* network input buffer */ 162 +
  163 +/* network input buffer */
161 static unsigned char *sbbuf = (unsigned char *)NULL; 164 static unsigned char *sbbuf = (unsigned char *)NULL;
162 - /* telnet sub-option buffer */ 165 +
  166 +/* telnet sub-option buffer */
163 static unsigned char *sbptr; 167 static unsigned char *sbptr;
164 static unsigned char telnet_state; 168 static unsigned char telnet_state;
165 -// static int syncing;  
166 static char ttype_tmpval[13]; 169 static char ttype_tmpval[13];
167 170
168 #if defined(X3270_TN3270E) /*[*/ 171 #if defined(X3270_TN3270E) /*[*/
@@ -868,7 +871,7 @@ static void net_connected(H3270 *session) @@ -868,7 +871,7 @@ static void net_connected(H3270 *session)
868 need_tls_follows = False; 871 need_tls_follows = False;
869 #endif /*]*/ 872 #endif /*]*/
870 telnet_state = TNS_DATA; 873 telnet_state = TNS_DATA;
871 - ibptr = ibuf; 874 + ibptr = h3270.ibuf;
872 875
873 /* clear statistics and flags */ 876 /* clear statistics and flags */
874 (void) time(&ns_time); 877 (void) time(&ns_time);
@@ -1253,7 +1256,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) @@ -1253,7 +1256,7 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1253 } else 1256 } else
1254 Warning(NULL, _( "EOR received when not in 3270 mode, ignored." )); 1257 Warning(NULL, _( "EOR received when not in 3270 mode, ignored." ));
1255 trace_dsn("RCVD EOR\n"); 1258 trace_dsn("RCVD EOR\n");
1256 - ibptr = ibuf; 1259 + ibptr = h3270.ibuf;
1257 telnet_state = TNS_DATA; 1260 telnet_state = TNS_DATA;
1258 break; 1261 break;
1259 case WILL: 1262 case WILL:
@@ -1860,12 +1863,12 @@ process_bind(unsigned char *buf, int buflen) @@ -1860,12 +1863,12 @@ process_bind(unsigned char *buf, int buflen)
1860 static int 1863 static int
1861 process_eor(void) 1864 process_eor(void)
1862 { 1865 {
1863 - if (h3270.syncing || !(ibptr - ibuf)) 1866 + if (h3270.syncing || !(ibptr - h3270.ibuf))
1864 return(0); 1867 return(0);
1865 1868
1866 #if defined(X3270_TN3270E) /*[*/ 1869 #if defined(X3270_TN3270E) /*[*/
1867 if (IN_E) { 1870 if (IN_E) {
1868 - tn3270e_header *h = (tn3270e_header *)ibuf; 1871 + tn3270e_header *h = (tn3270e_header *) h3270.ibuf;
1869 unsigned char *s; 1872 unsigned char *s;
1870 enum pds rv; 1873 enum pds rv;
1871 1874
@@ -1883,8 +1886,8 @@ process_eor(void) @@ -1883,8 +1886,8 @@ process_eor(void)
1883 tn3270e_submode = E_3270; 1886 tn3270e_submode = E_3270;
1884 check_in3270(&h3270); 1887 check_in3270(&h3270);
1885 response_required = h->response_flag; 1888 response_required = h->response_flag;
1886 - rv = process_ds(ibuf + EH_SIZE,  
1887 - (ibptr - ibuf) - EH_SIZE); 1889 + rv = process_ds(h3270.ibuf + EH_SIZE,
  1890 + (ibptr - h3270.ibuf) - EH_SIZE);
1888 if (rv < 0 && 1891 if (rv < 0 &&
1889 response_required != TN3270E_RSF_NO_RESPONSE) 1892 response_required != TN3270E_RSF_NO_RESPONSE)
1890 tn3270e_nak(rv); 1893 tn3270e_nak(rv);
@@ -1896,7 +1899,7 @@ process_eor(void) @@ -1896,7 +1899,7 @@ process_eor(void)
1896 case TN3270E_DT_BIND_IMAGE: 1899 case TN3270E_DT_BIND_IMAGE:
1897 if (!(e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE))) 1900 if (!(e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE)))
1898 return 0; 1901 return 0;
1899 - process_bind(ibuf + EH_SIZE, (ibptr - ibuf) - EH_SIZE); 1902 + process_bind(h3270.ibuf + EH_SIZE, (ibptr - h3270.ibuf) - EH_SIZE);
1900 trace_dsn("< BIND PLU-name '%s'\n", plu_name); 1903 trace_dsn("< BIND PLU-name '%s'\n", plu_name);
1901 tn3270e_bound = 1; 1904 tn3270e_bound = 1;
1902 check_in3270(&h3270); 1905 check_in3270(&h3270);
@@ -1913,7 +1916,7 @@ process_eor(void) @@ -1913,7 +1916,7 @@ process_eor(void)
1913 /* In tn3270e NVT mode */ 1916 /* In tn3270e NVT mode */
1914 tn3270e_submode = E_NVT; 1917 tn3270e_submode = E_NVT;
1915 check_in3270(&h3270); 1918 check_in3270(&h3270);
1916 - for (s = ibuf; s < ibptr; s++) { 1919 + for (s = h3270.ibuf; s < ibptr; s++) {
1917 ansi_process(*s++); 1920 ansi_process(*s++);
1918 } 1921 }
1919 return 0; 1922 return 0;
@@ -1922,8 +1925,8 @@ process_eor(void) @@ -1922,8 +1925,8 @@ process_eor(void)
1922 return 0; 1925 return 0;
1923 tn3270e_submode = E_SSCP; 1926 tn3270e_submode = E_SSCP;
1924 check_in3270(&h3270); 1927 check_in3270(&h3270);
1925 - ctlr_write_sscp_lu(ibuf + EH_SIZE,  
1926 - (ibptr - ibuf) - EH_SIZE); 1928 + ctlr_write_sscp_lu(h3270.ibuf + EH_SIZE,
  1929 + (ibptr - h3270.ibuf) - EH_SIZE);
1927 return 0; 1930 return 0;
1928 default: 1931 default:
1929 /* Should do something more extraordinary here. */ 1932 /* Should do something more extraordinary here. */
@@ -1932,7 +1935,7 @@ process_eor(void) @@ -1932,7 +1935,7 @@ process_eor(void)
1932 } else 1935 } else
1933 #endif /*]*/ 1936 #endif /*]*/
1934 { 1937 {
1935 - (void) process_ds(ibuf, ibptr - ibuf); 1938 + (void) process_ds(h3270.ibuf, ibptr - h3270.ibuf);
1936 } 1939 }
1937 return 0; 1940 return 0;
1938 } 1941 }
@@ -2464,10 +2467,11 @@ check_in3270(H3270 *session) @@ -2464,10 +2467,11 @@ check_in3270(H3270 *session)
2464 #endif /*]*/ 2467 #endif /*]*/
2465 2468
2466 /* Allocate the initial 3270 input buffer. */ 2469 /* Allocate the initial 3270 input buffer. */
2467 - if (new_cstate >= CONNECTED_INITIAL && !ibuf_size) {  
2468 - ibuf = (unsigned char *)lib3270_malloc(BUFSIZ);  
2469 - ibuf_size = BUFSIZ;  
2470 - ibptr = ibuf; 2470 + if(new_cstate >= CONNECTED_INITIAL && !(h3270.ibuf_size && h3270.ibuf))
  2471 + {
  2472 + h3270.ibuf = (unsigned char *) lib3270_malloc(BUFSIZ);
  2473 + h3270.ibuf_size = BUFSIZ;
  2474 + ibptr = h3270.ibuf;
2471 } 2475 }
2472 2476
2473 #if defined(X3270_ANSI) /*[*/ 2477 #if defined(X3270_ANSI) /*[*/
@@ -2498,10 +2502,11 @@ check_in3270(H3270 *session) @@ -2498,10 +2502,11 @@ check_in3270(H3270 *session)
2498 static void 2502 static void
2499 store3270in(unsigned char c) 2503 store3270in(unsigned char c)
2500 { 2504 {
2501 - if (ibptr - ibuf >= ibuf_size) {  
2502 - ibuf_size += BUFSIZ;  
2503 - ibuf = (unsigned char *)Realloc((char *)ibuf, ibuf_size);  
2504 - ibptr = ibuf + ibuf_size - BUFSIZ; 2505 + if (ibptr - h3270.ibuf >= h3270.ibuf_size)
  2506 + {
  2507 + h3270.ibuf_size += BUFSIZ;
  2508 + h3270.ibuf = (unsigned char *) lib3270_realloc((char *) h3270.ibuf, h3270.ibuf_size);
  2509 + ibptr = h3270.ibuf + h3270.ibuf_size - BUFSIZ;
2505 } 2510 }
2506 *ibptr++ = c; 2511 *ibptr++ = c;
2507 } 2512 }
@@ -2733,7 +2738,7 @@ static void @@ -2733,7 +2738,7 @@ static void
2733 tn3270e_ack(void) 2738 tn3270e_ack(void)
2734 { 2739 {
2735 unsigned char rsp_buf[10]; 2740 unsigned char rsp_buf[10];
2736 - tn3270e_header *h_in = (tn3270e_header *)ibuf; 2741 + tn3270e_header *h_in = (tn3270e_header *) h3270.ibuf;
2737 int rsp_len = 0; 2742 int rsp_len = 0;
2738 2743
2739 rsp_len = 0; 2744 rsp_len = 0;
@@ -2760,7 +2765,7 @@ static void @@ -2760,7 +2765,7 @@ static void
2760 tn3270e_nak(enum pds rv) 2765 tn3270e_nak(enum pds rv)
2761 { 2766 {
2762 unsigned char rsp_buf[10]; 2767 unsigned char rsp_buf[10];
2763 - tn3270e_header *h_in = (tn3270e_header *)ibuf; 2768 + tn3270e_header *h_in = (tn3270e_header *) h3270.ibuf;
2764 int rsp_len = 0; 2769 int rsp_len = 0;
2765 char *neg = NULL; 2770 char *neg = NULL;
2766 2771