From 627c3b9517154020dd2bc984fd04c5ee883aae8d Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 19 Apr 2016 09:42:29 -0300 Subject: [PATCH] Updating version, changing timer management, adding setting for unlock delay. --- connect.c | 2 +- ctlr.c | 6 ++++-- iocalls.c | 61 ++++++++++++++++++++++++++++++++----------------------------- kybd.c | 147 ++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------- session.c | 4 ++++ telnet.c | 4 ++-- utilc.h | 4 ++-- 7 files changed, 63 insertions(+), 165 deletions(-) diff --git a/connect.c b/connect.c index 193c92f..3f4b8ed 100644 --- a/connect.c +++ b/connect.c @@ -84,7 +84,7 @@ static void net_connected(H3270 *hSession, int fd, LIB3270_IO_FLAG flag, void *d if(hSession->ns_write_id) { trace("%s write=%p",__FUNCTION__,hSession->ns_write_id); - lib3270_remove_poll(hSession->ns_write_id); + lib3270_remove_poll(hSession, hSession->ns_write_id); hSession->ns_write_id = NULL; } diff --git a/ctlr.c b/ctlr.c index 3b21e79..569a798 100644 --- a/ctlr.c +++ b/ctlr.c @@ -2860,8 +2860,10 @@ void ticking_start(H3270 *hSession, Boolean anyway) return; status_untiming(hSession); + if (hSession->ticking) - RemoveTimeOut(hSession->tick_id); + RemoveTimeOut(hSession, hSession->tick_id); + hSession->ticking = 1; hSession->tick_id = AddTimeOut(1000, hSession, keep_ticking); hSession->t_want = hSession->t_start; @@ -2889,7 +2891,7 @@ static void ticking_stop(H3270 *hSession) if (!hSession->ticking) return; - RemoveTimeOut(hSession->tick_id); + RemoveTimeOut(hSession, hSession->tick_id); hSession->ticking = 0; status_timing(hSession,&hSession->t_start, &t1); } diff --git a/iocalls.c b/iocalls.c index f9bf97d..37613c5 100644 --- a/iocalls.c +++ b/iocalls.c @@ -45,34 +45,34 @@ /*---[ Standard calls ]-------------------------------------------------------------------------------------*/ // Timeout calls -static void internal_remove_timeout(void *timer); -static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); +static void internal_remove_timeout(H3270 *session, void *timer); +static void * internal_add_timeout(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)); static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata ); -static void internal_remove_poll(void *id); +static void internal_remove_poll(H3270 *session, void *id); -static int internal_wait(H3270 *hSession, int seconds); +static int internal_wait(H3270 *session, int seconds); -static void internal_ring_bell(H3270 *); +static void internal_ring_bell(H3270 *session); /*---[ Active callbacks ]-----------------------------------------------------------------------------------*/ - static void * (*add_timeout)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) + static void * (*add_timeout)(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)) = internal_add_timeout; - static void (*remove_timeout)(void *timer) + static void (*remove_timeout)(H3270 *session, void *timer) = internal_remove_timeout; static void * (*add_poll)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) = internal_add_poll; - static void (*remove_poll)(void *id) + static void (*remove_poll)(H3270 *session, void *id) = internal_remove_poll; - static int (*wait)(H3270 *hSession, int seconds) + static int (*wait)(H3270 *session, int seconds) = internal_wait; - static int (*event_dispatcher)(H3270 *hSession,int wait) + static int (*event_dispatcher)(H3270 *session,int wait) = lib3270_default_event_dispatcher; static void (*ring_bell)(H3270 *) @@ -134,7 +134,7 @@ static void ms_ts(unsigned long long *u) } #endif -static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) +static void * internal_add_timeout(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)) { timeout_t *t_new; timeout_t *t; @@ -199,7 +199,7 @@ static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, vo return t_new; } -static void internal_remove_timeout(void * timer) +static void internal_remove_timeout(H3270 *session, void * timer) { timeout_t *st = (timeout_t *)timer; timeout_t *t; @@ -243,7 +243,7 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo return ip; } -static void internal_remove_poll(void *id) +static void internal_remove_poll(H3270 *session, void *id) { input_t *ip; input_t *prev = (input_t *)NULL; @@ -258,7 +258,7 @@ static void internal_remove_poll(void *id) if (ip == (input_t *)NULL) { - lib3270_write_log(NULL,"lib3270","Invalid call to (%s): Input %p wasnt found in the list",__FUNCTION__,id); + lib3270_write_log(session,"lib3270","Invalid call to (%s): Input %p wasnt found in the list",__FUNCTION__,id); return; } @@ -271,12 +271,12 @@ static void internal_remove_poll(void *id) inputs_changed = True; } -LIB3270_EXPORT void lib3270_remove_poll(void *id) { +LIB3270_EXPORT void lib3270_remove_poll(H3270 *session, void *id) { debug("%s %p",__FUNCTION__,id); - remove_poll(id); + remove_poll(session, id); } -LIB3270_EXPORT void lib3270_remove_poll_fd(int fd) +LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) { input_t *ip; @@ -285,7 +285,7 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(int fd) { if(ip->fd == fd) { - remove_poll(ip); + remove_poll(session, ip); return; } } @@ -294,7 +294,7 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(int fd) } -LIB3270_EXPORT void lib3270_update_poll_fd(int fd, LIB3270_IO_FLAG flag) +LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_FLAG flag) { input_t *ip; @@ -308,7 +308,7 @@ LIB3270_EXPORT void lib3270_update_poll_fd(int fd, LIB3270_IO_FLAG flag) } } - lib3270_write_log(NULL,"iocalls","Invalid or unexpected FD on %s(%d)",__FUNCTION__,fd); + lib3270_write_log(session,"iocalls","Invalid or unexpected FD on %s(%d)",__FUNCTION__,fd); } @@ -612,15 +612,18 @@ void * AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 { void *timer; CHECK_SESSION_HANDLE(session); - timer = add_timeout(interval_ms,session,proc); + timer = add_timeout(session,interval_ms,proc); trace("Timeout %p created with %ld ms",timer,interval_ms); return timer; } -void RemoveTimeOut(void * timer) +void RemoveTimeOut(H3270 *session, void * timer) { + if(!timer) + return; + trace("Removing timeout %p",timer); - return remove_timeout(timer); + return remove_timeout(session, timer); } void x_except_on(H3270 *h) @@ -632,7 +635,7 @@ void x_except_on(H3270 *h) return; if(reading) - lib3270_remove_poll(h->ns_read_id); + lib3270_remove_poll(h,h->ns_read_id); h->ns_exception_id = lib3270_add_poll_fd(h,h->sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); @@ -646,22 +649,22 @@ void remove_input_calls(H3270 *session) { if(session->ns_read_id) { - lib3270_remove_poll(session->ns_read_id); + lib3270_remove_poll(session,session->ns_read_id); session->ns_read_id = NULL; } if(session->ns_exception_id) { - lib3270_remove_poll(session->ns_exception_id); + lib3270_remove_poll(session,session->ns_exception_id); session->ns_exception_id = NULL; } if(session->ns_write_id) { - lib3270_remove_poll(session->ns_write_id); + lib3270_remove_poll(session,session->ns_write_id); session->ns_write_id = NULL; } } -LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)), void (*rm)(void *timer)) +LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)), void (*rm)(H3270 *session, void *timer)) { if(add) add_timeout = add; @@ -671,7 +674,7 @@ LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long i } -LIB3270_EXPORT void lib3270_register_fd_handlers(void * (*add)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata), void (*rm)(void *id)) { +LIB3270_EXPORT void lib3270_register_fd_handlers(void * (*add)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata), void (*rm)(H3270 *, void *id)) { if(add) add_poll = add; diff --git a/kybd.c b/kybd.c index f3d0345..a3a779c 100644 --- a/kybd.c +++ b/kybd.c @@ -124,27 +124,6 @@ static int flush_ta(H3270 *hSession); static void key_AID(H3270 *session, unsigned char aid_code); static void kybdlock_set(H3270 *session, unsigned int bits); -/* -#if defined(X3270_DBCS) -Boolean key_WCharacter(unsigned char code[], Boolean *skipped); -#endif -*/ - -/* -static int nxk = 0; -static struct xks -{ - KeySym key; - KeySym assoc; -} *xk; -*/ - -// static Boolean reverse = False; /* reverse-input mode */ - -/* Globals */ -// unsigned int kybdlock = KL_NOT_CONNECTED; -//unsigned char aid = AID_NO; /* current attention ID */ - /* Composite key mappings. */ struct akeysym @@ -152,14 +131,6 @@ struct akeysym KeySym keysym; enum keytype keytype; }; -/* -static struct akeysym cc_first; -static struct composite { - struct akeysym k1, k2; - struct akeysym translation; -} *composites = NULL; -static int n_composites = 0; -*/ #define ak_eq(k1, k2) (((k1).keysym == (k2).keysym) && \ ((k1).keytype == (k2).keytype)) @@ -180,12 +151,6 @@ struct ta unsigned char aid_code; }; -/* -*ta_head = (struct ta *) NULL, - *ta_tail = (struct ta *) NULL; -*/ - - #if defined(DEBUG) #define ENQUEUE_ACTION(x) enq_ta(hSession, (void (*)(H3270 *, const char *, const char *)) x, NULL, NULL, #x) #else @@ -445,7 +410,7 @@ void kybd_inhibit(H3270 *session, Boolean inhibit) void kybd_connect(H3270 *session, int connected, void *dunno) { if (session->kybdlock & KL_DEFERRED_UNLOCK) - RemoveTimeOut(session->unlock_id); + RemoveTimeOut(session, session->unlock_id); lib3270_kybdlock_clear(session, -1); @@ -467,7 +432,8 @@ void kybd_connect(H3270 *session, int connected, void *dunno) void kybd_in3270(H3270 *hSession, int in3270 unused, void *dunno) { if (hSession->kybdlock & KL_DEFERRED_UNLOCK) - RemoveTimeOut(hSession->unlock_id); + RemoveTimeOut(hSession, hSession->unlock_id); + lib3270_kybdlock_clear(hSession,~KL_AWAITING_FIRST); /* There might be a macro pending. */ @@ -1185,7 +1151,7 @@ void do_reset(H3270 *hSession, Boolean explicit) * keyboard now, or want to defer further into the future. */ if (hSession->kybdlock & KL_DEFERRED_UNLOCK) - RemoveTimeOut(hSession->unlock_id); + RemoveTimeOut(hSession, hSession->unlock_id); /* * If explicit (from the keyboard), unlock the keyboard now. @@ -1199,7 +1165,17 @@ void do_reset(H3270 *hSession, Boolean explicit) { lib3270_kybdlock_clear(hSession,~KL_DEFERRED_UNLOCK); kybdlock_set(hSession,KL_DEFERRED_UNLOCK); - hSession->unlock_id = AddTimeOut(UNLOCK_MS, hSession, defer_unlock); + + if(hSession->unlock_delay_ms) + { + hSession->unlock_id = AddTimeOut(hSession->unlock_delay_ms, hSession, defer_unlock); + } + else + { + hSession->unlock_id = 0; + defer_unlock(hSession); + } + } /* Clean up other modes. */ @@ -2998,95 +2974,8 @@ int kybd_prime(H3270 *hSession) } #endif /*]*/ -/* - * Translate a keysym name to a keysym, including APL and extended - * characters. - */ /* -static KeySym -MyStringToKeysym(char *s, enum keytype *keytypep) +LIB3270_EXPORT void lib3270_set_unlock_delay(H3270 *session, unsigned short delay) { - KeySym k; - int cc; - char *ptr; - unsigned char xc; - - -#if defined(X3270_APL) - if (!strncmp(s, "apl_", 4)) { - int is_ge; - - k = APLStringToKeysym(s, &is_ge); - if (is_ge) - *keytypep = KT_GE; - else - *keytypep = KT_STD; - } else -#endif - { - k = StringToKeysym(s); - *keytypep = KT_STD; - } - if (k == NoSymbol && ((xc = utf8_lookup(s, NULL, NULL)) != 0)) - k = xc; - if (k == NoSymbol && !strcasecmp(s, "euro")) - k = 0xa4; - if (k == NoSymbol && strlen(s) == 1) - k = s[0] & 0xff; - if (k < ' ') - k = NoSymbol; - else if (k > 0xff) { - int i; - - for (i = 0; i < nxk; i++) - if (xk[i].key == k) { - k = xk[i].assoc; - break; - } - if (k > 0xff) - k &= 0xff; - } - - // Allow arbitrary values, e.g., 0x03 for ^C. - if (k == NoSymbol && - (cc = strtoul(s, &ptr, 0)) > 0 && - cc < 0xff && - ptr != s && - *ptr == '\0') - k = cc; - - return k; -} -*/ - -/* Add a key to the extended association table. */ -/* -void -add_xk(KeySym key, KeySym assoc) -{ - int i; - - for (i = 0; i < nxk; i++) - if (xk[i].key == key) { - xk[i].assoc = assoc; - return; - } - xk = (struct xks *) Realloc(xk, (nxk + 1) * sizeof(struct xks)); - xk[nxk].key = key; - xk[nxk].assoc = assoc; - nxk++; -} -*/ - -/* Clear the extended association table. */ -/* -void clear_xks(void) -{ - if (nxk) { - lib3270_free(xk); - xk = (struct xks *)NULL; - nxk = 0; - } + CHECK_SESSION_HANDLE(session); + session->unlock_delay_ms = delay; } -*/ - - diff --git a/session.c b/session.c index 3bfa2e3..1a9946b 100644 --- a/session.c +++ b/session.c @@ -242,6 +242,10 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->colors = 16; hSession->m3279 = 1; + // Keyboard unlock + hSession->unlock_delay_ms = 350; /* 0.35s after last unlock */ + + // CSD for(f=0;f<4;f++) hSession->csd[f] = hSession->saved_csd[f] = LIB3270_ANSI_CSD_US; diff --git a/telnet.c b/telnet.c index f13248c..7121fe9 100644 --- a/telnet.c +++ b/telnet.c @@ -909,7 +909,7 @@ LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession) if(hSession->ns_write_id) { - lib3270_remove_poll(hSession->ns_write_id); + lib3270_remove_poll(hSession, hSession->ns_write_id); hSession->ns_write_id = 0; } @@ -1961,7 +1961,7 @@ void net_exception(H3270 *session, int fd, LIB3270_IO_FLAG flag, void *dunno) if(session->ns_exception_id) { - lib3270_remove_poll(session->ns_exception_id); + lib3270_remove_poll(session, session->ns_exception_id); session->ns_exception_id = NULL; } } diff --git a/utilc.h b/utilc.h index 3a268be..b4808a4 100644 --- a/utilc.h +++ b/utilc.h @@ -40,9 +40,9 @@ LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session)); -LIB3270_INTERNAL void RemoveSource(void *); +LIB3270_INTERNAL void RemoveSource(H3270 *session, void *cookie); LIB3270_INTERNAL void * AddTimeOut(unsigned long msec, H3270 *session, void (*fn)(H3270 *session)); -LIB3270_INTERNAL void RemoveTimeOut(void *cookie); +LIB3270_INTERNAL void RemoveTimeOut(H3270 *session, void *cookie); LIB3270_INTERNAL const char * KeysymToString(KeySym k); -- libgit2 0.21.2