Commit 4fd901ecbc84455db09a1d7b3f6e14abe555d566

Authored by Perry Werneck
1 parent ca836b43

Implementing windows connect.

@@ -228,6 +228,9 @@ @@ -228,6 +228,9 @@
228 <Unit filename="src/core/windows/connect.c"> 228 <Unit filename="src/core/windows/connect.c">
229 <Option compilerVar="CC" /> 229 <Option compilerVar="CC" />
230 </Unit> 230 </Unit>
  231 + <Unit filename="src/core/windows/download.c">
  232 + <Option compilerVar="CC" />
  233 + </Unit>
231 <Unit filename="src/core/windows/event_dispatcher.c"> 234 <Unit filename="src/core/windows/event_dispatcher.c">
232 <Option compilerVar="CC" /> 235 <Option compilerVar="CC" />
233 </Unit> 236 </Unit>
@@ -237,6 +240,7 @@ @@ -237,6 +240,7 @@
237 <Unit filename="src/core/windows/log.c"> 240 <Unit filename="src/core/windows/log.c">
238 <Option compilerVar="CC" /> 241 <Option compilerVar="CC" />
239 </Unit> 242 </Unit>
  243 + <Unit filename="src/core/windows/private.h" />
240 <Unit filename="src/core/windows/registry.c"> 244 <Unit filename="src/core/windows/registry.c">
241 <Option compilerVar="CC" /> 245 <Option compilerVar="CC" />
242 </Unit> 246 </Unit>
src/core/windows/connect.c
@@ -53,7 +53,13 @@ @@ -53,7 +53,13 @@
53 if(!connect(sock,address,address_len)) 53 if(!connect(sock,address,address_len))
54 return 0; 54 return 0;
55 55
56 - debug("WSAGetLastError=%d",(int) WSAGetLastError()); 56 + /*
  57 + if(WSAGetLastError() != WSAEINPROGRESS) {
  58 + debug("Can't connect WSAGetLastError=%d",(int) WSAGetLastError());
  59 + errno = ENOTCONN;
  60 + return -1;
  61 + }
  62 + */
57 63
58 unsigned int timer; 64 unsigned int timer;
59 for(timer = 0; timer < hSession->connection.timeout; timer += 10) { 65 for(timer = 0; timer < hSession->connection.timeout; timer += 10) {
@@ -64,7 +70,7 @@ @@ -64,7 +70,7 @@
64 struct timeval tm; 70 struct timeval tm;
65 71
66 tm.tv_sec = 0; 72 tm.tv_sec = 0;
67 - tm.tv_usec = 10; 73 + tm.tv_usec = 10000;
68 74
69 fd_set wfds; 75 fd_set wfds;
70 FD_ZERO(&wfds); 76 FD_ZERO(&wfds);
@@ -81,6 +87,7 @@ @@ -81,6 +87,7 @@
81 87
82 } 88 }
83 89
  90 + debug("Timeout! WSAGetLastError=%d",(int) WSAGetLastError());
84 return errno = ETIMEDOUT; 91 return errno = ETIMEDOUT;
85 92
86 } 93 }
@@ -173,6 +180,10 @@ @@ -173,6 +180,10 @@
173 if(sock_connect(hSession, sock, rp->ai_addr, rp->ai_addrlen)) 180 if(sock_connect(hSession, sock, rp->ai_addr, rp->ai_addrlen))
174 { 181 {
175 // Can't connect to host 182 // Can't connect to host
  183 + state->winerror = WSAGetLastError();
  184 + if(state->winerror == WSAEWOULDBLOCK) {
  185 + state->winerror = 0;
  186 + }
176 state->syserror = errno; 187 state->syserror = errno;
177 closesocket(sock); 188 closesocket(sock);
178 sock = -1; 189 sock = -1;
@@ -286,20 +297,45 @@ @@ -286,20 +297,45 @@
286 } 297 }
287 298
288 lib3270_autoptr(char) syserror = NULL; 299 lib3270_autoptr(char) syserror = NULL;
289 - if(state.syserror) 300 +
  301 +#ifdef _WIN32
  302 + if(state.winerror)
290 { 303 {
291 syserror = lib3270_strdup_printf( 304 syserror = lib3270_strdup_printf(
  305 + _("The system error was \"%s\""),
  306 + lib3270_win32_strerror(state.winerror)
  307 + );
  308 + } else if(state.syserror == ETIMEDOUT) {
  309 +
  310 + syserror = lib3270_strdup_printf(
  311 + _("The system error was \"%s\" (rc=%d)"),
  312 + _("Timeout conneting to host"),
  313 + state.syserror
  314 + );
  315 +
  316 + } else if(state.syserror == ENOTCONN) {
  317 +
  318 + syserror = lib3270_strdup_printf(
  319 + _("The system error was \"%s\" (rc=%d)"),
  320 + _("Not connected to host"),
  321 + state.syserror
  322 + );
  323 +
  324 + } else if(state.syserror) {
  325 + syserror = lib3270_strdup_printf(
292 _("The system error was \"%s\" (rc=%d)"), 326 _("The system error was \"%s\" (rc=%d)"),
293 strerror(state.syserror), 327 strerror(state.syserror),
294 state.syserror 328 state.syserror
295 ); 329 );
296 } 330 }
297 -#ifdef _WIN32  
298 - else if(state.winerror) 331 +
  332 +#else
  333 + if(state.syserror)
299 { 334 {
300 syserror = lib3270_strdup_printf( 335 syserror = lib3270_strdup_printf(
301 - _("The system error was \"%s\""),  
302 - lib3270_win32_strerror(WSAGetLastError()) 336 + _("The system error was \"%s\" (rc=%d)"),
  337 + strerror(state.syserror),
  338 + state.syserror
303 ); 339 );
304 } 340 }
305 #endif // _WIN32 341 #endif // _WIN32
src/core/windows/download.c 0 → 100644
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  1 +/*
  2 + * "Software pw3270, 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 - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +#include "private.h"
  31 +#include <utilc.h>
  32 +
  33 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  34 +
  35 + char * lib3270_url_get(H3270 *hSession, const char *u, const char **error) {
  36 +
  37 + lib3270_autoptr(char) url = lib3270_unescape(u);
  38 +
  39 + if(strncasecmp(url,"file://",7) == 0) {
  40 +
  41 + // Load local file contents.
  42 + char *rc = lib3270_file_get_contents(hSession,url+7);
  43 + if(!rc)
  44 + *error = strerror(errno);
  45 + return rc;
  46 + }
  47 +
  48 + if(strncasecmp(url,"http://",7) == 0 || strncasecmp(url,"https://",8)) {
  49 +
  50 + // Use WinHTTP
  51 + return lib3270_url_get_using_http(hSession, url, error);
  52 +
  53 + }
  54 +
  55 +#if defined(HAVE_LIBCURL)
  56 +
  57 + return lib3270_url_get_using_curl(hSession,url,error);
  58 +
  59 +#else
  60 +
  61 + // Can't get contents
  62 + *error = _("No handler for URL scheme.");
  63 + errno = EINVAL;
  64 + return NULL;
  65 +
  66 +
  67 +#endif // HAVE_LIBCURL
  68 +
  69 +
  70 + }
src/core/windows/http.c
@@ -52,7 +52,7 @@ static void lib3270_autoptr_cleanup_HINTERNET(HINTERNET **hInternet) @@ -52,7 +52,7 @@ static void lib3270_autoptr_cleanup_HINTERNET(HINTERNET **hInternet)
52 *hInternet = 0; 52 *hInternet = 0;
53 } 53 }
54 54
55 -char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, const char **error_message) 55 +char * lib3270_url_get_using_http(H3270 *hSession, const char *url, const char **error_message)
56 { 56 {
57 wchar_t wHostname[4096]; 57 wchar_t wHostname[4096];
58 wchar_t wPath[4096]; 58 wchar_t wPath[4096];
@@ -185,8 +185,6 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co @@ -185,8 +185,6 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co
185 return NULL; 185 return NULL;
186 } 186 }
187 187
188 - if(length)  
189 - *length = (size_t) szResponse;  
190 188
191 lib3270_write_nettrace(hSession,"Got %u bytes from %s\n",(unsigned int) szResponse, url); 189 lib3270_write_nettrace(hSession,"Got %u bytes from %s\n",(unsigned int) szResponse, url);
192 190
src/core/windows/private.h 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  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 ', 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 private.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça)
  27 + *
  28 + */
  29 +
  30 +#ifndef PRIVATE_H_INCLUDED
  31 +
  32 + #define PRIVATE_H_INCLUDED
  33 +
  34 + #include <config.h>
  35 +
  36 + #include <winsock2.h>
  37 + #include <windows.h>
  38 +
  39 + #include <internals.h>
  40 +
  41 + #include <lib3270.h>
  42 + #include <lib3270/log.h>
  43 +
  44 + LIB3270_INTERNAL char * lib3270_url_get_using_ldap(H3270 *hSession, const char *u, const char **error);
  45 + LIB3270_INTERNAL char * lib3270_url_get_using_http(H3270 *hSession, const char *url, const char **error);
  46 +
  47 +
  48 +#endif // !PRIVATE_H_INCLUDED
src/include/internals.h
@@ -902,3 +902,9 @@ LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state); @@ -902,3 +902,9 @@ LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state);
902 */ 902 */
903 LIB3270_INTERNAL X509_CRL * lib3270_crl_get_using_ldap(H3270 *hSession, const char *url, const char **error); 903 LIB3270_INTERNAL X509_CRL * lib3270_crl_get_using_ldap(H3270 *hSession, const char *url, const char **error);
904 #endif // HAVE_LDAP 904 #endif // HAVE_LDAP
  905 +
  906 +#ifdef _WIN32
  907 +
  908 + LIB3270_INTERNAL char * lib3270_get_from_url(H3270 *hSession, const char *url, const char **error_message);
  909 +
  910 +#endif // _WIN32