Skip to content
Snippets Groups Projects
Commit 30ec57d3 authored by daniil.frolov's avatar daniil.frolov Committed by Constantin P.
Browse files

Hotfix 14724

parent 2c0c1583
No related branches found
No related tags found
1 merge request!482Hotfix 14724
......@@ -45,7 +45,7 @@ static inline dap_guuid_t dap_guuid_new()
DAP_STATIC_INLINE dap_guuid_t dap_guuid_compose(uint64_t a_net_id, uint64_t a_service_id)
{
return (dap_guuid_t){ .net_id = a_net_id, .srv_id = a_service_id };
return (dap_guuid_t){{ .net_id = a_net_id, .srv_id = a_service_id }};
}
dap_guuid_str_t dap_guuid_to_hex_str_(dap_guuid_t a_guuid);
#define dap_guuid_to_hex_str(guid) dap_guuid_to_hex_str_(guid).s
......
......@@ -18,3 +18,12 @@ target_include_directories(${PROJECT_NAME} INTERFACE . include/)
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} dap_core dap_json-c dap_client dap_cli_server)
if(INSTALL_DAP_SDK)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${JSON_RPC_CORE_HEADERS}")
INSTALL(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib/dap/net/server/json_rpc/rpc_core/
ARCHIVE DESTINATION lib/dap/net/server/json_rpc/rpc_core/
PUBLIC_HEADER DESTINATION include/dap/net/server/json_rpc/rpc_core/
)
endif()
\ No newline at end of file
......@@ -136,6 +136,8 @@ dap_json_rpc_type_param_t dap_json_rpc_params_get_type_param(dap_json_rpc_params
*/
dap_json_rpc_params_t * dap_json_rpc_params_create_from_array_list(json_object *a_array_list);
dap_json_rpc_params_t * dap_json_rpc_params_create_from_subcmd_and_args(json_object *a_subcmd, json_object *a_args, const char* a_method);
/**
* Get a JSON string representation of dap_json_rpc_params_t.
*
......
#include "dap_json_rpc_params.h"
#include "dap_string.h"
#define LOG_TAG "dap_json_rpc_params"
......@@ -118,6 +119,83 @@ dap_json_rpc_params_t * dap_json_rpc_params_create_from_array_list(json_object *
return params;
}
dap_json_rpc_params_t * dap_json_rpc_params_create_from_subcmd_and_args(json_object *a_subcmd, json_object *a_args, const char* a_method)
{
if (a_method == NULL )
return NULL;
dap_json_rpc_params_t *params = dap_json_rpc_params_create();
dap_string_t * l_str_tmp = dap_string_new("");
// add subcmd to params
dap_string_append_printf(l_str_tmp, "%s;", a_method);
if(a_subcmd){
enum json_type l_subcmd_type = json_object_get_type(a_subcmd);
if(l_subcmd_type == json_type_array){
int length = json_object_array_length(a_subcmd);
for (int i = 0; i < length; i++){
json_object *jobj = json_object_array_get_idx(a_subcmd, i);
json_type jobj_type = json_object_get_type(jobj);
if (jobj_type != json_type_string){
log_it(L_ERROR, "Bad subcommand type");
dap_string_free(l_str_tmp, true);
return NULL;
}
dap_string_append_printf(l_str_tmp, "%s;", json_object_get_string(jobj));
}
} else if (l_subcmd_type == json_type_string) {
dap_string_append_printf(l_str_tmp, "%s;", json_object_get_string( a_subcmd));
} else {
return log_it(L_CRITICAL, "Subcomand must be array or string type."), dap_string_free(l_str_tmp, true), NULL;
}
}
if (a_args){
json_object_object_foreach(a_args, key, val){
const char *l_key_str = NULL;
const char *l_val_str = NULL;
enum json_type l_arg_type = json_object_get_type(val);
if(l_arg_type == json_type_string ||
l_arg_type == json_type_null || l_arg_type == json_type_object) {
l_key_str = key;
l_val_str = json_object_get_string(val);
} else if(l_arg_type == json_type_array){
int length = json_object_array_length(val);
dap_string_append_printf(l_str_tmp, "-%s;", key);
for (int i = 0; i < length; i++){
json_object *jobj = json_object_array_get_idx(val, i);
json_type jobj_type = json_object_get_type(jobj);
if (jobj_type != json_type_string){
log_it(L_ERROR, "Bad subcommand type");
dap_string_free(l_str_tmp, true);
return NULL;
}
dap_string_append_printf(l_str_tmp, "%s%s", json_object_get_string(jobj), i == length - 1 ? ";" : ",");
}
continue;
}
if(l_key_str){
dap_string_append_printf(l_str_tmp, "-%s;%s;", l_key_str, l_val_str ? l_val_str : "");
} else {
return log_it(L_CRITICAL, "Bad argument!"), dap_string_free(l_str_tmp, true), NULL;
}
}
}
l_str_tmp->str[strlen(l_str_tmp->str) - 1] = '\0';
dap_json_rpc_params_add_data(params, l_str_tmp->str, TYPE_PARAM_STRING);
dap_string_free(l_str_tmp, true);
return params;
}
char *dap_json_rpc_params_get_string_json(dap_json_rpc_params_t * a_params)
{
dap_return_val_if_fail(a_params, NULL);
......
......@@ -236,7 +236,9 @@ dap_json_rpc_request_t *dap_json_rpc_request_from_json(const char *a_data)
json_object *jobj = json_tokener_parse_verbose(a_data, &jterr),
*jobj_id = NULL,
*jobj_method = NULL,
*jobj_params = NULL;
*jobj_params = NULL,
*jobj_subcmd = NULL,
*l_arguments_obj = NULL;
if (jterr == json_tokener_success)
do {
if (json_object_object_get_ex(jobj, "id", &jobj_id))
......@@ -253,13 +255,21 @@ dap_json_rpc_request_t *dap_json_rpc_request_from_json(const char *a_data)
break;
}
if (json_object_object_get_ex(jobj, "params", &jobj_params))
json_object_object_get_ex(jobj, "params", &jobj_params);
json_object_object_get_ex(jobj, "subcommand", &jobj_subcmd);
json_object_object_get_ex(jobj, "arguments", &l_arguments_obj);
if (jobj_params)
request->params = dap_json_rpc_params_create_from_array_list(jobj_params);
else {
log_it(L_ERROR, "Error parse JSON string, Can't find array params for request with id: %" DAP_UINT64_FORMAT_U, request->id);
break;
}
else
request->params = dap_json_rpc_params_create_from_subcmd_and_args(jobj_subcmd, l_arguments_obj, request->method);
json_object_put(jobj);
if (!request->params){
dap_json_rpc_params_remove_all(request->params);
DAP_DEL_MULTY(request->method, request);
return NULL;
}
return request;
} while (0);
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment