Commit 9c7e012d8847bc68178ae1bcd37f230ea4148cbe
1 parent
1fcc324e
Exists in
master
and in
3 other branches
+ Adding getter/setter methods
+ lib3270_connect now receives the time to wait for connection (in seconds).
Showing
14 changed files
with
414 additions
and
141 deletions
Show diff stats
lib3270.cbp
| ... | ... | @@ -37,9 +37,6 @@ |
| 37 | 37 | <Unit filename="LICENCA" /> |
| 38 | 38 | <Unit filename="LICENSE" /> |
| 39 | 39 | <Unit filename="README.md" /> |
| 40 | - <Unit filename="X3270.xad" /> | |
| 41 | - <Unit filename="config.status" /> | |
| 42 | - <Unit filename="configure" /> | |
| 43 | 40 | <Unit filename="configure.ac" /> |
| 44 | 41 | <Unit filename="gitsync.sh" /> |
| 45 | 42 | <Unit filename="src/include/3270ds.h" /> |
| ... | ... | @@ -76,6 +73,7 @@ |
| 76 | 73 | <Unit filename="src/include/lib3270/log.h" /> |
| 77 | 74 | <Unit filename="src/include/lib3270/macros.h" /> |
| 78 | 75 | <Unit filename="src/include/lib3270/popup.h" /> |
| 76 | + <Unit filename="src/include/lib3270/properties.h" /> | |
| 79 | 77 | <Unit filename="src/include/lib3270/selection.h" /> |
| 80 | 78 | <Unit filename="src/include/lib3270/session.h" /> |
| 81 | 79 | <Unit filename="src/include/lib3270/trace.h" /> |
| ... | ... | @@ -181,6 +179,9 @@ |
| 181 | 179 | <Option compilerVar="CC" /> |
| 182 | 180 | </Unit> |
| 183 | 181 | <Unit filename="src/lib3270/private.h" /> |
| 182 | + <Unit filename="src/lib3270/properties.c"> | |
| 183 | + <Option compilerVar="CC" /> | |
| 184 | + </Unit> | |
| 184 | 185 | <Unit filename="src/lib3270/resolver.c"> |
| 185 | 186 | <Option compilerVar="CC" /> |
| 186 | 187 | </Unit> | ... | ... |
src/include/api.h
| ... | ... | @@ -106,53 +106,6 @@ |
| 106 | 106 | #endif |
| 107 | 107 | */ |
| 108 | 108 | |
| 109 | - /** 3270 connection handle */ | |
| 110 | -// #define LUNAME_SIZE 16 | |
| 111 | -// #define FULL_MODEL_NAME_SIZE 13 | |
| 112 | - | |
| 113 | -// #define ST_RESOLVING LIB3270_STATE_RESOLVING | |
| 114 | -// #define ST_HALF_CONNECT LIB3270_STATE_HALF_CONNECT | |
| 115 | -// #define ST_CONNECT LIB3270_STATE_CONNECT | |
| 116 | -// #define ST_3270_MODE LIB3270_STATE_3270_MODE | |
| 117 | -// #define ST_LINE_MODE LIB3270_STATE_LINE_MODE | |
| 118 | -// #define ST_REMODEL LIB3270_STATE_REMODEL | |
| 119 | -// #define ST_PRINTER LIB3270_STATE_PRINTER | |
| 120 | -// #define ST_EXITING LIB3270_STATE_EXITING | |
| 121 | -// #define ST_CHARSET LIB3270_STATE_CHARSET | |
| 122 | -// #define N_ST LIB3270_STATE_USER | |
| 123 | -// #define LIB3270_STATE_CHANGE LIB3270_STATE | |
| 124 | - | |
| 125 | - /** connection state */ | |
| 126 | -// #define cstate LIB3270_CSTATE | |
| 127 | -// #define NOT_CONNECTED LIB3270_NOT_CONNECTED | |
| 128 | -// #define RESOLVING LIB3270_RESOLVING | |
| 129 | -// #define PENDING LIB3270_PENDING | |
| 130 | -// #define CONNECTED_INITIAL LIB3270_CONNECTED_INITIAL | |
| 131 | -// #define CONNECTED_ANSI LIB3270_CONNECTED_ANSI | |
| 132 | -// #define CONNECTED_3270 LIB3270_CONNECTED_3270 | |
| 133 | -// #define CONNECTED_INITIAL_E LIB3270_CONNECTED_INITIAL_E | |
| 134 | -// #define CONNECTED_NVT LIB3270_CONNECTED_NVT | |
| 135 | -// #define CONNECTED_SSCP LIB3270_CONNECTED_SSCP | |
| 136 | -// #define CONNECTED_TN3270E LIB3270_CONNECTED_TN3270E | |
| 137 | - | |
| 138 | -// #define LIB3270_STATUS LIB3270_MESSAGE | |
| 139 | -// #define LIB3270_STATUS_BLANK LIB3270_MESSAGE_NONE | |
| 140 | -// #define LIB3270_STATUS_SYSWAIT LIB3270_MESSAGE_SYSWAIT | |
| 141 | -// #define LIB3270_STATUS_TWAIT LIB3270_MESSAGE_TWAIT | |
| 142 | -// #define LIB3270_STATUS_CONNECTED LIB3270_MESSAGE_CONNECTED | |
| 143 | -// #define LIB3270_STATUS_DISCONNECTED LIB3270_MESSAGE_DISCONNECTED | |
| 144 | -// #define LIB3270_STATUS_AWAITING_FIRST LIB3270_MESSAGE_AWAITING_FIRST | |
| 145 | -// #define LIB3270_MESSAGE_MINUS LIB3270_MESSAGE_MINUS | |
| 146 | -// #define LIB3270_STATUS_PROTECTED LIB3270_MESSAGE_PROTECTED | |
| 147 | -// #define LIB3270_STATUS_NUMERIC LIB3270_MESSAGE_NUMERIC | |
| 148 | -// #define LIB3270_STATUS_OVERFLOW LIB3270_MESSAGE_OVERFLOW | |
| 149 | -// #define LIB3270_STATUS_INHIBIT LIB3270_MESSAGE_INHIBIT | |
| 150 | -// #define LIB3270_STATUS_KYBDLOCK LIB3270_MESSAGE_KYBDLOCK | |
| 151 | -// #define LIB3270_STATUS_X LIB3270_MESSAGE_X | |
| 152 | -// #define LIB3270_MESSAGE_RESOLVING LIB3270_MESSAGE_RESOLVING | |
| 153 | -// #define LIB3270_STATUS_CONNECTING LIB3270_MESSAGE_CONNECTING | |
| 154 | -// #define LIB3270_STATUS_USER LIB3270_MESSAGE_USER | |
| 155 | - | |
| 156 | 109 | #define OIA_FLAG_BOXSOLID LIB3270_FLAG_BOXSOLID |
| 157 | 110 | #define OIA_FLAG_UNDERA LIB3270_FLAG_UNDERA |
| 158 | 111 | #define OIA_FLAG_TYPEAHEAD LIB3270_FLAG_TYPEAHEAD |
| ... | ... | @@ -190,16 +143,6 @@ |
| 190 | 143 | #define CS_DBCS 0x03 /**< DBCS character set (X'F8') */ |
| 191 | 144 | #define CS_GE 0x04 /**< cs flag for Graphic Escape */ |
| 192 | 145 | |
| 193 | - /** | |
| 194 | - * Return a "malloced" copy of the device buffer, set number of elements | |
| 195 | - */ | |
| 196 | -// LOCAL_EXTERN struct ea * copy_device_buffer(int *el); | |
| 197 | - | |
| 198 | - /** | |
| 199 | - * Set the contents of the device buffer for debugging purposes | |
| 200 | - */ | |
| 201 | -// LOCAL_EXTERN int set_device_buffer(struct ea *src, int el); | |
| 202 | - | |
| 203 | 146 | /* File transfer */ |
| 204 | 147 | |
| 205 | 148 | #define FT_RECORD_FORMAT_FIXED LIB3270_FT_RECORD_FORMAT_FIXED |
| ... | ... | @@ -218,25 +161,7 @@ |
| 218 | 161 | #define FT_ABORT_WAIT LIB3270_FT_STATE_ABORT_WAIT |
| 219 | 162 | #define FT_ABORT_SENT LIB3270_FT_STATE_ABORT_SENT |
| 220 | 163 | |
| 221 | -// LOCAL_EXTERN int BeginFileTransfer(unsigned short flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft); | |
| 222 | 164 | LOCAL_EXTERN int CancelFileTransfer(int force); |
| 223 | -// LOCAL_EXTERN enum ft_state GetFileTransferState(void); | |
| 224 | - | |
| 225 | -/* | |
| 226 | - struct filetransfer_callbacks | |
| 227 | - { | |
| 228 | - unsigned short sz; | |
| 229 | - | |
| 230 | - void (*begin)(unsigned short flags, const char *local, const char *remote); | |
| 231 | - void (*complete)(const char *errmsg,unsigned long length,double kbytes_sec,const char *mode); | |
| 232 | - void (*update)(unsigned long length,unsigned long total,double kbytes_sec); | |
| 233 | - void (*running)(int is_cut); | |
| 234 | - void (*aborting)(void); | |
| 235 | - | |
| 236 | - }; | |
| 237 | - | |
| 238 | - LOCAL_EXTERN int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk); | |
| 239 | -*/ | |
| 240 | 165 | |
| 241 | 166 | #define PCONNECTED lib3270_pconnected(hSession) |
| 242 | 167 | #define HALF_CONNECTED lib3270_half_connected(hSession) |
| ... | ... | @@ -249,19 +174,8 @@ |
| 249 | 174 | #define IN_TN3270E lib3270_in_tn3270e(hSession) |
| 250 | 175 | #define IN_E lib3270_in_e(hSession) |
| 251 | 176 | |
| 252 | - #ifndef LIB3270 | |
| 253 | - | |
| 254 | -// LOCAL_EXTERN enum ft_state QueryFTstate(void); | |
| 255 | - | |
| 256 | - #endif | |
| 257 | - | |
| 258 | - | |
| 259 | 177 | /* Screen processing */ |
| 260 | 178 | |
| 261 | -// #define CURSOR_MODE_NORMAL LIB3270_CURSOR_EDITABLE | |
| 262 | -// #define CURSOR_MODE_WAITING LIB3270_CURSOR_WAITING | |
| 263 | -// #define CURSOR_MODE_LOCKED LIB3270_CURSOR_LOCKED | |
| 264 | - | |
| 265 | 179 | typedef enum _SCRIPT_STATE |
| 266 | 180 | { |
| 267 | 181 | SCRIPT_STATE_NONE, |
| ... | ... | @@ -287,7 +201,6 @@ |
| 287 | 201 | #define COLOR_ATTR_NONE 0x0000 |
| 288 | 202 | #define COLOR_ATTR_FIELD LIB3270_ATTR_FIELD |
| 289 | 203 | #define COLOR_ATTR_BLINK LIB3270_ATTR_BLINK |
| 290 | -// #define COLOR_ATTR_UNDERLINE LIB3270_ATTR_UNDERLINE | |
| 291 | 204 | #define COLOR_ATTR_INTENSIFY LIB3270_ATTR_INTENSIFY |
| 292 | 205 | |
| 293 | 206 | #define CHAR_ATTR_UNCONVERTED LIB3270_ATTR_CG |
| ... | ... | @@ -298,27 +211,19 @@ |
| 298 | 211 | #define find_field_length(s,a) find_field_length(s,a) |
| 299 | 212 | |
| 300 | 213 | LOCAL_EXTERN unsigned char get_field_attribute(H3270 *session, int baddr); |
| 301 | -// LOCAL_EXTERN int screen_read(char *dest, int baddr, int count); | |
| 302 | 214 | LOCAL_EXTERN void Input_String(const unsigned char *str); |
| 303 | 215 | LOCAL_EXTERN void screen_size(int *rows, int *cols); |
| 304 | 216 | |
| 305 | -// #define query_secure_connection(h) lib3270_get_ssl_state(h) | |
| 306 | 217 | #define lib3270_paste_string(str) lib3270_set_string(NULL,str) |
| 307 | 218 | #define get_3270_terminal_size(h,r,c) lib3270_get_screen_size(h,r,c) |
| 308 | 219 | |
| 309 | 220 | /* Keyboard */ |
| 310 | 221 | LOCAL_EXTERN int emulate_input(char *s, int len, int pasting); |
| 311 | 222 | |
| 312 | - /* Network related calls */ | |
| 313 | -// LOCAL_EXTERN int Get3270Socket(void); | |
| 314 | - | |
| 315 | 223 | /* Misc calls */ |
| 316 | 224 | |
| 317 | 225 | #define query_3270_terminal_status(void) lib3270_get_program_message(NULL) |
| 318 | 226 | |
| 319 | -// #define set_3270_model(h,m) lib3270_set_model(h,m) | |
| 320 | -// #define get_3270_model(h) lib3270_get_model(h) | |
| 321 | - | |
| 322 | 227 | /* Get connection info */ |
| 323 | 228 | #define get_connected_lu(h) lib3270_get_luname(h) |
| 324 | 229 | |
| ... | ... | @@ -326,10 +231,6 @@ |
| 326 | 231 | |
| 327 | 232 | #include <lib3270/actions.h> |
| 328 | 233 | |
| 329 | - // #define host_connect(n,wait) lib3270_connect(NULL,n,wait) | |
| 330 | - // #define host_reconnect(w) lib3270_reconnect(NULL,w) | |
| 331 | - | |
| 332 | - | |
| 333 | 234 | #ifdef __cplusplus |
| 334 | 235 | } |
| 335 | 236 | #endif | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -513,13 +513,15 @@ |
| 513 | 513 | /** |
| 514 | 514 | * @brief Network connect operation, keep main loop running |
| 515 | 515 | * |
| 516 | - * @param h Session handle. | |
| 517 | - * @param wait Non zero to wait for connection to be ok. | |
| 516 | + * @param h Session handle. | |
| 517 | + * @param seconds Seconds to wait for connection . | |
| 518 | 518 | * |
| 519 | 519 | * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure. |
| 520 | 520 | * |
| 521 | 521 | */ |
| 522 | - LIB3270_EXPORT int lib3270_connect(H3270 *h,int wait); | |
| 522 | + LIB3270_EXPORT int lib3270_connect(H3270 *h,int seconds); | |
| 523 | + | |
| 524 | + LIB3270_EXPORT int lib3270_set_connected(H3270 *h,int state); | |
| 523 | 525 | |
| 524 | 526 | /** |
| 525 | 527 | * @brief Connect to defined host, keep main loop running. |
| ... | ... | @@ -927,7 +929,6 @@ |
| 927 | 929 | */ |
| 928 | 930 | LIB3270_EXPORT void lib3270_ring_bell(H3270 *session); |
| 929 | 931 | |
| 930 | - | |
| 931 | 932 | /** |
| 932 | 933 | * Get lib3270's charset. |
| 933 | 934 | * | ... | ... |
src/include/lib3270/internals.h
| ... | ... | @@ -36,7 +36,7 @@ |
| 36 | 36 | |
| 37 | 37 | LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf); |
| 38 | 38 | LIB3270_EXPORT void lib3270_set_disconnected(H3270 *hSession); |
| 39 | - LIB3270_EXPORT void lib3270_set_connected(H3270 *hSession); | |
| 39 | + LIB3270_EXPORT void lib3270_set_connected_initial(H3270 *hSession); | |
| 40 | 40 | LIB3270_EXPORT void lib3270_setup_session(H3270 *session); |
| 41 | 41 | |
| 42 | 42 | ... | ... |
| ... | ... | @@ -0,0 +1,90 @@ |
| 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 -.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 | + /** | |
| 31 | + * @brief TN3270 Session properties. | |
| 32 | + * | |
| 33 | + * @author perry.werneck@gmail.com | |
| 34 | + * | |
| 35 | + */ | |
| 36 | + | |
| 37 | +#ifndef LIB3270_PROPERTIES_H_INCLUDED | |
| 38 | + | |
| 39 | + #define LIB3270_PROPERTIES_H_INCLUDED | |
| 40 | + | |
| 41 | +#ifdef __cplusplus | |
| 42 | + extern "C" { | |
| 43 | +#endif | |
| 44 | + | |
| 45 | + typedef struct _lib3270_int_property | |
| 46 | + { | |
| 47 | + const char * name; ///< @brief Property name. | |
| 48 | + const char * description; ///< @brief Property description. | |
| 49 | + int (*get)(H3270 *hSession); ///< @brief Get value. | |
| 50 | + int (*set)(H3270 *hSession, int value); ///< @brief Set value. | |
| 51 | + | |
| 52 | + } LIB3270_INT_PROPERTY; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @brief Get lib3270 integer properties table. | |
| 56 | + * | |
| 57 | + * @return The properties table. | |
| 58 | + * | |
| 59 | + */ | |
| 60 | + LIB3270_EXPORT const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @brief Get lib3270 property by name. | |
| 64 | + * | |
| 65 | + * @param name Nome of the property. | |
| 66 | + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). | |
| 67 | + * | |
| 68 | + * @return Property value or -1 in case of error (sets errno). | |
| 69 | + * | |
| 70 | + */ | |
| 71 | + LIB3270_EXPORT int lib3270_get_property(H3270 * hSession, const char *name, int seconds); | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * @brief Set lib3270 property by name. | |
| 75 | + * | |
| 76 | + * @param name Nome of the property. | |
| 77 | + * @param value New property value. | |
| 78 | + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). | |
| 79 | + * | |
| 80 | + * @return 0 if ok, -1 in case of error (sets errno). | |
| 81 | + * | |
| 82 | + */ | |
| 83 | + LIB3270_EXPORT int lib3270_set_property(H3270 * hSession, const char *name, int value, int seconds); | |
| 84 | + | |
| 85 | +#ifdef __cplusplus | |
| 86 | + } | |
| 87 | +#endif | |
| 88 | + | |
| 89 | +#endif // LIB3270_PROPERTIES_H_INCLUDED | |
| 90 | + | ... | ... |
src/lib3270/connect.c
| ... | ... | @@ -137,9 +137,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 137 | 137 | #endif |
| 138 | 138 | |
| 139 | 139 | lib3270_setup_session(hSession); |
| 140 | - | |
| 141 | - | |
| 142 | - lib3270_set_connected(hSession); | |
| 140 | + lib3270_set_connected_initial(hSession); | |
| 143 | 141 | |
| 144 | 142 | } |
| 145 | 143 | |
| ... | ... | @@ -239,7 +237,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 239 | 237 | |
| 240 | 238 | } |
| 241 | 239 | |
| 242 | - int lib3270_connect(H3270 *hSession, int wait) | |
| 240 | + int lib3270_connect(H3270 *hSession, int seconds) | |
| 243 | 241 | { |
| 244 | 242 | int s; |
| 245 | 243 | int optval; |
| ... | ... | @@ -252,10 +250,10 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 252 | 250 | lib3270_main_iterate(hSession,0); |
| 253 | 251 | |
| 254 | 252 | if(hSession->auto_reconnect_inprogress) |
| 255 | - return EAGAIN; | |
| 253 | + return errno = EAGAIN; | |
| 256 | 254 | |
| 257 | 255 | if(hSession->sock > 0) |
| 258 | - return EBUSY; | |
| 256 | + return errno = EBUSY; | |
| 259 | 257 | |
| 260 | 258 | #if defined(_WIN32) |
| 261 | 259 | sockstart(hSession); |
| ... | ... | @@ -325,7 +323,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 325 | 323 | |
| 326 | 324 | |
| 327 | 325 | lib3270_set_disconnected(hSession); |
| 328 | - return ENOENT; | |
| 326 | + return errno = ENOENT; | |
| 329 | 327 | } |
| 330 | 328 | |
| 331 | 329 | |
| ... | ... | @@ -350,7 +348,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 350 | 348 | _( "This version of %s was built without support for secure sockets layer (SSL)." ), |
| 351 | 349 | PACKAGE_NAME); |
| 352 | 350 | |
| 353 | - return EINVAL; | |
| 351 | + return errno = EINVAL; | |
| 354 | 352 | #endif // HAVE_LIBSSL |
| 355 | 353 | } |
| 356 | 354 | |
| ... | ... | @@ -507,7 +505,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 507 | 505 | if(hSession->sock < 0) |
| 508 | 506 | { |
| 509 | 507 | lib3270_set_disconnected(hSession); |
| 510 | - return ENOTCONN; | |
| 508 | + return errno = ENOTCONN; | |
| 511 | 509 | } |
| 512 | 510 | |
| 513 | 511 | // Connecting, set callbacks, wait for connection |
| ... | ... | @@ -519,9 +517,9 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 519 | 517 | |
| 520 | 518 | trace("%s: Connection in progress",__FUNCTION__); |
| 521 | 519 | |
| 522 | - if(wait) | |
| 520 | + if(seconds) | |
| 523 | 521 | { |
| 524 | - time_t end = time(0)+120; | |
| 522 | + time_t end = time(0)+seconds; | |
| 525 | 523 | |
| 526 | 524 | while(time(0) < end) |
| 527 | 525 | { |
| ... | ... | @@ -539,7 +537,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 539 | 537 | break; |
| 540 | 538 | |
| 541 | 539 | case LIB3270_NOT_CONNECTED: |
| 542 | - return ENOTCONN; | |
| 540 | + return errno = ENOTCONN; | |
| 543 | 541 | |
| 544 | 542 | case LIB3270_CONNECTED_TN3270E: |
| 545 | 543 | return 0; |
| ... | ... | @@ -553,7 +551,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d |
| 553 | 551 | |
| 554 | 552 | lib3270_disconnect(hSession); |
| 555 | 553 | lib3270_write_log(hSession,"connect", "%s",__FUNCTION__,strerror(ETIMEDOUT)); |
| 556 | - return ETIMEDOUT; | |
| 554 | + return errno = ETIMEDOUT; | |
| 557 | 555 | } |
| 558 | 556 | |
| 559 | 557 | return 0; | ... | ... |
src/lib3270/host.c
| ... | ... | @@ -127,7 +127,7 @@ void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) |
| 127 | 127 | lib3270_st_changed(hSession, LIB3270_STATE_3270_MODE, now3270); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -void lib3270_set_connected(H3270 *hSession) | |
| 130 | +void lib3270_set_connected_initial(H3270 *hSession) | |
| 131 | 131 | { |
| 132 | 132 | hSession->cstate = LIB3270_CONNECTED_INITIAL; |
| 133 | 133 | hSession->starting = 1; // Enable autostart | ... | ... |
src/lib3270/kybd.c
src/lib3270/paste.c
| ... | ... | @@ -0,0 +1,223 @@ |
| 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. 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 | +/** | |
| 31 | + * @brief This module handles the properties get/set methods. | |
| 32 | + */ | |
| 33 | + | |
| 34 | + #include <config.h> | |
| 35 | + #include "private.h" | |
| 36 | + #include <string.h> | |
| 37 | + #include <lib3270.h> | |
| 38 | + #include <lib3270/properties.h> | |
| 39 | + | |
| 40 | + static const LIB3270_INT_PROPERTY properties[] = { | |
| 41 | + | |
| 42 | + { | |
| 43 | + "ready", ///< Property name. | |
| 44 | + N_( "" ), ///< Property description. | |
| 45 | + lib3270_is_ready, ///< Get value. | |
| 46 | + NULL ///< Set value. | |
| 47 | + }, | |
| 48 | + | |
| 49 | + { | |
| 50 | + "connected", ///< Property name. | |
| 51 | + N_( "" ), ///< Property description. | |
| 52 | + lib3270_is_connected, ///< Get value. | |
| 53 | + lib3270_set_connected ///< Set value. | |
| 54 | + }, | |
| 55 | + | |
| 56 | + { | |
| 57 | + "secure", ///< Property name. | |
| 58 | + N_( "" ), ///< Property description. | |
| 59 | + lib3270_is_secure, ///< Get value. | |
| 60 | + NULL ///< Set value. | |
| 61 | + }, | |
| 62 | + | |
| 63 | + { | |
| 64 | + "tso", ///< Property name. | |
| 65 | + N_( "Non zero if the host is TSO." ), ///< Property description. | |
| 66 | + lib3270_is_tso, ///< Get value. | |
| 67 | + NULL ///< Set value. | |
| 68 | + }, | |
| 69 | + | |
| 70 | + { | |
| 71 | + "pconnected", ///< Property name. | |
| 72 | + N_( "" ), ///< Property description. | |
| 73 | + lib3270_pconnected, ///< Get value. | |
| 74 | + NULL ///< Set value. | |
| 75 | + }, | |
| 76 | + | |
| 77 | + { | |
| 78 | + "half_connected", ///< Property name. | |
| 79 | + N_( "" ), ///< Property description. | |
| 80 | + lib3270_half_connected, ///< Get value. | |
| 81 | + NULL ///< Set value. | |
| 82 | + }, | |
| 83 | + | |
| 84 | + { | |
| 85 | + "neither", ///< Property name. | |
| 86 | + N_( "" ), ///< Property description. | |
| 87 | + lib3270_in_neither, ///< Get value. | |
| 88 | + NULL ///< Set value. | |
| 89 | + }, | |
| 90 | + | |
| 91 | + { | |
| 92 | + "ansi", ///< Property name. | |
| 93 | + N_( "" ), ///< Property description. | |
| 94 | + lib3270_in_ansi, ///< Get value. | |
| 95 | + NULL ///< Set value. | |
| 96 | + }, | |
| 97 | + | |
| 98 | + { | |
| 99 | + "3270", ///< Property name. | |
| 100 | + N_( "" ), ///< Property description. | |
| 101 | + lib3270_in_3270, ///< Get value. | |
| 102 | + NULL ///< Set value. | |
| 103 | + }, | |
| 104 | + | |
| 105 | + { | |
| 106 | + "sscp", ///< Property name. | |
| 107 | + N_( "" ), ///< Property description. | |
| 108 | + lib3270_in_sscp, ///< Get value. | |
| 109 | + NULL ///< Set value. | |
| 110 | + }, | |
| 111 | + | |
| 112 | + { | |
| 113 | + "tn3270e", ///< Property name. | |
| 114 | + N_( "" ), ///< Property description. | |
| 115 | + lib3270_in_tn3270e, ///< Get value. | |
| 116 | + NULL ///< Set value. | |
| 117 | + }, | |
| 118 | + | |
| 119 | + { | |
| 120 | + "e", ///< Property name. | |
| 121 | + N_( "" ), ///< Property description. | |
| 122 | + lib3270_in_e, ///< Get value. | |
| 123 | + NULL ///< Set value. | |
| 124 | + }, | |
| 125 | + | |
| 126 | + /* | |
| 127 | + { | |
| 128 | + "", ///< Property name. | |
| 129 | + N_( "" ), ///< Property description. | |
| 130 | + NULL, ///< Get value. | |
| 131 | + NULL ///< Set value. | |
| 132 | + }, | |
| 133 | + */ | |
| 134 | + | |
| 135 | + { | |
| 136 | + NULL, | |
| 137 | + NULL, | |
| 138 | + NULL, | |
| 139 | + NULL | |
| 140 | + } | |
| 141 | + }; | |
| 142 | + | |
| 143 | + int lib3270_set_connected(H3270 *hSession, int state) { | |
| 144 | + | |
| 145 | + if(state) { | |
| 146 | + | |
| 147 | + if(lib3270_connect(hSession,120)) | |
| 148 | + return -1; | |
| 149 | + | |
| 150 | + } else { | |
| 151 | + | |
| 152 | + return lib3270_disconnect(hSession); | |
| 153 | + } | |
| 154 | + | |
| 155 | + return 0; | |
| 156 | + } | |
| 157 | + | |
| 158 | + const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { | |
| 159 | + return properties; | |
| 160 | + } | |
| 161 | + | |
| 162 | +int lib3270_get_property(H3270 *hSession, const char *name, int seconds) | |
| 163 | +{ | |
| 164 | + size_t ix; | |
| 165 | + | |
| 166 | + if(seconds) | |
| 167 | + { | |
| 168 | + lib3270_wait_for_ready(hSession, seconds); | |
| 169 | + } | |
| 170 | + | |
| 171 | + for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) | |
| 172 | + { | |
| 173 | + if(!strcasecmp(name,properties[ix].name)) | |
| 174 | + { | |
| 175 | + if(properties[ix].get) | |
| 176 | + { | |
| 177 | + return properties[ix].get(hSession); | |
| 178 | + } | |
| 179 | + else | |
| 180 | + { | |
| 181 | + errno = EPERM; | |
| 182 | + return -1; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + | |
| 186 | + | |
| 187 | + } | |
| 188 | + | |
| 189 | + errno = ENOENT; | |
| 190 | + return -1; | |
| 191 | +} | |
| 192 | + | |
| 193 | +int lib3270_set_property(H3270 *hSession, const char *name, int value, int seconds) | |
| 194 | +{ | |
| 195 | + size_t ix; | |
| 196 | + | |
| 197 | + if(seconds) | |
| 198 | + { | |
| 199 | + lib3270_wait_for_ready(hSession, seconds); | |
| 200 | + } | |
| 201 | + | |
| 202 | + for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) | |
| 203 | + { | |
| 204 | + if(!strcasecmp(name,properties[ix].name)) | |
| 205 | + { | |
| 206 | + if(properties[ix].set) | |
| 207 | + { | |
| 208 | + return properties[ix].set(hSession, value); | |
| 209 | + } | |
| 210 | + else | |
| 211 | + { | |
| 212 | + errno = EPERM; | |
| 213 | + return -1; | |
| 214 | + } | |
| 215 | + } | |
| 216 | + | |
| 217 | + } | |
| 218 | + | |
| 219 | + errno = ENOENT; | |
| 220 | + return -1; | |
| 221 | + | |
| 222 | +} | |
| 223 | + | ... | ... |
src/lib3270/ssl.c
| ... | ... | @@ -220,7 +220,7 @@ int ssl_negotiate(H3270 *hSession) |
| 220 | 220 | |
| 221 | 221 | |
| 222 | 222 | /* Tell the world that we are (still) connected, now in secure mode. */ |
| 223 | - lib3270_set_connected(hSession); | |
| 223 | + lib3270_set_connected_initial(hSession); | |
| 224 | 224 | non_blocking(hSession,True); |
| 225 | 225 | |
| 226 | 226 | return 0; | ... | ... |
src/lib3270/state.c
| ... | ... | @@ -33,74 +33,134 @@ |
| 33 | 33 | |
| 34 | 34 | LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h) |
| 35 | 35 | { |
| 36 | - CHECK_SESSION_HANDLE(h); | |
| 36 | + if(!h) | |
| 37 | + { | |
| 38 | + errno = EINVAL; | |
| 39 | + return -1; | |
| 40 | + } | |
| 41 | + | |
| 37 | 42 | return h->cstate; |
| 38 | 43 | } |
| 39 | 44 | |
| 40 | 45 | LIB3270_EXPORT int lib3270_pconnected(H3270 *h) |
| 41 | 46 | { |
| 42 | - CHECK_SESSION_HANDLE(h); | |
| 47 | + if(!h) | |
| 48 | + { | |
| 49 | + errno = EINVAL; | |
| 50 | + return -1; | |
| 51 | + } | |
| 52 | + | |
| 43 | 53 | return (((int) h->cstate) >= (int)LIB3270_RESOLVING); |
| 44 | 54 | } |
| 45 | 55 | |
| 46 | 56 | LIB3270_EXPORT int lib3270_half_connected(H3270 *h) |
| 47 | 57 | { |
| 48 | - CHECK_SESSION_HANDLE(h); | |
| 58 | + if(!h) | |
| 59 | + { | |
| 60 | + errno = EINVAL; | |
| 61 | + return -1; | |
| 62 | + } | |
| 63 | + | |
| 49 | 64 | return (h->cstate == LIB3270_RESOLVING || h->cstate == LIB3270_PENDING); |
| 50 | 65 | } |
| 51 | 66 | |
| 52 | 67 | LIB3270_EXPORT int lib3270_connected(H3270 *h) |
| 53 | 68 | { |
| 54 | - CHECK_SESSION_HANDLE(h); | |
| 69 | + if(!h) | |
| 70 | + { | |
| 71 | + errno = EINVAL; | |
| 72 | + return -1; | |
| 73 | + } | |
| 74 | + | |
| 55 | 75 | return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL); |
| 56 | 76 | } |
| 57 | 77 | |
| 58 | 78 | LIB3270_EXPORT int lib3270_disconnected(H3270 *h) |
| 59 | 79 | { |
| 60 | - CHECK_SESSION_HANDLE(h); | |
| 80 | + if(!h) | |
| 81 | + { | |
| 82 | + errno = EINVAL; | |
| 83 | + return -1; | |
| 84 | + } | |
| 85 | + | |
| 61 | 86 | return ((int) h->cstate == (int)LIB3270_NOT_CONNECTED); |
| 62 | 87 | } |
| 63 | 88 | |
| 64 | 89 | |
| 65 | 90 | LIB3270_EXPORT int lib3270_in_neither(H3270 *h) |
| 66 | 91 | { |
| 67 | - CHECK_SESSION_HANDLE(h); | |
| 92 | + if(!h) | |
| 93 | + { | |
| 94 | + errno = EINVAL; | |
| 95 | + return -1; | |
| 96 | + } | |
| 97 | + | |
| 68 | 98 | return (h->cstate == LIB3270_CONNECTED_INITIAL); |
| 69 | 99 | } |
| 70 | 100 | |
| 71 | 101 | LIB3270_EXPORT int lib3270_in_ansi(H3270 *h) |
| 72 | 102 | { |
| 73 | - CHECK_SESSION_HANDLE(h); | |
| 103 | + if(!h) | |
| 104 | + { | |
| 105 | + errno = EINVAL; | |
| 106 | + return -1; | |
| 107 | + } | |
| 108 | + | |
| 74 | 109 | return (h->cstate == LIB3270_CONNECTED_ANSI || h->cstate == LIB3270_CONNECTED_NVT); |
| 75 | 110 | } |
| 76 | 111 | |
| 77 | 112 | LIB3270_EXPORT int lib3270_in_3270(H3270 *h) |
| 78 | 113 | { |
| 79 | - CHECK_SESSION_HANDLE(h); | |
| 114 | + if(!h) | |
| 115 | + { | |
| 116 | + errno = EINVAL; | |
| 117 | + return -1; | |
| 118 | + } | |
| 119 | + | |
| 80 | 120 | return (h->cstate == LIB3270_CONNECTED_3270 || h->cstate == LIB3270_CONNECTED_TN3270E || h->cstate == LIB3270_CONNECTED_SSCP); |
| 81 | 121 | } |
| 82 | 122 | |
| 83 | 123 | LIB3270_EXPORT int lib3270_in_sscp(H3270 *h) |
| 84 | 124 | { |
| 85 | - CHECK_SESSION_HANDLE(h); | |
| 125 | + if(!h) | |
| 126 | + { | |
| 127 | + errno = EINVAL; | |
| 128 | + return -1; | |
| 129 | + } | |
| 130 | + | |
| 86 | 131 | return (h->cstate == LIB3270_CONNECTED_SSCP); |
| 87 | 132 | } |
| 88 | 133 | |
| 89 | 134 | LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h) |
| 90 | 135 | { |
| 91 | - CHECK_SESSION_HANDLE(h); | |
| 136 | + if(!h) | |
| 137 | + { | |
| 138 | + errno = EINVAL; | |
| 139 | + return -1; | |
| 140 | + } | |
| 141 | + | |
| 92 | 142 | return (h->cstate == LIB3270_CONNECTED_TN3270E); |
| 93 | 143 | } |
| 94 | 144 | |
| 95 | 145 | LIB3270_EXPORT int lib3270_is_connected(H3270 *h) |
| 96 | 146 | { |
| 97 | - CHECK_SESSION_HANDLE(h); | |
| 147 | + if(!h) | |
| 148 | + { | |
| 149 | + errno = EINVAL; | |
| 150 | + return -1; | |
| 151 | + } | |
| 152 | + | |
| 98 | 153 | return (h->cstate == LIB3270_CONNECTED_TN3270E); |
| 99 | 154 | } |
| 100 | 155 | |
| 101 | 156 | LIB3270_EXPORT int lib3270_in_e(H3270 *h) |
| 102 | 157 | { |
| 103 | - CHECK_SESSION_HANDLE(h); | |
| 158 | + if(!h) | |
| 159 | + { | |
| 160 | + errno = EINVAL; | |
| 161 | + return -1; | |
| 162 | + } | |
| 163 | + | |
| 104 | 164 | return (h->cstate >= LIB3270_CONNECTED_INITIAL_E); |
| 105 | 165 | } |
| 106 | 166 | ... | ... |
src/lib3270/telnet.c
| ... | ... | @@ -889,7 +889,7 @@ static void connection_complete(H3270 *session) |
| 889 | 889 | host_disconnect(session,True); |
| 890 | 890 | return; |
| 891 | 891 | } |
| 892 | - lib3270_set_connected(session); | |
| 892 | + lib3270_set_connected_initial(session); | |
| 893 | 893 | net_connected(session); |
| 894 | 894 | } |
| 895 | 895 | |
| ... | ... | @@ -1082,7 +1082,7 @@ void net_input(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag unused, void |
| 1082 | 1082 | host_disconnect(hSession,True); |
| 1083 | 1083 | return; |
| 1084 | 1084 | } |
| 1085 | - lib3270_set_connected(hSession); | |
| 1085 | + lib3270_set_connected_initial(hSession); | |
| 1086 | 1086 | if(net_connected(hSession)) |
| 1087 | 1087 | return; |
| 1088 | 1088 | } | ... | ... |
src/lib3270/testprogram/testprogram.c
| ... | ... | @@ -20,7 +20,7 @@ int main(int numpar, char *param[]) |
| 20 | 20 | // lib3270_set_toggle(session,LIB3270_TOGGLE_DS_TRACE,1); |
| 21 | 21 | |
| 22 | 22 | lib3270_set_url(h,url ? url : "tn3270://fandezhi.efglobe.com"); |
| 23 | - rc = lib3270_connect(h,1); | |
| 23 | + rc = lib3270_connect(h,120); | |
| 24 | 24 | |
| 25 | 25 | printf("\nConnect exits with rc=%d\n",rc); |
| 26 | 26 | ... | ... |