diff --git a/lib3270.cbp b/lib3270.cbp index ccc8c0a..eb6b8d5 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -37,9 +37,6 @@ - - - @@ -76,6 +73,7 @@ + @@ -181,6 +179,9 @@ + + diff --git a/src/include/api.h b/src/include/api.h index 0fdd5a1..2260df7 100644 --- a/src/include/api.h +++ b/src/include/api.h @@ -106,53 +106,6 @@ #endif */ - /** 3270 connection handle */ -// #define LUNAME_SIZE 16 -// #define FULL_MODEL_NAME_SIZE 13 - -// #define ST_RESOLVING LIB3270_STATE_RESOLVING -// #define ST_HALF_CONNECT LIB3270_STATE_HALF_CONNECT -// #define ST_CONNECT LIB3270_STATE_CONNECT -// #define ST_3270_MODE LIB3270_STATE_3270_MODE -// #define ST_LINE_MODE LIB3270_STATE_LINE_MODE -// #define ST_REMODEL LIB3270_STATE_REMODEL -// #define ST_PRINTER LIB3270_STATE_PRINTER -// #define ST_EXITING LIB3270_STATE_EXITING -// #define ST_CHARSET LIB3270_STATE_CHARSET -// #define N_ST LIB3270_STATE_USER -// #define LIB3270_STATE_CHANGE LIB3270_STATE - - /** connection state */ -// #define cstate LIB3270_CSTATE -// #define NOT_CONNECTED LIB3270_NOT_CONNECTED -// #define RESOLVING LIB3270_RESOLVING -// #define PENDING LIB3270_PENDING -// #define CONNECTED_INITIAL LIB3270_CONNECTED_INITIAL -// #define CONNECTED_ANSI LIB3270_CONNECTED_ANSI -// #define CONNECTED_3270 LIB3270_CONNECTED_3270 -// #define CONNECTED_INITIAL_E LIB3270_CONNECTED_INITIAL_E -// #define CONNECTED_NVT LIB3270_CONNECTED_NVT -// #define CONNECTED_SSCP LIB3270_CONNECTED_SSCP -// #define CONNECTED_TN3270E LIB3270_CONNECTED_TN3270E - -// #define LIB3270_STATUS LIB3270_MESSAGE -// #define LIB3270_STATUS_BLANK LIB3270_MESSAGE_NONE -// #define LIB3270_STATUS_SYSWAIT LIB3270_MESSAGE_SYSWAIT -// #define LIB3270_STATUS_TWAIT LIB3270_MESSAGE_TWAIT -// #define LIB3270_STATUS_CONNECTED LIB3270_MESSAGE_CONNECTED -// #define LIB3270_STATUS_DISCONNECTED LIB3270_MESSAGE_DISCONNECTED -// #define LIB3270_STATUS_AWAITING_FIRST LIB3270_MESSAGE_AWAITING_FIRST -// #define LIB3270_MESSAGE_MINUS LIB3270_MESSAGE_MINUS -// #define LIB3270_STATUS_PROTECTED LIB3270_MESSAGE_PROTECTED -// #define LIB3270_STATUS_NUMERIC LIB3270_MESSAGE_NUMERIC -// #define LIB3270_STATUS_OVERFLOW LIB3270_MESSAGE_OVERFLOW -// #define LIB3270_STATUS_INHIBIT LIB3270_MESSAGE_INHIBIT -// #define LIB3270_STATUS_KYBDLOCK LIB3270_MESSAGE_KYBDLOCK -// #define LIB3270_STATUS_X LIB3270_MESSAGE_X -// #define LIB3270_MESSAGE_RESOLVING LIB3270_MESSAGE_RESOLVING -// #define LIB3270_STATUS_CONNECTING LIB3270_MESSAGE_CONNECTING -// #define LIB3270_STATUS_USER LIB3270_MESSAGE_USER - #define OIA_FLAG_BOXSOLID LIB3270_FLAG_BOXSOLID #define OIA_FLAG_UNDERA LIB3270_FLAG_UNDERA #define OIA_FLAG_TYPEAHEAD LIB3270_FLAG_TYPEAHEAD @@ -190,16 +143,6 @@ #define CS_DBCS 0x03 /**< DBCS character set (X'F8') */ #define CS_GE 0x04 /**< cs flag for Graphic Escape */ - /** - * Return a "malloced" copy of the device buffer, set number of elements - */ -// LOCAL_EXTERN struct ea * copy_device_buffer(int *el); - - /** - * Set the contents of the device buffer for debugging purposes - */ -// LOCAL_EXTERN int set_device_buffer(struct ea *src, int el); - /* File transfer */ #define FT_RECORD_FORMAT_FIXED LIB3270_FT_RECORD_FORMAT_FIXED @@ -218,25 +161,7 @@ #define FT_ABORT_WAIT LIB3270_FT_STATE_ABORT_WAIT #define FT_ABORT_SENT LIB3270_FT_STATE_ABORT_SENT -// LOCAL_EXTERN int BeginFileTransfer(unsigned short flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft); LOCAL_EXTERN int CancelFileTransfer(int force); -// LOCAL_EXTERN enum ft_state GetFileTransferState(void); - -/* - struct filetransfer_callbacks - { - unsigned short sz; - - void (*begin)(unsigned short flags, const char *local, const char *remote); - void (*complete)(const char *errmsg,unsigned long length,double kbytes_sec,const char *mode); - void (*update)(unsigned long length,unsigned long total,double kbytes_sec); - void (*running)(int is_cut); - void (*aborting)(void); - - }; - - LOCAL_EXTERN int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk); -*/ #define PCONNECTED lib3270_pconnected(hSession) #define HALF_CONNECTED lib3270_half_connected(hSession) @@ -249,19 +174,8 @@ #define IN_TN3270E lib3270_in_tn3270e(hSession) #define IN_E lib3270_in_e(hSession) - #ifndef LIB3270 - -// LOCAL_EXTERN enum ft_state QueryFTstate(void); - - #endif - - /* Screen processing */ -// #define CURSOR_MODE_NORMAL LIB3270_CURSOR_EDITABLE -// #define CURSOR_MODE_WAITING LIB3270_CURSOR_WAITING -// #define CURSOR_MODE_LOCKED LIB3270_CURSOR_LOCKED - typedef enum _SCRIPT_STATE { SCRIPT_STATE_NONE, @@ -287,7 +201,6 @@ #define COLOR_ATTR_NONE 0x0000 #define COLOR_ATTR_FIELD LIB3270_ATTR_FIELD #define COLOR_ATTR_BLINK LIB3270_ATTR_BLINK -// #define COLOR_ATTR_UNDERLINE LIB3270_ATTR_UNDERLINE #define COLOR_ATTR_INTENSIFY LIB3270_ATTR_INTENSIFY #define CHAR_ATTR_UNCONVERTED LIB3270_ATTR_CG @@ -298,27 +211,19 @@ #define find_field_length(s,a) find_field_length(s,a) LOCAL_EXTERN unsigned char get_field_attribute(H3270 *session, int baddr); -// LOCAL_EXTERN int screen_read(char *dest, int baddr, int count); LOCAL_EXTERN void Input_String(const unsigned char *str); LOCAL_EXTERN void screen_size(int *rows, int *cols); -// #define query_secure_connection(h) lib3270_get_ssl_state(h) #define lib3270_paste_string(str) lib3270_set_string(NULL,str) #define get_3270_terminal_size(h,r,c) lib3270_get_screen_size(h,r,c) /* Keyboard */ LOCAL_EXTERN int emulate_input(char *s, int len, int pasting); - /* Network related calls */ -// LOCAL_EXTERN int Get3270Socket(void); - /* Misc calls */ #define query_3270_terminal_status(void) lib3270_get_program_message(NULL) -// #define set_3270_model(h,m) lib3270_set_model(h,m) -// #define get_3270_model(h) lib3270_get_model(h) - /* Get connection info */ #define get_connected_lu(h) lib3270_get_luname(h) @@ -326,10 +231,6 @@ #include - // #define host_connect(n,wait) lib3270_connect(NULL,n,wait) - // #define host_reconnect(w) lib3270_reconnect(NULL,w) - - #ifdef __cplusplus } #endif diff --git a/src/include/lib3270.h b/src/include/lib3270.h index d0bbf9c..4a93848 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -513,13 +513,15 @@ /** * @brief Network connect operation, keep main loop running * - * @param h Session handle. - * @param wait Non zero to wait for connection to be ok. + * @param h Session handle. + * @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 wait); + LIB3270_EXPORT int lib3270_connect(H3270 *h,int seconds); + + LIB3270_EXPORT int lib3270_set_connected(H3270 *h,int state); /** * @brief Connect to defined host, keep main loop running. @@ -927,7 +929,6 @@ */ LIB3270_EXPORT void lib3270_ring_bell(H3270 *session); - /** * Get lib3270's charset. * diff --git a/src/include/lib3270/internals.h b/src/include/lib3270/internals.h index 135c366..82bcd8f 100644 --- a/src/include/lib3270/internals.h +++ b/src/include/lib3270/internals.h @@ -36,7 +36,7 @@ LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf); LIB3270_EXPORT void lib3270_set_disconnected(H3270 *hSession); - LIB3270_EXPORT void lib3270_set_connected(H3270 *hSession); + LIB3270_EXPORT void lib3270_set_connected_initial(H3270 *hSession); LIB3270_EXPORT void lib3270_setup_session(H3270 *session); diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h new file mode 100644 index 0000000..324f2f5 --- /dev/null +++ b/src/include/lib3270/properties.h @@ -0,0 +1,90 @@ +/* + * "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 -.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) + * + */ + + /** + * @brief TN3270 Session properties. + * + * @author perry.werneck@gmail.com + * + */ + +#ifndef LIB3270_PROPERTIES_H_INCLUDED + + #define LIB3270_PROPERTIES_H_INCLUDED + +#ifdef __cplusplus + extern "C" { +#endif + + typedef struct _lib3270_int_property + { + const char * name; ///< @brief Property name. + const char * description; ///< @brief Property description. + int (*get)(H3270 *hSession); ///< @brief Get value. + int (*set)(H3270 *hSession, int value); ///< @brief Set value. + + } LIB3270_INT_PROPERTY; + + /** + * @brief Get lib3270 integer properties table. + * + * @return The properties table. + * + */ + LIB3270_EXPORT const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void); + + /** + * @brief Get lib3270 property by name. + * + * @param name Nome of the property. + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). + * + * @return Property value or -1 in case of error (sets errno). + * + */ + LIB3270_EXPORT int lib3270_get_property(H3270 * hSession, const char *name, int seconds); + + /** + * @brief Set lib3270 property by name. + * + * @param name Nome of the property. + * @param value New property value. + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). + * + * @return 0 if ok, -1 in case of error (sets errno). + * + */ + LIB3270_EXPORT int lib3270_set_property(H3270 * hSession, const char *name, int value, int seconds); + +#ifdef __cplusplus + } +#endif + +#endif // LIB3270_PROPERTIES_H_INCLUDED + diff --git a/src/lib3270/connect.c b/src/lib3270/connect.c index 3885416..e1a5ca1 100644 --- a/src/lib3270/connect.c +++ b/src/lib3270/connect.c @@ -137,9 +137,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d #endif lib3270_setup_session(hSession); - - - lib3270_set_connected(hSession); + lib3270_set_connected_initial(hSession); } @@ -239,7 +237,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d } - int lib3270_connect(H3270 *hSession, int wait) + int lib3270_connect(H3270 *hSession, int seconds) { int s; int optval; @@ -252,10 +250,10 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d lib3270_main_iterate(hSession,0); if(hSession->auto_reconnect_inprogress) - return EAGAIN; + return errno = EAGAIN; if(hSession->sock > 0) - return EBUSY; + return errno = EBUSY; #if defined(_WIN32) sockstart(hSession); @@ -325,7 +323,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d lib3270_set_disconnected(hSession); - return ENOENT; + return errno = ENOENT; } @@ -350,7 +348,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d _( "This version of %s was built without support for secure sockets layer (SSL)." ), PACKAGE_NAME); - return EINVAL; + return errno = EINVAL; #endif // HAVE_LIBSSL } @@ -507,7 +505,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d if(hSession->sock < 0) { lib3270_set_disconnected(hSession); - return ENOTCONN; + return errno = ENOTCONN; } // Connecting, set callbacks, wait for connection @@ -519,9 +517,9 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d trace("%s: Connection in progress",__FUNCTION__); - if(wait) + if(seconds) { - time_t end = time(0)+120; + time_t end = time(0)+seconds; while(time(0) < end) { @@ -539,7 +537,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d break; case LIB3270_NOT_CONNECTED: - return ENOTCONN; + return errno = ENOTCONN; case LIB3270_CONNECTED_TN3270E: return 0; @@ -553,7 +551,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d lib3270_disconnect(hSession); lib3270_write_log(hSession,"connect", "%s",__FUNCTION__,strerror(ETIMEDOUT)); - return ETIMEDOUT; + return errno = ETIMEDOUT; } return 0; diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 2679780..a783844 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -127,7 +127,7 @@ void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) lib3270_st_changed(hSession, LIB3270_STATE_3270_MODE, now3270); } -void lib3270_set_connected(H3270 *hSession) +void lib3270_set_connected_initial(H3270 *hSession) { hSession->cstate = LIB3270_CONNECTED_INITIAL; hSession->starting = 1; // Enable autostart diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 8911d7a..b998d52 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -29,9 +29,8 @@ * */ -/* - * kybd.c - * This module handles the keyboard for the 3270 emulator. +/** + * @brief This module handles the keyboard for the 3270 emulator. */ struct ta; diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c index c9ee83a..47e3673 100644 --- a/src/lib3270/paste.c +++ b/src/lib3270/paste.c @@ -320,7 +320,7 @@ LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) return 0; } - if(strlen((char *) str) > sz) + if((int) strlen((char *) str) > sz) { h->paste_buffer = strdup((char *) (str+sz)); return 1; diff --git a/src/lib3270/properties.c b/src/lib3270/properties.c new file mode 100644 index 0000000..fad4a8b --- /dev/null +++ b/src/lib3270/properties.c @@ -0,0 +1,223 @@ +/* + * "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. 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) + * + */ + +/** + * @brief This module handles the properties get/set methods. + */ + + #include + #include "private.h" + #include + #include + #include + + static const LIB3270_INT_PROPERTY properties[] = { + + { + "ready", ///< Property name. + N_( "" ), ///< Property description. + lib3270_is_ready, ///< Get value. + NULL ///< Set value. + }, + + { + "connected", ///< Property name. + N_( "" ), ///< Property description. + lib3270_is_connected, ///< Get value. + lib3270_set_connected ///< Set value. + }, + + { + "secure", ///< Property name. + N_( "" ), ///< Property description. + lib3270_is_secure, ///< Get value. + NULL ///< Set value. + }, + + { + "tso", ///< Property name. + N_( "Non zero if the host is TSO." ), ///< Property description. + lib3270_is_tso, ///< Get value. + NULL ///< Set value. + }, + + { + "pconnected", ///< Property name. + N_( "" ), ///< Property description. + lib3270_pconnected, ///< Get value. + NULL ///< Set value. + }, + + { + "half_connected", ///< Property name. + N_( "" ), ///< Property description. + lib3270_half_connected, ///< Get value. + NULL ///< Set value. + }, + + { + "neither", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_neither, ///< Get value. + NULL ///< Set value. + }, + + { + "ansi", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_ansi, ///< Get value. + NULL ///< Set value. + }, + + { + "3270", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_3270, ///< Get value. + NULL ///< Set value. + }, + + { + "sscp", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_sscp, ///< Get value. + NULL ///< Set value. + }, + + { + "tn3270e", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_tn3270e, ///< Get value. + NULL ///< Set value. + }, + + { + "e", ///< Property name. + N_( "" ), ///< Property description. + lib3270_in_e, ///< Get value. + NULL ///< Set value. + }, + + /* + { + "", ///< Property name. + N_( "" ), ///< Property description. + NULL, ///< Get value. + NULL ///< Set value. + }, + */ + + { + NULL, + NULL, + NULL, + NULL + } + }; + + int lib3270_set_connected(H3270 *hSession, int state) { + + if(state) { + + if(lib3270_connect(hSession,120)) + return -1; + + } else { + + return lib3270_disconnect(hSession); + } + + return 0; + } + + const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { + return properties; + } + +int lib3270_get_property(H3270 *hSession, const char *name, int seconds) +{ + size_t ix; + + if(seconds) + { + lib3270_wait_for_ready(hSession, seconds); + } + + for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) + { + if(!strcasecmp(name,properties[ix].name)) + { + if(properties[ix].get) + { + return properties[ix].get(hSession); + } + else + { + errno = EPERM; + return -1; + } + } + + + } + + errno = ENOENT; + return -1; +} + +int lib3270_set_property(H3270 *hSession, const char *name, int value, int seconds) +{ + size_t ix; + + if(seconds) + { + lib3270_wait_for_ready(hSession, seconds); + } + + for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) + { + if(!strcasecmp(name,properties[ix].name)) + { + if(properties[ix].set) + { + return properties[ix].set(hSession, value); + } + else + { + errno = EPERM; + return -1; + } + } + + } + + errno = ENOENT; + return -1; + +} + diff --git a/src/lib3270/ssl.c b/src/lib3270/ssl.c index cb9b079..c1b5032 100644 --- a/src/lib3270/ssl.c +++ b/src/lib3270/ssl.c @@ -220,7 +220,7 @@ int ssl_negotiate(H3270 *hSession) /* Tell the world that we are (still) connected, now in secure mode. */ - lib3270_set_connected(hSession); + lib3270_set_connected_initial(hSession); non_blocking(hSession,True); return 0; diff --git a/src/lib3270/state.c b/src/lib3270/state.c index 4ce089c..a76bf15 100644 --- a/src/lib3270/state.c +++ b/src/lib3270/state.c @@ -33,74 +33,134 @@ LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return h->cstate; } LIB3270_EXPORT int lib3270_pconnected(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (((int) h->cstate) >= (int)LIB3270_RESOLVING); } LIB3270_EXPORT int lib3270_half_connected(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_RESOLVING || h->cstate == LIB3270_PENDING); } LIB3270_EXPORT int lib3270_connected(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL); } LIB3270_EXPORT int lib3270_disconnected(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return ((int) h->cstate == (int)LIB3270_NOT_CONNECTED); } LIB3270_EXPORT int lib3270_in_neither(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_INITIAL); } LIB3270_EXPORT int lib3270_in_ansi(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_ANSI || h->cstate == LIB3270_CONNECTED_NVT); } LIB3270_EXPORT int lib3270_in_3270(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_3270 || h->cstate == LIB3270_CONNECTED_TN3270E || h->cstate == LIB3270_CONNECTED_SSCP); } LIB3270_EXPORT int lib3270_in_sscp(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_SSCP); } LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_TN3270E); } LIB3270_EXPORT int lib3270_is_connected(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate == LIB3270_CONNECTED_TN3270E); } LIB3270_EXPORT int lib3270_in_e(H3270 *h) { - CHECK_SESSION_HANDLE(h); + if(!h) + { + errno = EINVAL; + return -1; + } + return (h->cstate >= LIB3270_CONNECTED_INITIAL_E); } diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 48c40e2..79a20ea 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -889,7 +889,7 @@ static void connection_complete(H3270 *session) host_disconnect(session,True); return; } - lib3270_set_connected(session); + lib3270_set_connected_initial(session); net_connected(session); } @@ -1082,7 +1082,7 @@ void net_input(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag unused, void host_disconnect(hSession,True); return; } - lib3270_set_connected(hSession); + lib3270_set_connected_initial(hSession); if(net_connected(hSession)) return; } diff --git a/src/lib3270/testprogram/testprogram.c b/src/lib3270/testprogram/testprogram.c index 005c914..09ef26f 100644 --- a/src/lib3270/testprogram/testprogram.c +++ b/src/lib3270/testprogram/testprogram.c @@ -20,7 +20,7 @@ int main(int numpar, char *param[]) // lib3270_set_toggle(session,LIB3270_TOGGLE_DS_TRACE,1); lib3270_set_url(h,url ? url : "tn3270://fandezhi.efglobe.com"); - rc = lib3270_connect(h,1); + rc = lib3270_connect(h,120); printf("\nConnect exits with rc=%d\n",rc); -- libgit2 0.21.2