commit 15dc4e7d68afa6660c421f967fc0970d68e071bf
parent a8da222eee433452801f88fcbce43a77adc8eba8
Author: Marc Stibane <marc@taler.net>
Date: Mon, 23 Oct 2023 23:11:38 +0200
formatting, added TALER_WALLET_LOG_MESSAGE
Diffstat:
2 files changed, 83 insertions(+), 82 deletions(-)
diff --git a/taler_wallet_core_lib.c b/taler_wallet_core_lib.c
@@ -1,17 +1,17 @@
/*
- This file is part of GNU Taler
- Copyright (C) 2014-2022 Taler Systems SA
+ This file is part of GNU Taler
+ Copyright (C) 2014-2022 Taler Systems SA
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ You should have received a copy of the GNU Affero General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
#include "taler_wallet_core_lib.h"
@@ -89,8 +89,8 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
void
TALER_WALLET_set_message_handler(struct TALER_WALLET_Instance *twi,
- TALER_WALLET_MessageHandlerFn handler_f,
- void *handler_cls)
+ TALER_WALLET_MessageHandlerFn handler_f,
+ void *handler_cls)
{
twi->handler_cls = handler_cls;
twi->handler_f = handler_f;
@@ -122,11 +122,11 @@ TALER_WALLET_send_request (struct TALER_WALLET_Instance *twi,
static void
wallet_host_message_handler(void *cls, const char *msg)
{
- struct TALER_WALLET_Instance *wh = cls;
+ struct TALER_WALLET_Instance *wh = cls;
- if (wh->handler_f) {
- wh->handler_f(wh->handler_cls, msg);
- }
+ if (wh->handler_f) {
+ wh->handler_f(wh->handler_cls, msg);
+ }
}
@@ -148,23 +148,23 @@ static JSValue js_native_log(JSContext *ctx,
int argc, JSValueConst *argv,
int magic, JSValue *func_data)
{
- struct TALER_WALLET_Instance *wh;
- const char *tag = NULL;
- const char *msg = NULL;
- uint32_t level = 0;
- wh = JS_GetOpaque(func_data[0], js_wallet_instance_handle_id);
- if (NULL != wh->log_handler_f) {
- JS_ToUint32(ctx, &level, argv[0]);
- tag = JS_ToCString(ctx, argv[1]);
- msg = JS_ToCString(ctx, argv[2]);
- wh->log_handler_f(wh->log_handler_cls,
- level,
- tag,
- msg);
- }
- JS_FreeCString(ctx, tag);
- JS_FreeCString(ctx, msg);
- return JS_UNDEFINED;
+ struct TALER_WALLET_Instance *wh;
+ const char *tag = NULL;
+ const char *msg = NULL;
+ uint32_t level = 0;
+ wh = JS_GetOpaque(func_data[0], js_wallet_instance_handle_id);
+ if (NULL != wh->log_handler_f) {
+ JS_ToUint32(ctx, &level, argv[0]);
+ tag = JS_ToCString(ctx, argv[1]);
+ msg = JS_ToCString(ctx, argv[2]);
+ wh->log_handler_f(wh->log_handler_cls,
+ level,
+ tag,
+ msg);
+ }
+ JS_FreeCString(ctx, tag);
+ JS_FreeCString(ctx, msg);
+ return JS_UNDEFINED;
}
@@ -189,21 +189,21 @@ run(void *cls)
JS_SetHostPromiseRejectionTracker(wh->rt, js_std_promise_rejection_tracker,
- NULL);
+ NULL);
js_std_add_helpers(wh->ctx, 0, NULL);
// install native log handler
if (NULL != wh->log_handler_f) {
- JSValue global_obj;
- JSValue data;
-
- data = JS_NewObjectClass(wh->ctx, js_wallet_instance_handle_id);
- JS_SetOpaque(data, wh);
- global_obj = JS_GetGlobalObject(wh->ctx);
- // We could also try to add this to "os" or "tart", but we are lazy.
- JS_SetPropertyStr(wh->ctx, global_obj, "__nativeLog",
- JS_NewCFunctionData(wh->ctx, js_native_log, 3, 0, 1, &data));
+ JSValue global_obj;
+ JSValue data;
+
+ data = JS_NewObjectClass(wh->ctx, js_wallet_instance_handle_id);
+ JS_SetOpaque(data, wh);
+ global_obj = JS_GetGlobalObject(wh->ctx);
+ // We could also try to add this to "os" or "tart", but we are lazy.
+ JS_SetPropertyStr(wh->ctx, global_obj, "__nativeLog",
+ JS_NewCFunctionData(wh->ctx, js_native_log, 3, 0, 1, &data));
}
fprintf(stderr, "qtart: loading JS code\n");
@@ -237,21 +237,21 @@ TALER_WALLET_run (struct TALER_WALLET_Instance *wh)
pthread_mutex_lock(&wh->handle_mutex);
if (0 != pthread_attr_init(&tattr)) {
- pthread_mutex_unlock(&wh->handle_mutex);
- fprintf(stderr, "could not initialize pthread attr\n");
- return -1;
+ pthread_mutex_unlock(&wh->handle_mutex);
+ fprintf(stderr, "could not initialize pthread attr\n");
+ return -1;
}
if (0 != pthread_attr_setstacksize(&tattr, WALLET_THREAD_STACK_SIZE)) {
- pthread_mutex_unlock(&wh->handle_mutex);
- fprintf(stderr, "could not set stack size\n");
- return -1;
+ pthread_mutex_unlock(&wh->handle_mutex);
+ fprintf(stderr, "could not set stack size\n");
+ return -1;
}
if (0 != pthread_create(&wallet_thread, &tattr, run, wh)) {
- pthread_mutex_unlock(&wh->handle_mutex);
- fprintf(stderr, "could not create wallet thread\n");
- return -1;
+ pthread_mutex_unlock(&wh->handle_mutex);
+ fprintf(stderr, "could not create wallet thread\n");
+ return -1;
}
wh->wallet_thread = wallet_thread;
diff --git a/taler_wallet_core_lib.h b/taler_wallet_core_lib.h
@@ -1,17 +1,17 @@
/*
- This file is part of GNU Taler
- Copyright (C) 2014-2022 Taler Systems SA
+ This file is part of GNU Taler
+ Copyright (C) 2014-2022 Taler Systems SA
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ You should have received a copy of the GNU Affero General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
@@ -39,13 +39,27 @@ struct TALER_WALLET_Instance;
typedef void (*TALER_WALLET_MessageHandlerFn)(void *handler_p, const char *message);
enum TALER_WALLET_LogLevel {
- TALER_WALLET_LOG_TRACE = 1,
- TALER_WALLET_LOG_INFO = 2,
- TALER_WALLET_LOG_WARN = 3,
- TALER_WALLET_LOG_ERROR = 4
+ TALER_WALLET_LOG_TRACE = 1,
+ TALER_WALLET_LOG_INFO = 2,
+ TALER_WALLET_LOG_MESSAGE = 3,
+ TALER_WALLET_LOG_WARN = 4,
+ TALER_WALLET_LOG_ERROR = 5
};
/**
+ * Handler for log message from wallet-core.
+ *
+ * @param log_p opaque closure for the log handler
+ * @param level log level of the log message
+ * @param tag log tag (usually the file from which the message gets logged)
+ * @param msg the log message
+ */
+typedef void (*TALER_WALLET_LogHandlerFn)(void *log_p,
+ enum TALER_WALLET_LogLevel level,
+ const char *tag,
+ const char *msg);
+
+/**
* Create a new wallet-core instance..
*/
struct TALER_WALLET_Instance *
@@ -62,19 +76,6 @@ TALER_WALLET_set_message_handler(struct TALER_WALLET_Instance *twi,
TALER_WALLET_MessageHandlerFn handler_f,
void *handler_p);
-/**
- * Handler for log message from wallet-core.
- *
- * @param log_p opaque closure for the log handler
- * @param level log level of the log message
- * @param tag log tag (usually the file from which the message gets logged)
- * @param msg the log message
- */
-typedef void (*TALER_WALLET_LogHandlerFn)(void *log_p,
- enum TALER_WALLET_LogLevel level,
- const char *tag,
- const char *msg);
-
/**
* Set a handler for log messages from wallet-core.
@@ -136,7 +137,7 @@ TALER_WALLET_join(struct TALER_WALLET_Instance *twi);
/**
* Handler for messages that should be logged.
- *
+ *
* @param stream NOT YET IMPLEMENTED: indicator for the stream that
* the message is coming from,
*/
@@ -144,9 +145,9 @@ typedef void (*TALER_LogFn)(void *cls, int stream, const char *msg);
/**
* Redirect stderr and stdout to a function.
- *
+ *
* Workaround for platforms where stderr is not visible in logs.
- *
+ *
* @return 0 on success, error code otherwise
*/
int