diff --git a/XtGlue.c b/XtGlue.c index 77042e3..e5c53a7 100644 --- a/XtGlue.c +++ b/XtGlue.c @@ -18,7 +18,7 @@ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA, 02111-1307, USA * - * Este programa está nomeado como XtGlue.c e possui 896 linhas de código. + * Este programa está nomeado como XtGlue.c e possui - linhas de código. * * Contatos: * @@ -79,482 +79,6 @@ #include "resolverc.h" -#define InputReadMask 0x1 -#define InputExceptMask 0x2 -#define InputWriteMask 0x4 - -#define MILLION 1000000L - -/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ - - H3270 h3270; - -/*---[ Callbacks ]------------------------------------------------------------------------------------------*/ - -static void DefaultRemoveTimeOut(void *timer); -static void * DefaultAddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); - -static void * DefaultAddInput(int source, H3270 *session, void (*fn)(H3270 *session)); -static void * DefaultAddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); - -#if !defined(_WIN32) /*[*/ -static void * DefaultAddOutput(int source, H3270 *session, void (*fn)(H3270 *session)); -#endif - -static void DefaultRemoveInput(void *id); - -static int DefaultProcessEvents(int block); - -static void dunno(H3270 *session) -{ - -} - -static const struct lib3270_callbacks default_callbacks = -{ - sizeof(struct lib3270_callbacks), - - DefaultAddTimeOut, // unsigned long (*AddTimeOut)(unsigned long interval_ms, void (*proc)(void)); - DefaultRemoveTimeOut, // void (*RemoveTimeOut)(unsigned long timer); - - DefaultAddInput, // unsigned long (*AddInput)(int source, void (*fn)(void)); - DefaultRemoveInput, // void (*RemoveInput)(unsigned long id); - - DefaultAddExcept, // unsigned long (*AddExcept)(int source, void (*fn)(void)); - - #if !defined(_WIN32) /*[*/ - DefaultAddOutput, // unsigned long (*AddOutput)(int source, void (*fn)(void)); - #endif /*]*/ - - NULL, // int (*CallAndWait)(int(*callback)(void *), void *parm); - - NULL, // int (*Wait)(int seconds); - DefaultProcessEvents, // int (*RunPendingEvents)(int wait); - dunno - - -}; - -static const struct lib3270_callbacks *callbacks = &default_callbacks; - -/*---[ Implement default calls ]----------------------------------------------------------------------------*/ - -/* Timeouts. */ - -#if defined(_WIN32) /*[*/ -static void ms_ts(unsigned long long *u) -{ - FILETIME t; - - /* Get the system time, in 100ns units. */ - GetSystemTimeAsFileTime(&t); - memcpy(u, &t, sizeof(unsigned long long)); - - /* Divide by 10,000 to get ms. */ - *u /= 10000ULL; -} -#endif /*]*/ - -typedef struct timeout -{ - struct timeout *next; -#if defined(_WIN32) /*[*/ - unsigned long long ts; -#else /*][*/ - struct timeval tv; -#endif /*]*/ - void (*proc)(H3270 *session); - H3270 *session; - Boolean in_play; -} timeout_t; - -#define TN (timeout_t *)NULL -static timeout_t *timeouts = TN; - -static void * DefaultAddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) -{ - timeout_t *t_new; - timeout_t *t; - timeout_t *prev = TN; - - Trace("%s session=%p proc=%p",__FUNCTION__,session,proc); - - t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t)); - - t_new->proc = proc; - t_new->session = session; - t_new->in_play = False; -#if defined(_WIN32) /*[*/ - ms_ts(&t_new->ts); - t_new->ts += interval_ms; -#else /*][*/ - (void) gettimeofday(&t_new->tv, NULL); - t_new->tv.tv_sec += interval_ms / 1000L; - t_new->tv.tv_usec += (interval_ms % 1000L) * 1000L; - if (t_new->tv.tv_usec > MILLION) { - t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION; - t_new->tv.tv_usec %= MILLION; - } -#endif /*]*/ - - /* Find where to insert this item. */ - for (t = timeouts; t != TN; t = t->next) { -#if defined(_WIN32) /*[*/ - if (t->ts > t_new->ts) -#else /*][*/ - if (t->tv.tv_sec > t_new->tv.tv_sec || - (t->tv.tv_sec == t_new->tv.tv_sec && - t->tv.tv_usec > t_new->tv.tv_usec)) -#endif /*]*/ - break; - prev = t; - } - - /* Insert it. */ - if (prev == TN) { /* Front. */ - t_new->next = timeouts; - timeouts = t_new; - } else if (t == TN) { /* Rear. */ - t_new->next = TN; - prev->next = t_new; - } else { /* Middle. */ - t_new->next = t; - prev->next = t_new; - } - - trace("Timeout added: %p",t_new); - - return t_new; -} - -static void DefaultRemoveTimeOut(void * timer) -{ - timeout_t *st = (timeout_t *)timer; - timeout_t *t; - timeout_t *prev = TN; - - Trace("Removing timeout: %p",st); - - if (st->in_play) - return; - for (t = timeouts; t != TN; t = t->next) { - if (t == st) { - if (prev != TN) - prev->next = t->next; - else - timeouts = t->next; - lib3270_free(t); - return; - } - prev = t; - } -} - -/* Input events. */ -typedef struct input { - struct input *next; - int source; - int condition; - void (*proc)(H3270 *session); - H3270 *session; -} input_t; -static input_t *inputs = (input_t *)NULL; -static Boolean inputs_changed = False; - -static void * DefaultAddInput(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - input_t *ip; - - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - - ip = (input_t *) lib3270_malloc(sizeof(input_t)); - - ip->source = source; - ip->condition = InputReadMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; - inputs = ip; - inputs_changed = True; - - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip); - - return ip; -} - -static void * DefaultAddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) -{ -#if defined(_WIN32) /*[*/ - return 0; -#else /*][*/ - input_t *ip; - - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - - ip = (input_t *) lib3270_malloc(sizeof(input_t)); - - ip->source = source; - ip->condition = InputExceptMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; - inputs = ip; - inputs_changed = True; - - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip); - - return ip; -#endif /*]*/ -} - -#if !defined(_WIN32) /*[*/ -static void * DefaultAddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - input_t *ip; - - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - - ip = (input_t *)lib3270_malloc(sizeof(input_t)); - memset(ip,0,sizeof(input_t)); - - ip->source = source; - ip->condition = InputWriteMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; - inputs = ip; - inputs_changed = True; - - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip); - - return ip; -} -#endif /*]*/ - -static void DefaultRemoveInput(void *id) -{ - input_t *ip; - input_t *prev = (input_t *)NULL; - - Trace("%s: fhandle=%p",__FUNCTION__,(input_t *) id); - - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) - { - if (ip == (input_t *)id) - break; - - prev = ip; - } - if (ip == (input_t *)NULL) - return; - - if (prev != (input_t *)NULL) - prev->next = ip->next; - else - inputs = ip->next; - - lib3270_free(ip); - inputs_changed = True; -} - -#if defined(_WIN32) /*[*/ -#define MAX_HA 256 -#endif /*]*/ - -/* Event dispatcher. */ -static int DefaultProcessEvents(int block) -{ -#if defined(_WIN32) - HANDLE ha[MAX_HA]; - DWORD nha; - DWORD tmo; - DWORD ret; - unsigned long long now; - int i; -#else - fd_set rfds, wfds, xfds; - int ns; - struct timeval now, twait, *tp; -#endif - input_t *ip, *ip_next; - struct timeout *t; - Boolean any_events; - int processed_any = 0; - - retry: - - // If we've processed any input, then don't block again. - - if(processed_any) - block = 0; - any_events = False; -#if defined(_WIN32) - nha = 0; -#else - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&xfds); -#endif - - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) - { - if ((unsigned long)ip->condition & InputReadMask) - { -#if defined(_WIN32) - ha[nha++] = (HANDLE) ip->source; -#else - FD_SET(ip->source, &rfds); -#endif - any_events = True; - } -#if !defined(_WIN32) - if ((unsigned long)ip->condition & InputWriteMask) - { - FD_SET(ip->source, &wfds); - any_events = True; - } - if ((unsigned long)ip->condition & InputExceptMask) - { - FD_SET(ip->source, &xfds); - any_events = True; - } -#endif - } - - if (block) - { - if (timeouts != TN) { -#if defined(_WIN32) - ms_ts(&now); - if (now > timeouts->ts) - tmo = 0; - else - tmo = timeouts->ts - now; -#else - (void) gettimeofday(&now, (void *)NULL); - twait.tv_sec = timeouts->tv.tv_sec - now.tv_sec; - twait.tv_usec = timeouts->tv.tv_usec - now.tv_usec; - if (twait.tv_usec < 0L) { - twait.tv_sec--; - twait.tv_usec += MILLION; - } - if (twait.tv_sec < 0L) - twait.tv_sec = twait.tv_usec = 0L; - tp = &twait; -#endif - any_events = True; - } else { - // Block for 1 second (at maximal) -#if defined(_WIN32) - tmo = 1; -#else - twait.tv_sec = 1; - twait.tv_usec = 0L; - tp = &twait; -#endif - } - } - else - { -#if defined(_WIN32) - tmo = 1; -#else - twait.tv_sec = twait.tv_usec = 0L; - tp = &twait; -#endif - } - - if (!any_events) - return processed_any; - -#if defined(_WIN32) - ret = WaitForMultipleObjects(nha, ha, FALSE, tmo); - if (ret == WAIT_FAILED) - { -#else - ns = select(FD_SETSIZE, &rfds, &wfds, &xfds, tp); - if (ns < 0) - { - if (errno != EINTR) - Warning(NULL, "process_events: select() failed" ); -#endif - return processed_any; - } - - inputs_changed = False; - -#if defined(_WIN32) - for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip_next, i++) - { -#else - for (ip = inputs; ip != (input_t *) NULL; ip = ip_next) - { -#endif - ip_next = ip->next; - if (((unsigned long)ip->condition & InputReadMask) && -#if defined(_WIN32) - ret == WAIT_OBJECT_0 + i) - { -#else - FD_ISSET(ip->source, &rfds)) - { -#endif - (*ip->proc)(ip->session); - processed_any = True; - if (inputs_changed) - goto retry; - } - -#if !defined(_WIN32) - if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds)) - { - (*ip->proc)(ip->session); - processed_any = True; - if (inputs_changed) - goto retry; - } - if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds)) - { - (*ip->proc)(ip->session); - processed_any = True; - if (inputs_changed) - goto retry; - } -#endif - } - - // See what's expired. - if (timeouts != TN) { -#if defined(_WIN32) - ms_ts(&now); -#else - (void) gettimeofday(&now, (void *)NULL); -#endif - while ((t = timeouts) != TN) { -#if defined(_WIN32) - if (t->ts <= now) { -#else - if (t->tv.tv_sec < now.tv_sec || - (t->tv.tv_sec == now.tv_sec && - t->tv.tv_usec < now.tv_usec)) { -#endif - timeouts = t->next; - t->in_play = True; - (*t->proc)(t->session); - processed_any = True; - lib3270_free(t); - } else - break; - } - } - - if (inputs_changed) - goto retry; - - return processed_any; - -} - /*---[ Implement external calls ]---------------------------------------------------------------------------*/ static struct { @@ -784,6 +308,7 @@ KeySym StringToKeysym(char *s) return NoSymbol; } +/* const char * KeysymToString(KeySym k) { int i; @@ -794,202 +319,4 @@ const char * KeysymToString(KeySym k) } return (char *)NULL; } - - -/* Timeouts. */ - -void * AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) -{ - CHECK_SESSION_HANDLE(session); - if(callbacks->AddTimeOut) - return callbacks->AddTimeOut(interval_ms,session,proc); - return 0; -} - -void RemoveTimeOut(void * timer) -{ - if(callbacks->RemoveTimeOut) - return callbacks->RemoveTimeOut(timer); -} - -void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - CHECK_SESSION_HANDLE(session); - - trace("Adding input %d",source); - - if(callbacks->AddInput) - return callbacks->AddInput(source,session,fn); - return 0; -} - -void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - CHECK_SESSION_HANDLE(session); - if(callbacks->AddExcept) - return callbacks->AddExcept(source,session,fn); - return 0; -} - -#if !defined(_WIN32) /*[*/ -void * AddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - CHECK_SESSION_HANDLE(session); - if(callbacks->AddOutput) - return callbacks->AddOutput(source,session,fn); - return 0; -} -#endif /*]*/ - -void RemoveInput(void * id) -{ - if(callbacks->RemoveInput) - callbacks->RemoveInput(id); -} - -LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) -{ - return &h3270; -} - -LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk) -{ - if(!cbk) - return EINVAL; - - if(cbk->sz != sizeof(struct lib3270_callbacks)) - return EINVAL; - - callbacks = cbk; - return 0; - -} - -LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return h->cstate; -} - -LIB3270_EXPORT int lib3270_pconnected(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (((int) h->cstate) >= (int)RESOLVING); -} - -LIB3270_EXPORT int lib3270_half_connected(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == RESOLVING || h->cstate == PENDING); -} - -LIB3270_EXPORT int lib3270_connected(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return ((int) h->cstate >= (int)CONNECTED_INITIAL); -} - -LIB3270_EXPORT int lib3270_in_neither(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == CONNECTED_INITIAL); -} - -LIB3270_EXPORT int lib3270_in_ansi(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == CONNECTED_ANSI || h->cstate == CONNECTED_NVT); -} - -LIB3270_EXPORT int lib3270_in_3270(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == CONNECTED_3270 || h->cstate == CONNECTED_TN3270E || h->cstate == CONNECTED_SSCP); -} - -LIB3270_EXPORT int lib3270_in_sscp(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == CONNECTED_SSCP); -} - -LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate == CONNECTED_TN3270E); -} - -LIB3270_EXPORT int lib3270_in_e(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return (h->cstate >= CONNECTED_INITIAL_E); -} - -LIB3270_EXPORT void * lib3270_get_widget(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return h->widget; -} - -LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm) -{ - int rc; - CHECK_SESSION_HANDLE(h); - - if(h->set_timer) - h->set_timer(h,1); - - lib3270_main_iterate(h,0); - if(callbacks->callthread) - { - h->bgthread = 1; - trace("%s: background thread for %p starts",__FUNCTION__,h); - rc = callbacks->callthread(callback,h,parm); - trace("%s: background thread for %p ends",__FUNCTION__,h); - h->bgthread = 0; - } - else - { - rc = callback(h,parm); - } - lib3270_main_iterate(h,0); - - if(h->set_timer) - h->set_timer(h,0); - - return rc; -} - -LIB3270_EXPORT void lib3270_main_iterate(H3270 *session, int wait) -{ - if(callbacks->RunPendingEvents) - callbacks->RunPendingEvents(wait); -} - -LIB3270_EXPORT int lib3270_wait(seconds) -{ - time_t end; - - if(callbacks->Wait) - return callbacks->Wait(seconds); - - // Alternative wait call - end = time(0) + seconds; - - while(time(0) < end) - { - lib3270_main_iterate(&h3270,1); - } - - return 0; -} - -LIB3270_EXPORT void lib3270_ring_bell(H3270 *session) -{ - CHECK_SESSION_HANDLE(session); - - if(lib3270_get_toggle(session,LIB3270_TOGGLE_BEEP)) - callbacks->ring_bell(session); -} - - +*/ diff --git a/api.h b/api.h index 8e77970..5b04c80 100644 --- a/api.h +++ b/api.h @@ -88,25 +88,28 @@ #define CN ((char *) NULL) #endif - /* Debug & log */ + /* Debug & log */ /* #if defined( DEBUG ) #define Trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); - #else - #define Trace( fmt, ... ) /* __VA_ARGS__ */ - #define trace( fmt, ... ) /* __VA_ARGS__ */ + #elif !defined(Trace) + #define Trace( fmt, ... ) // __VA_ARGS__ + #define trace( fmt, ... ) // __VA_ARGS__ #endif - +*/ #include + // #define WriteLog(module,fmt, ...) lib3270_write_log(NULL,module,fmt,__VA_ARGS__) // #define WriteRCLog(module,rc,fmt, ...) lib3270_write_rc(NULL,module,fmt,__VA_ARGS__) +/* #ifdef LIB3270_MODULE_NAME #define Log(fmt, ...) lib3270_write_log(NULL,LIB3270_MODULE_NAME,fmt,__VA_ARGS__) #else #define Log(fmt, ...) lib3270_write_log(NULL,"MSG",fmt,__VA_ARGS__) #endif +*/ /** 3270 connection handle */ // #define LUNAME_SIZE 16 diff --git a/globals.h b/globals.h index b77e997..5cc7a6e 100644 --- a/globals.h +++ b/globals.h @@ -371,3 +371,4 @@ LIB3270_INTERNAL void key_ACharacter(unsigned char c, enum keytype keytype, enum LIB3270_INTERNAL void lib3270_initialize(void); LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); +LIB3270_INTERNAL void add_input_calls(H3270 *, void (*)(H3270 *), void (*)(H3270 *)); diff --git a/host.c b/host.c index 5ee7c02..f0e1b37 100644 --- a/host.c +++ b/host.c @@ -565,25 +565,8 @@ static int do_connect(H3270 *hSession, const char *n) /* Success. */ - /* Set pending string. */ -// if (ps == CN) -// ps = appres.login_macro; - -// if (ps != CN) -// login_macro(ps); - - /* Prepare Xt for I/O. */ -// x_add_input(hSession); -#ifdef _WIN32 - hSession->ns_exception_id = AddExcept((int) hSession->sockEvent, hSession, net_exception); - hSession->ns_read_id = AddInput((int) hSession->sockEvent, hSession, net_input); -#else - hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); - hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); -#endif // WIN32 - - hSession->excepting = True; - hSession->reading = True; + /* Setup socket I/O. */ + add_input_calls(hSession,net_input,net_exception); /* Set state and tell the world. */ if (pending) @@ -672,18 +655,7 @@ void host_disconnect(H3270 *h, int failed) if (CONNECTED || HALF_CONNECTED) { // Disconecting, disable input - if(h->reading) - { - RemoveInput(h->ns_read_id); - h->reading = False; - } - if(h->excepting) - { - RemoveInput(h->ns_exception_id); - h->excepting = False; - } -// x_remove_input(h); - + remove_input_calls(h); net_disconnect(h); trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,lib3270_get_toggle(h,LIB3270_TOGGLE_RECONNECT),h->auto_reconnect_inprogress); @@ -759,7 +731,7 @@ LIB3270_EXPORT void lib3270_register_schange(H3270 *h, LIB3270_STATE_CHANGE tx, /* Signal a state change. */ void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode) { -#if defined(DEBUG) +#if defined(DEBUG) || defined(ANDROID) static const char * state_name[LIB3270_STATE_USER] = { diff --git a/init.c b/init.c deleted file mode 100644 index a6e4e45..0000000 --- a/init.c +++ /dev/null @@ -1,371 +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. 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., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como init.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) - * - */ - - -#include "globals.h" -// #include "appres.h" -#include "charsetc.h" -#include "kybdc.h" -#include "ansic.h" - -#include - -/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ - - static int parse_model_number(H3270 *session, const char *m); - -/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ - -void lib3270_session_free(H3270 *h) -{ - int f; - - // Terminate session - if(lib3270_connected(h)) - lib3270_disconnect(h); - - shutdown_toggles(h); - - // Release state change callbacks - for(f=0;fst_callbacks[f]) - { - struct lib3270_state_callback *next = h->st_callbacks[f]->next; - lib3270_free(h->st_callbacks[f]); - h->st_callbacks[f] = next; - } - } - - // Release memory - #define RELEASE_BUFFER(x) if(x) { free(x); x = NULL; } - - RELEASE_BUFFER(h->charset); - RELEASE_BUFFER(h->paste_buffer); - - for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++) - { - RELEASE_BUFFER(h->buffer[f]); - } - -} - -static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) -{ -} - -static void nop_char(H3270 *session, unsigned char chr) -{ -} - -static void nop(H3270 *session) -{ -} - -static void update_model(H3270 *session, const char *name, int model, int rows, int cols) -{ -} - -static void changed(H3270 *session, int bstart, int bend) -{ -} - -static void update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr) -{ -} - -static void update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on) -{ -} - -static void update_selection(H3270 *session, int start, int end) -{ -} - -static void set_cursor(H3270 *session, LIB3270_CURSOR id) -{ -} - -static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text) -{ - lib3270_write_log(session,"%s",title); - lib3270_write_log(session,"%s",message); - lib3270_write_log(session,"%s",text); -} - -static void update_ssl(H3270 *session, LIB3270_SSL_STATE state) -{ -} - -static void lib3270_session_init(H3270 *hSession, const char *model) -{ - int ovc, ovr; - char junk; - int model_number; - - memset(hSession,0,sizeof(H3270)); - hSession->sz = sizeof(H3270); - - // Set the defaults. - hSession->extended = 1; - hSession->typeahead = 1; - hSession->oerr_lock = 1; - hSession->unlock_delay = 1; - hSession->icrnl = 1; - hSession->onlcr = 1; - hSession->host_charset = "bracket"; - -/* -#if !defined(_WIN32) - hSession->host_charset = "bracket"; -#else - - if (is_nt) - hSession->host_charset = "bracket"; - else - hSession->host_charset = "bracket437"; -#endif -*/ - - - // Initialize toggles - initialize_toggles(hSession); - - // Dummy calls to avoid "ifs" - hSession->update = update_char; - hSession->update_model = update_model; - hSession->update_cursor = update_cursor; - hSession->set_selection = nop_char; - hSession->ctlr_done = nop; - hSession->changed = changed; - hSession->erase = screen_disp; - hSession->suspend = nop; - hSession->resume = screen_disp; - hSession->update_oia = update_oia; - hSession->update_selection = update_selection; - hSession->cursor = set_cursor; - hSession->message = message; - hSession->update_ssl = update_ssl; - hSession->sock = -1; - -#ifdef _WIN32 - hSession->sockEvent = NULL; -#endif // _WIN32 - - hSession->model_num = -1; - hSession->cstate = NOT_CONNECTED; - hSession->oia_status = -1; - - strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); - hSession->model_name = &hSession->full_model_name[4]; - - if(!*model) - model = "2"; // No model, use the default one - - model_number = parse_model_number(hSession,model); - if (model_number < 0) - { - popup_an_error(hSession,"Invalid model number: %s", model); - model_number = 0; - } - - if (!model_number) - { -#if defined(RESTRICT_3279) - model_number = 3; -#else - model_number = 4; -#endif - } - - if(hSession->mono) - hSession->m3279 = 0; - else - hSession->m3279 = 1; - - if(!hSession->extended) - hSession->oversize = CN; - -#if defined(RESTRICT_3279) - if (hSession->m3279 && model_number == 4) - model_number = 3; -#endif - - Trace("Model_number: %d",model_number); - - if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) - { - ovc = 0; - ovr = 0; - } - ctlr_set_rows_cols(hSession, model_number, ovc, ovr); - - if (hSession->termname != CN) - hSession->termtype = hSession->termname; - else - hSession->termtype = hSession->full_model_name; - - Trace("Termtype: %s",hSession->termtype); - - if (hSession->apl_mode) - hSession->host_charset = "apl"; - -} - -H3270 * lib3270_session_new(const char *model) -{ - static int configured = 0; - - H3270 *hSession = &h3270; - - Trace("%s - configured=%d",__FUNCTION__,configured); - - if(configured) - { - // TODO (perry#5#): Allocate a new structure. - errno = EBUSY; - return hSession; - } - - configured = 1; - - - lib3270_session_init(hSession, model); - - if(screen_init(hSession)) - return NULL; - - Trace("Charset: %s",hSession->host_charset); - if (charset_init(hSession,hSession->host_charset) != CS_OKAY) - { - Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->host_charset); - (void) charset_init(hSession,CN); - } - - trace("%s: Initializing KYBD",__FUNCTION__); - lib3270_register_schange(hSession,LIB3270_STATE_CONNECT,kybd_connect,NULL); - lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,kybd_in3270,NULL); - -#if defined(X3270_ANSI) - trace("%s: Initializing ANSI",__FUNCTION__); - lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,ansi_in3270,NULL); -#endif // X3270_ANSI - - -#if defined(X3270_FT) - ft_init(hSession); -#endif - -/* -#if defined(X3270_PRINTER) - printer_init(); -#endif -*/ - Trace("%s finished",__FUNCTION__); - - errno = 0; - return hSession; -} - - /* -- * Parse the model number. -- * Returns -1 (error), 0 (default), or the specified number. -- */ -static int parse_model_number(H3270 *session, const char *m) -{ - int sl; - int n; - - if(!m) - return 0; - - sl = strlen(m); - - /* An empty model number is no good. */ - if (!sl) - return 0; - - if (sl > 1) { - /* - * If it's longer than one character, it needs to start with - * '327[89]', and it sets the m3279 resource. - */ - if (!strncmp(m, "3278", 4)) - { - session->m3279 = 0; - } - else if (!strncmp(m, "3279", 4)) - { - session->m3279 = 1; - } - else - { - return -1; - } - m += 4; - sl -= 4; - - /* Check more syntax. -E is allowed, but ignored. */ - switch (m[0]) { - case '\0': - /* Use default model number. */ - return 0; - case '-': - /* Model number specified. */ - m++; - sl--; - break; - default: - return -1; - } - switch (sl) { - case 1: /* n */ - break; - case 3: /* n-E */ - if (strcasecmp(m + 1, "-E")) { - return -1; - } - break; - default: - return -1; - } - } - - /* Check the numeric model number. */ - n = atoi(m); - if (n >= 2 && n <= 5) { - return n; - } else { - return -1; - } - -} diff --git a/iocalls.c b/iocalls.c new file mode 100644 index 0000000..76422a4 --- /dev/null +++ b/iocalls.c @@ -0,0 +1,689 @@ +/* + * "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., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como iocalls.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) + * + */ + +#include "globals.h" +#include +#include +#include "xioc.h" +#include "telnetc.h" + +#define MILLION 1000000L +#define InputReadMask 0x1 +#define InputExceptMask 0x2 +#define InputWriteMask 0x4 + +#if defined(_WIN32) + #define MAX_HA 256 +#endif + +/*---[ Standard 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_add_input(int source, H3270 *session, void (*fn)(H3270 *session)); +static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session)); + +static void internal_remove_input(void *id); + +static int internal_process_events(int block); + +static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm); +static int internal_wait(int seconds); + +static int internal_event_dispatcher(int block); +static void internal_ring_bell(H3270 *); + +/*---[ Active callbacks ]-----------------------------------------------------------------------------------*/ + + static void * (*add_timeout)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) + = internal_add_timeout; + + static void (*remove_timeout)(void *timer) + = internal_remove_timeout; + + static void * (*add_input)(int source, H3270 *session, void (*fn)(H3270 *session)) + = internal_add_input; + + static void (*remove_input)(void *id) + = internal_remove_input; + + static void * (*add_except)(int source, H3270 *session, void (*fn)(H3270 *session)) + = internal_add_except; + + static int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm) + = internal_callthread; + + static int (*wait)(int seconds) + = internal_wait; + + static int (*event_dispatcher)(int wait) + = internal_event_dispatcher; + + static void (*ring_bell)(H3270 *) + = internal_ring_bell; + +/*---[ Typedefs ]-------------------------------------------------------------------------------------------*/ + + typedef struct timeout + { + struct timeout *next; +#if defined(_WIN32) /*[*/ + unsigned long long ts; +#else /*][*/ + struct timeval tv; +#endif /*]*/ + void (*proc)(H3270 *session); + H3270 *session; + Boolean in_play; + } timeout_t; + + #define TN (timeout_t *)NULL + + /* Input events. */ +typedef struct input +{ + struct input *next; + int source; + int condition; + void (*proc)(H3270 *session); + H3270 *session; +} input_t; + + + +/*---[ Statics ]--------------------------------------------------------------------------------------------*/ + + static timeout_t * timeouts = NULL; + static input_t * inputs = NULL; + static Boolean inputs_changed = False; + +/*---[ Implement ]------------------------------------------------------------------------------------------*/ + + +/* Timeouts */ + +#if defined(_WIN32) +static void ms_ts(unsigned long long *u) +{ + FILETIME t; + + /* Get the system time, in 100ns units. */ + GetSystemTimeAsFileTime(&t); + memcpy(u, &t, sizeof(unsigned long long)); + + /* Divide by 10,000 to get ms. */ + *u /= 10000ULL; +} +#endif + +static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) +{ + timeout_t *t_new; + timeout_t *t; + timeout_t *prev = TN; + + trace("%s session=%p proc=%p",__FUNCTION__,session,proc); + + t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t)); + + t_new->proc = proc; + t_new->session = session; + t_new->in_play = False; + +#if defined(_WIN32) + ms_ts(&t_new->ts); + t_new->ts += interval_ms; +#else + + gettimeofday(&t_new->tv, NULL); + t_new->tv.tv_sec += interval_ms / 1000L; + t_new->tv.tv_usec += (interval_ms % 1000L) * 1000L; + + if (t_new->tv.tv_usec > MILLION) + { + t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION; + t_new->tv.tv_usec %= MILLION; + } +#endif /*]*/ + + /* Find where to insert this item. */ + for (t = timeouts; t != TN; t = t->next) + { +#if defined(_WIN32) + if (t->ts > t_new->ts) +#else + if (t->tv.tv_sec > t_new->tv.tv_sec || (t->tv.tv_sec == t_new->tv.tv_sec && t->tv.tv_usec > t_new->tv.tv_usec)) +#endif + break; + + prev = t; + } + + // Insert it. + if (prev == TN) + { // Front. + t_new->next = timeouts; + timeouts = t_new; + } + else if (t == TN) + { // Rear. + t_new->next = TN; + prev->next = t_new; + } + else + { // Middle. + t_new->next = t; + prev->next = t_new; + } + + trace("Timeout %p added with value %ld",t_new,interval_ms); + + return t_new; +} + +static void internal_remove_timeout(void * timer) +{ + timeout_t *st = (timeout_t *)timer; + timeout_t *t; + timeout_t *prev = TN; + + trace("Removing timeout: %p",st); + + if (st->in_play) + return; + + for (t = timeouts; t != TN; t = t->next) + { + if (t == st) + { + if (prev != TN) + prev->next = t->next; + else + timeouts = t->next; + lib3270_free(t); + return; + } + prev = t; + } +} + +/* Input events. */ + +static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session)) +{ + input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); + + trace("%s session=%p proc=%p",__FUNCTION__,session,fn); + + ip->source = source; + ip->condition = InputReadMask; + ip->proc = fn; + ip->session = session; + ip->next = inputs; + inputs = ip; + inputs_changed = True; + + trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip); + + return ip; +} + +static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session)) +{ +#if defined(_WIN32) + return 0; +#else + input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); + + trace("%s session=%p proc=%p",__FUNCTION__,session,fn); + + ip->source = source; + ip->condition = InputExceptMask; + ip->proc = fn; + ip->session = session; + ip->next = inputs; + inputs = ip; + inputs_changed = True; + + trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip); + + return ip; +#endif +} + +static void internal_remove_input(void *id) +{ + input_t *ip; + input_t *prev = (input_t *)NULL; + + trace("%s: fhandle=%p",__FUNCTION__,(input_t *) id); + + for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) + { + if (ip == (input_t *)id) + break; + + prev = ip; + } + + if (ip == (input_t *)NULL) + return; + + if (prev != (input_t *)NULL) + prev->next = ip->next; + else + inputs = ip->next; + + lib3270_free(ip); + inputs_changed = True; +} + +/* Event dispatcher. */ +static int internal_event_dispatcher(int block) +{ +#if defined(_WIN32) + HANDLE ha[MAX_HA]; + DWORD nha; + DWORD tmo; + DWORD ret; + unsigned long long now; + int i; +#else + fd_set rfds, wfds, xfds; + int ns; + struct timeval now, twait, *tp; +#endif + input_t *ip, *ip_next; + struct timeout *t; + Boolean any_events; + int processed_any = 0; + + retry: + + // If we've processed any input, then don't block again. + + if(processed_any) + block = 0; + any_events = False; +#if defined(_WIN32) + nha = 0; +#else + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&xfds); +#endif + + for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) + { + if ((unsigned long)ip->condition & InputReadMask) + { +#if defined(_WIN32) + ha[nha++] = (HANDLE) ip->source; +#else + FD_SET(ip->source, &rfds); +#endif + any_events = True; + } +#if !defined(_WIN32) + if ((unsigned long)ip->condition & InputWriteMask) + { + FD_SET(ip->source, &wfds); + any_events = True; + } + if ((unsigned long)ip->condition & InputExceptMask) + { + FD_SET(ip->source, &xfds); + any_events = True; + } +#endif + } + + if (block) + { + if (timeouts != TN) { +#if defined(_WIN32) + ms_ts(&now); + if (now > timeouts->ts) + tmo = 0; + else + tmo = timeouts->ts - now; +#else + (void) gettimeofday(&now, (void *)NULL); + twait.tv_sec = timeouts->tv.tv_sec - now.tv_sec; + twait.tv_usec = timeouts->tv.tv_usec - now.tv_usec; + if (twait.tv_usec < 0L) { + twait.tv_sec--; + twait.tv_usec += MILLION; + } + if (twait.tv_sec < 0L) + twait.tv_sec = twait.tv_usec = 0L; + tp = &twait; +#endif + any_events = True; + } else { + // Block for 1 second (at maximal) +#if defined(_WIN32) + tmo = 1; +#else + twait.tv_sec = 1; + twait.tv_usec = 0L; + tp = &twait; +#endif + } + } + else + { +#if defined(_WIN32) + tmo = 1; +#else + twait.tv_sec = twait.tv_usec = 0L; + tp = &twait; +#endif + } + + if (!any_events) + return processed_any; + +#if defined(_WIN32) + ret = WaitForMultipleObjects(nha, ha, FALSE, tmo); + if (ret == WAIT_FAILED) + { +#else + ns = select(FD_SETSIZE, &rfds, &wfds, &xfds, tp); + if (ns < 0) + { + if (errno != EINTR) + Warning(NULL, "process_events: select() failed" ); +#endif + return processed_any; + } + + inputs_changed = False; + +#if defined(_WIN32) + for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip_next, i++) + { +#else + for (ip = inputs; ip != (input_t *) NULL; ip = ip_next) + { +#endif + ip_next = ip->next; + if (((unsigned long)ip->condition & InputReadMask) && +#if defined(_WIN32) + ret == WAIT_OBJECT_0 + i) + { +#else + FD_ISSET(ip->source, &rfds)) + { +#endif + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } + +#if !defined(_WIN32) + if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds)) + { + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } + if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds)) + { + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } +#endif + } + + // See what's expired. + if (timeouts != TN) { +#if defined(_WIN32) + ms_ts(&now); +#else + (void) gettimeofday(&now, (void *)NULL); +#endif + + while ((t = timeouts) != TN) + { +#if defined(_WIN32) + if (t->ts <= now) { +#else + if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec)) + { +#endif + timeouts = t->next; + t->in_play = True; + (*t->proc)(t->session); + processed_any = True; + lib3270_free(t); + } else + break; + } + } + + if (inputs_changed) + goto retry; + + return processed_any; + +} + +static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm) +{ + callback(session,parm); +} + +static int internal_wait(int seconds) +{ + time_t end; + + // Alternative wait call + end = time(0) + seconds; + + while(time(0) < end) + { + lib3270_main_iterate(&h3270,1); + } + + return 0; +} + +static void internal_ring_bell(H3270 *session) +{ + return; +} + +/* External entry points */ + +void * AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) +{ + CHECK_SESSION_HANDLE(session); + return add_timeout(interval_ms,session,proc); +} + +void RemoveTimeOut(void * timer) +{ + return remove_timeout(timer); +} + +void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) +{ + CHECK_SESSION_HANDLE(session); + return add_input(source,session,fn); +} + +void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) +{ + CHECK_SESSION_HANDLE(session); + return add_except(source,session,fn); +} + +void RemoveInput(void * id) +{ + remove_input(id); +} + +void x_except_on(H3270 *h) +{ + if(h->excepting) + return; + + if(h->reading) + RemoveInput(h->ns_read_id); + +#ifdef WIN32 + h->ns_exception_id = AddExcept((int) h->sockEvent, h, net_exception); + h->excepting = 1; + + if(h->reading) + h->ns_read_id = AddInput( (int) h->sockEvent, h, net_input); +#else + h->ns_exception_id = AddExcept(h->sock, h, net_exception); + h->excepting = 1; + + if(h->reading) + h->ns_read_id = AddInput(h->sock, h, net_input); +#endif // WIN32 +} + +void add_input_calls(H3270 *session, void (*in)(H3270 *session), void (*exc)(H3270 *session)) +{ +#ifdef _WIN32 + session->ns_exception_id = AddExcept((int) session->sockEvent, session, exc); + session->ns_read_id = AddInput((int) session->sockEvent, session, in); +#else + session->ns_exception_id = AddExcept(session->sock, session, exc); + session->ns_read_id = AddInput(session->sock, session, in); +#endif // WIN32 + + session->excepting = 1; + session->reading = 1; +} + +void remove_input_calls(H3270 *session) +{ + if(session->ns_read_id) + { + RemoveInput(session->ns_read_id); + session->ns_read_id = NULL; + session->reading = 0; + } + if(session->ns_exception_id) + { + RemoveInput(session->ns_exception_id); + session->ns_exception_id = NULL; + session->excepting = 0; + } +} + +LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk) +{ + if(!cbk) + return EINVAL; + + if(cbk->sz != sizeof(struct lib3270_callbacks)) + return EINVAL; + + if(cbk->AddTimeOut) + add_timeout = cbk->AddTimeOut; + + if(cbk->RemoveTimeOut) + remove_timeout = cbk->RemoveTimeOut; + + if(cbk->AddInput) + add_input = cbk->AddInput; + + if(cbk->RemoveInput) + remove_input = cbk->RemoveInput; + + if(cbk->AddExcept) + add_except = cbk->AddExcept; + + if(cbk->callthread) + callthread = cbk->callthread; + + if(cbk->Wait) + wait = cbk->Wait; + + if(cbk->event_dispatcher) + event_dispatcher = cbk->event_dispatcher; + + if(cbk->ring_bell) + ring_bell = cbk->ring_bell; + + return 0; + +} + +LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm) +{ + int rc; + CHECK_SESSION_HANDLE(h); + + if(h->set_timer) + h->set_timer(h,1); + + lib3270_main_iterate(h,0); + callthread(callback,h,parm); + lib3270_main_iterate(h,0); + + if(h->set_timer) + h->set_timer(h,0); + + return rc; +} + +LIB3270_EXPORT void lib3270_main_iterate(H3270 *session, int block) +{ + CHECK_SESSION_HANDLE(session); + event_dispatcher(block); +} + +LIB3270_EXPORT int lib3270_wait(seconds) +{ + wait(seconds); +} + +LIB3270_EXPORT void lib3270_ring_bell(H3270 *session) +{ + CHECK_SESSION_HANDLE(session); + if(lib3270_get_toggle(session,LIB3270_TOGGLE_BEEP)) + ring_bell(session); +} + + + diff --git a/kybd.c b/kybd.c index 78954ff..e1d912a 100644 --- a/kybd.c +++ b/kybd.c @@ -492,7 +492,7 @@ static void key_AID(H3270 *session, unsigned char aid_code) if (IN_ANSI) { register unsigned i; - Trace("aid_code: %02x IN_ANSI: %d",aid_code,IN_ANSI); + trace("aid_code: %02x IN_ANSI: %d",aid_code,IN_ANSI); if (aid_code == AID_ENTER) { net_sendc('\r'); @@ -516,7 +516,7 @@ static void key_AID(H3270 *session, unsigned char aid_code) plugin_aid(aid_code); #endif /*]*/ - Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr); + trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr); if (IN_SSCP) { if (kybdlock & KL_OIA_MINUS) @@ -2295,7 +2295,7 @@ LIB3270_KEY_ACTION( enter ) { // reset_idle_timer(); - Trace("%s (kybdlock & KL_OIA_MINUS): %d kybdlock: %d",__FUNCTION__,(kybdlock & KL_OIA_MINUS),kybdlock); + trace("%s (kybdlock & KL_OIA_MINUS): %d kybdlock: %d",__FUNCTION__,(kybdlock & KL_OIA_MINUS),kybdlock); if (kybdlock & KL_OIA_MINUS) return -1; diff --git a/screen.c b/screen.c index 74e5a33..fe8ec5e 100644 --- a/screen.c +++ b/screen.c @@ -622,7 +622,21 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) { +#ifdef ANDROID + + char len = strlen(fmt); + char * mask = malloc(len+5); + strncpy(mask,fmt,len); + mask[len] = '\n'; + mask[len+1] = 0; + __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, mask, arg); + +#else + lib3270_write_va_log(session,"lib3270",fmt,arg); + +#endif // ANDROID + return 0; } diff --git a/session.c b/session.c new file mode 100644 index 0000000..13eb8f3 --- /dev/null +++ b/session.c @@ -0,0 +1,395 @@ +/* + * "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., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como session.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) + * + */ + + +#include "globals.h" +#include "charsetc.h" +#include "kybdc.h" +#include "ansic.h" + +/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ + + H3270 h3270; + +/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ + + static int parse_model_number(H3270 *session, const char *m); + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +void lib3270_session_free(H3270 *h) +{ + int f; + + // Terminate session + if(lib3270_connected(h)) + lib3270_disconnect(h); + + shutdown_toggles(h); + + // Release state change callbacks + for(f=0;fst_callbacks[f]) + { + struct lib3270_state_callback *next = h->st_callbacks[f]->next; + lib3270_free(h->st_callbacks[f]); + h->st_callbacks[f] = next; + } + } + + // Release memory + lib3270_free(h->charset); + lib3270_free(h->paste_buffer); + h->charset = NULL; + h->paste_buffer = NULL; + + for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++) + { + lib3270_free(h->buffer[f]); + h->buffer[f] = NULL; + } + +} + +static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) +{ +} + +static void nop_char(H3270 *session, unsigned char chr) +{ +} + +static void nop(H3270 *session) +{ +} + +static void update_model(H3270 *session, const char *name, int model, int rows, int cols) +{ +} + +static void changed(H3270 *session, int bstart, int bend) +{ +} + +static void update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr) +{ +} + +static void update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on) +{ +} + +static void update_selection(H3270 *session, int start, int end) +{ +} + +static void set_cursor(H3270 *session, LIB3270_CURSOR id) +{ +} + +static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text) +{ +#ifdef ANDROID + + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",title); + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",message); + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",text); + +#else + + lib3270_write_log(session,"%s",title); + lib3270_write_log(session,"%s",message); + lib3270_write_log(session,"%s",text); + +#endif // ANDROID + +} + +static void update_ssl(H3270 *session, LIB3270_SSL_STATE state) +{ +} + +static void lib3270_session_init(H3270 *hSession, const char *model) +{ + int ovc, ovr; + char junk; + int model_number; + + memset(hSession,0,sizeof(H3270)); + hSession->sz = sizeof(H3270); + + // Set the defaults. + hSession->extended = 1; + hSession->typeahead = 1; + hSession->oerr_lock = 1; + hSession->unlock_delay = 1; + hSession->icrnl = 1; + hSession->onlcr = 1; + hSession->host_charset = "bracket"; + +/* +#if !defined(_WIN32) + hSession->host_charset = "bracket"; +#else + + if (is_nt) + hSession->host_charset = "bracket"; + else + hSession->host_charset = "bracket437"; +#endif +*/ + + + // Initialize toggles + initialize_toggles(hSession); + + // Dummy calls to avoid "ifs" + hSession->update = update_char; + hSession->update_model = update_model; + hSession->update_cursor = update_cursor; + hSession->set_selection = nop_char; + hSession->ctlr_done = nop; + hSession->changed = changed; + hSession->erase = screen_disp; + hSession->suspend = nop; + hSession->resume = screen_disp; + hSession->update_oia = update_oia; + hSession->update_selection = update_selection; + hSession->cursor = set_cursor; + hSession->message = message; + hSession->update_ssl = update_ssl; + hSession->sock = -1; + +#ifdef _WIN32 + hSession->sockEvent = NULL; +#endif // _WIN32 + + hSession->model_num = -1; + hSession->cstate = NOT_CONNECTED; + hSession->oia_status = -1; + + strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); + hSession->model_name = &hSession->full_model_name[4]; + + if(!*model) + model = "2"; // No model, use the default one + + model_number = parse_model_number(hSession,model); + if (model_number < 0) + { + popup_an_error(hSession,"Invalid model number: %s", model); + model_number = 0; + } + + if (!model_number) + { +#if defined(RESTRICT_3279) + model_number = 3; +#else + model_number = 4; +#endif + } + + if(hSession->mono) + hSession->m3279 = 0; + else + hSession->m3279 = 1; + + if(!hSession->extended) + hSession->oversize = CN; + +#if defined(RESTRICT_3279) + if (hSession->m3279 && model_number == 4) + model_number = 3; +#endif + + trace("Model_number: %d",model_number); + + if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2) + { + ovc = 0; + ovr = 0; + } + ctlr_set_rows_cols(hSession, model_number, ovc, ovr); + + if (hSession->termname != CN) + hSession->termtype = hSession->termname; + else + hSession->termtype = hSession->full_model_name; + + trace("Termtype: %s",hSession->termtype); + + if (hSession->apl_mode) + hSession->host_charset = "apl"; + +} + +H3270 * lib3270_session_new(const char *model) +{ + static int configured = 0; + + H3270 *hSession = &h3270; + + trace("%s - configured=%d",__FUNCTION__,configured); + + if(configured) + { + // TODO (perry#5#): Allocate a new structure. + errno = EBUSY; + return hSession; + } + + configured = 1; + + + lib3270_session_init(hSession, model); + + if(screen_init(hSession)) + return NULL; + + trace("Charset: %s",hSession->host_charset); + if (charset_init(hSession,hSession->host_charset) != CS_OKAY) + { + Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->host_charset); + (void) charset_init(hSession,CN); + } + + trace("%s: Initializing KYBD",__FUNCTION__); + lib3270_register_schange(hSession,LIB3270_STATE_CONNECT,kybd_connect,NULL); + lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,kybd_in3270,NULL); + +#if defined(X3270_ANSI) + trace("%s: Initializing ANSI",__FUNCTION__); + lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,ansi_in3270,NULL); +#endif // X3270_ANSI + + +#if defined(X3270_FT) + ft_init(hSession); +#endif + +/* +#if defined(X3270_PRINTER) + printer_init(); +#endif +*/ + trace("%s finished",__FUNCTION__); + + errno = 0; + return hSession; +} + + /* +- * Parse the model number. +- * Returns -1 (error), 0 (default), or the specified number. +- */ +static int parse_model_number(H3270 *session, const char *m) +{ + int sl; + int n; + + if(!m) + return 0; + + sl = strlen(m); + + /* An empty model number is no good. */ + if (!sl) + return 0; + + if (sl > 1) { + /* + * If it's longer than one character, it needs to start with + * '327[89]', and it sets the m3279 resource. + */ + if (!strncmp(m, "3278", 4)) + { + session->m3279 = 0; + } + else if (!strncmp(m, "3279", 4)) + { + session->m3279 = 1; + } + else + { + return -1; + } + m += 4; + sl -= 4; + + /* Check more syntax. -E is allowed, but ignored. */ + switch (m[0]) { + case '\0': + /* Use default model number. */ + return 0; + case '-': + /* Model number specified. */ + m++; + sl--; + break; + default: + return -1; + } + switch (sl) { + case 1: /* n */ + break; + case 3: /* n-E */ + if (strcasecmp(m + 1, "-E")) { + return -1; + } + break; + default: + return -1; + } + } + + /* Check the numeric model number. */ + n = atoi(m); + if (n >= 2 && n <= 5) { + return n; + } else { + return -1; + } + +} + +LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) +{ + return &h3270; +} + +LIB3270_EXPORT void * lib3270_get_widget(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->widget; +} diff --git a/sources.mak b/sources.mak index ec9bb16..819f19f 100644 --- a/sources.mak +++ b/sources.mak @@ -26,10 +26,13 @@ # Terminal only sources TERMINAL_SOURCES = bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \ - host.c sf.c ansi.c log.c resolver.c xio.c tables.c proxy.c utf8.c charset.c \ - version.c init.c + host.c sf.c ansi.c resolver.c tables.c utf8.c charset.c \ + version.c session.c state.c + +# Network I/O Sources +NETWORK_SOURCES = iocalls.c proxy.c # Full library sources -SOURCES = $(TERMINAL_SOURCES) actions.c ft.c ft_cut.c ft_dft.c glue.c resources.c \ - rpq.c see.c trace_ds.c paste.c macros.c fallbacks.c +SOURCES = $(TERMINAL_SOURCES) $(NETWORK_SOURCES) actions.c ft.c ft_cut.c ft_dft.c glue.c resources.c \ + rpq.c see.c trace_ds.c paste.c macros.c fallbacks.c log.c diff --git a/state.c b/state.c new file mode 100644 index 0000000..2c62514 --- /dev/null +++ b/state.c @@ -0,0 +1,94 @@ +/* + * "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., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como state.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) + * + */ + +#include "globals.h" + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->cstate; +} + +LIB3270_EXPORT int lib3270_pconnected(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (((int) h->cstate) >= (int)RESOLVING); +} + +LIB3270_EXPORT int lib3270_half_connected(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == RESOLVING || h->cstate == PENDING); +} + +LIB3270_EXPORT int lib3270_connected(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return ((int) h->cstate >= (int)CONNECTED_INITIAL); +} + +LIB3270_EXPORT int lib3270_in_neither(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == CONNECTED_INITIAL); +} + +LIB3270_EXPORT int lib3270_in_ansi(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == CONNECTED_ANSI || h->cstate == CONNECTED_NVT); +} + +LIB3270_EXPORT int lib3270_in_3270(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == CONNECTED_3270 || h->cstate == CONNECTED_TN3270E || h->cstate == CONNECTED_SSCP); +} + +LIB3270_EXPORT int lib3270_in_sscp(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == CONNECTED_SSCP); +} + +LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate == CONNECTED_TN3270E); +} + +LIB3270_EXPORT int lib3270_in_e(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->cstate >= CONNECTED_INITIAL_E); +} + + diff --git a/telnet.c b/telnet.c index 8211340..6f6cdb9 100644 --- a/telnet.c +++ b/telnet.c @@ -952,17 +952,6 @@ void net_disconnect(H3270 *session) session->connected_lu = CN; status_lu(&h3270,CN); -/* -#if !defined(_WIN32) - // We have no more interest in output buffer space. - if(session->output_id != NULL) - { - RemoveInput(session->output_id); - session->output_id = NULL; - } -#endif -*/ - } @@ -1978,9 +1967,9 @@ void net_exception(H3270 *session) if(session->excepting) { RemoveInput(session->ns_exception_id); + session->ns_exception_id = NULL; session->excepting = 0; } -// x_except_off(session); } } diff --git a/toggles.c b/toggles.c index 0d9521b..ec9072c 100644 --- a/toggles.c +++ b/toggles.c @@ -93,7 +93,7 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i */ static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix) { - Trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); + trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); t->upcall(session, t, TT_INTERACTIVE); if(session->update_toggle) diff --git a/util.c b/util.c index 4dd8355..6b9f219 100644 --- a/util.c +++ b/util.c @@ -881,217 +881,6 @@ rpf_free(rpf_t *r) r->cur_len = 0; } -/* -#if defined(X3270_DISPLAY) - -// Glue between x3270 and the X libraries. - -// -// A way to work around problems with Xt resources. It seems to be impossible -// to get arbitrarily named resources. Someday this should be hacked to -// add classes too. -// -char * get_resource(const char *name) -{ - XrmValue value; - char *type; - char *str; - char *r = CN; - - str = xs_buffer("%s.%s", XtName(toplevel), name); - if ((XrmGetResource(rdb, str, 0, &type, &value) == True) && *value.addr) - r = value.addr; - XtFree(str); - - lib3270_write_log(&h3270,"resource","%s=\"%s\"",name,r); - - return r; -} - -// -// Input callbacks. -// -typedef void voidfn(void); - -typedef struct iorec { - voidfn *fn; - XtInputId id; - struct iorec *next; -} iorec_t; - -static iorec_t *iorecs = NULL; - -static void -io_fn(XtPointer closure, int *source unused, XtInputId *id) -{ - iorec_t *iorec; - - for (iorec = iorecs; iorec != NULL; iorec = iorec->next) { - if (iorec->id == *id) { - (*iorec->fn)(); - break; - } - } -} - -unsigned long -AddInput(int sock, voidfn *fn) -{ - iorec_t *iorec; - - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t)); - iorec->fn = fn; - iorec->id = XtAppAddInput(appcontext, sock, - (XtPointer) XtInputReadMask, io_fn, NULL); - - iorec->next = iorecs; - iorecs = iorec; - - return iorec->id; -} - -unsigned long -AddExcept(int sock, voidfn *fn) -{ - iorec_t *iorec; - - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t)); - iorec->fn = fn; - iorec->id = XtAppAddInput(appcontext, sock, - (XtPointer) XtInputExceptMask, io_fn, NULL); - iorec->next = iorecs; - iorecs = iorec; - - return iorec->id; -} - -unsigned long -AddOutput(int sock, voidfn *fn) -{ - iorec_t *iorec; - - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t)); - iorec->fn = fn; - iorec->id = XtAppAddInput(appcontext, sock, - (XtPointer) XtInputWriteMask, io_fn, NULL); - iorec->next = iorecs; - iorecs = iorec; - - return iorec->id; -} - -void -RemoveInput(unsigned long cookie) -{ - iorec_t *iorec; - iorec_t *prev = NULL; - - for (iorec = iorecs; iorec != NULL; iorec = iorec->next) { - if (iorec->id == (XtInputId)cookie) { - break; - } - prev = iorec; - } - - if (iorec != NULL) { - XtRemoveInput((XtInputId)cookie); - if (prev != NULL) - prev->next = iorec->next; - else - iorecs = iorec->next; - XtFree((XtPointer)iorec); - } -} - -// -/ Timer callbacks. -// - -typedef struct torec { - voidfn *fn; - XtIntervalId id; - struct torec *next; -} torec_t; - -static torec_t *torecs = NULL; - -static void -to_fn(XtPointer closure, XtIntervalId *id) -{ - torec_t *torec; - torec_t *prev = NULL; - voidfn *fn = NULL; - - for (torec = torecs; torec != NULL; torec = torec->next) { - if (torec->id == *id) { - break; - } - prev = torec; - } - - if (torec != NULL) { - - // Remember the record. - fn = torec->fn; - - // Free the record. - if (prev != NULL) - prev->next = torec->next; - else - torecs = torec->next; - XtFree((XtPointer)torec); - - // Call the function. - (*fn)(); - } -} - -unsigned long -AddTimeOut(unsigned long msec, voidfn *fn) -{ - torec_t *torec; - - torec = (torec_t *)XtMalloc(sizeof(torec_t)); - torec->fn = fn; - torec->id = XtAppAddTimeOut(appcontext, msec, to_fn, NULL); - torec->next = torecs; - torecs = torec; - return (unsigned long)torec->id; -} - -void -RemoveTimeOut(unsigned long cookie) -{ - torec_t *torec; - torec_t *prev = NULL; - - for (torec = torecs; torec != NULL; torec = torec->next) { - if (torec->id == (XtIntervalId)cookie) { - break; - } - prev = torec; - } - - if (torec != NULL) { - XtRemoveTimeOut((XtIntervalId)cookie); - if (prev != NULL) - prev->next = torec->next; - else - torecs = torec->next; - XtFree((XtPointer)torec); - } else { - Error("RemoveTimeOut: Can't find"); - } -} - -KeySym -StringToKeysym(char *s) -{ - return XStringToKeysym(s); -} -#endif -*/ - LIB3270_EXPORT void lib3270_free(void *p) { if(p) diff --git a/utilc.h b/utilc.h index 4de1292..4d057d1 100644 --- a/utilc.h +++ b/utilc.h @@ -38,7 +38,7 @@ LIB3270_INTERNAL void xs_warning(const char *fmt, ...) printflike(1, 2); LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session)); -LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); +// LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void RemoveInput(void *); LIB3270_INTERNAL void * AddTimeOut(unsigned long msec, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void RemoveTimeOut(void *cookie); diff --git a/xio.c b/xio.c index 5fecfef..21d60c3 100644 --- a/xio.c +++ b/xio.c @@ -44,51 +44,8 @@ #include "utilc.h" #include "xioc.h" -/* Statics. */ -// static unsigned long ns_read_id; -// static unsigned long ns_exception_id; -// static Boolean reading = False; -// static Boolean excepting = False; +#error xio.c is deprecated, use iocalls.c -/* - * Called to set up input on a new network connection. - */ -/* -void x_add_input(H3270 *h) -{ -#ifdef _WIN32 - h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); - h->excepting = True; - h->ns_read_id = AddInput(h->sockEvent, h, net_input); - h->reading = True; -#else - h->ns_exception_id = AddExcept(h->sock, h, net_exception); - h->excepting = True; - h->ns_read_id = AddInput(h->sock, h, net_input); - h->reading = True; -#endif // WIN32 -} -*/ -/* - * Called when an exception is received to disable further exceptions. - */ /* -void x_except_off(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - - if(h->excepting) - { - RemoveInput(h->ns_exception_id); - h->excepting = False; - } -} -*/ - -/* - * Called when exception processing is complete to re-enable exceptions. - * This includes removing and restoring reading, so the exceptions are always - * processed first. - */ void x_except_on(H3270 *h) { if(h->excepting) @@ -99,33 +56,15 @@ void x_except_on(H3270 *h) #ifdef WIN32 h->ns_exception_id = AddExcept((int) h->sockEvent, h, net_exception); - h->excepting = True; + h->excepting = 1; if(h->reading) h->ns_read_id = AddInput( (int) h->sockEvent, h, net_input); #else h->ns_exception_id = AddExcept(h->sock, h, net_exception); - h->excepting = True; + h->excepting = 1; if(h->reading) h->ns_read_id = AddInput(h->sock, h, net_input); #endif // WIN32 } - -/* - * Called to disable input on a closing network connection. - */ /* -void x_remove_input(H3270 *h) -{ - if(h->reading) - { - RemoveInput(h->ns_read_id); - h->reading = False; - } - if(h->excepting) - { - RemoveInput(h->ns_exception_id); - h->excepting = False; - } -} -*/ -- libgit2 0.21.2