diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 30a703c..4a8db9e 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -278,33 +278,27 @@ /** - * Connect options + * @brief Host options * */ - typedef enum lib3270_option + typedef enum lib3270_host_type { - /* Host types */ - LIB3270_OPTION_AS400 = 0x0001, /**< AS400 host - Prefix every PF with PA1 */ - LIB3270_OPTION_TSO = 0x0002, /**< Host is TSO? */ - LIB3270_OPTION_S390 = 0x0006, /**< Host is S390? (TSO included) */ + // Host types + LIB3270_HOST_AS400 = 0x0001, ///< AS400 host - Prefix every PF with PA1 + LIB3270_HOST_TSO = 0x0002, ///< Host is TSO? + LIB3270_HOST_S390 = 0x0006, ///< Host is S390? (TSO included) - /* Other options */ - LIB3270_OPTION_SSL = 0x0010, /**< Secure connection ? */ + } LIB3270_HOST_TYPE; + #define LIB3270_HOSTTYPE_DEFAULT LIB3270_HOST_S390 - LIB3270_OPTION_WAIT = 0x8000 /**< Wait for session ready on connect ? */ - } LIB3270_OPTION; - - #define LIB3270_OPTION_HOST_TYPE 0x0007 - #define LIB3270_OPTION_DEFAULTS LIB3270_OPTION_S390 - - typedef struct _lib3270_option_entry + typedef struct _LIB3270_HOST_TYPE_entry { - LIB3270_OPTION option; - const char * name; - const char * description; - const char * tooltip; - } LIB3270_OPTION_ENTRY; + LIB3270_HOST_TYPE type; + const char * name; + const char * description; + const char * tooltip; + } LIB3270_HOST_TYPE_ENTRY; /** * SSL state @@ -517,7 +511,9 @@ * @param h Session handle. * */ - LIB3270_EXPORT LIB3270_OPTION lib3270_get_options(H3270 *hSession); + LIB3270_EXPORT LIB3270_HOST_TYPE lib3270_get_host_type(H3270 *hSession); + + LIB3270_EXPORT const char * lib3270_get_host_type_name(H3270 *hSession); /** * @brief Get URL of the hostname for the connect/reconnect operations. @@ -531,17 +527,17 @@ /** - * @brief Network connect operation, keep main loop running + * @brief Reconnect to host. * * @param h Session handle. - * @param seconds Seconds to wait for connection . + * @param seconds Seconds to wait for connection. * * @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,int seconds); + LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int seconds); - LIB3270_EXPORT int lib3270_set_connected(H3270 *h,int state); +// LIB3270_EXPORT int lib3270_set_connected(H3270 *h,int state); /** * @brief Connect to defined host, keep main loop running. @@ -554,7 +550,7 @@ * @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_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt); +// LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_HOST_TYPE opt); /** * @brief Connect by URL @@ -1249,17 +1245,16 @@ LIB3270_EXPORT int lib3270_clear_operator_error(H3270 *hSession); - LIB3270_EXPORT void lib3270_set_options(H3270 *hSession, LIB3270_OPTION opt); LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, int colortype); LIB3270_EXPORT int lib3270_get_color_type(H3270 *hSession); - LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name); - LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession); + LIB3270_EXPORT int lib3270_set_host_type_by_name(H3270 *hSession, const char *name); + LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, LIB3270_HOST_TYPE opt); - LIB3270_EXPORT LIB3270_OPTION lib3270_parse_host_type(const char *name); + LIB3270_EXPORT LIB3270_HOST_TYPE lib3270_parse_host_type(const char *name); - LIB3270_EXPORT const LIB3270_OPTION_ENTRY * lib3270_get_option_list(void); + LIB3270_EXPORT const LIB3270_HOST_TYPE_ENTRY * lib3270_get_option_list(void); LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr); @@ -1277,14 +1272,28 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, void *), void *parm); /** - * The host is TSO? + * @brief The host is TSO? * * @param hSession Session Handle * * @return Non zero if the host is TSO. * */ - LIB3270_EXPORT int lib3270_is_tso(H3270 *hSession); + LIB3270_EXPORT int lib3270_is_tso(H3270 *hSession); + + LIB3270_EXPORT int lib3270_set_tso(H3270 *hSession, int on); + + /** + * @brief Host is AS400 (Prefix every PF with PA1). + * + * @param hSession Session Handle + * + * @return Non zero if the host is AS400. + * + */ + LIB3270_EXPORT int lib3270_is_as400(H3270 *hSession); + + LIB3270_EXPORT int lib3270_set_as400(H3270 *hSession, int on); #ifdef WIN32 LIB3270_EXPORT const char * lib3270_win32_strerror(int e); diff --git a/src/include/lib3270/macros.h b/src/include/lib3270/macros.h deleted file mode 100644 index 2058096..0000000 --- a/src/include/lib3270/macros.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * "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 macros.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) - * - */ - - #error Deprecated - - - // #define LIB3270_MACRO( name ) LIB3270_EXPORT char * lib3270_macro_ ## name (H3270 *hSession, int argc, const char **argv) - -// LIB3270_EXPORT char * lib3270_run_macro(H3270 *session, const char **argv); - diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index 608d632..693b7e8 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -439,13 +439,13 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); (ft->flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" ); - trace("tso=%s",hSession->options & LIB3270_OPTION_TSO ? "yes" : "No"); + trace("tso=%s",lib3270_is_tso(hSession) ? "yes" : "No"); if(!(ft->flags & LIB3270_FT_OPTION_RECEIVE)) { // Sending file - if(hSession->options & LIB3270_OPTION_TSO) + if(lib3270_is_tso(hSession)) { // TSO Host if(recfm > 0) @@ -492,7 +492,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); if(*op) { - if(hSession->options & LIB3270_OPTION_TSO) + if(lib3270_is_tso(hSession)) snconcat(buffer,4095," %s",op+1); else snconcat(buffer,4095," (%s",op+1); diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 51650c4..ab18658 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -58,11 +58,21 @@ /** * @brief Called from timer to attempt an automatic reconnection. */ -int lib3270_reconnect(H3270 *hSession) +int lib3270_check_for_auto_reconnect(H3270 *hSession) { - lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession)); - hSession->auto_reconnect_inprogress = 0; - lib3270_connect(hSession,0); + if(hSession->popups) + { + lib3270_write_log(hSession,"3270","Delaying auto-reconnect. There's %u pending popup(s)",(unsigned int) hSession->popups); + return 1; + } + + if(hSession->auto_reconnect_inprogress) + { + lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession)); + lib3270_reconnect(hSession,0); + hSession->auto_reconnect_inprogress = 0; + } + return 0; } @@ -86,7 +96,7 @@ int host_disconnect(H3270 *hSession, int failed) { /* Schedule an automatic reconnection. */ hSession->auto_reconnect_inprogress = 1; - (void) AddTimer(failed ? RECONNECT_ERR_MS : RECONNECT_MS, hSession, lib3270_reconnect); + (void) AddTimer(failed ? RECONNECT_ERR_MS : RECONNECT_MS, hSession, lib3270_check_for_auto_reconnect); } /* @@ -219,12 +229,16 @@ static void update_host(H3270 *h) Replace(h->host.full, lib3270_strdup_printf( "%s%s:%s", - h->options&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://", +#ifdef HAVE_LIBSSL + (h->ssl.enabled ? "tn3270s://" : "tn3270://"), +#else + "tn3270://", +#endif // HAVE_LIBSSL h->host.current, h->host.srvc )); - trace("hosturl=[%s] ssl=%s",h->host.full,(h->options&LIB3270_OPTION_SSL) ? "yes" : "no"); + trace("hosturl=[%s] ssl=%s",h->host.full,h->ssl.enabled ? "yes" : "no"); } @@ -269,18 +283,21 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) { static const struct _sch { - LIB3270_OPTION opt; + char ssl; const char * text; const char * srvc; } sch[] = { - { LIB3270_OPTION_DEFAULTS, "tn3270://", "telnet" }, - { LIB3270_OPTION_SSL, "tn3270s://", "telnets" }, - { LIB3270_OPTION_DEFAULTS, "telnet://", "telnet" }, - { LIB3270_OPTION_DEFAULTS, "telnets://", "telnets" }, - { LIB3270_OPTION_SSL, "L://", "telnets" }, +#ifdef HAVE_LIBSSL + { 1, "tn3270s://", "telnets" }, + { 1, "telnets://", "telnets" }, + { 1, "L://", "telnets" }, + { 1, "L:", "telnets" }, +#endif // HAVE_LIBSSL + + { 0, "tn3270://", "telnet" }, + { 0, "telnet://", "telnet" } - { LIB3270_OPTION_SSL, "L:", "telnets" } // The compatibility should be the last option }; char * str = strdup(n); @@ -291,16 +308,21 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) int f; trace("%s(%s)",__FUNCTION__,str); - h->options = LIB3270_OPTION_DEFAULTS; + +#ifdef HAVE_LIBSSL + h->ssl.enabled = 0; +#endif // HAVE_LIBSSL for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++) { size_t sz = strlen(sch[f].text); if(!strncasecmp(hostname,sch[f].text,sz)) { - h->options = sch[f].opt; - srvc = sch[f].srvc; - hostname += sz; +#ifdef HAVE_LIBSSL + h->ssl.enabled = sch[f].ssl; +#endif // HAVE_LIBSSL + srvc = sch[f].srvc; + hostname += sz; break; } } @@ -348,25 +370,18 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) *(val++) = 0; if(lib3270_set_string_property(h, var, val, 0) == 0) - { continue; - } - - /* - if(!(strcasecmp(var,"lu") && strcasecmp(var,"luname"))) - { - lib3270_set_luname(h, val); - // strncpy(h->luname,val,LIB3270_LUNAME_LENGTH); - } - else - { - lib3270_write_log(h,"","Ignoring invalid URL attribute \"%s\"",var); - } - */ lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); } + else + { + if(lib3270_set_int_property(h,var,1,0)) + continue; + + lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); + } } diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 075bf13..d3112e2 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -534,14 +534,14 @@ LIB3270_EXPORT int lib3270_pfkey(H3270 *hSession, int key) if (hSession->kybdlock) { - if(hSession->options & LIB3270_OPTION_AS400) + if(hSession->host_type & LIB3270_HOST_AS400) enq_key(hSession,pa_xlate[0]); enq_key(hSession,pf_xlate[key-1]); } else { - if(hSession->options & LIB3270_OPTION_AS400) + if(hSession->host_type & LIB3270_HOST_AS400) key_AID(hSession,pa_xlate[0]); key_AID(hSession,pf_xlate[key-1]); diff --git a/src/lib3270/linux/connect.c b/src/lib3270/linux/connect.c index 0aa6d59..9f1b0e6 100644 --- a/src/lib3270/linux/connect.c +++ b/src/lib3270/linux/connect.c @@ -124,11 +124,12 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u lib3270_set_url(hSession,url); } - return lib3270_connect(hSession, wait); + return lib3270_reconnect(hSession, wait); } - LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt) + /* + LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_HOST_TYPE opt) { CHECK_SESSION_HANDLE(hSession); @@ -155,22 +156,23 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u hostname = name; } - hSession->options = opt & ~LIB3270_OPTION_WAIT; + hSession->options = opt & ~LIB3270_HOST_TYPE_WAIT; Replace(hSession->host.current,strdup(hostname)); Replace(hSession->host.srvc,strdup(srvc)); Replace(hSession->host.full, lib3270_strdup_printf( "%s%s:%s", - opt&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://", + opt&LIB3270_HOST_TYPE_SSL ? "tn3270s://" : "tn3270://", hostname, srvc )); trace("current_host=\"%s\"",hSession->host.current); - return lib3270_connect(hSession,opt & LIB3270_OPTION_WAIT); + return lib3270_reconnect(hSession,opt & LIB3270_HOST_TYPE_WAIT); } + */ struct resolver { @@ -223,7 +225,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u } - int lib3270_connect(H3270 *hSession, int seconds) + int lib3270_reconnect(H3270 *hSession, int seconds) { int optval; struct resolver host; @@ -283,22 +285,13 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u hSession->ever_3270 = False; hSession->ssl.host = 0; - if(hSession->options&LIB3270_OPTION_SSL) - { #if defined(HAVE_LIBSSL) + if(hSession->ssl.enabled) + { hSession->ssl.host = 1; ssl_init(hSession); -#else - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "SSL error" ), - _( "Unable to connect to secure hosts" ), - _( "This version of %s was built without support for secure sockets layer (SSL)." ), - PACKAGE_NAME); - - return errno = EINVAL; -#endif // HAVE_LIBSSL } +#endif // HAVE_LIBSSL // set options for inline out-of-band data and keepalives optval = 1; diff --git a/src/lib3270/macros.c b/src/lib3270/macros.c deleted file mode 100644 index 100e0b1..0000000 --- a/src/lib3270/macros.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * "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 macros.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) - * - */ - -/* -#ifdef WIN32 - #include - #include -#endif // WIN32 - - #include - #include - #include - #include - #include - #include - #include - #include - #include "private.h" - #include "utilc.h" - #include "api.h" - */ - -/*--[ Structs & Defines ]----------------------------------------------------------------------------*/ - -/* - struct macro_list - { - const char *name; - char *(*exec)(H3270 *session, int argc, const char **argv); - }; -*/ - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - -/* - static const char * get_state(H3270 *h) - { - #define DECLARE_XLAT_STATE(x) { x, #x } - static const struct _xlat_state - { - LIB3270_CSTATE state; - const char * ret; - } xlat_state[] = - { - DECLARE_XLAT_STATE( LIB3270_NOT_CONNECTED ), - DECLARE_XLAT_STATE( LIB3270_RESOLVING ), - DECLARE_XLAT_STATE( LIB3270_PENDING ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_INITIAL ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_ANSI ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_3270 ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_INITIAL_E ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_NVT ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_SSCP ), - DECLARE_XLAT_STATE( LIB3270_CONNECTED_TN3270E ) - }; - - size_t f; - - LIB3270_CSTATE state = lib3270_get_connection_state(h); - - for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++) - { - if(state == xlat_state[f].state) - return xlat_state[f].ret; - } - - return "Unexpected"; - } - - LIB3270_MACRO( encoding ) - { - return strdup(lib3270_get_display_charset(hSession)); - } - - LIB3270_MACRO( get ) - { - char *buffer = NULL; - - switch(argc) - { - case 1: // Get entire screen - buffer = lib3270_get_string_at_address(hSession,0,-1,'\n'); - break; - - default: - errno = EINVAL; - } - - return buffer; - } - - LIB3270_MACRO( set ) - { - const char *str = NULL; - int rows, cols; - - if(lib3270_get_program_message(hSession) != LIB3270_MESSAGE_NONE) - { - errno = EBUSY; - return NULL; - } - - lib3270_get_screen_size(hSession,&rows,&cols); - - switch(argc) - { - case 1: - lib3270_enter(hSession); - break; - - case 2: - str = argv[1]; - break; - - case 3: - lib3270_set_cursor_address(hSession,atoi(argv[1])); - str = argv[2]; - break; - - case 4: - lib3270_set_cursor_address(hSession,(atoi(argv[1])-1) * cols + (atoi(argv[2])-1)); - str = argv[3]; - break; - - default: - errno = EINVAL; - return NULL; - } - - if(str) - lib3270_set_string(NULL, (const unsigned char *) str); - - return strdup(get_state(hSession)); - } - - LIB3270_MACRO( status ) - { - const char * luname = (const char *) lib3270_get_luname(hSession); - const char * state = get_state(hSession); - const char * host = (const char *) lib3270_get_hostname(hSession); - char * rsp; - size_t sz; - - if(!luname) - luname = "none"; - - if(!host) - host = "-"; - - sz = strlen(luname)+strlen(state)+strlen(host)+4; - rsp = lib3270_malloc(sz+1); - snprintf(rsp,sz,"%s %s %s",state,luname,host); - return rsp; - } - - LIB3270_MACRO( cstate ) - { - return strdup(get_state(hSession)); - } - - LIB3270_MACRO( luname ) - { - const char * luname = (const char *) lib3270_get_luname(hSession); - return strdup(luname ? luname : "none" ); - } - - LIB3270_MACRO( pf ) - { - char ret[10]; - if(argc != 2) - { - errno = EINVAL; - return NULL; - } - snprintf(ret,9,"%d",lib3270_pfkey(hSession,atoi(argv[1]))); - return strdup(ret); - } - - LIB3270_MACRO( pa ) - { - char ret[10]; - if(argc != 2) - { - errno = EINVAL; - return NULL; - } - snprintf(ret,9,"%d",lib3270_pakey(hSession,atoi(argv[1]))); - return strdup(ret); - } - - LIB3270_MACRO( enter ) - { - char ret[10]; - if(argc != 1) - { - errno = EINVAL; - return NULL; - } - snprintf(ret,9,"%d",lib3270_enter(hSession)); - return strdup(ret); - } - - LIB3270_MACRO( connect ) - { - int rc = EBUSY; - char ret[10]; - - switch(argc) - { - case 1: - rc = lib3270_connect(hSession,0); - break; - - case 2: - lib3270_set_url(hSession,argv[1]); - rc = lib3270_connect(hSession,0); - break; - - case 3: - lib3270_set_url(hSession,argv[1]); - rc = lib3270_connect(hSession,atoi(argv[2])); - break; - - default: - return NULL; - } - - snprintf(ret,9,"%d",rc); - return strdup(ret); - } - - LIB3270_MACRO( disconnect ) - { - lib3270_disconnect(hSession); - return strdup("0"); - } - - LIB3270_MACRO( unselect ) - { - lib3270_unselect(hSession); - return strdup("0"); - } - - LIB3270_MACRO( select ) - { - int rc = -1; - char ret[10]; - - switch(argc) - { - case 1: // 1 argument, select all - rc = lib3270_select_all(hSession); - break; - - case 3: // 2 arguments, first and last addr - rc = lib3270_select_region(hSession,atoi(argv[1]),atoi(argv[2])); - break; - - - default: - errno = EINVAL; - return NULL; - } - - snprintf(ret,9,"%d",rc); - return strdup(ret); - - } -*/ - -/*--[ Macro entry point ]----------------------------------------------------------------------------*/ - -/* - LIB3270_EXPORT char * lib3270_run_macro(H3270 *session, const char **argv) - { - #define LIB3270_MACRO_ENTRY( name ) { #name, lib3270_macro_ ## name } - - static const struct macro_list cmd[] = - { - LIB3270_MACRO_ENTRY( connect ), - LIB3270_MACRO_ENTRY( cstate ), - LIB3270_MACRO_ENTRY( disconnect ), - LIB3270_MACRO_ENTRY( encoding ), - LIB3270_MACRO_ENTRY( enter ), - LIB3270_MACRO_ENTRY( get ), - LIB3270_MACRO_ENTRY( luname ), - LIB3270_MACRO_ENTRY( pa ), - LIB3270_MACRO_ENTRY( pf ), - LIB3270_MACRO_ENTRY( set ), - LIB3270_MACRO_ENTRY( status ), - LIB3270_MACRO_ENTRY( select ), - LIB3270_MACRO_ENTRY( unselect ), - - {NULL, NULL} - }; - - int argc; - int f; - - CHECK_SESSION_HANDLE(session); - - trace("macro(%s)",argv[0]); - - // Get the number of arguments - for(argc = 0; argv[argc]; argc++); - - // Search for macro function - for(f=0;cmd[f].name;f++) - { - if(!strcasecmp(cmd[f].name,argv[0])) - return cmd[f].exec(session,argc,argv); - } - - if(argc == 1) - { - // Search for action - const LIB3270_ACTION_ENTRY *actions = lib3270_get_action_table(); - - for(f=0;actions[f].name;f++) - { - if(!strcasecmp(actions[f].name,argv[0])) - { - int rc = actions[f].call(session); - return xs_buffer("%d",rc); - } - } - - } - - // Not found, return NULL - return NULL; - } -*/ diff --git a/src/lib3270/options.c b/src/lib3270/options.c index 0cb951b..d746d97 100644 --- a/src/lib3270/options.c +++ b/src/lib3270/options.c @@ -35,22 +35,22 @@ /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ - static const LIB3270_OPTION_ENTRY host_type[] = + static const LIB3270_HOST_TYPE_ENTRY host_type[] = { { - LIB3270_OPTION_S390, + LIB3270_HOST_S390, "S390", N_( "IBM S/390" ), NULL }, { - LIB3270_OPTION_AS400, + LIB3270_HOST_AS400, "AS400", N_( "IBM AS/400" ), NULL }, { - LIB3270_OPTION_TSO, + LIB3270_HOST_TSO, "TSO", N_( "Other (TSO)" ), NULL @@ -73,25 +73,17 @@ /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ -LIB3270_EXPORT LIB3270_OPTION lib3270_get_options(H3270 *hSession) +LIB3270_EXPORT LIB3270_HOST_TYPE lib3270_get_host_type(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); - return hSession->options; + return hSession->host_type; } -LIB3270_EXPORT void lib3270_set_options(H3270 *hSession, LIB3270_OPTION opt) +LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, LIB3270_HOST_TYPE opt) { - CHECK_SESSION_HANDLE(hSession); - hSession->options = opt; - - Replace(hSession->host.full, - lib3270_strdup_printf( - "%s%s:%s", - hSession->options&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://", - hSession->host.current, - hSession->host.srvc - )); - + FAIL_IF_ONLINE(hSession); + hSession->host_type = opt; + return 0; } LIB3270_EXPORT int lib3270_get_color_type(H3270 *hSession) @@ -137,7 +129,7 @@ LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, int colortype) } -LIB3270_EXPORT const LIB3270_OPTION_ENTRY * lib3270_get_option_list(void) +LIB3270_EXPORT const LIB3270_HOST_TYPE_ENTRY * lib3270_get_option_list(void) { return host_type; } @@ -145,10 +137,40 @@ LIB3270_EXPORT const LIB3270_OPTION_ENTRY * lib3270_get_option_list(void) LIB3270_EXPORT int lib3270_is_tso(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); - return (hSession->options & LIB3270_OPTION_TSO) != 0; + return (hSession->host_type & LIB3270_HOST_TSO) != 0; +} + +LIB3270_EXPORT int lib3270_set_tso(H3270 *hSession, int on) +{ + FAIL_IF_ONLINE(hSession); + + if(on) + hSession->host_type = LIB3270_HOST_TSO; + else + hSession->host_type &= ~LIB3270_HOST_TSO; + + return 0; +} + +LIB3270_EXPORT int lib3270_is_as400(H3270 *hSession) +{ + CHECK_SESSION_HANDLE(hSession); + return (hSession->host_type & LIB3270_HOST_AS400) != 0; } -LIB3270_EXPORT LIB3270_OPTION lib3270_parse_host_type(const char *name) +LIB3270_EXPORT int lib3270_set_as400(H3270 *hSession, int on) +{ + FAIL_IF_ONLINE(hSession); + + if(on) + hSession->host_type |= LIB3270_HOST_AS400; + else + hSession->host_type &= ~LIB3270_HOST_AS400; + + return 0; +} + +LIB3270_EXPORT LIB3270_HOST_TYPE lib3270_parse_host_type(const char *name) { int f; @@ -156,22 +178,23 @@ LIB3270_EXPORT LIB3270_OPTION lib3270_parse_host_type(const char *name) for(f=0;host_type[f].name;f++) { if(!strcasecmp(host_type[f].name,name)) - return host_type[f].option; + return host_type[f].type; } + errno = ENOENT; return 0; } -LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name) +LIB3270_EXPORT int lib3270_set_host_type_by_name(H3270 *hSession, const char *name) { - size_t f; + FAIL_IF_ONLINE(hSession); + size_t f; for(f=0;f<(sizeof(host_type)/sizeof(host_type[0]));f++) { if(host_type[f].name && !strcasecmp(host_type[f].name,name)) { - hSession->options &= ~LIB3270_OPTION_HOST_TYPE; - hSession->options |= host_type[f].option; + hSession->host_type = host_type[f].type; return 0; } } @@ -179,13 +202,13 @@ LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name) return errno = EINVAL; } -LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession) +LIB3270_EXPORT const char * lib3270_get_host_type_name(H3270 *hSession) { size_t f; for(f=0;f<(sizeof(host_type)/sizeof(host_type[0]));f++) { - if(hSession->options & host_type[f].option) + if(hSession->host_type == host_type[f].type) { return host_type[f].name; } diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 1c7eccd..6a10643 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -309,7 +309,7 @@ struct _h3270 LIB3270_CSTATE cstate; ///< @brief Connection state. // flags - LIB3270_OPTION options; ///< @brief Session options. + LIB3270_HOST_TYPE host_type; ///< @brief Host type. int selected : 1; ///< @brief Has selected region? int rectsel : 1; ///< @brief Selected region is a rectangle ? @@ -605,6 +605,7 @@ struct _h3270 /// @brief SSL Data. struct { + char enabled; char host; LIB3270_SSL_STATE state; unsigned long error; @@ -647,7 +648,7 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block /** * @brief Called from timer to attempt an automatic reconnection. */ -LIB3270_INTERNAL int lib3270_reconnect(H3270 *hSession); +LIB3270_INTERNAL int lib3270_check_for_auto_reconnect(H3270 *hSession); #if defined(DEBUG) #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__); diff --git a/src/lib3270/properties.c b/src/lib3270/properties.c index 0e2931b..726f06a 100644 --- a/src/lib3270/properties.c +++ b/src/lib3270/properties.c @@ -72,7 +72,7 @@ "connected", // Property name. N_( "" ), // Property description. lib3270_is_connected, // Get value. - lib3270_set_connected // Set value. + NULL // Set value. }, { @@ -86,7 +86,14 @@ "tso", // Property name. N_( "Non zero if the host is TSO." ), // Property description. lib3270_is_tso, // Get value. - NULL // Set value. + lib3270_set_tso // Set value. + }, + + { + "as400", // Property name. + N_( "Non zero if the host is AS400." ), // Property description. + lib3270_is_as400, // Get value. + lib3270_set_as400 // Set value. }, { @@ -360,8 +367,8 @@ { "host_type", // Property name. N_( "" ), // Property description. - lib3270_get_host_type, // Get value. - lib3270_set_host_type // Set value. + lib3270_get_host_type_name, // Get value. + lib3270_set_host_type_by_name // Set value. }, { @@ -422,11 +429,12 @@ } + /* int lib3270_set_connected(H3270 *hSession, int state) { if(state) { - if(lib3270_connect(hSession,120)) + if(lib3270_reconnect(hSession,120)) return -1; } else { @@ -436,6 +444,7 @@ return 0; } + */ int lib3270_get_int_property(H3270 *hSession, const char *name, int seconds) { diff --git a/src/lib3270/session.c b/src/lib3270/session.c index b748836..cc8a3a5 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -314,7 +314,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->saved_wraparound_mode = 1; hSession->once_cset = -1; hSession->state = LIB3270_ANSI_STATE_DATA; - hSession->options = LIB3270_OPTION_DEFAULTS; + hSession->host_type = LIB3270_HOSTTYPE_DEFAULT; hSession->colors = 16; hSession->m3279 = 1; hSession->unlock_delay_ms = 350; // 0.35s after last unlock diff --git a/src/lib3270/testprogram/testprogram.c b/src/lib3270/testprogram/testprogram.c index 29820cd..8f892b9 100644 --- a/src/lib3270/testprogram/testprogram.c +++ b/src/lib3270/testprogram/testprogram.c @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) //lib3270_set_toggle(h,LIB3270_TOGGLE_DS_TRACE,1); lib3270_set_toggle(h,LIB3270_TOGGLE_SSL_TRACE,1); - rc = lib3270_connect(h,120); + rc = lib3270_reconnect(h,120); printf("\nConnect %s exits with rc=%d\n",lib3270_get_url(h),rc); lib3270_wait_for_ready(h,10); diff --git a/src/lib3270/toggles.c b/src/lib3270/toggles.c index 9461551..1e58224 100644 --- a/src/lib3270/toggles.c +++ b/src/lib3270/toggles.c @@ -352,7 +352,7 @@ static void toggle_reconnect(H3270 *hSession, struct lib3270_toggle *t unused, L /* Schedule an automatic reconnection. */ lib3270_write_log(hSession,"toggle","Auto-reconnect toggle was activated when offline, reconnecting"); hSession->auto_reconnect_inprogress = 1; - (void) AddTimer(RECONNECT_MS, hSession, lib3270_reconnect); + (void) AddTimer(RECONNECT_MS, hSession, lib3270_check_for_auto_reconnect); } } diff --git a/src/lib3270/windows/connect.c b/src/lib3270/windows/connect.c index 8a678ed..63951f8 100644 --- a/src/lib3270/windows/connect.c +++ b/src/lib3270/windows/connect.c @@ -159,11 +159,12 @@ LIB3270_EXPORT int lib3270_connect_url(H3270 *hSession, const char *url, int wai lib3270_set_url(hSession,url); } - return lib3270_connect(hSession, wait); + return lib3270_reconnect(hSession, wait); } -LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt) +/* +LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_HOST_TYPE opt) { CHECK_SESSION_HANDLE(hSession); @@ -190,22 +191,23 @@ LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, c hostname = name; } - hSession->options = opt & ~LIB3270_OPTION_WAIT; + hSession->options = opt & ~LIB3270_HOST_TYPE_WAIT; Replace(hSession->host.current,strdup(hostname)); Replace(hSession->host.srvc,strdup(srvc)); Replace(hSession->host.full, lib3270_strdup_printf( "%s%s:%s", - opt&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://", + opt&LIB3270_HOST_TYPE_SSL ? "tn3270s://" : "tn3270://", hostname, srvc )); trace("current_host=\"%s\"",hSession->host.current); - return lib3270_connect(hSession,opt & LIB3270_OPTION_WAIT); + return lib3270_reconnect(hSession,opt & LIB3270_HOST_TYPE_WAIT); } +*/ struct resolver { @@ -260,7 +262,7 @@ LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, c } -int lib3270_connect(H3270 *hSession, int seconds) +int lib3270_reconnect(H3270 *hSession, int seconds) { int optval; struct resolver host; @@ -330,7 +332,7 @@ int lib3270_connect(H3270 *hSession, int seconds) hSession->ever_3270 = False; hSession->ssl.host = 0; - if(hSession->options&LIB3270_OPTION_SSL) + if(hSession->options&LIB3270_HOST_TYPE_SSL) { #if defined(HAVE_LIBSSL) hSession->ssl.host = 1; -- libgit2 0.21.2