diff --git a/ctlr.c b/ctlr.c index 927cfa5..6f87307 100644 --- a/ctlr.c +++ b/ctlr.c @@ -26,12 +26,11 @@ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ -/* - * ctlr.c +/** + * @file * This module handles interpretation of the 3270 data stream and * maintenance of the 3270 device state. It was split out from * screen.c, which handles X operations. @@ -75,11 +74,12 @@ static void ctlr_connect(H3270 *session, int ignored, void *dunno); static void ticking_stop(H3270 *session); static void ctlr_add_ic(H3270 *session, int baddr, unsigned char ic); -/* +/** * code_table is used to translate buffer addresses and attributes to the 3270 * datastream representation */ -static unsigned char code_table[64] = { +static const unsigned char code_table[64] = +{ 0x40, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, @@ -1248,7 +1248,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er if (add_dbcs) { ctlr_add(hSession,hSession->buffer_addr, add_c2,hSession->default_cs); - ctlr_add_fg(hSession,hSession->buffer_addr, h3270.default_fg); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); @@ -1345,7 +1345,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er trace_ds(hSession,"%s",see_efa(*cp,*(cp + 1))); cp++; if (hSession->m3279) - ctlr_add_fg(hSession,h3270.buffer_addr, *cp); + ctlr_add_fg(hSession,hSession->buffer_addr, *cp); } else if (*cp == XA_BACKGROUND) { @@ -1358,7 +1358,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er { trace_ds(hSession,"%s",see_efa(*cp,*(cp + 1))); cp++; - ctlr_add_gr(hSession,h3270.buffer_addr, *cp & 0x0f); + ctlr_add_gr(hSession,hSession->buffer_addr, *cp & 0x0f); } else if (*cp == XA_CHARSET) { @@ -1401,7 +1401,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er case ORDER_SFE: /* start field extended */ END_TEXT("StartFieldExtended"); if (previous != SBA) - trace_ds(hSession,"%s",rcba(hSession,h3270.buffer_addr)); + trace_ds(hSession,"%s",rcba(hSession,hSession->buffer_addr)); previous = ORDER; cp++; /* skip order */ na = *cp; @@ -1421,12 +1421,12 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } else if (*cp == XA_FOREGROUND) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; - if (h3270.m3279) + if (hSession->m3279) efa_fg = *cp; } else if (*cp == XA_BACKGROUND) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); cp++; - if (h3270.m3279) + if (hSession->m3279) efa_bg = *cp; } else if (*cp == XA_HIGHLIGHTING) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); @@ -1437,7 +1437,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er cp++; if (*cp == 0xf1) efa_cs = CS_APL; - else if (h3270.dbcs && (*cp == 0xf8)) + else if (hSession->dbcs && (*cp == 0xf8)) efa_cs = CS_DBCS; else efa_cs = CS_BASE; @@ -1456,11 +1456,11 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } if (!any_fa) START_FIELD(0); - ctlr_add_cs(hSession,h3270.buffer_addr, efa_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, efa_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, efa_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, efa_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, efa_ic); + ctlr_add_cs(hSession,hSession->buffer_addr, efa_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, efa_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, efa_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, efa_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, efa_ic); INC_BA(hSession->buffer_addr); last_cmd = True; last_zpt = False; @@ -1471,41 +1471,41 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er cp++; if (*cp == XA_FOREGROUND) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); - if (h3270.m3279) - h3270.default_fg = *(cp + 1); + if (hSession->m3279) + hSession->default_fg = *(cp + 1); } else if (*cp == XA_BACKGROUND) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); - if (h3270.m3279) - h3270.default_bg = *(cp + 1); + if (hSession->m3279) + hSession->default_bg = *(cp + 1); } else if (*cp == XA_HIGHLIGHTING) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); - h3270.default_gr = *(cp + 1) & 0x0f; + hSession->default_gr = *(cp + 1) & 0x0f; } else if (*cp == XA_ALL) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); - h3270.default_fg = 0; - h3270.default_bg = 0; - h3270.default_gr = 0; - h3270.default_cs = 0; - h3270.default_ic = 0; + hSession->default_fg = 0; + hSession->default_bg = 0; + hSession->default_gr = 0; + hSession->default_cs = 0; + hSession->default_ic = 0; } else if (*cp == XA_CHARSET) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); switch (*(cp + 1)) { case 0xf1: - h3270.default_cs = CS_APL; + hSession->default_cs = CS_APL; break; case 0xf8: - h3270.default_cs = CS_DBCS; + hSession->default_cs = CS_DBCS; break; default: - h3270.default_cs = CS_BASE; + hSession->default_cs = CS_BASE; break; } } else if (*cp == XA_INPUT_CONTROL) { trace_ds(hSession,"%s", see_efa(*cp, *(cp + 1))); if (*(cp + 1) == 1) - h3270.default_ic = 1; + hSession->default_ic = 1; else - h3270.default_ic = 0; + hSession->default_ic = 0; } else trace_ds(hSession,"%s[unsupported]",see_efa(*cp, *(cp + 1))); cp++; @@ -1523,7 +1523,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er END_TEXT(see_ebc(*cp)); previous = ORDER; d = ctlr_lookleft_state(buffer_addr, &why); - if (h3270.default_cs == CS_DBCS || d != DBCS_NONE) { + if (hSession->default_cs == CS_DBCS || d != DBCS_NONE) { ABORT_WRITE("invalid format control order in DBCS field"); } ctlr_add(hSession,hSession->buffer_addr, *cp, hSession->default_cs); @@ -1550,11 +1550,11 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er } /* All is well. */ previous = ORDER; - ctlr_add(hSession,h3270.buffer_addr, *cp, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession,hSession->buffer_addr, *cp, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); last_cmd = True; last_zpt = False; @@ -1569,31 +1569,31 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er if (d != DBCS_NONE && why == DBCS_FIELD) { ABORT_WRITE("SI in DBCS field"); } - fa_addr = find_field_attribute(hSession,h3270.buffer_addr); - baddr = h3270.buffer_addr; + fa_addr = find_field_attribute(hSession,hSession->buffer_addr); + baddr = hSession->buffer_addr; DEC_BA(baddr); while (!aborted && ((fa_addr >= 0 && baddr != fa_addr) || - (fa_addr < 0 && baddr != h3270.rows*h3270.cols - 1))) { - if (h3270.ea_buf[baddr].cc == FCORDER_SI) { + (fa_addr < 0 && baddr != hSession->rows*hSession->cols - 1))) { + if (hSession->ea_buf[baddr].cc == FCORDER_SI) { ABORT_WRITE("double SI"); } - if (h3270.ea_buf[baddr].cc == FCORDER_SO) + if (hSession->ea_buf[baddr].cc == FCORDER_SO) break; DEC_BA(baddr); } if (aborted) break; - if (h3270.ea_buf[baddr].cc != FCORDER_SO) { + if (hSession->ea_buf[baddr].cc != FCORDER_SO) { ABORT_WRITE("SI without SO"); } /* All is well. */ previous = ORDER; - ctlr_add(hSession,h3270.buffer_addr, *cp, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession,hSession->buffer_addr, *cp, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); last_cmd = True; last_zpt = False; @@ -1601,11 +1601,11 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er case FCORDER_NULL: /* NULL or DBCS control char */ previous = NULLCH; add_dbcs = False; - d = ctlr_lookleft_state(h3270.buffer_addr, &why); + d = ctlr_lookleft_state(hSession->buffer_addr, &why); if (d == DBCS_RIGHT) { ABORT_WRITE("NULL overwriting right half of DBCS character"); } - if (d != DBCS_NONE || h3270.default_cs == CS_DBCS) { + if (d != DBCS_NONE || hSession->default_cs == CS_DBCS) { add_c1 = EBC_null; cp++; if (cp >= buf + buflen) { @@ -1641,19 +1641,19 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er END_TEXT("NULL"); add_c1 = *cp; } - ctlr_add(hSession,h3270.buffer_addr, add_c1, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession,hSession->buffer_addr, add_c1, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); if (add_dbcs) { - ctlr_add(hSession,h3270.buffer_addr, add_c2, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession,hSession->buffer_addr, add_c2, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); } last_cmd = False; @@ -1699,19 +1699,19 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er #if defined(X3270_DBCS) /*[*/ } #endif /*]*/ - ctlr_add(hSession,h3270.buffer_addr, add_c1, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(hSession,h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(hSession,h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession,hSession->buffer_addr, add_c1, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession,hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession,hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); #if defined(X3270_DBCS) /*[*/ if (add_dbcs) { - ctlr_add(h3270.buffer_addr, add_c2, h3270.default_cs); - ctlr_add_fg(hSession,h3270.buffer_addr, h3270.default_fg); - ctlr_add_bg(h3270.buffer_addr, h3270.default_bg); - ctlr_add_gr(h3270.buffer_addr, h3270.default_gr); - ctlr_add_ic(hSession,h3270.buffer_addr, h3270.default_ic); + ctlr_add(hSession->buffer_addr, add_c2, hSession->default_cs); + ctlr_add_fg(hSession,hSession->buffer_addr, hSession->default_fg); + ctlr_add_bg(hSession->buffer_addr, hSession->default_bg); + ctlr_add_gr(hSession->buffer_addr, hSession->default_gr); + ctlr_add_ic(hSession,hSession->buffer_addr, hSession->default_ic); INC_BA(hSession->buffer_addr); } #endif /*]*/ @@ -1724,9 +1724,9 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er END_TEXT0; trace_ds(hSession,"\n"); if (wcc_keyboard_restore) { - h3270.aid = AID_NO; + hSession->aid = AID_NO; do_reset(hSession,False); - } else if (h3270.kybdlock & KL_OIA_TWAIT) { + } else if (hSession->kybdlock & KL_OIA_TWAIT) { lib3270_kybdlock_clear(hSession,KL_OIA_TWAIT); status_changed(hSession,LIB3270_STATUS_SYSWAIT); } @@ -2431,7 +2431,7 @@ void ctlr_scroll(H3270 *hSession) /* Synchronize pending changes prior to this. */ /* Move ea_buf. */ - (void) memmove(&hSession->ea_buf[0], &hSession->ea_buf[h3270.cols],qty * sizeof(struct lib3270_ea)); + (void) memmove(&hSession->ea_buf[0], &hSession->ea_buf[hSession->cols],qty * sizeof(struct lib3270_ea)); /* Clear the last line. */ (void) memset((char *) &hSession->ea_buf[qty], 0, hSession->cols * sizeof(struct lib3270_ea)); diff --git a/globals.h b/globals.h index 597461e..72f457c 100644 --- a/globals.h +++ b/globals.h @@ -196,7 +196,7 @@ LIB3270_INTERNAL const char * build_rpq_revision; // LIB3270_INTERNAL char *local_encoding; #if defined(X3270_DISPLAY) /*[*/ - LIB3270_INTERNAL char *locale_name; +// LIB3270_INTERNAL char *locale_name; #endif /*]*/ #endif /*]*/ @@ -227,7 +227,7 @@ LIB3270_INTERNAL const char * build_rpq_revision; // LIB3270_INTERNAL Boolean shifted; // LIB3270_INTERNAL Boolean ssl_host; -LIB3270_INTERNAL Boolean *standard_font; +// LIB3270_INTERNAL Boolean *standard_font; // LIB3270_INTERNAL Boolean std_ds_host; // LIB3270_INTERNAL char *termtype; // LIB3270_INTERNAL Widget toplevel; @@ -277,7 +277,7 @@ struct toggle_name { }; -/* translation lists */ +/* translation lists */ /* struct trans_list { char *name; char *pathname; @@ -286,6 +286,7 @@ struct trans_list { struct trans_list *next; }; LIB3270_INTERNAL struct trans_list *trans_list; +*/ /* input key type */ // enum keytype { KT_STD, KT_GE }; diff --git a/iocalls.c b/iocalls.c index bac34e3..749bcf7 100644 --- a/iocalls.c +++ b/iocalls.c @@ -63,9 +63,9 @@ static void internal_remove_input(void *id); // static int internal_process_events(int block); static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm); -static int internal_wait(int seconds); +static int internal_wait(H3270 *hSession, int seconds); -static int internal_event_dispatcher(int block); +static int internal_event_dispatcher(H3270 *hSession, int block); static void internal_ring_bell(H3270 *); /*---[ Active callbacks ]-----------------------------------------------------------------------------------*/ @@ -96,10 +96,10 @@ static void internal_ring_bell(H3270 *); static int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm) = internal_callthread; - static int (*wait)(int seconds) + static int (*wait)(H3270 *hSession, int seconds) = internal_wait; - static int (*event_dispatcher)(int wait) + static int (*event_dispatcher)(H3270 *hSession,int wait) = internal_event_dispatcher; static void (*ring_bell)(H3270 *) @@ -333,7 +333,7 @@ static void internal_remove_input(void *id) } /* Event dispatcher. */ -static int internal_event_dispatcher(int block) +static int internal_event_dispatcher(H3270 *hSession, int block) { #if defined(_WIN32) HANDLE ha[MAX_HA]; @@ -533,7 +533,7 @@ static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, return 0; } -static int internal_wait(int seconds) +static int internal_wait(H3270 *hSession, int seconds) { time_t end; @@ -542,7 +542,7 @@ static int internal_wait(int seconds) while(time(0) < end) { - lib3270_main_iterate(&h3270,1); + lib3270_main_iterate(hSession,1); } return 0; @@ -713,15 +713,15 @@ LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 * return 0; } -LIB3270_EXPORT void lib3270_main_iterate(H3270 *session, int block) +LIB3270_EXPORT void lib3270_main_iterate(H3270 *hSession, int block) { - CHECK_SESSION_HANDLE(session); - event_dispatcher(block); + CHECK_SESSION_HANDLE(hSession); + event_dispatcher(hSession,block); } LIB3270_EXPORT int lib3270_wait(H3270 *hSession, int seconds) { - wait(seconds); + wait(hSession,seconds); return 0; } @@ -731,7 +731,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) while(time(0) < end) { - event_dispatcher(1); + event_dispatcher(hSession,1); if(hSession->oia_status == LIB3270_STATUS_BLANK) return 0; diff --git a/kybd.c b/kybd.c index 799be29..148823d 100644 --- a/kybd.c +++ b/kybd.c @@ -2130,7 +2130,7 @@ LIB3270_ACTION( eraseinput ) f = True; } if (!hSession->ea_buf[baddr].fa) { - ctlr_add(&h3270,baddr, EBC_null, 0); + ctlr_add(hSession,baddr, EBC_null, 0); } } while (!hSession->ea_buf[baddr].fa); } else { /* skip protected */ @@ -2417,7 +2417,7 @@ kybd_scroll_lock(Boolean lock) if (lock) kybdlock_set(KL_SCROLLED, "kybd_scroll_lock"); else - kybdlock_clr(&h3270, KL_SCROLLED, "kybd_scroll_lock"); + kybdlock_clr(hSession, KL_SCROLLED, "kybd_scroll_lock"); } */ /* diff --git a/proxy.c b/proxy.c index 34ebeb2..d376952 100644 --- a/proxy.c +++ b/proxy.c @@ -26,14 +26,15 @@ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ -/* - * proxy.c +/** + * @file proxy.c + * * This module implements various kinds of proxies. + * */ #ifdef _WIN32 @@ -101,63 +102,65 @@ enum PT_MAX } proxytype_t; -/* proxy type names -- keep these in sync with proxytype_t! */ -char *type_name[] = -{ - "unknown", - "passthru", - "HTTP", - "TELNET", - "SOCKS4", - "SOCKS4A", - "SOCKS5", - "SOCKS5D" -}; - #define PROXY_PASSTHRU "passthru" #define PORT_PASSTHRU "3514" -#define PROXY_HTTP "http" -#define PORT_HTTP "3128" +#define PROXY_HTTP "http" +#define PORT_HTTP "3128" #define PROXY_TELNET "telnet" #define PROXY_SOCKS4 "socks4" -#define PORT_SOCKS4 "1080" +#define PORT_SOCKS4 "1080" #define PROXY_SOCKS4A "socks4a" #define PORT_SOCKS4A "1080" #define PROXY_SOCKS5 "socks5" -#define PORT_SOCKS5 "1080" +#define PORT_SOCKS5 "1080" #define PROXY_SOCKS5D "socks5d" #define PORT_SOCKS5D "1080" -static int parse_host_port(char *s, char **phost, char **pport); +static int parse_host_port(H3270 *hSession, char *s, char **phost, char **pport); -static int proxy_passthru(int fd, char *host, unsigned short port); -static int proxy_http(int fd, char *host, unsigned short port); -static int proxy_telnet(int fd, char *host, unsigned short port); -static int proxy_socks4(int fd, char *host, unsigned short port, int force_a); -static int proxy_socks5(int fd, char *host, unsigned short port, int force_d); +static int proxy_passthru(H3270 *hSession, int fd, char *host, unsigned short port); +static int proxy_http(H3270 *hSession, int fd, char *host, unsigned short port); +static int proxy_telnet(H3270 *hSession, int fd, char *host, unsigned short port); +static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a); +static int proxy_socks5(H3270 *hSession, int fd, char *host, unsigned short port, int force_d); -char * proxy_type_name(int type) +const char * proxy_type_name(int type) { - if (type < 1 || type >= PT_MAX) - return "unknown"; + /* proxy type names -- keep these in sync with proxytype_t! */ + const char *type_name[] = + { + "unknown", + "passthru", + "HTTP", + "TELNET", + "SOCKS4", + "SOCKS4A", + "SOCKS5", + "SOCKS5D" + }; + + + if (type < 1 || type >= PT_MAX) + return "unknown"; else - return type_name[type]; + return type_name[type]; } -/* +/** * Resolve the type, hostname and port for a proxy. - * Returns -1 for failure, 0 for no proxy, >0 (the proxy type) for success. + * + * @return -1 for failure, 0 for no proxy, >0 (the proxy type) for success. */ -int proxy_setup(H3270 *session, char **phost, char **pport) +int proxy_setup(H3270 *hSession, char **phost, char **pport) { - char * proxy = session->proxy; + char * proxy = hSession->proxy; char * colon; int sl; @@ -166,14 +169,14 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if ((colon = strchr(proxy, ':')) == CN || (colon == proxy)) { - popup_an_error(session,_( "Invalid proxy syntax" ) ); + popup_an_error(hSession,_( "Invalid proxy syntax" ) ); return -1; } sl = colon - proxy; if (sl == strlen(PROXY_PASSTHRU) && !strncasecmp(proxy, PROXY_PASSTHRU, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) @@ -185,7 +188,7 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_HTTP) && !strncasecmp(proxy, PROXY_HTTP, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) *pport = NewString(PORT_HTTP); @@ -195,11 +198,11 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_TELNET) && !strncasecmp(proxy, PROXY_TELNET, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) { - popup_an_error(session,_( "Must specify port for telnet proxy" ) ); + popup_an_error(hSession,_( "Must specify port for telnet proxy" ) ); return -1; } return PT_TELNET; @@ -207,7 +210,7 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_SOCKS4) && !strncasecmp(proxy, PROXY_SOCKS4, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) @@ -218,7 +221,7 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_SOCKS4A) && !strncasecmp(proxy, PROXY_SOCKS4A, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) @@ -229,7 +232,7 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_SOCKS5) && !strncasecmp(proxy, PROXY_SOCKS5, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) @@ -240,7 +243,7 @@ int proxy_setup(H3270 *session, char **phost, char **pport) if (sl == strlen(PROXY_SOCKS5D) && !strncasecmp(proxy, PROXY_SOCKS5D, sl)) { - if (parse_host_port(colon + 1, phost, pport) < 0) + if (parse_host_port(hSession, colon + 1, phost, pport) < 0) return -1; if (*pport == CN) @@ -249,19 +252,20 @@ int proxy_setup(H3270 *session, char **phost, char **pport) return PT_SOCKS5D; } - popup_an_error(session,"Invalid proxy type '%.*s'", sl, proxy); + popup_an_error(hSession,_( "Invalid proxy type '%.*s'" ), sl, proxy); return -1; } -/* +/** * Parse host[:port] from a string. + * * 'host' can be in square brackets to allow numeric IPv6 addresses. * Returns the host name and port name in heap memory. - * Returns -1 for failure, 0 for success. + * + * @return -1 for failure, 0 for success. */ -static int -parse_host_port(char *s, char **phost, char **pport) +static int parse_host_port(H3270 *hSession, char *s, char **phost, char **pport) { char *colon; char *hstart; @@ -277,7 +281,7 @@ parse_host_port(char *s, char **phost, char **pport) rbrack == s + 1 || (*(rbrack + 1) != '\0' && *(rbrack + 1) != ':')) { - popup_an_error(NULL,"Invalid proxy hostname syntax"); + popup_an_error(hSession,_( "Invalid proxy hostname syntax")); return -1; } if (*(rbrack + 1) == ':') @@ -289,7 +293,7 @@ parse_host_port(char *s, char **phost, char **pport) hstart = s; colon = strchr(s, ':'); if (colon == s) { - popup_an_error(NULL,"Invalid proxy hostname syntax"); + popup_an_error(hSession,_("Invalid proxy hostname syntax")); return -1; } if (colon == NULL) @@ -311,37 +315,38 @@ parse_host_port(char *s, char **phost, char **pport) return 0; } -/* +/** * Negotiate with the proxy server. - * Returns -1 for failure, 0 for success. + * + * @return -1 for failure, 0 for success. */ -int -proxy_negotiate(int type, int fd, char *host, unsigned short port) +int proxy_negotiate(H3270 *hSession, int type, int fd, char *host, unsigned short port) { - switch (type) { + switch (type) + { case PT_NONE: return 0; case PT_PASSTHRU: - return proxy_passthru(fd, host, port); + return proxy_passthru(hSession, fd, host, port); case PT_HTTP: - return proxy_http(fd, host, port); + return proxy_http(hSession, fd, host, port); case PT_TELNET: - return proxy_telnet(fd, host, port); + return proxy_telnet(hSession, fd, host, port); case PT_SOCKS4: - return proxy_socks4(fd, host, port, 0); + return proxy_socks4(hSession, fd, host, port, 0); case PT_SOCKS4A: - return proxy_socks4(fd, host, port, 1); + return proxy_socks4(hSession, fd, host, port, 1); case PT_SOCKS5: - return proxy_socks5(fd, host, port, 0); + return proxy_socks5(hSession, fd, host, port, 0); case PT_SOCKS5D: - return proxy_socks5(fd, host, port, 1); + return proxy_socks5(hSession, fd, host, port, 1); default: return -1; } } /* Sun PASSTHRU proxy. */ -static int proxy_passthru(int fd, char *host, unsigned short port) +static int proxy_passthru(H3270 *hSession, int fd, char *host, unsigned short port) { char *buf; @@ -349,24 +354,24 @@ static int proxy_passthru(int fd, char *host, unsigned short port) (void) sprintf(buf, "%s %u\r\n", host, port); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"Passthru Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); - trace_netdata(&h3270,'>', (unsigned char *)buf, (int) strlen(buf)); + trace_dsn(hSession,"Passthru Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); + trace_netdata(hSession,'>', (unsigned char *)buf, (int) strlen(buf)); #endif /*]*/ if (send(fd, buf, strlen(buf), 0) < 0) { - popup_a_sockerr(&h3270,"Passthru Proxy: send error"); + popup_a_sockerr(hSession,_( "Passthru Proxy: send error" )); lib3270_free(buf); return -1; } lib3270_free(buf); - return 0; + return 0; } /* HTTP (RFC 2817 CONNECT tunnel) proxy. */ static int -proxy_http(int fd, char *host, unsigned short port) +proxy_http(H3270 *hSession, int fd, char *host, unsigned short port) { char *buf; char *colon; @@ -385,12 +390,13 @@ proxy_http(int fd, char *host, unsigned short port) port); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); - trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf)); + trace_dsn(hSession,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); + trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); #endif /*]*/ - if (send(fd, buf, strlen(buf), 0) < 0) { - popup_a_sockerr(NULL,"HTTP Proxy: send error"); + if (send(fd, buf, strlen(buf), 0) < 0) + { + popup_a_sockerr(hSession,_( "HTTP Proxy: send error" )); lib3270_free(buf); return -1; } @@ -402,24 +408,26 @@ proxy_http(int fd, char *host, unsigned short port) port); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); - trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf)); + trace_dsn(hSession,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); + trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); #endif /*]*/ - if (send(fd, buf, strlen(buf), 0) < 0) { - popup_a_sockerr(NULL,"HTTP Proxy: send error"); + if (send(fd, buf, strlen(buf), 0) < 0) + { + popup_a_sockerr(hSession,_( "HTTP Proxy: send error")); lib3270_free(buf); return -1; } strcpy(buf, "\r\n"); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"HTTP Proxy: xmit ''\n"); - trace_netdata(&h3270, '>', (unsigned char *)buf, strlen(buf)); + trace_dsn(hSession,"HTTP Proxy: xmit ''\n"); + trace_netdata(hSession, '>', (unsigned char *)buf, strlen(buf)); #endif /*]*/ - if (send(fd, buf, strlen(buf), 0) < 0) { - popup_a_sockerr(NULL,"HTTP Proxy: send error"); + if (send(fd, buf, strlen(buf), 0) < 0) + { + popup_a_sockerr(hSession,_( "HTTP Proxy: send error" )); lib3270_free(buf); return -1; } @@ -429,8 +437,9 @@ proxy_http(int fd, char *host, unsigned short port) * Process the reply. * Read a byte at a time until \n or EOF. */ - for (;;) { - fd_set rfds; + for (;;) + { + fd_set rfds; struct timeval tv; FD_ZERO(&rfds); @@ -438,29 +447,30 @@ proxy_http(int fd, char *host, unsigned short port) tv.tv_sec = 15; tv.tv_usec = 0; if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) { - popup_an_error(NULL,"HTTP Proxy: server timeout"); + popup_an_error(hSession,_( "HTTP Proxy: server timeout" )); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread); + trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); #endif /*]*/ return -1; } nr = recv(fd, &rbuf[nread], 1, 0); if (nr < 0) { - popup_a_sockerr(NULL,"HTTP Proxy: receive error"); + popup_a_sockerr(hSession,_( "HTTP Proxy: receive error" )); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread); + trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); #endif /*]*/ return -1; } - if (nr == 0) { + if (nr == 0) + { #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread); + trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); #endif /*]*/ - popup_an_error(NULL,"HTTP Proxy: unexpected EOF"); + popup_an_error(hSession,_( "HTTP Proxy: unexpected EOF" )); return -1; } if (rbuf[nread] == '\r') @@ -475,18 +485,18 @@ proxy_http(int fd, char *host, unsigned short port) rbuf[nread] = '\0'; #if defined(X3270_TRACE) /*[*/ - trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread); - trace_dsn(&h3270,"HTTP Proxy: recv '%s'\n", rbuf); + trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); + trace_dsn(hSession,"HTTP Proxy: recv '%s'\n", rbuf); #endif /*]*/ if (strncmp(rbuf, "HTTP/", 5) || (space = strchr(rbuf, ' ')) == CN) { - popup_an_error(&h3270,"HTTP Proxy: unrecognized reply"); + popup_an_error(hSession,_( "HTTP Proxy: unrecognized reply" )); return -1; } if (*(space + 1) != '2') { - popup_an_error(&h3270,"HTTP Proxy: CONNECT failed:\n%s", rbuf); + popup_an_error(hSession,_( "HTTP Proxy: CONNECT failed:\n%s"), rbuf); return -1; } @@ -495,7 +505,7 @@ proxy_http(int fd, char *host, unsigned short port) /* TELNET proxy. */ static int -proxy_telnet(int fd, char *host, unsigned short port) +proxy_telnet(H3270 *hSession, int fd, char *host, unsigned short port) { char *buf; @@ -503,13 +513,13 @@ proxy_telnet(int fd, char *host, unsigned short port) (void) sprintf(buf, "connect %s %u\r\n", host, port); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"TELNET Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); - trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf)); + trace_dsn(hSession,"TELNET Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); + trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); #endif /*]*/ if (send(fd, buf, strlen(buf), 0) < 0) { - popup_a_sockerr(&h3270,"TELNET Proxy: send error"); + popup_a_sockerr(hSession,_( "TELNET Proxy: send error")); lib3270_free(buf); return -1; } @@ -520,19 +530,19 @@ proxy_telnet(int fd, char *host, unsigned short port) /* SOCKS version 4 proxy. */ #if defined(HAVE_GETADDRINFO) -static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) +static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a) { - popup_an_error(NULL,"%s", _( "Unsupported socks 4 proxy" ) ); + popup_an_error(hSession,"%s", _( "Unsupported socks 4 proxy" ) ); return 0; } #else -static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) +static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a) { - struct hostent *hp; + struct hostent *hp; struct in_addr ipaddr; int use_4a = 0; char *user; - char *buf; + char *buf; char *s; char rbuf[8]; int nr; @@ -578,13 +588,13 @@ static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) s += strlen(host) + 1; #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"SOCKS4 Proxy: version 4 connect port %u address 0.0.0.1 user '%s' host '%s'\n",port, user, host); - trace_netdata(&h3270,'>', (unsigned char *)buf, s - buf); + trace_dsn(hSession,"SOCKS4 Proxy: version 4 connect port %u address 0.0.0.1 user '%s' host '%s'\n",port, user, host); + trace_netdata(hSession,'>', (unsigned char *)buf, s - buf); #endif /*]*/ if (send(fd, buf, s - buf, 0) < 0) { - popup_a_sockerr(&h3270,"SOCKS4 Proxy: send error"); + popup_a_sockerr(hSession,_( "SOCKS4 Proxy: send error" )); lib3270_free(buf); return -1; } @@ -603,14 +613,14 @@ static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) s += strlen(user) + 1; #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"SOCKS4 Proxy: xmit version 4 connect port %u address %s user '%s'\n",port, inet_ntoa(ipaddr), user); - trace_netdata(&h3270,'>', (unsigned char *)buf, s - buf); + trace_dsn(hSession,_( "SOCKS4 Proxy: xmit version 4 connect port %u address %s user '%s'\n"),port, inet_ntoa(ipaddr), user); + trace_netdata(hSession,'>', (unsigned char *)buf, s - buf); #endif /*]*/ if (send(fd, buf, s - buf, 0) < 0) { lib3270_free(buf); - popup_a_sockerr(&h3270,"SOCKS4 Proxy: send error"); + popup_a_sockerr(hSession,_("SOCKS4 Proxy: send error")); return -1; } lib3270_free(buf); @@ -628,50 +638,55 @@ static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) FD_SET(fd, &rfds); tv.tv_sec = 15; tv.tv_usec = 0; - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) { - popup_an_error(NULL,"SOCKS4 Proxy: server timeout"); + if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) + { + popup_an_error(hSession,_("SOCKS4 Proxy: server timeout")); return -1; } - nr = recv(fd, &rbuf[nread], 1, 0); - if (nr < 0) { - popup_a_sockerr(NULL,"SOCKS4 Proxy: receive error"); + nr = recv(fd, &rbuf[nread], 1, 0); + + if (nr < 0) + { + popup_a_sockerr(hSession,_("SOCKS4 Proxy: receive error")); return -1; } if (nr == 0) - break; + break; + if (++nread >= sizeof(rbuf)) - break; + break; } #if defined(X3270_TRACE) /*[*/ - trace_netdata(&h3270,'<', (unsigned char *)rbuf, nread); + trace_netdata(hSession,'<', (unsigned char *)rbuf, nread); if (use_4a) { struct in_addr a; rport = (rbuf[2] << 8) | rbuf[3]; memcpy(&a, &rbuf[4], 4); - trace_dsn(&h3270,"SOCKS4 Proxy: recv status 0x%02x port %u address %s\n",rbuf[1],rport,inet_ntoa(a)); + trace_dsn(hSession,_("SOCKS4 Proxy: recv status 0x%02x port %u address %s\n"),rbuf[1],rport,inet_ntoa(a)); } else - trace_dsn(&h3270,"SOCKS4 Proxy: recv status 0x%02x\n", rbuf[1]); + trace_dsn(hSession,_("SOCKS4 Proxy: recv status 0x%02x\n"), rbuf[1]); #endif /*]*/ - switch (rbuf[1]) { + switch (rbuf[1]) + { case 0x5a: break; case 0x5b: - popup_an_error(&h3270,"SOCKS4 Proxy: request rejected or failed"); + popup_an_error(hSession,_("SOCKS4 Proxy: request rejected or failed")); return -1; case 0x5c: - popup_an_error(&h3270,"SOCKS4 Proxy: client is not reachable"); + popup_an_error(hSession,_("SOCKS4 Proxy: client is not reachable")); return -1; case 0x5d: - popup_an_error(&h3270,"SOCKS4 Proxy: userid error"); + popup_an_error(hSession,_("SOCKS4 Proxy: userid error")); return -1; default: - popup_an_error(&h3270,"SOCKS4 Proxy: unknown status 0x%02x",rbuf[1]); + popup_an_error(hSession,_("SOCKS4 Proxy: unknown status 0x%02x",rbuf[1])); return -1; } @@ -680,8 +695,7 @@ static int proxy_socks4(int fd, char *host, unsigned short port, int force_a) #endif // HAVE_GETADDRINFO /* SOCKS version 5 (RFC 1928) proxy. */ -static int -proxy_socks5(int fd, char *host, unsigned short port, int force_d) +static int proxy_socks5(H3270 *hSession, int fd, char *host, unsigned short port, int force_d) { union { struct sockaddr sa; @@ -700,8 +714,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) int n2read = 0; char nbuf[256]; int done = 0; + #if defined(X3270_TRACE) /*[*/ - char *atype_name[] = { + const char *atype_name[] = + { "", "IPv4", "", @@ -719,12 +735,11 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) int rv; /* Resolve the hostname. */ - rv = resolve_host_and_port(&h3270,host, CN, &rport, &ha.sa, &ha_len,errmsg, sizeof(errmsg)); + rv = resolve_host_and_port(hSession,host, CN, &rport, &ha.sa, &ha_len,errmsg, sizeof(errmsg)); if (rv == -2) use_name = 1; else if (rv < 0) { - popup_an_error(NULL,"SOCKS5 proxy: %s/%u: %s", host, port, - errmsg); + popup_an_error(hSession,_("SOCKS5 proxy: %s/%u: %s"), host, port,errmsg); return -1; } } @@ -732,11 +747,12 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) /* Send the authentication request to the server. */ strcpy((char *)rbuf, "\005\001\000"); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"SOCKS5 Proxy: xmit version 5 nmethods 1 (no auth)\n"); - trace_netdata(&h3270, '>', rbuf, 3); + trace_dsn(hSession,_("SOCKS5 Proxy: xmit version 5 nmethods 1 (no auth)\n")); + trace_netdata(hSession, '>', rbuf, 3); #endif /*]*/ - if (send(fd, (const char *) rbuf, 3, 0) < 0) { - popup_a_sockerr(NULL,"SOCKS5 Proxy: send error"); + if (send(fd, (const char *) rbuf, 3, 0) < 0) + { + popup_a_sockerr(hSession,_("SOCKS5 Proxy: send error")); return -1; } @@ -755,10 +771,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) tv.tv_usec = 0; if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) { - popup_an_error(&h3270,"SOCKS5 Proxy: server timeout"); + popup_an_error(hSession,_("SOCKS5 Proxy: server timeout")); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', rbuf, nread); + trace_netdata(hSession, '<', rbuf, nread); #endif /*]*/ return -1; } @@ -766,19 +782,19 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) nr = recv(fd, (char *) &rbuf[nread], 1, 0); if (nr < 0) { - popup_a_sockerr(&h3270,"SOCKS5 Proxy: receive error"); + popup_a_sockerr(hSession,_("SOCKS5 Proxy: receive error")); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', rbuf, nread); + trace_netdata(hSession, '<', rbuf, nread); #endif /*]*/ return -1; } if (nr == 0) { - popup_a_sockerr(NULL,"SOCKS5 Proxy: unexpected EOF"); + popup_a_sockerr(hSession,_("SOCKS5 Proxy: unexpected EOF")); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', rbuf, nread); + trace_netdata(hSession, '<', rbuf, nread); #endif /*]*/ return -1; } @@ -787,21 +803,22 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) } #if defined(X3270_TRACE) /*[*/ - trace_netdata(&h3270, '<', rbuf, nread); + trace_netdata(hSession, '<', rbuf, nread); #endif /*]*/ if (rbuf[0] != 0x05 || (rbuf[1] != 0 && rbuf[1] != 0xff)) { - popup_an_error(&h3270,"SOCKS5 Proxy: bad authentication response"); + popup_an_error(hSession,_("SOCKS5 Proxy: bad authentication response")); return -1; } #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"SOCKS5 Proxy: recv version %d method %d\n", rbuf[0],rbuf[1]); + trace_dsn(hSession,"SOCKS5 Proxy: recv version %d method %d\n", rbuf[0],rbuf[1]); #endif /*]*/ - if (rbuf[1] == 0xff) { - popup_an_error(&h3270,"SOCKS5 Proxy: authentication failure"); + if (rbuf[1] == 0xff) + { + popup_an_error(hSession,_("SOCKS5 Proxy: authentication failure")); return -1; } @@ -832,16 +849,16 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) SET16(s, port); #if defined(X3270_TRACE) /*[*/ - trace_dsn(&h3270,"SOCKS5 Proxy: xmit version 5 connect %s %s port %u\n", + trace_dsn(hSession,"SOCKS5 Proxy: xmit version 5 connect %s %s port %u\n", use_name? "domainname": ((ha.sa.sa_family == AF_INET)? "IPv4": "IPv6"), use_name? host: nbuf, port); - trace_netdata(&h3270, '>', (unsigned char *)buf, s - buf); + trace_netdata(hSession, '>', (unsigned char *)buf, s - buf); #endif /*]*/ if (send(fd, buf, s - buf, 0) < 0) { - popup_a_sockerr(NULL,"SOCKS5 Proxy: send error"); + popup_a_sockerr(hSession,_("SOCKS5 Proxy: send error")); lib3270_free(buf); return -1; } @@ -855,8 +872,9 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) nread = 0; done = 0; buf = NULL; - while (!done) { - fd_set rfds; + while (!done) + { + fd_set rfds; struct timeval tv; unsigned char r; @@ -864,27 +882,28 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) FD_SET(fd, &rfds); tv.tv_sec = 15; tv.tv_usec = 0; - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) { - popup_an_error(NULL,"SOCKS5 Proxy: server timeout"); + if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) + { + popup_an_error(hSession,_("SOCKS5 Proxy: server timeout")); return -1; } nr = recv(fd, (char *) &r, 1, 0); if (nr < 0) { - popup_a_sockerr(NULL,"SOCKS5 Proxy: receive error"); + popup_a_sockerr(hSession,_("SOCKS5 Proxy: receive error")); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); #endif /*]*/ return -1; } if (nr == 0) { - popup_an_error(&h3270, "SOCKS5 Proxy: unexpected EOF"); + popup_an_error(hSession, _("SOCKS5 Proxy: unexpected EOF")); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); #endif /*]*/ return -1; } @@ -896,10 +915,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) case 0: if (r != 0x05) { - popup_an_error(&h3270, "SOCKS5 Proxy: incorrect reply version 0x%02x", r); + popup_an_error(hSession, _("SOCKS5 Proxy: incorrect reply version 0x%02x"), r); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); #endif /*]*/ return -1; } @@ -907,52 +926,49 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) case 1: #if defined(X3270_TRACE) /*[*/ if (r != 0x00) - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); #endif /*]*/ - switch (r) { + switch (r) + { case 0x00: - break; + break; case 0x01: - popup_an_error(&h3270, "SOCKS5 Proxy: server failure"); + popup_an_error(hSession, _("SOCKS5 Proxy: server failure")); return -1; case 0x02: - popup_an_error(&h3270, "SOCKS5 Proxy: connection not allowed"); + popup_an_error(hSession, _("SOCKS5 Proxy: connection not allowed")); return -1; case 0x03: - popup_an_error(NULL,"SOCKS5 Proxy: network " - "unreachable"); + popup_an_error(hSession, _("SOCKS5 Proxy: network unreachable")); return -1; case 0x04: - popup_an_error(NULL,"SOCKS5 Proxy: host " - "unreachable"); + popup_an_error(hSession, _("SOCKS5 Proxy: host unreachable")); return -1; case 0x05: - popup_an_error(NULL,"SOCKS5 Proxy: connection " - "refused"); + popup_an_error(hSession, _("SOCKS5 Proxy: connection refused")); return -1; case 0x06: - popup_an_error(NULL,"SOCKS5 Proxy: ttl expired"); + popup_an_error(hSession, _("SOCKS5 Proxy: ttl expired")); return -1; case 0x07: - popup_an_error(NULL,"SOCKS5 Proxy: command not " - "supported"); + popup_an_error(hSession, _("SOCKS5 Proxy: command not supported")); return -1; case 0x08: - popup_an_error(NULL,"SOCKS5 Proxy: address type " - "not supported"); + popup_an_error(hSession, _("SOCKS5 Proxy: address type not supported")); return -1; default: - popup_an_error(NULL,"SOCKS5 Proxy: unknown server " - "error 0x%02x", r); + popup_an_error(hSession, _("SOCKS5 Proxy: unknown server error 0x%02x"), r); return -1; } break; + case 2: break; case 3: - switch (r) { + switch (r) + { case 0x01: - n2read = 6; + n2read = 6; break; case 0x03: n2read = -1; @@ -963,10 +979,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) break; #endif /*]*/ default: - popup_an_error(&h3270, "SOCKS5 Proxy: unknown server address type 0x%02x", r); + popup_an_error(hSession, _("SOCKS5 Proxy: unknown server address type 0x%02x"), r); #if defined(X3270_TRACE) /*[*/ if (nread) - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); #endif /*]*/ return -1; } @@ -981,7 +997,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) } #if defined(X3270_TRACE) /*[*/ - trace_netdata(&h3270, '<', (unsigned char *)buf, nread); + trace_netdata(hSession, '<', (unsigned char *)buf, nread); switch (buf[3]) { case 0x01: /* IPv4 */ memcpy(&ha.sin.sin_addr, &buf[4], 4); @@ -1008,8 +1024,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) break; } rport = (*portp << 8) + *(portp + 1); - trace_dsn(&h3270,"SOCKS5 Proxy: recv version %d status 0x%02x address %s %s " - "port %u\n", + trace_dsn(hSession,"SOCKS5 Proxy: recv version %d status 0x%02x address %s %s port %u\n", buf[0], buf[1], atype_name[(unsigned char)buf[3]], nbuf, diff --git a/proxyc.h b/proxyc.h index c2c6094..605983c 100644 --- a/proxyc.h +++ b/proxyc.h @@ -17,6 +17,6 @@ * Declarations for proxy.c. */ -LIB3270_INTERNAL int proxy_setup(H3270 *session, char **phost, char **pport); -LIB3270_INTERNAL int proxy_negotiate(int type, int fd, char *host, unsigned short port); -LIB3270_INTERNAL char * proxy_type_name(int type); +LIB3270_INTERNAL int proxy_setup(H3270 *session, char **phost, char **pport); +LIB3270_INTERNAL int proxy_negotiate(H3270 *session, int type, int fd, char *host, unsigned short port); +LIB3270_INTERNAL const char * proxy_type_name(int type); diff --git a/sf.c b/sf.c index 244a315..b703901 100644 --- a/sf.c +++ b/sf.c @@ -79,7 +79,7 @@ int * char_height = &ch; /* Globals */ static Boolean sfont = False; -Boolean * standard_font = &sfont; +static Boolean * standard_font = &sfont; /* Statics */ diff --git a/telnet.c b/telnet.c index 9b5c52d..d805a43 100644 --- a/telnet.c +++ b/telnet.c @@ -812,68 +812,68 @@ static void setup_lus(H3270 *hSession) hSession->try_lu = *hSession->curr_lu; } -static void net_connected(H3270 *session) +static void net_connected(H3270 *hSession) { - if(session->proxy_type > 0) + if(hSession->proxy_type > 0) { /* Negotiate with the proxy. */ - trace_dsn(session,"Connected to proxy server %s, port %u.\n",session->proxy_host, session->proxy_port); + trace_dsn(hSession,"Connected to proxy server %s, port %u.\n",hSession->proxy_host, hSession->proxy_port); - if (proxy_negotiate(session->proxy_type, session->sock, session->hostname,session->current_port) < 0) + if (proxy_negotiate(hSession, hSession->proxy_type, hSession->sock, hSession->hostname,hSession->current_port) < 0) { - host_disconnect(session,True); + host_disconnect(hSession,True); return; } } - trace_dsn(session,"Connected to %s, port %u%s.\n", session->hostname, session->current_port,session->ssl_host? " via SSL": ""); + trace_dsn(hSession,"Connected to %s, port %u%s.\n", hSession->hostname, hSession->current_port,hSession->ssl_host? " via SSL": ""); #if defined(HAVE_LIBSSL) /*[*/ /* Set up SSL. */ - if(session->ssl_con && session->secure == LIB3270_SSL_UNDEFINED) + if(hSession->ssl_con && hSession->secure == LIB3270_SSL_UNDEFINED) { int rc; - set_ssl_state(session,LIB3270_SSL_NEGOTIATING); + set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING); - if (SSL_set_fd(session->ssl_con, session->sock) != 1) + if (SSL_set_fd(hSession->ssl_con, hSession->sock) != 1) { - trace_dsn(session,"Can't set fd!\n"); - popup_system_error(session,_( "Connection failed" ), _( "Can't set SSL socket file descriptor" ), "%s", SSL_state_string_long(session->ssl_con)); - set_ssl_state(session,LIB3270_SSL_UNSECURE); + trace_dsn(hSession,"Can't set fd!\n"); + popup_system_error(hSession,_( "Connection failed" ), _( "Can't set SSL socket file descriptor" ), "%s", SSL_state_string_long(hSession->ssl_con)); + set_ssl_state(hSession,LIB3270_SSL_UNSECURE); } else { - rc = SSL_connect(session->ssl_con); + rc = SSL_connect(hSession->ssl_con); if(rc != 1) { unsigned long e = ERR_get_error(); - const char * state = SSL_state_string_long(session->ssl_con); + const char * state = SSL_state_string_long(hSession->ssl_con); - trace_dsn(session,"TLS/SSL tunneled connection failed with error %ld, rc=%d and state=%s",e,rc,state); + trace_dsn(hSession,"TLS/SSL tunneled connection failed with error %ld, rc=%d and state=%s",e,rc,state); - host_disconnect(session,True); + host_disconnect(hSession,True); - if(e != session->last_ssl_error) + if(e != hSession->last_ssl_error) { - session->message(session,LIB3270_NOTIFY_ERROR,_( "Connection failed" ),_( "SSL negotiation failed" ),state); - session->last_ssl_error = e; + hSession->message(hSession,LIB3270_NOTIFY_ERROR,_( "Connection failed" ),_( "SSL negotiation failed" ),state); + hSession->last_ssl_error = e; } return; } } -// session->secure_connection = True; - trace_dsn(session,"TLS/SSL tunneled connection complete. Connection is now secure.\n"); +// hSession->secure_connection = True; + trace_dsn(hSession,"TLS/SSL tunneled connection complete. Connection is now secure.\n"); /* Tell everyone else again. */ - lib3270_set_connected(session); + lib3270_set_connected(hSession); } #endif /*]*/ - lib3270_setup_session(session); + lib3270_setup_session(hSession); } -- libgit2 0.21.2