Commit 7eb746485d47d43bd640a13ae41568b585f950e1

Authored by perry.werneck@gmail.com
1 parent 2e3024e1

trace_netdata passa a receber um handle de sessão

src/lib3270/html.c
... ... @@ -208,7 +208,7 @@
208 208 if(info->mode == HTML_MODE_TEXT)
209 209 return;
210 210  
211   - trace("maxlength=%d",info->maxlength);
  211 +// trace("maxlength=%d",info->maxlength);
212 212  
213 213 if(info->maxlength < 1)
214 214 {
... ...
src/lib3270/iocalls.c
... ... @@ -570,13 +570,21 @@ void RemoveTimeOut(void * timer)
570 570 return remove_timeout(timer);
571 571 }
572 572  
  573 +#ifdef WIN32
573 574 void * AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session))
  575 +#else
  576 +void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session))
  577 +#endif // WIN32
574 578 {
575 579 CHECK_SESSION_HANDLE(session);
576 580 return add_input(source,session,fn);
577 581 }
578 582  
  583 +#ifdef WIN32
579 584 void * AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session))
  585 +#else
  586 +void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))
  587 +#endif // WIN32
580 588 {
581 589 CHECK_SESSION_HANDLE(session);
582 590 return add_except(source,session,fn);
... ...
src/lib3270/proxy.c
... ... @@ -341,8 +341,7 @@ proxy_negotiate(int type, int fd, char *host, unsigned short port)
341 341 }
342 342  
343 343 /* Sun PASSTHRU proxy. */
344   -static int
345   -proxy_passthru(int fd, char *host, unsigned short port)
  344 +static int proxy_passthru(int fd, char *host, unsigned short port)
346 345 {
347 346 char *buf;
348 347  
... ... @@ -351,11 +350,12 @@ proxy_passthru(int fd, char *host, unsigned short port)
351 350  
352 351 #if defined(X3270_TRACE) /*[*/
353 352 trace_dsn("Passthru Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf);
354   - trace_netdata('>', (unsigned char *)buf, (int) strlen(buf));
  353 + trace_netdata(&h3270,'>', (unsigned char *)buf, (int) strlen(buf));
355 354 #endif /*]*/
356 355  
357   - if (send(fd, buf, strlen(buf), 0) < 0) {
358   - popup_a_sockerr(NULL,"Passthru Proxy: send error");
  356 + if (send(fd, buf, strlen(buf), 0) < 0)
  357 + {
  358 + popup_a_sockerr(NULL,"Passthru Proxy: send error");
359 359 lib3270_free(buf);
360 360 return -1;
361 361 }
... ... @@ -386,7 +386,7 @@ proxy_http(int fd, char *host, unsigned short port)
386 386  
387 387 #if defined(X3270_TRACE) /*[*/
388 388 trace_dsn("HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf);
389   - trace_netdata('>', (unsigned char *)buf, (int) strlen(buf));
  389 + trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf));
390 390 #endif /*]*/
391 391  
392 392 if (send(fd, buf, strlen(buf), 0) < 0) {
... ... @@ -403,7 +403,7 @@ proxy_http(int fd, char *host, unsigned short port)
403 403  
404 404 #if defined(X3270_TRACE) /*[*/
405 405 trace_dsn("HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf);
406   - trace_netdata('>', (unsigned char *)buf, (int) strlen(buf));
  406 + trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf));
407 407 #endif /*]*/
408 408  
409 409 if (send(fd, buf, strlen(buf), 0) < 0) {
... ... @@ -415,7 +415,7 @@ proxy_http(int fd, char *host, unsigned short port)
415 415 strcpy(buf, "\r\n");
416 416 #if defined(X3270_TRACE) /*[*/
417 417 trace_dsn("HTTP Proxy: xmit ''\n");
418   - trace_netdata('>', (unsigned char *)buf, strlen(buf));
  418 + trace_netdata(&h3270, '>', (unsigned char *)buf, strlen(buf));
419 419 #endif /*]*/
420 420  
421 421 if (send(fd, buf, strlen(buf), 0) < 0) {
... ... @@ -441,7 +441,7 @@ proxy_http(int fd, char *host, unsigned short port)
441 441 popup_an_error(NULL,"HTTP Proxy: server timeout");
442 442 #if defined(X3270_TRACE) /*[*/
443 443 if (nread)
444   - trace_netdata('<', (unsigned char *)rbuf, nread);
  444 + trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread);
445 445 #endif /*]*/
446 446 return -1;
447 447 }
... ... @@ -451,14 +451,14 @@ proxy_http(int fd, char *host, unsigned short port)
451 451 popup_a_sockerr(NULL,"HTTP Proxy: receive error");
452 452 #if defined(X3270_TRACE) /*[*/
453 453 if (nread)
454   - trace_netdata('<', (unsigned char *)rbuf, nread);
  454 + trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread);
455 455 #endif /*]*/
456 456 return -1;
457 457 }
458 458 if (nr == 0) {
459 459 #if defined(X3270_TRACE) /*[*/
460 460 if (nread)
461   - trace_netdata('<', (unsigned char *)rbuf, nread);
  461 + trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread);
462 462 #endif /*]*/
463 463 popup_an_error(NULL,"HTTP Proxy: unexpected EOF");
464 464 return -1;
... ... @@ -475,7 +475,7 @@ proxy_http(int fd, char *host, unsigned short port)
475 475 rbuf[nread] = '\0';
476 476  
477 477 #if defined(X3270_TRACE) /*[*/
478   - trace_netdata('<', (unsigned char *)rbuf, nread);
  478 + trace_netdata(&h3270, '<', (unsigned char *)rbuf, nread);
479 479 trace_dsn("HTTP Proxy: recv '%s'\n", rbuf);
480 480 #endif /*]*/
481 481  
... ... @@ -502,7 +502,7 @@ proxy_telnet(int fd, char *host, unsigned short port)
502 502  
503 503 #if defined(X3270_TRACE) /*[*/
504 504 trace_dsn("TELNET Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf);
505   - trace_netdata('>', (unsigned char *)buf, (int) strlen(buf));
  505 + trace_netdata(&h3270, '>', (unsigned char *)buf, (int) strlen(buf));
506 506 #endif /*]*/
507 507  
508 508 if (send(fd, buf, strlen(buf), 0) < 0) {
... ... @@ -735,7 +735,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
735 735 strcpy((char *)rbuf, "\005\001\000");
736 736 #if defined(X3270_TRACE) /*[*/
737 737 trace_dsn("SOCKS5 Proxy: xmit version 5 nmethods 1 (no auth)\n");
738   - trace_netdata('>', rbuf, 3);
  738 + trace_netdata(&h3270, '>', rbuf, 3);
739 739 #endif /*]*/
740 740 if (send(fd, (const char *) rbuf, 3, 0) < 0) {
741 741 popup_a_sockerr(NULL,"SOCKS5 Proxy: send error");
... ... @@ -755,29 +755,32 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
755 755 FD_SET(fd, &rfds);
756 756 tv.tv_sec = 15;
757 757 tv.tv_usec = 0;
758   - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) {
759   - popup_an_error(NULL,"SOCKS5 Proxy: server timeout");
  758 + if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0)
  759 + {
  760 + popup_an_error(&h3270,"SOCKS5 Proxy: server timeout");
760 761 #if defined(X3270_TRACE) /*[*/
761   - if (nread)
762   - trace_netdata('<', rbuf, nread);
  762 + if (nread)
  763 + trace_netdata(&h3270, '<', rbuf, nread);
763 764 #endif /*]*/
764 765 return -1;
765 766 }
766 767  
767 768 nr = recv(fd, (char *) &rbuf[nread], 1, 0);
768   - if (nr < 0) {
769   - popup_a_sockerr(NULL,"SOCKS5 Proxy: receive error");
  769 + if (nr < 0)
  770 + {
  771 + popup_a_sockerr(&h3270,"SOCKS5 Proxy: receive error");
770 772 #if defined(X3270_TRACE) /*[*/
771   - if (nread)
772   - trace_netdata('<', rbuf, nread);
  773 + if (nread)
  774 + trace_netdata(&h3270, '<', rbuf, nread);
773 775 #endif /*]*/
774 776 return -1;
775 777 }
776   - if (nr == 0) {
  778 + if (nr == 0)
  779 + {
777 780 popup_a_sockerr(NULL,"SOCKS5 Proxy: unexpected EOF");
778 781 #if defined(X3270_TRACE) /*[*/
779   - if (nread)
780   - trace_netdata('<', rbuf, nread);
  782 + if (nread)
  783 + trace_netdata(&h3270, '<', rbuf, nread);
781 784 #endif /*]*/
782 785 return -1;
783 786 }
... ... @@ -786,17 +789,17 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
786 789 }
787 790  
788 791 #if defined(X3270_TRACE) /*[*/
789   - trace_netdata('<', rbuf, nread);
  792 + trace_netdata(&h3270, '<', rbuf, nread);
790 793 #endif /*]*/
791 794  
792   - if (rbuf[0] != 0x05 || (rbuf[1] != 0 && rbuf[1] != 0xff)) {
793   - popup_an_error(NULL,"SOCKS5 Proxy: bad authentication response");
  795 + if (rbuf[0] != 0x05 || (rbuf[1] != 0 && rbuf[1] != 0xff))
  796 + {
  797 + popup_an_error(NULL,"SOCKS5 Proxy: bad authentication response");
794 798 return -1;
795 799 }
796 800  
797 801 #if defined(X3270_TRACE) /*[*/
798   - trace_dsn("SOCKS5 Proxy: recv version %d method %d\n", rbuf[0],
799   - rbuf[1]);
  802 + trace_dsn("SOCKS5 Proxy: recv version %d method %d\n", rbuf[0],rbuf[1]);
800 803 #endif /*]*/
801 804  
802 805 if (rbuf[1] == 0xff) {
... ... @@ -836,7 +839,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
836 839 ((ha.sa.sa_family == AF_INET)? "IPv4": "IPv6"),
837 840 use_name? host: nbuf,
838 841 port);
839   - trace_netdata('>', (unsigned char *)buf, s - buf);
  842 + trace_netdata(&h3270, '>', (unsigned char *)buf, s - buf);
840 843 #endif /*]*/
841 844  
842 845 if (send(fd, buf, s - buf, 0) < 0) {
... ... @@ -869,19 +872,21 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
869 872 }
870 873  
871 874 nr = recv(fd, (char *) &r, 1, 0);
872   - if (nr < 0) {
  875 + if (nr < 0)
  876 + {
873 877 popup_a_sockerr(NULL,"SOCKS5 Proxy: receive error");
874 878 #if defined(X3270_TRACE) /*[*/
875   - if (nread)
876   - trace_netdata('<', (unsigned char *)buf, nread);
  879 + if (nread)
  880 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
877 881 #endif /*]*/
878 882 return -1;
879 883 }
880   - if (nr == 0) {
881   - popup_an_error(NULL,"SOCKS5 Proxy: unexpected EOF");
  884 + if (nr == 0)
  885 + {
  886 + popup_an_error(&h3270, "SOCKS5 Proxy: unexpected EOF");
882 887 #if defined(X3270_TRACE) /*[*/
883   - if (nread)
884   - trace_netdata('<', (unsigned char *)buf, nread);
  888 + if (nread)
  889 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
885 890 #endif /*]*/
886 891 return -1;
887 892 }
... ... @@ -891,12 +896,12 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
891 896  
892 897 switch (nread++) {
893 898 case 0:
894   - if (r != 0x05) {
895   - popup_an_error(NULL,"SOCKS5 Proxy: incorrect "
896   - "reply version 0x%02x", r);
  899 + if (r != 0x05)
  900 + {
  901 + popup_an_error(&h3270, "SOCKS5 Proxy: incorrect reply version 0x%02x", r);
897 902 #if defined(X3270_TRACE) /*[*/
898 903 if (nread)
899   - trace_netdata('<', (unsigned char *)buf, nread);
  904 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
900 905 #endif /*]*/
901 906 return -1;
902 907 }
... ... @@ -904,17 +909,16 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
904 909 case 1:
905 910 #if defined(X3270_TRACE) /*[*/
906 911 if (r != 0x00)
907   - trace_netdata('<', (unsigned char *)buf, nread);
  912 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
908 913 #endif /*]*/
909 914 switch (r) {
910 915 case 0x00:
911 916 break;
912 917 case 0x01:
913   - popup_an_error(NULL,"SOCKS5 Proxy: server failure");
  918 + popup_an_error(&h3270, "SOCKS5 Proxy: server failure");
914 919 return -1;
915 920 case 0x02:
916   - popup_an_error(NULL,"SOCKS5 Proxy: connection not "
917   - "allowed");
  921 + popup_an_error(&h3270, "SOCKS5 Proxy: connection not allowed");
918 922 return -1;
919 923 case 0x03:
920 924 popup_an_error(NULL,"SOCKS5 Proxy: network "
... ... @@ -961,11 +965,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
961 965 break;
962 966 #endif /*]*/
963 967 default:
964   - popup_an_error(NULL,"SOCKS5 Proxy: unknown server "
965   - "address type 0x%02x", r);
  968 + popup_an_error(&h3270, "SOCKS5 Proxy: unknown server address type 0x%02x", r);
966 969 #if defined(X3270_TRACE) /*[*/
967 970 if (nread)
968   - trace_netdata('<', (unsigned char *)buf, nread);
  971 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
969 972 #endif /*]*/
970 973 return -1;
971 974 }
... ... @@ -980,7 +983,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d)
980 983 }
981 984  
982 985 #if defined(X3270_TRACE) /*[*/
983   - trace_netdata('<', (unsigned char *)buf, nread);
  986 + trace_netdata(&h3270, '<', (unsigned char *)buf, nread);
984 987 switch (buf[3]) {
985 988 case 0x01: /* IPv4 */
986 989 memcpy(&ha.sin.sin_addr, &buf[4], 4);
... ...
src/lib3270/telnet.c
... ... @@ -210,7 +210,7 @@ static char vlnext;
210 210 // static unsigned short proxy_port = 0;
211 211  
212 212 static int telnet_fsm(H3270 *session, unsigned char c);
213   -static void net_rawout(H3270 *session, unsigned const char *buf, int len);
  213 +static void net_rawout(H3270 *session, unsigned const char *buf, size_t len);
214 214 static void check_in3270(H3270 *session);
215 215 static void store3270in(H3270 *hSession, unsigned char c);
216 216 static void check_linemode(H3270 *hSession, Boolean init);
... ... @@ -992,7 +992,9 @@ LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned
992 992 {
993 993 register const unsigned char * cp;
994 994  
995   - trace_netdata('<', netrbuf, nr);
  995 + trace("%s: nr=%d",__FUNCTION__,nr);
  996 +
  997 + trace_netdata(hSession, '<', netrbuf, nr);
996 998  
997 999 hSession->ns_brcvd += nr;
998 1000 for (cp = netrbuf; cp < (netrbuf + nr); cp++)
... ... @@ -2096,15 +2098,20 @@ LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf
2096 2098 return -1;
2097 2099 }
2098 2100  
2099   -/*
2100   - * net_rawout
2101   - * Send out raw telnet data. We assume that there will always be enough
2102   - * space to buffer what we want to transmit, so we don't handle EAGAIN or
2103   - * EWOULDBLOCK.
  2101 +/**
  2102 + * Send out raw telnet data.
  2103 + *
  2104 + * We assume that there will always be enough space to buffer what we want to transmit,
  2105 + * so we don't handle EAGAIN or EWOULDBLOCK.
  2106 + *
  2107 + * @param hSession Session handle.
  2108 + * @param buf Buffer to send.
  2109 + * @param len Buffer length
  2110 + *
2104 2111 */
2105   -static void net_rawout(H3270 *hSession, unsigned const char *buf, int len)
  2112 +static void net_rawout(H3270 *hSession, unsigned const char *buf, size_t len)
2106 2113 {
2107   - trace_netdata('>', buf, len);
  2114 + trace_netdata(hSession, '>', buf, len);
2108 2115  
2109 2116 while (len)
2110 2117 {
... ... @@ -2669,22 +2676,26 @@ opt(unsigned char c)
2669 2676  
2670 2677 #define LINEDUMP_MAX 32
2671 2678  
2672   -void trace_netdata(char direction, unsigned const char *buf, int len)
  2679 +void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, int len)
2673 2680 {
2674 2681 int offset;
2675 2682 struct timeval ts;
2676 2683 double tdiff;
2677 2684  
2678   - if (!lib3270_get_toggle(&h3270,LIB3270_TOGGLE_DS_TRACE))
  2685 + if (!lib3270_get_toggle(hSession,LIB3270_TOGGLE_DS_TRACE))
2679 2686 return;
  2687 +
2680 2688 (void) gettimeofday(&ts, (struct timezone *)NULL);
2681   - if (IN_3270) {
  2689 + if (IN_3270)
  2690 + {
2682 2691 tdiff = ((1.0e6 * (double)(ts.tv_sec - h3270.ds_ts.tv_sec)) +
2683 2692 (double)(ts.tv_usec - h3270.ds_ts.tv_usec)) / 1.0e6;
2684 2693 trace_dsn("%c +%gs\n", direction, tdiff);
2685 2694 }
2686   - h3270.ds_ts = ts;
2687   - for (offset = 0; offset < len; offset++) {
  2695 +
  2696 + hSession->ds_ts = ts;
  2697 + for (offset = 0; offset < len; offset++)
  2698 + {
2688 2699 if (!(offset % LINEDUMP_MAX))
2689 2700 trace_dsn("%s%c 0x%-3x ",
2690 2701 (offset ? "\n" : ""), direction, offset);
... ...
src/lib3270/telnetc.h
... ... @@ -60,7 +60,7 @@ LIB3270_INTERNAL void space3270out(H3270 *hSession, int n);
60 60 // LIB3270_INTERNAL char *net_proxy_port(void);
61 61  
62 62 #if defined(X3270_TRACE)
63   - LIB3270_INTERNAL void trace_netdata(char direction, unsigned const char *buf, int len);
  63 + LIB3270_INTERNAL void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, int len);
64 64 #else
65 65 #define trace_netdata(direction, buf, len) /* */
66 66 #endif // X3270_TRACE
... ...