2025-08-19 11:40:27 +03:00
|
|
|
#include "response_builder.h"
|
|
|
|
|
|
|
|
|
|
#include "utils/json_writer.h"
|
|
|
|
|
#include "utils/logger.h"
|
|
|
|
|
|
|
|
|
|
static const char* DEFAULT_ERROR_CODE = "INTERNAL_ERROR";
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
build_response_from_error_code(const char *error_code)
|
|
|
|
|
{
|
|
|
|
|
JsonBuilder *jbuilder;
|
|
|
|
|
char *response;
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_error_code enter");
|
|
|
|
|
|
|
|
|
|
if (error_code == NULL) {
|
|
|
|
|
error_code = DEFAULT_ERROR_CODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jbuilder = json_builder_new();
|
|
|
|
|
if (jbuilder == NULL) {
|
|
|
|
|
LOG_ERROR("build_response_from_error_code. json_builder_new failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_begin_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("build_response_from_error_code. json_builder_begin_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_write_member_string(jbuilder, "error_code", error_code)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_end_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("build_response_from_error_code. json_builder_end_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = json_write_to_str(jbuilder);
|
|
|
|
|
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_error_code exit");
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (jbuilder != NULL) {
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
}
|
|
|
|
|
LOG_ERROR("build_response_from_error_code exit with error");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
build_response_from_signature(const char *signature, const char *state)
|
|
|
|
|
{
|
|
|
|
|
JsonBuilder *jbuilder;
|
|
|
|
|
char *response;
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_signature enter");
|
|
|
|
|
|
|
|
|
|
jbuilder = json_builder_new();
|
|
|
|
|
if (jbuilder == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_new failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_begin_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_begin_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_write_member_string(jbuilder, "signature", signature)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_write_member_string(jbuilder, "state", state)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_end_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_end_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = json_write_to_str(jbuilder);
|
|
|
|
|
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_signature exit");
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (jbuilder != NULL) {
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
}
|
|
|
|
|
LOG_ERROR("build_response_from_signature exit with error");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2025-08-29 13:03:06 +03:00
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
build_response_from_signer_cert(const cert_info_t *cert_info)
|
|
|
|
|
{
|
|
|
|
|
JsonBuilder *jbuilder;
|
|
|
|
|
char *response;
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_signer_cert enter");
|
|
|
|
|
|
|
|
|
|
jbuilder = json_builder_new();
|
|
|
|
|
if (jbuilder == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_new failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_begin_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_begin_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_write_member_string(jbuilder, "signer_subject", cert_info->subject)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_write_member_string(jbuilder, "issuer_name", cert_info->issuer)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json_builder_end_object(jbuilder) == NULL) {
|
|
|
|
|
LOG_ERROR("json_builder_end_object failed");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = json_write_to_str(jbuilder);
|
|
|
|
|
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
|
|
|
|
|
LOG_TRACE("build_response_from_signer_cert exit");
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (jbuilder != NULL) {
|
|
|
|
|
g_object_unref(jbuilder);
|
|
|
|
|
}
|
|
|
|
|
LOG_ERROR("build_response_from_signer_cert exit with error");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|