Skip to content
Snippets Groups Projects
Commit b43dfc58 authored by armatusmiles's avatar armatusmiles
Browse files

[*] change response format in dap_enc_http to json

parent 12863e2c
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@
#include "dap_enc_base64.h"
#include "dap_enc_msrln.h"
#include "http_status_code.h"
#include <json-c/json.h>
#define LOG_TAG "dap_enc_http"
......@@ -46,9 +47,23 @@ int enc_http_init()
void enc_http_deinit()
{
}
static void _enc_http_write_reply(struct dap_http_simple *cl_st,
const char* encrypt_id,
const char* encrypt_msg)
{
struct json_object *jobj = json_object_new_object();
json_object_object_add(jobj, "encrypt_id", json_object_new_string(encrypt_id));
json_object_object_add(jobj, "encrypt_msg", json_object_new_string(encrypt_msg));
const char* json_str = json_object_to_json_string(jobj);
dap_http_simple_reply(cl_st, (void*) json_str,
(size_t) strlen(json_str));
json_object_put(jobj);
}
void dap_enc_http_json_response_format_enable(bool);
/**
* @brief enc_http_proc Enc http interface
* @param cl_st HTTP Simple client instance
......@@ -89,7 +104,7 @@ void enc_http_proc(struct dap_http_simple *cl_st, void * arg)
size_t encrypt_id_size = dap_enc_base64_encode(key_ks->id, DAP_ENC_KS_KEY_ID_SIZE, encrypt_id, DAP_ENC_DATA_TYPE_B64);
encrypt_id[encrypt_id_size] = '\0';
dap_http_simple_reply_f(cl_st, "%s %s", encrypt_id, encrypt_msg);
_enc_http_write_reply(cl_st, encrypt_id, encrypt_msg);
dap_enc_key_delete(msrln_key);
......
......@@ -62,8 +62,8 @@ typedef struct enc_http_delegate{
struct dap_http_client *http;
} enc_http_delegate_t;
int enc_http_init();
void enc_http_deinit();
int enc_http_init(void);
void enc_http_deinit(void);
size_t enc_http_reply(enc_http_delegate_t * dg, void * data, size_t data_size);
size_t enc_http_reply_f(enc_http_delegate_t * dg, const char * data, ...);
......
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