Commit d546495b31037a979a687f153981c139e86648c2
1 parent
ed32cc59
Exists in
master
and in
5 other branches
Incluindo mecanismo que permita a jni android substituir todo o I/O de rede por funções próprias
Showing
5 changed files
with
124 additions
and
115 deletions
Show diff stats
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +/* | ||
2 | + * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como internals.h e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * | ||
27 | + */ | ||
28 | + | ||
29 | +#ifndef LIB3270_INTERNALS_H_INCLUDED | ||
30 | + | ||
31 | + #define LIB3270_INTERNALS_H_INCLUDED 1 | ||
32 | + | ||
33 | +#ifdef __cplusplus | ||
34 | + extern "C" { | ||
35 | +#endif | ||
36 | + | ||
37 | + LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf); | ||
38 | + | ||
39 | +#ifdef __cplusplus | ||
40 | + } | ||
41 | +#endif | ||
42 | + | ||
43 | +#endif // LIB3270_HTML_H_INCLUDED | ||
44 | + |
src/include/lib3270/session.h
@@ -227,7 +227,7 @@ | @@ -227,7 +227,7 @@ | ||
227 | unsigned char * ibptr; | 227 | unsigned char * ibptr; |
228 | unsigned char * obuf_base; | 228 | unsigned char * obuf_base; |
229 | int obuf_size; | 229 | int obuf_size; |
230 | - unsigned char * netrbuf; | 230 | +// unsigned char * netrbuf; |
231 | 231 | ||
232 | // network input buffer | 232 | // network input buffer |
233 | unsigned char * sbbuf; | 233 | unsigned char * sbbuf; |
@@ -264,7 +264,7 @@ | @@ -264,7 +264,7 @@ | ||
264 | int reading : 1; | 264 | int reading : 1; |
265 | int excepting : 1; | 265 | int excepting : 1; |
266 | 266 | ||
267 | - // SSL Data (Always defined to mantain the same structure size | 267 | + // SSL Data (Always defined to mantain the same structure size) |
268 | unsigned long last_ssl_error; | 268 | unsigned long last_ssl_error; |
269 | SSL * ssl_con; | 269 | SSL * ssl_con; |
270 | 270 | ||
@@ -273,6 +273,8 @@ | @@ -273,6 +273,8 @@ | ||
273 | struct lib3270_state_callback *st_last[LIB3270_STATE_USER]; | 273 | struct lib3270_state_callback *st_last[LIB3270_STATE_USER]; |
274 | 274 | ||
275 | // Session based callbacks | 275 | // Session based callbacks |
276 | + int (*write)(H3270 *hSession, unsigned const char *buf, int len); | ||
277 | + | ||
276 | void (*configure)(H3270 *session, unsigned short rows, unsigned short cols); | 278 | void (*configure)(H3270 *session, unsigned short rows, unsigned short cols); |
277 | void (*update)(H3270 *session, int baddr, unsigned char c, unsigned short attr, unsigned char cursor); | 279 | void (*update)(H3270 *session, int baddr, unsigned char c, unsigned short attr, unsigned char cursor); |
278 | void (*changed)(H3270 *session, int offset, int len); | 280 | void (*changed)(H3270 *session, int offset, int len); |
src/lib3270/globals.h
@@ -352,5 +352,6 @@ LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); | @@ -352,5 +352,6 @@ LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); | ||
352 | // LIB3270_INTERNAL void add_input_calls(H3270 *, void (*)(H3270 *), void (*)(H3270 *)); | 352 | // LIB3270_INTERNAL void add_input_calls(H3270 *, void (*)(H3270 *), void (*)(H3270 *)); |
353 | 353 | ||
354 | LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); | 354 | LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); |
355 | - | ||
356 | LIB3270_INTERNAL void remove_input_calls(H3270 *session); | 355 | LIB3270_INTERNAL void remove_input_calls(H3270 *session); |
356 | + | ||
357 | +LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len); |
src/lib3270/session.c
@@ -167,6 +167,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | @@ -167,6 +167,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | ||
167 | hSession->sz = sizeof(H3270); | 167 | hSession->sz = sizeof(H3270); |
168 | 168 | ||
169 | // Default calls | 169 | // Default calls |
170 | + hSession->write = lib3270_send; | ||
170 | hSession->update = update_char; | 171 | hSession->update = update_char; |
171 | hSession->update_model = update_model; | 172 | hSession->update_model = update_model; |
172 | hSession->update_cursor = update_cursor; | 173 | hSession->update_cursor = update_cursor; |
src/lib3270/telnet.c
@@ -102,6 +102,8 @@ | @@ -102,6 +102,8 @@ | ||
102 | #include "xioc.h" | 102 | #include "xioc.h" |
103 | #include "screen.h" | 103 | #include "screen.h" |
104 | 104 | ||
105 | +#include <lib3270/internals.h> | ||
106 | + | ||
105 | #if !defined(TELOPT_NAWS) /*[*/ | 107 | #if !defined(TELOPT_NAWS) /*[*/ |
106 | #define TELOPT_NAWS 31 | 108 | #define TELOPT_NAWS 31 |
107 | #endif /*]*/ | 109 | #endif /*]*/ |
@@ -519,8 +521,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -519,8 +521,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
519 | sockstart(session); | 521 | sockstart(session); |
520 | #endif | 522 | #endif |
521 | 523 | ||
522 | - if (session->netrbuf == (unsigned char *)NULL) | ||
523 | - session->netrbuf = (unsigned char *)lib3270_malloc(BUFSZ); | 524 | +// if (session->netrbuf == (unsigned char *)NULL) |
525 | +// session->netrbuf = (unsigned char *)lib3270_malloc(BUFSZ); | ||
524 | 526 | ||
525 | #if defined(X3270_ANSI) /*[*/ | 527 | #if defined(X3270_ANSI) /*[*/ |
526 | if (!t_valid) | 528 | if (!t_valid) |
@@ -965,7 +967,6 @@ void net_disconnect(H3270 *session) | @@ -965,7 +967,6 @@ void net_disconnect(H3270 *session) | ||
965 | 967 | ||
966 | } | 968 | } |
967 | 969 | ||
968 | - | ||
969 | LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf) | 970 | LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf) |
970 | { | 971 | { |
971 | register const unsigned char * cp; | 972 | register const unsigned char * cp; |
@@ -1989,131 +1990,91 @@ void net_exception(H3270 *session) | @@ -1989,131 +1990,91 @@ void net_exception(H3270 *session) | ||
1989 | * | 1990 | * |
1990 | */ | 1991 | */ |
1991 | 1992 | ||
1992 | - | ||
1993 | -/* | ||
1994 | - * net_rawout | ||
1995 | - * Send out raw telnet data. We assume that there will always be enough | ||
1996 | - * space to buffer what we want to transmit, so we don't handle EAGAIN or | ||
1997 | - * EWOULDBLOCK. | ||
1998 | - */ | ||
1999 | -static void | ||
2000 | -net_rawout(H3270 *session, unsigned const char *buf, int len) | 1993 | +LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len) |
2001 | { | 1994 | { |
2002 | - int nw; | 1995 | + int rc; |
2003 | 1996 | ||
2004 | - trace_netdata('>', buf, len); | 1997 | +#if defined(HAVE_LIBSSL) |
1998 | + if(hSession->ssl_con != NULL) | ||
1999 | + rc = SSL_write(hSession->ssl_con, (const char *) buf, len); | ||
2000 | + else | ||
2001 | + rc = send(hSession->sock, (const char *) buf, len, 0); | ||
2002 | +#else | ||
2003 | + rc = send(hSession->sock, (const char *) buf, len, 0); | ||
2004 | +#endif // HAVE_LIBSSL | ||
2005 | 2005 | ||
2006 | - while (len) { | ||
2007 | -#if defined(OMTU) /*[*/ | ||
2008 | - int n2w = len; | ||
2009 | - int pause = 0; | 2006 | + if(rc > 0) |
2007 | + return rc; | ||
2010 | 2008 | ||
2011 | - if (n2w > OMTU) { | ||
2012 | - n2w = OMTU; | ||
2013 | - pause = 1; | ||
2014 | - } | ||
2015 | -#else | ||
2016 | -# define n2w len | ||
2017 | -#endif | ||
2018 | -#if defined(HAVE_LIBSSL) /*[*/ | ||
2019 | - if(session->ssl_con != NULL) | ||
2020 | - nw = SSL_write(session->ssl_con, (const char *) buf, n2w); | ||
2021 | - else | ||
2022 | -#endif /*]*/ | 2009 | + // Recv error, notify |
2023 | 2010 | ||
2024 | -/* | ||
2025 | -#if defined(LOCAL_PROCESS) | ||
2026 | - if (local_process) | ||
2027 | - nw = write(sock, (const char *) buf, n2w); | ||
2028 | - else | ||
2029 | -#endif | ||
2030 | -*/ | ||
2031 | - nw = send(session->sock, (const char *) buf, n2w, 0); | ||
2032 | - if (nw < 0) { | ||
2033 | -#if defined(HAVE_LIBSSL) /*[*/ | ||
2034 | - if (session->ssl_con != NULL) | ||
2035 | - { | ||
2036 | - unsigned long e; | ||
2037 | - char err_buf[120]; | 2011 | +#if defined(HAVE_LIBSSL) |
2012 | + if(hSession->ssl_con != NULL) | ||
2013 | + { | ||
2014 | + unsigned long e; | ||
2015 | + char err_buf[120]; | ||
2038 | 2016 | ||
2039 | - e = ERR_get_error(); | ||
2040 | - (void) ERR_error_string(e, err_buf); | ||
2041 | - trace_dsn("RCVD SSL_write error %ld (%s)\n", e,err_buf); | ||
2042 | - popup_an_error(NULL,"SSL_write:\n%s", err_buf); | ||
2043 | - host_disconnect(session,False); | ||
2044 | - return; | ||
2045 | - } | ||
2046 | -#endif /*]*/ | ||
2047 | - trace_dsn("RCVD socket error %d\n", errno); | ||
2048 | - if (socket_errno() == SE_EPIPE || socket_errno() == SE_ECONNRESET) { | ||
2049 | - host_disconnect(session,False); | ||
2050 | - return; | ||
2051 | - } else if (socket_errno() == SE_EINTR) { | ||
2052 | - goto bot; | ||
2053 | - } else { | ||
2054 | - popup_a_sockerr(NULL, N_( "Socket write error" ) ); | ||
2055 | - host_disconnect(session,True); | ||
2056 | - return; | ||
2057 | - } | ||
2058 | - } | ||
2059 | - session->ns_bsent += nw; | ||
2060 | - len -= nw; | ||
2061 | - buf += nw; | ||
2062 | - bot: | ||
2063 | -#if defined(OMTU) | ||
2064 | - if (pause) | ||
2065 | - sleep(1); | ||
2066 | -#endif | ||
2067 | - ; | 2017 | + e = ERR_get_error(); |
2018 | + (void) ERR_error_string(e, err_buf); | ||
2019 | + trace_dsn("RCVD SSL_write error %ld (%s)\n", e,err_buf); | ||
2020 | + popup_an_error(hSession,_( "SSL_write:\n%s" ), err_buf); | ||
2021 | + return -1; | ||
2068 | } | 2022 | } |
2069 | -} | 2023 | +#endif // HAVE_LIBSSL |
2070 | 2024 | ||
2071 | - | ||
2072 | -#if defined(X3270_ANSI) /*[*/ | ||
2073 | -/* | ||
2074 | - * net_hexansi_out | ||
2075 | - * Send uncontrolled user data to the host in ANSI mode, performing IAC | ||
2076 | - * and CR quoting as necessary. | ||
2077 | - */ /* | ||
2078 | -void | ||
2079 | -net_hexansi_out(unsigned char *buf, int len) | ||
2080 | -{ | ||
2081 | - unsigned char *tbuf; | ||
2082 | - unsigned char *xbuf; | 2025 | + trace_dsn("RCVD socket error %d\n", socket_errno()); |
2083 | 2026 | ||
2084 | - if (!len) | ||
2085 | - return; | 2027 | + switch(socket_errno()) |
2028 | + { | ||
2029 | + case SE_EPIPE: | ||
2030 | + popup_an_error(hSession, "%s", N_( "Broken pipe" )); | ||
2031 | + break; | ||
2086 | 2032 | ||
2087 | -#if defined(X3270_TRACE) | ||
2088 | - // Trace the data. | ||
2089 | - if (lib3270_get_toggle(&h3270,LIB3270_TOGGLE_DS_TRACE)) { | ||
2090 | - int i; | 2033 | + case SE_ECONNRESET: |
2034 | + popup_an_error(hSession, "%s", N_( "Connection reset by peer" )); | ||
2035 | + break; | ||
2091 | 2036 | ||
2092 | - trace_dsn(">"); | ||
2093 | - for (i = 0; i < len; i++) | ||
2094 | - trace_dsn(" %s", ctl_see((int) *(buf+i))); | ||
2095 | - trace_dsn("\n"); | ||
2096 | - } | ||
2097 | -#endif | 2037 | + case SE_EINTR: |
2038 | + return 0; | ||
2098 | 2039 | ||
2099 | - // Expand it | ||
2100 | - tbuf = xbuf = (unsigned char *)lib3270_malloc(2*len); | ||
2101 | - while (len) { | ||
2102 | - unsigned char c = *buf++; | 2040 | + default: |
2041 | + popup_a_sockerr(NULL, "%s", N_( "Socket write error" ) ); | ||
2103 | 2042 | ||
2104 | - *tbuf++ = c; | ||
2105 | - len--; | ||
2106 | - if (c == IAC) | ||
2107 | - *tbuf++ = IAC; | ||
2108 | - else if (c == '\r' && (!len || *buf != '\n')) | ||
2109 | - *tbuf++ = '\0'; | ||
2110 | } | 2043 | } |
2111 | 2044 | ||
2112 | - // Send it to the host | ||
2113 | - net_rawout(&h3270,xbuf, tbuf - xbuf); | ||
2114 | - lib3270_free(xbuf); | 2045 | + return -1; |
2115 | } | 2046 | } |
2116 | -*/ | 2047 | + |
2048 | +/* | ||
2049 | + * net_rawout | ||
2050 | + * Send out raw telnet data. We assume that there will always be enough | ||
2051 | + * space to buffer what we want to transmit, so we don't handle EAGAIN or | ||
2052 | + * EWOULDBLOCK. | ||
2053 | + */ | ||
2054 | +static void net_rawout(H3270 *hSession, unsigned const char *buf, int len) | ||
2055 | +{ | ||
2056 | + trace_netdata('>', buf, len); | ||
2057 | + | ||
2058 | + while (len) | ||
2059 | + { | ||
2060 | + int nw = hSession->write(hSession,buf,len); | ||
2061 | + | ||
2062 | + if (nw > 0) | ||
2063 | + { | ||
2064 | + // Data received | ||
2065 | + hSession->ns_bsent += nw; | ||
2066 | + len -= nw; | ||
2067 | + buf += nw; | ||
2068 | + } | ||
2069 | + else if(nw < 0) | ||
2070 | + { | ||
2071 | + host_disconnect(hSession,True); | ||
2072 | + return; | ||
2073 | + } | ||
2074 | + } | ||
2075 | +} | ||
2076 | + | ||
2077 | +#if defined(X3270_ANSI) | ||
2117 | 2078 | ||
2118 | /* | 2079 | /* |
2119 | * net_cookedout | 2080 | * net_cookedout |