From 95c3d684c4e46a57c50dcf4c3ec363cf5c76d0b3 Mon Sep 17 00:00:00 2001 From: "pavel.uhanov" <pavel.uhanov@demlabs.net> Date: Tue, 11 Feb 2025 11:01:56 +0000 Subject: [PATCH 1/4] [*] port --- core/include/dap_common.h | 4 ++++ net/server/cli_server/dap_cli_server.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/include/dap_common.h b/core/include/dap_common.h index 3f631be7c..ba771572d 100755 --- a/core/include/dap_common.h +++ b/core/include/dap_common.h @@ -859,6 +859,10 @@ static const uint16_t s_ascii_table_data[256] = { #define dap_ascii_isprint(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_PRINT) #define dap_ascii_isxdigit(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_XDIGIT) +#define DAP_FLAG_ADD(a, flag) ((a) | (flag)) +#define DAP_FLAG_REMOVE(a, flag) ((a) & ~(flag)) +#define DAP_FLAG_CHECK(a, flag) ((a) & (flag)) + static void * ( *const volatile memset_safe ) (void*, int, size_t) = memset; DAP_STATIC_INLINE void DAP_AtomicLock( dap_spinlock_t *lock ) diff --git a/net/server/cli_server/dap_cli_server.c b/net/server/cli_server/dap_cli_server.c index 7a42efeab..1d2e9d691 100644 --- a/net/server/cli_server/dap_cli_server.c +++ b/net/server/cli_server/dap_cli_server.c @@ -262,7 +262,8 @@ int json_commands(const char * a_name) { "stats", "print_log", "stake_lock", - "exec_cmd" + "exec_cmd", + "policy" }; for (size_t i = 0; i < sizeof(long_cmd)/sizeof(long_cmd[0]); i++) { if (!strcmp(a_name, long_cmd[i])) { -- GitLab From 59c43e0be868aa09b9d04271899ffee3f1a0182e Mon Sep 17 00:00:00 2001 From: "pavel.uhanov" <pavel.uhanov@demlabs.net> Date: Tue, 25 Feb 2025 07:35:04 +0300 Subject: [PATCH 2/4] [+] add dap_time_from_str_custom func --- core/include/dap_common.h | 2 +- core/include/dap_time.h | 2 +- core/src/dap_time.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/include/dap_common.h b/core/include/dap_common.h index ba771572d..32f0e7a3c 100755 --- a/core/include/dap_common.h +++ b/core/include/dap_common.h @@ -229,7 +229,7 @@ static inline void *s_vm_extend(const char *a_rtn_name, int a_rtn_line, void *a_ #define DAP_DELETE(p) free((void*)(p)) #define DAP_DEL_Z(p) do { DAP_FREE(p); (p) = NULL; } while (0); #define DAP_DEL_ARRAY(p, c) for ( intmax_t _c = p ? (intmax_t)(c) : 0; _c > 0; DAP_DELETE(p[--_c]) ); -#define DAP_DUP_SIZE(p, s) ({ intmax_t _s = (intmax_t)(s); __typeof__(p) _p = ( (uintptr_t)(p) && _s >= DAP_TYPE_SIZE(p) ) ? DAP_CAST(__typeof__(p), calloc(1, _s)) : NULL; _p ? DAP_CAST(__typeof__(p), memcpy(_p, (p), _s)) : NULL; }) +#define DAP_DUP_SIZE(p, s) ({ intmax_t _s = (intmax_t)(s); void *_p = ( (uintptr_t)(p) && _s >= DAP_TYPE_SIZE(p) ) ? calloc(1, _s) : NULL; _p ? DAP_CAST(__typeof__(p), memcpy(_p, (p), _s)) : NULL; }) #define DAP_DUP(p) ({ __typeof__(p) _p = p; _p = (uintptr_t)_p ? calloc(1, sizeof(*(p))) : NULL; if (_p) *_p = *(p); _p; }) #endif diff --git a/core/include/dap_time.h b/core/include/dap_time.h index 26a2878aa..a2ec6cdb0 100644 --- a/core/include/dap_time.h +++ b/core/include/dap_time.h @@ -57,4 +57,4 @@ int dap_nanotime_to_str_rfc822(char *a_out, size_t a_out_size_max, dap_nanotime_ int timespec_diff(struct timespec *a_start, struct timespec *a_stop, struct timespec *a_result); dap_time_t dap_time_from_str_simplified(const char *a_time_str); - +dap_time_t dap_time_from_str_custom(const char *a_time_str, const char *a_format_str); diff --git a/core/src/dap_time.c b/core/src/dap_time.c index fc1108c38..39141655e 100644 --- a/core/src/dap_time.c +++ b/core/src/dap_time.c @@ -207,3 +207,20 @@ int dap_nanotime_to_str_rfc822(char *a_out, size_t a_out_size_max, dap_nanotime_ time_t l_time = dap_nanotime_to_sec(a_chain_time); return dap_time_to_str_rfc822(a_out, a_out_size_max, l_time); } + +/** + * @brief Convert time str to dap_time_t by custom format + * @param a_time_str + * @param a_format_str + * @return time from string or 0 if bad time format + */ +dap_time_t dap_time_from_str_custom(const char *a_time_str, const char *a_format_str) +{ + dap_return_val_if_pass(!a_time_str || !a_format_str, 0); + struct tm l_tm = {}; + char *ret = strptime(a_time_str, a_format_str, &l_tm); + if ( !ret || *ret ) + return log_it(L_ERROR, "Invalid timestamp \"%s\" by format \"%s\"", a_time_str, a_format_str), 0; + time_t tmp = mktime(&l_tm); + return tmp > 0 ? (dap_time_t)tmp : 0; +} \ No newline at end of file -- GitLab From 5e6f7028754b4788078b528abdfb204b2ca2a7f8 Mon Sep 17 00:00:00 2001 From: "pavel.uhanov" <pavel.uhanov@demlabs.net> Date: Tue, 25 Feb 2025 17:01:34 +0300 Subject: [PATCH 3/4] [*] restore dap_dup_size --- core/include/dap_common.h | 2 +- global-db/dap_global_db.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/include/dap_common.h b/core/include/dap_common.h index 32f0e7a3c..ba771572d 100755 --- a/core/include/dap_common.h +++ b/core/include/dap_common.h @@ -229,7 +229,7 @@ static inline void *s_vm_extend(const char *a_rtn_name, int a_rtn_line, void *a_ #define DAP_DELETE(p) free((void*)(p)) #define DAP_DEL_Z(p) do { DAP_FREE(p); (p) = NULL; } while (0); #define DAP_DEL_ARRAY(p, c) for ( intmax_t _c = p ? (intmax_t)(c) : 0; _c > 0; DAP_DELETE(p[--_c]) ); -#define DAP_DUP_SIZE(p, s) ({ intmax_t _s = (intmax_t)(s); void *_p = ( (uintptr_t)(p) && _s >= DAP_TYPE_SIZE(p) ) ? calloc(1, _s) : NULL; _p ? DAP_CAST(__typeof__(p), memcpy(_p, (p), _s)) : NULL; }) +#define DAP_DUP_SIZE(p, s) ({ intmax_t _s = (intmax_t)(s); __typeof__(p) _p = ( (uintptr_t)(p) && _s >= DAP_TYPE_SIZE(p) ) ? DAP_CAST(__typeof__(p), calloc(1, _s)) : NULL; _p ? DAP_CAST(__typeof__(p), memcpy(_p, (p), _s)) : NULL; }) #define DAP_DUP(p) ({ __typeof__(p) _p = p; _p = (uintptr_t)_p ? calloc(1, sizeof(*(p))) : NULL; if (_p) *_p = *(p); _p; }) #endif diff --git a/global-db/dap_global_db.c b/global-db/dap_global_db.c index cb4dde542..09b0987aa 100644 --- a/global-db/dap_global_db.c +++ b/global-db/dap_global_db.c @@ -1387,7 +1387,7 @@ int dap_global_db_del_ex(const char * a_group, const char *a_key, const void * a l_msg->callback_arg = a_arg; l_msg->callback_result = a_callback; if (a_value_len) { - l_msg->value = DAP_DUP_SIZE(a_value, a_value_len); + l_msg->value = DAP_DUP_SIZE((void *)a_value, a_value_len); l_msg->value_length = a_value_len; } -- GitLab From 57e0a6afa1ef51685819580818ad4ffb211a7a07 Mon Sep 17 00:00:00 2001 From: Pavel Uhanov <pavel.uhanov@demlabs.net> Date: Wed, 26 Feb 2025 13:57:28 +0300 Subject: [PATCH 4/4] [*] adopt json_print_value to int64 --- net/server/json_rpc/rpc_core/src/dap_json_rpc_response.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server/json_rpc/rpc_core/src/dap_json_rpc_response.c b/net/server/json_rpc/rpc_core/src/dap_json_rpc_response.c index d5769c9f3..d5ea2f6b3 100644 --- a/net/server/json_rpc/rpc_core/src/dap_json_rpc_response.c +++ b/net/server/json_rpc/rpc_core/src/dap_json_rpc_response.c @@ -212,7 +212,7 @@ void json_print_value(json_object *obj, const char *key, int indent_level, bool printf(print_separator ? "%s, " : "%s", json_object_get_string(obj)); break; case json_type_int: - printf("%d", json_object_get_int(obj)); + printf("%lld", json_object_get_int64(obj)); break; case json_type_double: printf("%lf", json_object_get_double(obj)); -- GitLab