--- libaitrpc/src/cli.c 2011/11/03 13:35:39 1.5.2.6 +++ libaitrpc/src/cli.c 2012/03/13 17:10:13 1.6.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.5.2.6 2011/11/03 13:35:39 misho Exp $ +* $Id: cli.c,v 1.6.2.1 2012/03/13 17:10:13 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -291,7 +291,7 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, fd_set fds; u_char *buf, str[MAXPATHLEN + UCHAR_MAX + 1]; struct tagRPCCall *rpc; - struct tagRPCRet *rrpc = NULL; + struct tagRPCCall *rrpc = NULL; int ret = 0, Limit = 0; struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; uint16_t tag; @@ -328,7 +328,7 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, if (io_arraySize(in_vars)) { /* marshaling variables */ - ret = io_vals2buffer(buf + Limit, cli->cli_netbuf - Limit, in_vars); + ret = io_vars2buffer(buf + Limit, cli->cli_netbuf - Limit, in_vars); if (ret == -1) { rpc_SetErr(EBADRPC, "Error:: in prepare RPC packet values (-7) ...\n"); free(buf); @@ -371,102 +371,48 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, free(buf); return 0; } - if (ret < sizeof(struct tagRPCRet)) { + if (ret < sizeof(struct tagRPCCall)) { rpc_SetErr(ERPCMISMATCH, "Error:: too short RPC packet ...\n"); free(buf); return -4; } else - rrpc = (struct tagRPCRet*) buf; + rrpc = (struct tagRPCCall*) buf; /* check RPC packet session info */ - if (rpc_chkPktSession(&rrpc->ret_session, cli->cli_parent)) { + if (rpc_chkPktSession(&rrpc->call_session, cli->cli_parent)) { rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n"); free(buf); return -5; } else - Limit = sizeof(struct tagRPCRet); - if (rrpc->ret_tag != tag || rrpc->ret_hash != hash) { + Limit = sizeof(struct tagRPCCall); + if (rrpc->call_tag != tag || rrpc->call_hash != hash) { rpc_SetErr(ERPCMISMATCH, "Error:: get wrong RPC reply ...\n"); free(buf); return -5; } - if (ntohl(rrpc->ret_retcode) < 0 && ntohl(rrpc->ret_errno)) { - rpc_SetErr(ntohl(rrpc->ret_errno), "Error::Server side: retcode=%d #%d %s\n", - ntohl(rrpc->ret_retcode), ntohl(rrpc->ret_errno), - strerror(ntohl(rrpc->ret_errno))); + if (ntohl(rrpc->call_rep.ret) < 0 && ntohl(rrpc->call_rep.eno)) { + rpc_SetErr(ntohl(rrpc->call_rep.eno), "Error::Server side: retcode=%d #%d %s\n", + ntohl(rrpc->call_rep.ret), ntohl(rrpc->call_rep.eno), + strerror(ntohl(rrpc->call_rep.eno))); free(buf); return -6; } - if (ntohs(rrpc->ret_argc) * sizeof(ait_val_t) > cli->cli_netbuf - Limit) { + if (ntohs(rrpc->call_argc) * sizeof(ait_val_t) > cli->cli_netbuf - Limit) { rpc_SetErr(EMSGSIZE, "Error:: reply RPC packet is too long ...\n"); free(buf); return -7; } /* RPC is OK! Go de-marshaling variables ... */ - if (ntohs(rrpc->ret_argc)) { - *out_vars = io_buffer2vals(buf + Limit, cli->cli_netbuf - Limit, - ntohs(rrpc->ret_argc), 0); + if (ntohs(rrpc->call_argc)) { + *out_vars = io_buffer2vars(buf + Limit, cli->cli_netbuf - Limit, + ntohs(rrpc->call_argc), 0); if (!*out_vars) { free(buf); return -1; } } - ret = ntohl(rrpc->ret_retcode); + ret = ntohl(rrpc->call_rep.ret); free(buf); return ret; -} - -/* - * rpc_cli_freeVars() Free ait_val_t array returned from RPC call - * @vars = Variable array - * return: none - */ -inline void -rpc_cli_freeVars(array_t ** __restrict vars) -{ - register int i; - - if (!vars || !*vars) - return; - - for (i = 0; i < io_arraySize(*vars); i++) - if (io_arrayGet(*vars, i)) - AIT_FREE_VAL(io_array(*vars, i, ait_val_t*)); - - io_arrayFree(*vars); - io_arrayDestroy(vars); -} - -/* - * rpc_cli_allocVars() Allocate ait_val_t array for RPC call - * @args = Number of arguments - * return: =NULL error or !=NULL allocated array - */ -inline array_t * -rpc_cli_allocVars(u_short args) -{ - array_t *arr; - register int i; - ait_val_t *v; - - if (!args) - return NULL; - - if (!(arr = io_arrayInit(args))) - return NULL; - - for (i = 0; i < io_arraySize(arr); i++) { - v = malloc(sizeof(ait_val_t)); - if (!v) { - LOGERR; - rpc_cli_freeVars(&arr); - return NULL; - } else { - memset(v, 0, sizeof(ait_val_t)); - io_arraySet(arr, i, v); - } - } - - return arr; }