diff --git a/src/classlib/local.cc b/src/classlib/local.cc index ff6a03a..bde2278 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -279,7 +279,8 @@ const char * (*_get_version)(void); LIB3270_CSTATE (*_get_connection_state)(H3270 *h); int (*_disconnect)(H3270 *h); - int (*_connect)(H3270 *h,const char *n, int wait); + int (*_connect)(H3270 *h,int wait); + const char (*_set_host)(H3270 *h, const char *n); int (*_is_connected)(H3270 *h); void (*_main_iterate)(H3270 *h, int wait); int (*_wait)(H3270 *hSession, int seconds); @@ -334,6 +335,7 @@ { (void **) & _get_version, "lib3270_get_version" }, { (void **) & _disconnect, "lib3270_disconnect" }, { (void **) & _connect, "lib3270_connect" }, + { (void **) & _set_host, "lib3270_set_host" }, { (void **) & _main_iterate, "lib3270_main_iterate" }, { (void **) & _wait, "lib3270_wait" }, { (void **) & _enter, "lib3270_enter" }, @@ -416,9 +418,14 @@ return _get_connection_state(hSession); } - int connect(const char *uri, bool wait) + int connect(bool wait) { - return _connect(hSession,uri,(int) wait); + return _connect(hSession,(int) wait); + } + + int set_host(const char *uri) + { + return _set_host(hSession,uri) != NULL; } int disconnect(void) diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index 84be82f..27c5821 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -651,7 +651,7 @@ return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); } - int connect(const char *uri, bool wait) + int connect(bool wait) { #if defined(WIN32) @@ -660,9 +660,6 @@ pkt->packet_id = HLLAPI_PACKET_CONNECT; pkt->wait = (unsigned char) wait; - strcpy(pkt->hostname,uri); - - trace("Sending %s",pkt->hostname); return query_intval((void *) pkt,cbSize,true); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 8b0c36f..677ab52 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -421,17 +421,13 @@ /** * Network connect operation, keep main loop running * - * Sets 'reconnect_host', 'current_host' and 'full_current_host' as - * side-effects. - * * @param h Session handle. - * @param n Host ID (NULL to use the last one) * @param wait Non zero to wait for connection to be ok. * * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure. * */ - LIB3270_EXPORT int lib3270_connect(H3270 *h,const char *n, int wait); + LIB3270_EXPORT int lib3270_connect(H3270 *h,int wait); /** * Connect to defined host, keep main loop running. @@ -456,14 +452,6 @@ LIB3270_EXPORT int lib3270_disconnect(H3270 *h); /** - * Reconnect. - * - * @param h Session handle. - * @param wait Non zero to wait for connection to be ok. - */ - LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait); - - /** * Get connection state. * * @param h Session handle. diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 1f603bd..fa96b45 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -128,7 +128,8 @@ virtual string * get_display_charset(void); // Connection & Network - virtual int connect(const char *uri, bool wait = true) = 0; + virtual int connect(bool wait = true) = 0; + virtual int set_host(const char *hostname) = 0; virtual int disconnect(void) = 0; virtual int wait_for_ready(int seconds) = 0; virtual int wait(int seconds) = 0; diff --git a/src/include/pw3270/ipcpackets.h b/src/include/pw3270/ipcpackets.h index 3c6c913..c6c5d0c 100644 --- a/src/include/pw3270/ipcpackets.h +++ b/src/include/pw3270/ipcpackets.h @@ -30,6 +30,7 @@ typedef enum _hllapi_packet { HLLAPI_PACKET_CONNECT, + HLLAPI_PACKET_SET_HOST, HLLAPI_PACKET_DISCONNECT, HLLAPI_PACKET_GET_PROGRAM_MESSAGE, HLLAPI_PACKET_GET_TEXT_AT_OFFSET, @@ -90,7 +91,6 @@ struct hllapi_packet_connect { unsigned char packet_id; unsigned char wait; - char hostname[1]; }; struct hllapi_packet_keycode diff --git a/src/lib3270/api.h b/src/lib3270/api.h index c6beed4..612e879 100644 --- a/src/lib3270/api.h +++ b/src/lib3270/api.h @@ -324,8 +324,8 @@ #include - #define host_connect(n,wait) lib3270_connect(NULL,n,wait) - #define host_reconnect(w) lib3270_reconnect(NULL,w) + // #define host_connect(n,wait) lib3270_connect(NULL,n,wait) + // #define host_reconnect(w) lib3270_reconnect(NULL,w) #ifdef __cplusplus diff --git a/src/lib3270/connect.c b/src/lib3270/connect.c index f98bc1d..1908359 100644 --- a/src/lib3270/connect.c +++ b/src/lib3270/connect.c @@ -201,7 +201,7 @@ static void net_connected(H3270 *hSession) sockstart(hSession); #endif - hSession->host.opt = opt; + hSession->host.opt = opt & ~LIB3270_CONNECT_OPTION_WAIT; Replace(hSession->host.current,strdup(hostname)); Replace(hSession->host.full, diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 1bcce31..6b825dc 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -457,17 +457,7 @@ static int do_connect(H3270 *hSession) return 0; } -/** - * Connect to selected host. - * - * @param h Session handle. - * @param n Hostname (null to reconnect to the last one; - * @param wait Wait for connection ok before return. - * - * @return 0 if the connection was ok, non zero on error. - * - */ -int lib3270_connect(H3270 *hSession, const char *n, int wait) +int lib3270_connect(H3270 *hSession, int wait) { int rc; @@ -475,18 +465,18 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait) lib3270_main_iterate(hSession,0); - if(hSession->auto_reconnect_inprogress) - return EAGAIN; - - if(PCONNECTED) + if (CONNECTED || HALF_CONNECTED) return EBUSY; - if(n) - lib3270_set_host(hSession,n); - if(!hSession->host.full) return EINVAL; + if (hSession->auto_reconnect_inprogress) + return EBUSY; + + if(PCONNECTED) + return EBUSY; + rc = do_connect(hSession); if(rc) return rc; @@ -514,7 +504,7 @@ static void try_reconnect(H3270 *session) { lib3270_write_log(session,"3270","Starting auto-reconnect (Host: %s)",session->host.full ? session->host.full : "-"); session->auto_reconnect_inprogress = 0; - lib3270_reconnect(session,0); + lib3270_connect(session,0); } LIB3270_EXPORT int lib3270_disconnect(H3270 *h) @@ -689,8 +679,6 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) } } - trace("SRVC=[%s]",srvc); - if(!*hostname) return h->host.current; @@ -709,18 +697,22 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) query = ""; } + trace("SRVC=[%s]",srvc); + Replace(h->host.current,strdup(hostname)); Replace(h->host.srvc,strdup(srvc)); Replace(h->host.full, lib3270_strdup_printf( "%s%s:%s%s%s", - h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "", + h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "tn3270://", hostname, srvc, *query ? "?" : "", query )); + trace("hosturl=[%s]",h->host.full); + free(str); } @@ -733,6 +725,7 @@ LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h) return h->host.current; } +/* LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) { int rc; @@ -742,13 +735,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) if (CONNECTED || HALF_CONNECTED) return EBUSY; - if (hSession->host.full == CN) + if (!hSession->host.full) return EINVAL; if (hSession->auto_reconnect_inprogress) return EBUSY; - rc = lib3270_connect(hSession,hSession->host.full,wait); + rc = lib3270_connect(hSession,wait); if(rc) { @@ -758,6 +751,7 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) return 0; } +*/ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) { diff --git a/src/lib3270/macros.c b/src/lib3270/macros.c index f92929a..afdead7 100644 --- a/src/lib3270/macros.c +++ b/src/lib3270/macros.c @@ -254,15 +254,17 @@ switch(argc) { case 1: - rc = lib3270_reconnect(hSession,0); + rc = lib3270_connect(hSession,0); break; case 2: - rc = lib3270_connect(hSession,argv[1],0); + lib3270_set_host(hSession,argv[1]); + rc = lib3270_connect(hSession,0); break; case 3: - rc = lib3270_connect(hSession,argv[1],atoi(argv[2])); + lib3270_set_host(hSession,argv[1]); + rc = lib3270_connect(hSession,atoi(argv[2])); break; default: diff --git a/src/plugins/hllapi/calls.cc b/src/plugins/hllapi/calls.cc index 258620c..e3926c3 100644 --- a/src/plugins/hllapi/calls.cc +++ b/src/plugins/hllapi/calls.cc @@ -100,7 +100,9 @@ try { - rc = session::get_default()->connect(uri,wait); + if(uri && *uri) + session::get_default()->set_host(uri); + rc = session::get_default()->connect(wait); } catch(std::exception &e) { diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c index 3d5e273..73c1726 100644 --- a/src/plugins/hllapi/pluginmain.c +++ b/src/plugins/hllapi/pluginmain.c @@ -197,7 +197,6 @@ { case HLLAPI_PACKET_CONNECT: send_result(source,lib3270_connect( lib3270_get_default_session_handle(), - ((struct hllapi_packet_connect *) source->buffer)->hostname, ((struct hllapi_packet_connect *) source->buffer)->wait)); break; diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 54b7af3..67b648c 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -89,7 +89,7 @@ const string get_version(void); LIB3270_CSTATE get_cstate(void); int disconnect(void); - int connect(const char *uri, bool wait = true); + int connect(bool wait = true); bool is_connected(void); bool is_ready(void); @@ -542,9 +542,9 @@ extern "C" return 0; } - int plugin::connect(const char *uri, bool wait) + int plugin::connect(bool wait) { - return lib3270_connect(hSession,uri,wait); + return lib3270_connect(hSession,wait); } bool plugin::is_connected(void) diff --git a/src/plugins/rx3270/rexx_methods.cc b/src/plugins/rx3270/rexx_methods.cc index a7b1767..23a911c 100644 --- a/src/plugins/rx3270/rexx_methods.cc +++ b/src/plugins/rx3270/rexx_methods.cc @@ -100,7 +100,11 @@ RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONA session *hSession = (session *) sessionPtr; if(!hSession) return -1; - return hSession->connect(uri,wait != 0); + + if(uri) + hSession->set_hostname(uri); + + return hSession->connect(wait != 0); } RexxMethod1(int, rx3270_method_disconnect, CSELF, sessionPtr) diff --git a/src/plugins/rx3270/typed_routines.cc b/src/plugins/rx3270/typed_routines.cc index 156b616..fee6097 100644 --- a/src/plugins/rx3270/typed_routines.cc +++ b/src/plugins/rx3270/typed_routines.cc @@ -93,7 +93,12 @@ RexxRoutine0(int, rx3270Disconnect) RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, wait) { - return session::get_default()->connect(hostname,wait); + session * hSession = session::get_default(); + + if(hostname && *hostname) + hSession->set_hostname(hostname); + + return hSession->connect(wait); } RexxRoutine0(int, rx3270isConnected) diff --git a/src/pw3270/hostdialog.c b/src/pw3270/hostdialog.c index 319b661..123ba02 100644 --- a/src/pw3270/hostdialog.c +++ b/src/pw3270/hostdialog.c @@ -393,12 +393,14 @@ case GTK_RESPONSE_ACCEPT: gtk_widget_set_sensitive(dialog,FALSE); + /* hostname = g_strconcat( gtk_toggle_button_get_active(sslcheck) ? "L:" : "", gtk_entry_get_text(host), ":", gtk_entry_get_text(port), NULL ); + */ #if GTK_CHECK_VERSION(2,18,0) gtk_widget_set_visible(dialog,FALSE); @@ -411,7 +413,11 @@ v3270_set_session_options(widget,host_type[iHostType].option); v3270_set_session_color_type(widget,colortable[iColorTable].colors); - if(!lib3270_connect(v3270_get_session(widget),hostname,1)) +// if(!lib3270_connect(v3270_get_session(widget),hostname,1)) + if(!lib3270_connect_host( v3270_get_session(widget), + gtk_entry_get_text(host), + gtk_entry_get_text(port), + gtk_toggle_button_get_active(sslcheck) ? LIB3270_CONNECT_OPTION_SSL : LIB3270_CONNECT_OPTION_DEFAULTS)) { again = FALSE; } diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index 38709e3..fb86eb1 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -1400,64 +1400,14 @@ int v3270_connect(GtkWidget *widget, const gchar *uri) terminal = GTK_V3270(widget); -#ifdef DEBUG if(uri) { - LIB3270_CONNECT_OPTION opt = LIB3270_CONNECT_OPTION_DEFAULTS; - gchar * scheme = g_uri_unescape_string(uri,NULL); - gchar * hostname = strchr(scheme,':'); - gchar * srvc; - gchar * query; - - if(hostname) - { - *(hostname++) = 0; - - while(*hostname && !g_ascii_isalnum(*hostname)) - hostname++; - - if(*hostname) - { - if( ! (g_ascii_strcasecmp(scheme,"l") && g_ascii_strcasecmp(scheme,"ssl")) ) - opt |= LIB3270_CONNECT_OPTION_SSL; - - srvc = strchr(hostname,':'); - if(srvc) - { - *(srvc++) = 0; - query = strchr(srvc,'?'); - if(query) - *(query++) = 0; - else - query = ""; - } - else - { - srvc = "telnet"; - } - - rc = lib3270_connect_host(terminal->host,hostname,srvc,opt); - - } - - } - - - g_free(scheme); - - } - else - { - rc = lib3270_connect(terminal->host,uri,0); + trace("%s(%s)",__FUNCTION__,uri); + lib3270_set_host(terminal->host,uri); } -#else - rc = lib3270_connect(terminal->host,uri,0); -#endif // DEBUG - - trace("%s exits with rc=%d (%s)",__FUNCTION__,rc,strerror(rc)); + return lib3270_connect(terminal->host,0); - return rc; } static gboolean notify_focus(GtkWidget *widget, GdkEventFocus *event) -- libgit2 0.21.2