msg: fix some problem
Type: fix Signed-off-by: staylightblow8 <liudf0716@gmail.com>
This commit is contained in:
334
msg.c
334
msg.c
@@ -20,8 +20,8 @@
|
||||
\********************************************************************/
|
||||
|
||||
/** @file msg.c
|
||||
@brief xfrpc client msg related
|
||||
@author Copyright (C) 2016 Dengfeng Liu <liu_df@qq.com>
|
||||
@brief xfrpc client msg related
|
||||
@author Copyright (C) 2016 Dengfeng Liu <liu_df@qq.com>
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@@ -41,44 +41,45 @@
|
||||
#include "client.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define JSON_MARSHAL_TYPE(jobj,key,jtype,item) \
|
||||
json_object_object_add(jobj, key, json_object_new_##jtype((item)));
|
||||
#define JSON_MARSHAL_TYPE(jobj, key, jtype, item) \
|
||||
json_object_object_add(jobj, key, json_object_new_##jtype((item)));
|
||||
|
||||
#define SAFE_JSON_STRING(str_target) \
|
||||
str_target?str_target:"\0"
|
||||
str_target ? str_target : "\0"
|
||||
|
||||
const char msg_types[] = {TypeLogin,
|
||||
TypeLoginResp,
|
||||
TypeNewProxy,
|
||||
TypeNewProxyResp,
|
||||
TypeNewWorkConn,
|
||||
TypeReqWorkConn,
|
||||
TypeStartWorkConn,
|
||||
TypePing,
|
||||
TypePong,
|
||||
TypeUDPPacket};
|
||||
const char msg_types[] = {TypeLogin,
|
||||
TypeLoginResp,
|
||||
TypeNewProxy,
|
||||
TypeNewProxyResp,
|
||||
TypeNewWorkConn,
|
||||
TypeReqWorkConn,
|
||||
TypeStartWorkConn,
|
||||
TypePing,
|
||||
TypePong,
|
||||
TypeUDPPacket};
|
||||
|
||||
char *
|
||||
calc_md5(const char *data, int datalen)
|
||||
{
|
||||
unsigned char digest[16] = {0};
|
||||
char *out = (char*)malloc(33);
|
||||
char *out = (char *)malloc(33);
|
||||
assert(out);
|
||||
|
||||
MD5_CTX md5;
|
||||
|
||||
|
||||
MD5_Init(&md5);
|
||||
MD5_Update(&md5, data, datalen);
|
||||
MD5_Final(digest, &md5);
|
||||
|
||||
for (int n = 0; n < 16; ++n) {
|
||||
snprintf(&(out[n*2]), 3, "%02x", (unsigned int)digest[n]);
|
||||
}
|
||||
|
||||
return out;
|
||||
for (int n = 0; n < 16; ++n)
|
||||
{
|
||||
snprintf(&(out[n * 2]), 3, "%02x", (unsigned int)digest[n]);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
fill_custom_domains(struct json_object *j_ctl_req, const char *custom_domains)
|
||||
{
|
||||
struct json_object *jarray_cdomains = json_object_new_array();
|
||||
@@ -86,7 +87,8 @@ fill_custom_domains(struct json_object *j_ctl_req, const char *custom_domains)
|
||||
char *tmp = strdup(custom_domains);
|
||||
assert(tmp);
|
||||
char *tok = tmp, *end = tmp;
|
||||
while (tok != NULL) {
|
||||
while (tok != NULL)
|
||||
{
|
||||
strsep(&end, ",");
|
||||
|
||||
int dname_len = strlen(tok) + 1;
|
||||
@@ -99,15 +101,16 @@ fill_custom_domains(struct json_object *j_ctl_req, const char *custom_domains)
|
||||
tok = end;
|
||||
}
|
||||
SAFE_FREE(tmp);
|
||||
|
||||
|
||||
json_object_object_add(j_ctl_req, "custom_domains", jarray_cdomains);
|
||||
}
|
||||
|
||||
struct work_conn *
|
||||
new_work_conn() {
|
||||
new_work_conn()
|
||||
{
|
||||
struct work_conn *work_c = calloc(1, sizeof(struct work_conn));
|
||||
assert(work_c);
|
||||
if (work_c)
|
||||
if (work_c)
|
||||
work_c->run_id = NULL;
|
||||
|
||||
return work_c;
|
||||
@@ -122,28 +125,31 @@ get_auth_key(const char *token, long int *timestamp)
|
||||
snprintf(seed, 128, "%s%ld", token, *timestamp);
|
||||
else
|
||||
snprintf(seed, 128, "%ld", *timestamp);
|
||||
|
||||
|
||||
return calc_md5(seed, strlen(seed));
|
||||
}
|
||||
|
||||
size_t
|
||||
size_t
|
||||
login_request_marshal(char **msg)
|
||||
{
|
||||
size_t nret = 0;
|
||||
struct json_object *j_login_req = json_object_new_object();
|
||||
if (j_login_req == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
struct login *lg = get_common_login_config();
|
||||
if (!lg)
|
||||
{
|
||||
json_object_put(j_login_req);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
SAFE_FREE(lg->privilege_key);
|
||||
struct common_conf *cf = get_common_config();
|
||||
char *auth_key = get_auth_key(cf->auth_token, &lg->timestamp);
|
||||
lg->privilege_key = strdup(auth_key);
|
||||
assert(lg->privilege_key);
|
||||
|
||||
|
||||
JSON_MARSHAL_TYPE(j_login_req, "version", string, lg->version);
|
||||
JSON_MARSHAL_TYPE(j_login_req, "hostname", string, SAFE_JSON_STRING(lg->hostname));
|
||||
JSON_MARSHAL_TYPE(j_login_req, "os", string, lg->os);
|
||||
@@ -155,10 +161,11 @@ login_request_marshal(char **msg)
|
||||
JSON_MARSHAL_TYPE(j_login_req, "run_id", string, SAFE_JSON_STRING(lg->run_id));
|
||||
JSON_MARSHAL_TYPE(j_login_req, "pool_count", int, lg->pool_count);
|
||||
json_object_object_add(j_login_req, "metas", NULL);
|
||||
|
||||
|
||||
const char *tmp = NULL;
|
||||
tmp = json_object_to_json_string(j_login_req);
|
||||
if (tmp && strlen(tmp) > 0) {
|
||||
if (tmp && strlen(tmp) > 0)
|
||||
{
|
||||
nret = strlen(tmp);
|
||||
*msg = strdup(tmp);
|
||||
assert(*msg);
|
||||
@@ -168,54 +175,66 @@ login_request_marshal(char **msg)
|
||||
return nret;
|
||||
}
|
||||
|
||||
int
|
||||
new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
int new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
int nret = 0;
|
||||
int nret = 0;
|
||||
char *path = NULL;
|
||||
char *delimiter = ",";
|
||||
char *save = NULL;
|
||||
struct json_object *j_np_req = json_object_new_object();
|
||||
if ( ! j_np_req)
|
||||
if (!j_np_req)
|
||||
return 0;
|
||||
|
||||
|
||||
JSON_MARSHAL_TYPE(j_np_req, "proxy_name", string, np_req->proxy_name);
|
||||
// if proxy_type is socks5, set the proxy_type to tcp
|
||||
if (strcmp(np_req->proxy_type, "socks5") == 0 || strcmp(np_req->proxy_type, "mstsc") == 0) {
|
||||
if (strcmp(np_req->proxy_type, "socks5") == 0 || strcmp(np_req->proxy_type, "mstsc") == 0)
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "proxy_type", string, "tcp");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "proxy_type", string, np_req->proxy_type);
|
||||
}
|
||||
JSON_MARSHAL_TYPE(j_np_req, "use_encryption", boolean, np_req->use_encryption);
|
||||
JSON_MARSHAL_TYPE(j_np_req, "use_compression", boolean, np_req->use_compression);
|
||||
|
||||
// if proxy_type is tcp, http, https and socks5, set group and group_key to j_np_req
|
||||
if (strcmp(np_req->proxy_type, "tcp") == 0 ||
|
||||
strcmp(np_req->proxy_type, "http") == 0 ||
|
||||
strcmp(np_req->proxy_type, "https") == 0 ||
|
||||
strcmp(np_req->proxy_type, "socks5") == 0) {
|
||||
|
||||
if (np_req->group) {
|
||||
if (strcmp(np_req->proxy_type, "tcp") == 0 ||
|
||||
strcmp(np_req->proxy_type, "http") == 0 ||
|
||||
strcmp(np_req->proxy_type, "https") == 0 ||
|
||||
strcmp(np_req->proxy_type, "socks5") == 0)
|
||||
{
|
||||
|
||||
if (np_req->group)
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "group", string, np_req->group);
|
||||
}
|
||||
if (np_req->group_key) {
|
||||
if (np_req->group_key)
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "group_key", string, np_req->group_key);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_ftp_proxy(np_req)) {
|
||||
if (is_ftp_proxy(np_req))
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "remote_data_port", int, np_req->remote_data_port);
|
||||
}
|
||||
|
||||
if (np_req->custom_domains) {
|
||||
if (np_req->custom_domains)
|
||||
{
|
||||
fill_custom_domains(j_np_req, np_req->custom_domains);
|
||||
json_object_object_add(j_np_req, "remote_port", NULL);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
json_object_object_add(j_np_req, "custom_domains", NULL);
|
||||
if (np_req->remote_port != -1) {
|
||||
if (np_req->remote_port != -1)
|
||||
{
|
||||
JSON_MARSHAL_TYPE(j_np_req, "remote_port", int, np_req->remote_port);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
json_object_object_add(j_np_req, "remote_port", NULL);
|
||||
}
|
||||
}
|
||||
@@ -223,23 +242,28 @@ new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
JSON_MARSHAL_TYPE(j_np_req, "subdomain", string, SAFE_JSON_STRING(np_req->subdomain));
|
||||
|
||||
json_object *j_location_array = json_object_new_array();
|
||||
if (np_req->locations) {
|
||||
if (np_req->locations)
|
||||
{
|
||||
json_object_object_add(j_np_req, "locations", j_location_array);
|
||||
path = strtok_r(np_req->locations, delimiter, &save);
|
||||
while (path) {
|
||||
while (path)
|
||||
{
|
||||
json_object_array_add(j_location_array, json_object_new_string(path));
|
||||
path = strtok_r(NULL, delimiter, &save);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
json_object_object_add(j_np_req, "locations", NULL);
|
||||
}
|
||||
|
||||
|
||||
JSON_MARSHAL_TYPE(j_np_req, "host_header_rewrite", string, SAFE_JSON_STRING(np_req->host_header_rewrite));
|
||||
JSON_MARSHAL_TYPE(j_np_req, "http_user", string, SAFE_JSON_STRING(np_req->http_user));
|
||||
JSON_MARSHAL_TYPE(j_np_req, "http_pwd", string, SAFE_JSON_STRING(np_req->http_pwd));
|
||||
|
||||
|
||||
tmp = json_object_to_json_string(j_np_req);
|
||||
if (tmp && strlen(tmp) > 0) {
|
||||
if (tmp && strlen(tmp) > 0)
|
||||
{
|
||||
nret = strlen(tmp);
|
||||
*msg = strdup(tmp);
|
||||
assert(*msg);
|
||||
@@ -249,18 +273,18 @@ new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
return nret;
|
||||
}
|
||||
|
||||
int
|
||||
new_work_conn_marshal(const struct work_conn *work_c, char **msg)
|
||||
int new_work_conn_marshal(const struct work_conn *work_c, char **msg)
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
int nret = 0;
|
||||
struct json_object *j_new_work_conn = json_object_new_object();
|
||||
if (! j_new_work_conn)
|
||||
if (!j_new_work_conn)
|
||||
return 0;
|
||||
|
||||
JSON_MARSHAL_TYPE(j_new_work_conn, "run_id", string, SAFE_JSON_STRING(work_c->run_id));
|
||||
tmp = json_object_to_json_string(j_new_work_conn);
|
||||
if (tmp && strlen(tmp) > 0) {
|
||||
if (tmp && strlen(tmp) > 0)
|
||||
{
|
||||
nret = strlen(tmp);
|
||||
*msg = strdup(tmp);
|
||||
assert(*msg);
|
||||
@@ -278,7 +302,7 @@ new_proxy_resp_unmarshal(const char *jres)
|
||||
struct json_object *j_np_res = json_tokener_parse(jres);
|
||||
if (j_np_res == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
struct new_proxy_response *npr = calloc(1, sizeof(struct new_proxy_response));
|
||||
assert(npr);
|
||||
|
||||
@@ -287,24 +311,43 @@ new_proxy_resp_unmarshal(const char *jres)
|
||||
npr->run_id = strdup(json_object_get_string(npr_run_id));
|
||||
|
||||
struct json_object *npr_proxy_remote_addr = NULL;
|
||||
if (! json_object_object_get_ex(j_np_res, "remote_addr", &npr_proxy_remote_addr))
|
||||
if (!json_object_object_get_ex(j_np_res, "remote_addr", &npr_proxy_remote_addr))
|
||||
{
|
||||
free(npr->run_id);
|
||||
free(npr);
|
||||
npr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
const char *remote_addr = json_object_get_string(npr_proxy_remote_addr);
|
||||
char *port = strrchr(remote_addr, ':');
|
||||
if (port) {
|
||||
if (port)
|
||||
{
|
||||
port++;
|
||||
npr->remote_port = atoi(port);
|
||||
}
|
||||
|
||||
struct json_object *npr_proxy_name = NULL;
|
||||
if (! json_object_object_get_ex(j_np_res, "proxy_name", &npr_proxy_name))
|
||||
if (!json_object_object_get_ex(j_np_res, "proxy_name", &npr_proxy_name))
|
||||
{
|
||||
free(npr->run_id);
|
||||
free(npr);
|
||||
npr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
npr->proxy_name = strdup(json_object_get_string(npr_proxy_name));
|
||||
assert(npr->proxy_name);
|
||||
|
||||
struct json_object *npr_error = NULL;
|
||||
if(! json_object_object_get_ex(j_np_res, "error", &npr_error))
|
||||
if (!json_object_object_get_ex(j_np_res, "error", &npr_error))
|
||||
{
|
||||
free(npr->run_id);
|
||||
free(npr->proxy_name);
|
||||
free(npr);
|
||||
npr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
npr->error = strdup(json_object_get_string(npr_error));
|
||||
assert(npr->error);
|
||||
|
||||
@@ -320,25 +363,43 @@ login_resp_unmarshal(const char *jres)
|
||||
struct json_object *j_lg_res = json_tokener_parse(jres);
|
||||
if (j_lg_res == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
struct login_resp *lr = calloc(1, sizeof(struct login_resp));
|
||||
assert(lr);
|
||||
|
||||
struct json_object *l_version = NULL;
|
||||
if (! json_object_object_get_ex(j_lg_res, "version", &l_version))
|
||||
if (!json_object_object_get_ex(j_lg_res, "version", &l_version))
|
||||
{
|
||||
free(lr);
|
||||
lr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
lr->version = strdup(json_object_get_string(l_version));
|
||||
assert(lr->version);
|
||||
|
||||
struct json_object *l_run_id = NULL;
|
||||
if (! json_object_object_get_ex(j_lg_res, "run_id", &l_run_id))
|
||||
if (!json_object_object_get_ex(j_lg_res, "run_id", &l_run_id))
|
||||
{
|
||||
free(lr->version);
|
||||
free(lr);
|
||||
lr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
lr->run_id = strdup(json_object_get_string(l_run_id));
|
||||
assert(lr->run_id);
|
||||
|
||||
struct json_object *l_error = NULL;
|
||||
if(! json_object_object_get_ex(j_lg_res, "error", &l_error))
|
||||
if (!json_object_object_get_ex(j_lg_res, "error", &l_error))
|
||||
{
|
||||
free(lr->version);
|
||||
free(lr->run_id);
|
||||
free(lr);
|
||||
lr = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
lr->error = strdup(json_object_get_string(l_error));
|
||||
assert(lr->error);
|
||||
|
||||
@@ -358,8 +419,12 @@ start_work_conn_resp_unmarshal(const char *resp_msg)
|
||||
assert(sr);
|
||||
|
||||
struct json_object *pn = NULL;
|
||||
if(! json_object_object_get_ex(j_start_w_res, "proxy_name", &pn))
|
||||
if (!json_object_object_get_ex(j_start_w_res, "proxy_name", &pn))
|
||||
{
|
||||
free(sr);
|
||||
sr = NULL;
|
||||
goto START_W_C_R_END;
|
||||
}
|
||||
|
||||
sr->proxy_name = strdup(json_object_get_string(pn));
|
||||
assert(sr->proxy_name);
|
||||
@@ -377,22 +442,35 @@ control_response_unmarshal(const char *jres)
|
||||
return NULL;
|
||||
struct control_response *ctl_res = calloc(sizeof(struct control_response), 1);
|
||||
assert(ctl_res);
|
||||
|
||||
|
||||
struct json_object *jtype = NULL;
|
||||
if(! json_object_object_get_ex(j_ctl_res, "type", &jtype))
|
||||
if (!json_object_object_get_ex(j_ctl_res, "type", &jtype))
|
||||
{
|
||||
free(ctl_res);
|
||||
ctl_res = NULL;
|
||||
goto END_ERROR;
|
||||
ctl_res->type = json_object_get_int(jtype);
|
||||
|
||||
struct json_object *jcode = NULL;
|
||||
if(! json_object_object_get_ex(j_ctl_res, "code", &jcode))
|
||||
goto END_ERROR;
|
||||
ctl_res->code = json_object_get_int(jcode);
|
||||
|
||||
struct json_object *jmsg = NULL;
|
||||
if(json_object_object_get_ex(j_ctl_res, "msg", &jmsg)) {
|
||||
ctl_res->msg = strdup(json_object_get_string(jmsg));
|
||||
assert(ctl_res->msg);
|
||||
}
|
||||
ctl_res->type = json_object_get_int(jtype);
|
||||
|
||||
struct json_object *jcode = NULL;
|
||||
if (!json_object_object_get_ex(j_ctl_res, "code", &jcode))
|
||||
{
|
||||
free(ctl_res);
|
||||
ctl_res = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
ctl_res->code = json_object_get_int(jcode);
|
||||
|
||||
struct json_object *jmsg = NULL;
|
||||
if (!json_object_object_get_ex(j_ctl_res, "msg", &jmsg))
|
||||
{
|
||||
free(ctl_res);
|
||||
ctl_res = NULL;
|
||||
goto END_ERROR;
|
||||
}
|
||||
ctl_res->msg = strdup(json_object_get_string(jmsg));
|
||||
assert(ctl_res->msg);
|
||||
|
||||
END_ERROR:
|
||||
json_object_put(j_ctl_res);
|
||||
@@ -404,29 +482,11 @@ control_response_free(struct control_response *res)
|
||||
{
|
||||
if (!res)
|
||||
return;
|
||||
|
||||
|
||||
SAFE_FREE(res->msg);
|
||||
SAFE_FREE(res);
|
||||
}
|
||||
|
||||
int
|
||||
msg_type_valid_check(char msg_type)
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 0; i<(sizeof(msg_types) / sizeof(*msg_types)); i++) {
|
||||
if (msg_types[i] == msg_type)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
get_msg_type(uint8_t type)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// marshal udp packet msg
|
||||
int
|
||||
new_udp_packet_marshal(const struct udp_packet *udp, char **msg)
|
||||
@@ -439,7 +499,8 @@ new_udp_packet_marshal(const struct udp_packet *udp, char **msg)
|
||||
assert(content);
|
||||
json_object_object_add(j_udp, "c", content);
|
||||
|
||||
if (udp->laddr) {
|
||||
if (udp->laddr)
|
||||
{
|
||||
// laddr is a struct, parse it to json object and add to j_udp
|
||||
struct json_object *j_laddr = json_object_new_object();
|
||||
assert(j_laddr);
|
||||
@@ -453,14 +514,17 @@ new_udp_packet_marshal(const struct udp_packet *udp, char **msg)
|
||||
json_object *j_laddr_zone = json_object_new_string("");
|
||||
assert(j_laddr_zone);
|
||||
json_object_object_add(j_laddr, "Zone", j_laddr_zone);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// laddr is NULL, add null to j_udp
|
||||
struct json_object *j_laddr = json_object_new_object();
|
||||
assert(j_laddr);
|
||||
json_object_object_add(j_udp, "l", j_laddr);
|
||||
}
|
||||
|
||||
if (udp->raddr) {
|
||||
if (udp->raddr)
|
||||
{
|
||||
// raddr is a struct, parse it to json object and add to j_udp
|
||||
struct json_object *j_raddr = json_object_new_object();
|
||||
assert(j_raddr);
|
||||
@@ -474,11 +538,13 @@ new_udp_packet_marshal(const struct udp_packet *udp, char **msg)
|
||||
json_object *j_raddr_zone = json_object_new_string("");
|
||||
assert(j_raddr_zone);
|
||||
json_object_object_add(j_raddr, "Zone", j_raddr_zone);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// raddr is NULL, add null to j_udp
|
||||
struct json_object *j_raddr = json_object_new_object();
|
||||
assert(j_raddr);
|
||||
json_object_object_add(j_udp, "r", j_raddr);
|
||||
json_object_object_add(j_udp, "r", j_raddr);
|
||||
}
|
||||
|
||||
// convert json to string msg
|
||||
@@ -494,7 +560,7 @@ udp_packet_free(struct udp_packet *udp)
|
||||
{
|
||||
if (!udp)
|
||||
return;
|
||||
|
||||
|
||||
SAFE_FREE(udp->content);
|
||||
SAFE_FREE(udp->laddr->addr);
|
||||
SAFE_FREE(udp->laddr->zone);
|
||||
@@ -508,7 +574,7 @@ udp_packet_free(struct udp_packet *udp)
|
||||
|
||||
// unmarshal udp packet msg
|
||||
struct udp_packet *
|
||||
udp_packet_unmarshal (const char *msg)
|
||||
udp_packet_unmarshal(const char *msg)
|
||||
{
|
||||
struct json_object *j_udp = json_tokener_parse(msg);
|
||||
if (j_udp == NULL)
|
||||
@@ -517,23 +583,37 @@ udp_packet_unmarshal (const char *msg)
|
||||
assert(udp);
|
||||
|
||||
struct json_object *j_content = NULL;
|
||||
if(! json_object_object_get_ex(j_udp, "c", &j_content))
|
||||
if (!json_object_object_get_ex(j_udp, "c", &j_content))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
udp->content = strdup(json_object_get_string(j_content));
|
||||
assert(udp->content);
|
||||
|
||||
struct json_object *j_laddr = NULL;
|
||||
if(! json_object_object_get_ex(j_udp, "l", &j_laddr))
|
||||
if (!json_object_object_get_ex(j_udp, "l", &j_laddr))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
struct json_object *j_laddr_ip = NULL;
|
||||
if(! json_object_object_get_ex(j_laddr, "IP", &j_laddr_ip))
|
||||
if (!json_object_object_get_ex(j_laddr, "IP", &j_laddr_ip))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
struct json_object *j_laddr_port = NULL;
|
||||
if(! json_object_object_get_ex(j_laddr, "Port", &j_laddr_port))
|
||||
if (!json_object_object_get_ex(j_laddr, "Port", &j_laddr_port))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
struct json_object *j_laddr_zone = NULL;
|
||||
if(! json_object_object_get_ex(j_laddr, "Zone", &j_laddr_zone))
|
||||
if (!json_object_object_get_ex(j_laddr, "Zone", &j_laddr_zone))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
udp->laddr = calloc(sizeof(struct udp_addr), 1);
|
||||
assert(udp->laddr);
|
||||
udp->laddr->addr = strdup(json_object_get_string(j_laddr_ip));
|
||||
@@ -543,17 +623,29 @@ udp_packet_unmarshal (const char *msg)
|
||||
assert(udp->laddr->zone);
|
||||
|
||||
struct json_object *j_raddr = NULL;
|
||||
if(! json_object_object_get_ex(j_udp, "r", &j_raddr))
|
||||
if (!json_object_object_get_ex(j_udp, "r", &j_raddr))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
struct json_object *j_raddr_ip = NULL;
|
||||
if(! json_object_object_get_ex(j_raddr, "IP", &j_raddr_ip))
|
||||
if (!json_object_object_get_ex(j_raddr, "IP", &j_raddr_ip))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
struct json_object *j_raddr_port = NULL;
|
||||
if(! json_object_object_get_ex(j_raddr, "Port", &j_raddr_port))
|
||||
if (!json_object_object_get_ex(j_raddr, "Port", &j_raddr_port))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
struct json_object *j_raddr_zone = NULL;
|
||||
if(! json_object_object_get_ex(j_raddr, "Zone", &j_raddr_zone))
|
||||
if (!json_object_object_get_ex(j_raddr, "Zone", &j_raddr_zone))
|
||||
{
|
||||
goto END_ERROR;
|
||||
}
|
||||
|
||||
udp->raddr = calloc(sizeof(struct udp_addr), 1);
|
||||
assert(udp->raddr);
|
||||
udp->raddr->addr = strdup(json_object_get_string(j_raddr_ip));
|
||||
|
||||
3
msg.h
3
msg.h
@@ -110,7 +110,6 @@ struct start_work_conn_resp {
|
||||
|
||||
int new_udp_packet_marshal(const struct udp_packet *udp, char **msg);
|
||||
int new_proxy_service_marshal(const struct proxy_service *np_req, char **msg);
|
||||
int msg_type_valid_check(char msg_type);
|
||||
char *calc_md5(const char *data, int datalen);
|
||||
char *get_auth_key(const char *token, long int *timestamp);
|
||||
size_t login_request_marshal(char **msg);
|
||||
@@ -132,6 +131,4 @@ void udp_packet_free(struct udp_packet *udp);
|
||||
|
||||
void control_response_free(struct control_response *res);
|
||||
|
||||
char *get_msg_type(uint8_t type);
|
||||
|
||||
#endif //_MSG_H_
|
||||
|
||||
Reference in New Issue
Block a user