Commit 7c41e1dc65c31e5e644649390dc747432a0882d9

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

Movendo campos para a estrutura de sessao

src/include/lib3270.h
@@ -35,6 +35,14 @@ @@ -35,6 +35,14 @@
35 #include <stdarg.h> 35 #include <stdarg.h>
36 36
37 /** 37 /**
  38 + * BIND definitions.
  39 + */
  40 + #define LIB3270_BIND_RU 0x31
  41 + #define LIB3270_BIND_OFF_PLU_NAME_LEN 26
  42 + #define LIB3270_BIND_OFF_PLU_NAME 27
  43 + #define LIB3270_BIND_PLU_NAME_MAX 8
  44 +
  45 + /**
38 * Character attributes 46 * Character attributes
39 */ 47 */
40 typedef enum _lib3270_attr 48 typedef enum _lib3270_attr
src/include/lib3270/session.h
@@ -199,6 +199,14 @@ @@ -199,6 +199,14 @@
199 int ansi_data; 199 int ansi_data;
200 int lnext; 200 int lnext;
201 int backslashed; 201 int backslashed;
  202 + char plu_name[LIB3270_BIND_PLU_NAME_MAX+1];
  203 + char **lus;
  204 + char **curr_lu;
  205 + char * try_lu;
  206 + int proxy_type;
  207 + char * proxy_host;
  208 + char * proxy_portname;
  209 + unsigned short proxy_port;
202 210
203 enum 211 enum
204 { 212 {
src/lib3270/3270ds.h
@@ -327,7 +327,7 @@ @@ -327,7 +327,7 @@
327 #define EBC_eo 0xff 327 #define EBC_eo 0xff
328 328
329 /* BIND definitions. */ 329 /* BIND definitions. */
330 -#define BIND_RU 0x31  
331 -#define BIND_OFF_PLU_NAME_LEN 26  
332 -#define BIND_OFF_PLU_NAME 27  
333 -#define BIND_PLU_NAME_MAX 8 330 +#define BIND_RU LIB3270_BIND_RU
  331 +#define BIND_OFF_PLU_NAME_LEN LIB3270_BIND_OFF_PLU_NAME_LEN
  332 +#define BIND_OFF_PLU_NAME LIB3270_BIND_OFF_PLU_NAME
  333 +#define BIND_PLU_NAME_MAX LIB3270_BIND_PLU_NAME_MAX
src/lib3270/telnet.c
@@ -197,15 +197,15 @@ static char vlnext; @@ -197,15 +197,15 @@ static char vlnext;
197 // static int tn3270e_negotiated = 0; 197 // static int tn3270e_negotiated = 0;
198 //static enum { E_NONE, E_3270, E_NVT, E_SSCP } tn3270e_submode = E_NONE; 198 //static enum { E_NONE, E_3270, E_NVT, E_SSCP } tn3270e_submode = E_NONE;
199 // static int tn3270e_bound = 0; 199 // static int tn3270e_bound = 0;
200 -static char plu_name[BIND_PLU_NAME_MAX+1];  
201 -static char **lus = (char **)NULL;  
202 -static char **curr_lu = (char **)NULL;  
203 -static char *try_lu = CN; 200 +// static char plu_name[BIND_PLU_NAME_MAX+1];
  201 +// static char **lus = (char **)NULL;
  202 +// static char **curr_lu = (char **)NULL;
  203 +//static char *try_lu = CN;
204 204
205 -static int proxy_type = 0;  
206 -static char *proxy_host = CN;  
207 -static char *proxy_portname = CN;  
208 -static unsigned short proxy_port = 0; 205 +// static int proxy_type = 0;
  206 +// static char *proxy_host = CN;
  207 +//static char *proxy_portname = CN;
  208 +// static unsigned short proxy_port = 0;
209 209
210 static int telnet_fsm(H3270 *session, unsigned char c); 210 static int telnet_fsm(H3270 *session, unsigned char c);
211 static void net_rawout(H3270 *session, unsigned const char *buf, int len); 211 static void net_rawout(H3270 *session, unsigned const char *buf, int len);
@@ -587,11 +587,11 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -587,11 +587,11 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
587 587
588 #endif // HAVE_GETADDRINFO 588 #endif // HAVE_GETADDRINFO
589 } 589 }
590 - else if(session->proxy != CN && !proxy_type) 590 + else if(session->proxy != CN && !session->proxy_type)
591 { 591 {
592 - proxy_type = proxy_setup(session, &proxy_host, &proxy_portname); 592 + session->proxy_type = proxy_setup(session, &session->proxy_host, &session->proxy_portname);
593 593
594 - if (proxy_type > 0) 594 + if (session->proxy_type > 0)
595 { 595 {
596 unsigned long lport; 596 unsigned long lport;
597 char *ptr; 597 char *ptr;
@@ -613,7 +613,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -613,7 +613,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
613 } 613 }
614 } 614 }
615 615
616 - if (proxy_type < 0) 616 + if (session->proxy_type < 0)
617 return -1; 617 return -1;
618 } 618 }
619 619
@@ -625,9 +625,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -625,9 +625,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
625 passthru_len); 625 passthru_len);
626 haddr.sin.sin_port = passthru_port; 626 haddr.sin.sin_port = passthru_port;
627 ha_len = sizeof(struct sockaddr_in); 627 ha_len = sizeof(struct sockaddr_in);
628 - } else if (proxy_type > 0) {  
629 - if (resolve_host_and_port(session,proxy_host, proxy_portname,  
630 - &proxy_port, &haddr.sa, &ha_len, errmsg, 628 + } else if (session->proxy_type > 0) {
  629 + if (resolve_host_and_port(session,session->proxy_host, session->proxy_portname,
  630 + &session->proxy_port, &haddr.sa, &ha_len, errmsg,
631 sizeof(errmsg)) < 0) { 631 sizeof(errmsg)) < 0) {
632 popup_an_error(session,errmsg); 632 popup_an_error(session,errmsg);
633 return -1; 633 return -1;
@@ -769,9 +769,9 @@ setup_lus(void) @@ -769,9 +769,9 @@ setup_lus(void)
769 h3270.connected_type = CN; 769 h3270.connected_type = CN;
770 770
771 if (!h3270.luname[0]) { 771 if (!h3270.luname[0]) {
772 - Replace(lus, NULL);  
773 - curr_lu = (char **)NULL;  
774 - try_lu = CN; 772 + Replace(h3270.lus, NULL);
  773 + h3270.curr_lu = (char **)NULL;
  774 + h3270.try_lu = CN;
775 return; 775 return;
776 } 776 }
777 777
@@ -789,33 +789,33 @@ setup_lus(void) @@ -789,33 +789,33 @@ setup_lus(void)
789 * Allocate enough memory to construct an argv[] array for 789 * Allocate enough memory to construct an argv[] array for
790 * the LUs. 790 * the LUs.
791 */ 791 */
792 - Replace(lus,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(h3270.luname) + 1)); 792 + Replace(h3270.lus,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(h3270.luname) + 1));
793 793
794 /* Copy each LU into the array. */ 794 /* Copy each LU into the array. */
795 - lu = (char *)(lus + n_lus + 1); 795 + lu = (char *)(h3270.lus + n_lus + 1);
796 (void) strcpy(lu, h3270.luname); 796 (void) strcpy(lu, h3270.luname);
797 i = 0; 797 i = 0;
798 do { 798 do {
799 - lus[i++] = lu; 799 + h3270.lus[i++] = lu;
800 comma = strchr(lu, ','); 800 comma = strchr(lu, ',');
801 if (comma != CN) { 801 if (comma != CN) {
802 *comma = '\0'; 802 *comma = '\0';
803 lu = comma + 1; 803 lu = comma + 1;
804 } 804 }
805 } while (comma != CN); 805 } while (comma != CN);
806 - lus[i] = CN;  
807 - curr_lu = lus;  
808 - try_lu = *curr_lu; 806 + h3270.lus[i] = CN;
  807 + h3270.curr_lu = h3270.lus;
  808 + h3270.try_lu = *h3270.curr_lu;
809 } 809 }
810 810
811 static void net_connected(H3270 *session) 811 static void net_connected(H3270 *session)
812 { 812 {
813 - if (proxy_type > 0) 813 + if(session->proxy_type > 0)
814 { 814 {
815 /* Negotiate with the proxy. */ 815 /* Negotiate with the proxy. */
816 - trace_dsn("Connected to proxy server %s, port %u.\n",proxy_host, proxy_port); 816 + trace_dsn("Connected to proxy server %s, port %u.\n",session->proxy_host, session->proxy_port);
817 817
818 - if (proxy_negotiate(proxy_type, session->sock, session->hostname,session->current_port) < 0) 818 + if (proxy_negotiate(session->proxy_type, session->sock, session->hostname,session->current_port) < 0)
819 { 819 {
820 host_disconnect(session,True); 820 host_disconnect(session,True);
821 return; 821 return;
@@ -1171,8 +1171,8 @@ send_naws(void) @@ -1171,8 +1171,8 @@ send_naws(void)
1171 static void 1171 static void
1172 next_lu(void) 1172 next_lu(void)
1173 { 1173 {
1174 - if (curr_lu != (char **)NULL && (try_lu = *++curr_lu) == CN)  
1175 - curr_lu = (char **)NULL; 1174 + if (h3270.curr_lu != (char **)NULL && (h3270.try_lu = *++h3270.curr_lu) == CN)
  1175 + h3270.curr_lu = (char **)NULL;
1176 } 1176 }
1177 1177
1178 /* 1178 /*
@@ -1456,16 +1456,16 @@ static int telnet_fsm(H3270 *session, unsigned char c) @@ -1456,16 +1456,16 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1456 1456
1457 trace_dsn("%s %s\n", opt(session->sbbuf[0]), 1457 trace_dsn("%s %s\n", opt(session->sbbuf[0]),
1458 telquals[session->sbbuf[1]]); 1458 telquals[session->sbbuf[1]]);
1459 - if (lus != (char **)NULL && try_lu == CN) { 1459 + if (session->lus != (char **)NULL && h3270.try_lu == CN) {
1460 /* None of the LUs worked. */ 1460 /* None of the LUs worked. */
1461 popup_an_error(NULL,"Cannot connect to specified LU"); 1461 popup_an_error(NULL,"Cannot connect to specified LU");
1462 return -1; 1462 return -1;
1463 } 1463 }
1464 1464
1465 tt_len = strlen(session->termtype); 1465 tt_len = strlen(session->termtype);
1466 - if (try_lu != CN && *try_lu) {  
1467 - tt_len += strlen(try_lu) + 1;  
1468 - session->connected_lu = try_lu; 1466 + if (h3270.try_lu != CN && *h3270.try_lu) {
  1467 + tt_len += strlen(h3270.try_lu) + 1;
  1468 + session->connected_lu = h3270.try_lu;
1469 } else 1469 } else
1470 session->connected_lu = CN; 1470 session->connected_lu = CN;
1471 status_lu(session,session->connected_lu); 1471 status_lu(session,session->connected_lu);
@@ -1475,8 +1475,8 @@ static int telnet_fsm(H3270 *session, unsigned char c) @@ -1475,8 +1475,8 @@ static int telnet_fsm(H3270 *session, unsigned char c)
1475 (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", 1475 (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c",
1476 IAC, SB, TELOPT_TTYPE, TELQUAL_IS, 1476 IAC, SB, TELOPT_TTYPE, TELQUAL_IS,
1477 session->termtype, 1477 session->termtype,
1478 - (try_lu != CN && *try_lu) ? "@" : "",  
1479 - (try_lu != CN && *try_lu) ? try_lu : "", 1478 + (h3270.try_lu != CN && *h3270.try_lu) ? "@" : "",
  1479 + (h3270.try_lu != CN && *h3270.try_lu) ? h3270.try_lu : "",
1480 IAC, SE); 1480 IAC, SE);
1481 net_rawout(&h3270, (unsigned char *)tt_out, tb_len); 1481 net_rawout(&h3270, (unsigned char *)tt_out, tb_len);
1482 1482
@@ -1523,8 +1523,8 @@ tn3270e_request(void) @@ -1523,8 +1523,8 @@ tn3270e_request(void)
1523 char *t; 1523 char *t;
1524 1524
1525 tt_len = strlen(h3270.termtype); 1525 tt_len = strlen(h3270.termtype);
1526 - if (try_lu != CN && *try_lu)  
1527 - tt_len += strlen(try_lu) + 1; 1526 + if (h3270.try_lu != CN && *h3270.try_lu)
  1527 + tt_len += strlen(h3270.try_lu) + 1;
1528 1528
1529 tb_len = 5 + tt_len + 2; 1529 tb_len = 5 + tt_len + 2;
1530 tt_out = lib3270_malloc(tb_len + 1); 1530 tt_out = lib3270_malloc(tb_len + 1);
@@ -1537,8 +1537,8 @@ tn3270e_request(void) @@ -1537,8 +1537,8 @@ tn3270e_request(void)
1537 if (tt_out[12] == '9') 1537 if (tt_out[12] == '9')
1538 tt_out[12] = '8'; 1538 tt_out[12] = '8';
1539 1539
1540 - if (try_lu != CN && *try_lu)  
1541 - t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, try_lu); 1540 + if (h3270.try_lu != CN && *h3270.try_lu)
  1541 + t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, h3270.try_lu);
1542 1542
1543 (void) sprintf(t, "%c%c", IAC, SE); 1543 (void) sprintf(t, "%c%c", IAC, SE);
1544 1544
@@ -1546,8 +1546,8 @@ tn3270e_request(void) @@ -1546,8 +1546,8 @@ tn3270e_request(void)
1546 1546
1547 trace_dsn("SENT %s %s DEVICE-TYPE REQUEST %.*s%s%s %s\n", 1547 trace_dsn("SENT %s %s DEVICE-TYPE REQUEST %.*s%s%s %s\n",
1548 cmd(SB), opt(TELOPT_TN3270E), (int) strlen(h3270.termtype), tt_out + 5, 1548 cmd(SB), opt(TELOPT_TN3270E), (int) strlen(h3270.termtype), tt_out + 5,
1549 - (try_lu != CN && *try_lu) ? " CONNECT " : "",  
1550 - (try_lu != CN && *try_lu) ? try_lu : "", 1549 + (h3270.try_lu != CN && *h3270.try_lu) ? " CONNECT " : "",
  1550 + (h3270.try_lu != CN && *h3270.try_lu) ? h3270.try_lu : "",
1551 cmd(SE)); 1551 cmd(SE));
1552 1552
1553 lib3270_free(tt_out); 1553 lib3270_free(tt_out);
@@ -1670,10 +1670,10 @@ tn3270e_negotiate(void) @@ -1670,10 +1670,10 @@ tn3270e_negotiate(void)
1670 } 1670 }
1671 1671
1672 next_lu(); 1672 next_lu();
1673 - if (try_lu != CN) { 1673 + if (h3270.try_lu != CN) {
1674 /* Try the next LU. */ 1674 /* Try the next LU. */
1675 tn3270e_request(); 1675 tn3270e_request();
1676 - } else if (lus != (char **)NULL) { 1676 + } else if (h3270.lus != (char **)NULL) {
1677 /* No more LUs to try. Give up. */ 1677 /* No more LUs to try. Give up. */
1678 backoff_tn3270e(_("Host rejected resource(s)")); 1678 backoff_tn3270e(_("Host rejected resource(s)"));
1679 } else { 1679 } else {
@@ -1849,7 +1849,7 @@ process_bind(unsigned char *buf, int buflen) @@ -1849,7 +1849,7 @@ process_bind(unsigned char *buf, int buflen)
1849 { 1849 {
1850 int namelen, i; 1850 int namelen, i;
1851 1851
1852 - (void) memset(plu_name, '\0', sizeof(plu_name)); 1852 + (void) memset(h3270.plu_name, '\0', sizeof(h3270.plu_name));
1853 1853
1854 /* Make sure it's a BIND. */ 1854 /* Make sure it's a BIND. */
1855 if (buflen < 1 || buf[0] != BIND_RU) { 1855 if (buflen < 1 || buf[0] != BIND_RU) {
@@ -1865,7 +1865,7 @@ process_bind(unsigned char *buf, int buflen) @@ -1865,7 +1865,7 @@ process_bind(unsigned char *buf, int buflen)
1865 if (namelen > BIND_PLU_NAME_MAX) 1865 if (namelen > BIND_PLU_NAME_MAX)
1866 namelen = BIND_PLU_NAME_MAX; 1866 namelen = BIND_PLU_NAME_MAX;
1867 for (i = 0; i < namelen; i++) { 1867 for (i = 0; i < namelen; i++) {
1868 - plu_name[i] = ebc2asc0[buf[BIND_OFF_PLU_NAME + i]]; 1868 + h3270.plu_name[i] = ebc2asc0[buf[BIND_OFF_PLU_NAME + i]];
1869 } 1869 }
1870 } 1870 }
1871 #endif /*]*/ 1871 #endif /*]*/
@@ -1910,7 +1910,7 @@ process_eor(void) @@ -1910,7 +1910,7 @@ process_eor(void)
1910 if (!(h3270.e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE))) 1910 if (!(h3270.e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE)))
1911 return 0; 1911 return 0;
1912 process_bind(h3270.ibuf + EH_SIZE, (h3270.ibptr - h3270.ibuf) - EH_SIZE); 1912 process_bind(h3270.ibuf + EH_SIZE, (h3270.ibptr - h3270.ibuf) - EH_SIZE);
1913 - trace_dsn("< BIND PLU-name '%s'\n", plu_name); 1913 + trace_dsn("< BIND PLU-name '%s'\n", h3270.plu_name);
1914 h3270.tn3270e_bound = 1; 1914 h3270.tn3270e_bound = 1;
1915 check_in3270(&h3270); 1915 check_in3270(&h3270);
1916 return 0; 1916 return 0;
@@ -2468,9 +2468,9 @@ check_in3270(H3270 *session) @@ -2468,9 +2468,9 @@ check_in3270(H3270 *session)
2468 * TN3270E mode, reset the LU list so we can try again 2468 * TN3270E mode, reset the LU list so we can try again
2469 * in the new mode. 2469 * in the new mode.
2470 */ 2470 */
2471 - if (lus != (char **)NULL && was_in_e != IN_E) {  
2472 - curr_lu = lus;  
2473 - try_lu = *curr_lu; 2471 + if (h3270.lus != (char **)NULL && was_in_e != IN_E) {
  2472 + h3270.curr_lu = h3270.lus;
  2473 + h3270.try_lu = *h3270.curr_lu;
2474 } 2474 }
2475 #endif /*]*/ 2475 #endif /*]*/
2476 2476
@@ -3452,30 +3452,30 @@ int net_getsockname(const H3270 *session, void *buf, int *len) @@ -3452,30 +3452,30 @@ int net_getsockname(const H3270 *session, void *buf, int *len)
3452 char * 3452 char *
3453 net_proxy_type(void) 3453 net_proxy_type(void)
3454 { 3454 {
3455 - if (proxy_type > 0)  
3456 - return proxy_type_name(proxy_type); 3455 + if(h3270.proxy_type > 0)
  3456 + return proxy_type_name(h3270.proxy_type);
3457 else 3457 else
3458 - return NULL; 3458 + return NULL;
3459 } 3459 }
3460 3460
3461 /* Return the current proxy host, or NULL. */ 3461 /* Return the current proxy host, or NULL. */
3462 char * 3462 char *
3463 net_proxy_host(void) 3463 net_proxy_host(void)
3464 { 3464 {
3465 - if (proxy_type > 0)  
3466 - return proxy_host; 3465 + if(h3270.proxy_type > 0)
  3466 + return h3270.proxy_host;
3467 else 3467 else
3468 - return NULL; 3468 + return NULL;
3469 } 3469 }
3470 3470
3471 /* Return the current proxy port, or NULL. */ 3471 /* Return the current proxy port, or NULL. */
3472 char * 3472 char *
3473 net_proxy_port(void) 3473 net_proxy_port(void)
3474 { 3474 {
3475 - if (proxy_type > 0)  
3476 - return proxy_portname; 3475 + if (h3270.proxy_type > 0)
  3476 + return h3270.proxy_portname;
3477 else 3477 else
3478 - return NULL; 3478 + return NULL;
3479 } 3479 }
3480 3480
3481 LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session) 3481 LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session)