Commit 56390d90 authored by xpetrak2's avatar xpetrak2 Committed by xHire
Browse files

Message coding

parent ab5a6c06
......@@ -17,7 +17,7 @@ AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror])
AC_CONFIG_FILES([Makefile])
dnl Compiler flags
AM_CFLAGS="-std=c89 -pedantic -Wall -Wextra -pipe"
AM_CFLAGS="-std=c99 -pedantic -Wall -Wextra -pipe"
dnl Checks for programs.
dnl C compiler
......
......@@ -57,7 +57,7 @@ enum payload_type {
* encrypted message data holder.
*/
typedef struct s_encrypted {
char *payload; /**< Encrypted message content. */
char *payload; /**< Encrypted message content (hex-encoded). */
} encrypted_t;
/**
......
......@@ -118,15 +118,11 @@ enum process_message_result
enum process_message_result ret;
/* decode JSON message; if parsing JSON message into message_t failed */
if (decode_message(json_message, &message, &json_message_body)) {
ret = decode_message(json_message, &message, &json_message_body);
if (ret != PMR_DONE) {
log_debug("process_encoded_message - decoding a received "
"message has failed. The message:\n%s", json_message);
return PMR_ERR_PARSING;
}
if (message.version != PROTOCOL_VERSION) {
free(json_message_body);
return PMR_ERR_VERSION;
"message has failed.");
return ret;
}
/* integrity verification part; if the message integrity is violated */
......@@ -460,7 +456,7 @@ static int process_encrypted(const encrypted_t *encrypted_payload,
{
void *data;
char *json_payload;
char *json_payload_data;
json_t *json_payload_data;
enum trade_step next_step;
enum payload_type payload_type;
int res;
......@@ -472,14 +468,14 @@ static int process_encrypted(const encrypted_t *encrypted_payload,
identity->keypair.secret_key,
&json_payload)) {
log_debug("process_encrypted - decrypting message payload has "
"failed. Payload:\n%s", encrypted_payload->payload);
"failed. Payload:\n%s\n", encrypted_payload->payload);
return 1;
}
if (decode_payload_type(json_payload,
&payload_type,
&json_payload_data)) {
log_debug("process_encrypted - decoding decrypted payload "
"has failed. Payload:\n%s", json_payload);
"has failed. Payload:\n%s\n", json_payload);
free(json_payload);
return 1;
}
......@@ -493,7 +489,7 @@ static int process_encrypted(const encrypted_t *encrypted_payload,
payload_type,
&data)) {
log_debug("process_encrypted - decoding payload's data "
"has failed. Data:\n%s", json_payload_data);
"has failed. Data:\n%s\n", json_payload);
free(json_payload_data);
return 1;
}
......
This diff is collapsed.
/*
* Coincer
* Copyright (C) 2017-2018 Coincer Developers
* Copyright (C) 2017-2019 Coincer Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -19,7 +19,10 @@
#ifndef JSON_PARSER_H
#define JSON_PARSER_H
#include <jansson.h>
#include "daemon_messages.h"
#include "daemon_messages_processor.h" /* enum process_message_result */
#include "trade.h"
/* the order of these strings must be the same as the order of enums within
......@@ -46,20 +49,21 @@ static const char *payload_type_str[] = {
"trade.reject"
};
int decode_message(const char *json_message,
message_t *message,
char **json_body);
enum process_message_result
decode_message(const char *json_message,
message_t *message,
char **json_body);
int decode_message_body(const char *json_body,
message_body_t *body,
char **json_data);
json_t **json_data);
int decode_message_data(const char *json_data,
const enum message_type type,
void **data);
int decode_payload_type(const char *json_payload,
enum payload_type *type,
char **json_data);
int decode_payload_data(const char *json_data,
json_t **json_data);
int decode_payload_data(const json_t *json_data,
enum payload_type type,
void **data);
int decode_trade_execution(const char *json_data,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment