version 1.1.1.1.2.2, 2010/06/18 15:47:33
|
version 1.9.2.9, 2012/05/17 14:22:24
|
Line 5
|
Line 5
|
* $Author$ |
* $Author$ |
* $Id$ |
* $Id$ |
* |
* |
*************************************************************************/ | ************************************************************************** |
| The ELWIX and AITNET software is distributed under the following |
| terms: |
| |
| All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the following conditions |
| are met: |
| 1. Redistributions of source code must retain the above copyright |
| notice, this list of conditions and the following disclaimer. |
| 2. Redistributions in binary form must reproduce the above copyright |
| notice, this list of conditions and the following disclaimer in the |
| documentation and/or other materials provided with the distribution. |
| 3. All advertising materials mentioning features or use of this software |
| must display the following acknowledgement: |
| This product includes software developed by Michael Pounov <misho@elwix.org> |
| ELWIX - Embedded LightWeight unIX and its contributors. |
| 4. Neither the name of AITNET nor the names of its contributors |
| may be used to endorse or promote products derived from this software |
| without specific prior written permission. |
| |
| THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND |
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| SUCH DAMAGE. |
| */ |
#include "global.h" |
#include "global.h" |
|
|
|
|
/* |
/* |
* rpc_cli_openClient() Connect to RPC Server | * rpc_cli_openBLOBClient() - Connect to BLOB Server |
* @ProgID = ProgramID for RPC session request | * |
* @ProcID = ProcessID for RPC session request | * @rpccli = RPC Client session |
* @family = Family socket type, AF_INET or AF_INET6 | |
* @csHost = Host name or IP address for bind server | |
* @Port = Port for bind server, if Port == 0 default port is selected |
* @Port = Port for bind server, if Port == 0 default port is selected |
* return: NULL == error or !=NULL connection to RPC server established | * return: NULL == error or !=NULL connection to BLOB server established |
*/ |
*/ |
rpc_cli_t * |
rpc_cli_t * |
rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short family, const char *csHost, u_short Port) | rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, u_short Port) |
{ |
{ |
rpc_cli_t *cli = NULL; |
rpc_cli_t *cli = NULL; |
struct hostent *host = NULL; |
|
struct sockaddr_in sin; |
|
struct sockaddr_in6 sin6; |
|
|
|
if (!csHost || (family != AF_INET && family != AF_INET6)) { | if (!rpccli) { |
rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to RPC server ...\n"); | rpc_SetErr(EINVAL, "Invalid parameters can`t connect to BLOB server"); |
return NULL; |
return NULL; |
} |
} |
if (!Port) | |
Port = RPC_DEFPORT; | cli = malloc(sizeof(rpc_cli_t)); |
if (csHost) { | if (!cli) { |
host = gethostbyname2(csHost, family); | LOGERR; |
if (!host) { | return NULL; |
rpc_SetErr(h_errno, "Error:: %s\n", hstrerror(h_errno)); | } else |
return NULL; | memcpy(cli, rpccli, sizeof(rpc_cli_t)); |
} | |
} | memcpy(&cli->cli_sa, &rpccli->cli_sa, sizeof(io_sockaddr_t)); |
switch (family) { | switch (cli->cli_sa.sa.sa_family) { |
case AF_INET: |
case AF_INET: |
memset(&sin, 0, sizeof sin); | cli->cli_sa.sin.sin_port = |
sin.sin_len = sizeof sin; | htons(Port ? Port : ntohs(cli->cli_sa.sin.sin_port) + 1); |
sin.sin_family = family; | |
sin.sin_port = htons(Port); | |
if (csHost) | |
memcpy(&sin.sin_addr, host->h_addr, host->h_length); | |
break; |
break; |
case AF_INET6: |
case AF_INET6: |
memset(&sin6, 0, sizeof sin6); | cli->cli_sa.sin6.sin6_port = |
sin6.sin6_len = sizeof sin6; | htons(Port ? Port : ntohs(cli->cli_sa.sin6.sin6_port) + 1); |
sin6.sin6_family = family; | |
sin6.sin6_port = htons(Port); | |
if (csHost) | |
memcpy(&sin6.sin6_addr, host->h_addr, host->h_length); | |
break; |
break; |
|
case AF_LOCAL: |
|
strlcat(cli->cli_sa.sun.sun_path, ".blob", sizeof cli->cli_sa.sun.sun_path); |
|
break; |
default: |
default: |
rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to RPC server ...\n"); | rpc_SetErr(EINVAL, "Invalid socket type %d", cli->cli_sa.sa.sa_family); |
return NULL; |
return NULL; |
} |
} |
|
|
|
AIT_COPY_VAL(&cli->cli_buf, &rpccli->cli_buf); |
|
|
|
/* connect to BLOB server */ |
|
cli->cli_sock = socket(cli->cli_sa.sa.sa_family, SOCK_STREAM, 0); |
|
if (cli->cli_sock == -1) { |
|
LOGERR; |
|
free(cli); |
|
return NULL; |
|
} |
|
if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { |
|
LOGERR; |
|
close(cli->cli_sock); |
|
free(cli); |
|
return NULL; |
|
} |
|
|
|
return cli; |
|
} |
|
|
|
/* |
|
* rpc_cli_closeBLOBClient() - Close connection to BLOB server and free resources |
|
* |
|
* @cli = BLOB Client session |
|
* return: none |
|
*/ |
|
void |
|
rpc_cli_closeBLOBClient(rpc_cli_t ** __restrict cli) |
|
{ |
|
if (!cli || !*cli) |
|
return; |
|
|
|
shutdown((*cli)->cli_sock, SHUT_RDWR); |
|
close((*cli)->cli_sock); |
|
|
|
AIT_FREE_VAL(&(*cli)->cli_buf); |
|
|
|
free(*cli); |
|
*cli = NULL; |
|
} |
|
|
|
/* -------------------------------------------------------------- */ |
|
|
|
/* |
|
* rpc_cli_openClient() - Connect to RPC Server |
|
* |
|
* @ProgID = ProgramID for RPC session request |
|
* @ProcID = ProcessID for RPC session request |
|
* @netBuf = Network buffer length, if =0 == BUFSIZ (also meaning max RPC packet) |
|
* @csHost = Host name or IP address for bind server |
|
* @Port = Port for bind server, if Port == 0 default port is selected |
|
* return: NULL == error or !=NULL connection to RPC server established |
|
*/ |
|
rpc_cli_t * |
|
rpc_cli_openClient(u_int ProgID, u_char ProcID, int netBuf, const char *csHost, u_short Port) |
|
{ |
|
rpc_cli_t *cli = NULL; |
|
io_sockaddr_t sa; |
|
|
|
if (!io_gethostbyname(csHost, Port, &sa)) |
|
return NULL; |
|
if (!Port) |
|
Port = RPC_DEFPORT; |
|
if (!netBuf) |
|
netBuf = BUFSIZ; |
|
|
|
#ifdef HAVE_SRANDOMDEV |
|
srandomdev(); |
|
#else |
|
time_t tim; |
|
|
|
srandom((time(&tim) ^ getpid())); |
|
#endif |
|
|
cli = malloc(sizeof(rpc_cli_t)); |
cli = malloc(sizeof(rpc_cli_t)); |
if (!cli) { |
if (!cli) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
} else |
} else |
memset(cli, 0, sizeof(rpc_cli_t)); |
memset(cli, 0, sizeof(rpc_cli_t)); |
|
|
|
/* build session */ |
cli->cli_parent = malloc(sizeof(rpc_sess_t)); |
cli->cli_parent = malloc(sizeof(rpc_sess_t)); |
if (!cli->cli_parent) { |
if (!cli->cli_parent) { |
LOGERR; |
LOGERR; |
Line 78 rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short
|
Line 180 rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short
|
((rpc_sess_t*) cli->cli_parent)->sess_process = ProcID; |
((rpc_sess_t*) cli->cli_parent)->sess_process = ProcID; |
} |
} |
|
|
if (family == AF_INET) | memcpy(&cli->cli_sa, &sa, sizeof cli->cli_sa); |
memcpy(&cli->cli_sa, &sin, sizeof cli->cli_sa); | AIT_SET_BUF2(&cli->cli_buf, 0, netBuf); |
else | |
memcpy(&cli->cli_sa, &sin6, sizeof cli->cli_sa); | /* connect to RPC server */ |
cli->cli_sock = socket(family, SOCK_STREAM, 0); | cli->cli_sock = socket(cli->cli_sa.sa.sa_family, SOCK_STREAM, 0); |
if (cli->cli_sock == -1) { |
if (cli->cli_sock == -1) { |
LOGERR; |
LOGERR; |
|
AIT_FREE_VAL(&cli->cli_buf); |
free(cli->cli_parent); |
free(cli->cli_parent); |
free(cli); |
free(cli); |
return NULL; |
return NULL; |
} |
} |
if (connect(cli->cli_sock, &cli->cli_sa, sizeof cli->cli_sa) == -1) { | if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { |
LOGERR; |
LOGERR; |
|
AIT_FREE_VAL(&cli->cli_buf); |
|
close(cli->cli_sock); |
free(cli->cli_parent); |
free(cli->cli_parent); |
free(cli); |
free(cli); |
return NULL; |
return NULL; |
Line 100 rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short
|
Line 205 rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short
|
} |
} |
|
|
/* |
/* |
* rpc_cli_closeClient() Close connection to RPC server and free resources | * rpc_cli_closeClient() - Close connection to RPC server and free resources |
| * |
* @cli = RPC Client session |
* @cli = RPC Client session |
* return: none |
* return: none |
*/ |
*/ |
void |
void |
rpc_cli_closeClient(rpc_cli_t * __restrict cli) | rpc_cli_closeClient(rpc_cli_t ** __restrict cli) |
{ |
{ |
if (!cli) { | if (!cli || !*cli) |
rpc_SetErr(EINVAL, "Error:: Can`t close connection because parameter is null!\n"); | |
return; |
return; |
} |
|
|
|
shutdown(cli->cli_sock, SHUT_RDWR); | shutdown((*cli)->cli_sock, SHUT_RDWR); |
close(cli->cli_sock); | close((*cli)->cli_sock); |
|
|
if (cli->cli_parent) | AIT_FREE_VAL(&(*cli)->cli_buf); |
free(cli->cli_parent); | |
free(cli); | if ((*cli)->cli_parent) |
cli = NULL; | free((*cli)->cli_parent); |
| |
| free(*cli); |
| *cli = NULL; |
} |
} |
|
|
|
|
/* |
/* |
* rpc_cli_execCall() Execute RPC call | * rpc_cli_execCall() - Execute RPC call |
| * |
* @cli = RPC Client session |
* @cli = RPC Client session |
* @csModule = Module name, if NULL self binary | * @noreply = We not want RPC reply |
* @csFunc = Function name for execute | * @tag = Function tag for execution |
* @in_argc = IN count of arguments | * @in_vars = IN RPC call array of rpc values, may be NULL |
* @in_vals = IN RPC call array of rpc values | * @out_vars = OUT returned array of rpc values, if !=NULL must be free after use with io_freeVars() |
* @out_argc = OUT returned count of arguments | |
* @out_vals = OUT returned array of rpc values, must be free after use (see rpc_cli_freeVals()) | |
* return: -1 error or != -1 ok result |
* return: -1 error or != -1 ok result |
*/ |
*/ |
int |
int |
rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, const char *csFunc, int in_argc, | rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short tag, |
rpc_val_t * __restrict in_vals, int *out_argc, rpc_val_t ** __restrict out_vals) | array_t * __restrict in_vars, array_t ** __restrict out_vars) |
{ |
{ |
fd_set fds; | struct tagRPCCall *rpc; |
u_char buf[BUFSIZ], str[MAXPATHLEN + UCHAR_MAX + 1], *data; | int ret = 0, wlen = sizeof(struct tagRPCCall); |
struct tagRPCCall *rpc = (struct tagRPCCall*) buf; | uint16_t crc; |
struct tagRPCRet *rrpc; | u_char *buf; |
int ret = 0, Limit = 0; | struct pollfd pfd; |
register int i; | |
rpc_val_t *v; | |
struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; | |
|
|
FD_ZERO(&fds); | if (!cli) { |
memset(buf, 0, BUFSIZ); | rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!"); |
memset(str, 0, MAXPATHLEN + UCHAR_MAX + 1); | |
if (!cli || !csFunc || (in_argc && !in_vals)) { | |
rpc_SetErr(EINVAL, "Error:: Can`t execute call because parameter is null or invalid!\n"); | |
return -1; |
return -1; |
} | } else |
if (csModule) | buf = AIT_GET_BUF(&cli->cli_buf); |
strlcpy((char*) str, csModule, MAXPATHLEN + UCHAR_MAX + 1); | if (out_vars) |
strlcat((char*) str, "__", MAXPATHLEN + UCHAR_MAX + 1); | *out_vars = NULL; |
strlcat((char*) str, csFunc, MAXPATHLEN + UCHAR_MAX + 1); | |
|
|
memcpy(&rpc->call_session, cli->cli_parent, sizeof rpc->call_session); | /* prepare RPC call */ |
rpc->call_argc = in_argc; | rpc = (struct tagRPCCall*) buf; |
rpc->call_tag = crcFletcher16((u_short*) str, (MAXPATHLEN + UCHAR_MAX + 1) / 2); | rpc_addPktSession(&rpc->call_session, cli->cli_parent); |
rpc->call_hash = hash_fnv((char*) str, MAXPATHLEN + UCHAR_MAX + 1); | rpc->call_argc = htons(io_arraySize(in_vars)); |
Limit = sizeof(struct tagRPCCall); | rpc->call_tag = htons(tag); |
if (in_argc) { | rpc->call_seq = htons(random() % USHRT_MAX); |
v = (rpc_val_t*) (buf + sizeof(struct tagRPCCall)); | |
memcpy(v, in_vals, in_argc * sizeof(rpc_val_t)); | |
Limit += in_argc * sizeof(rpc_val_t); | |
data = (u_char*) v + in_argc * sizeof(rpc_val_t); | |
for (i = 0; i < in_argc; i++) { | |
switch (in_vals[i].val_type) { | |
case buffer: | |
if (Limit + in_vals[i].val_len > BUFSIZ) { | |
ret = -7; | |
break; | |
} | |
|
|
memcpy(data, in_vals[i].val.buffer, in_vals[i].val_len); | /* set reply */ |
v[i].val.buffer = (uint8_t*) ((void*) data - (void*) v); | rpc->call_req.flags = noreply ? RPC_NOREPLY : RPC_REPLY; |
data += in_vals[i].val_len; | |
Limit += in_vals[i].val_len; | |
break; | |
case string: | |
if (Limit + in_vals[i].val_len + 1 > BUFSIZ) { | |
ret = -7; | |
break; | |
} | |
|
|
memcpy(data, in_vals[i].val.string, in_vals[i].val_len); | if (io_arraySize(in_vars)) { |
v[i].val.string = (int8_t*) ((void*) data - (void*) v); | /* marshaling variables */ |
data += in_vals[i].val_len; | ret = io_vars2buffer(buf + wlen, AIT_LEN(&cli->cli_buf) - wlen, in_vars); |
Limit += in_vals[i].val_len; | if (ret == -1) { |
break; | rpc_SetErr(EBADRPC, "Failed to prepare RPC packet values"); |
case array: | return -1; |
if (Limit + in_vals[i].val_len > BUFSIZ) { | } else |
ret = -7; | wlen += ret; |
break; | |
} | |
| |
memcpy(data, in_vals[i].val.array, in_vals[i].val_len); | |
v[i].val.array = (int8_t**) ((void*) data - (void*) v); | |
data += in_vals[i].val_len; | |
Limit += in_vals[i].val_len; | |
break; | |
default: | |
break; | |
} | |
} | |
if (ret < 0) { | |
rpc_SetErr(EMSGSIZE, "Error:: in prepare RPC packet (-7) ...\n"); | |
return ret; | |
} | |
} |
} |
if ((ret = send(cli->cli_sock, buf, Limit, 0)) == -1) { | |
| /* total packet length */ |
| rpc->call_len = htons(wlen); |
| |
| /* calculate CRC */ |
| rpc->call_crc ^= rpc->call_crc; |
| rpc->call_crc = htons(crcFletcher16((u_short*) buf, wlen / 2)); |
| |
| if ((ret = send(cli->cli_sock, buf, wlen, MSG_NOSIGNAL)) == -1) { |
LOGERR; |
LOGERR; |
return -1; |
return -1; |
|
} else if (ret != wlen) { |
|
rpc_SetErr(EPROCUNAVAIL, "RPC request, should be send %d bytes, " |
|
"really sended %d bytes", wlen, ret); |
|
return -1; |
} |
} |
if (ret != Limit) { |
|
rpc_SetErr(EBADMSG, "Error:: in send RPC request, should be send %d bytes, really is %d\n", |
|
Limit, ret); |
|
return -9; |
|
} |
|
|
|
FD_SET(cli->cli_sock, &fds); | if (noreply) /* we not want reply */ |
if ((ret = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) < 1) { | return 0; |
if (ret) { | |
| /* reply from RPC server */ |
| pfd.fd = cli->cli_sock; |
| pfd.events = POLLIN | POLLPRI; |
| if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || |
| pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
| if (ret) |
LOGERR; |
LOGERR; |
} else | else |
rpc_SetErr(ETIMEDOUT, "Error:: timeout, no return from RPC server?\n"); | rpc_SetErr(ETIMEDOUT, "Timeout, no answer from RPC server"); |
| |
return -1; |
return -1; |
} |
} |
memset(buf, 0, BUFSIZ); | memset(buf, 0, AIT_LEN(&cli->cli_buf)); |
if ((ret = recv(cli->cli_sock, buf, BUFSIZ, 0)) == -1) { | if ((ret = recv(cli->cli_sock, buf, AIT_LEN(&cli->cli_buf), 0)) < 1) { |
LOGERR; | if (ret) |
return -3; | LOGERR; |
| return -1; |
} |
} |
if (!ret) // receive EOF |
|
return 0; |
|
if (ret < sizeof(struct tagRPCCall)) { |
if (ret < sizeof(struct tagRPCCall)) { |
rpc_SetErr(EMSGSIZE, "Error:: too short RPC packet ...\n"); | rpc_SetErr(ERPCMISMATCH, "Short RPC packet"); |
return -4; | return -1; |
| } |
| |
| /* calculate CRC */ |
| crc = ntohs(rpc->call_crc); |
| rpc->call_crc ^= rpc->call_crc; |
| if (crc != crcFletcher16((u_short*) buf, ret / 2)) { |
| rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); |
| return -1; |
| } |
| |
| /* check RPC packet session info */ |
| if (rpc_chkPktSession(&rpc->call_session, cli->cli_parent)) { |
| rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); |
| return -1; |
} else |
} else |
rrpc = (struct tagRPCRet*) buf; | wlen = sizeof(struct tagRPCCall); |
// check RPC packet session info | if (ntohs(rpc->call_tag) != tag) { |
if (memcmp(&rrpc->ret_session, cli->cli_parent, sizeof rrpc->ret_session)) { | rpc_SetErr(ERPCMISMATCH, "Get wrong RPC reply"); |
rpc_SetErr(EINVAL, "Error:: get invalid RPC session ...\n"); | return -1; |
return -5; | |
} |
} |
if (rrpc->ret_retcode < 0 && rrpc->ret_errno) { | if (ntohl(rpc->call_rep.eno) && ntohl(rpc->call_rep.ret) == -1) { |
rpc_SetErr(rrpc->ret_errno, "Error::Server side: %s\n", strerror(rrpc->ret_errno)); | rpc_SetErr(ntohl(rpc->call_rep.eno), "Server side: retcode=%d #%d %s", |
return -6; | ntohl(rpc->call_rep.ret), ntohl(rpc->call_rep.eno), |
| strerror(ntohl(rpc->call_rep.eno))); |
| return -1; |
} |
} |
// RPC is OK! Go decapsulate variables ... | if (ntohs(rpc->call_argc) * sizeof(ait_val_t) > AIT_LEN(&cli->cli_buf) - wlen) { |
if (rrpc->ret_argc) { | rpc_SetErr(EMSGSIZE, "Reply RPC packet is too long ..."); |
*out_argc = rrpc->ret_argc; | return -1; |
*out_vals = calloc(rrpc->ret_argc, sizeof(rpc_val_t)); | } |
if (!*out_vals) { | |
LOGERR; | /* RPC is OK! Go de-marshaling variables ... */ |
*out_argc = 0; | if (out_vars && ntohs(rpc->call_argc)) { |
| *out_vars = io_buffer2vars(buf + wlen, AIT_LEN(&cli->cli_buf) - wlen, |
| ntohs(rpc->call_argc), 0); |
| if (!*out_vars) { |
| rpc_SetErr(io_GetErrno(), "%s", io_GetError()); |
return -1; |
return -1; |
} else | } |
Limit = rrpc->ret_argc * sizeof(rpc_val_t); | |
memcpy(*out_vals, buf + sizeof(struct tagRPCRet), Limit); | |
// RPC received variables types OK! | |
data = (u_char*) buf + sizeof(struct tagRPCRet) + Limit; | |
for (i = 0; i < rrpc->ret_argc; i++) | |
switch ((*out_vals)[i].val_type) { | |
case buffer: | |
(*out_vals)[i].val.buffer = malloc((*out_vals)[i].val_len); | |
if (!(*out_vals)[i].val.buffer) { | |
rpc_SetErr(errno, "Error:: in prepare RPC reply ...\n"); | |
free(*out_vals); | |
*out_vals = NULL; | |
*out_argc = 0; | |
return -1; | |
} else | |
memcpy((*out_vals)[i].val.buffer, data, (*out_vals)[i].val_len); | |
data += (*out_vals)[i].val_len; | |
break; | |
case string: | |
(*out_vals)[i].val.string = (int8_t*) strdup((char*) data); | |
if (!(*out_vals)[i].val.string) { | |
rpc_SetErr(errno, "Error:: in prepare RPC reply ...\n"); | |
free(*out_vals); | |
*out_vals = NULL; | |
*out_argc = 0; | |
return -1; | |
} | |
data += (*out_vals)[i].val_len + 1; | |
break; | |
case array: | |
(*out_vals)[i].val.array = malloc((*out_vals)[i].val_len); | |
if (!(*out_vals)[i].val.array) { | |
rpc_SetErr(errno, "Error:: in prepare RPC reply ...\n"); | |
free(*out_vals); | |
*out_vals = NULL; | |
*out_argc = 0; | |
return -1; | |
} else | |
memcpy((*out_vals)[i].val.array, data, (*out_vals)[i].val_len); | |
data += (*out_vals)[i].val_len; | |
break; | |
default: | |
break; | |
} | |
} else { | |
if (out_argc) | |
*out_argc = 0; | |
if (out_vals) | |
*out_vals = NULL; | |
} |
} |
|
|
return rrpc->ret_retcode; | ret = ntohl(rpc->call_rep.ret); |
| return ret; |
} |
} |
|
|
/* |
/* |
* rpc_cli_freeVals() Free rpc_val_t array returned from RPC call | * rpc_cli_ping() - Ping RPC server |
* @args = Number of arguments in array | * |
* @vals = Value elements | * @cli = connected client |
* return: none | * return: -1 error or !=-1 ping seq id |
*/ |
*/ |
inline void | inline int |
rpc_cli_freeVals(int args, rpc_val_t *vals) | rpc_cli_ping(rpc_cli_t *cli) |
{ |
{ |
register int i; | array_t *arr; |
| int ret = 0; |
|
|
if (!vals) | if (!cli) |
return; | return -1; |
|
|
for (i = 0; i < args; i++) | if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVPING, NULL, &arr)) |
RPC_FREE_VAL(&vals[i]); | return -1; |
| else |
| ret = AIT_GET_U16(io_getVars(arr, 0)); |
| io_freeVars(&arr); |
|
|
free(vals); | return ret; |
vals = NULL; | |
} |
} |