Skip to content

Commit

Permalink
Use JSON module instead of cJSON (#155)
Browse files Browse the repository at this point in the history
Modifies the code to use the JSON module in AWS C Common instead of directly
using cJSON. This prevents duplicate copies/includes of cJSON, as well as
helping reduce additional dependencies and code duplication.

Commit Log:
* Adjusted to use JSON module instead of cJSON
* Minor fixes to code formatting
* Modified to work with latest aws-c-common JSON module changes
* Adjusted based on JSON module changes, removed use of cJSON in test
* Clang-format fixes
* Adjustments to latest JSON module
* Fixed formatting and JSON include statements being incorrect
* Adjustments based on latest JSON module changes after code review
* Changes to work with latest JSON module changes
* Updated to work with latest JSON module change
* Updated Sigv4 test to use latest JSON module changes
* Further signv4 test adjustments
* More test adjustments to fit JSON changes
* Hopefully last change needed to fix sigv4 test
* Sigv4 fix - fixed treating a non-pointer like a pointer
* Credentials utils fixes
* Added some print statements to better find where the new error is coming from
* Added JSON module initializing in Credentials Provider Tests, since common.c does not initialize it in these tests
* Added missing JSON module init and cleanup in other tests
* Fixed crashes in imds client due to aws byte cursor passing with JSON
* Clang format fix and code comment fix
* Fix for uninitialized local variable warning
* Removed calling json module init in aws_imds_client_test
* Removed remaining JSON module inits and cleanups
* Init AWS auth library in credentials provider test
* Added Auth library init to credentials provider test (needed to init JSON)
  • Loading branch information
TwistedTwigleg committed Apr 15, 2022
1 parent aaf4c1f commit 5f49a0c
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 6,452 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@ file(GLOB AWS_AUTH_PRIVATE_HEADERS
"include/aws/auth/private/*.h"
)

file(GLOB AWS_AUTH_EXTERNAL_HEADERS
"include/aws/auth/external/*.h"
)

file(GLOB AWS_AUTH_ROOT_SRC
"source/*.c"
)

file(GLOB AWS_AUTH_EXTERNAL_SRC
"source/external/*.c"
)

if (WIN32)
if (MSVC)
source_group("Header Files\\aws\\auth" FILES ${AWS_AUTH_HEADERS})
Expand All @@ -74,12 +66,10 @@ endif()
file(GLOB AUTH_HEADERS
${AWS_AUTH_ROOT_HEADERS}
${AWS_AUTH_PRIVATE_HEADERS}
${AWS_AUTH_EXTERNAL_HEADERS}
)

file(GLOB AUTH_SRC
${AWS_AUTH_ROOT_SRC}
${AWS_AUTH_EXTERNAL_SRC}
)

add_library(${PROJECT_NAME} ${LIBTYPE} ${AUTH_HEADERS} ${AUTH_SRC})
Expand Down
294 changes: 0 additions & 294 deletions include/aws/auth/external/cJSON.h

This file was deleted.

8 changes: 4 additions & 4 deletions include/aws/auth/private/credentials_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <aws/auth/auth.h>
#include <aws/auth/credentials.h>
#include <aws/auth/external/cJSON.h>
#include <aws/common/json.h>
#include <aws/http/connection_manager.h>

struct aws_http_connection;
Expand Down Expand Up @@ -135,13 +135,13 @@ struct aws_parse_credentials_from_json_doc_options {
* performe a case insensitive search.
*/
AWS_AUTH_API
struct aws_credentials *aws_parse_credentials_from_cjson_object(
struct aws_credentials *aws_parse_credentials_from_aws_json_object(
struct aws_allocator *allocator,
struct cJSON *document_root,
struct aws_json_value *document_root,
const struct aws_parse_credentials_from_json_doc_options *options);

/**
* This API is similar to aws_parse_credentials_from_cjson_object,
* This API is similar to aws_parse_credentials_from_aws_json_object,
* except it accpets a char buffer json document as it's input.
*/
AWS_AUTH_API
Expand Down
15 changes: 1 addition & 14 deletions source/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
#include <aws/auth/auth.h>

#include <aws/auth/external/cJSON.h>
#include <aws/auth/private/aws_signing.h>

#include <aws/cal/cal.h>
Expand All @@ -14,6 +13,7 @@
#include <aws/sdkutils/sdkutils.h>

#include <aws/common/error.h>
#include <aws/common/json.h>

#define AWS_DEFINE_ERROR_INFO_AUTH(CODE, STR) AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-auth")

Expand Down Expand Up @@ -114,14 +114,6 @@ static struct aws_log_subject_info_list s_auth_log_subject_list = {
static bool s_library_initialized = false;
static struct aws_allocator *s_library_allocator = NULL;

static void *s_cJSONAlloc(size_t sz) {
return aws_mem_acquire(s_library_allocator, sz);
}

static void s_cJSONFree(void *ptr) {
aws_mem_release(s_library_allocator, ptr);
}

void aws_auth_library_init(struct aws_allocator *allocator) {
if (s_library_initialized) {
return;
Expand All @@ -141,11 +133,6 @@ void aws_auth_library_init(struct aws_allocator *allocator) {
aws_register_log_subject_info_list(&s_auth_log_subject_list);

AWS_FATAL_ASSERT(aws_signing_init_signing_tables(allocator) == AWS_OP_SUCCESS);

struct cJSON_Hooks allocation_hooks = {.malloc_fn = s_cJSONAlloc, .free_fn = s_cJSONFree};

cJSON_InitHooks(&allocation_hooks);

s_library_initialized = true;
}

Expand Down
Loading

0 comments on commit 5f49a0c

Please sign in to comment.