Commit 48efc5cc3de315556266cd12925a508ce65083f2

Authored by Perry Werneck
1 parent 0461fddb

Debugging windows code.

sdk/lib3270-delayed.pc.in
... ... @@ -13,5 +13,5 @@ Description: @PACKAGE_DESCRIPTION@
13 13 Version: @PACKAGE_VERSION@
14 14 Libs: -L\@libdir@ -l@LIB3270_NAME@.delayed
15 15 Libs.private: @LIBS@ @LIBSSL_LIBS@ @LIBICONV@ @INTL_LIBS@ @LDAP_LIBS@ @LIBCURL_LIBS@
16   -Cflags: -I@includedir@
  16 +Cflags: -I@includedir@ -DLIB3270_NAME=@LIB3270_NAME@
17 17  
... ...
src/core/init.c
... ... @@ -70,6 +70,7 @@
70 70 #ifdef _WIN32
71 71 /// @brief Windows Event Log Handler.
72 72 HANDLE hEventLog = 0;
  73 +HANDLE hModule = 0;
73 74 #endif // _WIN32
74 75  
75 76 /**
... ... @@ -135,11 +136,12 @@ int lib3270_unloaded(void)
135 136  
136 137 #if defined WIN32
137 138  
138   -BOOL WINAPI DllMain(HANDLE GNUC_UNUSED(hinst), DWORD dwcallpurpose, LPVOID GNUC_UNUSED(lpvResvd))
  139 +BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwcallpurpose, LPVOID GNUC_UNUSED(lpvResvd))
139 140 {
140 141 switch(dwcallpurpose)
141 142 {
142 143 case DLL_PROCESS_ATTACH:
  144 + hModule = hInstance;
143 145 hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME));
144 146 get_version_info();
145 147 lib3270_loaded();
... ...
src/core/windows/connect.c
... ... @@ -91,7 +91,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG
91 91 LIB3270_NOTIFY_ERROR,
92 92 _( "Connection failed" ),
93 93 buffer,
94   - _( "%s"), lib3270_win32_strerror(err)
  94 + _( "%s (rc=%d)"), strerror(err), err
95 95 );
96 96 trace("%s",__FUNCTION__);
97 97 return;
... ... @@ -150,6 +150,7 @@ static void sockstart(H3270 *session)
150 150  
151 151 struct resolver
152 152 {
  153 + int rc;
153 154 int convert;
154 155 const char * message;
155 156 };
... ... @@ -174,8 +175,11 @@ static void sockstart(H3270 *session)
174 175 status_resolving(hSession);
175 176  
176 177 int rc = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
  178 + debug("getaddrinfo(%s,%s) returns %d",hSession->host.current,hSession->host.srvc,rc);
  179 +
177 180 if(rc != 0)
178 181 {
  182 + ((struct resolver *) host)->rc = rc;
179 183 ((struct resolver *) host)->message = gai_strerror(rc);
180 184 ((struct resolver *) host)->convert = 1;
181 185 return -1;
... ... @@ -188,6 +192,7 @@ static void sockstart(H3270 *session)
188 192 hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
189 193 if(hSession->sock < 0)
190 194 {
  195 + ((struct resolver *) host)->rc = errno;
191 196 ((struct resolver *) host)->message = strerror(errno);
192 197 continue;
193 198 }
... ... @@ -196,6 +201,7 @@ static void sockstart(H3270 *session)
196 201 if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen))
197 202 {
198 203 SOCK_CLOSE(hSession);
  204 + ((struct resolver *) host)->rc = errno;
199 205 ((struct resolver *) host)->message = strerror(errno);
200 206 continue;
201 207 }
... ... @@ -225,6 +231,37 @@ int net_reconnect(H3270 *hSession, int seconds)
225 231 char msg[4096];
226 232 strncpy(msg,host.message,4095);
227 233  
  234 + debug("host.message=\"%s\"",host.message);
  235 +
  236 + {
  237 + // Register on event log
  238 + lib3270_autoptr(char) username = lib3270_get_user_name();
  239 +
  240 + snprintf(msg,sizeof(msg),"rc=%d",host.rc);
  241 +
  242 + const char *outMsg[] = {
  243 + username,
  244 + "networking",
  245 + message,
  246 + host.message,
  247 + msg
  248 + };
  249 +
  250 + ReportEvent(
  251 + hEventLog,
  252 + EVENTLOG_ERROR_TYPE,
  253 + 1,
  254 + 0,
  255 + NULL,
  256 + (sizeof(outMsg)/sizeof(outMsg[0])),
  257 + 0,
  258 + outMsg,
  259 + NULL
  260 + );
  261 +
  262 + }
  263 +
  264 +
228 265 #ifdef HAVE_ICONV
229 266 if(host.convert)
230 267 {
... ... @@ -232,7 +269,7 @@ int net_reconnect(H3270 *hSession, int seconds)
232 269 size_t out = 4096;
233 270 size_t in = strlen(host.message);
234 271  
235   - iconv_t hConv = iconv_open(lib3270_win32_local_charset(),"UTF-8");
  272 + iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset());
236 273 if(iconv(
237 274 hConv,
238 275 &host.message,&in,
... ... @@ -250,8 +287,10 @@ int net_reconnect(H3270 *hSession, int seconds)
250 287 LIB3270_NOTIFY_ERROR,
251 288 _( "Connection error" ),
252 289 message,
253   - "%s",
254   - NULL);
  290 + "%s (rc=%d)",
  291 + msg,
  292 + host.rc
  293 + );
255 294  
256 295 }
257 296 else
... ...
src/core/windows/log.c
... ... @@ -43,15 +43,7 @@
43 43  
44 44 void default_log_writer(H3270 GNUC_UNUSED(*session), const char *module, int rc, const char *fmt, va_list arg_ptr)
45 45 {
46   - char username[UNLEN + 1];
47   - DWORD szName = sizeof(username);
48   -
49   - memset(username,0,szName);
50   -
51   - if(!GetUserName(username, &szName)) {
52   - strncpy(username,"?",UNLEN);
53   - }
54   -
  46 + lib3270_autoptr(char) username = lib3270_get_user_name();
55 47 lib3270_autoptr(char) msg = lib3270_vsprintf(fmt,arg_ptr);
56 48  
57 49 const char *outMsg[] = {
... ...
src/core/windows/util.c
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include <winsock2.h>
36 36 #include <windows.h>
  37 +#include <lmcons.h>
37 38 #include <lib3270-internals.h>
38 39  
39 40 #include "winversc.h"
... ... @@ -267,3 +268,31 @@ LIB3270_EXPORT char * lib3270_build_data_filename(const char *name)
267 268 return lib3270_strdup_printf("%s\\%s",wc_fn,name);
268 269  
269 270 }
  271 +
  272 +LIB3270_EXPORT char * lib3270_get_installation_path()
  273 +{
  274 + char lpFilename[4096];
  275 +
  276 + memset(lpFilename,0,sizeof(lpFilename));
  277 + DWORD szPath = GetModuleFileName(hModule,lpFilename,sizeof(lpFilename));
  278 + lpFilename[szPath] = 0;
  279 +
  280 + char * ptr = strrchr(lpFilename,'\\');
  281 + if(ptr)
  282 + ptr[1] = 0;
  283 +
  284 + return strdup(lpFilename);
  285 +}
  286 +
  287 +char * lib3270_get_user_name()
  288 +{
  289 + char username[UNLEN + 1];
  290 + DWORD szName = UNLEN;
  291 +
  292 + memset(username,0,UNLEN + 1);
  293 + GetUserName(username, &szName);
  294 +
  295 + return strdup(username);
  296 +
  297 +}
  298 +
... ...
src/include/lib3270-internals.h
... ... @@ -713,6 +713,7 @@ struct _h3270
713 713 #ifdef _WIN32
714 714 /// @brief Windows Event Log Handler.
715 715 LIB3270_INTERNAL HANDLE hEventLog;
  716 +LIB3270_INTERNAL HANDLE hModule;
716 717 #endif // _WIN32
717 718  
718 719 #ifdef HAVE_SYSLOG
... ... @@ -827,5 +828,7 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
827 828 /// @brief Default log writer.
828 829 LIB3270_INTERNAL void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr);
829 830  
  831 + LIB3270_INTERNAL char * lib3270_get_user_name();
  832 +
830 833 #endif
831 834  
... ...
src/include/lib3270.h
... ... @@ -1398,6 +1398,14 @@
1398 1398 */
1399 1399 LIB3270_EXPORT char * lib3270_win32_translate_error_code(int lasterror);
1400 1400  
  1401 + /**
  1402 + * @brief Get lib3270's installation path.
  1403 + *
  1404 + * @return Full path for the lib3270 installation path (release it with lib3270_free)
  1405 + *
  1406 + */
  1407 + LIB3270_EXPORT char * lib3270_get_installation_path();
  1408 +
1401 1409 #endif // WIn32
1402 1410  
1403 1411 /**
... ...
src/ssl/ctx_init.c
... ... @@ -133,7 +133,10 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
133 133  
134 134 #ifdef _WIN32
135 135 {
136   - lib3270_autoptr(char) certpath = lib3270_build_data_filename("certs");
  136 + lib3270_autoptr(char) appdir = lib3270_get_installation_path();
  137 + lib3270_autoptr(char) certpath = lib3270_strdup_printf("%s\\certs",appdir);
  138 +
  139 + debug("Searching certs from \"%s\".", certpath);
137 140  
138 141 if(SSL_CTX_load_verify_locations(ssl_ctx,NULL,certpath))
139 142 {
... ...
src/ssl/windows/ldap.c
... ... @@ -90,8 +90,6 @@ static inline void lib3270_autoptr_cleanup_BerElement(BerElement **ber)
90 90  
91 91 X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl)
92 92 {
93   - debug("********************************************************* %s",__FUNCTION__);
94   -
95 93 X509_CRL * x509_crl = NULL;
96 94 int rc = 0;
97 95  
... ... @@ -266,8 +264,6 @@ X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons
266 264  
267 265 ldap_value_free_len(value);
268 266  
269   - debug("********************************************************* %s",__FUNCTION__);
270   -
271 267 return x509_crl;
272 268  
273 269 }
... ...
src/testprogram/testprogram.c
... ... @@ -68,6 +68,13 @@ int main(int argc, char *argv[])
68 68  
69 69 printf("HOST URL: %s\tHOST CRL: %s\n",lib3270_get_url(h),lib3270_get_crl_url(h));
70 70  
  71 +#ifdef _WIN32
  72 + {
  73 + lib3270_autoptr(char) apppath = lib3270_get_installation_path();
  74 + printf("Application path: \"%s\"\n",apppath);
  75 + }
  76 +#endif // _WIN32
  77 +
71 78 if(lib3270_set_url(h,NULL))
72 79 lib3270_set_url(h,"tn3270://fandezhi.efglobe.com");
73 80  
... ...