Commit 23867c9ef5921a986f4bf93f4e0c1cb96123abdf
1 parent
25a75bde
Exists in
master
and in
5 other branches
Implementando novo mecanismo de conexão
Showing
8 changed files
with
101 additions
and
75 deletions
Show diff stats
src/include/lib3270/session.h
src/lib3270/connect.c
| ... | ... | @@ -59,6 +59,7 @@ |
| 59 | 59 | #include "hostc.h" |
| 60 | 60 | #include "trace_dsc.h" |
| 61 | 61 | #include "utilc.h" |
| 62 | +#include "telnetc.h" | |
| 62 | 63 | #include <lib3270/internals.h> |
| 63 | 64 | |
| 64 | 65 | /*---[ Implement ]-------------------------------------------------------------------------------*/ |
| ... | ... | @@ -66,7 +67,30 @@ |
| 66 | 67 | |
| 67 | 68 | static void net_connected(H3270 *hSession) |
| 68 | 69 | { |
| 69 | - trace("***************** %s",__FUNCTION__); | |
| 70 | + RemoveSource(hSession->ns_write_id); | |
| 71 | + hSession->ns_write_id = NULL; | |
| 72 | + | |
| 73 | +#ifdef _WIN32 | |
| 74 | + hSession->ns_exception_id = AddExcept(hSession->sockEvent, hSession, net_exception); | |
| 75 | + hSession->ns_read_id = AddInput(hSession->sockEvent, hSession, net_input); | |
| 76 | +#else | |
| 77 | + hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); | |
| 78 | + hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); | |
| 79 | +#endif // WIN32 | |
| 80 | + hSession->excepting = 1; | |
| 81 | + hSession->reading = 1; | |
| 82 | + | |
| 83 | +/* | |
| 84 | +#if defined(HAVE_LIBSSL) | |
| 85 | + if(hSession->ssl_con && hSession->secure == LIB3270_SSL_UNDEFINED) | |
| 86 | + { | |
| 87 | + if(ssl_negotiate(hSession)) | |
| 88 | + return; | |
| 89 | + } | |
| 90 | +#endif | |
| 91 | +*/ | |
| 92 | + | |
| 93 | + lib3270_setup_session(hSession); | |
| 70 | 94 | |
| 71 | 95 | } |
| 72 | 96 | |
| ... | ... | @@ -120,7 +144,6 @@ static void net_connected(H3270 *hSession) |
| 120 | 144 | LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc) |
| 121 | 145 | { |
| 122 | 146 | int s; |
| 123 | - int sock = -1; | |
| 124 | 147 | struct addrinfo hints; |
| 125 | 148 | struct addrinfo * result = NULL; |
| 126 | 149 | struct addrinfo * rp = NULL; |
| ... | ... | @@ -138,7 +161,7 @@ static void net_connected(H3270 *hSession) |
| 138 | 161 | if(hSession->auto_reconnect_inprogress) |
| 139 | 162 | return EAGAIN; |
| 140 | 163 | |
| 141 | - if(PCONNECTED) | |
| 164 | + if(hSession->sock > 0) | |
| 142 | 165 | return EBUSY; |
| 143 | 166 | |
| 144 | 167 | #if defined(_WIN32) |
| ... | ... | @@ -194,7 +217,7 @@ static void net_connected(H3270 *hSession) |
| 194 | 217 | |
| 195 | 218 | status_changed(hSession,LIB3270_STATUS_CONNECTING); |
| 196 | 219 | |
| 197 | - for(rp = result; sock < 0 && rp != NULL; rp = rp->ai_next) | |
| 220 | + for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next) | |
| 198 | 221 | { |
| 199 | 222 | hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
| 200 | 223 | if(hSession->sock < 0) |
| ... | ... | @@ -204,6 +227,36 @@ static void net_connected(H3270 *hSession) |
| 204 | 227 | u_long block; |
| 205 | 228 | u_int len = sizeof(int); |
| 206 | 229 | |
| 230 | + if(session->sockEvent == NULL) | |
| 231 | + { | |
| 232 | + char ename[256]; | |
| 233 | + | |
| 234 | + snprintf(ename, 255, "%s-%d", PACKAGE_NAME, getpid()); | |
| 235 | + | |
| 236 | + session->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename); | |
| 237 | + if(session->sockEvent == NULL) | |
| 238 | + { | |
| 239 | + lib3270_popup_dialog( session, | |
| 240 | + LIB3270_NOTIFY_CRITICAL, | |
| 241 | + N_( "Network startup error" ), | |
| 242 | + N_( "Cannot create socket handle" ), | |
| 243 | + "%s", win32_strerror(GetLastError()) ); | |
| 244 | + _exit(1); | |
| 245 | + } | |
| 246 | + } | |
| 247 | + | |
| 248 | + if (WSAEventSelect(session->sock, session->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0) | |
| 249 | + { | |
| 250 | + lib3270_popup_dialog( session, | |
| 251 | + LIB3270_NOTIFY_CRITICAL, | |
| 252 | + N_( "Network startup error" ), | |
| 253 | + N_( "WSAEventSelect failed" ), | |
| 254 | + "%s", win32_strerror(GetLastError()) ); | |
| 255 | + _exit(1); | |
| 256 | + } | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 207 | 260 | WSASetLastError(0); |
| 208 | 261 | block = 0; |
| 209 | 262 | |
| ... | ... | @@ -213,8 +266,7 @@ static void net_connected(H3270 *hSession) |
| 213 | 266 | LIB3270_NOTIFY_ERROR, |
| 214 | 267 | _( "Connection error" ), |
| 215 | 268 | _( "ioctlsocket(FIONBIO) failed." ), |
| 216 | - "Windows error %d", | |
| 217 | - WSAGetLastError() ); | |
| 269 | + "%s", win32_strerror(GetLastError())); | |
| 218 | 270 | |
| 219 | 271 | SOCK_CLOSE(hSession); |
| 220 | 272 | } |
| ... | ... | @@ -227,14 +279,13 @@ static void net_connected(H3270 *hSession) |
| 227 | 279 | LIB3270_NOTIFY_ERROR, |
| 228 | 280 | _( "Connection error" ), |
| 229 | 281 | _( "Can't connect to host." ), |
| 230 | - "Windows error %d", | |
| 231 | - WSAGetLastError() ); | |
| 282 | + "%s", win32_strerror(GetLastError())); | |
| 232 | 283 | SOCK_CLOSE(hSession); |
| 233 | 284 | } |
| 234 | 285 | } |
| 235 | 286 | |
| 236 | 287 | #else |
| 237 | - fcntl(hSession->sock, F_SETFL,fcntl(sock,F_GETFL,0)|O_NONBLOCK); | |
| 288 | + fcntl(hSession->sock, F_SETFL,fcntl(hSession->sock,F_GETFL,0)|O_NONBLOCK); | |
| 238 | 289 | |
| 239 | 290 | errno = 0; |
| 240 | 291 | if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen)) |
| ... | ... | @@ -288,11 +339,13 @@ static void net_connected(H3270 *hSession) |
| 288 | 339 | #endif |
| 289 | 340 | |
| 290 | 341 | // Connecting, set callbacks, wait for connection |
| 291 | - trace_dsn(hSession,"Half-connected.\n"); | |
| 292 | - | |
| 293 | 342 | lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True); |
| 294 | 343 | |
| 344 | +#ifdef _WIN32 | |
| 345 | + hSession->ns_write_id = AddOutput(hSession->sockEvent, hSession, net_connected); | |
| 346 | +#else | |
| 295 | 347 | hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected); |
| 348 | +#endif // WIN32 | |
| 296 | 349 | |
| 297 | 350 | return 0; |
| 298 | 351 | ... | ... |
src/lib3270/globals.h
| ... | ... | @@ -357,3 +357,4 @@ LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); |
| 357 | 357 | LIB3270_INTERNAL void check_session_handle(H3270 **hSession); |
| 358 | 358 | #endif // DEBUG |
| 359 | 359 | |
| 360 | +LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc); | ... | ... |
src/lib3270/iocalls.c
| ... | ... | @@ -269,7 +269,7 @@ static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *s |
| 269 | 269 | { |
| 270 | 270 | input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); |
| 271 | 271 | |
| 272 | - trace("%s session=%p proc=%p",__FUNCTION__,session,fn); | |
| 272 | + trace("%s session=%p proc=%p handle=%p",__FUNCTION__,session,fn,ip); | |
| 273 | 273 | |
| 274 | 274 | ip->source = source; |
| 275 | 275 | ip->condition = InputReadMask; |
| ... | ... | @@ -290,7 +290,7 @@ static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 * |
| 290 | 290 | { |
| 291 | 291 | input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); |
| 292 | 292 | |
| 293 | - trace("%s session=%p proc=%p",__FUNCTION__,session,fn); | |
| 293 | + trace("%s session=%p proc=%p handle=%p",__FUNCTION__,session,fn,ip); | |
| 294 | 294 | |
| 295 | 295 | ip->source = source; |
| 296 | 296 | ip->condition = InputWriteMask; |
| ... | ... | @@ -346,7 +346,10 @@ static void internal_remove_source(void *id) |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | if (ip == (input_t *)NULL) |
| 349 | + { | |
| 350 | + lib3270_write_log(NULL,"lib3270","Double removal on %s: Input %p wasnt found in the list",__FUNCTION__,id); | |
| 349 | 351 | return; |
| 352 | + } | |
| 350 | 353 | |
| 351 | 354 | if (prev != (input_t *)NULL) |
| 352 | 355 | prev->next = ip->next; |
| ... | ... | @@ -782,6 +785,12 @@ void remove_input_calls(H3270 *session) |
| 782 | 785 | session->ns_exception_id = NULL; |
| 783 | 786 | session->excepting = 0; |
| 784 | 787 | } |
| 788 | + if(session->ns_write_id) | |
| 789 | + { | |
| 790 | + RemoveSource(session->ns_write_id); | |
| 791 | + session->ns_write_id = NULL; | |
| 792 | + session->writing = 0; | |
| 793 | + } | |
| 785 | 794 | } |
| 786 | 795 | |
| 787 | 796 | LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)), void (*rm)(void *timer)) | ... | ... |
src/lib3270/lib3270.cbp
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | <Option compiler="gcc" /> |
| 8 | 8 | <Build> |
| 9 | 9 | <Target title="Debug"> |
| 10 | - <Option output=".bin/Debug/lib3270" prefix_auto="1" extension_auto="1" /> | |
| 10 | + <Option output=".bin/Debug/3270" prefix_auto="1" extension_auto="1" /> | |
| 11 | 11 | <Option object_output=".obj/Debug/" /> |
| 12 | 12 | <Option type="3" /> |
| 13 | 13 | <Option compiler="gcc" /> |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | </Linker> |
| 21 | 21 | </Target> |
| 22 | 22 | <Target title="Release"> |
| 23 | - <Option output=".bin/Release/lib3270" prefix_auto="1" extension_auto="1" /> | |
| 23 | + <Option output=".bin/Release/3270" prefix_auto="1" extension_auto="1" /> | |
| 24 | 24 | <Option object_output=".obj/Release/" /> |
| 25 | 25 | <Option type="3" /> |
| 26 | 26 | <Option compiler="gcc" /> |
| ... | ... | @@ -58,6 +58,8 @@ |
| 58 | 58 | </Compiler> |
| 59 | 59 | <Linker> |
| 60 | 60 | <Add option="-pthread" /> |
| 61 | + <Add option="-lssl" /> | |
| 62 | + <Add option="-lcrypto" /> | |
| 61 | 63 | </Linker> |
| 62 | 64 | <Unit filename="../include/lib3270.h" /> |
| 63 | 65 | <Unit filename="../include/lib3270/action_table.h" /> |
| ... | ... | @@ -87,14 +89,14 @@ |
| 87 | 89 | <Unit filename="charset.c"> |
| 88 | 90 | <Option compilerVar="CC" /> |
| 89 | 91 | </Unit> |
| 90 | - <Unit filename="charsetc.h" /> | |
| 91 | 92 | <Unit filename="childc.h" /> |
| 93 | + <Unit filename="connect.c"> | |
| 94 | + <Option compilerVar="CC" /> | |
| 95 | + </Unit> | |
| 92 | 96 | <Unit filename="ctlr.c"> |
| 93 | 97 | <Option compilerVar="CC" /> |
| 94 | 98 | </Unit> |
| 95 | - <Unit filename="ctlr.h" /> | |
| 96 | 99 | <Unit filename="ctlrc.h" /> |
| 97 | - <Unit filename="dialogc.h" /> | |
| 98 | 100 | <Unit filename="fallbacks.c"> |
| 99 | 101 | <Option compilerVar="CC" /> |
| 100 | 102 | </Unit> |
| ... | ... | @@ -192,9 +194,6 @@ |
| 192 | 194 | <Option compilerVar="CC" /> |
| 193 | 195 | </Unit> |
| 194 | 196 | <Unit filename="statusc.h" /> |
| 195 | - <Unit filename="tables.c"> | |
| 196 | - <Option compilerVar="CC" /> | |
| 197 | - </Unit> | |
| 198 | 197 | <Unit filename="tablesc.h" /> |
| 199 | 198 | <Unit filename="telnet.c"> |
| 200 | 199 | <Option compilerVar="CC" /> | ... | ... |
src/lib3270/tablesc.h
| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Copyright 1995, 1999, 2000, 2002, 2001, 2002, 2005, 2006 by Paul Mattes. | |
| 3 | - * Permission to use, copy, modify, and distribute this software and its | |
| 4 | - * documentation for any purpose and without fee is hereby granted, | |
| 5 | - * provided that the above copyright notice appear in all copies and that | |
| 6 | - * both that copyright notice and this permission notice appear in | |
| 7 | - * supporting documentation. | |
| 8 | - * | |
| 9 | - * x3270, c3270, s3270, tcl3270 and pr3287 are distributed in the hope that | |
| 10 | - * they will be useful, but WITHOUT ANY WARRANTY; without even the implied | |
| 11 | - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | - * file LICENSE for more details. | |
| 13 | - */ | |
| 14 | - | |
| 15 | -/* | |
| 16 | - * tablesc.h | |
| 17 | - * Global declarations for tables.c. | |
| 18 | - */ | |
| 19 | - | |
| 20 | -#error Deprecated, replace for charset.h | |
| 21 | - | |
| 22 | -// LIB3270_INTERNAL void initialize_tables(H3270 *hSession); | |
| 23 | -// LIB3270_INTERNAL void charset_defaults(H3270 *hSession); | |
| 24 | - | |
| 25 | -// LIB3270_INTERNAL unsigned short ebc2cg[256]; | |
| 26 | -// LIB3270_INTERNAL unsigned short cg2ebc[256]; | |
| 27 | -// LIB3270_INTERNAL unsigned short ebc2asc[256]; | |
| 28 | -// LIB3270_INTERNAL unsigned short asc2ebc[256]; | |
| 29 | -// LIB3270_INTERNAL unsigned short ft2asc[256]; | |
| 30 | -// LIB3270_INTERNAL unsigned short asc2ft[256]; | |
| 31 | - | |
| 32 | -#ifdef EXTENDED_TABLES | |
| 33 | -// LIB3270_INTERNAL unsigned short ebc2asc7[256]; | |
| 34 | -// LIB3270_INTERNAL const unsigned short ebc2asc70[256]; | |
| 35 | -// LIB3270_INTERNAL const unsigned short ge2asc[256]; | |
| 36 | -#endif // EXTENDED_TABLES | |
| 37 | - | |
| 38 | -// LIB3270_INTERNAL const unsigned short asc2cg[256]; | |
| 39 | -// LIB3270_INTERNAL const unsigned short cg2asc[256]; | |
| 40 | -// LIB3270_INTERNAL const unsigned short ebc2cg0[256]; | |
| 41 | -// LIB3270_INTERNAL const unsigned short cg2ebc0[256]; | |
| 42 | -// LIB3270_INTERNAL const unsigned short asc2ebc0[256]; | |
| 43 | -// LIB3270_INTERNAL const unsigned short asc2uc[256]; | |
| 44 | -// LIB3270_INTERNAL const unsigned short ebc2uc[256]; | |
| 45 | -// LIB3270_INTERNAL const unsigned short ft2asc0[256]; |
src/lib3270/telnet.c
| ... | ... | @@ -1016,24 +1016,30 @@ static void connection_complete(H3270 *session) |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | |
| 1019 | -LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *session) | |
| 1019 | +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession) | |
| 1020 | 1020 | { |
| 1021 | 1021 | trace("%s",__FUNCTION__); |
| 1022 | 1022 | |
| 1023 | 1023 | #if defined(HAVE_LIBSSL) |
| 1024 | - if(session->ssl_con != NULL) | |
| 1024 | + if(hSession->ssl_con != NULL) | |
| 1025 | 1025 | { |
| 1026 | - SSL_shutdown(session->ssl_con); | |
| 1027 | - SSL_free(session->ssl_con); | |
| 1028 | - session->ssl_con = NULL; | |
| 1026 | + SSL_shutdown(hSession->ssl_con); | |
| 1027 | + SSL_free(hSession->ssl_con); | |
| 1028 | + hSession->ssl_con = NULL; | |
| 1029 | 1029 | } |
| 1030 | 1030 | #endif |
| 1031 | 1031 | |
| 1032 | - if(session->sock >= 0) | |
| 1032 | + if(hSession->ns_write_id) | |
| 1033 | + { | |
| 1034 | + RemoveSource(hSession->ns_write_id); | |
| 1035 | + hSession->ns_write_id = 0; | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + if(hSession->sock >= 0) | |
| 1033 | 1039 | { |
| 1034 | - shutdown(session->sock, 2); | |
| 1035 | - SOCK_CLOSE(session->sock); | |
| 1036 | - session->sock = -1; | |
| 1040 | + shutdown(hSession->sock, 2); | |
| 1041 | + SOCK_CLOSE(hSession->sock); | |
| 1042 | + hSession->sock = -1; | |
| 1037 | 1043 | } |
| 1038 | 1044 | } |
| 1039 | 1045 | ... | ... |
src/lib3270/testprogram.c
| ... | ... | @@ -35,6 +35,8 @@ int main(int numpar, char *param[]) |
| 35 | 35 | pthread_create(&thread, NULL, mainloop, NULL); |
| 36 | 36 | pthread_detach(thread); |
| 37 | 37 | |
| 38 | + lib3270_connect_host(h, "127.0.0.1", "80"); | |
| 39 | + | |
| 38 | 40 | while(fgets(line,4095,stdin)) |
| 39 | 41 | { |
| 40 | 42 | // const LIB3270_MACRO_LIST *cmd = get_3270_calls(); | ... | ... |