From 90029c7c5ceb90a03306947e21b691c5a0c33b5f Mon Sep 17 00:00:00 2001 From: XavierChanth Date: Wed, 4 Dec 2024 13:54:17 -0500 Subject: [PATCH] chore: cleanup platform management --- cmake/find_mbedtls.cmake | 1 - packages/atchops/include/atchops/aes.h | 2 + packages/atchops/include/atchops/aes_ctr.h | 1 + packages/atchops/include/atchops/base64.h | 1 + packages/atchops/include/atchops/constants.h | 1 + packages/atchops/include/atchops/hex.h | 1 + packages/atchops/include/atchops/iv.h | 1 + packages/atchops/include/atchops/mbedtls.h | 6 +-- packages/atchops/include/atchops/platform.h | 26 ++++++++++ packages/atchops/include/atchops/rsa.h | 3 +- packages/atchops/include/atchops/rsa_key.h | 1 + packages/atchops/include/atchops/sha.h | 1 + packages/atchops/include/atchops/utf8.h | 1 + packages/atchops/include/atchops/uuid.h | 1 + packages/atchops/src/aes.c | 12 +++-- packages/atchops/src/aes_ctr.c | 8 +-- packages/atchops/src/base64.c | 19 +++---- packages/atchops/src/hex.c | 5 +- packages/atchops/src/iv.c | 3 +- packages/atchops/src/mbedtls.c | 1 + packages/atchops/src/rsa.c | 1 + packages/atchops/src/rsa_key.c | 1 + packages/atchops/src/sha.c | 1 + packages/atchops/src/utf8.c | 1 + packages/atchops/src/uuid.c | 47 ++++------------- packages/atclient/include/atclient/atclient.h | 1 + .../include/atclient/atclient_utils.h | 1 + packages/atclient/include/atclient/atkey.h | 5 +- packages/atclient/include/atclient/atkeys.h | 1 + .../atclient/include/atclient/atkeys_file.h | 1 + .../include/atclient/atnotification.h | 1 + .../atclient/include/atclient/connection.h | 1 + .../include/atclient/connection_hooks.h | 1 + .../atclient/include/atclient/constants.h | 2 +- .../include/atclient/encryption_key_helpers.h | 1 + packages/atclient/include/atclient/mbedtls.h | 9 ++-- packages/atclient/include/atclient/metadata.h | 1 + packages/atclient/include/atclient/monitor.h | 1 + packages/atclient/include/atclient/notify.h | 1 + .../atclient/include/atclient/notify_params.h | 1 + .../include/atclient/request_options.h | 1 + .../atclient/include/atclient/string_utils.h | 1 + packages/atclient/src/atclient.c | 5 +- packages/atclient/src/atclient_delete.c | 12 +++-- packages/atclient/src/atclient_get_atkeys.c | 39 ++++++++------- .../atclient/src/atclient_get_public_key.c | 34 ++++++++----- packages/atclient/src/atclient_get_self_key.c | 5 +- .../atclient/src/atclient_get_shared_key.c | 19 +++---- .../atclient/src/atclient_put_public_key.c | 9 ++-- packages/atclient/src/atclient_put_self_key.c | 19 +++---- .../atclient/src/atclient_put_shared_key.c | 47 +++++++++-------- packages/atclient/src/atclient_utils.c | 3 +- packages/atclient/src/atkey.c | 10 ++-- packages/atclient/src/atkeys.c | 1 + packages/atclient/src/atkeys_file.c | 7 ++- packages/atclient/src/atnotification.c | 5 +- packages/atclient/src/connection.c | 11 ++-- packages/atclient/src/connection_hooks.c | 17 ++++--- .../atclient/src/encryption_key_helpers.c | 45 +++++++++-------- packages/atclient/src/metadata.c | 5 +- packages/atclient/src/monitor.c | 6 ++- packages/atclient/src/notify.c | 1 + packages/atclient/src/notify_params.c | 1 + packages/atclient/src/request_options.c | 50 +++++++++++-------- packages/atclient/src/string_utils.c | 1 + packages/atcommons/include/atcommons/json.h | 24 +++++++-- packages/atcommons/src/enroll_namespace.c | 9 +--- packages/atcommons/src/enroll_params.c | 8 +-- packages/atlogger/include/atlogger/atlogger.h | 3 -- packages/atlogger/src/atlogger.c | 48 ++++++++++-------- 70 files changed, 357 insertions(+), 263 deletions(-) create mode 100644 packages/atchops/include/atchops/platform.h diff --git a/cmake/find_mbedtls.cmake b/cmake/find_mbedtls.cmake index 3f15f5bd..bae966b9 100644 --- a/cmake/find_mbedtls.cmake +++ b/cmake/find_mbedtls.cmake @@ -2,7 +2,6 @@ # Configurable variables option(ENABLE_TESTING "Enable MbedTLS tests" OFF) -option(ATCHOPS_MBEDTLS_VERSION_2 "Use v2 of mbedtls" OFF) set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE OPT_IN) # only try find_package if FIND_PACKAGE_ARGS is set message(STATUS "[MbedTLS] fetching package...") diff --git a/packages/atchops/include/atchops/aes.h b/packages/atchops/include/atchops/aes.h index 98efefb9..28790d77 100644 --- a/packages/atchops/include/atchops/aes.h +++ b/packages/atchops/include/atchops/aes.h @@ -1,9 +1,11 @@ #ifndef ATCHOPS_AES_H #define ATCHOPS_AES_H + #ifdef __cplusplus extern "C" { #endif +#include // IWYU pragma: keep #include enum atchops_aes_size { diff --git a/packages/atchops/include/atchops/aes_ctr.h b/packages/atchops/include/atchops/aes_ctr.h index c7a0f3af..b7ebaf09 100644 --- a/packages/atchops/include/atchops/aes_ctr.h +++ b/packages/atchops/include/atchops/aes_ctr.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atchops/aes.h" +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/base64.h b/packages/atchops/include/atchops/base64.h index 89a13e88..9bf148f5 100644 --- a/packages/atchops/include/atchops/base64.h +++ b/packages/atchops/include/atchops/base64.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/constants.h b/packages/atchops/include/atchops/constants.h index 77eecfc2..4cfe6590 100644 --- a/packages/atchops/include/atchops/constants.h +++ b/packages/atchops/include/atchops/constants.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #define ATCHOPS_RNG_PERSONALIZATION "@atchops12345" #ifdef __cplusplus diff --git a/packages/atchops/include/atchops/hex.h b/packages/atchops/include/atchops/hex.h index f336a1be..180f04e5 100644 --- a/packages/atchops/include/atchops/hex.h +++ b/packages/atchops/include/atchops/hex.h @@ -3,6 +3,7 @@ #ifdef __cplusplus extern "C" { #endif +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/iv.h b/packages/atchops/include/atchops/iv.h index ef40cca1..b3bbb3f0 100644 --- a/packages/atchops/include/atchops/iv.h +++ b/packages/atchops/include/atchops/iv.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include #define ATCHOPS_IV_BUFFER_SIZE 16 // non-base64 ivs are always 16 bytes long diff --git a/packages/atchops/include/atchops/mbedtls.h b/packages/atchops/include/atchops/mbedtls.h index b90aa0cb..2518b7fb 100644 --- a/packages/atchops/include/atchops/mbedtls.h +++ b/packages/atchops/include/atchops/mbedtls.h @@ -4,15 +4,13 @@ extern "C" { #endif -#ifdef TARGET_PORTENTA_H7 -#define ATCHOPS_MBEDTLS_VERSION_2 -#endif - +#include // IWYU pragma: keep #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export +#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export diff --git a/packages/atchops/include/atchops/platform.h b/packages/atchops/include/atchops/platform.h new file mode 100644 index 00000000..056416a4 --- /dev/null +++ b/packages/atchops/include/atchops/platform.h @@ -0,0 +1,26 @@ +#ifndef ATCHOPS_PLATFORM_H +#define ATCHOPS_PLATFORM_H + +// NOTE: there are two platform specific files: +// - atchops/platform.h +// - atcommons/json.h + +// Platforms we support + +// Default MbedTLS version + +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#define ATCHOPS_TARGET_UNIX + +#elif defined(_WIN32) +#define ATCHOPS_TARGET_WINDOWS + +#elif defined(CONFIG_IDF_TARGET_ESP32) +#define ATCHOPS_TARGET_ESPIDF + +#elif defined(TARGET_PORTENTA_H7) +#define ATCHOPS_TARGET_ARDUINO +#define ATCHOPS_MBEDTLS_VERSION_2 + +#endif +#endif diff --git a/packages/atchops/include/atchops/rsa.h b/packages/atchops/include/atchops/rsa.h index 5b19de4c..dea2dcf9 100644 --- a/packages/atchops/include/atchops/rsa.h +++ b/packages/atchops/include/atchops/rsa.h @@ -4,9 +4,10 @@ extern "C" { #endif -#include "atchops/constants.h" +#include "atchops/constants.h" // IWYU pragma: keep #include "atchops/rsa_key.h" #include "atchops/sha.h" +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/rsa_key.h b/packages/atchops/include/atchops/rsa_key.h index 25bbd67e..0577d057 100644 --- a/packages/atchops/include/atchops/rsa_key.h +++ b/packages/atchops/include/atchops/rsa_key.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include #include diff --git a/packages/atchops/include/atchops/sha.h b/packages/atchops/include/atchops/sha.h index 038d3851..450edd6b 100644 --- a/packages/atchops/include/atchops/sha.h +++ b/packages/atchops/include/atchops/sha.h @@ -5,6 +5,7 @@ extern "C" { #endif #include +#include // IWYU pragma: keep #include typedef enum atchops_md_type { diff --git a/packages/atchops/include/atchops/utf8.h b/packages/atchops/include/atchops/utf8.h index 4bb5b2a7..37dad714 100644 --- a/packages/atchops/include/atchops/utf8.h +++ b/packages/atchops/include/atchops/utf8.h @@ -3,6 +3,7 @@ #ifdef __cplusplus extern "C" { #endif +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/uuid.h b/packages/atchops/include/atchops/uuid.h index 92d2234c..e219800b 100644 --- a/packages/atchops/include/atchops/uuid.h +++ b/packages/atchops/include/atchops/uuid.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/src/aes.c b/packages/atchops/src/aes.c index 85f8eb41..d0f05919 100644 --- a/packages/atchops/src/aes.c +++ b/packages/atchops/src/aes.c @@ -2,9 +2,10 @@ #include "atchops/base64.h" #include "atchops/constants.h" #include "atchops/mbedtls.h" -#include -#include +#include #include +#include +#include #define TAG "aes" @@ -14,13 +15,13 @@ int atchops_aes_generate_key(unsigned char *key, const enum atchops_aes_size key /* * 1. Validate arguments */ - if(key == NULL) { + if (key == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "key is NULL\n"); return ret; } - if(keybits != ATCHOPS_AES_256) { + if (keybits != ATCHOPS_AES_256) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Unsupported keybits\n"); return ret; @@ -45,7 +46,8 @@ int atchops_aes_generate_key(unsigned char *key, const enum atchops_aes_size key /* * 3. Seed the random number generator */ - if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)personlization, strlen(personlization))) != 0) { + if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)personlization, + strlen(personlization))) != 0) { goto exit; } diff --git a/packages/atchops/src/aes_ctr.c b/packages/atchops/src/aes_ctr.c index 6db90568..7d2efd69 100644 --- a/packages/atchops/src/aes_ctr.c +++ b/packages/atchops/src/aes_ctr.c @@ -1,6 +1,7 @@ #include "atchops/aes_ctr.h" -#include #include "atchops/mbedtls.h" +#include +#include #include #include #include @@ -238,9 +239,10 @@ int atchops_aes_ctr_decrypt(const unsigned char *key, const enum atchops_aes_siz /* * 5. Return outputs */ - if(plaintext_padded_len - pad_val > plaintext_size) { + if (plaintext_padded_len - pad_val > plaintext_size) { ret = 1; - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "plaintext_size is less than (plaintext_padded_len - pad_val). The buffer is too small.\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "plaintext_size is less than (plaintext_padded_len - pad_val). The buffer is too small.\n"); goto exit; } diff --git a/packages/atchops/src/base64.c b/packages/atchops/src/base64.c index b0b3dd6c..4510ff1e 100644 --- a/packages/atchops/src/base64.c +++ b/packages/atchops/src/base64.c @@ -1,6 +1,7 @@ #include "atchops/base64.h" -#include #include "atchops/mbedtls.h" +#include +#include #include #define TAG "base64" @@ -43,12 +44,12 @@ int atchops_base64_encode(const unsigned char *src, const size_t src_len, unsign */ if (dst_len == NULL) { size_t x; // throw away variable - if((ret = mbedtls_base64_encode(dst, dst_size, &x, src, src_len)) != 0) { + if ((ret = mbedtls_base64_encode(dst, dst_size, &x, src, src_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: mbedtls_base64_encode failed\n"); goto exit; } } else { - if((ret = mbedtls_base64_encode(dst, dst_size, dst_len, src, src_len)) != 0) { + if ((ret = mbedtls_base64_encode(dst, dst_size, dst_len, src, src_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: mbedtls_base64_encode failed\n"); goto exit; } @@ -65,25 +66,25 @@ int atchops_base64_decode(const unsigned char *src, const size_t src_len, unsign /* * 1. Validate arguments */ - if(src == NULL) { + if (src == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: src is NULL\n"); return ret; } - if(src_len <= 0) { + if (src_len <= 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: src_len is less than or equal to 0\n"); return ret; } - if(dst == NULL) { + if (dst == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: dst is NULL\n"); return ret; } - if(dst_size <= 0) { + if (dst_size <= 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: dst_size is less than or equal to 0\n"); return ret; @@ -94,12 +95,12 @@ int atchops_base64_decode(const unsigned char *src, const size_t src_len, unsign */ if (dst_len == NULL) { size_t x; // throw away variable - if((ret = mbedtls_base64_decode(dst, dst_size, &x, src, src_len)) != 0) { + if ((ret = mbedtls_base64_decode(dst, dst_size, &x, src, src_len)) != 0) { atlogger_log("base64", ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: mbedtls_base64_decode failed\n"); goto exit; } } else { - if((ret = mbedtls_base64_decode(dst, dst_size, dst_len, src, src_len)) != 0) { + if ((ret = mbedtls_base64_decode(dst, dst_size, dst_len, src, src_len)) != 0) { atlogger_log("base64", ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_decode: mbedtls_base64_decode failed\n"); goto exit; } diff --git a/packages/atchops/src/hex.c b/packages/atchops/src/hex.c index f6e0b8f2..b6cef8ca 100644 --- a/packages/atchops/src/hex.c +++ b/packages/atchops/src/hex.c @@ -1,4 +1,5 @@ #include "atchops/hex.h" +#include #include #include @@ -29,7 +30,7 @@ int atchops_hex_to_bytes(unsigned char *bytes, const size_t byte_len, const char int atchops_bytes_to_hex(char *hex_str, const size_t hex_str_len, const unsigned char *bytes, const size_t bytes_len) { // Ensure the hex string buffer is large enough: 2 chars for each byte + 1 for null terminator if (hex_str_len < (bytes_len * 2 + 1)) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Insufficient space for hex string\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Insufficient space for hex string\n"); return -1; } @@ -39,4 +40,4 @@ int atchops_bytes_to_hex(char *hex_str, const size_t hex_str_len, const unsigned hex_str[bytes_len * 2] = '\0'; return 0; -} \ No newline at end of file +} diff --git a/packages/atchops/src/iv.c b/packages/atchops/src/iv.c index 0c9800eb..984bce54 100644 --- a/packages/atchops/src/iv.c +++ b/packages/atchops/src/iv.c @@ -1,8 +1,9 @@ #include "atchops/iv.h" #include "atchops/base64.h" #include "atchops/constants.h" -#include #include "atchops/mbedtls.h" +#include +#include #include #include diff --git a/packages/atchops/src/mbedtls.c b/packages/atchops/src/mbedtls.c index 1ca2d4e8..3b2a7f6e 100644 --- a/packages/atchops/src/mbedtls.c +++ b/packages/atchops/src/mbedtls.c @@ -1,5 +1,6 @@ #include "atchops/mbedtls.h" #include "atchops/sha.h" +#include const mbedtls_md_type_t atchops_mbedtls_md_map[] = { [ATCHOPS_MD_NONE] = MBEDTLS_MD_NONE, [ATCHOPS_MD_MD5] = MBEDTLS_MD_MD5, diff --git a/packages/atchops/src/rsa.c b/packages/atchops/src/rsa.c index 7cd52a01..53f46e52 100644 --- a/packages/atchops/src/rsa.c +++ b/packages/atchops/src/rsa.c @@ -3,6 +3,7 @@ #include "atchops/rsa_key.h" #include "atchops/sha.h" #include "atlogger/atlogger.h" +#include #include #include #include diff --git a/packages/atchops/src/rsa_key.c b/packages/atchops/src/rsa_key.c index f92ee636..89ff9116 100644 --- a/packages/atchops/src/rsa_key.c +++ b/packages/atchops/src/rsa_key.c @@ -2,6 +2,7 @@ #include "atchops/base64.h" #include "atchops/constants.h" #include "atchops/mbedtls.h" +#include #include #include #include diff --git a/packages/atchops/src/sha.c b/packages/atchops/src/sha.c index 5f9c45eb..d16ad9bc 100644 --- a/packages/atchops/src/sha.c +++ b/packages/atchops/src/sha.c @@ -1,5 +1,6 @@ #include "atchops/sha.h" #include "atchops/mbedtls.h" +#include #include #include diff --git a/packages/atchops/src/utf8.c b/packages/atchops/src/utf8.c index 9f04c0ad..62f7e657 100644 --- a/packages/atchops/src/utf8.c +++ b/packages/atchops/src/utf8.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/packages/atchops/src/uuid.c b/packages/atchops/src/uuid.c index 7f78be0c..eb7dfd7f 100644 --- a/packages/atchops/src/uuid.c +++ b/packages/atchops/src/uuid.c @@ -1,4 +1,5 @@ #include "atchops/uuid.h" +#include #include #include #include @@ -82,13 +83,10 @@ exit: { return ret; } * under the terms of the MIT license. See LICENSE for details. */ -#if defined(_WIN32) -#include -#include -#endif - -#if defined(CONFIG_IDF_TARGET_ESP32) +#if defined(ATCHOPS_TARGET_ESPIDF) #include "esp_random.h" +#else +#include "atchops/mbedtls.h" #endif static uint64_t xorshift128plus(uint64_t *s) { @@ -102,39 +100,10 @@ static uint64_t xorshift128plus(uint64_t *s) { } static int uuid4_init(void) { -#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) - int res; - FILE *fp = fopen("/dev/urandom", "rb"); - if (!fp) { - return UUID4_EFAILURE; - } - res = fread(seed, 1, sizeof(seed), fp); - fclose(fp); - if (res != sizeof(seed)) { - return UUID4_EFAILURE; - } - -#elif defined(_WIN32) - int res; - HCRYPTPROV hCryptProv; - res = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); - if (!res) { - return UUID4_EFAILURE; - } - res = CryptGenRandom(hCryptProv, (DWORD)sizeof(seed), (PBYTE)seed); - CryptReleaseContext(hCryptProv, 0); - if (!res) { - return UUID4_EFAILURE; - } - -#elif defined(CONFIG_IDF_TARGET_ESP32) - for (int i = 0; i < 2; i++) { - seed[i] = ((uint64_t)esp_random() << 32) | esp_random(); // Generate random 64-bit values - } -#elif defined(TARGET_PORTENTA_H7) +#if defined(ATCHOPS_TARGET_UNIX) || defined(ATCHOPS_TARGET_WINDOWS) || defined(ATCHOPS_TARGET_ARDUINO) int ret = 0; - mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; + mbedtls_entropy_context entropy; // TODO replace this string const unsigned char pers[13] = {"Arduino_Seed"}; @@ -170,6 +139,10 @@ static int uuid4_init(void) { mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_entropy_free(&entropy); return UUID4_ESUCCESS; +#elif defined(ATCHOPS_TARGET_ESPIDF) + for (int i = 0; i < 2; i++) { + seed[i] = ((uint64_t)esp_random() << 32) | esp_random(); // Generate random 64-bit values + } #else #error "unsupported platform" #endif diff --git a/packages/atclient/include/atclient/atclient.h b/packages/atclient/include/atclient/atclient.h index c34beabb..81440979 100644 --- a/packages/atclient/include/atclient/atclient.h +++ b/packages/atclient/include/atclient/atclient.h @@ -8,6 +8,7 @@ extern "C" { #include "atclient/atkeys.h" #include "atclient/connection.h" #include "atclient/request_options.h" +#include // IWYU pragma: keep #include #include diff --git a/packages/atclient/include/atclient/atclient_utils.h b/packages/atclient/include/atclient/atclient_utils.h index b8b0bf19..f6d7472a 100644 --- a/packages/atclient/include/atclient/atclient_utils.h +++ b/packages/atclient/include/atclient/atclient_utils.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atclient/atkeys.h" +#include // IWYU pragma: keep /** * @brief Get address of atServer from the atDirectory, You should check the return code of this function before using diff --git a/packages/atclient/include/atclient/atkey.h b/packages/atclient/include/atclient/atkey.h index 504dd0a5..5f1ffca9 100644 --- a/packages/atclient/include/atclient/atkey.h +++ b/packages/atclient/include/atclient/atkey.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atclient/metadata.h" +#include // IWYU pragma: keep #include #include @@ -274,8 +275,8 @@ int atclient_atkey_create_shared_key(atclient_atkey *atkey, const char *name, co const char *shared_with, const char *namespace_str); /** - * @brief Populates the atclient_key struct with the reserved key name provided. Reserved keys are usually restricted keys - * that are required the server for proper functioning and sometimes might not follow the standard atkey fomrmat + * @brief Populates the atclient_key struct with the reserved key name provided. Reserved keys are usually restricted + * keys that are required the server for proper functioning and sometimes might not follow the standard atkey fomrmat * * @param atkey the atkey struct to populate, assumed that this was already initialized via atclient_atkey_init * @param name name of your key, e.g. "privatekey:at_secret" diff --git a/packages/atclient/include/atclient/atkeys.h b/packages/atclient/include/atclient/atkeys.h index 46788de9..3f119fa5 100644 --- a/packages/atclient/include/atclient/atkeys.h +++ b/packages/atclient/include/atclient/atkeys.h @@ -6,6 +6,7 @@ extern "C" { #include "atchops/rsa_key.h" #include "atclient/atkeys_file.h" +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/atkeys_file.h b/packages/atclient/include/atclient/atkeys_file.h index 526e5448..00e71596 100644 --- a/packages/atclient/include/atclient/atkeys_file.h +++ b/packages/atclient/include/atclient/atkeys_file.h @@ -3,6 +3,7 @@ #ifdef __cplusplus extern "C" { #endif +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/atnotification.h b/packages/atclient/include/atclient/atnotification.h index b20420ee..9d3be6ba 100644 --- a/packages/atclient/include/atclient/atnotification.h +++ b/packages/atclient/include/atclient/atnotification.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atcommons/json.h" +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/connection.h b/packages/atclient/include/atclient/connection.h index b487b17d..08aea6a2 100644 --- a/packages/atclient/include/atclient/connection.h +++ b/packages/atclient/include/atclient/connection.h @@ -6,6 +6,7 @@ extern "C" { #include "atchops/mbedtls.h" #include "atclient/connection_hooks.h" +#include // IWYU pragma: keep #include #include diff --git a/packages/atclient/include/atclient/connection_hooks.h b/packages/atclient/include/atclient/connection_hooks.h index c9442dad..aace57f7 100644 --- a/packages/atclient/include/atclient/connection_hooks.h +++ b/packages/atclient/include/atclient/connection_hooks.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/constants.h b/packages/atclient/include/atclient/constants.h index ef6352f6..7b7e5a82 100755 --- a/packages/atclient/include/atclient/constants.h +++ b/packages/atclient/include/atclient/constants.h @@ -99,7 +99,7 @@ extern "C" { #define BHWHT "\e[1;97m" // Reset -#define reset "\e[0m" +#define ATCLIENT_RESET "\e[0m" #define CRESET "\e[0m" #define COLOR_RESET "\e[0m" diff --git a/packages/atclient/include/atclient/encryption_key_helpers.h b/packages/atclient/include/atclient/encryption_key_helpers.h index be0ede45..b12bdeb9 100644 --- a/packages/atclient/include/atclient/encryption_key_helpers.h +++ b/packages/atclient/include/atclient/encryption_key_helpers.h @@ -7,6 +7,7 @@ extern "C" { #include "atclient/atclient.h" #include "atclient/atkey.h" #include "atclient/atkeys.h" +#include // IWYU pragma: keep /** * @brief Retreives the public encryption key of a given atsign. diff --git a/packages/atclient/include/atclient/mbedtls.h b/packages/atclient/include/atclient/mbedtls.h index 69046c1c..a50a1e0d 100644 --- a/packages/atclient/include/atclient/mbedtls.h +++ b/packages/atclient/include/atclient/mbedtls.h @@ -4,11 +4,10 @@ extern "C" { #endif -#include -#include -#include -#include -#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export #ifdef __cplusplus } diff --git a/packages/atclient/include/atclient/metadata.h b/packages/atclient/include/atclient/metadata.h index e9425806..ff030d8e 100644 --- a/packages/atclient/include/atclient/metadata.h +++ b/packages/atclient/include/atclient/metadata.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atcommons/json.h" +#include // IWYU pragma: keep #include #include #include // IWYU pragma: keep (for uint8_t) diff --git a/packages/atclient/include/atclient/monitor.h b/packages/atclient/include/atclient/monitor.h index 584164da..e8874ad9 100644 --- a/packages/atclient/include/atclient/monitor.h +++ b/packages/atclient/include/atclient/monitor.h @@ -6,6 +6,7 @@ extern "C" { #include "atclient/atclient.h" #include "atclient/atnotification.h" +#include // IWYU pragma: keep #include /** diff --git a/packages/atclient/include/atclient/notify.h b/packages/atclient/include/atclient/notify.h index b16237d2..181fcf8d 100644 --- a/packages/atclient/include/atclient/notify.h +++ b/packages/atclient/include/atclient/notify.h @@ -6,6 +6,7 @@ extern "C" { #include "atclient/atclient.h" #include "atclient/notify_params.h" +#include // IWYU pragma: keep int atclient_notify(atclient *ctx, const atclient_notify_params *params, char **notification_id); diff --git a/packages/atclient/include/atclient/notify_params.h b/packages/atclient/include/atclient/notify_params.h index 0882b7b9..058a55fa 100644 --- a/packages/atclient/include/atclient/notify_params.h +++ b/packages/atclient/include/atclient/notify_params.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "atclient/atkey.h" +#include // IWYU pragma: keep #include #define ATCLIENT_DEFAULT_NOTIFIER "SYSTEM" diff --git a/packages/atclient/include/atclient/request_options.h b/packages/atclient/include/atclient/request_options.h index b872a01d..69741cda 100644 --- a/packages/atclient/include/atclient/request_options.h +++ b/packages/atclient/include/atclient/request_options.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/string_utils.h b/packages/atclient/include/atclient/string_utils.h index 3062e1f1..eab201f7 100755 --- a/packages/atclient/include/atclient/string_utils.h +++ b/packages/atclient/include/atclient/string_utils.h @@ -4,6 +4,7 @@ extern "C" { #endif +#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/src/atclient.c b/packages/atclient/src/atclient.c index 66506288..c079affa 100755 --- a/packages/atclient/src/atclient.c +++ b/packages/atclient/src/atclient.c @@ -11,6 +11,7 @@ #include "atclient/request_options.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" +#include #include #include #include @@ -454,7 +455,7 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr goto exit; } char *atsign_without_at = malloc(sizeof(char) * strlen(atsign_with_at) + 1); - if(atsign_without_at == NULL) { + if (atsign_without_at == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for atsign_without_at"); ret = -1; goto exit; @@ -574,7 +575,7 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr * 10a. Build `cram:` noop_cmd */ cram_cmd = malloc(sizeof(char) * ATCLIENT_CRAM_COMMAND_LEN + 1); // free later - if(cram_cmd == NULL) { + if (cram_cmd == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for cram_cmd"); ret = -1; goto exit; diff --git a/packages/atclient/src/atclient_delete.c b/packages/atclient/src/atclient_delete.c index d2c11d82..d2e799f1 100755 --- a/packages/atclient/src/atclient_delete.c +++ b/packages/atclient/src/atclient_delete.c @@ -3,6 +3,7 @@ #include "atclient/constants.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" +#include #include #include #include @@ -18,7 +19,7 @@ int atclient_delete(atclient *atclient, const atclient_atkey *atkey, const atcli /* * 1. Check arguments */ - if ((ret = atclient_delete_validate_arguments(atclient, atkey, (atclient_delete_request_options*)options)) != 0) { + if ((ret = atclient_delete_validate_arguments(atclient, atkey, (atclient_delete_request_options *)options)) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_delete_validate_arguments: %d\n", ret); return ret; @@ -65,8 +66,8 @@ int atclient_delete(atclient *atclient, const atclient_atkey *atkey, const atcli /* * 4. Send command */ - if ((ret = atclient_connection_send(&atclient->atserver_connection, (unsigned char *)delete_cmd, - delete_cmd_size - 1, recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&atclient->atserver_connection, (unsigned char *)delete_cmd, delete_cmd_size - 1, + recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -134,7 +135,8 @@ static int atclient_delete_validate_arguments(const atclient *atclient, const at } // skip atclient_atkey_is_shared_by_initialized() if atclient_delete_request_options->skip_shared_by_check is true - if(atclient_delete_request_options_is_skip_shared_by_check_flag_initialized(options) && options->skip_shared_by_check) { + if (atclient_delete_request_options_is_skip_shared_by_check_flag_initialized(options) && + options->skip_shared_by_check) { ret = 0; goto exit; } @@ -147,4 +149,4 @@ static int atclient_delete_validate_arguments(const atclient *atclient, const at ret = 0; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atclient_get_atkeys.c b/packages/atclient/src/atclient_get_atkeys.c index 3a2604d0..f8ea08e3 100755 --- a/packages/atclient/src/atclient_get_atkeys.c +++ b/packages/atclient/src/atclient_get_atkeys.c @@ -1,22 +1,25 @@ +#include #include +#include #include #include #include #include #include -#include #define TAG "atclient_get_atkeys" -static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, const size_t *output_array_len); +static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, + const size_t *output_array_len); -int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *output_array_len, const atclient_get_atkeys_request_options *request_options) { +int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *output_array_len, + const atclient_get_atkeys_request_options *request_options) { int ret = 1; /* * 1. Validate arguments */ - if ((ret = atclient_get_atkeys_validate_arguments(atclient, (const atclient_atkey **) atkey, output_array_len)) != 0) { + if ((ret = atclient_get_atkeys_validate_arguments(atclient, (const atclient_atkey **)atkey, output_array_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_atkeys_validate_arguments: %d\n", ret); return ret; } @@ -26,22 +29,21 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp */ size_t scan_cmd_size = strlen("scan"); - if(request_options != NULL) { - if(atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { - if(request_options->show_hidden) { + if (request_options != NULL) { + if (atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { + if (request_options->show_hidden) { scan_cmd_size += strlen(":showHidden:true"); } else { scan_cmd_size += strlen(":showHidden:false"); } } - if(atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { + if (atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { scan_cmd_size += strlen(" ") + strlen(request_options->regex); } } scan_cmd_size += strlen("\r\n") + 1; - char scan_cmd[scan_cmd_size]; const size_t recv_size = 8192; // TODO change using atclient_connection_read which will handle realloc @@ -55,15 +57,15 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp */ size_t pos = 0; pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, "scan"); - if(request_options != NULL) { - if(atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { - if(request_options->show_hidden) { + if (request_options != NULL) { + if (atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { + if (request_options->show_hidden) { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, ":showHidden:true"); } else { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, ":showHidden:false"); } } - if(atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { + if (atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, " %s", request_options->regex); } } @@ -88,7 +90,7 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -158,7 +160,8 @@ exit: { } } -static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, const size_t *output_array_len) { +static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, + const size_t *output_array_len) { int ret = 1; // check to make sure atclient is not null @@ -180,13 +183,13 @@ static int atclient_get_atkeys_validate_arguments(const atclient *atclient, cons goto exit; } - if(atkey == NULL) { + if (atkey == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is NULL\n"); goto exit; } - if(output_array_len == NULL) { + if (output_array_len == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "output_array_len is NULL\n"); goto exit; @@ -195,4 +198,4 @@ static int atclient_get_atkeys_validate_arguments(const atclient *atclient, cons ret = 0; goto exit; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atclient_get_public_key.c b/packages/atclient/src/atclient_get_public_key.c index 4af9ccc4..887ce8d5 100755 --- a/packages/atclient/src/atclient_get_public_key.c +++ b/packages/atclient/src/atclient_get_public_key.c @@ -2,22 +2,24 @@ #include "atclient/atkey.h" #include "atclient/constants.h" #include "atclient/string_utils.h" +#include #include #include #include #define TAG "atclient_get_public_key" -static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, const char **value); +static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, + const char **value); -int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **value, atclient_get_public_key_request_options *request_options) { +int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **value, + atclient_get_public_key_request_options *request_options) { int ret = 1; /* * 1. Validate arguments */ - if ((ret = atclient_get_public_key_validate_arguments(atclient, atkey, (const char **) value)) != - 0) { + if ((ret = atclient_get_public_key_validate_arguments(atclient, atkey, (const char **)value)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_public_key_validate_arguments: %d\n", ret); return ret; } @@ -54,7 +56,9 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va goto exit; } - const bool bypass_cache = request_options != NULL && atclient_get_public_key_request_options_is_bypass_cache_initialized(request_options) && request_options->bypass_cache; + const bool bypass_cache = request_options != NULL && + atclient_get_public_key_request_options_is_bypass_cache_initialized(request_options) && + request_options->bypass_cache; const size_t plookup_cmd_size = strlen("plookup:all:\r\n") + (bypass_cache ? strlen("bypassCache:true:") : 0) + strlen(atkey_str_without_public) + 1; @@ -83,7 +87,7 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -108,8 +112,11 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va * 6. Return data to caller */ - bool write_metadata_to_atkey = request_options != NULL && atclient_get_public_key_request_options_is_store_atkey_metadata_initialized(request_options) && request_options->store_atkey_metadata; - if(write_metadata_to_atkey) { + bool write_metadata_to_atkey = + request_options != NULL && + atclient_get_public_key_request_options_is_store_atkey_metadata_initialized(request_options) && + request_options->store_atkey_metadata; + if (write_metadata_to_atkey) { cJSON *metadata = cJSON_GetObjectItem(root, "metaData"); if (metadata == NULL) { ret = 1; @@ -125,7 +132,7 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va } } - if(value != NULL) { + if (value != NULL) { if ((*value = malloc(sizeof(char) * (strlen(data->valuestring) + 1))) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for value\n"); @@ -148,7 +155,8 @@ exit: { } } -static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, const char **value) { +static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, + const char **value) { int ret = 1; if (atclient == NULL) { @@ -175,13 +183,13 @@ static int atclient_get_public_key_validate_arguments(const atclient *atclient, goto exit; } - if(!atclient_atkey_is_key_initialized(atkey)) { + if (!atclient_atkey_is_key_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not initialized\n"); goto exit; } - if(!atclient_atkey_is_shared_by_initialized(atkey)) { + if (!atclient_atkey_is_shared_by_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not shared by initialized\n"); goto exit; @@ -204,4 +212,4 @@ static int atclient_get_public_key_validate_arguments(const atclient *atclient, ret = 0; goto exit; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atclient_get_self_key.c b/packages/atclient/src/atclient_get_self_key.c index 09408d8e..6c91d5c0 100755 --- a/packages/atclient/src/atclient_get_self_key.c +++ b/packages/atclient/src/atclient_get_self_key.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -91,7 +92,7 @@ int atclient_get_self_key(atclient *atclient, atclient_atkey *atkey, char **valu char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -271,4 +272,4 @@ static int atclient_get_self_key_validate_arguments(const atclient *atclient, co ret = 0; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atclient_get_shared_key.c b/packages/atclient/src/atclient_get_shared_key.c index 667f3438..c7982e1c 100755 --- a/packages/atclient/src/atclient_get_shared_key.c +++ b/packages/atclient/src/atclient_get_shared_key.c @@ -5,11 +5,12 @@ #include #include #include +#include +#include #include #include #include #include -#include #define TAG "atclient_get_sharedkey" @@ -24,11 +25,11 @@ static int atclient_get_shared_key_shared_by_other_with_me(atclient *atclient, atclient_atkey *atkey, char **value, const atclient_get_shared_key_request_options *request_options); -int atclient_get_shared_key(atclient *atclient, atclient_atkey *atkey, - char **value, const atclient_get_shared_key_request_options *request_options) { +int atclient_get_shared_key(atclient *atclient, atclient_atkey *atkey, char **value, + const atclient_get_shared_key_request_options *request_options) { int ret = 1; - if ((ret = atclient_get_shared_key_validate_arguments(atclient, atkey, (const char **) value)) != 0) { + if ((ret = atclient_get_shared_key_validate_arguments(atclient, atkey, (const char **)value)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_shared_key_validate_arguments: %d\n", ret); return ret; } @@ -130,9 +131,9 @@ static int atclient_get_shared_key_validate_arguments(const atclient *atclient, exit: { return ret; } } -static int atclient_get_shared_key_shared_by_me_with_other( - atclient *atclient, atclient_atkey *atkey, - char **value, const atclient_get_shared_key_request_options *request_options) { +static int +atclient_get_shared_key_shared_by_me_with_other(atclient *atclient, atclient_atkey *atkey, char **value, + const atclient_get_shared_key_request_options *request_options) { int ret = 1; /* @@ -229,7 +230,7 @@ static int atclient_get_shared_key_shared_by_me_with_other( char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -455,7 +456,7 @@ atclient_get_shared_key_shared_by_other_with_me(atclient *atclient, atclient_atk char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); diff --git a/packages/atclient/src/atclient_put_public_key.c b/packages/atclient/src/atclient_put_public_key.c index b246d05d..52e912bc 100755 --- a/packages/atclient/src/atclient_put_public_key.c +++ b/packages/atclient/src/atclient_put_public_key.c @@ -1,12 +1,13 @@ #include +#include #include #include +#include #include #include #include #include #include -#include #define TAG "atclient_put_public_key" @@ -86,7 +87,7 @@ int atclient_put_public_key(atclient *ctx, atclient_atkey *atkey, const char *va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -125,13 +126,13 @@ static int atclient_put_public_key_validate_arguments(const atclient *ctx, const goto exit; } - if(!atclient_is_atserver_connection_started(ctx)) { + if (!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; } - if(!atclient_is_atsign_initialized(ctx)) { + if (!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx->atsign is not intiialized\n"); goto exit; diff --git a/packages/atclient/src/atclient_put_self_key.c b/packages/atclient/src/atclient_put_self_key.c index 3ad09345..ab4d6f6d 100755 --- a/packages/atclient/src/atclient_put_self_key.c +++ b/packages/atclient/src/atclient_put_self_key.c @@ -1,14 +1,15 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include -#include #define TAG "atclient_put_self_key" @@ -87,7 +88,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu } memset(iv_base64, 0, sizeof(unsigned char) * iv_base64_size); - if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *) iv_base64, iv_base64_size, NULL)) != 0) { + if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *)iv_base64, iv_base64_size, NULL)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } @@ -109,7 +110,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu size_t value_encrypted_base64_len = 0; memset(value_encrypted_base64, 0, sizeof(char) * value_encrypted_base64_size); - if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *) value_encrypted_base64, + if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *)value_encrypted_base64, value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; @@ -161,7 +162,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -196,13 +197,13 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke goto exit; } - if(!atclient_is_atserver_connection_started(ctx)) { + if (!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; } - if(!atclient_is_atsign_initialized(ctx)) { + if (!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx->atsign is not intiialized\n"); goto exit; @@ -214,13 +215,13 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke goto exit; } - if(!atclient_atkey_is_key_initialized(atkey)) { + if (!atclient_atkey_is_key_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not initialized\n"); goto exit; } - if(!atclient_atkey_is_shared_by_initialized(atkey)) { + if (!atclient_atkey_is_shared_by_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.shared_by is not initialized\n"); goto exit; @@ -235,4 +236,4 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke ret = 0; goto exit; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atclient_put_shared_key.c b/packages/atclient/src/atclient_put_shared_key.c index 7819309d..709b8624 100755 --- a/packages/atclient/src/atclient_put_shared_key.c +++ b/packages/atclient/src/atclient_put_shared_key.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -77,18 +78,18 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va if (request_options != NULL && atclient_put_shared_key_request_options_is_shared_encryption_key_initialized(request_options)) { memcpy(shared_encryption_key, request_options->shared_encryption_key, shared_encryption_key_size); - } else { - ret = atclient_get_shared_encryption_key_shared_by_me(ctx, recipient_atsign_with_at, - shared_encryption_key); + } else { + ret = atclient_get_shared_encryption_key_shared_by_me(ctx, recipient_atsign_with_at, shared_encryption_key); if (ret == ATCLIENT_ERR_AT0015_KEY_NOT_FOUND) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Did not find shared_encryption_key_shared_by_me.. Creating key pair for me and other...\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, + "Did not find shared_encryption_key_shared_by_me.. Creating key pair for me and other...\n"); if ((ret = atclient_create_shared_encryption_key_pair_for_me_and_other(ctx, recipient_atsign_with_at, - shared_encryption_key)) != 0) { + shared_encryption_key)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_create_shared_encryption_key_pair_for_me_and_other: %d\n", ret); + "atclient_create_shared_encryption_key_pair_for_me_and_other: %d\n", ret); goto exit; } - } else if(ret != 0) { + } else if (ret != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_shared_encryption_key_shared_by_me: %d\n", ret); goto exit; } @@ -97,18 +98,18 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va /* * 4. Generate IV */ - if((ret = atchops_iv_generate(iv)) != 0) { + if ((ret = atchops_iv_generate(iv)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_iv_generate: %d\n", ret); goto exit; } memset(iv_base64, 0, sizeof(char) * iv_base64_size); - if((ret = atchops_base64_encode(iv, iv_size, (unsigned char *) iv_base64, iv_base64_size, NULL)) != 0) { + if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *)iv_base64, iv_base64_size, NULL)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } - if((ret = atclient_atkey_metadata_set_iv_nonce(&(atkey->metadata), iv_base64)) != 0) { + if ((ret = atclient_atkey_metadata_set_iv_nonce(&(atkey->metadata), iv_base64)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkey_metadata_set_iv_nonce: %d\n", ret); goto exit; } @@ -118,15 +119,16 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va */ size_t value_encrypted_len = 0; memset(value_encrypted, 0, sizeof(unsigned char) * value_encrypted_size); - if ((ret = atchops_aes_ctr_encrypt(shared_encryption_key, ATCHOPS_AES_256, iv, (const unsigned char *) value, value_len, value_encrypted, - value_encrypted_size, &value_encrypted_len)) != 0) { + if ((ret = atchops_aes_ctr_encrypt(shared_encryption_key, ATCHOPS_AES_256, iv, (const unsigned char *)value, + value_len, value_encrypted, value_encrypted_size, &value_encrypted_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_aes_ctr_encrypt: %d\n", ret); goto exit; } size_t value_encrypted_base64_len = 0; memset(value_encrypted_base64, 0, sizeof(char) * value_encrypted_base64_size); - if((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *) value_encrypted_base64, value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { + if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *)value_encrypted_base64, + value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } @@ -146,8 +148,8 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va } const size_t atkey_str_len = strlen(atkey_str); - const size_t update_cmd_size = - strlen("update") + metadata_protocol_str_len + strlen(":") + atkey_str_len + strlen(" ") + value_encrypted_base64_len + strlen("\r\n") + 1; + const size_t update_cmd_size = strlen("update") + metadata_protocol_str_len + strlen(":") + atkey_str_len + + strlen(" ") + value_encrypted_base64_len + strlen("\r\n") + 1; if ((update_cmd = malloc(sizeof(char) * update_cmd_size)) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for update_cmd\n"); @@ -160,8 +162,8 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va /* * 7. Send update command */ - if ((ret = atclient_connection_send(&ctx->atserver_connection, (unsigned char *) update_cmd, update_cmd_len, recv, recv_size, - &recv_len)) != 0) { + if ((ret = atclient_connection_send(&ctx->atserver_connection, (unsigned char *)update_cmd, update_cmd_len, recv, + recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -173,7 +175,7 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -189,13 +191,14 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va ret = 0; goto exit; -exit: { +exit: { free(recipient_atsign_with_at); free(update_cmd); free(metadata_protocol_str); free(atkey_str); free(recv); - return ret; } + return ret; +} } static int atclient_put_shared_key_validate_arguments(const atclient *ctx, const atclient_atkey *atkey, @@ -211,13 +214,13 @@ static int atclient_put_shared_key_validate_arguments(const atclient *ctx, const goto exit; } - if(!atclient_is_atsign_initialized(ctx)) { + if (!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atsign is not initialized\n"); goto exit; } - if(!atclient_is_atserver_connection_started(ctx)) { + if (!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; diff --git a/packages/atclient/src/atclient_utils.c b/packages/atclient/src/atclient_utils.c index 0554e524..eb18e96e 100644 --- a/packages/atclient/src/atclient_utils.c +++ b/packages/atclient/src/atclient_utils.c @@ -2,6 +2,7 @@ #include "atclient/atkeys.h" #include "atclient/connection.h" #include "atclient/string_utils.h" +#include #include #include #include @@ -122,4 +123,4 @@ int atclient_utils_populate_atkeys_from_homedir(atclient_atkeys *atkeys, const c goto exit; exit: { return ret; } -} \ No newline at end of file +} diff --git a/packages/atclient/src/atkey.c b/packages/atclient/src/atkey.c index 36bea17f..83bb6a66 100644 --- a/packages/atclient/src/atkey.c +++ b/packages/atclient/src/atkey.c @@ -2,6 +2,7 @@ #include "atclient/metadata.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" +#include #include #include #include @@ -78,9 +79,10 @@ size_t atclient_atkey_strlen(const atclient_atkey *atkey) { return 0; } - atclient_atkey_type type = atclient_atkey_get_type(atkey); + atclient_atkey_type type = atclient_atkey_get_type(atkey); - if((!atclient_atkey_is_shared_by_initialized(atkey) || strlen(atkey->shared_by) <= 0) && type != ATCLIENT_ATKEY_TYPE_RESERVED_KEY){ + if ((!atclient_atkey_is_shared_by_initialized(atkey) || strlen(atkey->shared_by) <= 0) && + type != ATCLIENT_ATKEY_TYPE_RESERVED_KEY) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey->shared_by is not initialized\n"); return 0; } @@ -103,8 +105,8 @@ size_t atclient_atkey_strlen(const atclient_atkey *atkey) { if (atclient_atkey_is_namespacestr_initialized(atkey) && strlen(atkey->namespace_str) > 0) { len += strlen(".") + strlen(atkey->namespace_str); } - if(atclient_atkey_is_shared_by_initialized(atkey)){ - len += strlen(atkey->shared_by); + if (atclient_atkey_is_shared_by_initialized(atkey)) { + len += strlen(atkey->shared_by); } return len; } diff --git a/packages/atclient/src/atkeys.c b/packages/atclient/src/atkeys.c index 5add317d..dbce3981 100644 --- a/packages/atclient/src/atkeys.c +++ b/packages/atclient/src/atkeys.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/packages/atclient/src/atkeys_file.c b/packages/atclient/src/atkeys_file.c index 1b428429..78635108 100644 --- a/packages/atclient/src/atkeys_file.c +++ b/packages/atclient/src/atkeys_file.c @@ -1,6 +1,7 @@ #include "atclient/atkeys_file.h" #include "atlogger/atlogger.h" -#include +#include +#include #include #include #include @@ -77,6 +78,7 @@ int atclient_atkeys_file_from_path(atclient_atkeys_file *atkeys_file, const char return ret; } +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON int atclient_atkeys_file_from_string(atclient_atkeys_file *atkeys_file, const char *file_string) { int ret = 1; @@ -282,6 +284,9 @@ exit: { return ret; } } +#else +#error "JSON provider not supported" +#endif void atclient_atkeys_file_free(atclient_atkeys_file *atkeys_file) { unset_aes_pkam_public_key_str(atkeys_file); diff --git a/packages/atclient/src/atnotification.c b/packages/atclient/src/atnotification.c index b702a2f3..80a30528 100644 --- a/packages/atclient/src/atnotification.c +++ b/packages/atclient/src/atnotification.c @@ -1,4 +1,5 @@ #include "atclient/atnotification.h" +#include #include #include #include @@ -6,7 +7,7 @@ #define TAG "atnotification" // Json library specific -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON static int atclient_atnotification_from_cjson_node(atclient_atnotification *notification, const cJSON *root); #endif @@ -1581,7 +1582,7 @@ exit: { return ret; } } // Json library specific -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON int atclient_atnotification_from_json_str(atclient_atnotification *notification, const char *json_str) { int ret = 1; /* diff --git a/packages/atclient/src/connection.c b/packages/atclient/src/connection.c index 922d4c3e..faa8a0d2 100644 --- a/packages/atclient/src/connection.c +++ b/packages/atclient/src/connection.c @@ -4,7 +4,8 @@ #include "atclient/connection_hooks.h" #include "atclient/constants.h" #include "atlogger/atlogger.h" -#include +#include +#include #include #include #include @@ -308,7 +309,7 @@ int atclient_connection_write(atclient_connection *ctx, const unsigned char *val memcpy(valuecopy, value, value_len); atlogger_fix_stdout_buffer((char *)valuecopy, value_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, value_len, valuecopy, - reset); + ATCLIENT_RESET); free(valuecopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -421,7 +422,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src, memcpy(srccopy, src, src_len); atlogger_fix_stdout_buffer((char *)srccopy, src_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, strlen((char *)srccopy), - srccopy, reset); + srccopy, ATCLIENT_RESET); free(srccopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -539,7 +540,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src, memcpy(recvcopy, recv, *recv_len); atlogger_fix_stdout_buffer((char *)recvcopy, *recv_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, *recv_len, recvcopy, - reset); + ATCLIENT_RESET); free(recvcopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -732,7 +733,7 @@ int atclient_connection_read(atclient_connection *ctx, unsigned char **value, si memcpy(recvcopy, recv, recv_len); atlogger_fix_stdout_buffer((char *)recvcopy, recv_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, recv_len, recvcopy, - reset); + ATCLIENT_RESET); free(recvcopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, diff --git a/packages/atclient/src/connection_hooks.c b/packages/atclient/src/connection_hooks.c index 0537deb2..7936b327 100644 --- a/packages/atclient/src/connection_hooks.c +++ b/packages/atclient/src/connection_hooks.c @@ -1,9 +1,10 @@ -#include "atclient/connection.h" #include "atclient/connection_hooks.h" +#include "atclient/connection.h" +#include #include -#include -#include #include +#include +#include #define TAG "connection_hooks" @@ -129,28 +130,28 @@ int atclient_connection_hooks_set(atclient_connection *ctx, const atclient_conne atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Received 'NONE' hook as hook set input type\n"); goto exit; case ATCLIENT_CONNECTION_HOOK_TYPE_PRE_READ: { - if((ret = atclient_connection_hooks_set_pre_read(ctx, (atclient_connection_hook *)hook)) != 0) { + if ((ret = atclient_connection_hooks_set_pre_read(ctx, (atclient_connection_hook *)hook)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set pre read hook\n"); goto exit; } break; } case ATCLIENT_CONNECTION_HOOK_TYPE_POST_READ: { - if((ret = atclient_connection_hooks_set_post_read(ctx, (atclient_connection_hook *)hook)) != 0) { + if ((ret = atclient_connection_hooks_set_post_read(ctx, (atclient_connection_hook *)hook)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set post read hook\n"); goto exit; } break; } case ATCLIENT_CONNECTION_HOOK_TYPE_PRE_WRITE: { - if((ret = atclient_connection_hooks_set_pre_write(ctx, (atclient_connection_hook *)hook)) != 0) { + if ((ret = atclient_connection_hooks_set_pre_write(ctx, (atclient_connection_hook *)hook)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set pre write hook\n"); goto exit; } break; } case ATCLIENT_CONNECTION_HOOK_TYPE_POST_WRITE: { - if((ret = atclient_connection_hooks_set_post_write(ctx, (atclient_connection_hook *)hook)) != 0) { + if ((ret = atclient_connection_hooks_set_post_write(ctx, (atclient_connection_hook *)hook)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set post write hook\n"); goto exit; } @@ -389,4 +390,4 @@ exit: { return ret; } static void atclient_connection_hooks_unset_post_write(atclient_connection *ctx) { ctx->hooks->post_write = NULL; atclient_connection_hooks_set_is_post_write_initialized(ctx, false); -} \ No newline at end of file +} diff --git a/packages/atclient/src/encryption_key_helpers.c b/packages/atclient/src/encryption_key_helpers.c index 9fdcaede..812d9786 100644 --- a/packages/atclient/src/encryption_key_helpers.c +++ b/packages/atclient/src/encryption_key_helpers.c @@ -6,6 +6,7 @@ #include "atclient/constants.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" +#include #include #include @@ -83,7 +84,7 @@ int atclient_get_public_encryption_key(atclient *ctx, const char *atsign, char * char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -198,7 +199,8 @@ int atclient_get_shared_encryption_key_shared_by_me(atclient *ctx, const char *r if (!atclient_string_utils_starts_with(response, "data:")) { if (atclient_string_utils_starts_with(response, "error:AT0015-key not found")) { ret = ATCLIENT_ERR_AT0015_KEY_NOT_FOUND; - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_stringutils_starts_with: %d; error:AT0015-key not found\n", ret); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "atclient_stringutils_starts_with: %d; error:AT0015-key not found\n", ret); goto exit; } } @@ -270,7 +272,8 @@ int atclient_get_shared_encryption_key_shared_by_other(atclient *ctx, const char const size_t shared_encryption_key_encrypted_base64_size = 2048; unsigned char shared_encryption_key_encrypted_base64[shared_encryption_key_encrypted_base64_size]; - const size_t shared_encryption_key_encrypted_size = atchops_base64_decoded_size(shared_encryption_key_encrypted_base64_size); + const size_t shared_encryption_key_encrypted_size = + atchops_base64_decoded_size(shared_encryption_key_encrypted_base64_size); unsigned char shared_encryption_key_encrypted[shared_encryption_key_encrypted_size]; /* @@ -356,8 +359,7 @@ exit: { } int atclient_create_shared_encryption_key_pair_for_me_and_other( - atclient *atclient, const char *recipient_atsign, - unsigned char *shared_encryption_key_shared_by_me_with_other) { + atclient *atclient, const char *recipient_atsign, unsigned char *shared_encryption_key_shared_by_me_with_other) { int ret = 1; @@ -369,7 +371,6 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( return ret; } - if (recipient_atsign == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recipient_atsign is NULL\n"); return ret; @@ -404,7 +405,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( unsigned char shared_encryption_key_base64[shared_encryption_key_base64_size]; // encrypted for us - const size_t shared_encryption_key_base64_encrypted_for_us_size = 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant + const size_t shared_encryption_key_base64_encrypted_for_us_size = + 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant unsigned char shared_encryption_key_base64_encrypted_for_us[shared_encryption_key_base64_encrypted_for_us_size]; // encrypted for us (base64 encoded) @@ -414,7 +416,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( shared_encryption_key_base64_encrypted_for_us_base64[shared_encryption_key_base64_encrypted_for_us_base64_size]; // encrypted for them - const size_t shared_encryption_key_base64_encrypted_for_them_size = 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant + const size_t shared_encryption_key_base64_encrypted_for_them_size = + 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant unsigned char shared_encryption_key_base64_encrypted_for_them[shared_encryption_key_base64_encrypted_for_them_size]; // encrypted for them (base64 encoded) @@ -423,7 +426,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( unsigned char shared_encryption_key_base64_encrypted_for_them_base64 [shared_encryption_key_base64_encrypted_for_them_base64_size]; - char *update_cmd_for_us = NULL; // for us (update:shared_key.shared_with@shared_by command) + char *update_cmd_for_us = NULL; // for us (update:shared_key.shared_with@shared_by command) char *update_cmd_for_them = NULL; // for them (update:@shared_with:shared_key@shared_by command) const size_t recv_size = 256; // sufficient to receive response from a update: command @@ -454,7 +457,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( goto exit; } - if ((ret = atchops_rsa_key_populate_public_key(&public_key_struct, public_key_base64, strlen(public_key_base64))) != 0) { + if ((ret = atchops_rsa_key_populate_public_key(&public_key_struct, public_key_base64, strlen(public_key_base64))) != + 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_rsa_key_populate_public_key: %d\n", ret); goto exit; } @@ -486,7 +490,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( memset(shared_encryption_key_base64_encrypted_for_us, 0, sizeof(unsigned char) * shared_encryption_key_base64_encrypted_for_us_size); if ((ret = atchops_rsa_encrypt(&atclient->atkeys.encrypt_public_key, (unsigned char *)shared_encryption_key_base64, - shared_encryption_key_base64_len, shared_encryption_key_base64_encrypted_for_us)) != 0) { + shared_encryption_key_base64_len, shared_encryption_key_base64_encrypted_for_us)) != + 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "failed to encrypt shared enc key for us | atchops_rsa_encrypt: %d\n", ret); goto exit; @@ -531,8 +536,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( */ // 6a. `update:shared_key.recipient_atsign@myatsign ` const size_t update_cmd_for_us_size = strlen("update:shared_key.") + strlen(sharedwith_atsign_without_at) + - strlen(sharedby_atsign_with_at) + strlen(" ") + - shared_encryption_key_base64_encrypted_for_us_base64_len + strlen("\r\n") + 1; + strlen(sharedby_atsign_with_at) + strlen(" ") + + shared_encryption_key_base64_encrypted_for_us_base64_len + strlen("\r\n") + 1; if ((update_cmd_for_us = (char *)malloc(sizeof(char) * update_cmd_for_us_size)) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for update_cmd_for_us\n"); @@ -542,9 +547,9 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( sharedby_atsign_with_at, shared_encryption_key_base64_encrypted_for_us_base64); // 6b. `update:@shared_with:shared_key@shared_by ` - const size_t update_cmd_for_them_size = strlen("update:") + strlen(sharedwith_atsign_with_at) + strlen(":shared_key") + - strlen(sharedby_atsign_with_at) + strlen(" ") + - shared_encryption_key_base64_encrypted_for_them_base64_len + strlen("\r\n") + 1; + const size_t update_cmd_for_them_size = + strlen("update:") + strlen(sharedwith_atsign_with_at) + strlen(":shared_key") + strlen(sharedby_atsign_with_at) + + strlen(" ") + shared_encryption_key_base64_encrypted_for_them_base64_len + strlen("\r\n") + 1; if ((update_cmd_for_them = (char *)malloc(sizeof(char) * update_cmd_for_them_size)) == NULL) { ret = 1; @@ -559,8 +564,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( */ // 7a. Our key - if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_us, update_cmd_for_us_size - 1, - recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_us, + update_cmd_for_us_size - 1, recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -576,8 +581,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( recv_len = 0; // 7b. Their key - if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_them, update_cmd_for_them_size - 1, - recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_them, + update_cmd_for_them_size - 1, recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } diff --git a/packages/atclient/src/metadata.c b/packages/atclient/src/metadata.c index 1df11b21..10c2db88 100644 --- a/packages/atclient/src/metadata.c +++ b/packages/atclient/src/metadata.c @@ -2,6 +2,7 @@ #include "atclient/string_utils.h" #include "atcommons/json.h" #include "atlogger/atlogger.h" +#include #include #include #include @@ -12,7 +13,7 @@ #define TAG "metadata" // Json library specific -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON static int atclient_atkey_metadata_from_cjson_node(atclient_atkey_metadata *metadata, const cJSON *json); #endif @@ -2069,7 +2070,7 @@ exit: { return ret; } } // Json library specific -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON int atclient_atkey_metadata_from_json_str(atclient_atkey_metadata *metadata, const char *metadata_str) { int ret = 1; diff --git a/packages/atclient/src/monitor.c b/packages/atclient/src/monitor.c index cce93425..0533a4f1 100644 --- a/packages/atclient/src/monitor.c +++ b/packages/atclient/src/monitor.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -92,7 +93,8 @@ int atclient_monitor_start(atclient *monitor_conn, const char *regex) { goto exit; } atlogger_fix_stdout_buffer(cmd, cmdsize); - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLK, HCYN, (int)strlen(cmd), cmd, reset); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLK, HCYN, (int)strlen(cmd), cmd, + ATCLIENT_RESET); ret = 0; goto exit; @@ -178,7 +180,7 @@ int atclient_monitor_read(atclient *monitor_conn, atclient *atclient, atclient_m } atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, (int)strlen(buffer), buffer, - reset); + ATCLIENT_RESET); char *messagetype = NULL; char *messagebody = NULL; diff --git a/packages/atclient/src/notify.c b/packages/atclient/src/notify.c index e1158aa8..c8e3e9b3 100644 --- a/packages/atclient/src/notify.c +++ b/packages/atclient/src/notify.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/packages/atclient/src/notify_params.c b/packages/atclient/src/notify_params.c index ad134b36..20730225 100644 --- a/packages/atclient/src/notify_params.c +++ b/packages/atclient/src/notify_params.c @@ -1,6 +1,7 @@ #include "atclient/notify_params.h" #include "atchops/aes.h" #include "atclient/atkey.h" +#include #include #include #include diff --git a/packages/atclient/src/request_options.c b/packages/atclient/src/request_options.c index b5c86fe5..835e31f1 100644 --- a/packages/atclient/src/request_options.c +++ b/packages/atclient/src/request_options.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -75,19 +76,17 @@ atclient_get_atkeys_request_options_set_show_hidden_initialized(atclient_get_atk /* * 5. Authenticate Request Options */ -static void -atclient_authenticate_options_set_atdirectory_host_initialized(atclient_authenticate_options *options, - const bool initialized); +static void atclient_authenticate_options_set_atdirectory_host_initialized(atclient_authenticate_options *options, + const bool initialized); -static void -atclient_authenticate_options_set_atdirectory_port_initialized(atclient_authenticate_options *options, - const bool initialized); +static void atclient_authenticate_options_set_atdirectory_port_initialized(atclient_authenticate_options *options, + const bool initialized); static void atclient_authenticate_options_set_atserver_host_initialized(atclient_authenticate_options *options, - const bool initialized); + const bool initialized); static void atclient_authenticate_options_set_atserver_port_initialized(atclient_authenticate_options *options, - const bool initialized); + const bool initialized); /* * ================= @@ -1344,8 +1343,8 @@ void atclient_delete_request_options_set_skip_shared_by_check(atclient_delete_re /* * 3. Set value and set intiliazed to true */ - memcpy(&(options->skip_shared_by_check), &option, sizeof(option)); atclient_delete_request_options_set_skip_shared_by_check_intitialized(options, true); + memcpy(&(options->skip_shared_by_check), &option, sizeof(option)); } void atclient_delete_request_options_unset_skip_shared_by_check(atclient_delete_request_options *options) { @@ -1772,8 +1771,7 @@ void atclient_authenticate_options_unset_atserver_port(atclient_authenticate_opt atclient_authenticate_options_set_atserver_port_initialized(options, false); } -int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_options *options, - char *atdirectory_host) { +int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_options *options, char *atdirectory_host) { int ret = 1; /* @@ -1811,7 +1809,6 @@ int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_opt memcpy(options->atdirectory_host, atdirectory_host, atdirectory_host_len); options->atdirectory_host[atdirectory_host_len] = '\0'; - ret = 0; goto exit; exit: { return ret; } @@ -1871,7 +1868,7 @@ int atclient_authenticate_options_set_atserver_host(atclient_authenticate_option * 3. Set atserver host */ const size_t atserver_host_size = strlen(atserver_host) + 1; - if((options->atserver_host = (char *)malloc(sizeof(char) * atserver_host_size)) == NULL) { + if ((options->atserver_host = (char *)malloc(sizeof(char) * atserver_host_size)) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_authenticate_options_set_atserver_host: Failed to allocate memory for atserver host\n"); @@ -1920,6 +1917,8 @@ int atclient_authenticate_options_set_atserver_port(atclient_authenticate_option goto exit; exit: { return ret; } +<<<<<<< Conflict 2 of 2 + ++ ++ ++ +Contents of side #1 } static void atclient_authenticate_options_set_atdirectory_host_initialized(atclient_authenticate_options *options, @@ -1928,8 +1927,9 @@ static void atclient_authenticate_options_set_atdirectory_host_initialized(atcli * 1. Validate arguments */ if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_authenticate_options_set_atdirectory_host_initialized: " - "Invalid arguments\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "atclient_authenticate_options_set_atdirectory_host_initialized: " + "Invalid arguments\n"); return; } @@ -1951,8 +1951,9 @@ static void atclient_authenticate_options_set_atdirectory_port_initialized(atcli * 1. Validate arguments */ if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_authenticate_options_set_atdirectory_port_initialized: " - "Invalid arguments\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "atclient_authenticate_options_set_atdirectory_port_initialized: " + "Invalid arguments\n"); return; } @@ -1974,8 +1975,9 @@ static void atclient_authenticate_options_set_atserver_host_initialized(atclient * 1. Validate arguments */ if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_authenticate_options_set_atserver_host_initialized: " - "Invalid arguments\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "atclient_authenticate_options_set_atserver_host_initialized: " + "Invalid arguments\n"); return; } @@ -1997,8 +1999,9 @@ static void atclient_authenticate_options_set_atserver_port_initialized(atclient * 1. Validate arguments */ if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_authenticate_options_set_atserver_port_initialized: " - "Invalid arguments\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "atclient_authenticate_options_set_atserver_port_initialized: " + "Invalid arguments\n"); return; } @@ -2013,3 +2016,8 @@ static void atclient_authenticate_options_set_atserver_port_initialized(atclient ~ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INITIALIZED; } } +% % % % % % % Changes from base to side #2 - +} ++ +} +>>>>>>> Conflict 2 of 2 ends diff --git a/packages/atclient/src/string_utils.c b/packages/atclient/src/string_utils.c index ca9350b1..f18fbde5 100755 --- a/packages/atclient/src/string_utils.c +++ b/packages/atclient/src/string_utils.c @@ -1,4 +1,5 @@ #include "atclient/string_utils.h" +#include #include #include #include diff --git a/packages/atcommons/include/atcommons/json.h b/packages/atcommons/include/atcommons/json.h index 33e4eb0b..7c6e983c 100644 --- a/packages/atcommons/include/atcommons/json.h +++ b/packages/atcommons/include/atcommons/json.h @@ -4,13 +4,29 @@ extern "C" { #endif -#define ATCLIENT_JSON_PROVIDER_CJSON 1 -#define ATCLIENT_JSON_PROVIDER ATCLIENT_JSON_PROVIDER_CJSON +// NOTE: there are two platform specific files: +// - atchops/platform.h +// - atcommons/json.h -#if defined(CONFIG_IDF_TARGET_ESP32) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \ + defined(_WIN32) +#define ATCOMMONS_JSON_PROVIDER_CJSON +#include // IWYU pragma: export + +#elif defined(CONFIG_IDF_TARGET_ESP32) +#define ATCOMMONS_JSON_PROVIDER_CJSON #include // IWYU pragma: export + +#elif defined(TARGET_PORTENTA_H7) +#define ATCOMMONS_JSON_PROVIDER_CJSON +#define ATCOMMONS_JSON_PROVIDER_ARDUINO + +// This file will be injected into the Arduino build by the generator +// search for atsdk_cjson.h.template in the generators directory +#include + #else -#include // IWYU pragma: export +#error "unable to resolve json provider for platform" #endif #ifdef __cplusplus diff --git a/packages/atcommons/src/enroll_namespace.c b/packages/atcommons/src/enroll_namespace.c index e796569a..0a284aa0 100644 --- a/packages/atcommons/src/enroll_namespace.c +++ b/packages/atcommons/src/enroll_namespace.c @@ -48,7 +48,7 @@ int atcommons_enroll_namespace_to_json(char *ns_str, const size_t ns_str_size, s return 0; } -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_list_str_len, const atcommons_enroll_namespace_list_t *ns_list) { if (ns_list == NULL) { @@ -85,10 +85,5 @@ int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_li } #else -int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_list_str_len, - const atcommons_enroll_namespace_list_t *ns_list) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atcommons_enroll_namespace_list_to_json is not implemented for provider %d\n", ATCLIENT_JSON_PROVIDER); - return 1; -} +#error "JSON provider not supported" #endif diff --git a/packages/atcommons/src/enroll_params.c b/packages/atcommons/src/enroll_params.c index 372b66f5..03570cfd 100644 --- a/packages/atcommons/src/enroll_params.c +++ b/packages/atcommons/src/enroll_params.c @@ -37,7 +37,7 @@ int atcommons_enroll_params_init(atcommons_enroll_params_t *ep) { return 0; } -#if ATCLIENT_JSON_PROVIDER == ATCLIENT_JSON_PROVIDER_CJSON +#ifdef ATCOMMONS_JSON_PROVIDER_CJSON int atcommons_enroll_params_to_json(char **json_string, size_t *json_string_len, const atcommons_enroll_params_t *ep) { int ret = 0; @@ -118,9 +118,5 @@ int atcommons_enroll_params_to_json(char **json_string, size_t *json_string_len, return ret; } #else -int atcommons_enroll_params_to_json(char **json_string, size_t *json_string_len, const atcommons_enroll_params_t *ep) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atcommons_enroll_params_to_json is not implemented for provider %d\n", ATCLIENT_JSON_PROVIDER); - return 1; -} +#error "JSON provider not supported" #endif diff --git a/packages/atlogger/include/atlogger/atlogger.h b/packages/atlogger/include/atlogger/atlogger.h index fbce9d2c..499470bc 100644 --- a/packages/atlogger/include/atlogger/atlogger.h +++ b/packages/atlogger/include/atlogger/atlogger.h @@ -15,9 +15,6 @@ enum atlogger_logging_level { ATLOGGER_LOGGING_LEVEL_DEBUG = 100, // everything, very verbose }; -// opts -#define ATLOGGER_ENABLE_TIMESTAMPS 1 - enum atlogger_logging_level atlogger_get_logging_level(); void atlogger_set_logging_level(const enum atlogger_logging_level level); void atlogger_set_opts(int opts); diff --git a/packages/atlogger/src/atlogger.c b/packages/atlogger/src/atlogger.c index cf3ff729..11cee62a 100644 --- a/packages/atlogger/src/atlogger.c +++ b/packages/atlogger/src/atlogger.c @@ -5,7 +5,14 @@ #include #include #include + +#if defined(TARGET_PORTENTA_H7) +#define ATLOGGER_DISABLE_TIMESTAMPS +#endif + +#ifndef ATLOGGER_DISABLE_TIMESTAMPS #include +#endif #define PREFIX_BUFFER_LEN 64 #define INFO_PREFIX "\e[0;32m[INFO]\e[0m" @@ -23,8 +30,6 @@ static int is_ctx_initalized = 0; static atlogger_ctx *atlogger_get_instance() { if (is_ctx_initalized == 0) { - ctx.opts = ATLOGGER_ENABLE_TIMESTAMPS; - is_ctx_initalized = 1; } return &ctx; @@ -60,29 +65,28 @@ static void atlogger_get_prefix(enum atlogger_logging_level logging_level, char } } - atlogger_ctx *ctx = atlogger_get_instance(); +#ifndef ATLOGGER_DISABLE_TIMESTAMPS struct timespec timespec; - if (ctx->opts & ATLOGGER_ENABLE_TIMESTAMPS) { - int res = clock_gettime(CLOCK_REALTIME, ×pec); - - if (res == 0) { - res = strftime(prefix + off, PREFIX_BUFFER_LEN - off, " %F %T", - gmtime(×pec.tv_sec)); // format accurate to the second - if (res != 0) { - off += res; - res = 0; - } + int res = clock_gettime(CLOCK_REALTIME, ×pec); + + if (res == 0) { + res = strftime(prefix + off, PREFIX_BUFFER_LEN - off, " %F %T", + gmtime(×pec.tv_sec)); // format accurate to the second + if (res != 0) { + off += res; + res = 0; } - if (res == 0) { - snprintf(prefix + off, PREFIX_BUFFER_LEN - off, ".%09lu", timespec.tv_nsec); - off += strlen(prefix + off); - } - - off -= 3; - snprintf(prefix + off, PREFIX_BUFFER_LEN - off, " |"); - off += 2; - prefix[off] = '\0'; } + if (res == 0) { + snprintf(prefix + off, PREFIX_BUFFER_LEN - off, ".%09lu", timespec.tv_nsec); + off += strlen(prefix + off); + } +#endif + + off -= 3; + snprintf(prefix + off, PREFIX_BUFFER_LEN - off, " |"); + off += 2; + prefix[off] = '\0'; } enum atlogger_logging_level atlogger_get_logging_level() {