Commit fa4353639c4a77a426039bb91b2abdb7939838e6
1 parent
51677050
Exists in
master
and in
3 other branches
Testing windows build.
Showing
6 changed files
with
274 additions
and
471 deletions
Show diff stats
src/lib3270/private.h
... | ... | @@ -656,7 +656,7 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); |
656 | 656 | |
657 | 657 | #if defined(HAVE_LIBSSL) /*[*/ |
658 | 658 | |
659 | - LIB3270_INTERNAL int ssl_ctx_init(void); | |
659 | + LIB3270_INTERNAL int ssl_ctx_init(H3270 *hSession); | |
660 | 660 | LIB3270_INTERNAL int ssl_init(H3270 *session); |
661 | 661 | LIB3270_INTERNAL int ssl_negotiate(H3270 *hSession); |
662 | 662 | LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state); | ... | ... |
src/lib3270/ssl/init.c
src/lib3270/ssl/negotiate.c
... | ... | @@ -84,10 +84,11 @@ int ssl_init(H3270 *hSession) |
84 | 84 | hSession->ssl.error = 0; |
85 | 85 | hSession->ssl.host = False; |
86 | 86 | |
87 | - if(ssl_ctx_init()) { | |
87 | + if(ssl_ctx_init(hSession)) { | |
88 | 88 | |
89 | 89 | hSession->ssl.error = ERR_get_error(); |
90 | 90 | |
91 | + /* | |
91 | 92 | lib3270_popup_dialog( |
92 | 93 | hSession, |
93 | 94 | LIB3270_NOTIFY_ERROR, |
... | ... | @@ -95,6 +96,7 @@ int ssl_init(H3270 *hSession) |
95 | 96 | N_( "SSL initialization has failed" ), |
96 | 97 | "%s",ERR_reason_error_string(hSession->ssl.error) |
97 | 98 | ); |
99 | + */ | |
98 | 100 | |
99 | 101 | set_ssl_state(hSession,LIB3270_SSL_UNDEFINED); |
100 | 102 | |
... | ... | @@ -110,6 +112,7 @@ int ssl_init(H3270 *hSession) |
110 | 112 | { |
111 | 113 | hSession->ssl.error = ERR_get_error(); |
112 | 114 | |
115 | + /* | |
113 | 116 | lib3270_popup_dialog( |
114 | 117 | hSession, |
115 | 118 | LIB3270_NOTIFY_ERROR, |
... | ... | @@ -117,6 +120,7 @@ int ssl_init(H3270 *hSession) |
117 | 120 | N_( "Cant create a new SSL structure for current connection." ), |
118 | 121 | N_( "%s" ),ERR_lib_error_string(hSession->ssl.error) |
119 | 122 | ); |
123 | + */ | |
120 | 124 | |
121 | 125 | return -1; |
122 | 126 | } | ... | ... |
src/lib3270/util.c
... | ... | @@ -19,207 +19,42 @@ |
19 | 19 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
20 | 20 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 | * |
22 | - * Este programa está nomeado como util.c e possui - linhas de código. | |
22 | + * Este programa está nomeado como - e possui - linhas de código. | |
23 | 23 | * |
24 | 24 | * Contatos: |
25 | 25 | * |
26 | 26 | * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
27 | 27 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
28 | - * licinio@bb.com.br (Licínio Luis Branco) | |
29 | - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
30 | - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | |
31 | 28 | * |
32 | 29 | */ |
33 | 30 | |
34 | -/* | |
35 | - * util.c | |
36 | - * Utility functions for x3270/c3270/s3270/tcl3270 | |
31 | +/** | |
32 | + * @brief Utility functions for x3270/c3270/s3270/tcl3270 | |
37 | 33 | */ |
38 | 34 | |
39 | 35 | #define _GNU_SOURCE |
40 | 36 | |
41 | -#if defined(_WIN32) | |
42 | - #include <winsock2.h> | |
43 | - #include <windows.h> | |
44 | -#endif // _WIN32 | |
45 | - | |
46 | 37 | #include "private.h" |
38 | +// #include <pwd.h> | |
47 | 39 | |
48 | -#if defined(_WIN32) | |
49 | - | |
50 | - #include "winversc.h" | |
51 | - #include <ws2tcpip.h> | |
52 | - #include <stdio.h> | |
53 | - #include <errno.h> | |
54 | - #include "w3miscc.h" | |
55 | - | |
56 | -#else | |
57 | - #include <pwd.h> | |
58 | -#endif // _WIN32 | |
59 | - | |
60 | -#ifdef HAVE_MALLOC_H | |
61 | - #include <malloc.h> | |
62 | -#endif | |
63 | - | |
64 | -#ifndef ANDROID | |
65 | - #include <stdlib.h> | |
66 | -#endif // !ANDROID | |
40 | +//#ifdef HAVE_ICONV | |
41 | +// #include <iconv.h> | |
42 | +//#endif // HAVE_ICONV | |
67 | 43 | |
68 | -#ifdef HAVE_ICONV | |
69 | - #include <iconv.h> | |
70 | -#endif // HAVE_ICONV | |
71 | - | |
72 | -#include <stdarg.h> | |
73 | -#include "resources.h" | |
44 | +//#include <stdarg.h> | |
45 | +// #include "resources.h" | |
74 | 46 | |
75 | 47 | #include "utilc.h" |
76 | -#include "popupsc.h" | |
77 | -#include "api.h" | |
48 | +//#include "popupsc.h" | |
49 | +//#include "api.h" | |
78 | 50 | |
79 | -#include <lib3270/session.h> | |
80 | -#include <lib3270/selection.h> | |
51 | +//#include <lib3270/session.h> | |
52 | +//#include <lib3270/selection.h> | |
81 | 53 | |
82 | 54 | #define my_isspace(c) isspace((unsigned char)c) |
83 | 55 | |
84 | -#if defined(_WIN32) | |
85 | - | |
86 | -int is_nt = 1; | |
87 | -int has_ipv6 = 1; | |
88 | - | |
89 | -int get_version_info(void) | |
90 | -{ | |
91 | - OSVERSIONINFO info; | |
92 | - | |
93 | - // Figure out what version of Windows this is. | |
94 | - memset(&info, '\0', sizeof(info)); | |
95 | - info.dwOSVersionInfoSize = sizeof(info); | |
96 | - if(GetVersionEx(&info) == 0) | |
97 | - { | |
98 | - lib3270_write_log(NULL,"lib3270","%s","Can't get Windows version"); | |
99 | - return -1; | |
100 | - } | |
101 | - | |
102 | - // Yes, people still run Win98. | |
103 | - if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) | |
104 | - is_nt = 0; | |
105 | - | |
106 | - // Win2K and earlier is IPv4-only. WinXP and later can have IPv6. | |
107 | - if (!is_nt || info.dwMajorVersion < 5 || (info.dwMajorVersion == 5 && info.dwMinorVersion < 1)) | |
108 | - { | |
109 | - has_ipv6 = 0; | |
110 | - } | |
111 | - | |
112 | - return 0; | |
113 | -} | |
114 | - | |
115 | -// Convert a network address to a string. | |
116 | -#ifndef HAVE_INET_NTOP | |
117 | -const char * inet_ntop(int af, const void *src, char *dst, socklen_t cnt) | |
118 | -{ | |
119 | - union { | |
120 | - struct sockaddr sa; | |
121 | - struct sockaddr_in sin; | |
122 | - struct sockaddr_in6 sin6; | |
123 | - } sa; | |
124 | - DWORD ssz; | |
125 | - DWORD sz = cnt; | |
126 | - | |
127 | - memset(&sa, '\0', sizeof(sa)); | |
128 | - | |
129 | - switch (af) { | |
130 | - case AF_INET: | |
131 | - sa.sin = *(struct sockaddr_in *)src; // struct copy | |
132 | - ssz = sizeof(struct sockaddr_in); | |
133 | - break; | |
134 | - case AF_INET6: | |
135 | - sa.sin6 = *(struct sockaddr_in6 *)src; // struct copy | |
136 | - ssz = sizeof(struct sockaddr_in6); | |
137 | - break; | |
138 | - default: | |
139 | - if (cnt > 0) | |
140 | - dst[0] = '\0'; | |
141 | - return NULL; | |
142 | - } | |
143 | - | |
144 | - sa.sa.sa_family = af; | |
145 | - | |
146 | - if (WSAAddressToString(&sa.sa, ssz, NULL, dst, &sz) != 0) { | |
147 | - if (cnt > 0) | |
148 | - dst[0] = '\0'; | |
149 | - return NULL; | |
150 | - } | |
151 | - | |
152 | - return dst; | |
153 | -} | |
154 | -#endif // HAVE_INET_NTOP | |
155 | - | |
156 | -// Decode a Win32 error number. | |
157 | -LIB3270_EXPORT const char * lib3270_win32_strerror(int e) | |
158 | -{ | |
159 | - static char buffer[4096]; | |
160 | - | |
161 | - if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,e,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,sizeof(buffer),NULL) == 0) | |
162 | - { | |
163 | - snprintf(buffer, 4095, _( "Windows error %d" ), e); | |
164 | - return buffer; | |
165 | - } | |
166 | - | |
167 | -#ifdef HAVE_ICONV | |
168 | - { | |
169 | - // Convert from windows codepage to UTF-8 pw3270´s default charset | |
170 | - iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); | |
171 | - | |
172 | - trace("[%s]",buffer); | |
173 | - | |
174 | - if(hConv == (iconv_t) -1) | |
175 | - { | |
176 | - lib3270_write_log(NULL,"iconv","%s: Error creating charset conversion",__FUNCTION__); | |
177 | - } | |
178 | - else | |
179 | - { | |
180 | - size_t in = strlen(buffer); | |
181 | - size_t out = (in << 1); | |
182 | - char * ptr; | |
183 | - char * outBuffer = (char *) malloc(out); | |
184 | - ICONV_CONST char * inBuffer = (ICONV_CONST char *) buffer; | |
185 | - | |
186 | - memset(ptr=outBuffer,0,out); | |
187 | - | |
188 | - iconv(hConv,NULL,NULL,NULL,NULL); // Reset state | |
189 | - | |
190 | - if(iconv(hConv,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
191 | - { | |
192 | - strncpy(buffer,outBuffer,4095); | |
193 | - } | |
194 | - | |
195 | - free(outBuffer); | |
196 | - | |
197 | - iconv_close(hConv); | |
198 | - } | |
199 | - | |
200 | - } | |
201 | -#endif // HAVE_ICONV | |
202 | - | |
203 | - return buffer; | |
204 | -} | |
205 | - | |
206 | -LIB3270_EXPORT const char * lib3270_win32_local_charset(void) | |
207 | -{ | |
208 | - // Reference: | |
209 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/dd318070(v=vs.85).aspx | |
210 | - | |
211 | - /// TODO: Use GetACP() to identify the correct code page | |
212 | - | |
213 | - trace("Windows CHARSET is %u",GetACP()); | |
214 | - | |
215 | - return "CP1252"; | |
216 | -} | |
217 | - | |
218 | - | |
219 | -#endif // _WIN32 | |
220 | - | |
221 | -/* | |
222 | - * Cheesy internal version of sprintf that allocates its own memory. | |
56 | +/** | |
57 | + * @brief Cheesy internal version of sprintf that allocates its own memory. | |
223 | 58 | */ |
224 | 59 | char * lib3270_vsprintf(const char *fmt, va_list args) |
225 | 60 | { |
... | ... | @@ -270,10 +105,11 @@ LIB3270_EXPORT char * lib3270_strdup_printf(const char *fmt, ...) |
270 | 105 | return r; |
271 | 106 | } |
272 | 107 | |
273 | -/* | |
274 | - * Common helper functions to insert strings, through a template, into a new | |
275 | - * buffer. | |
276 | - * 'format' is assumed to be a printf format string with '%s's in it. | |
108 | +/** | |
109 | + * @brief Common helper functions to insert strings, through a template, into a new buffer. | |
110 | + * | |
111 | + * @param format A printf format string with '%s's in it. | |
112 | + * | |
277 | 113 | */ |
278 | 114 | char * xs_buffer(const char *fmt, ...) |
279 | 115 | { |
... | ... | @@ -314,7 +150,9 @@ xs_error(const char *fmt, ...) |
314 | 150 | } |
315 | 151 | |
316 | 152 | |
317 | -/* | |
153 | +/** | |
154 | + * @brief Definition resource splitter. | |
155 | + * | |
318 | 156 | * Definition resource splitter, for resources of the repeating form: |
319 | 157 | * left: right\n |
320 | 158 | * |
... | ... | @@ -392,8 +230,9 @@ split_dresource(char **st, char **left, char **right) |
392 | 230 | return 1; |
393 | 231 | } |
394 | 232 | |
395 | -/* | |
396 | - * Split a DBCS resource into its parts. | |
233 | +/** | |
234 | + * @brief Split a DBCS resource into its parts. | |
235 | + * | |
397 | 236 | * Returns the number of parts found: |
398 | 237 | * -1 error (empty sub-field) |
399 | 238 | * 0 nothing found |
... | ... | @@ -466,8 +305,8 @@ split_dbcs_resource(const char *value, char sep, char **part1, char **part2) |
466 | 305 | } |
467 | 306 | |
468 | 307 | #if defined(X3270_DISPLAY) /*[*/ |
469 | -/* | |
470 | - * List resource splitter, for lists of elements speparated by newlines. | |
308 | +/** | |
309 | + * @brief List resource splitter, for lists of elements speparated by newlines. | |
471 | 310 | * |
472 | 311 | * Can be called iteratively. |
473 | 312 | * Returns 1 for success, 0 for EOF, -1 for error. |
... | ... | @@ -518,243 +357,8 @@ split_lresource(char **st, char **value) |
518 | 357 | #endif /*]*/ |
519 | 358 | |
520 | 359 | |
521 | -/* | |
522 | -#if !defined(LIB3270) | |
523 | - | |
524 | -const char * | |
525 | -get_message(const char *key) | |
526 | -{ | |
527 | - static char namebuf[128]; | |
528 | - char *r; | |
529 | - | |
530 | - (void) sprintf(namebuf, "%s.%s", ResMessage, key); | |
531 | - if ((r = get_resource(namebuf)) != CN) | |
532 | - return r; | |
533 | - else { | |
534 | - (void) sprintf(namebuf, "[missing \"%s\" message]", key); | |
535 | - return namebuf; | |
536 | - } | |
537 | -} | |
538 | - | |
539 | -#endif | |
540 | -*/ | |
541 | - | |
542 | -// #define ex_getenv getenv | |
543 | - | |
544 | -/* Variable and tilde substitution functions. */ /* | |
545 | -static char * | |
546 | -var_subst(const char *s) | |
547 | -{ | |
548 | - enum { VS_BASE, VS_QUOTE, VS_DOLLAR, VS_BRACE, VS_VN, VS_VNB, VS_EOF } | |
549 | - state = VS_BASE; | |
550 | - char c; | |
551 | - int o_len = strlen(s) + 1; | |
552 | - char *ob; | |
553 | - char *o; | |
554 | - const char *vn_start = CN; | |
555 | - | |
556 | - if (strchr(s, '$') == CN) | |
557 | - return NewString(s); | |
558 | - | |
559 | - o_len = strlen(s) + 1; | |
560 | - ob = lib3270_malloc(o_len); | |
561 | - o = ob; | |
562 | -# define LBR '{' | |
563 | -# define RBR '}' | |
564 | - | |
565 | - while (state != VS_EOF) { | |
566 | - c = *s; | |
567 | - switch (state) { | |
568 | - case VS_BASE: | |
569 | - if (c == '\\') | |
570 | - state = VS_QUOTE; | |
571 | - else if (c == '$') | |
572 | - state = VS_DOLLAR; | |
573 | - else | |
574 | - *o++ = c; | |
575 | - break; | |
576 | - case VS_QUOTE: | |
577 | - if (c == '$') { | |
578 | - *o++ = c; | |
579 | - o_len--; | |
580 | - } else { | |
581 | - *o++ = '\\'; | |
582 | - *o++ = c; | |
583 | - } | |
584 | - state = VS_BASE; | |
585 | - break; | |
586 | - case VS_DOLLAR: | |
587 | - if (c == LBR) | |
588 | - state = VS_BRACE; | |
589 | - else if (isalpha(c) || c == '_') { | |
590 | - vn_start = s; | |
591 | - state = VS_VN; | |
592 | - } else { | |
593 | - *o++ = '$'; | |
594 | - *o++ = c; | |
595 | - state = VS_BASE; | |
596 | - } | |
597 | - break; | |
598 | - case VS_BRACE: | |
599 | - if (isalpha(c) || c == '_') { | |
600 | - vn_start = s; | |
601 | - state = VS_VNB; | |
602 | - } else { | |
603 | - *o++ = '$'; | |
604 | - *o++ = LBR; | |
605 | - *o++ = c; | |
606 | - state = VS_BASE; | |
607 | - } | |
608 | - break; | |
609 | - case VS_VN: | |
610 | - case VS_VNB: | |
611 | - if (!(isalnum(c) || c == '_')) { | |
612 | - int vn_len; | |
613 | - char *vn; | |
614 | - char *vv; | |
615 | - | |
616 | - vn_len = s - vn_start; | |
617 | - if (state == VS_VNB && c != RBR) { | |
618 | - *o++ = '$'; | |
619 | - *o++ = LBR; | |
620 | - (void) strncpy(o, vn_start, vn_len); | |
621 | - o += vn_len; | |
622 | - state = VS_BASE; | |
623 | - continue; // rescan | |
624 | - } | |
625 | - vn = lib3270_malloc(vn_len + 1); | |
626 | - (void) strncpy(vn, vn_start, vn_len); | |
627 | - vn[vn_len] = '\0'; | |
628 | - | |
629 | -#ifndef ANDROID | |
630 | - if((vv = getenv(vn))) | |
631 | - { | |
632 | - *o = '\0'; | |
633 | - o_len = o_len | |
634 | - - 1 // '$' | |
635 | - - (state == VS_VNB) // | |
636 | - - vn_len // name | |
637 | - - (state == VS_VNB) // } | |
638 | - + strlen(vv); | |
639 | - ob = Realloc(ob, o_len); | |
640 | - o = strchr(ob, '\0'); | |
641 | - (void) strcpy(o, vv); | |
642 | - o += strlen(vv); | |
643 | - } | |
644 | -#endif // !ANDROID | |
645 | - | |
646 | - lib3270_free(vn); | |
647 | - if (state == VS_VNB) { | |
648 | - state = VS_BASE; | |
649 | - break; | |
650 | - } else { | |
651 | - // Rescan this character | |
652 | - state = VS_BASE; | |
653 | - continue; | |
654 | - } | |
655 | - } | |
656 | - break; | |
657 | - case VS_EOF: | |
658 | - break; | |
659 | - } | |
660 | - s++; | |
661 | - if (c == '\0') | |
662 | - state = VS_EOF; | |
663 | - } | |
664 | - return ob; | |
665 | -} | |
666 | -*/ | |
667 | - | |
668 | -#if !defined(_WIN32) | |
669 | -/* | |
670 | - * Do tilde (home directory) substitution on a string. Returns a malloc'd | |
671 | - * result. | |
672 | - */ | |
673 | - /* | |
674 | -static char * | |
675 | -tilde_subst(const char *s) | |
676 | -{ | |
677 | - char *slash; | |
678 | - const char *name; | |
679 | - const char *rest; | |
680 | - struct passwd *p; | |
681 | - char *r; | |
682 | - char *mname = CN; | |
683 | - | |
684 | - // Does it start with a "~"? | |
685 | - if (*s != '~') | |
686 | - return NewString(s); | |
687 | - | |
688 | - // Terminate with "/". | |
689 | - slash = strchr(s, '/'); | |
690 | - if (slash) { | |
691 | - int len = slash - s; | |
692 | - | |
693 | - mname = lib3270_malloc(len + 1); | |
694 | - (void) strncpy(mname, s, len); | |
695 | - mname[len] = '\0'; | |
696 | - name = mname; | |
697 | - rest = slash; | |
698 | - } else { | |
699 | - name = s; | |
700 | - rest = strchr(name, '\0'); | |
701 | - } | |
702 | - | |
703 | - // Look it up. | |
704 | - if (!strcmp(name, "~")) // this user | |
705 | - p = getpwuid(getuid()); | |
706 | - else // somebody else | |
707 | - p = getpwnam(name + 1); | |
708 | - | |
709 | - // Free any temporary copy. | |
710 | - lib3270_free(mname); | |
711 | - | |
712 | - // Substitute and return. | |
713 | - if (p == (struct passwd *)NULL) | |
714 | - r = NewString(s); | |
715 | - else { | |
716 | - r = lib3270_malloc(strlen(p->pw_dir) + strlen(rest) + 1); | |
717 | - (void) strcpy(r, p->pw_dir); | |
718 | - (void) strcat(r, rest); | |
719 | - } | |
720 | - return r; | |
721 | -} */ | |
722 | -#endif | |
723 | -/* | |
724 | -char * | |
725 | -do_subst(const char *s, Boolean do_vars, Boolean do_tilde) | |
726 | -{ | |
727 | - if (!do_vars && !do_tilde) | |
728 | - return NewString(s); | |
729 | - | |
730 | - if (do_vars) { | |
731 | - char *t; | |
732 | - | |
733 | - t = var_subst(s); | |
734 | -#if !defined(_WIN32) | |
735 | - if (do_tilde) { | |
736 | - char *u; | |
737 | - | |
738 | - u = tilde_subst(t); | |
739 | - lib3270_free(t); | |
740 | - return u; | |
741 | - } | |
742 | -#endif | |
743 | - return t; | |
744 | - } | |
745 | - | |
746 | -#if !defined(_WIN32) | |
747 | - return tilde_subst(s); | |
748 | -#else | |
749 | - return NewString(s); | |
750 | -#endif | |
751 | -} | |
752 | - | |
753 | -*/ | |
754 | - | |
755 | -/* | |
756 | - * ctl_see | |
757 | - * Expands a character in the manner of "cat -v". | |
360 | +/** | |
361 | + * @brief Expands a character in the manner of "cat -v". | |
758 | 362 | */ |
759 | 363 | char * |
760 | 364 | ctl_see(int c) |
... | ... | @@ -782,8 +386,8 @@ ctl_see(int c) |
782 | 386 | return buf; |
783 | 387 | } |
784 | 388 | |
785 | -/* | |
786 | - * Whitespace stripper. | |
389 | +/** | |
390 | + * @brief Whitespace stripper. | |
787 | 391 | */ |
788 | 392 | char * |
789 | 393 | strip_whitespace(const char *s) |
... | ... | @@ -802,8 +406,8 @@ strip_whitespace(const char *s) |
802 | 406 | return t; |
803 | 407 | } |
804 | 408 | |
805 | -/* | |
806 | - * Hierarchy (a>b>c) splitter. | |
409 | +/** | |
410 | + * @brief Hierarchy (a>b>c) splitter. | |
807 | 411 | */ |
808 | 412 | Boolean |
809 | 413 | split_hier(char *label, char **base, char ***parents) |
... | ... | @@ -837,8 +441,8 @@ split_hier(char *label, char **base, char ***parents) |
837 | 441 | return True; |
838 | 442 | } |
839 | 443 | |
840 | -/* | |
841 | - * Incremental, reallocing version of snprintf. | |
444 | +/** | |
445 | + * @brief Incremental, reallocing version of snprintf. | |
842 | 446 | */ |
843 | 447 | #define RPF_BLKSIZE 4096 |
844 | 448 | #define SP_TMP_LEN 16384 |
... | ... | @@ -852,14 +456,18 @@ rpf_init(rpf_t *r) |
852 | 456 | r->cur_len = 0; |
853 | 457 | } |
854 | 458 | |
855 | -/* Reset an initialized RPF structure (re-use with length 0). */ | |
459 | +/** | |
460 | + * @brief Reset an initialized RPF structure (re-use with length 0). | |
461 | + */ | |
856 | 462 | void |
857 | 463 | rpf_reset(rpf_t *r) |
858 | 464 | { |
859 | 465 | r->cur_len = 0; |
860 | 466 | } |
861 | 467 | |
862 | -/* Append a string to a dynamically-allocated buffer. */ | |
468 | +/** | |
469 | + * @brief Append a string to a dynamically-allocated buffer. | |
470 | + */ | |
863 | 471 | void |
864 | 472 | rpf(rpf_t *r, char *fmt, ...) |
865 | 473 | { |
... | ... | @@ -889,7 +497,9 @@ rpf(rpf_t *r, char *fmt, ...) |
889 | 497 | r->cur_len += ns; |
890 | 498 | } |
891 | 499 | |
892 | -/* Free resources associated with an RPF. */ | |
500 | +/** | |
501 | + * @brief Free resources associated with an RPF. | |
502 | + */ | |
893 | 503 | void |
894 | 504 | rpf_free(rpf_t *r) |
895 | 505 | { |
... | ... | @@ -931,7 +541,6 @@ LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr) |
931 | 541 | return ptr; |
932 | 542 | } |
933 | 543 | |
934 | - | |
935 | 544 | LIB3270_EXPORT void * lib3270_malloc(int len) |
936 | 545 | { |
937 | 546 | char *r; |
... | ... | @@ -988,37 +597,16 @@ void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...) |
988 | 597 | |
989 | 598 | } |
990 | 599 | |
991 | -#if defined(_WIN32) | |
992 | - | |
993 | -#define SECS_BETWEEN_EPOCHS 11644473600ULL | |
994 | -#define SECS_TO_100NS 10000000ULL /* 10^7 */ | |
995 | - | |
996 | -int gettimeofday(struct timeval *tv, void *ignored) | |
600 | +LIB3270_EXPORT int lib3270_print(H3270 *h) | |
997 | 601 | { |
998 | - FILETIME t; | |
999 | - ULARGE_INTEGER u; | |
1000 | - | |
1001 | - GetSystemTimeAsFileTime(&t); | |
1002 | - memcpy(&u, &t, sizeof(ULARGE_INTEGER)); | |
1003 | - | |
1004 | - /* Isolate seconds and move epochs. */ | |
1005 | - tv->tv_sec = (DWORD)((u.QuadPart / SECS_TO_100NS) - SECS_BETWEEN_EPOCHS); | |
1006 | - tv->tv_usec = (u.QuadPart % SECS_TO_100NS) / 10ULL; | |
1007 | - return 0; | |
1008 | -} | |
1009 | - | |
1010 | -#endif | |
1011 | - | |
1012 | - LIB3270_EXPORT int lib3270_print(H3270 *h) | |
1013 | - { | |
1014 | 602 | CHECK_SESSION_HANDLE(h); |
1015 | 603 | trace("%s(%p)",__FUNCTION__,h); |
1016 | 604 | return h->cbk.print(h); |
1017 | - } | |
605 | +} | |
1018 | 606 | |
1019 | 607 | |
1020 | - LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr) | |
1021 | - { | |
608 | +LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr) | |
609 | +{ | |
1022 | 610 | static const struct _ptr { |
1023 | 611 | unsigned short id; |
1024 | 612 | LIB3270_POINTER value; |
... | ... | @@ -1050,10 +638,10 @@ int gettimeofday(struct timeval *tv, void *ignored) |
1050 | 638 | |
1051 | 639 | return hSession->pointer; |
1052 | 640 | |
1053 | - } | |
641 | +} | |
1054 | 642 | |
1055 | - LIB3270_EXPORT int lib3270_getpeername(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) | |
1056 | - { | |
643 | +LIB3270_EXPORT int lib3270_getpeername(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) | |
644 | +{ | |
1057 | 645 | CHECK_SESSION_HANDLE(hSession); |
1058 | 646 | |
1059 | 647 | memset(addr,0,*addrlen); |
... | ... | @@ -1065,10 +653,10 @@ int gettimeofday(struct timeval *tv, void *ignored) |
1065 | 653 | |
1066 | 654 | return getpeername(hSession->sock, addr, addrlen); |
1067 | 655 | |
1068 | - } | |
656 | +} | |
1069 | 657 | |
1070 | - LIB3270_EXPORT int lib3270_getsockname(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) | |
1071 | - { | |
658 | +LIB3270_EXPORT int lib3270_getsockname(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) | |
659 | +{ | |
1072 | 660 | CHECK_SESSION_HANDLE(hSession); |
1073 | 661 | |
1074 | 662 | memset(addr,0,*addrlen); |
... | ... | @@ -1079,4 +667,4 @@ int gettimeofday(struct timeval *tv, void *ignored) |
1079 | 667 | } |
1080 | 668 | |
1081 | 669 | return getsockname(hSession->sock, addr, addrlen); |
1082 | - } | |
670 | +} | ... | ... |
src/lib3270/windows/event_dispatcher.c
... | ... | @@ -0,0 +1,210 @@ |
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 | |
5 | + * o nome G3270. | |
6 | + * | |
7 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
8 | + * | |
9 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
10 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
11 | + * Free Software Foundation. | |
12 | + * | |
13 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
14 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
15 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
16 | + * obter mais detalhes. | |
17 | + * | |
18 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
19 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
20 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | + * | |
22 | + * Este programa está nomeado como - e possui - linhas de código. | |
23 | + * | |
24 | + * Contatos: | |
25 | + * | |
26 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
27 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
28 | + * | |
29 | + */ | |
30 | + | |
31 | +/** | |
32 | + * @brief Win32 Utility functions. | |
33 | + */ | |
34 | + | |
35 | +#include <winsock2.h> | |
36 | +#include <windows.h> | |
37 | +#include "../private.h" | |
38 | + | |
39 | +#include "winversc.h" | |
40 | +#include <ws2tcpip.h> | |
41 | +#include <stdio.h> | |
42 | +#include <errno.h> | |
43 | +#include "w3miscc.h" | |
44 | +#include <malloc.h> | |
45 | + | |
46 | +#ifdef HAVE_ICONV | |
47 | + #include <iconv.h> | |
48 | +#endif // HAVE_ICONV | |
49 | + | |
50 | +//#include <stdarg.h> | |
51 | +//#include "resources.h" | |
52 | + | |
53 | +//#include "utilc.h" | |
54 | +//#include "popupsc.h" | |
55 | +//#include "api.h" | |
56 | + | |
57 | +//#include <lib3270/session.h> | |
58 | +//#include <lib3270/selection.h> | |
59 | + | |
60 | +#define my_isspace(c) isspace((unsigned char)c) | |
61 | + | |
62 | +int is_nt = 1; | |
63 | +int has_ipv6 = 1; | |
64 | + | |
65 | +int get_version_info(void) | |
66 | +{ | |
67 | + OSVERSIONINFO info; | |
68 | + | |
69 | + // Figure out what version of Windows this is. | |
70 | + memset(&info, '\0', sizeof(info)); | |
71 | + info.dwOSVersionInfoSize = sizeof(info); | |
72 | + if(GetVersionEx(&info) == 0) | |
73 | + { | |
74 | + lib3270_write_log(NULL,"lib3270","%s","Can't get Windows version"); | |
75 | + return -1; | |
76 | + } | |
77 | + | |
78 | + // Yes, people still run Win98. | |
79 | + if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) | |
80 | + is_nt = 0; | |
81 | + | |
82 | + // Win2K and earlier is IPv4-only. WinXP and later can have IPv6. | |
83 | + if (!is_nt || info.dwMajorVersion < 5 || (info.dwMajorVersion == 5 && info.dwMinorVersion < 1)) | |
84 | + { | |
85 | + has_ipv6 = 0; | |
86 | + } | |
87 | + | |
88 | + return 0; | |
89 | +} | |
90 | + | |
91 | +// Convert a network address to a string. | |
92 | +#ifndef HAVE_INET_NTOP | |
93 | +const char * inet_ntop(int af, const void *src, char *dst, socklen_t cnt) | |
94 | +{ | |
95 | + union { | |
96 | + struct sockaddr sa; | |
97 | + struct sockaddr_in sin; | |
98 | + struct sockaddr_in6 sin6; | |
99 | + } sa; | |
100 | + DWORD ssz; | |
101 | + DWORD sz = cnt; | |
102 | + | |
103 | + memset(&sa, '\0', sizeof(sa)); | |
104 | + | |
105 | + switch (af) { | |
106 | + case AF_INET: | |
107 | + sa.sin = *(struct sockaddr_in *)src; // struct copy | |
108 | + ssz = sizeof(struct sockaddr_in); | |
109 | + break; | |
110 | + case AF_INET6: | |
111 | + sa.sin6 = *(struct sockaddr_in6 *)src; // struct copy | |
112 | + ssz = sizeof(struct sockaddr_in6); | |
113 | + break; | |
114 | + default: | |
115 | + if (cnt > 0) | |
116 | + dst[0] = '\0'; | |
117 | + return NULL; | |
118 | + } | |
119 | + | |
120 | + sa.sa.sa_family = af; | |
121 | + | |
122 | + if (WSAAddressToString(&sa.sa, ssz, NULL, dst, &sz) != 0) { | |
123 | + if (cnt > 0) | |
124 | + dst[0] = '\0'; | |
125 | + return NULL; | |
126 | + } | |
127 | + | |
128 | + return dst; | |
129 | +} | |
130 | +#endif // HAVE_INET_NTOP | |
131 | + | |
132 | +// Decode a Win32 error number. | |
133 | +LIB3270_EXPORT const char * lib3270_win32_strerror(int e) | |
134 | +{ | |
135 | + static char buffer[4096]; | |
136 | + | |
137 | + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,e,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,sizeof(buffer),NULL) == 0) | |
138 | + { | |
139 | + snprintf(buffer, 4095, _( "Windows error %d" ), e); | |
140 | + return buffer; | |
141 | + } | |
142 | + | |
143 | +#ifdef HAVE_ICONV | |
144 | + { | |
145 | + // Convert from windows codepage to UTF-8 pw3270´s default charset | |
146 | + iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); | |
147 | + | |
148 | + trace("[%s]",buffer); | |
149 | + | |
150 | + if(hConv == (iconv_t) -1) | |
151 | + { | |
152 | + lib3270_write_log(NULL,"iconv","%s: Error creating charset conversion",__FUNCTION__); | |
153 | + } | |
154 | + else | |
155 | + { | |
156 | + size_t in = strlen(buffer); | |
157 | + size_t out = (in << 1); | |
158 | + char * ptr; | |
159 | + char * outBuffer = (char *) malloc(out); | |
160 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) buffer; | |
161 | + | |
162 | + memset(ptr=outBuffer,0,out); | |
163 | + | |
164 | + iconv(hConv,NULL,NULL,NULL,NULL); // Reset state | |
165 | + | |
166 | + if(iconv(hConv,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
167 | + { | |
168 | + strncpy(buffer,outBuffer,4095); | |
169 | + } | |
170 | + | |
171 | + free(outBuffer); | |
172 | + | |
173 | + iconv_close(hConv); | |
174 | + } | |
175 | + | |
176 | + } | |
177 | +#endif // HAVE_ICONV | |
178 | + | |
179 | + return buffer; | |
180 | +} | |
181 | + | |
182 | +LIB3270_EXPORT const char * lib3270_win32_local_charset(void) | |
183 | +{ | |
184 | + // Reference: | |
185 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/dd318070(v=vs.85).aspx | |
186 | + | |
187 | + /// TODO: Use GetACP() to identify the correct code page | |
188 | + | |
189 | + trace("Windows CHARSET is %u",GetACP()); | |
190 | + | |
191 | + return "CP1252"; | |
192 | +} | |
193 | + | |
194 | +#define SECS_BETWEEN_EPOCHS 11644473600ULL | |
195 | +#define SECS_TO_100NS 10000000ULL /* 10^7 */ | |
196 | + | |
197 | +int gettimeofday(struct timeval *tv, void *ignored) | |
198 | +{ | |
199 | + FILETIME t; | |
200 | + ULARGE_INTEGER u; | |
201 | + | |
202 | + GetSystemTimeAsFileTime(&t); | |
203 | + memcpy(&u, &t, sizeof(ULARGE_INTEGER)); | |
204 | + | |
205 | + /* Isolate seconds and move epochs. */ | |
206 | + tv->tv_sec = (DWORD)((u.QuadPart / SECS_TO_100NS) - SECS_BETWEEN_EPOCHS); | |
207 | + tv->tv_usec = (u.QuadPart % SECS_TO_100NS) / 10ULL; | |
208 | + return 0; | |
209 | +} | |
210 | + | ... | ... |