--- libaitrpc/src/cli.c 2011/10/31 14:45:26 1.5.2.4 +++ libaitrpc/src/cli.c 2011/11/03 15:32:21 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.5.2.4 2011/10/31 14:45:26 misho Exp $ +* $Id: cli.c,v 1.6 2011/11/03 15:32:21 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -65,8 +65,6 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to BLOB server ...\n"); return NULL; } - if (!Port) - Port = RPC_DEFPORT + 1; cli = malloc(sizeof(rpc_cli_t)); if (!cli) { @@ -76,12 +74,12 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, memcpy(cli, rpccli, sizeof(rpc_cli_t)); memcpy(&sa, &rpccli->cli_sa, sizeof sa); - switch (rpccli->cli_sa.sa.sa_family) { + switch (sa.sa.sa_family) { case AF_INET: - sa.sin.sin_port = htons(Port); + sa.sin.sin_port = htons(Port ? Port : ntohs(sa.sin.sin_port) + 1); break; case AF_INET6: - sa.sin6.sin6_port = htons(Port); + sa.sin6.sin6_port = htons(Port ? Port : ntohs(sa.sin6.sin6_port) + 1); break; case AF_LOCAL: strlcat(sa.sun.sun_path, ".blob", sizeof sa.sun.sun_path); @@ -109,7 +107,7 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, free(cli); return NULL; } - if (connect(cli->cli_sock, &cli->cli_sa.sa, sizeof cli->cli_sa) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { LOGERR; close(cli->cli_sock); free(cli); @@ -243,7 +241,7 @@ rpc_cli_openClient(u_int ProgID, u_int ProcID, int net free(cli); return NULL; } - if (connect(cli->cli_sock, &cli->cli_sa.sa, sizeof cli->cli_sa) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { LOGERR; close(cli->cli_sock); free(cli->cli_parent); @@ -323,14 +321,14 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, /* prepare RPC call */ rpc = (struct tagRPCCall*) buf; rpc_addPktSession(&rpc->call_session, cli->cli_parent); - rpc->call_argc = htons(in_vars ? io_arraySize(in_vars) : 0); + rpc->call_argc = htons(io_arraySize(in_vars)); rpc->call_tag = tag = htons(crcFletcher16((u_short*) str, sizeof str / 2)); rpc->call_hash = hash = htonl(hash_fnv((char*) str, sizeof str)); Limit = sizeof(struct tagRPCCall); - if (in_vars && io_arraySize(in_vars)) { + 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); @@ -387,7 +385,6 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, } else Limit = sizeof(struct tagRPCRet); if (rrpc->ret_tag != tag || rrpc->ret_hash != hash) { - printf("tag=%x/%x hash=%x/%x\n", rrpc->ret_tag, tag, rrpc->ret_hash, hash); rpc_SetErr(ERPCMISMATCH, "Error:: get wrong RPC reply ...\n"); free(buf); return -5; @@ -407,7 +404,7 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, /* RPC is OK! Go de-marshaling variables ... */ if (ntohs(rrpc->ret_argc)) { - *out_vars = io_buffer2vals(buf + Limit, cli->cli_netbuf - Limit, + *out_vars = io_buffer2vars(buf + Limit, cli->cli_netbuf - Limit, ntohs(rrpc->ret_argc), 0); if (!*out_vars) { free(buf); @@ -418,58 +415,4 @@ rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, ret = ntohl(rrpc->ret_retcode); free(buf); return ret; -} - -/* - * rpc_cli_freeVals() Free ait_val_t array returned from RPC call - * @vars = Variable array - * return: none - */ -inline void -rpc_cli_freeVals(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_allocVals() Allocate ait_val_t array for RPC call - * @args = Number of arguments - * return: =NULL error or !=NULL allocated array - */ -inline array_t * -rpc_cli_allocVals(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_freeVals(&arr); - return NULL; - } else { - memset(v, 0, sizeof(ait_val_t)); - io_arraySet(arr, i, v); - } - } - - return arr; }