diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | agni.c | 46 | ||||
-rw-r--r-- | cmd/cmd_stat.c | 9 | ||||
-rw-r--r-- | cmd/cmd_todo.c | 16 | ||||
-rw-r--r-- | nbrpc_call.c | 188 | ||||
-rw-r--r-- | nbrpc_event.c | 256 | ||||
-rw-r--r-- | nbrpc_event.h | 4 | ||||
-rw-r--r-- | tbl_qcmd.c | 6 |
8 files changed, 347 insertions, 180 deletions
@@ -1,6 +1,6 @@ PROJECT=agni CC=gcc -CFLAGS=-g3 +CFLAGS=-g3 -Wall SOURCES=$(wildcard *.c) OBJECTS=$(SOURCES:.c=.o) LDFLAGS=-lrt -lm @@ -288,12 +288,12 @@ int th_start_client(void *data) ENL(); } //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); - PRINT("out_attr.mq_msgsize %d\n", out_attr.mq_msgsize); + PRINT("out_attr.mq_msgsize %ld\n", out_attr.mq_msgsize); out_buf = malloc(out_attr.mq_msgsize); if (out_buf == NULL) { - ERROR("Can allocate out_buf, size of %d\n", out_attr.mq_msgsize); + ERROR("Can allocate out_buf, size of %ld\n", out_attr.mq_msgsize); } memset(out_buf, 0, out_attr.mq_msgsize); @@ -380,7 +380,7 @@ int th_start_client(void *data) user[sep-cmd->ircident] = 0x0; char *resp_user = token_new_str(cmd->tok, 2); //PRINT("resp_user %s\n",resp_user); - int formated_size = -1; + //int formated_size = -1; int count; sds str_out; @@ -556,6 +556,10 @@ int th_start_client(void *data) } req = rpc_req_new(qcmd->cmd, qcmd->param, qcmd->cid); + req->user = alloc_new_str("U-ser"); + req->mask = alloc_new_str("M-ask"); + req->server = alloc_new_str("S-erver"); + rpc_req_marsh(req, &nb_req); buf_nb = nb_create(nb_req); memcpy(out_buf, buf_nb, nb_req->size > out_attr.mq_msgsize ? out_attr.mq_msgsize : nb_req->size); @@ -769,31 +773,6 @@ int th_event_manager(void *data) run = 1; while(run) { - //check if there is some message and save it to buffer - /* - run += 1; - mq_event = mq_ntf_select(mq, MQ_OUT); - switch(mq_event) - { - case 0: - //PRINT("EVENT 0\n"); - break; - case 1: - PRINT("MQ_EVENT OUT\n"); - memset(out_buf, 0, out_attr.mq_msgsize); - if (mq_ntf_read(mq, MQ_OUT, out_buf, out_attr.mq_msgsize) == -1) - { - printf("Cant read output message\n"); - } else - { - out_buf[out_attr.mq_msgsize-1] = 0x0; - printf("Recieve %s\n", out_buf); - } - break; - default: - printf("Unknown event type\n"); - } - */ run += 1; for (i_mq=0;i_mq<cfg->mq_num;i_mq++) @@ -828,7 +807,7 @@ int th_event_manager(void *data) if (0 == nb_load(nb_req, out_buf)) { rpc_req_unmarsh(nb_req, &req); - PRINT("EVENT-REQ: %d-%s(%s)\n", req->id, req->method, req->params); + PRINT("EVENT-REQ: %d-%s(%s) %s-%s-%s\n", req->id, req->method, req->params, req->user, req->mask, req->server); //nb_print(nb_req); if (strncmp(req->method,":PRIVMSG",8)) @@ -850,21 +829,24 @@ int th_event_manager(void *data) FREE(stat_str); } - if (tbl_exec_run(etbl, exec_params, "", "", "", &ret_msg)>=0) + if (tbl_exec_run(etbl, exec_params, req->user, req->mask, req->server, &ret_msg)>=0) { if (ret_msg != NULL) { - printf("Ret message %s\n",ret_msg); + printf("Ret message %s\n",(char *)ret_msg); //send response resp = rpc_resp_new(ret_msg,"None",req->id); + resp->user = alloc_new_str(""); + resp->mask = alloc_new_str(""); + resp->server = alloc_new_str(""); rpc_resp_marsh(resp, &nb_resp); buf_nb = nb_create(nb_resp); mq_ntf_write(mq_cur, MQ_IN, buf_nb, nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); stats.cnt_ipc_tx += nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size; FREE(buf_nb); - printf("EVENT-Write %d bytes\n", nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); + printf("EVENT-Write %ld bytes\n", nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); FREE(ret_msg); nb_free(nb_resp); diff --git a/cmd/cmd_stat.c b/cmd/cmd_stat.c index 73b7fa6..dc2a097 100644 --- a/cmd/cmd_stat.c +++ b/cmd/cmd_stat.c @@ -5,7 +5,6 @@ void *cmd_stat(void *data) char *param = (char *)data; char *ret = NULL; - int i; int count; sds params; sds out_result; @@ -25,16 +24,16 @@ void *cmd_stat(void *data) out_result = sdscat(out_result,"+----------+----------+\n"); //cmd_success - snprintf(buf,buf_size,"| CMD_SUCC | %08s |\n", tokens[0]); + snprintf(buf,buf_size,"| CMD_SUCC | %8s |\n", tokens[0]); out_result = sdscat(out_result, buf); //cmd_err - snprintf(buf,buf_size,"| CMD_ERR | %08s |\n", tokens[1]); + snprintf(buf,buf_size,"| CMD_ERR | %8s |\n", tokens[1]); out_result = sdscat(out_result, buf); //ipc tx - snprintf(buf,buf_size,"| IPC_TX | %08s |\n", tokens[2]); + snprintf(buf,buf_size,"| IPC_TX | %8s |\n", tokens[2]); out_result = sdscat(out_result, buf); //ipc rx - snprintf(buf,buf_size,"| IPC_RX | %08s |\n", tokens[3]); + snprintf(buf,buf_size,"| IPC_RX | %8s |\n", tokens[3]); out_result = sdscat(out_result, buf); out_result = sdscat(out_result,"+----------+----------+"); diff --git a/cmd/cmd_todo.c b/cmd/cmd_todo.c index e525d38..2b3993b 100644 --- a/cmd/cmd_todo.c +++ b/cmd/cmd_todo.c @@ -32,19 +32,18 @@ void *cmd_todo(void *data) return NULL; } - PNL(); fret = rpc_call_req_unmarsh(nb_req, &req); - PNL(); if (fret != 0) { ERROR("Invalid request format\n"); return NULL; } - PNL(); //---------------------------------------------------------------------------- //main code + PRINT("%s-%s-%s-%s-%s\n", req->method, req->params, req->user, req->mask, req->server); + //---------------------------------------------------------------------------- //prepare response @@ -53,24 +52,21 @@ void *cmd_todo(void *data) PNL(); resp = rpc_call_resp_new("Success","None",1); - resp->user = alloc_new_str(""); - resp->server = alloc_new_str(""); - resp->mask = alloc_new_str(""); + resp->user = alloc_new_str(" "); + resp->server = alloc_new_str(" "); + resp->mask = alloc_new_str(" "); PNL(); rpc_call_resp_marsh(resp, &nb_resp); PNL(); - nb_buf = nb_create(nb_resp); + nb_buf = (char *)nb_create(nb_resp); if (nb_buf) { ret = nb_buf; } - PNL(); nb_free(nb_resp); - PNL(); rpc_call_resp_free(resp); - PNL(); return ret; } diff --git a/nbrpc_call.c b/nbrpc_call.c index 1fc60ba..67242a9 100644 --- a/nbrpc_call.c +++ b/nbrpc_call.c @@ -28,7 +28,7 @@ rpc_call_request* rpc_call_req_new(char *method, char *params, int id) ret->params = alloc_new_str(params); ret->user = NULL; ret->mask = NULL; - ret->server == NULL; + ret->server = NULL; return ret; } @@ -64,7 +64,9 @@ int rpc_call_req_free(rpc_call_request *req) FREE(req->method); FREE(req->params); FREE(req); + return 0; } + return -1; } @@ -78,7 +80,9 @@ int rpc_call_resp_free(rpc_call_response *resp) FREE(resp->mask); FREE(resp->server); FREE(resp); + return 0; } + return -1; } @@ -91,24 +95,22 @@ int rpc_call_req_marsh( rpc_call_request *req, netbyte_store **nb_req) nb = calloc(1,sizeof(netbyte_store)); nb_init(nb); - nb_u8arr_create(&nb_method, strlen(req->method), req->method); + nb_u8arr_create(&nb_method, strlen(req->method), (uint8_t *)req->method); nb_add_u8arr(nb, &nb_method); - nb_u8arr_create(&nb_params, strlen(req->params), req->params); + nb_u8arr_create(&nb_params, strlen(req->params), (uint8_t *)req->params); nb_add_u8arr(nb, &nb_params); nb_u32_create(&nb_id, req->id); - //PRINT("%d\n", req->id); - //PRINT("%d\n", nb_id.val); nb_add_u32(nb, &nb_id); - nb_u8arr_create(&nb_user, strlen(req->user), req->user); + nb_u8arr_create(&nb_user, strlen(req->user), (uint8_t *)req->user); nb_add_u8arr(nb, &nb_user); - nb_u8arr_create(&nb_mask, strlen(req->mask), req->mask); + nb_u8arr_create(&nb_mask, strlen(req->mask), (uint8_t *)req->mask); nb_add_u8arr(nb, &nb_params); - nb_u8arr_create(&nb_server, strlen(req->server), req->server); + nb_u8arr_create(&nb_server, strlen(req->server), (uint8_t *)req->server); nb_add_u8arr(nb, &nb_server); //nb_print(nb); @@ -129,24 +131,22 @@ int rpc_call_resp_marsh( rpc_call_response *resp, netbyte_store **nb_resp) nb = calloc(1,sizeof(netbyte_store)); nb_init(nb); - eret = nb_u8arr_create(&nb_result, strlen(resp->result), resp->result); + eret = nb_u8arr_create(&nb_result, strlen(resp->result), (uint8_t *)resp->result); eret |= nb_add_u8arr(nb, &nb_result); - eret = nb_u8arr_create(&nb_error, strlen(resp->error), resp->error); + eret = nb_u8arr_create(&nb_error, strlen(resp->error), (uint8_t *)resp->error); eret |= nb_add_u8arr(nb, &nb_error); eret = nb_u32_create(&nb_id, resp->id); - //PRINT("%d\n", resp->id); - //PRINT("%d\n", nb_id.val); eret |= nb_add_u32(nb, &nb_id); - eret = nb_u8arr_create(&nb_user, strlen(resp->user), resp->user); + eret = nb_u8arr_create(&nb_user, strlen(resp->user), (uint8_t *)resp->user); eret |= nb_add_u8arr(nb, &nb_user); - eret = nb_u8arr_create(&nb_mask, strlen(resp->mask), resp->mask); + eret = nb_u8arr_create(&nb_mask, strlen(resp->mask), (uint8_t *)resp->mask); eret |= nb_add_u8arr(nb, &nb_mask); - eret = nb_u8arr_create(&nb_server, strlen(resp->server), resp->server); + eret = nb_u8arr_create(&nb_server, strlen(resp->server), (uint8_t *)resp->server); eret |= nb_add_u8arr(nb, &nb_server); if (!eret) @@ -180,10 +180,15 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //method if (0 == nb_val(nb_req, 0, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->method = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->method = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -191,10 +196,15 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //params if (0 == nb_val(nb_req, 1, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->params = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->params = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -202,11 +212,16 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //id if (0 == nb_val(nb_req, 2, &type)) - if (type->type == NBT_U32) { - //PNL(); - nb_u32 *u32 = (nb_u32 *)type->nb_val; - __req->id = u32->val; + if (type->type == NBT_U32) + { + //PNL(); + nb_u32 *u32 = (nb_u32 *)type->nb_val; + __req->id = u32->val; + } else + { + ENL(); + } } else { ENL(); @@ -214,11 +229,16 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //user if (0 == nb_val(nb_req, 3, &type)) - if (type->type == NBT_U8ARRAY) { - //PNL(); - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->user = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->user = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -226,11 +246,16 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //mask if (0 == nb_val(nb_req, 4, &type)) - if (type->type == NBT_U8ARRAY) { - //PNL(); - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->mask = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->mask = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -238,11 +263,16 @@ int rpc_call_req_unmarsh( netbyte_store *nb_req, rpc_call_request **req) //server if (0 == nb_val(nb_req, 5, &type)) - if (type->type == NBT_U8ARRAY) { - //PNL(); - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->server = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->server = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -273,10 +303,15 @@ int rpc_call_resp_unmarsh(netbyte_store *nb_resp, rpc_call_response **resp) //result if (0 == nb_val(nb_resp, 0, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->result = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->result = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -284,10 +319,15 @@ int rpc_call_resp_unmarsh(netbyte_store *nb_resp, rpc_call_response **resp) //error if (0 == nb_val(nb_resp, 1, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->error = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->error = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -295,12 +335,17 @@ int rpc_call_resp_unmarsh(netbyte_store *nb_resp, rpc_call_response **resp) //id if (0 == nb_val(nb_resp, 2, &type)) - if (type->type == NBT_U32) { - PNL(); - nb_u32 *u32 = (nb_u32 *)type->nb_val; - __resp->id = u32->val; - //PRINT("%d\n",u32->val) + if (type->type == NBT_U32) + { + PNL(); + nb_u32 *u32 = (nb_u32 *)type->nb_val; + __resp->id = u32->val; + //PRINT("%d\n",u32->val) + } else + { + ENL(); + } } else { ENL(); @@ -308,35 +353,44 @@ int rpc_call_resp_unmarsh(netbyte_store *nb_resp, rpc_call_response **resp) //user if (0 == nb_val(nb_resp, 3, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->user = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->user = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); } //mask - if (0 == nb_val(nb_resp, 1, &type)) - if (type->type == NBT_U8ARRAY) - { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->mask = alloc_new_str_s(u8arr->val, u8arr->len); - } else - { - ENL(); + if (0 == nb_val(nb_resp, 4, &type)) + { + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->mask = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } //server - if (0 == nb_val(nb_resp, 1, &type)) - if (type->type == NBT_U8ARRAY) - { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->server = alloc_new_str_s(u8arr->val, u8arr->len); - } else - { - ENL(); + if (0 == nb_val(nb_resp, 5, &type)) + { + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->server = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } *resp = __resp; diff --git a/nbrpc_event.c b/nbrpc_event.c index dc5cddd..85e4aab 100644 --- a/nbrpc_event.c +++ b/nbrpc_event.c @@ -15,6 +15,9 @@ rpc_request* rpc_req_new(char *method, char *params, int id) ret->id = id; ret->method = alloc_new_str(method); ret->params = alloc_new_str(params); + ret->user = NULL; + ret->mask = NULL; + ret->server = NULL; return ret; } @@ -33,7 +36,9 @@ rpc_response* rpc_resp_new(char *result, char *error, int id) ret->id = id; ret->result = alloc_new_str(result); ret->error = alloc_new_str(error); - + ret->user = NULL; + ret->mask = NULL; + ret->server = NULL; return ret; } @@ -42,12 +47,15 @@ int rpc_req_free(rpc_request *req) { if (req) { - free(req->method); - free(req->params); - free(req); - req = NULL; + FREE(req->user); + FREE(req->mask); + FREE(req->user); + FREE(req->method); + FREE(req->params); + FREE(req); + return 0; } - + return -1; } @@ -55,11 +63,15 @@ int rpc_resp_free(rpc_response *resp) { if (resp) { - free(resp->result); - free(resp->error); - free(resp); - resp = NULL; + FREE(resp->user); + FREE(resp->mask); + FREE(resp->server); + FREE(resp->result); + FREE(resp->error); + FREE(resp); + return 0; } + return -1; } @@ -67,24 +79,28 @@ int rpc_req_marsh( rpc_request *req, netbyte_store **nb_req) { netbyte_store *nb = NULL; nb_u32 nb_id; - nb_u8arr nb_method, nb_params; + nb_u8arr nb_method, nb_params, nb_user, nb_mask, nb_server; nb = calloc(1,sizeof(netbyte_store)); nb_init(nb); - nb_u8arr_create(&nb_method, strlen(req->method), req->method); + nb_u8arr_create(&nb_method, strlen(req->method), (uint8_t *)req->method); nb_add_u8arr(nb, &nb_method); - nb_u8arr_create(&nb_params, strlen(req->params), req->params); + nb_u8arr_create(&nb_params, strlen(req->params), (uint8_t *)req->params); nb_add_u8arr(nb, &nb_params); nb_u32_create(&nb_id, req->id); - //PRINT("%d\n", req->id); - //PRINT("%d\n", nb_id.val); nb_add_u32(nb, &nb_id); - //nb_print(nb); - //nb_print(nb); + nb_u8arr_create(&nb_user, strlen(req->user), (uint8_t *)req->user); + nb_add_u8arr(nb, &nb_user); + + nb_u8arr_create(&nb_mask, strlen(req->mask), (uint8_t *)req->mask); + nb_add_u8arr(nb, &nb_mask); + + nb_u8arr_create(&nb_server, strlen(req->server), (uint8_t *)req->server); + nb_add_u8arr(nb, &nb_server); *nb_req = nb; return 0; @@ -96,28 +112,35 @@ int rpc_resp_marsh( rpc_response *resp, netbyte_store **nb_resp) int eret; netbyte_store *nb = NULL; nb_u32 nb_id; - nb_u8arr nb_result, nb_error; + nb_u8arr nb_result, nb_error, nb_user, nb_mask, nb_server; nb = calloc(1,sizeof(netbyte_store)); nb_init(nb); - eret = nb_u8arr_create(&nb_result, strlen(resp->result), resp->result); + eret = nb_u8arr_create(&nb_result, strlen(resp->result), (uint8_t *)resp->result); eret |= nb_add_u8arr(nb, &nb_result); - eret = nb_u8arr_create(&nb_error, strlen(resp->error), resp->error); + eret = nb_u8arr_create(&nb_error, strlen(resp->error), (uint8_t *)resp->error); eret |= nb_add_u8arr(nb, &nb_error); eret = nb_u32_create(&nb_id, resp->id); - //PRINT("%d\n", resp->id); - //PRINT("%d\n", nb_id.val); eret |= nb_add_u32(nb, &nb_id); + + eret = nb_u8arr_create(&nb_user, strlen(resp->user), (uint8_t *)resp->user); + eret |= nb_add_u8arr(nb, &nb_user); + + eret = nb_u8arr_create(&nb_mask, strlen(resp->mask), (uint8_t *)resp->mask); + eret |= nb_add_u8arr(nb, &nb_mask); + + eret = nb_u8arr_create(&nb_server, strlen(resp->server), (uint8_t *)resp->server); + eret |= nb_add_u8arr(nb, &nb_server); + + if (!eret) { ENL(); } - //nb_print(nb); - *nb_resp = nb; return 0; } @@ -141,34 +164,82 @@ int rpc_req_unmarsh( netbyte_store *nb_req, rpc_request **req) __req = calloc(1,sizeof(rpc_request)); if (0 == nb_val(nb_req, 0, &type)) - if (type->type == NBT_U8ARRAY) - { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->method = alloc_new_str_s(u8arr->val, u8arr->len); - } else { - ENL(); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->method = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } if (0 == nb_val(nb_req, 1, &type)) - if (type->type == NBT_U8ARRAY) - { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __req->params = alloc_new_str_s(u8arr->val, u8arr->len); - } else { - ENL(); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->params = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } if (0 == nb_val(nb_req, 2, &type)) - if (type->type == NBT_U32) - { - //PNL(); - nb_u32 *u32 = (nb_u32 *)type->nb_val; - __req->id = u32->val; - } else { - ENL(); + if (type->type == NBT_U32) + { + //PNL(); + nb_u32 *u32 = (nb_u32 *)type->nb_val; + __req->id = u32->val; + } else + { + ENL(); + } + } + + //user + if (0 == nb_val(nb_req, 3, &type)) + { + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->user = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } + } + + //mask + if (0 == nb_val(nb_req, 4, &type)) + { + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->mask = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } + } + + //server + if (0 == nb_val(nb_req, 5, &type)) + { + if (type->type == NBT_U8ARRAY) + { + //PNL(); + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __req->server = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } *req = __req; @@ -195,32 +266,95 @@ int rpc_resp_unmarsh(netbyte_store *nb_resp, rpc_response **resp) __resp = calloc(1,sizeof(rpc_response)); if (0 == nb_val(nb_resp, 0, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->result = alloc_new_str_s(u8arr->val, u8arr->len); + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->result = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); } if (0 == nb_val(nb_resp, 1, &type)) - if (type->type == NBT_U8ARRAY) { - nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; - __resp->error = alloc_new_str_s(u8arr->val, u8arr->len); - } else + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->error = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } + } else { ENL(); } if (0 == nb_val(nb_resp, 2, &type)) - if (type->type == NBT_U32) { - PNL(); - nb_u32 *u32 = (nb_u32 *)type->nb_val; - __resp->id = u32->val; - //PRINT("%d\n",u32->val) + if (type->type == NBT_U32) + { + PNL(); + nb_u32 *u32 = (nb_u32 *)type->nb_val; + __resp->id = u32->val; + //PRINT("%d\n",u32->val) + } else + { + ENL(); + } + } else + { + ENL(); + } + + //user + if (0 == nb_val(nb_resp, 3, &type)) + { + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->user = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } + } else + { + ENL(); + } + + //mask + if (0 == nb_val(nb_resp, 4, &type)) + { + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->mask = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } + } else + { + ENL(); + } + + //server + if (0 == nb_val(nb_resp, 5, &type)) + { + if (type->type == NBT_U8ARRAY) + { + nb_u8arr *u8arr = (nb_u8arr *)type->nb_val; + __resp->server = alloc_new_str_s((char *)u8arr->val, u8arr->len); + } else + { + ENL(); + } } else { ENL(); @@ -234,36 +368,36 @@ int rpc_resp_unmarsh(netbyte_store *nb_resp, rpc_response **resp) int rpc_req_set_user(rpc_request *req) { - + return -1; } int rpc_resp_set_user(rpc_response *resp) { - + return -1; } int rpc_req_set_mask(rpc_request *req) { - + return -1; } int rpc_resp_set_mask(rpc_response *resp) { - + return -1; } int rpc_req_set_server(rpc_request *req) { - + return -1; } int rpc_resp_set_server(rpc_response *resp) { - + return -1; } diff --git a/nbrpc_event.h b/nbrpc_event.h index 5b0bad8..14dce96 100644 --- a/nbrpc_event.h +++ b/nbrpc_event.h @@ -11,20 +11,20 @@ typedef struct rpc_request { char *method; char *params; + int id; char *user; char *mask; char *server; - int id; } rpc_request; typedef struct rpc_response { char *result; char *error; + int id; char *user; char *mask; char *server; - int id; } rpc_response; rpc_request* rpc_req_new(char *method, char *params, int id); @@ -152,15 +152,17 @@ int tbl_exec_run(tbl_exec *tbl, char *cmd, char *user, char *mask, char *server, nb_init(nb_req); //create request - req = rpc_call_req_new(el->name, "asd", 1); + req = rpc_call_req_new(el->name, cmd, 1); if (!req) PERM(); if (user != NULL) { + PRINT("%s user\n", user); req->user = alloc_new_str(user); } if (mask != NULL) { - req->mask = alloc_new_str(mask); + PRINT("%s mask\n", mask); + req->mask = alloc_new_str("asd!!"); } if (server != NULL) { |