Commit 42c42795771fa64b338a173ffdf9ecdb97c3604f

Authored by perry.werneck@gmail.com
1 parent da6da894

Android: Movendo funções de rede para um bloco separado visando a futura transfe…

…rência da parte de rede em android para a java.net.socket, substituindo chamadas de log e trace por similares da API android
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple 18 * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA, 02111-1307, USA 19 * Place, Suite 330, Boston, MA, 02111-1307, USA
20 * 20 *
21 - * Este programa está nomeado como XtGlue.c e possui 896 linhas de código. 21 + * Este programa está nomeado como XtGlue.c e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
@@ -79,482 +79,6 @@ @@ -79,482 +79,6 @@
79 79
80 #include "resolverc.h" 80 #include "resolverc.h"
81 81
82 -#define InputReadMask 0x1  
83 -#define InputExceptMask 0x2  
84 -#define InputWriteMask 0x4  
85 -  
86 -#define MILLION 1000000L  
87 -  
88 -/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/  
89 -  
90 - H3270 h3270;  
91 -  
92 -/*---[ Callbacks ]------------------------------------------------------------------------------------------*/  
93 -  
94 -static void DefaultRemoveTimeOut(void *timer);  
95 -static void * DefaultAddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session));  
96 -  
97 -static void * DefaultAddInput(int source, H3270 *session, void (*fn)(H3270 *session));  
98 -static void * DefaultAddExcept(int source, H3270 *session, void (*fn)(H3270 *session));  
99 -  
100 -#if !defined(_WIN32) /*[*/  
101 -static void * DefaultAddOutput(int source, H3270 *session, void (*fn)(H3270 *session));  
102 -#endif  
103 -  
104 -static void DefaultRemoveInput(void *id);  
105 -  
106 -static int DefaultProcessEvents(int block);  
107 -  
108 -static void dunno(H3270 *session)  
109 -{  
110 -  
111 -}  
112 -  
113 -static const struct lib3270_callbacks default_callbacks =  
114 -{  
115 - sizeof(struct lib3270_callbacks),  
116 -  
117 - DefaultAddTimeOut, // unsigned long (*AddTimeOut)(unsigned long interval_ms, void (*proc)(void));  
118 - DefaultRemoveTimeOut, // void (*RemoveTimeOut)(unsigned long timer);  
119 -  
120 - DefaultAddInput, // unsigned long (*AddInput)(int source, void (*fn)(void));  
121 - DefaultRemoveInput, // void (*RemoveInput)(unsigned long id);  
122 -  
123 - DefaultAddExcept, // unsigned long (*AddExcept)(int source, void (*fn)(void));  
124 -  
125 - #if !defined(_WIN32) /*[*/  
126 - DefaultAddOutput, // unsigned long (*AddOutput)(int source, void (*fn)(void));  
127 - #endif /*]*/  
128 -  
129 - NULL, // int (*CallAndWait)(int(*callback)(void *), void *parm);  
130 -  
131 - NULL, // int (*Wait)(int seconds);  
132 - DefaultProcessEvents, // int (*RunPendingEvents)(int wait);  
133 - dunno  
134 -  
135 -  
136 -};  
137 -  
138 -static const struct lib3270_callbacks *callbacks = &default_callbacks;  
139 -  
140 -/*---[ Implement default calls ]----------------------------------------------------------------------------*/  
141 -  
142 -/* Timeouts. */  
143 -  
144 -#if defined(_WIN32) /*[*/  
145 -static void ms_ts(unsigned long long *u)  
146 -{  
147 - FILETIME t;  
148 -  
149 - /* Get the system time, in 100ns units. */  
150 - GetSystemTimeAsFileTime(&t);  
151 - memcpy(u, &t, sizeof(unsigned long long));  
152 -  
153 - /* Divide by 10,000 to get ms. */  
154 - *u /= 10000ULL;  
155 -}  
156 -#endif /*]*/  
157 -  
158 -typedef struct timeout  
159 -{  
160 - struct timeout *next;  
161 -#if defined(_WIN32) /*[*/  
162 - unsigned long long ts;  
163 -#else /*][*/  
164 - struct timeval tv;  
165 -#endif /*]*/  
166 - void (*proc)(H3270 *session);  
167 - H3270 *session;  
168 - Boolean in_play;  
169 -} timeout_t;  
170 -  
171 -#define TN (timeout_t *)NULL  
172 -static timeout_t *timeouts = TN;  
173 -  
174 -static void * DefaultAddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session))  
175 -{  
176 - timeout_t *t_new;  
177 - timeout_t *t;  
178 - timeout_t *prev = TN;  
179 -  
180 - Trace("%s session=%p proc=%p",__FUNCTION__,session,proc);  
181 -  
182 - t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t));  
183 -  
184 - t_new->proc = proc;  
185 - t_new->session = session;  
186 - t_new->in_play = False;  
187 -#if defined(_WIN32) /*[*/  
188 - ms_ts(&t_new->ts);  
189 - t_new->ts += interval_ms;  
190 -#else /*][*/  
191 - (void) gettimeofday(&t_new->tv, NULL);  
192 - t_new->tv.tv_sec += interval_ms / 1000L;  
193 - t_new->tv.tv_usec += (interval_ms % 1000L) * 1000L;  
194 - if (t_new->tv.tv_usec > MILLION) {  
195 - t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION;  
196 - t_new->tv.tv_usec %= MILLION;  
197 - }  
198 -#endif /*]*/  
199 -  
200 - /* Find where to insert this item. */  
201 - for (t = timeouts; t != TN; t = t->next) {  
202 -#if defined(_WIN32) /*[*/  
203 - if (t->ts > t_new->ts)  
204 -#else /*][*/  
205 - if (t->tv.tv_sec > t_new->tv.tv_sec ||  
206 - (t->tv.tv_sec == t_new->tv.tv_sec &&  
207 - t->tv.tv_usec > t_new->tv.tv_usec))  
208 -#endif /*]*/  
209 - break;  
210 - prev = t;  
211 - }  
212 -  
213 - /* Insert it. */  
214 - if (prev == TN) { /* Front. */  
215 - t_new->next = timeouts;  
216 - timeouts = t_new;  
217 - } else if (t == TN) { /* Rear. */  
218 - t_new->next = TN;  
219 - prev->next = t_new;  
220 - } else { /* Middle. */  
221 - t_new->next = t;  
222 - prev->next = t_new;  
223 - }  
224 -  
225 - trace("Timeout added: %p",t_new);  
226 -  
227 - return t_new;  
228 -}  
229 -  
230 -static void DefaultRemoveTimeOut(void * timer)  
231 -{  
232 - timeout_t *st = (timeout_t *)timer;  
233 - timeout_t *t;  
234 - timeout_t *prev = TN;  
235 -  
236 - Trace("Removing timeout: %p",st);  
237 -  
238 - if (st->in_play)  
239 - return;  
240 - for (t = timeouts; t != TN; t = t->next) {  
241 - if (t == st) {  
242 - if (prev != TN)  
243 - prev->next = t->next;  
244 - else  
245 - timeouts = t->next;  
246 - lib3270_free(t);  
247 - return;  
248 - }  
249 - prev = t;  
250 - }  
251 -}  
252 -  
253 -/* Input events. */  
254 -typedef struct input {  
255 - struct input *next;  
256 - int source;  
257 - int condition;  
258 - void (*proc)(H3270 *session);  
259 - H3270 *session;  
260 -} input_t;  
261 -static input_t *inputs = (input_t *)NULL;  
262 -static Boolean inputs_changed = False;  
263 -  
264 -static void * DefaultAddInput(int source, H3270 *session, void (*fn)(H3270 *session))  
265 -{  
266 - input_t *ip;  
267 -  
268 - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn);  
269 -  
270 - ip = (input_t *) lib3270_malloc(sizeof(input_t));  
271 -  
272 - ip->source = source;  
273 - ip->condition = InputReadMask;  
274 - ip->proc = fn;  
275 - ip->session = session;  
276 - ip->next = inputs;  
277 - inputs = ip;  
278 - inputs_changed = True;  
279 -  
280 - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);  
281 -  
282 - return ip;  
283 -}  
284 -  
285 -static void * DefaultAddExcept(int source, H3270 *session, void (*fn)(H3270 *session))  
286 -{  
287 -#if defined(_WIN32) /*[*/  
288 - return 0;  
289 -#else /*][*/  
290 - input_t *ip;  
291 -  
292 - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn);  
293 -  
294 - ip = (input_t *) lib3270_malloc(sizeof(input_t));  
295 -  
296 - ip->source = source;  
297 - ip->condition = InputExceptMask;  
298 - ip->proc = fn;  
299 - ip->session = session;  
300 - ip->next = inputs;  
301 - inputs = ip;  
302 - inputs_changed = True;  
303 -  
304 - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);  
305 -  
306 - return ip;  
307 -#endif /*]*/  
308 -}  
309 -  
310 -#if !defined(_WIN32) /*[*/  
311 -static void * DefaultAddOutput(int source, H3270 *session, void (*fn)(H3270 *session))  
312 -{  
313 - input_t *ip;  
314 -  
315 - Trace("%s session=%p proc=%p",__FUNCTION__,session,fn);  
316 -  
317 - ip = (input_t *)lib3270_malloc(sizeof(input_t));  
318 - memset(ip,0,sizeof(input_t));  
319 -  
320 - ip->source = source;  
321 - ip->condition = InputWriteMask;  
322 - ip->proc = fn;  
323 - ip->session = session;  
324 - ip->next = inputs;  
325 - inputs = ip;  
326 - inputs_changed = True;  
327 -  
328 - Trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);  
329 -  
330 - return ip;  
331 -}  
332 -#endif /*]*/  
333 -  
334 -static void DefaultRemoveInput(void *id)  
335 -{  
336 - input_t *ip;  
337 - input_t *prev = (input_t *)NULL;  
338 -  
339 - Trace("%s: fhandle=%p",__FUNCTION__,(input_t *) id);  
340 -  
341 - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next)  
342 - {  
343 - if (ip == (input_t *)id)  
344 - break;  
345 -  
346 - prev = ip;  
347 - }  
348 - if (ip == (input_t *)NULL)  
349 - return;  
350 -  
351 - if (prev != (input_t *)NULL)  
352 - prev->next = ip->next;  
353 - else  
354 - inputs = ip->next;  
355 -  
356 - lib3270_free(ip);  
357 - inputs_changed = True;  
358 -}  
359 -  
360 -#if defined(_WIN32) /*[*/  
361 -#define MAX_HA 256  
362 -#endif /*]*/  
363 -  
364 -/* Event dispatcher. */  
365 -static int DefaultProcessEvents(int block)  
366 -{  
367 -#if defined(_WIN32)  
368 - HANDLE ha[MAX_HA];  
369 - DWORD nha;  
370 - DWORD tmo;  
371 - DWORD ret;  
372 - unsigned long long now;  
373 - int i;  
374 -#else  
375 - fd_set rfds, wfds, xfds;  
376 - int ns;  
377 - struct timeval now, twait, *tp;  
378 -#endif  
379 - input_t *ip, *ip_next;  
380 - struct timeout *t;  
381 - Boolean any_events;  
382 - int processed_any = 0;  
383 -  
384 - retry:  
385 -  
386 - // If we've processed any input, then don't block again.  
387 -  
388 - if(processed_any)  
389 - block = 0;  
390 - any_events = False;  
391 -#if defined(_WIN32)  
392 - nha = 0;  
393 -#else  
394 - FD_ZERO(&rfds);  
395 - FD_ZERO(&wfds);  
396 - FD_ZERO(&xfds);  
397 -#endif  
398 -  
399 - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next)  
400 - {  
401 - if ((unsigned long)ip->condition & InputReadMask)  
402 - {  
403 -#if defined(_WIN32)  
404 - ha[nha++] = (HANDLE) ip->source;  
405 -#else  
406 - FD_SET(ip->source, &rfds);  
407 -#endif  
408 - any_events = True;  
409 - }  
410 -#if !defined(_WIN32)  
411 - if ((unsigned long)ip->condition & InputWriteMask)  
412 - {  
413 - FD_SET(ip->source, &wfds);  
414 - any_events = True;  
415 - }  
416 - if ((unsigned long)ip->condition & InputExceptMask)  
417 - {  
418 - FD_SET(ip->source, &xfds);  
419 - any_events = True;  
420 - }  
421 -#endif  
422 - }  
423 -  
424 - if (block)  
425 - {  
426 - if (timeouts != TN) {  
427 -#if defined(_WIN32)  
428 - ms_ts(&now);  
429 - if (now > timeouts->ts)  
430 - tmo = 0;  
431 - else  
432 - tmo = timeouts->ts - now;  
433 -#else  
434 - (void) gettimeofday(&now, (void *)NULL);  
435 - twait.tv_sec = timeouts->tv.tv_sec - now.tv_sec;  
436 - twait.tv_usec = timeouts->tv.tv_usec - now.tv_usec;  
437 - if (twait.tv_usec < 0L) {  
438 - twait.tv_sec--;  
439 - twait.tv_usec += MILLION;  
440 - }  
441 - if (twait.tv_sec < 0L)  
442 - twait.tv_sec = twait.tv_usec = 0L;  
443 - tp = &twait;  
444 -#endif  
445 - any_events = True;  
446 - } else {  
447 - // Block for 1 second (at maximal)  
448 -#if defined(_WIN32)  
449 - tmo = 1;  
450 -#else  
451 - twait.tv_sec = 1;  
452 - twait.tv_usec = 0L;  
453 - tp = &twait;  
454 -#endif  
455 - }  
456 - }  
457 - else  
458 - {  
459 -#if defined(_WIN32)  
460 - tmo = 1;  
461 -#else  
462 - twait.tv_sec = twait.tv_usec = 0L;  
463 - tp = &twait;  
464 -#endif  
465 - }  
466 -  
467 - if (!any_events)  
468 - return processed_any;  
469 -  
470 -#if defined(_WIN32)  
471 - ret = WaitForMultipleObjects(nha, ha, FALSE, tmo);  
472 - if (ret == WAIT_FAILED)  
473 - {  
474 -#else  
475 - ns = select(FD_SETSIZE, &rfds, &wfds, &xfds, tp);  
476 - if (ns < 0)  
477 - {  
478 - if (errno != EINTR)  
479 - Warning(NULL, "process_events: select() failed" );  
480 -#endif  
481 - return processed_any;  
482 - }  
483 -  
484 - inputs_changed = False;  
485 -  
486 -#if defined(_WIN32)  
487 - for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip_next, i++)  
488 - {  
489 -#else  
490 - for (ip = inputs; ip != (input_t *) NULL; ip = ip_next)  
491 - {  
492 -#endif  
493 - ip_next = ip->next;  
494 - if (((unsigned long)ip->condition & InputReadMask) &&  
495 -#if defined(_WIN32)  
496 - ret == WAIT_OBJECT_0 + i)  
497 - {  
498 -#else  
499 - FD_ISSET(ip->source, &rfds))  
500 - {  
501 -#endif  
502 - (*ip->proc)(ip->session);  
503 - processed_any = True;  
504 - if (inputs_changed)  
505 - goto retry;  
506 - }  
507 -  
508 -#if !defined(_WIN32)  
509 - if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds))  
510 - {  
511 - (*ip->proc)(ip->session);  
512 - processed_any = True;  
513 - if (inputs_changed)  
514 - goto retry;  
515 - }  
516 - if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds))  
517 - {  
518 - (*ip->proc)(ip->session);  
519 - processed_any = True;  
520 - if (inputs_changed)  
521 - goto retry;  
522 - }  
523 -#endif  
524 - }  
525 -  
526 - // See what's expired.  
527 - if (timeouts != TN) {  
528 -#if defined(_WIN32)  
529 - ms_ts(&now);  
530 -#else  
531 - (void) gettimeofday(&now, (void *)NULL);  
532 -#endif  
533 - while ((t = timeouts) != TN) {  
534 -#if defined(_WIN32)  
535 - if (t->ts <= now) {  
536 -#else  
537 - if (t->tv.tv_sec < now.tv_sec ||  
538 - (t->tv.tv_sec == now.tv_sec &&  
539 - t->tv.tv_usec < now.tv_usec)) {  
540 -#endif  
541 - timeouts = t->next;  
542 - t->in_play = True;  
543 - (*t->proc)(t->session);  
544 - processed_any = True;  
545 - lib3270_free(t);  
546 - } else  
547 - break;  
548 - }  
549 - }  
550 -  
551 - if (inputs_changed)  
552 - goto retry;  
553 -  
554 - return processed_any;  
555 -  
556 -}  
557 -  
558 /*---[ Implement external calls ]---------------------------------------------------------------------------*/ 82 /*---[ Implement external calls ]---------------------------------------------------------------------------*/
559 83
560 static struct { 84 static struct {
@@ -784,6 +308,7 @@ KeySym StringToKeysym(char *s) @@ -784,6 +308,7 @@ KeySym StringToKeysym(char *s)
784 return NoSymbol; 308 return NoSymbol;
785 } 309 }
786 310
  311 +/*
787 const char * KeysymToString(KeySym k) 312 const char * KeysymToString(KeySym k)
788 { 313 {
789 int i; 314 int i;
@@ -794,202 +319,4 @@ const char * KeysymToString(KeySym k) @@ -794,202 +319,4 @@ const char * KeysymToString(KeySym k)
794 } 319 }
795 return (char *)NULL; 320 return (char *)NULL;
796 } 321 }
797 -  
798 -  
799 -/* Timeouts. */  
800 -  
801 -void * AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session))  
802 -{  
803 - CHECK_SESSION_HANDLE(session);  
804 - if(callbacks->AddTimeOut)  
805 - return callbacks->AddTimeOut(interval_ms,session,proc);  
806 - return 0;  
807 -}  
808 -  
809 -void RemoveTimeOut(void * timer)  
810 -{  
811 - if(callbacks->RemoveTimeOut)  
812 - return callbacks->RemoveTimeOut(timer);  
813 -}  
814 -  
815 -void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session))  
816 -{  
817 - CHECK_SESSION_HANDLE(session);  
818 -  
819 - trace("Adding input %d",source);  
820 -  
821 - if(callbacks->AddInput)  
822 - return callbacks->AddInput(source,session,fn);  
823 - return 0;  
824 -}  
825 -  
826 -void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))  
827 -{  
828 - CHECK_SESSION_HANDLE(session);  
829 - if(callbacks->AddExcept)  
830 - return callbacks->AddExcept(source,session,fn);  
831 - return 0;  
832 -}  
833 -  
834 -#if !defined(_WIN32) /*[*/  
835 -void * AddOutput(int source, H3270 *session, void (*fn)(H3270 *session))  
836 -{  
837 - CHECK_SESSION_HANDLE(session);  
838 - if(callbacks->AddOutput)  
839 - return callbacks->AddOutput(source,session,fn);  
840 - return 0;  
841 -}  
842 -#endif /*]*/  
843 -  
844 -void RemoveInput(void * id)  
845 -{  
846 - if(callbacks->RemoveInput)  
847 - callbacks->RemoveInput(id);  
848 -}  
849 -  
850 -LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void)  
851 -{  
852 - return &h3270;  
853 -}  
854 -  
855 -LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk)  
856 -{  
857 - if(!cbk)  
858 - return EINVAL;  
859 -  
860 - if(cbk->sz != sizeof(struct lib3270_callbacks))  
861 - return EINVAL;  
862 -  
863 - callbacks = cbk;  
864 - return 0;  
865 -  
866 -}  
867 -  
868 -LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h)  
869 -{  
870 - CHECK_SESSION_HANDLE(h);  
871 - return h->cstate;  
872 -}  
873 -  
874 -LIB3270_EXPORT int lib3270_pconnected(H3270 *h)  
875 -{  
876 - CHECK_SESSION_HANDLE(h);  
877 - return (((int) h->cstate) >= (int)RESOLVING);  
878 -}  
879 -  
880 -LIB3270_EXPORT int lib3270_half_connected(H3270 *h)  
881 -{  
882 - CHECK_SESSION_HANDLE(h);  
883 - return (h->cstate == RESOLVING || h->cstate == PENDING);  
884 -}  
885 -  
886 -LIB3270_EXPORT int lib3270_connected(H3270 *h)  
887 -{  
888 - CHECK_SESSION_HANDLE(h);  
889 - return ((int) h->cstate >= (int)CONNECTED_INITIAL);  
890 -}  
891 -  
892 -LIB3270_EXPORT int lib3270_in_neither(H3270 *h)  
893 -{  
894 - CHECK_SESSION_HANDLE(h);  
895 - return (h->cstate == CONNECTED_INITIAL);  
896 -}  
897 -  
898 -LIB3270_EXPORT int lib3270_in_ansi(H3270 *h)  
899 -{  
900 - CHECK_SESSION_HANDLE(h);  
901 - return (h->cstate == CONNECTED_ANSI || h->cstate == CONNECTED_NVT);  
902 -}  
903 -  
904 -LIB3270_EXPORT int lib3270_in_3270(H3270 *h)  
905 -{  
906 - CHECK_SESSION_HANDLE(h);  
907 - return (h->cstate == CONNECTED_3270 || h->cstate == CONNECTED_TN3270E || h->cstate == CONNECTED_SSCP);  
908 -}  
909 -  
910 -LIB3270_EXPORT int lib3270_in_sscp(H3270 *h)  
911 -{  
912 - CHECK_SESSION_HANDLE(h);  
913 - return (h->cstate == CONNECTED_SSCP);  
914 -}  
915 -  
916 -LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h)  
917 -{  
918 - CHECK_SESSION_HANDLE(h);  
919 - return (h->cstate == CONNECTED_TN3270E);  
920 -}  
921 -  
922 -LIB3270_EXPORT int lib3270_in_e(H3270 *h)  
923 -{  
924 - CHECK_SESSION_HANDLE(h);  
925 - return (h->cstate >= CONNECTED_INITIAL_E);  
926 -}  
927 -  
928 -LIB3270_EXPORT void * lib3270_get_widget(H3270 *h)  
929 -{  
930 - CHECK_SESSION_HANDLE(h);  
931 - return h->widget;  
932 -}  
933 -  
934 -LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm)  
935 -{  
936 - int rc;  
937 - CHECK_SESSION_HANDLE(h);  
938 -  
939 - if(h->set_timer)  
940 - h->set_timer(h,1);  
941 -  
942 - lib3270_main_iterate(h,0);  
943 - if(callbacks->callthread)  
944 - {  
945 - h->bgthread = 1;  
946 - trace("%s: background thread for %p starts",__FUNCTION__,h);  
947 - rc = callbacks->callthread(callback,h,parm);  
948 - trace("%s: background thread for %p ends",__FUNCTION__,h);  
949 - h->bgthread = 0;  
950 - }  
951 - else  
952 - {  
953 - rc = callback(h,parm);  
954 - }  
955 - lib3270_main_iterate(h,0);  
956 -  
957 - if(h->set_timer)  
958 - h->set_timer(h,0);  
959 -  
960 - return rc;  
961 -}  
962 -  
963 -LIB3270_EXPORT void lib3270_main_iterate(H3270 *session, int wait)  
964 -{  
965 - if(callbacks->RunPendingEvents)  
966 - callbacks->RunPendingEvents(wait);  
967 -}  
968 -  
969 -LIB3270_EXPORT int lib3270_wait(seconds)  
970 -{  
971 - time_t end;  
972 -  
973 - if(callbacks->Wait)  
974 - return callbacks->Wait(seconds);  
975 -  
976 - // Alternative wait call  
977 - end = time(0) + seconds;  
978 -  
979 - while(time(0) < end)  
980 - {  
981 - lib3270_main_iterate(&h3270,1);  
982 - }  
983 -  
984 - return 0;  
985 -}  
986 -  
987 -LIB3270_EXPORT void lib3270_ring_bell(H3270 *session)  
988 -{  
989 - CHECK_SESSION_HANDLE(session);  
990 -  
991 - if(lib3270_get_toggle(session,LIB3270_TOGGLE_BEEP))  
992 - callbacks->ring_bell(session);  
993 -}  
994 -  
995 - 322 +*/
@@ -88,25 +88,28 @@ @@ -88,25 +88,28 @@
88 #define CN ((char *) NULL) 88 #define CN ((char *) NULL)
89 #endif 89 #endif
90 90
91 - /* Debug & log */ 91 + /* Debug & log */ /*
92 #if defined( DEBUG ) 92 #if defined( DEBUG )
93 #define Trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); 93 #define Trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr);
94 #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); 94 #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr);
95 - #else  
96 - #define Trace( fmt, ... ) /* __VA_ARGS__ */  
97 - #define trace( fmt, ... ) /* __VA_ARGS__ */ 95 + #elif !defined(Trace)
  96 + #define Trace( fmt, ... ) // __VA_ARGS__
  97 + #define trace( fmt, ... ) // __VA_ARGS__
98 #endif 98 #endif
99 - 99 +*/
100 100
101 #include <lib3270/log.h> 101 #include <lib3270/log.h>
  102 +
102 // #define WriteLog(module,fmt, ...) lib3270_write_log(NULL,module,fmt,__VA_ARGS__) 103 // #define WriteLog(module,fmt, ...) lib3270_write_log(NULL,module,fmt,__VA_ARGS__)
103 // #define WriteRCLog(module,rc,fmt, ...) lib3270_write_rc(NULL,module,fmt,__VA_ARGS__) 104 // #define WriteRCLog(module,rc,fmt, ...) lib3270_write_rc(NULL,module,fmt,__VA_ARGS__)
104 105
  106 +/*
105 #ifdef LIB3270_MODULE_NAME 107 #ifdef LIB3270_MODULE_NAME
106 #define Log(fmt, ...) lib3270_write_log(NULL,LIB3270_MODULE_NAME,fmt,__VA_ARGS__) 108 #define Log(fmt, ...) lib3270_write_log(NULL,LIB3270_MODULE_NAME,fmt,__VA_ARGS__)
107 #else 109 #else
108 #define Log(fmt, ...) lib3270_write_log(NULL,"MSG",fmt,__VA_ARGS__) 110 #define Log(fmt, ...) lib3270_write_log(NULL,"MSG",fmt,__VA_ARGS__)
109 #endif 111 #endif
  112 +*/
110 113
111 /** 3270 connection handle */ 114 /** 3270 connection handle */
112 // #define LUNAME_SIZE 16 115 // #define LUNAME_SIZE 16
@@ -371,3 +371,4 @@ LIB3270_INTERNAL void key_ACharacter(unsigned char c, enum keytype keytype, enum @@ -371,3 +371,4 @@ LIB3270_INTERNAL void key_ACharacter(unsigned char c, enum keytype keytype, enum
371 LIB3270_INTERNAL void lib3270_initialize(void); 371 LIB3270_INTERNAL void lib3270_initialize(void);
372 LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); 372 LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr);
373 373
  374 +LIB3270_INTERNAL void add_input_calls(H3270 *, void (*)(H3270 *), void (*)(H3270 *));
@@ -565,25 +565,8 @@ static int do_connect(H3270 *hSession, const char *n) @@ -565,25 +565,8 @@ static int do_connect(H3270 *hSession, const char *n)
565 565
566 /* Success. */ 566 /* Success. */
567 567
568 - /* Set pending string. */  
569 -// if (ps == CN)  
570 -// ps = appres.login_macro;  
571 -  
572 -// if (ps != CN)  
573 -// login_macro(ps);  
574 -  
575 - /* Prepare Xt for I/O. */  
576 -// x_add_input(hSession);  
577 -#ifdef _WIN32  
578 - hSession->ns_exception_id = AddExcept((int) hSession->sockEvent, hSession, net_exception);  
579 - hSession->ns_read_id = AddInput((int) hSession->sockEvent, hSession, net_input);  
580 -#else  
581 - hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception);  
582 - hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input);  
583 -#endif // WIN32  
584 -  
585 - hSession->excepting = True;  
586 - hSession->reading = True; 568 + /* Setup socket I/O. */
  569 + add_input_calls(hSession,net_input,net_exception);
587 570
588 /* Set state and tell the world. */ 571 /* Set state and tell the world. */
589 if (pending) 572 if (pending)
@@ -672,18 +655,7 @@ void host_disconnect(H3270 *h, int failed) @@ -672,18 +655,7 @@ void host_disconnect(H3270 *h, int failed)
672 if (CONNECTED || HALF_CONNECTED) 655 if (CONNECTED || HALF_CONNECTED)
673 { 656 {
674 // Disconecting, disable input 657 // Disconecting, disable input
675 - if(h->reading)  
676 - {  
677 - RemoveInput(h->ns_read_id);  
678 - h->reading = False;  
679 - }  
680 - if(h->excepting)  
681 - {  
682 - RemoveInput(h->ns_exception_id);  
683 - h->excepting = False;  
684 - }  
685 -// x_remove_input(h);  
686 - 658 + remove_input_calls(h);
687 net_disconnect(h); 659 net_disconnect(h);
688 660
689 trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,lib3270_get_toggle(h,LIB3270_TOGGLE_RECONNECT),h->auto_reconnect_inprogress); 661 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, @@ -759,7 +731,7 @@ LIB3270_EXPORT void lib3270_register_schange(H3270 *h, LIB3270_STATE_CHANGE tx,
759 /* Signal a state change. */ 731 /* Signal a state change. */
760 void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode) 732 void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode)
761 { 733 {
762 -#if defined(DEBUG) 734 +#if defined(DEBUG) || defined(ANDROID)
763 735
764 static const char * state_name[LIB3270_STATE_USER] = 736 static const char * state_name[LIB3270_STATE_USER] =
765 { 737 {
@@ -1,371 +0,0 @@ @@ -1,371 +0,0 @@
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., 59 Temple  
19 - * Place, Suite 330, Boston, MA, 02111-1307, USA  
20 - *  
21 - * Este programa está nomeado como init.c 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 - * licinio@bb.com.br (Licínio Luis Branco)  
28 - * kraucer@bb.com.br (Kraucer Fernandes Mazuco)  
29 - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)  
30 - *  
31 - */  
32 -  
33 -  
34 -#include "globals.h"  
35 -// #include "appres.h"  
36 -#include "charsetc.h"  
37 -#include "kybdc.h"  
38 -#include "ansic.h"  
39 -  
40 -#include <malloc.h>  
41 -  
42 -/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/  
43 -  
44 - static int parse_model_number(H3270 *session, const char *m);  
45 -  
46 -/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/  
47 -  
48 -void lib3270_session_free(H3270 *h)  
49 -{  
50 - int f;  
51 -  
52 - // Terminate session  
53 - if(lib3270_connected(h))  
54 - lib3270_disconnect(h);  
55 -  
56 - shutdown_toggles(h);  
57 -  
58 - // Release state change callbacks  
59 - for(f=0;f<N_ST;f++)  
60 - {  
61 - while(h->st_callbacks[f])  
62 - {  
63 - struct lib3270_state_callback *next = h->st_callbacks[f]->next;  
64 - lib3270_free(h->st_callbacks[f]);  
65 - h->st_callbacks[f] = next;  
66 - }  
67 - }  
68 -  
69 - // Release memory  
70 - #define RELEASE_BUFFER(x) if(x) { free(x); x = NULL; }  
71 -  
72 - RELEASE_BUFFER(h->charset);  
73 - RELEASE_BUFFER(h->paste_buffer);  
74 -  
75 - for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++)  
76 - {  
77 - RELEASE_BUFFER(h->buffer[f]);  
78 - }  
79 -  
80 -}  
81 -  
82 -static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor)  
83 -{  
84 -}  
85 -  
86 -static void nop_char(H3270 *session, unsigned char chr)  
87 -{  
88 -}  
89 -  
90 -static void nop(H3270 *session)  
91 -{  
92 -}  
93 -  
94 -static void update_model(H3270 *session, const char *name, int model, int rows, int cols)  
95 -{  
96 -}  
97 -  
98 -static void changed(H3270 *session, int bstart, int bend)  
99 -{  
100 -}  
101 -  
102 -static void update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr)  
103 -{  
104 -}  
105 -  
106 -static void update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on)  
107 -{  
108 -}  
109 -  
110 -static void update_selection(H3270 *session, int start, int end)  
111 -{  
112 -}  
113 -  
114 -static void set_cursor(H3270 *session, LIB3270_CURSOR id)  
115 -{  
116 -}  
117 -  
118 -static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text)  
119 -{  
120 - lib3270_write_log(session,"%s",title);  
121 - lib3270_write_log(session,"%s",message);  
122 - lib3270_write_log(session,"%s",text);  
123 -}  
124 -  
125 -static void update_ssl(H3270 *session, LIB3270_SSL_STATE state)  
126 -{  
127 -}  
128 -  
129 -static void lib3270_session_init(H3270 *hSession, const char *model)  
130 -{  
131 - int ovc, ovr;  
132 - char junk;  
133 - int model_number;  
134 -  
135 - memset(hSession,0,sizeof(H3270));  
136 - hSession->sz = sizeof(H3270);  
137 -  
138 - // Set the defaults.  
139 - hSession->extended = 1;  
140 - hSession->typeahead = 1;  
141 - hSession->oerr_lock = 1;  
142 - hSession->unlock_delay = 1;  
143 - hSession->icrnl = 1;  
144 - hSession->onlcr = 1;  
145 - hSession->host_charset = "bracket";  
146 -  
147 -/*  
148 -#if !defined(_WIN32)  
149 - hSession->host_charset = "bracket";  
150 -#else  
151 -  
152 - if (is_nt)  
153 - hSession->host_charset = "bracket";  
154 - else  
155 - hSession->host_charset = "bracket437";  
156 -#endif  
157 -*/  
158 -  
159 -  
160 - // Initialize toggles  
161 - initialize_toggles(hSession);  
162 -  
163 - // Dummy calls to avoid "ifs"  
164 - hSession->update = update_char;  
165 - hSession->update_model = update_model;  
166 - hSession->update_cursor = update_cursor;  
167 - hSession->set_selection = nop_char;  
168 - hSession->ctlr_done = nop;  
169 - hSession->changed = changed;  
170 - hSession->erase = screen_disp;  
171 - hSession->suspend = nop;  
172 - hSession->resume = screen_disp;  
173 - hSession->update_oia = update_oia;  
174 - hSession->update_selection = update_selection;  
175 - hSession->cursor = set_cursor;  
176 - hSession->message = message;  
177 - hSession->update_ssl = update_ssl;  
178 - hSession->sock = -1;  
179 -  
180 -#ifdef _WIN32  
181 - hSession->sockEvent = NULL;  
182 -#endif // _WIN32  
183 -  
184 - hSession->model_num = -1;  
185 - hSession->cstate = NOT_CONNECTED;  
186 - hSession->oia_status = -1;  
187 -  
188 - strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);  
189 - hSession->model_name = &hSession->full_model_name[4];  
190 -  
191 - if(!*model)  
192 - model = "2"; // No model, use the default one  
193 -  
194 - model_number = parse_model_number(hSession,model);  
195 - if (model_number < 0)  
196 - {  
197 - popup_an_error(hSession,"Invalid model number: %s", model);  
198 - model_number = 0;  
199 - }  
200 -  
201 - if (!model_number)  
202 - {  
203 -#if defined(RESTRICT_3279)  
204 - model_number = 3;  
205 -#else  
206 - model_number = 4;  
207 -#endif  
208 - }  
209 -  
210 - if(hSession->mono)  
211 - hSession->m3279 = 0;  
212 - else  
213 - hSession->m3279 = 1;  
214 -  
215 - if(!hSession->extended)  
216 - hSession->oversize = CN;  
217 -  
218 -#if defined(RESTRICT_3279)  
219 - if (hSession->m3279 && model_number == 4)  
220 - model_number = 3;  
221 -#endif  
222 -  
223 - Trace("Model_number: %d",model_number);  
224 -  
225 - if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2)  
226 - {  
227 - ovc = 0;  
228 - ovr = 0;  
229 - }  
230 - ctlr_set_rows_cols(hSession, model_number, ovc, ovr);  
231 -  
232 - if (hSession->termname != CN)  
233 - hSession->termtype = hSession->termname;  
234 - else  
235 - hSession->termtype = hSession->full_model_name;  
236 -  
237 - Trace("Termtype: %s",hSession->termtype);  
238 -  
239 - if (hSession->apl_mode)  
240 - hSession->host_charset = "apl";  
241 -  
242 -}  
243 -  
244 -H3270 * lib3270_session_new(const char *model)  
245 -{  
246 - static int configured = 0;  
247 -  
248 - H3270 *hSession = &h3270;  
249 -  
250 - Trace("%s - configured=%d",__FUNCTION__,configured);  
251 -  
252 - if(configured)  
253 - {  
254 - // TODO (perry#5#): Allocate a new structure.  
255 - errno = EBUSY;  
256 - return hSession;  
257 - }  
258 -  
259 - configured = 1;  
260 -  
261 -  
262 - lib3270_session_init(hSession, model);  
263 -  
264 - if(screen_init(hSession))  
265 - return NULL;  
266 -  
267 - Trace("Charset: %s",hSession->host_charset);  
268 - if (charset_init(hSession,hSession->host_charset) != CS_OKAY)  
269 - {  
270 - Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->host_charset);  
271 - (void) charset_init(hSession,CN);  
272 - }  
273 -  
274 - trace("%s: Initializing KYBD",__FUNCTION__);  
275 - lib3270_register_schange(hSession,LIB3270_STATE_CONNECT,kybd_connect,NULL);  
276 - lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,kybd_in3270,NULL);  
277 -  
278 -#if defined(X3270_ANSI)  
279 - trace("%s: Initializing ANSI",__FUNCTION__);  
280 - lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,ansi_in3270,NULL);  
281 -#endif // X3270_ANSI  
282 -  
283 -  
284 -#if defined(X3270_FT)  
285 - ft_init(hSession);  
286 -#endif  
287 -  
288 -/*  
289 -#if defined(X3270_PRINTER)  
290 - printer_init();  
291 -#endif  
292 -*/  
293 - Trace("%s finished",__FUNCTION__);  
294 -  
295 - errno = 0;  
296 - return hSession;  
297 -}  
298 -  
299 - /*  
300 -- * Parse the model number.  
301 -- * Returns -1 (error), 0 (default), or the specified number.  
302 -- */  
303 -static int parse_model_number(H3270 *session, const char *m)  
304 -{  
305 - int sl;  
306 - int n;  
307 -  
308 - if(!m)  
309 - return 0;  
310 -  
311 - sl = strlen(m);  
312 -  
313 - /* An empty model number is no good. */  
314 - if (!sl)  
315 - return 0;  
316 -  
317 - if (sl > 1) {  
318 - /*  
319 - * If it's longer than one character, it needs to start with  
320 - * '327[89]', and it sets the m3279 resource.  
321 - */  
322 - if (!strncmp(m, "3278", 4))  
323 - {  
324 - session->m3279 = 0;  
325 - }  
326 - else if (!strncmp(m, "3279", 4))  
327 - {  
328 - session->m3279 = 1;  
329 - }  
330 - else  
331 - {  
332 - return -1;  
333 - }  
334 - m += 4;  
335 - sl -= 4;  
336 -  
337 - /* Check more syntax. -E is allowed, but ignored. */  
338 - switch (m[0]) {  
339 - case '\0':  
340 - /* Use default model number. */  
341 - return 0;  
342 - case '-':  
343 - /* Model number specified. */  
344 - m++;  
345 - sl--;  
346 - break;  
347 - default:  
348 - return -1;  
349 - }  
350 - switch (sl) {  
351 - case 1: /* n */  
352 - break;  
353 - case 3: /* n-E */  
354 - if (strcasecmp(m + 1, "-E")) {  
355 - return -1;  
356 - }  
357 - break;  
358 - default:  
359 - return -1;  
360 - }  
361 - }  
362 -  
363 - /* Check the numeric model number. */  
364 - n = atoi(m);  
365 - if (n >= 2 && n <= 5) {  
366 - return n;  
367 - } else {  
368 - return -1;  
369 - }  
370 -  
371 -}  
iocalls.c 0 → 100644
@@ -0,0 +1,689 @@ @@ -0,0 +1,689 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como iocalls.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + */
  31 +
  32 +#include "globals.h"
  33 +#include <sys/time.h>
  34 +#include <sys/types.h>
  35 +#include "xioc.h"
  36 +#include "telnetc.h"
  37 +
  38 +#define MILLION 1000000L
  39 +#define InputReadMask 0x1
  40 +#define InputExceptMask 0x2
  41 +#define InputWriteMask 0x4
  42 +
  43 +#if defined(_WIN32)
  44 + #define MAX_HA 256
  45 +#endif
  46 +
  47 +/*---[ Standard calls ]-------------------------------------------------------------------------------------*/
  48 +
  49 +static void internal_remove_timeout(void *timer);
  50 +static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session));
  51 +
  52 +static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session));
  53 +static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session));
  54 +
  55 +static void internal_remove_input(void *id);
  56 +
  57 +static int internal_process_events(int block);
  58 +
  59 +static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm);
  60 +static int internal_wait(int seconds);
  61 +
  62 +static int internal_event_dispatcher(int block);
  63 +static void internal_ring_bell(H3270 *);
  64 +
  65 +/*---[ Active callbacks ]-----------------------------------------------------------------------------------*/
  66 +
  67 + static void * (*add_timeout)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session))
  68 + = internal_add_timeout;
  69 +
  70 + static void (*remove_timeout)(void *timer)
  71 + = internal_remove_timeout;
  72 +
  73 + static void * (*add_input)(int source, H3270 *session, void (*fn)(H3270 *session))
  74 + = internal_add_input;
  75 +
  76 + static void (*remove_input)(void *id)
  77 + = internal_remove_input;
  78 +
  79 + static void * (*add_except)(int source, H3270 *session, void (*fn)(H3270 *session))
  80 + = internal_add_except;
  81 +
  82 + static int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm)
  83 + = internal_callthread;
  84 +
  85 + static int (*wait)(int seconds)
  86 + = internal_wait;
  87 +
  88 + static int (*event_dispatcher)(int wait)
  89 + = internal_event_dispatcher;
  90 +
  91 + static void (*ring_bell)(H3270 *)
  92 + = internal_ring_bell;
  93 +
  94 +/*---[ Typedefs ]-------------------------------------------------------------------------------------------*/
  95 +
  96 + typedef struct timeout
  97 + {
  98 + struct timeout *next;
  99 +#if defined(_WIN32) /*[*/
  100 + unsigned long long ts;
  101 +#else /*][*/
  102 + struct timeval tv;
  103 +#endif /*]*/
  104 + void (*proc)(H3270 *session);
  105 + H3270 *session;
  106 + Boolean in_play;
  107 + } timeout_t;
  108 +
  109 + #define TN (timeout_t *)NULL
  110 +
  111 + /* Input events. */
  112 +typedef struct input
  113 +{
  114 + struct input *next;
  115 + int source;
  116 + int condition;
  117 + void (*proc)(H3270 *session);
  118 + H3270 *session;
  119 +} input_t;
  120 +
  121 +
  122 +
  123 +/*---[ Statics ]--------------------------------------------------------------------------------------------*/
  124 +
  125 + static timeout_t * timeouts = NULL;
  126 + static input_t * inputs = NULL;
  127 + static Boolean inputs_changed = False;
  128 +
  129 +/*---[ Implement ]------------------------------------------------------------------------------------------*/
  130 +
  131 +
  132 +/* Timeouts */
  133 +
  134 +#if defined(_WIN32)
  135 +static void ms_ts(unsigned long long *u)
  136 +{
  137 + FILETIME t;
  138 +
  139 + /* Get the system time, in 100ns units. */
  140 + GetSystemTimeAsFileTime(&t);
  141 + memcpy(u, &t, sizeof(unsigned long long));
  142 +
  143 + /* Divide by 10,000 to get ms. */
  144 + *u /= 10000ULL;
  145 +}
  146 +#endif
  147 +
  148 +static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session))
  149 +{
  150 + timeout_t *t_new;
  151 + timeout_t *t;
  152 + timeout_t *prev = TN;
  153 +
  154 + trace("%s session=%p proc=%p",__FUNCTION__,session,proc);
  155 +
  156 + t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t));
  157 +
  158 + t_new->proc = proc;
  159 + t_new->session = session;
  160 + t_new->in_play = False;
  161 +
  162 +#if defined(_WIN32)
  163 + ms_ts(&t_new->ts);
  164 + t_new->ts += interval_ms;
  165 +#else
  166 +
  167 + gettimeofday(&t_new->tv, NULL);
  168 + t_new->tv.tv_sec += interval_ms / 1000L;
  169 + t_new->tv.tv_usec += (interval_ms % 1000L) * 1000L;
  170 +
  171 + if (t_new->tv.tv_usec > MILLION)
  172 + {
  173 + t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION;
  174 + t_new->tv.tv_usec %= MILLION;
  175 + }
  176 +#endif /*]*/
  177 +
  178 + /* Find where to insert this item. */
  179 + for (t = timeouts; t != TN; t = t->next)
  180 + {
  181 +#if defined(_WIN32)
  182 + if (t->ts > t_new->ts)
  183 +#else
  184 + 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))
  185 +#endif
  186 + break;
  187 +
  188 + prev = t;
  189 + }
  190 +
  191 + // Insert it.
  192 + if (prev == TN)
  193 + { // Front.
  194 + t_new->next = timeouts;
  195 + timeouts = t_new;
  196 + }
  197 + else if (t == TN)
  198 + { // Rear.
  199 + t_new->next = TN;
  200 + prev->next = t_new;
  201 + }
  202 + else
  203 + { // Middle.
  204 + t_new->next = t;
  205 + prev->next = t_new;
  206 + }
  207 +
  208 + trace("Timeout %p added with value %ld",t_new,interval_ms);
  209 +
  210 + return t_new;
  211 +}
  212 +
  213 +static void internal_remove_timeout(void * timer)
  214 +{
  215 + timeout_t *st = (timeout_t *)timer;
  216 + timeout_t *t;
  217 + timeout_t *prev = TN;
  218 +
  219 + trace("Removing timeout: %p",st);
  220 +
  221 + if (st->in_play)
  222 + return;
  223 +
  224 + for (t = timeouts; t != TN; t = t->next)
  225 + {
  226 + if (t == st)
  227 + {
  228 + if (prev != TN)
  229 + prev->next = t->next;
  230 + else
  231 + timeouts = t->next;
  232 + lib3270_free(t);
  233 + return;
  234 + }
  235 + prev = t;
  236 + }
  237 +}
  238 +
  239 +/* Input events. */
  240 +
  241 +static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session))
  242 +{
  243 + input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t));
  244 +
  245 + trace("%s session=%p proc=%p",__FUNCTION__,session,fn);
  246 +
  247 + ip->source = source;
  248 + ip->condition = InputReadMask;
  249 + ip->proc = fn;
  250 + ip->session = session;
  251 + ip->next = inputs;
  252 + inputs = ip;
  253 + inputs_changed = True;
  254 +
  255 + trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);
  256 +
  257 + return ip;
  258 +}
  259 +
  260 +static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session))
  261 +{
  262 +#if defined(_WIN32)
  263 + return 0;
  264 +#else
  265 + input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t));
  266 +
  267 + trace("%s session=%p proc=%p",__FUNCTION__,session,fn);
  268 +
  269 + ip->source = source;
  270 + ip->condition = InputExceptMask;
  271 + ip->proc = fn;
  272 + ip->session = session;
  273 + ip->next = inputs;
  274 + inputs = ip;
  275 + inputs_changed = True;
  276 +
  277 + trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);
  278 +
  279 + return ip;
  280 +#endif
  281 +}
  282 +
  283 +static void internal_remove_input(void *id)
  284 +{
  285 + input_t *ip;
  286 + input_t *prev = (input_t *)NULL;
  287 +
  288 + trace("%s: fhandle=%p",__FUNCTION__,(input_t *) id);
  289 +
  290 + for (ip = inputs; ip != (input_t *)NULL; ip = ip->next)
  291 + {
  292 + if (ip == (input_t *)id)
  293 + break;
  294 +
  295 + prev = ip;
  296 + }
  297 +
  298 + if (ip == (input_t *)NULL)
  299 + return;
  300 +
  301 + if (prev != (input_t *)NULL)
  302 + prev->next = ip->next;
  303 + else
  304 + inputs = ip->next;
  305 +
  306 + lib3270_free(ip);
  307 + inputs_changed = True;
  308 +}
  309 +
  310 +/* Event dispatcher. */
  311 +static int internal_event_dispatcher(int block)
  312 +{
  313 +#if defined(_WIN32)
  314 + HANDLE ha[MAX_HA];
  315 + DWORD nha;
  316 + DWORD tmo;
  317 + DWORD ret;
  318 + unsigned long long now;
  319 + int i;
  320 +#else
  321 + fd_set rfds, wfds, xfds;
  322 + int ns;
  323 + struct timeval now, twait, *tp;
  324 +#endif
  325 + input_t *ip, *ip_next;
  326 + struct timeout *t;
  327 + Boolean any_events;
  328 + int processed_any = 0;
  329 +
  330 + retry:
  331 +
  332 + // If we've processed any input, then don't block again.
  333 +
  334 + if(processed_any)
  335 + block = 0;
  336 + any_events = False;
  337 +#if defined(_WIN32)
  338 + nha = 0;
  339 +#else
  340 + FD_ZERO(&rfds);
  341 + FD_ZERO(&wfds);
  342 + FD_ZERO(&xfds);
  343 +#endif
  344 +
  345 + for (ip = inputs; ip != (input_t *)NULL; ip = ip->next)
  346 + {
  347 + if ((unsigned long)ip->condition & InputReadMask)
  348 + {
  349 +#if defined(_WIN32)
  350 + ha[nha++] = (HANDLE) ip->source;
  351 +#else
  352 + FD_SET(ip->source, &rfds);
  353 +#endif
  354 + any_events = True;
  355 + }
  356 +#if !defined(_WIN32)
  357 + if ((unsigned long)ip->condition & InputWriteMask)
  358 + {
  359 + FD_SET(ip->source, &wfds);
  360 + any_events = True;
  361 + }
  362 + if ((unsigned long)ip->condition & InputExceptMask)
  363 + {
  364 + FD_SET(ip->source, &xfds);
  365 + any_events = True;
  366 + }
  367 +#endif
  368 + }
  369 +
  370 + if (block)
  371 + {
  372 + if (timeouts != TN) {
  373 +#if defined(_WIN32)
  374 + ms_ts(&now);
  375 + if (now > timeouts->ts)
  376 + tmo = 0;
  377 + else
  378 + tmo = timeouts->ts - now;
  379 +#else
  380 + (void) gettimeofday(&now, (void *)NULL);
  381 + twait.tv_sec = timeouts->tv.tv_sec - now.tv_sec;
  382 + twait.tv_usec = timeouts->tv.tv_usec - now.tv_usec;
  383 + if (twait.tv_usec < 0L) {
  384 + twait.tv_sec--;
  385 + twait.tv_usec += MILLION;
  386 + }
  387 + if (twait.tv_sec < 0L)
  388 + twait.tv_sec = twait.tv_usec = 0L;
  389 + tp = &twait;
  390 +#endif
  391 + any_events = True;
  392 + } else {
  393 + // Block for 1 second (at maximal)
  394 +#if defined(_WIN32)
  395 + tmo = 1;
  396 +#else
  397 + twait.tv_sec = 1;
  398 + twait.tv_usec = 0L;
  399 + tp = &twait;
  400 +#endif
  401 + }
  402 + }
  403 + else
  404 + {
  405 +#if defined(_WIN32)
  406 + tmo = 1;
  407 +#else
  408 + twait.tv_sec = twait.tv_usec = 0L;
  409 + tp = &twait;
  410 +#endif
  411 + }
  412 +
  413 + if (!any_events)
  414 + return processed_any;
  415 +
  416 +#if defined(_WIN32)
  417 + ret = WaitForMultipleObjects(nha, ha, FALSE, tmo);
  418 + if (ret == WAIT_FAILED)
  419 + {
  420 +#else
  421 + ns = select(FD_SETSIZE, &rfds, &wfds, &xfds, tp);
  422 + if (ns < 0)
  423 + {
  424 + if (errno != EINTR)
  425 + Warning(NULL, "process_events: select() failed" );
  426 +#endif
  427 + return processed_any;
  428 + }
  429 +
  430 + inputs_changed = False;
  431 +
  432 +#if defined(_WIN32)
  433 + for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip_next, i++)
  434 + {
  435 +#else
  436 + for (ip = inputs; ip != (input_t *) NULL; ip = ip_next)
  437 + {
  438 +#endif
  439 + ip_next = ip->next;
  440 + if (((unsigned long)ip->condition & InputReadMask) &&
  441 +#if defined(_WIN32)
  442 + ret == WAIT_OBJECT_0 + i)
  443 + {
  444 +#else
  445 + FD_ISSET(ip->source, &rfds))
  446 + {
  447 +#endif
  448 + (*ip->proc)(ip->session);
  449 + processed_any = True;
  450 + if (inputs_changed)
  451 + goto retry;
  452 + }
  453 +
  454 +#if !defined(_WIN32)
  455 + if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds))
  456 + {
  457 + (*ip->proc)(ip->session);
  458 + processed_any = True;
  459 + if (inputs_changed)
  460 + goto retry;
  461 + }
  462 + if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds))
  463 + {
  464 + (*ip->proc)(ip->session);
  465 + processed_any = True;
  466 + if (inputs_changed)
  467 + goto retry;
  468 + }
  469 +#endif
  470 + }
  471 +
  472 + // See what's expired.
  473 + if (timeouts != TN) {
  474 +#if defined(_WIN32)
  475 + ms_ts(&now);
  476 +#else
  477 + (void) gettimeofday(&now, (void *)NULL);
  478 +#endif
  479 +
  480 + while ((t = timeouts) != TN)
  481 + {
  482 +#if defined(_WIN32)
  483 + if (t->ts <= now) {
  484 +#else
  485 + if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec))
  486 + {
  487 +#endif
  488 + timeouts = t->next;
  489 + t->in_play = True;
  490 + (*t->proc)(t->session);
  491 + processed_any = True;
  492 + lib3270_free(t);
  493 + } else
  494 + break;
  495 + }
  496 + }
  497 +
  498 + if (inputs_changed)
  499 + goto retry;
  500 +
  501 + return processed_any;
  502 +
  503 +}
  504 +
  505 +static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm)
  506 +{
  507 + callback(session,parm);
  508 +}
  509 +
  510 +static int internal_wait(int seconds)
  511 +{
  512 + time_t end;
  513 +
  514 + // Alternative wait call
  515 + end = time(0) + seconds;
  516 +
  517 + while(time(0) < end)
  518 + {
  519 + lib3270_main_iterate(&h3270,1);
  520 + }
  521 +
  522 + return 0;
  523 +}
  524 +
  525 +static void internal_ring_bell(H3270 *session)
  526 +{
  527 + return;
  528 +}
  529 +
  530 +/* External entry points */
  531 +
  532 +void * AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session))
  533 +{
  534 + CHECK_SESSION_HANDLE(session);
  535 + return add_timeout(interval_ms,session,proc);
  536 +}
  537 +
  538 +void RemoveTimeOut(void * timer)
  539 +{
  540 + return remove_timeout(timer);
  541 +}
  542 +
  543 +void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session))
  544 +{
  545 + CHECK_SESSION_HANDLE(session);
  546 + return add_input(source,session,fn);
  547 +}
  548 +
  549 +void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))
  550 +{
  551 + CHECK_SESSION_HANDLE(session);
  552 + return add_except(source,session,fn);
  553 +}
  554 +
  555 +void RemoveInput(void * id)
  556 +{
  557 + remove_input(id);
  558 +}
  559 +
  560 +void x_except_on(H3270 *h)
  561 +{
  562 + if(h->excepting)
  563 + return;
  564 +
  565 + if(h->reading)
  566 + RemoveInput(h->ns_read_id);
  567 +
  568 +#ifdef WIN32
  569 + h->ns_exception_id = AddExcept((int) h->sockEvent, h, net_exception);
  570 + h->excepting = 1;
  571 +
  572 + if(h->reading)
  573 + h->ns_read_id = AddInput( (int) h->sockEvent, h, net_input);
  574 +#else
  575 + h->ns_exception_id = AddExcept(h->sock, h, net_exception);
  576 + h->excepting = 1;
  577 +
  578 + if(h->reading)
  579 + h->ns_read_id = AddInput(h->sock, h, net_input);
  580 +#endif // WIN32
  581 +}
  582 +
  583 +void add_input_calls(H3270 *session, void (*in)(H3270 *session), void (*exc)(H3270 *session))
  584 +{
  585 +#ifdef _WIN32
  586 + session->ns_exception_id = AddExcept((int) session->sockEvent, session, exc);
  587 + session->ns_read_id = AddInput((int) session->sockEvent, session, in);
  588 +#else
  589 + session->ns_exception_id = AddExcept(session->sock, session, exc);
  590 + session->ns_read_id = AddInput(session->sock, session, in);
  591 +#endif // WIN32
  592 +
  593 + session->excepting = 1;
  594 + session->reading = 1;
  595 +}
  596 +
  597 +void remove_input_calls(H3270 *session)
  598 +{
  599 + if(session->ns_read_id)
  600 + {
  601 + RemoveInput(session->ns_read_id);
  602 + session->ns_read_id = NULL;
  603 + session->reading = 0;
  604 + }
  605 + if(session->ns_exception_id)
  606 + {
  607 + RemoveInput(session->ns_exception_id);
  608 + session->ns_exception_id = NULL;
  609 + session->excepting = 0;
  610 + }
  611 +}
  612 +
  613 +LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk)
  614 +{
  615 + if(!cbk)
  616 + return EINVAL;
  617 +
  618 + if(cbk->sz != sizeof(struct lib3270_callbacks))
  619 + return EINVAL;
  620 +
  621 + if(cbk->AddTimeOut)
  622 + add_timeout = cbk->AddTimeOut;
  623 +
  624 + if(cbk->RemoveTimeOut)
  625 + remove_timeout = cbk->RemoveTimeOut;
  626 +
  627 + if(cbk->AddInput)
  628 + add_input = cbk->AddInput;
  629 +
  630 + if(cbk->RemoveInput)
  631 + remove_input = cbk->RemoveInput;
  632 +
  633 + if(cbk->AddExcept)
  634 + add_except = cbk->AddExcept;
  635 +
  636 + if(cbk->callthread)
  637 + callthread = cbk->callthread;
  638 +
  639 + if(cbk->Wait)
  640 + wait = cbk->Wait;
  641 +
  642 + if(cbk->event_dispatcher)
  643 + event_dispatcher = cbk->event_dispatcher;
  644 +
  645 + if(cbk->ring_bell)
  646 + ring_bell = cbk->ring_bell;
  647 +
  648 + return 0;
  649 +
  650 +}
  651 +
  652 +LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm)
  653 +{
  654 + int rc;
  655 + CHECK_SESSION_HANDLE(h);
  656 +
  657 + if(h->set_timer)
  658 + h->set_timer(h,1);
  659 +
  660 + lib3270_main_iterate(h,0);
  661 + callthread(callback,h,parm);
  662 + lib3270_main_iterate(h,0);
  663 +
  664 + if(h->set_timer)
  665 + h->set_timer(h,0);
  666 +
  667 + return rc;
  668 +}
  669 +
  670 +LIB3270_EXPORT void lib3270_main_iterate(H3270 *session, int block)
  671 +{
  672 + CHECK_SESSION_HANDLE(session);
  673 + event_dispatcher(block);
  674 +}
  675 +
  676 +LIB3270_EXPORT int lib3270_wait(seconds)
  677 +{
  678 + wait(seconds);
  679 +}
  680 +
  681 +LIB3270_EXPORT void lib3270_ring_bell(H3270 *session)
  682 +{
  683 + CHECK_SESSION_HANDLE(session);
  684 + if(lib3270_get_toggle(session,LIB3270_TOGGLE_BEEP))
  685 + ring_bell(session);
  686 +}
  687 +
  688 +
  689 +
@@ -492,7 +492,7 @@ static void key_AID(H3270 *session, unsigned char aid_code) @@ -492,7 +492,7 @@ static void key_AID(H3270 *session, unsigned char aid_code)
492 if (IN_ANSI) { 492 if (IN_ANSI) {
493 register unsigned i; 493 register unsigned i;
494 494
495 - Trace("aid_code: %02x IN_ANSI: %d",aid_code,IN_ANSI); 495 + trace("aid_code: %02x IN_ANSI: %d",aid_code,IN_ANSI);
496 496
497 if (aid_code == AID_ENTER) { 497 if (aid_code == AID_ENTER) {
498 net_sendc('\r'); 498 net_sendc('\r');
@@ -516,7 +516,7 @@ static void key_AID(H3270 *session, unsigned char aid_code) @@ -516,7 +516,7 @@ static void key_AID(H3270 *session, unsigned char aid_code)
516 plugin_aid(aid_code); 516 plugin_aid(aid_code);
517 #endif /*]*/ 517 #endif /*]*/
518 518
519 - Trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr); 519 + trace("IN_SSCP: %d cursor_addr: %d",IN_SSCP,h3270.cursor_addr);
520 520
521 if (IN_SSCP) { 521 if (IN_SSCP) {
522 if (kybdlock & KL_OIA_MINUS) 522 if (kybdlock & KL_OIA_MINUS)
@@ -2295,7 +2295,7 @@ LIB3270_KEY_ACTION( enter ) @@ -2295,7 +2295,7 @@ LIB3270_KEY_ACTION( enter )
2295 { 2295 {
2296 // reset_idle_timer(); 2296 // reset_idle_timer();
2297 2297
2298 - Trace("%s (kybdlock & KL_OIA_MINUS): %d kybdlock: %d",__FUNCTION__,(kybdlock & KL_OIA_MINUS),kybdlock); 2298 + trace("%s (kybdlock & KL_OIA_MINUS): %d kybdlock: %d",__FUNCTION__,(kybdlock & KL_OIA_MINUS),kybdlock);
2299 2299
2300 if (kybdlock & KL_OIA_MINUS) 2300 if (kybdlock & KL_OIA_MINUS)
2301 return -1; 2301 return -1;
@@ -622,7 +622,21 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit @@ -622,7 +622,21 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit
622 622
623 static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) 623 static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg)
624 { 624 {
  625 +#ifdef ANDROID
  626 +
  627 + char len = strlen(fmt);
  628 + char * mask = malloc(len+5);
  629 + strncpy(mask,fmt,len);
  630 + mask[len] = '\n';
  631 + mask[len+1] = 0;
  632 + __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, mask, arg);
  633 +
  634 +#else
  635 +
625 lib3270_write_va_log(session,"lib3270",fmt,arg); 636 lib3270_write_va_log(session,"lib3270",fmt,arg);
  637 +
  638 +#endif // ANDROID
  639 +
626 return 0; 640 return 0;
627 } 641 }
628 642
session.c 0 → 100644
@@ -0,0 +1,395 @@ @@ -0,0 +1,395 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como session.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)
  30 + *
  31 + */
  32 +
  33 +
  34 +#include "globals.h"
  35 +#include "charsetc.h"
  36 +#include "kybdc.h"
  37 +#include "ansic.h"
  38 +
  39 +/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
  40 +
  41 + H3270 h3270;
  42 +
  43 +/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/
  44 +
  45 + static int parse_model_number(H3270 *session, const char *m);
  46 +
  47 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  48 +
  49 +void lib3270_session_free(H3270 *h)
  50 +{
  51 + int f;
  52 +
  53 + // Terminate session
  54 + if(lib3270_connected(h))
  55 + lib3270_disconnect(h);
  56 +
  57 + shutdown_toggles(h);
  58 +
  59 + // Release state change callbacks
  60 + for(f=0;f<N_ST;f++)
  61 + {
  62 + while(h->st_callbacks[f])
  63 + {
  64 + struct lib3270_state_callback *next = h->st_callbacks[f]->next;
  65 + lib3270_free(h->st_callbacks[f]);
  66 + h->st_callbacks[f] = next;
  67 + }
  68 + }
  69 +
  70 + // Release memory
  71 + lib3270_free(h->charset);
  72 + lib3270_free(h->paste_buffer);
  73 + h->charset = NULL;
  74 + h->paste_buffer = NULL;
  75 +
  76 + for(f=0;f<(sizeof(h->buffer)/sizeof(h->buffer[0]));f++)
  77 + {
  78 + lib3270_free(h->buffer[f]);
  79 + h->buffer[f] = NULL;
  80 + }
  81 +
  82 +}
  83 +
  84 +static void update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor)
  85 +{
  86 +}
  87 +
  88 +static void nop_char(H3270 *session, unsigned char chr)
  89 +{
  90 +}
  91 +
  92 +static void nop(H3270 *session)
  93 +{
  94 +}
  95 +
  96 +static void update_model(H3270 *session, const char *name, int model, int rows, int cols)
  97 +{
  98 +}
  99 +
  100 +static void changed(H3270 *session, int bstart, int bend)
  101 +{
  102 +}
  103 +
  104 +static void update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr)
  105 +{
  106 +}
  107 +
  108 +static void update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on)
  109 +{
  110 +}
  111 +
  112 +static void update_selection(H3270 *session, int start, int end)
  113 +{
  114 +}
  115 +
  116 +static void set_cursor(H3270 *session, LIB3270_CURSOR id)
  117 +{
  118 +}
  119 +
  120 +static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text)
  121 +{
  122 +#ifdef ANDROID
  123 +
  124 + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",title);
  125 + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",message);
  126 + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",text);
  127 +
  128 +#else
  129 +
  130 + lib3270_write_log(session,"%s",title);
  131 + lib3270_write_log(session,"%s",message);
  132 + lib3270_write_log(session,"%s",text);
  133 +
  134 +#endif // ANDROID
  135 +
  136 +}
  137 +
  138 +static void update_ssl(H3270 *session, LIB3270_SSL_STATE state)
  139 +{
  140 +}
  141 +
  142 +static void lib3270_session_init(H3270 *hSession, const char *model)
  143 +{
  144 + int ovc, ovr;
  145 + char junk;
  146 + int model_number;
  147 +
  148 + memset(hSession,0,sizeof(H3270));
  149 + hSession->sz = sizeof(H3270);
  150 +
  151 + // Set the defaults.
  152 + hSession->extended = 1;
  153 + hSession->typeahead = 1;
  154 + hSession->oerr_lock = 1;
  155 + hSession->unlock_delay = 1;
  156 + hSession->icrnl = 1;
  157 + hSession->onlcr = 1;
  158 + hSession->host_charset = "bracket";
  159 +
  160 +/*
  161 +#if !defined(_WIN32)
  162 + hSession->host_charset = "bracket";
  163 +#else
  164 +
  165 + if (is_nt)
  166 + hSession->host_charset = "bracket";
  167 + else
  168 + hSession->host_charset = "bracket437";
  169 +#endif
  170 +*/
  171 +
  172 +
  173 + // Initialize toggles
  174 + initialize_toggles(hSession);
  175 +
  176 + // Dummy calls to avoid "ifs"
  177 + hSession->update = update_char;
  178 + hSession->update_model = update_model;
  179 + hSession->update_cursor = update_cursor;
  180 + hSession->set_selection = nop_char;
  181 + hSession->ctlr_done = nop;
  182 + hSession->changed = changed;
  183 + hSession->erase = screen_disp;
  184 + hSession->suspend = nop;
  185 + hSession->resume = screen_disp;
  186 + hSession->update_oia = update_oia;
  187 + hSession->update_selection = update_selection;
  188 + hSession->cursor = set_cursor;
  189 + hSession->message = message;
  190 + hSession->update_ssl = update_ssl;
  191 + hSession->sock = -1;
  192 +
  193 +#ifdef _WIN32
  194 + hSession->sockEvent = NULL;
  195 +#endif // _WIN32
  196 +
  197 + hSession->model_num = -1;
  198 + hSession->cstate = NOT_CONNECTED;
  199 + hSession->oia_status = -1;
  200 +
  201 + strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);
  202 + hSession->model_name = &hSession->full_model_name[4];
  203 +
  204 + if(!*model)
  205 + model = "2"; // No model, use the default one
  206 +
  207 + model_number = parse_model_number(hSession,model);
  208 + if (model_number < 0)
  209 + {
  210 + popup_an_error(hSession,"Invalid model number: %s", model);
  211 + model_number = 0;
  212 + }
  213 +
  214 + if (!model_number)
  215 + {
  216 +#if defined(RESTRICT_3279)
  217 + model_number = 3;
  218 +#else
  219 + model_number = 4;
  220 +#endif
  221 + }
  222 +
  223 + if(hSession->mono)
  224 + hSession->m3279 = 0;
  225 + else
  226 + hSession->m3279 = 1;
  227 +
  228 + if(!hSession->extended)
  229 + hSession->oversize = CN;
  230 +
  231 +#if defined(RESTRICT_3279)
  232 + if (hSession->m3279 && model_number == 4)
  233 + model_number = 3;
  234 +#endif
  235 +
  236 + trace("Model_number: %d",model_number);
  237 +
  238 + if (!hSession->extended || hSession->oversize == CN || sscanf(hSession->oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2)
  239 + {
  240 + ovc = 0;
  241 + ovr = 0;
  242 + }
  243 + ctlr_set_rows_cols(hSession, model_number, ovc, ovr);
  244 +
  245 + if (hSession->termname != CN)
  246 + hSession->termtype = hSession->termname;
  247 + else
  248 + hSession->termtype = hSession->full_model_name;
  249 +
  250 + trace("Termtype: %s",hSession->termtype);
  251 +
  252 + if (hSession->apl_mode)
  253 + hSession->host_charset = "apl";
  254 +
  255 +}
  256 +
  257 +H3270 * lib3270_session_new(const char *model)
  258 +{
  259 + static int configured = 0;
  260 +
  261 + H3270 *hSession = &h3270;
  262 +
  263 + trace("%s - configured=%d",__FUNCTION__,configured);
  264 +
  265 + if(configured)
  266 + {
  267 + // TODO (perry#5#): Allocate a new structure.
  268 + errno = EBUSY;
  269 + return hSession;
  270 + }
  271 +
  272 + configured = 1;
  273 +
  274 +
  275 + lib3270_session_init(hSession, model);
  276 +
  277 + if(screen_init(hSession))
  278 + return NULL;
  279 +
  280 + trace("Charset: %s",hSession->host_charset);
  281 + if (charset_init(hSession,hSession->host_charset) != CS_OKAY)
  282 + {
  283 + Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->host_charset);
  284 + (void) charset_init(hSession,CN);
  285 + }
  286 +
  287 + trace("%s: Initializing KYBD",__FUNCTION__);
  288 + lib3270_register_schange(hSession,LIB3270_STATE_CONNECT,kybd_connect,NULL);
  289 + lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,kybd_in3270,NULL);
  290 +
  291 +#if defined(X3270_ANSI)
  292 + trace("%s: Initializing ANSI",__FUNCTION__);
  293 + lib3270_register_schange(hSession,LIB3270_STATE_3270_MODE,ansi_in3270,NULL);
  294 +#endif // X3270_ANSI
  295 +
  296 +
  297 +#if defined(X3270_FT)
  298 + ft_init(hSession);
  299 +#endif
  300 +
  301 +/*
  302 +#if defined(X3270_PRINTER)
  303 + printer_init();
  304 +#endif
  305 +*/
  306 + trace("%s finished",__FUNCTION__);
  307 +
  308 + errno = 0;
  309 + return hSession;
  310 +}
  311 +
  312 + /*
  313 +- * Parse the model number.
  314 +- * Returns -1 (error), 0 (default), or the specified number.
  315 +- */
  316 +static int parse_model_number(H3270 *session, const char *m)
  317 +{
  318 + int sl;
  319 + int n;
  320 +
  321 + if(!m)
  322 + return 0;
  323 +
  324 + sl = strlen(m);
  325 +
  326 + /* An empty model number is no good. */
  327 + if (!sl)
  328 + return 0;
  329 +
  330 + if (sl > 1) {
  331 + /*
  332 + * If it's longer than one character, it needs to start with
  333 + * '327[89]', and it sets the m3279 resource.
  334 + */
  335 + if (!strncmp(m, "3278", 4))
  336 + {
  337 + session->m3279 = 0;
  338 + }
  339 + else if (!strncmp(m, "3279", 4))
  340 + {
  341 + session->m3279 = 1;
  342 + }
  343 + else
  344 + {
  345 + return -1;
  346 + }
  347 + m += 4;
  348 + sl -= 4;
  349 +
  350 + /* Check more syntax. -E is allowed, but ignored. */
  351 + switch (m[0]) {
  352 + case '\0':
  353 + /* Use default model number. */
  354 + return 0;
  355 + case '-':
  356 + /* Model number specified. */
  357 + m++;
  358 + sl--;
  359 + break;
  360 + default:
  361 + return -1;
  362 + }
  363 + switch (sl) {
  364 + case 1: /* n */
  365 + break;
  366 + case 3: /* n-E */
  367 + if (strcasecmp(m + 1, "-E")) {
  368 + return -1;
  369 + }
  370 + break;
  371 + default:
  372 + return -1;
  373 + }
  374 + }
  375 +
  376 + /* Check the numeric model number. */
  377 + n = atoi(m);
  378 + if (n >= 2 && n <= 5) {
  379 + return n;
  380 + } else {
  381 + return -1;
  382 + }
  383 +
  384 +}
  385 +
  386 +LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void)
  387 +{
  388 + return &h3270;
  389 +}
  390 +
  391 +LIB3270_EXPORT void * lib3270_get_widget(H3270 *h)
  392 +{
  393 + CHECK_SESSION_HANDLE(h);
  394 + return h->widget;
  395 +}
@@ -26,10 +26,13 @@ @@ -26,10 +26,13 @@
26 26
27 # Terminal only sources 27 # Terminal only sources
28 TERMINAL_SOURCES = bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \ 28 TERMINAL_SOURCES = bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \
29 - host.c sf.c ansi.c log.c resolver.c xio.c tables.c proxy.c utf8.c charset.c \  
30 - version.c init.c 29 + host.c sf.c ansi.c resolver.c tables.c utf8.c charset.c \
  30 + version.c session.c state.c
  31 +
  32 +# Network I/O Sources
  33 +NETWORK_SOURCES = iocalls.c proxy.c
31 34
32 # Full library sources 35 # Full library sources
33 -SOURCES = $(TERMINAL_SOURCES) actions.c ft.c ft_cut.c ft_dft.c glue.c resources.c \  
34 - rpq.c see.c trace_ds.c paste.c macros.c fallbacks.c 36 +SOURCES = $(TERMINAL_SOURCES) $(NETWORK_SOURCES) actions.c ft.c ft_cut.c ft_dft.c glue.c resources.c \
  37 + rpq.c see.c trace_ds.c paste.c macros.c fallbacks.c log.c
35 38
state.c 0 → 100644
@@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como state.c 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 +#include "globals.h"
  31 +
  32 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  33 +
  34 +LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h)
  35 +{
  36 + CHECK_SESSION_HANDLE(h);
  37 + return h->cstate;
  38 +}
  39 +
  40 +LIB3270_EXPORT int lib3270_pconnected(H3270 *h)
  41 +{
  42 + CHECK_SESSION_HANDLE(h);
  43 + return (((int) h->cstate) >= (int)RESOLVING);
  44 +}
  45 +
  46 +LIB3270_EXPORT int lib3270_half_connected(H3270 *h)
  47 +{
  48 + CHECK_SESSION_HANDLE(h);
  49 + return (h->cstate == RESOLVING || h->cstate == PENDING);
  50 +}
  51 +
  52 +LIB3270_EXPORT int lib3270_connected(H3270 *h)
  53 +{
  54 + CHECK_SESSION_HANDLE(h);
  55 + return ((int) h->cstate >= (int)CONNECTED_INITIAL);
  56 +}
  57 +
  58 +LIB3270_EXPORT int lib3270_in_neither(H3270 *h)
  59 +{
  60 + CHECK_SESSION_HANDLE(h);
  61 + return (h->cstate == CONNECTED_INITIAL);
  62 +}
  63 +
  64 +LIB3270_EXPORT int lib3270_in_ansi(H3270 *h)
  65 +{
  66 + CHECK_SESSION_HANDLE(h);
  67 + return (h->cstate == CONNECTED_ANSI || h->cstate == CONNECTED_NVT);
  68 +}
  69 +
  70 +LIB3270_EXPORT int lib3270_in_3270(H3270 *h)
  71 +{
  72 + CHECK_SESSION_HANDLE(h);
  73 + return (h->cstate == CONNECTED_3270 || h->cstate == CONNECTED_TN3270E || h->cstate == CONNECTED_SSCP);
  74 +}
  75 +
  76 +LIB3270_EXPORT int lib3270_in_sscp(H3270 *h)
  77 +{
  78 + CHECK_SESSION_HANDLE(h);
  79 + return (h->cstate == CONNECTED_SSCP);
  80 +}
  81 +
  82 +LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h)
  83 +{
  84 + CHECK_SESSION_HANDLE(h);
  85 + return (h->cstate == CONNECTED_TN3270E);
  86 +}
  87 +
  88 +LIB3270_EXPORT int lib3270_in_e(H3270 *h)
  89 +{
  90 + CHECK_SESSION_HANDLE(h);
  91 + return (h->cstate >= CONNECTED_INITIAL_E);
  92 +}
  93 +
  94 +
@@ -952,17 +952,6 @@ void net_disconnect(H3270 *session) @@ -952,17 +952,6 @@ void net_disconnect(H3270 *session)
952 session->connected_lu = CN; 952 session->connected_lu = CN;
953 status_lu(&h3270,CN); 953 status_lu(&h3270,CN);
954 954
955 -/*  
956 -#if !defined(_WIN32)  
957 - // We have no more interest in output buffer space.  
958 - if(session->output_id != NULL)  
959 - {  
960 - RemoveInput(session->output_id);  
961 - session->output_id = NULL;  
962 - }  
963 -#endif  
964 -*/  
965 -  
966 } 955 }
967 956
968 957
@@ -1978,9 +1967,9 @@ void net_exception(H3270 *session) @@ -1978,9 +1967,9 @@ void net_exception(H3270 *session)
1978 if(session->excepting) 1967 if(session->excepting)
1979 { 1968 {
1980 RemoveInput(session->ns_exception_id); 1969 RemoveInput(session->ns_exception_id);
  1970 + session->ns_exception_id = NULL;
1981 session->excepting = 0; 1971 session->excepting = 0;
1982 } 1972 }
1983 -// x_except_off(session);  
1984 } 1973 }
1985 } 1974 }
1986 1975
@@ -93,7 +93,7 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i @@ -93,7 +93,7 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i
93 */ 93 */
94 static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix) 94 static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix)
95 { 95 {
96 - Trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); 96 + trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall);
97 t->upcall(session, t, TT_INTERACTIVE); 97 t->upcall(session, t, TT_INTERACTIVE);
98 98
99 if(session->update_toggle) 99 if(session->update_toggle)
@@ -881,217 +881,6 @@ rpf_free(rpf_t *r) @@ -881,217 +881,6 @@ rpf_free(rpf_t *r)
881 r->cur_len = 0; 881 r->cur_len = 0;
882 } 882 }
883 883
884 -/*  
885 -#if defined(X3270_DISPLAY)  
886 -  
887 -// Glue between x3270 and the X libraries.  
888 -  
889 -//  
890 -// A way to work around problems with Xt resources. It seems to be impossible  
891 -// to get arbitrarily named resources. Someday this should be hacked to  
892 -// add classes too.  
893 -//  
894 -char * get_resource(const char *name)  
895 -{  
896 - XrmValue value;  
897 - char *type;  
898 - char *str;  
899 - char *r = CN;  
900 -  
901 - str = xs_buffer("%s.%s", XtName(toplevel), name);  
902 - if ((XrmGetResource(rdb, str, 0, &type, &value) == True) && *value.addr)  
903 - r = value.addr;  
904 - XtFree(str);  
905 -  
906 - lib3270_write_log(&h3270,"resource","%s=\"%s\"",name,r);  
907 -  
908 - return r;  
909 -}  
910 -  
911 -//  
912 -// Input callbacks.  
913 -//  
914 -typedef void voidfn(void);  
915 -  
916 -typedef struct iorec {  
917 - voidfn *fn;  
918 - XtInputId id;  
919 - struct iorec *next;  
920 -} iorec_t;  
921 -  
922 -static iorec_t *iorecs = NULL;  
923 -  
924 -static void  
925 -io_fn(XtPointer closure, int *source unused, XtInputId *id)  
926 -{  
927 - iorec_t *iorec;  
928 -  
929 - for (iorec = iorecs; iorec != NULL; iorec = iorec->next) {  
930 - if (iorec->id == *id) {  
931 - (*iorec->fn)();  
932 - break;  
933 - }  
934 - }  
935 -}  
936 -  
937 -unsigned long  
938 -AddInput(int sock, voidfn *fn)  
939 -{  
940 - iorec_t *iorec;  
941 -  
942 - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t));  
943 - iorec->fn = fn;  
944 - iorec->id = XtAppAddInput(appcontext, sock,  
945 - (XtPointer) XtInputReadMask, io_fn, NULL);  
946 -  
947 - iorec->next = iorecs;  
948 - iorecs = iorec;  
949 -  
950 - return iorec->id;  
951 -}  
952 -  
953 -unsigned long  
954 -AddExcept(int sock, voidfn *fn)  
955 -{  
956 - iorec_t *iorec;  
957 -  
958 - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t));  
959 - iorec->fn = fn;  
960 - iorec->id = XtAppAddInput(appcontext, sock,  
961 - (XtPointer) XtInputExceptMask, io_fn, NULL);  
962 - iorec->next = iorecs;  
963 - iorecs = iorec;  
964 -  
965 - return iorec->id;  
966 -}  
967 -  
968 -unsigned long  
969 -AddOutput(int sock, voidfn *fn)  
970 -{  
971 - iorec_t *iorec;  
972 -  
973 - iorec = (iorec_t *)XtMalloc(sizeof(iorec_t));  
974 - iorec->fn = fn;  
975 - iorec->id = XtAppAddInput(appcontext, sock,  
976 - (XtPointer) XtInputWriteMask, io_fn, NULL);  
977 - iorec->next = iorecs;  
978 - iorecs = iorec;  
979 -  
980 - return iorec->id;  
981 -}  
982 -  
983 -void  
984 -RemoveInput(unsigned long cookie)  
985 -{  
986 - iorec_t *iorec;  
987 - iorec_t *prev = NULL;  
988 -  
989 - for (iorec = iorecs; iorec != NULL; iorec = iorec->next) {  
990 - if (iorec->id == (XtInputId)cookie) {  
991 - break;  
992 - }  
993 - prev = iorec;  
994 - }  
995 -  
996 - if (iorec != NULL) {  
997 - XtRemoveInput((XtInputId)cookie);  
998 - if (prev != NULL)  
999 - prev->next = iorec->next;  
1000 - else  
1001 - iorecs = iorec->next;  
1002 - XtFree((XtPointer)iorec);  
1003 - }  
1004 -}  
1005 -  
1006 -//  
1007 -/ Timer callbacks.  
1008 -//  
1009 -  
1010 -typedef struct torec {  
1011 - voidfn *fn;  
1012 - XtIntervalId id;  
1013 - struct torec *next;  
1014 -} torec_t;  
1015 -  
1016 -static torec_t *torecs = NULL;  
1017 -  
1018 -static void  
1019 -to_fn(XtPointer closure, XtIntervalId *id)  
1020 -{  
1021 - torec_t *torec;  
1022 - torec_t *prev = NULL;  
1023 - voidfn *fn = NULL;  
1024 -  
1025 - for (torec = torecs; torec != NULL; torec = torec->next) {  
1026 - if (torec->id == *id) {  
1027 - break;  
1028 - }  
1029 - prev = torec;  
1030 - }  
1031 -  
1032 - if (torec != NULL) {  
1033 -  
1034 - // Remember the record.  
1035 - fn = torec->fn;  
1036 -  
1037 - // Free the record.  
1038 - if (prev != NULL)  
1039 - prev->next = torec->next;  
1040 - else  
1041 - torecs = torec->next;  
1042 - XtFree((XtPointer)torec);  
1043 -  
1044 - // Call the function.  
1045 - (*fn)();  
1046 - }  
1047 -}  
1048 -  
1049 -unsigned long  
1050 -AddTimeOut(unsigned long msec, voidfn *fn)  
1051 -{  
1052 - torec_t *torec;  
1053 -  
1054 - torec = (torec_t *)XtMalloc(sizeof(torec_t));  
1055 - torec->fn = fn;  
1056 - torec->id = XtAppAddTimeOut(appcontext, msec, to_fn, NULL);  
1057 - torec->next = torecs;  
1058 - torecs = torec;  
1059 - return (unsigned long)torec->id;  
1060 -}  
1061 -  
1062 -void  
1063 -RemoveTimeOut(unsigned long cookie)  
1064 -{  
1065 - torec_t *torec;  
1066 - torec_t *prev = NULL;  
1067 -  
1068 - for (torec = torecs; torec != NULL; torec = torec->next) {  
1069 - if (torec->id == (XtIntervalId)cookie) {  
1070 - break;  
1071 - }  
1072 - prev = torec;  
1073 - }  
1074 -  
1075 - if (torec != NULL) {  
1076 - XtRemoveTimeOut((XtIntervalId)cookie);  
1077 - if (prev != NULL)  
1078 - prev->next = torec->next;  
1079 - else  
1080 - torecs = torec->next;  
1081 - XtFree((XtPointer)torec);  
1082 - } else {  
1083 - Error("RemoveTimeOut: Can't find");  
1084 - }  
1085 -}  
1086 -  
1087 -KeySym  
1088 -StringToKeysym(char *s)  
1089 -{  
1090 - return XStringToKeysym(s);  
1091 -}  
1092 -#endif  
1093 -*/  
1094 -  
1095 LIB3270_EXPORT void lib3270_free(void *p) 884 LIB3270_EXPORT void lib3270_free(void *p)
1096 { 885 {
1097 if(p) 886 if(p)
@@ -38,7 +38,7 @@ LIB3270_INTERNAL void xs_warning(const char *fmt, ...) printflike(1, 2); @@ -38,7 +38,7 @@ LIB3270_INTERNAL void xs_warning(const char *fmt, ...) printflike(1, 2);
38 38
39 LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session)); 39 LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session));
40 LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session)); 40 LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session));
41 -LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); 41 +// LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session));
42 LIB3270_INTERNAL void RemoveInput(void *); 42 LIB3270_INTERNAL void RemoveInput(void *);
43 LIB3270_INTERNAL void * AddTimeOut(unsigned long msec, H3270 *session, void (*fn)(H3270 *session)); 43 LIB3270_INTERNAL void * AddTimeOut(unsigned long msec, H3270 *session, void (*fn)(H3270 *session));
44 LIB3270_INTERNAL void RemoveTimeOut(void *cookie); 44 LIB3270_INTERNAL void RemoveTimeOut(void *cookie);
@@ -44,51 +44,8 @@ @@ -44,51 +44,8 @@
44 #include "utilc.h" 44 #include "utilc.h"
45 #include "xioc.h" 45 #include "xioc.h"
46 46
47 -/* Statics. */  
48 -// static unsigned long ns_read_id;  
49 -// static unsigned long ns_exception_id;  
50 -// static Boolean reading = False;  
51 -// static Boolean excepting = False; 47 +#error xio.c is deprecated, use iocalls.c
52 48
53 -/*  
54 - * Called to set up input on a new network connection.  
55 - */  
56 -/*  
57 -void x_add_input(H3270 *h)  
58 -{  
59 -#ifdef _WIN32  
60 - h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception);  
61 - h->excepting = True;  
62 - h->ns_read_id = AddInput(h->sockEvent, h, net_input);  
63 - h->reading = True;  
64 -#else  
65 - h->ns_exception_id = AddExcept(h->sock, h, net_exception);  
66 - h->excepting = True;  
67 - h->ns_read_id = AddInput(h->sock, h, net_input);  
68 - h->reading = True;  
69 -#endif // WIN32  
70 -}  
71 -*/  
72 -/*  
73 - * Called when an exception is received to disable further exceptions.  
74 - */ /*  
75 -void x_except_off(H3270 *h)  
76 -{  
77 - CHECK_SESSION_HANDLE(h);  
78 -  
79 - if(h->excepting)  
80 - {  
81 - RemoveInput(h->ns_exception_id);  
82 - h->excepting = False;  
83 - }  
84 -}  
85 -*/  
86 -  
87 -/*  
88 - * Called when exception processing is complete to re-enable exceptions.  
89 - * This includes removing and restoring reading, so the exceptions are always  
90 - * processed first.  
91 - */  
92 void x_except_on(H3270 *h) 49 void x_except_on(H3270 *h)
93 { 50 {
94 if(h->excepting) 51 if(h->excepting)
@@ -99,33 +56,15 @@ void x_except_on(H3270 *h) @@ -99,33 +56,15 @@ void x_except_on(H3270 *h)
99 56
100 #ifdef WIN32 57 #ifdef WIN32
101 h->ns_exception_id = AddExcept((int) h->sockEvent, h, net_exception); 58 h->ns_exception_id = AddExcept((int) h->sockEvent, h, net_exception);
102 - h->excepting = True; 59 + h->excepting = 1;
103 60
104 if(h->reading) 61 if(h->reading)
105 h->ns_read_id = AddInput( (int) h->sockEvent, h, net_input); 62 h->ns_read_id = AddInput( (int) h->sockEvent, h, net_input);
106 #else 63 #else
107 h->ns_exception_id = AddExcept(h->sock, h, net_exception); 64 h->ns_exception_id = AddExcept(h->sock, h, net_exception);
108 - h->excepting = True; 65 + h->excepting = 1;
109 66
110 if(h->reading) 67 if(h->reading)
111 h->ns_read_id = AddInput(h->sock, h, net_input); 68 h->ns_read_id = AddInput(h->sock, h, net_input);
112 #endif // WIN32 69 #endif // WIN32
113 } 70 }
114 -  
115 -/*  
116 - * Called to disable input on a closing network connection.  
117 - */ /*  
118 -void x_remove_input(H3270 *h)  
119 -{  
120 - if(h->reading)  
121 - {  
122 - RemoveInput(h->ns_read_id);  
123 - h->reading = False;  
124 - }  
125 - if(h->excepting)  
126 - {  
127 - RemoveInput(h->ns_exception_id);  
128 - h->excepting = False;  
129 - }  
130 -}  
131 -*/