diff --git a/lib3270.cbp b/lib3270.cbp index 5a3de9c..23d23e6 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -228,6 +228,9 @@ + + @@ -237,6 +240,7 @@ + diff --git a/src/core/windows/connect.c b/src/core/windows/connect.c index 6c4aedb..934e61f 100644 --- a/src/core/windows/connect.c +++ b/src/core/windows/connect.c @@ -53,7 +53,13 @@ if(!connect(sock,address,address_len)) return 0; - debug("WSAGetLastError=%d",(int) WSAGetLastError()); + /* + if(WSAGetLastError() != WSAEINPROGRESS) { + debug("Can't connect WSAGetLastError=%d",(int) WSAGetLastError()); + errno = ENOTCONN; + return -1; + } + */ unsigned int timer; for(timer = 0; timer < hSession->connection.timeout; timer += 10) { @@ -64,7 +70,7 @@ struct timeval tm; tm.tv_sec = 0; - tm.tv_usec = 10; + tm.tv_usec = 10000; fd_set wfds; FD_ZERO(&wfds); @@ -81,6 +87,7 @@ } + debug("Timeout! WSAGetLastError=%d",(int) WSAGetLastError()); return errno = ETIMEDOUT; } @@ -173,6 +180,10 @@ if(sock_connect(hSession, sock, rp->ai_addr, rp->ai_addrlen)) { // Can't connect to host + state->winerror = WSAGetLastError(); + if(state->winerror == WSAEWOULDBLOCK) { + state->winerror = 0; + } state->syserror = errno; closesocket(sock); sock = -1; @@ -286,20 +297,45 @@ } lib3270_autoptr(char) syserror = NULL; - if(state.syserror) + +#ifdef _WIN32 + if(state.winerror) { syserror = lib3270_strdup_printf( + _("The system error was \"%s\""), + lib3270_win32_strerror(state.winerror) + ); + } else if(state.syserror == ETIMEDOUT) { + + syserror = lib3270_strdup_printf( + _("The system error was \"%s\" (rc=%d)"), + _("Timeout conneting to host"), + state.syserror + ); + + } else if(state.syserror == ENOTCONN) { + + syserror = lib3270_strdup_printf( + _("The system error was \"%s\" (rc=%d)"), + _("Not connected to host"), + state.syserror + ); + + } else if(state.syserror) { + syserror = lib3270_strdup_printf( _("The system error was \"%s\" (rc=%d)"), strerror(state.syserror), state.syserror ); } -#ifdef _WIN32 - else if(state.winerror) + +#else + if(state.syserror) { syserror = lib3270_strdup_printf( - _("The system error was \"%s\""), - lib3270_win32_strerror(WSAGetLastError()) + _("The system error was \"%s\" (rc=%d)"), + strerror(state.syserror), + state.syserror ); } #endif // _WIN32 diff --git a/src/core/windows/download.c b/src/core/windows/download.c new file mode 100644 index 0000000..9849020 --- /dev/null +++ b/src/core/windows/download.c @@ -0,0 +1,70 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include "private.h" +#include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + char * lib3270_url_get(H3270 *hSession, const char *u, const char **error) { + + lib3270_autoptr(char) url = lib3270_unescape(u); + + if(strncasecmp(url,"file://",7) == 0) { + + // Load local file contents. + char *rc = lib3270_file_get_contents(hSession,url+7); + if(!rc) + *error = strerror(errno); + return rc; + } + + if(strncasecmp(url,"http://",7) == 0 || strncasecmp(url,"https://",8)) { + + // Use WinHTTP + return lib3270_url_get_using_http(hSession, url, error); + + } + +#if defined(HAVE_LIBCURL) + + return lib3270_url_get_using_curl(hSession,url,error); + +#else + + // Can't get contents + *error = _("No handler for URL scheme."); + errno = EINVAL; + return NULL; + + +#endif // HAVE_LIBCURL + + + } diff --git a/src/core/windows/http.c b/src/core/windows/http.c index a206359..9afb856 100644 --- a/src/core/windows/http.c +++ b/src/core/windows/http.c @@ -52,7 +52,7 @@ static void lib3270_autoptr_cleanup_HINTERNET(HINTERNET **hInternet) *hInternet = 0; } -char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, const char **error_message) +char * lib3270_url_get_using_http(H3270 *hSession, const char *url, const char **error_message) { wchar_t wHostname[4096]; wchar_t wPath[4096]; @@ -185,8 +185,6 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co return NULL; } - if(length) - *length = (size_t) szResponse; lib3270_write_nettrace(hSession,"Got %u bytes from %s\n",(unsigned int) szResponse, url); diff --git a/src/core/windows/private.h b/src/core/windows/private.h new file mode 100644 index 0000000..c5713e7 --- /dev/null +++ b/src/core/windows/private.h @@ -0,0 +1,48 @@ +/* + * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como private.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) + * + */ + +#ifndef PRIVATE_H_INCLUDED + + #define PRIVATE_H_INCLUDED + + #include + + #include + #include + + #include + + #include + #include + + LIB3270_INTERNAL char * lib3270_url_get_using_ldap(H3270 *hSession, const char *u, const char **error); + LIB3270_INTERNAL char * lib3270_url_get_using_http(H3270 *hSession, const char *url, const char **error); + + +#endif // !PRIVATE_H_INCLUDED diff --git a/src/include/internals.h b/src/include/internals.h index 7d95aa8..afa2dbc 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -902,3 +902,9 @@ LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state); */ LIB3270_INTERNAL X509_CRL * lib3270_crl_get_using_ldap(H3270 *hSession, const char *url, const char **error); #endif // HAVE_LDAP + +#ifdef _WIN32 + + LIB3270_INTERNAL char * lib3270_get_from_url(H3270 *hSession, const char *url, const char **error_message); + +#endif // _WIN32 -- libgit2 0.21.2