From 6f550f75d8dd782e1787b65bee8aa0fc3d1817ba Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 17 Aug 2021 19:21:25 -0300 Subject: [PATCH] Adding 'tracefile' property (still incomplete). --- src/core/log.c | 21 +++++++++++---------- src/core/properties/string.c | 8 ++++++++ src/core/properties/unsigned.c | 1 + src/core/session.c | 3 ++- src/core/trace_ds.c | 21 +++++++++++++++++++++ src/include/internals.h | 6 ++++-- src/include/lib3270/log.h | 5 ++++- 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 7272f88..064d84c 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -53,7 +53,7 @@ static void (*loghandler)(H3270 *session, const char *module, int rc, const char static void logfile(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr) { - FILE *f = fopen(session->logfile, "a"); + FILE *f = fopen(session->file.log, "a"); if(f) { @@ -81,20 +81,21 @@ static void logfile(H3270 *session, const char *module, int rc, const char *fmt, } -LIB3270_EXPORT const char * lib3270_get_log_filename(H3270 * hSession) { - return hSession->logfile; +LIB3270_EXPORT const char * lib3270_get_log_filename(const H3270 * hSession) { + return hSession->file.log; } LIB3270_EXPORT int lib3270_set_log_filename(H3270 * hSession, const char *filename) { - if(hSession->logfile) { - lib3270_free(hSession->logfile); + if(hSession->file.log) { + lib3270_free(hSession->file.log); + hSession->file.log = NULL; } if(filename && *filename) { - hSession->logfile = lib3270_strdup(filename); + hSession->file.log = lib3270_strdup(filename); } else { - hSession->logfile = NULL; + hSession->file.log = NULL; } return 0; @@ -109,7 +110,7 @@ LIB3270_EXPORT int lib3270_write_log(H3270 *session, const char *module, const c va_list arg_ptr; va_start(arg_ptr, fmt); - if(session && session->logfile) { + if(session && session->file.log) { logfile(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),0,fmt,arg_ptr); } else { loghandler(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),0,fmt,arg_ptr); @@ -123,7 +124,7 @@ LIB3270_EXPORT int lib3270_write_rc(H3270 *session, const char *module, int rc, va_list arg_ptr; va_start(arg_ptr, fmt); - if(session && session->logfile) { + if(session && session->file.log) { logfile(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),rc,fmt,arg_ptr); } else { loghandler(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),rc,fmt,arg_ptr); @@ -134,7 +135,7 @@ LIB3270_EXPORT int lib3270_write_rc(H3270 *session, const char *module, int rc, } LIB3270_EXPORT void lib3270_write_va_log(H3270 *session, const char *module, const char *fmt, va_list arg) { - if(session && session->logfile) { + if(session && session->file.log) { logfile(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),0,fmt,arg); } else { loghandler(session,module ? module : LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),0,fmt,arg); diff --git a/src/core/properties/string.c b/src/core/properties/string.c index 8bf171b..2462364 100644 --- a/src/core/properties/string.c +++ b/src/core/properties/string.c @@ -191,6 +191,14 @@ LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_lis }, { + .name = "tracefile", // Property name. + .group = LIB3270_ACTION_GROUP_NONE, // Property group. + .description = N_( "The trace file name"), // Property description. + .get = lib3270_get_trace_filename, // Get value. + .set = lib3270_set_trace_filename // Set value. + }, + + { .name = NULL, .description = NULL, .get = NULL, diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index bad8d94..00f87f1 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -67,6 +67,7 @@ LIB3270_EXPORT unsigned int lib3270_get_auto_reconnect(const H3270 *hSession) { LIB3270_EXPORT int lib3270_set_auto_reconnect(H3270 *hSession, unsigned int timer) { hSession->connection.retry = timer; + return 0; } const LIB3270_UINT_PROPERTY * lib3270_get_unsigned_properties_list(void) { diff --git a/src/core/session.c b/src/core/session.c index 82741f7..09f75de 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -148,7 +148,8 @@ void lib3270_session_free(H3270 *h) { lib3270_linked_list_free(&h->input.list); // Release logfile - release_pointer(h->logfile); + release_pointer(h->file.log); + release_pointer(h->file.trace); lib3270_free(h); } diff --git a/src/core/trace_ds.c b/src/core/trace_ds.c index cbff9d2..5eee2be 100644 --- a/src/core/trace_ds.c +++ b/src/core/trace_ds.c @@ -348,4 +348,25 @@ void lib3270_trace_data(H3270 *hSession, const char *msg, const unsigned char *d } +LIB3270_EXPORT const char * lib3270_get_trace_filename(H3270 * hSession) { + return hSession->file.trace; +} + +LIB3270_EXPORT int lib3270_set_trace_filename(H3270 * hSession, const char *filename) { + + if(hSession->file.trace) { + lib3270_free(hSession->file.trace); + hSession->file.trace = NULL; + } + + if(filename && *filename) { + hSession->file.trace = lib3270_strdup(filename); + } else { + hSession->file.trace = NULL; + } + + return 0; + +} + #endif diff --git a/src/include/internals.h b/src/include/internals.h index 4c9ed5b..4b77129 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -653,8 +653,10 @@ struct _h3270 { unsigned int tasks; - /// @brief Log file name (if set) - char *logfile; + struct { + char *log; ///< @brief Log file name (if set). + char *trace; ///< @brief Trace file name (if set). + } file; }; diff --git a/src/include/lib3270/log.h b/src/include/lib3270/log.h index 5a86aeb..baeccdc 100644 --- a/src/include/lib3270/log.h +++ b/src/include/lib3270/log.h @@ -58,7 +58,10 @@ LIB3270_EXPORT int lib3270_write_rc(H3270 *session, const char *module, int rc LIB3270_EXPORT void lib3270_write_va_log(H3270 *session, const char *module, const char *fmt, va_list arg); LIB3270_EXPORT int lib3270_set_log_filename(H3270 * hSession, const char *name); -LIB3270_EXPORT const char * lib3270_get_log_filename(H3270 * hSession); +LIB3270_EXPORT const char * lib3270_get_log_filename(const H3270 * hSession); + +LIB3270_EXPORT int lib3270_set_trace_filename(H3270 * hSession, const char *name); +LIB3270_EXPORT const char * lib3270_get_trace_filename(const H3270 * hSession); /** * @brief Send logs to system log (if available) -- libgit2 0.21.2