Commit 7c41e1dc65c31e5e644649390dc747432a0882d9
1 parent
e9546c7f
Exists in
master
and in
5 other branches
Movendo campos para a estrutura de sessao
Showing
4 changed files
with
78 additions
and
62 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -35,6 +35,14 @@ |
35 | 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 | 46 | * Character attributes |
39 | 47 | */ |
40 | 48 | typedef enum _lib3270_attr | ... | ... |
src/include/lib3270/session.h
... | ... | @@ -199,6 +199,14 @@ |
199 | 199 | int ansi_data; |
200 | 200 | int lnext; |
201 | 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 | 211 | enum |
204 | 212 | { | ... | ... |
src/lib3270/3270ds.h
... | ... | @@ -327,7 +327,7 @@ |
327 | 327 | #define EBC_eo 0xff |
328 | 328 | |
329 | 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 | 197 | // static int tn3270e_negotiated = 0; |
198 | 198 | //static enum { E_NONE, E_3270, E_NVT, E_SSCP } tn3270e_submode = E_NONE; |
199 | 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 | 210 | static int telnet_fsm(H3270 *session, unsigned char c); |
211 | 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 | 587 | |
588 | 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 | 596 | unsigned long lport; |
597 | 597 | char *ptr; |
... | ... | @@ -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 | 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 | 625 | passthru_len); |
626 | 626 | haddr.sin.sin_port = passthru_port; |
627 | 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 | 631 | sizeof(errmsg)) < 0) { |
632 | 632 | popup_an_error(session,errmsg); |
633 | 633 | return -1; |
... | ... | @@ -769,9 +769,9 @@ setup_lus(void) |
769 | 769 | h3270.connected_type = CN; |
770 | 770 | |
771 | 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 | 775 | return; |
776 | 776 | } |
777 | 777 | |
... | ... | @@ -789,33 +789,33 @@ setup_lus(void) |
789 | 789 | * Allocate enough memory to construct an argv[] array for |
790 | 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 | 794 | /* Copy each LU into the array. */ |
795 | - lu = (char *)(lus + n_lus + 1); | |
795 | + lu = (char *)(h3270.lus + n_lus + 1); | |
796 | 796 | (void) strcpy(lu, h3270.luname); |
797 | 797 | i = 0; |
798 | 798 | do { |
799 | - lus[i++] = lu; | |
799 | + h3270.lus[i++] = lu; | |
800 | 800 | comma = strchr(lu, ','); |
801 | 801 | if (comma != CN) { |
802 | 802 | *comma = '\0'; |
803 | 803 | lu = comma + 1; |
804 | 804 | } |
805 | 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 | 811 | static void net_connected(H3270 *session) |
812 | 812 | { |
813 | - if (proxy_type > 0) | |
813 | + if(session->proxy_type > 0) | |
814 | 814 | { |
815 | 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 | 820 | host_disconnect(session,True); |
821 | 821 | return; |
... | ... | @@ -1171,8 +1171,8 @@ send_naws(void) |
1171 | 1171 | static void |
1172 | 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 | 1456 | |
1457 | 1457 | trace_dsn("%s %s\n", opt(session->sbbuf[0]), |
1458 | 1458 | telquals[session->sbbuf[1]]); |
1459 | - if (lus != (char **)NULL && try_lu == CN) { | |
1459 | + if (session->lus != (char **)NULL && h3270.try_lu == CN) { | |
1460 | 1460 | /* None of the LUs worked. */ |
1461 | 1461 | popup_an_error(NULL,"Cannot connect to specified LU"); |
1462 | 1462 | return -1; |
1463 | 1463 | } |
1464 | 1464 | |
1465 | 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 | 1469 | } else |
1470 | 1470 | session->connected_lu = CN; |
1471 | 1471 | status_lu(session,session->connected_lu); |
... | ... | @@ -1475,8 +1475,8 @@ static int telnet_fsm(H3270 *session, unsigned char c) |
1475 | 1475 | (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", |
1476 | 1476 | IAC, SB, TELOPT_TTYPE, TELQUAL_IS, |
1477 | 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 | 1480 | IAC, SE); |
1481 | 1481 | net_rawout(&h3270, (unsigned char *)tt_out, tb_len); |
1482 | 1482 | |
... | ... | @@ -1523,8 +1523,8 @@ tn3270e_request(void) |
1523 | 1523 | char *t; |
1524 | 1524 | |
1525 | 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 | 1529 | tb_len = 5 + tt_len + 2; |
1530 | 1530 | tt_out = lib3270_malloc(tb_len + 1); |
... | ... | @@ -1537,8 +1537,8 @@ tn3270e_request(void) |
1537 | 1537 | if (tt_out[12] == '9') |
1538 | 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 | 1543 | (void) sprintf(t, "%c%c", IAC, SE); |
1544 | 1544 | |
... | ... | @@ -1546,8 +1546,8 @@ tn3270e_request(void) |
1546 | 1546 | |
1547 | 1547 | trace_dsn("SENT %s %s DEVICE-TYPE REQUEST %.*s%s%s %s\n", |
1548 | 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 | 1551 | cmd(SE)); |
1552 | 1552 | |
1553 | 1553 | lib3270_free(tt_out); |
... | ... | @@ -1670,10 +1670,10 @@ tn3270e_negotiate(void) |
1670 | 1670 | } |
1671 | 1671 | |
1672 | 1672 | next_lu(); |
1673 | - if (try_lu != CN) { | |
1673 | + if (h3270.try_lu != CN) { | |
1674 | 1674 | /* Try the next LU. */ |
1675 | 1675 | tn3270e_request(); |
1676 | - } else if (lus != (char **)NULL) { | |
1676 | + } else if (h3270.lus != (char **)NULL) { | |
1677 | 1677 | /* No more LUs to try. Give up. */ |
1678 | 1678 | backoff_tn3270e(_("Host rejected resource(s)")); |
1679 | 1679 | } else { |
... | ... | @@ -1849,7 +1849,7 @@ process_bind(unsigned char *buf, int buflen) |
1849 | 1849 | { |
1850 | 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 | 1854 | /* Make sure it's a BIND. */ |
1855 | 1855 | if (buflen < 1 || buf[0] != BIND_RU) { |
... | ... | @@ -1865,7 +1865,7 @@ process_bind(unsigned char *buf, int buflen) |
1865 | 1865 | if (namelen > BIND_PLU_NAME_MAX) |
1866 | 1866 | namelen = BIND_PLU_NAME_MAX; |
1867 | 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 | 1871 | #endif /*]*/ |
... | ... | @@ -1910,7 +1910,7 @@ process_eor(void) |
1910 | 1910 | if (!(h3270.e_funcs & E_OPT(TN3270E_FUNC_BIND_IMAGE))) |
1911 | 1911 | return 0; |
1912 | 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 | 1914 | h3270.tn3270e_bound = 1; |
1915 | 1915 | check_in3270(&h3270); |
1916 | 1916 | return 0; |
... | ... | @@ -2468,9 +2468,9 @@ check_in3270(H3270 *session) |
2468 | 2468 | * TN3270E mode, reset the LU list so we can try again |
2469 | 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 | 2475 | #endif /*]*/ |
2476 | 2476 | |
... | ... | @@ -3452,30 +3452,30 @@ int net_getsockname(const H3270 *session, void *buf, int *len) |
3452 | 3452 | char * |
3453 | 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 | 3457 | else |
3458 | - return NULL; | |
3458 | + return NULL; | |
3459 | 3459 | } |
3460 | 3460 | |
3461 | 3461 | /* Return the current proxy host, or NULL. */ |
3462 | 3462 | char * |
3463 | 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 | 3467 | else |
3468 | - return NULL; | |
3468 | + return NULL; | |
3469 | 3469 | } |
3470 | 3470 | |
3471 | 3471 | /* Return the current proxy port, or NULL. */ |
3472 | 3472 | char * |
3473 | 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 | 3477 | else |
3478 | - return NULL; | |
3478 | + return NULL; | |
3479 | 3479 | } |
3480 | 3480 | |
3481 | 3481 | LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session) | ... | ... |