Annotation of libaitrpc/src/cli.c, revision 1.4.2.3
1.1 misho 1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.4.2.3 ! misho 6: * $Id: cli.c,v 1.4.2.2 2011/08/30 11:13:29 misho Exp $
1.1 misho 7: *
1.2 misho 8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
1.1 misho 46: #include "global.h"
47:
48:
49: /*
1.2 misho 50: * rpc_cli_openBLOBClient() Connect to BLOB Server
51: * @rpccli = RPC Client session
52: * @Port = Port for bind server, if Port == 0 default port is selected
53: * return: NULL == error or !=NULL connection to BLOB server established
54: */
55: rpc_cli_t *
56: rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, u_short Port)
57: {
58: rpc_cli_t *cli = NULL;
1.4 misho 59: struct sockaddr sa;
60: struct sockaddr_in *sin = (struct sockaddr_in*) &sa;
61: struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) &sa;
62: struct sockaddr_un *sun = (struct sockaddr_un*) &sa;
1.4.2.2 misho 63: int n;
1.4 misho 64:
65: if (!rpccli ||
66: (rpccli->cli_sa.sa_family != AF_INET && rpccli->cli_sa.sa_family != AF_INET6 &&
67: rpccli->cli_sa.sa_family != AF_LOCAL)) {
1.2 misho 68: rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to BLOB server ...\n");
69: return NULL;
70: }
71: if (!Port)
72: Port = RPC_DEFPORT + 1;
73:
74: cli = malloc(sizeof(rpc_cli_t));
75: if (!cli) {
76: LOGERR;
77: return NULL;
78: } else
79: memcpy(cli, rpccli, sizeof(rpc_cli_t));
80:
1.4 misho 81: memcpy(&sa, &rpccli->cli_sa, sizeof sa);
82: switch (rpccli->cli_sa.sa_family) {
83: case AF_INET:
84: sin->sin_port = htons(Port);
85: memcpy(&cli->cli_sa, sin, sizeof(struct sockaddr));
86: break;
87: case AF_INET6:
88: sin6->sin6_port = htons(Port);
89: memcpy(&cli->cli_sa, sin6, sizeof(struct sockaddr));
90: break;
91: case AF_LOCAL:
92: strlcat(sun->sun_path, ".blob", sizeof sun->sun_path);
93: memcpy(&cli->cli_sa, sun, sizeof(struct sockaddr));
94: break;
1.2 misho 95: }
96:
1.4 misho 97: /* connect to BLOB server */
1.2 misho 98: cli->cli_sock = socket(cli->cli_sa.sa_family, SOCK_STREAM, 0);
99: if (cli->cli_sock == -1) {
100: LOGERR;
101: free(cli);
102: return NULL;
103: }
1.4.2.2 misho 104: n = cli->cli_netbuf;
105: if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n) == -1) {
106: LOGERR;
107: close(cli->cli_sock);
108: free(cli->cli_parent);
109: free(cli);
110: return NULL;
111: }
112: if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof n) == -1) {
113: LOGERR;
114: close(cli->cli_sock);
115: free(cli->cli_parent);
116: free(cli);
117: return NULL;
118: }
1.2 misho 119: if (connect(cli->cli_sock, &cli->cli_sa, sizeof cli->cli_sa) == -1) {
120: LOGERR;
121: free(cli);
122: return NULL;
123: }
124:
125: return cli;
126: }
127:
128: /*
129: * rpc_cli_closeBLOBClient() Close connection to BLOB server and free resources
130: * @cli = BLOB Client session
131: * return: none
132: */
133: void
134: rpc_cli_closeBLOBClient(rpc_cli_t * __restrict cli)
135: {
136: if (!cli) {
137: rpc_SetErr(EINVAL, "Error:: Can`t close connection because parameter is null!\n");
138: return;
139: }
140:
141: shutdown(cli->cli_sock, SHUT_RDWR);
142: close(cli->cli_sock);
143:
144: free(cli);
145: cli = NULL;
146: }
147:
148: // --------------------------------------------------------------
149:
150: /*
1.1 misho 151: * rpc_cli_openClient() Connect to RPC Server
152: * @ProgID = ProgramID for RPC session request
153: * @ProcID = ProcessID for RPC session request
1.4.2.2 misho 154: * @netBuf = Network buffer length, if =0 == BUFSIZ (also meaning max RPC packet)
1.1 misho 155: * @family = Family socket type, AF_INET or AF_INET6
156: * @csHost = Host name or IP address for bind server
157: * @Port = Port for bind server, if Port == 0 default port is selected
158: * return: NULL == error or !=NULL connection to RPC server established
159: */
160: rpc_cli_t *
1.4.2.2 misho 161: rpc_cli_openClient(u_int ProgID, u_int ProcID, int netBuf, u_short family, const char *csHost, u_short Port)
1.1 misho 162: {
163: rpc_cli_t *cli = NULL;
164: struct hostent *host = NULL;
1.4 misho 165: struct sockaddr sa;
166: struct sockaddr_in *sin = (struct sockaddr_in*) &sa;
167: struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) &sa;
168: struct sockaddr_un *sun = (struct sockaddr_un*) &sa;
1.4.2.2 misho 169: int n;
1.1 misho 170:
1.4 misho 171: if (!csHost || (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) {
1.1 misho 172: rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to RPC server ...\n");
173: return NULL;
174: }
175: if (!Port)
176: Port = RPC_DEFPORT;
1.4.2.2 misho 177: if (!netBuf)
178: netBuf = BUFSIZ;
1.4 misho 179: if (csHost && family != AF_LOCAL) {
1.1 misho 180: host = gethostbyname2(csHost, family);
181: if (!host) {
182: rpc_SetErr(h_errno, "Error:: %s\n", hstrerror(h_errno));
183: return NULL;
184: }
185: }
1.4 misho 186: memset(&sa, 0, sizeof sa);
187: sa.sa_family = family;
1.1 misho 188: switch (family) {
189: case AF_INET:
1.4 misho 190: sin->sin_len = sizeof(struct sockaddr_in);
191: sin->sin_port = htons(Port);
1.1 misho 192: if (csHost)
1.4 misho 193: memcpy(&sin->sin_addr, host->h_addr, host->h_length);
1.1 misho 194: break;
195: case AF_INET6:
1.4 misho 196: sin6->sin6_len = sizeof(struct sockaddr_in6);
197: sin6->sin6_port = htons(Port);
1.1 misho 198: if (csHost)
1.4 misho 199: memcpy(&sin6->sin6_addr, host->h_addr, host->h_length);
200: break;
201: case AF_LOCAL:
202: sun->sun_len = sizeof(struct sockaddr_un);
203: if (csHost)
204: strlcpy(sun->sun_path, csHost, sizeof sun->sun_path);
1.1 misho 205: break;
206: default:
207: rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t connect to RPC server ...\n");
208: return NULL;
209: }
210:
211: cli = malloc(sizeof(rpc_cli_t));
212: if (!cli) {
213: LOGERR;
214: return NULL;
215: } else
216: memset(cli, 0, sizeof(rpc_cli_t));
1.4.2.2 misho 217:
218: cli->cli_netbuf = netBuf;
1.1 misho 219: cli->cli_parent = malloc(sizeof(rpc_sess_t));
220: if (!cli->cli_parent) {
221: LOGERR;
222: free(cli);
223: return NULL;
224: } else {
225: ((rpc_sess_t*) cli->cli_parent)->sess_version = RPC_VERSION;
226: ((rpc_sess_t*) cli->cli_parent)->sess_program = ProgID;
227: ((rpc_sess_t*) cli->cli_parent)->sess_process = ProcID;
228: }
229:
1.4 misho 230: switch (family) {
231: case AF_INET:
232: memcpy(&cli->cli_sa, sin, sizeof cli->cli_sa);
233: break;
234: case AF_INET6:
235: memcpy(&cli->cli_sa, sin6, sizeof cli->cli_sa);
236: break;
237: case AF_LOCAL:
238: memcpy(&cli->cli_sa, sun, sizeof cli->cli_sa);
239: break;
240: }
241:
242: /* connect to RPC server */
1.1 misho 243: cli->cli_sock = socket(family, SOCK_STREAM, 0);
244: if (cli->cli_sock == -1) {
245: LOGERR;
246: free(cli->cli_parent);
247: free(cli);
248: return NULL;
249: }
1.4.2.2 misho 250: n = cli->cli_netbuf;
251: if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n) == -1) {
252: LOGERR;
253: close(cli->cli_sock);
254: free(cli->cli_parent);
255: free(cli);
256: return NULL;
257: }
258: if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof n) == -1) {
259: LOGERR;
260: close(cli->cli_sock);
261: free(cli->cli_parent);
262: free(cli);
263: return NULL;
264: }
1.1 misho 265: if (connect(cli->cli_sock, &cli->cli_sa, sizeof cli->cli_sa) == -1) {
266: LOGERR;
1.4.2.2 misho 267: close(cli->cli_sock);
1.1 misho 268: free(cli->cli_parent);
269: free(cli);
270: return NULL;
271: }
272:
273: return cli;
274: }
275:
276: /*
277: * rpc_cli_closeClient() Close connection to RPC server and free resources
278: * @cli = RPC Client session
279: * return: none
280: */
281: void
282: rpc_cli_closeClient(rpc_cli_t * __restrict cli)
283: {
284: if (!cli) {
285: rpc_SetErr(EINVAL, "Error:: Can`t close connection because parameter is null!\n");
286: return;
287: }
288:
289: shutdown(cli->cli_sock, SHUT_RDWR);
290: close(cli->cli_sock);
291:
292: if (cli->cli_parent)
293: free(cli->cli_parent);
294: free(cli);
295: cli = NULL;
296: }
297:
298:
299: /*
300: * rpc_cli_execCall() Execute RPC call
301: * @cli = RPC Client session
302: * @csModule = Module name, if NULL self binary
303: * @csFunc = Function name for execute
304: * @in_argc = IN count of arguments
1.4 misho 305: * @in_vars = IN RPC call array of rpc values
1.1 misho 306: * @out_argc = OUT returned count of arguments
1.4 misho 307: * @out_vars = OUT returned array of rpc values, must be free after use (see rpc_cli_freeVals())
1.1 misho 308: * return: -1 error or != -1 ok result
309: */
310: int
311: rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, const char *csFunc, int in_argc,
1.4.2.1 misho 312: ait_val_t * __restrict in_vars, int *out_argc, ait_val_t ** __restrict out_vars)
1.1 misho 313: {
314: fd_set fds;
1.4.2.3 ! misho 315: u_char *buf, str[MAXPATHLEN + UCHAR_MAX + 1], *data;
! 316: struct tagRPCCall *rpc;
1.3 misho 317: struct tagRPCRet *rrpc = NULL;
1.1 misho 318: int ret = 0, Limit = 0;
319: register int i;
1.4.2.1 misho 320: ait_val_t *v;
1.2 misho 321: struct timeval tv = { DEF_RPC_TIMEOUT, 0 };
1.1 misho 322:
1.4 misho 323: if (!cli || !csFunc || (in_argc && !in_vars)) {
1.1 misho 324: rpc_SetErr(EINVAL, "Error:: Can`t execute call because parameter is null or invalid!\n");
325: return -1;
326: }
1.4.2.3 ! misho 327:
! 328: buf = malloc(cli->cli_netbuf);
! 329: if (!buf) {
! 330: LOGERR;
! 331: return -1;
! 332: } else
! 333: memset(buf, 0, cli->cli_netbuf);
! 334:
1.4 misho 335: /* build RPC call string for hash */
1.4.2.3 ! misho 336: memset(str, 0, sizeof str);
1.1 misho 337: if (csModule)
1.4 misho 338: strlcpy((char*) str, csModule, sizeof str);
339: strlcat((char*) str, "__", sizeof str);
340: strlcat((char*) str, csFunc, sizeof str);
1.1 misho 341:
1.4 misho 342: /* prepare RPC call */
1.4.2.3 ! misho 343: rpc = (struct tagRPCCall*) buf;
1.1 misho 344: memcpy(&rpc->call_session, cli->cli_parent, sizeof rpc->call_session);
345: rpc->call_argc = in_argc;
1.4 misho 346: rpc->call_tag = crcFletcher16((u_short*) str, sizeof str / 2);
347: rpc->call_hash = hash_fnv((char*) str, sizeof str);
1.1 misho 348: Limit = sizeof(struct tagRPCCall);
1.4.2.3 ! misho 349:
1.1 misho 350: if (in_argc) {
1.4.2.3 ! misho 351: /* marshaling variables */
1.4.2.1 misho 352: v = (ait_val_t*) (buf + sizeof(struct tagRPCCall));
1.4.2.3 ! misho 353: if (in_argc * sizeof(ait_val_t) > cli->cli_netbuf - Limit) {
1.3 misho 354: rpc_SetErr(EMSGSIZE, "Error:: in prepare RPC packet values (-7) ...\n");
1.4.2.3 ! misho 355: free(buf);
1.3 misho 356: return -7;
357: } else
1.4.2.1 misho 358: Limit += in_argc * sizeof(ait_val_t);
359: memcpy(v, in_vars, in_argc * sizeof(ait_val_t));
1.4.2.3 ! misho 360:
! 361: /* adding additional data */
1.4.2.1 misho 362: data = (u_char*) v + in_argc * sizeof(ait_val_t);
1.4 misho 363: for (i = 0; i < in_argc && !ret; i++) {
1.4.2.3 ! misho 364: switch (AIT_TYPE(&in_vars[i])) {
1.1 misho 365: case buffer:
1.4.2.3 ! misho 366: if (Limit + AIT_LEN(&in_vars[i]) > cli->cli_netbuf) {
1.1 misho 367: ret = -7;
368: break;
369: }
370:
1.4.2.3 ! misho 371: memcpy(data, in_vars[i].val.buffer, AIT_LEN(&in_vars[i]));
1.1 misho 372: v[i].val.buffer = (uint8_t*) ((void*) data - (void*) v);
1.4.2.3 ! misho 373: data += AIT_LEN(&in_vars[i]);
! 374: Limit += AIT_LEN(&in_vars[i]);
1.1 misho 375: break;
376: case string:
1.4.2.3 ! misho 377: if (Limit + AIT_LEN(&in_vars[i]) > cli->cli_netbuf) {
1.1 misho 378: ret = -7;
379: break;
380: }
381:
1.4.2.3 ! misho 382: memcpy(data, in_vars[i].val.string, AIT_LEN(&in_vars[i]));
1.1 misho 383: v[i].val.string = (int8_t*) ((void*) data - (void*) v);
1.4.2.3 ! misho 384: data += AIT_LEN(&in_vars[i]);
! 385: Limit += AIT_LEN(&in_vars[i]);
1.1 misho 386: break;
387: default:
388: break;
389: }
390: }
391: if (ret < 0) {
392: rpc_SetErr(EMSGSIZE, "Error:: in prepare RPC packet (-7) ...\n");
1.4.2.3 ! misho 393: free(buf);
1.1 misho 394: return ret;
395: }
396: }
1.4 misho 397:
1.1 misho 398: if ((ret = send(cli->cli_sock, buf, Limit, 0)) == -1) {
399: LOGERR;
1.4.2.3 ! misho 400: free(buf);
1.1 misho 401: return -1;
402: }
403: if (ret != Limit) {
1.2 misho 404: rpc_SetErr(ECANCELED, "Error:: in send RPC request, should be send %d bytes, really is %d\n",
1.1 misho 405: Limit, ret);
1.4.2.3 ! misho 406: free(buf);
1.1 misho 407: return -9;
408: }
409:
1.4.2.3 ! misho 410: /* reply from RPC server */
! 411: FD_ZERO(&fds);
1.1 misho 412: FD_SET(cli->cli_sock, &fds);
413: if ((ret = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) < 1) {
1.4 misho 414: if (ret)
1.1 misho 415: LOGERR;
1.4 misho 416: else
1.1 misho 417: rpc_SetErr(ETIMEDOUT, "Error:: timeout, no return from RPC server?\n");
1.4 misho 418:
1.4.2.3 ! misho 419: free(buf);
1.1 misho 420: return -1;
421: }
1.4.2.3 ! misho 422: memset(buf, 0, cli->cli_netbuf);
! 423: if ((ret = recv(cli->cli_sock, buf, cli->cli_netbuf, 0)) == -1) {
1.1 misho 424: LOGERR;
1.4.2.3 ! misho 425: free(buf);
1.1 misho 426: return -3;
427: }
1.4.2.3 ! misho 428: if (!ret) { /* receive EOF! */
! 429: free(buf);
1.1 misho 430: return 0;
1.4.2.3 ! misho 431: }
1.2 misho 432: if (ret < sizeof(struct tagRPCRet)) {
1.1 misho 433: rpc_SetErr(EMSGSIZE, "Error:: too short RPC packet ...\n");
1.4.2.3 ! misho 434: free(buf);
1.1 misho 435: return -4;
436: } else
437: rrpc = (struct tagRPCRet*) buf;
1.3 misho 438: /* check RPC packet session info */
1.1 misho 439: if (memcmp(&rrpc->ret_session, cli->cli_parent, sizeof rrpc->ret_session)) {
440: rpc_SetErr(EINVAL, "Error:: get invalid RPC session ...\n");
1.4.2.3 ! misho 441: free(buf);
1.1 misho 442: return -5;
1.2 misho 443: } else
444: Limit = sizeof(struct tagRPCRet);
1.1 misho 445: if (rrpc->ret_retcode < 0 && rrpc->ret_errno) {
1.2 misho 446: rpc_SetErr(rrpc->ret_errno, "Error::Server side: %d %s\n",
447: rrpc->ret_retcode, strerror(rrpc->ret_errno));
1.4.2.3 ! misho 448: free(buf);
1.1 misho 449: return -6;
450: }
1.4.2.3 ! misho 451: if (rrpc->ret_argc * sizeof(ait_val_t) > cli->cli_netbuf - Limit) {
1.4 misho 452: rpc_SetErr(EMSGSIZE, "Error:: reply RPC packet is too long ...\n");
1.4.2.3 ! misho 453: free(buf);
1.2 misho 454: return -7;
455: } else
1.4.2.1 misho 456: Limit += rrpc->ret_argc * sizeof(ait_val_t);
1.3 misho 457: /* RPC is OK! Go decapsulate variables ... */
1.1 misho 458: if (rrpc->ret_argc) {
459: *out_argc = rrpc->ret_argc;
1.4.2.1 misho 460: *out_vars = calloc(rrpc->ret_argc, sizeof(ait_val_t));
1.4 misho 461: if (!*out_vars) {
1.1 misho 462: LOGERR;
463: *out_argc = 0;
1.4.2.3 ! misho 464: free(buf);
1.1 misho 465: return -1;
466: } else
1.4 misho 467: memcpy(*out_vars, buf + sizeof(struct tagRPCRet), Limit - sizeof(struct tagRPCRet));
1.4.2.3 ! misho 468:
1.3 misho 469: /* RPC received variables types OK! */
1.2 misho 470: data = (u_char*) buf + Limit;
1.1 misho 471: for (i = 0; i < rrpc->ret_argc; i++)
1.4.2.3 ! misho 472: switch (AIT_TYPE(&(*out_vars)[i])) {
1.1 misho 473: case buffer:
1.4.2.3 ! misho 474: if (AIT_LEN(&(*out_vars)[i]) > cli->cli_netbuf - Limit) {
1.4 misho 475: rpc_SetErr(EMSGSIZE, "Error:: Too long RPC packet ...\n");
476: free(*out_vars);
477: *out_vars = NULL;
1.2 misho 478: *out_argc = 0;
1.4.2.3 ! misho 479: free(buf);
1.2 misho 480: return -7;
481: } else
1.4.2.3 ! misho 482: Limit += AIT_LEN(&(*out_vars)[i]);
1.2 misho 483:
1.4.2.3 ! misho 484: (*out_vars)[i].val.buffer = malloc(AIT_LEN(&(*out_vars)[i]));
1.4 misho 485: if (!(*out_vars)[i].val.buffer) {
1.1 misho 486: rpc_SetErr(errno, "Error:: in prepare RPC reply ...\n");
1.4 misho 487: free(*out_vars);
488: *out_vars = NULL;
1.1 misho 489: *out_argc = 0;
1.4.2.3 ! misho 490: free(buf);
1.1 misho 491: return -1;
492: } else
1.4.2.3 ! misho 493: memcpy((*out_vars)[i].val.buffer, data, AIT_LEN(&(*out_vars)[i]));
! 494: data += AIT_LEN(&(*out_vars)[i]);
1.1 misho 495: break;
496: case string:
1.4.2.3 ! misho 497: if (AIT_LEN(&(*out_vars)[i]) > cli->cli_netbuf - Limit) {
1.4 misho 498: rpc_SetErr(EMSGSIZE, "Error:: Too long RPC packet ...\n");
499: free(*out_vars);
500: *out_vars = NULL;
1.2 misho 501: *out_argc = 0;
1.4.2.3 ! misho 502: free(buf);
1.2 misho 503: return -7;
504: } else
1.4.2.3 ! misho 505: Limit += AIT_LEN(&(*out_vars)[i]);
1.2 misho 506:
1.4.2.3 ! misho 507: (*out_vars)[i].val.string = malloc(AIT_LEN(&(*out_vars)[i]));
1.4 misho 508: if (!(*out_vars)[i].val.string) {
1.1 misho 509: rpc_SetErr(errno, "Error:: in prepare RPC reply ...\n");
1.4 misho 510: free(*out_vars);
511: *out_vars = NULL;
1.1 misho 512: *out_argc = 0;
1.4.2.3 ! misho 513: free(buf);
1.1 misho 514: return -1;
1.3 misho 515: } else
1.4.2.3 ! misho 516: memcpy((*out_vars)[i].val.string, data, AIT_LEN(&(*out_vars)[i]));
! 517: data += AIT_LEN(&(*out_vars)[i]);
1.1 misho 518: break;
519: default:
520: break;
521: }
522: } else {
1.2 misho 523: if (out_argc)
524: *out_argc = 0;
1.4 misho 525: if (out_vars)
526: *out_vars = NULL;
1.1 misho 527: }
528:
1.4.2.3 ! misho 529: ret = rrpc->ret_retcode;
! 530: free(buf);
! 531: return ret;
1.1 misho 532: }
533:
534: /*
1.4.2.1 misho 535: * rpc_cli_freeVals() Free ait_val_t array returned from RPC call
1.1 misho 536: * @args = Number of arguments in array
1.4 misho 537: * @vars = Value elements
1.1 misho 538: * return: none
539: */
540: inline void
1.4.2.1 misho 541: rpc_cli_freeVals(int args, ait_val_t * __restrict vars)
1.1 misho 542: {
543: register int i;
544:
1.4 misho 545: if (!vars)
1.1 misho 546: return;
547:
548: for (i = 0; i < args; i++)
1.4.2.1 misho 549: AIT_FREE_VAL(&vars[i]);
1.1 misho 550:
1.4 misho 551: free(vars);
552: vars = NULL;
1.1 misho 553: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>