diff --git a/libs/libblade/src/blade_restmgr.c b/libs/libblade/src/blade_restmgr.c index 9c241e3ef7..69d4551017 100644 --- a/libs/libblade/src/blade_restmgr.c +++ b/libs/libblade/src/blade_restmgr.c @@ -106,9 +106,9 @@ void blade_restmgr_handle_exit_context(const struct mg_context *ctx); static void blade_restmgr_cleanup(void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type) { - blade_restmgr_t *brestmgr = (blade_restmgr_t *)ptr; + //blade_restmgr_t *brestmgr = (blade_restmgr_t *)ptr; - ks_assert(brestmgr); + //ks_assert(brestmgr); switch (action) { case KS_MPCL_ANNOUNCE: diff --git a/libs/libblade/switchblade/switchblade.c b/libs/libblade/switchblade/switchblade.c index e18dff0b80..5c4b89c70e 100644 --- a/libs/libblade/switchblade/switchblade.c +++ b/libs/libblade/switchblade/switchblade.c @@ -140,15 +140,23 @@ void command_quit(blade_handle_t *bh, char *args) int rest_service_test(blade_restmgr_t *brestmgr, struct mg_connection *conn, const char **captures) { const struct mg_request_info *info = NULL; + cJSON *json = NULL; + cJSON *json_captures = NULL; ks_sb_t *sb = NULL; + json = cJSON_CreateObject(); + ks_sb_create(&sb, NULL, 0); info = mg_get_request_info(conn); - ks_sb_printf(sb, "Method: %s\n", info->request_method); + cJSON_AddStringToObject(json, "method", info->request_method); - for (int i = 0; captures[i]; ++i) ks_sb_printf(sb, "Capture #%d: %s\n", i, captures[i]); + cJSON_AddItemToObject(json, "captures", (json_captures = cJSON_CreateArray())); + + for (int i = 0; captures[i]; ++i) cJSON_AddItemToArray(json_captures, cJSON_CreateString(captures[i])); + + ks_sb_json(sb, json); mg_printf(conn, "HTTP/1.1 200 OK\r\n" @@ -161,6 +169,8 @@ int rest_service_test(blade_restmgr_t *brestmgr, struct mg_connection *conn, con ks_sb_destroy(&sb); + cJSON_Delete(json); + return 200; } diff --git a/libs/libblade/switchblade/switchblade.vcxproj b/libs/libblade/switchblade/switchblade.vcxproj index de2fb48c5f..0eb09f50e8 100644 --- a/libs/libblade/switchblade/switchblade.vcxproj +++ b/libs/libblade/switchblade/switchblade.vcxproj @@ -182,7 +182,7 @@ MaxSpeed true true - _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions) true $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories) 4090 @@ -193,6 +193,7 @@ true true true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;rpcrt4.lib;winmm.lib;%(AdditionalDependencies) diff --git a/libs/libblade/test/testcli.vcxproj b/libs/libblade/test/testcli.vcxproj index 381d842a12..a0c687a67e 100644 --- a/libs/libblade/test/testcli.vcxproj +++ b/libs/libblade/test/testcli.vcxproj @@ -182,7 +182,7 @@ MaxSpeed true true - _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions) true $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories) 4090 @@ -193,6 +193,7 @@ true true true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;rpcrt4.lib;winmm.lib;%(AdditionalDependencies) diff --git a/libs/libblade/test/testcon.vcxproj b/libs/libblade/test/testcon.vcxproj index ffa9af660d..513324ec69 100644 --- a/libs/libblade/test/testcon.vcxproj +++ b/libs/libblade/test/testcon.vcxproj @@ -182,7 +182,7 @@ MaxSpeed true true - _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions) true $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories) 4090 @@ -193,6 +193,7 @@ true true true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;rpcrt4.lib;winmm.lib;%(AdditionalDependencies) diff --git a/libs/libks/src/include/ks_sb.h b/libs/libks/src/include/ks_sb.h index b9b5f1863f..e82da02ca0 100644 --- a/libs/libks/src/include/ks_sb.h +++ b/libs/libks/src/include/ks_sb.h @@ -48,6 +48,7 @@ KS_DECLARE(ks_status_t) ks_sb_accommodate(ks_sb_t *sb, ks_size_t len); KS_DECLARE(ks_status_t) ks_sb_append(ks_sb_t *sb, const char *str); KS_DECLARE(ks_status_t) ks_sb_append_ex(ks_sb_t *sb, const char *str, ks_size_t len); KS_DECLARE(ks_status_t) ks_sb_printf(ks_sb_t *sb, const char *fmt, ...); +KS_DECLARE(ks_status_t) ks_sb_json(ks_sb_t *sb, const cJSON *json); KS_END_EXTERN_C diff --git a/libs/libks/src/ks_sb.c b/libs/libks/src/ks_sb.c index acdbb594c0..19219b372d 100644 --- a/libs/libks/src/ks_sb.c +++ b/libs/libks/src/ks_sb.c @@ -191,6 +191,28 @@ done: return ret; } +KS_DECLARE(ks_status_t) ks_sb_json(ks_sb_t *sb, const cJSON *json) +{ + ks_status_t ret = KS_STATUS_SUCCESS; + char *str = NULL; + + ks_assert(sb); + ks_assert(json); + + str = cJSON_Print(json); + if (!str) { + ret = KS_STATUS_FAIL; + goto done; + } + + ks_sb_append(sb, str); + +done: + if (str) free(str); + + return ret; +} + /* For Emacs: * Local Variables: