FS-10690: [libblade] [libks] Added json wrapper to string builder. Fixed an issue with the "Release" build for x64, currently only Debug x64 and Release x64 build correctly, more will be fixed with other project updates soon.
This commit is contained in:
parent
4ba8c7dc48
commit
1991ce4817
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
|
@ -193,6 +193,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -182,7 +182,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
|
@ -193,6 +193,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -182,7 +182,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;KS_DECLARE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4090</DisableSpecificWarnings>
|
||||
|
@ -193,6 +193,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue