Commit f8a828b9eb8621515e180c45530af0fac9515108
1 parent
b1744c5f
Exists in
master
and in
3 other branches
Log messages are now sent to windows event log.
Showing
9 changed files
with
179 additions
and
37 deletions
Show diff stats
lib3270.cbp
@@ -174,6 +174,9 @@ | @@ -174,6 +174,9 @@ | ||
174 | <Unit filename="src/lib3270/linux/event_dispatcher.c"> | 174 | <Unit filename="src/lib3270/linux/event_dispatcher.c"> |
175 | <Option compilerVar="CC" /> | 175 | <Option compilerVar="CC" /> |
176 | </Unit> | 176 | </Unit> |
177 | + <Unit filename="src/lib3270/linux/log.c"> | ||
178 | + <Option compilerVar="CC" /> | ||
179 | + </Unit> | ||
177 | <Unit filename="src/lib3270/linux/util.c"> | 180 | <Unit filename="src/lib3270/linux/util.c"> |
178 | <Option compilerVar="CC" /> | 181 | <Option compilerVar="CC" /> |
179 | </Unit> | 182 | </Unit> |
@@ -277,6 +280,9 @@ | @@ -277,6 +280,9 @@ | ||
277 | <Unit filename="src/lib3270/windows/event_dispatcher.c"> | 280 | <Unit filename="src/lib3270/windows/event_dispatcher.c"> |
278 | <Option compilerVar="CC" /> | 281 | <Option compilerVar="CC" /> |
279 | </Unit> | 282 | </Unit> |
283 | + <Unit filename="src/lib3270/windows/log.c"> | ||
284 | + <Option compilerVar="CC" /> | ||
285 | + </Unit> | ||
280 | <Unit filename="src/lib3270/windows/resources.rc"> | 286 | <Unit filename="src/lib3270/windows/resources.rc"> |
281 | <Option compilerVar="WINDRES" /> | 287 | <Option compilerVar="WINDRES" /> |
282 | </Unit> | 288 | </Unit> |
src/include/lib3270.h
@@ -1138,9 +1138,16 @@ | @@ -1138,9 +1138,16 @@ | ||
1138 | /** | 1138 | /** |
1139 | * @brief Check if the screen position is protected. | 1139 | * @brief Check if the screen position is protected. |
1140 | * | 1140 | * |
1141 | + * @param hSession Session handle. | ||
1142 | + * @param baddr0 Search start addr (-1 to use current cursor position). | ||
1143 | + * | ||
1144 | + * @return -1 when failed 1 if the addr is protected and 0 if not. | ||
1145 | + * | ||
1141 | */ | 1146 | */ |
1142 | LIB3270_EXPORT int lib3270_get_is_protected(H3270 *hSession, int baddr0); | 1147 | LIB3270_EXPORT int lib3270_get_is_protected(H3270 *hSession, int baddr0); |
1143 | 1148 | ||
1149 | + LIB3270_EXPORT int LIB3270_DEPRECATED(lib3270_is_protected(H3270 *h, unsigned int baddr)); | ||
1150 | + | ||
1144 | /** | 1151 | /** |
1145 | * @brief Get Check if the screen position is protected. | 1152 | * @brief Get Check if the screen position is protected. |
1146 | * | 1153 | * |
@@ -1254,9 +1261,6 @@ | @@ -1254,9 +1261,6 @@ | ||
1254 | LIB3270_EXPORT const char * lib3270_get_model(H3270 *session); | 1261 | LIB3270_EXPORT const char * lib3270_get_model(H3270 *session); |
1255 | LIB3270_EXPORT int lib3270_get_model_number(H3270 *hSession); | 1262 | LIB3270_EXPORT int lib3270_get_model_number(H3270 *hSession); |
1256 | 1263 | ||
1257 | - LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr); | ||
1258 | - LIB3270_EXPORT int lib3270_is_protected_at(H3270 *h, unsigned int row, unsigned int col); | ||
1259 | - | ||
1260 | LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name); | 1264 | LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name); |
1261 | 1265 | ||
1262 | /** | 1266 | /** |
src/lib3270/ctlr.c
@@ -629,6 +629,28 @@ LIB3270_EXPORT int lib3270_get_is_protected(H3270 *hSession, int baddr) | @@ -629,6 +629,28 @@ LIB3270_EXPORT int lib3270_get_is_protected(H3270 *hSession, int baddr) | ||
629 | return FA_IS_PROTECTED(hSession->ea_buf[faddr].fa) ? 1 : 0; | 629 | return FA_IS_PROTECTED(hSession->ea_buf[faddr].fa) ? 1 : 0; |
630 | } | 630 | } |
631 | 631 | ||
632 | +LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr) | ||
633 | +{ | ||
634 | + return lib3270_get_is_protected(h, baddr); | ||
635 | + | ||
636 | + /* | ||
637 | + unsigned char fa; | ||
638 | + | ||
639 | + FAIL_IF_NOT_ONLINE(h); | ||
640 | + | ||
641 | + if(baddr > (h->rows * h->cols)) | ||
642 | + { | ||
643 | + errno = EINVAL; | ||
644 | + return -1; | ||
645 | + } | ||
646 | + | ||
647 | + fa = get_field_attribute(h,baddr); | ||
648 | + | ||
649 | + return FA_IS_PROTECTED(fa); | ||
650 | + */ | ||
651 | +} | ||
652 | + | ||
653 | + | ||
632 | 654 | ||
633 | /** | 655 | /** |
634 | * Perform an erase command, which may include changing the (virtual) screen size. | 656 | * Perform an erase command, which may include changing the (virtual) screen size. |
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
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., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - 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 "../private.h" | ||
31 | +#include <stdio.h> | ||
32 | +#include <stdarg.h> | ||
33 | +#include <config.h> | ||
34 | +#include <lib3270.h> | ||
35 | +#include <lib3270/log.h> | ||
36 | + | ||
37 | +/*---[ Implementacao ]--------------------------------------------------------------------------------------*/ | ||
38 | + | ||
39 | + void default_log_writer(H3270 GNUC_UNUSED(*session), const char *module, int GNUC_UNUSED(rc), const char *fmt, va_list arg_ptr) | ||
40 | + { | ||
41 | + printf("%s:\t",module); | ||
42 | + vprintf(fmt,arg_ptr); | ||
43 | + printf("\n"); | ||
44 | + fflush(stdout); | ||
45 | + } | ||
46 | + |
src/lib3270/log.c
@@ -41,21 +41,16 @@ | @@ -41,21 +41,16 @@ | ||
41 | #include <config.h> | 41 | #include <config.h> |
42 | #include <lib3270.h> | 42 | #include <lib3270.h> |
43 | #include <lib3270/log.h> | 43 | #include <lib3270/log.h> |
44 | -// #include "api.h" | ||
45 | - | ||
46 | -/*---[ Prototipes ]-----------------------------------------------------------------------------------------*/ | ||
47 | - | ||
48 | - static void defaultlog(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr); | ||
49 | 44 | ||
50 | /*---[ Constants ]------------------------------------------------------------------------------------------*/ | 45 | /*---[ Constants ]------------------------------------------------------------------------------------------*/ |
51 | 46 | ||
52 | - static void (*loghandler)(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr) = defaultlog; | 47 | + static void (*loghandler)(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr) = default_log_writer; |
53 | 48 | ||
54 | /*---[ Implementacao ]--------------------------------------------------------------------------------------*/ | 49 | /*---[ Implementacao ]--------------------------------------------------------------------------------------*/ |
55 | 50 | ||
56 | LIB3270_EXPORT void lib3270_set_log_handler(void (*handler)(H3270 *, const char *, int, const char *, va_list)) | 51 | LIB3270_EXPORT void lib3270_set_log_handler(void (*handler)(H3270 *, const char *, int, const char *, va_list)) |
57 | { | 52 | { |
58 | - loghandler = handler ? handler : defaultlog; | 53 | + loghandler = handler ? handler : default_log_writer; |
59 | } | 54 | } |
60 | 55 | ||
61 | LIB3270_EXPORT int lib3270_write_log(H3270 *session, const char *module, const char *fmt, ...) | 56 | LIB3270_EXPORT int lib3270_write_log(H3270 *session, const char *module, const char *fmt, ...) |
@@ -80,12 +75,3 @@ | @@ -80,12 +75,3 @@ | ||
80 | { | 75 | { |
81 | loghandler(session,module,0,fmt,arg); | 76 | loghandler(session,module,0,fmt,arg); |
82 | } | 77 | } |
83 | - | ||
84 | - static void defaultlog(H3270 GNUC_UNUSED(*session), const char *module, int GNUC_UNUSED(rc), const char *fmt, va_list arg_ptr) | ||
85 | - { | ||
86 | - fprintf(stderr,"%s:\t",module); | ||
87 | - vfprintf(stderr,fmt,arg_ptr); | ||
88 | - fprintf(stderr,"\n"); | ||
89 | - fflush(stderr); | ||
90 | - } | ||
91 | - |
src/lib3270/private.h
@@ -674,6 +674,11 @@ struct _h3270 | @@ -674,6 +674,11 @@ struct _h3270 | ||
674 | struct lib3270_state_callback * last[LIB3270_STATE_USER]; | 674 | struct lib3270_state_callback * last[LIB3270_STATE_USER]; |
675 | } st; | 675 | } st; |
676 | 676 | ||
677 | +#ifdef _WIN32 | ||
678 | + /// @brief Windows Event Log Handler. | ||
679 | + HANDLE hEventLog; | ||
680 | +#endif // _WIN32 | ||
681 | + | ||
677 | }; | 682 | }; |
678 | 683 | ||
679 | #define SELECTION_LEFT 0x01 | 684 | #define SELECTION_LEFT 0x01 |
@@ -770,5 +775,9 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); | @@ -770,5 +775,9 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); | ||
770 | 775 | ||
771 | LIB3270_INTERNAL unsigned char get_field_attribute(H3270 *session, int baddr); | 776 | LIB3270_INTERNAL unsigned char get_field_attribute(H3270 *session, int baddr); |
772 | 777 | ||
778 | + /// @brief Default log writer. | ||
779 | + LIB3270_INTERNAL void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr); | ||
780 | + | ||
781 | + | ||
773 | #endif | 782 | #endif |
774 | 783 |
src/lib3270/screen.c
@@ -997,21 +997,3 @@ LIB3270_EXPORT void lib3270_popup_va(H3270 *session, LIB3270_NOTIFY id , const c | @@ -997,21 +997,3 @@ LIB3270_EXPORT void lib3270_popup_va(H3270 *session, LIB3270_NOTIFY id , const c | ||
997 | session->popups--; | 997 | session->popups--; |
998 | 998 | ||
999 | } | 999 | } |
1000 | - | ||
1001 | -LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr) | ||
1002 | -{ | ||
1003 | - unsigned char fa; | ||
1004 | - | ||
1005 | - FAIL_IF_NOT_ONLINE(h); | ||
1006 | - | ||
1007 | - if(baddr > (h->rows * h->cols)) | ||
1008 | - { | ||
1009 | - errno = EINVAL; | ||
1010 | - return -1; | ||
1011 | - } | ||
1012 | - | ||
1013 | - fa = get_field_attribute(h,baddr); | ||
1014 | - | ||
1015 | - return FA_IS_PROTECTED(fa); | ||
1016 | -} | ||
1017 | - |
src/lib3270/session.c
@@ -151,6 +151,11 @@ void lib3270_session_free(H3270 *h) | @@ -151,6 +151,11 @@ void lib3270_session_free(H3270 *h) | ||
151 | lib3270_free(ip); | 151 | lib3270_free(ip); |
152 | } | 152 | } |
153 | 153 | ||
154 | +#ifdef _WIN32 | ||
155 | + DeregisterEventSource(h->hEventLog); | ||
156 | + h->hEventLog = 0; | ||
157 | +#endif // _WIN32 | ||
158 | + | ||
154 | trace("Releasing session %p",h); | 159 | trace("Releasing session %p",h); |
155 | lib3270_free(h); | 160 | lib3270_free(h); |
156 | 161 | ||
@@ -408,6 +413,10 @@ H3270 * lib3270_session_new(const char *model) | @@ -408,6 +413,10 @@ H3270 * lib3270_session_new(const char *model) | ||
408 | ft_init(hSession); | 413 | ft_init(hSession); |
409 | #endif | 414 | #endif |
410 | 415 | ||
416 | +#ifdef _WIN32 | ||
417 | + hSession->hEventLog = RegisterEventSource(NULL, PACKAGE_NAME); | ||
418 | +#endif // _WIN32 | ||
419 | + | ||
411 | trace("%s finished",__FUNCTION__); | 420 | trace("%s finished",__FUNCTION__); |
412 | 421 | ||
413 | errno = 0; | 422 | errno = 0; |
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
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., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - 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 <winsock2.h> | ||
31 | +#include <windows.h> | ||
32 | +#include <wtsapi32.h> | ||
33 | +#include <lmcons.h> | ||
34 | + | ||
35 | +#include "../private.h" | ||
36 | +#include <stdio.h> | ||
37 | +#include <stdarg.h> | ||
38 | +#include <config.h> | ||
39 | +#include <lib3270.h> | ||
40 | +#include <lib3270/log.h> | ||
41 | + | ||
42 | +/*---[ Implement ]------------------------------------------------------------------------------------------*/ | ||
43 | + | ||
44 | + void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr) | ||
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 | + | ||
55 | + lib3270_autoptr(char) msg = lib3270_vsprintf(fmt,arg_ptr); | ||
56 | + | ||
57 | + const char *outMsg[] = { | ||
58 | + username, | ||
59 | + module, | ||
60 | + msg | ||
61 | + }; | ||
62 | + | ||
63 | + if(session->hEventLog) { | ||
64 | + ReportEvent( | ||
65 | + session->hEventLog, | ||
66 | + (rc == 0 ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE), | ||
67 | + 1, | ||
68 | + 0, | ||
69 | + NULL, | ||
70 | + 3, | ||
71 | + 0, | ||
72 | + outMsg, | ||
73 | + NULL | ||
74 | + ); | ||
75 | + } | ||
76 | + | ||
77 | + } | ||
78 | + |