Annotation of libaitrpc/src/builtin.c, revision 1.3.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.3.2.3 ! misho 6: * $Id: builtin.c,v 1.3.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: /* builtin RPC server functions */
50:
51: int
1.3.2.3 ! misho 52: rpcServerClients(rpc_func_t *call, int ic, array_t *iv)
1.1 misho 53: {
1.2 misho 54: rpc_srv_t *srv;
1.3.2.3 ! misho 55: array_t *vals;
! 56: ait_val_t *v;
1.1 misho 57: rpc_cli_t *cli;
58: register int i;
1.3 misho 59: const char *str = NULL;
1.1 misho 60: char wrk[INET6_ADDRSTRLEN];
61: struct sockaddr_in *s;
62: struct sockaddr_in6 *s6;
1.3 misho 63: struct sockaddr_un *su;
1.1 misho 64:
1.2 misho 65: RPC_CALLBACK_CHECK_INPUT(call);
66: if (!call->func_parent)
1.1 misho 67: return -1;
68: else
1.2 misho 69: srv = call->func_parent;
70:
1.3 misho 71: if (!(vals = rpc_srv_returnVars(call, srv->srv_numcli)))
1.1 misho 72: return -1;
73:
1.3.2.3 ! misho 74: for (i = 0, cli = srv->srv_clients; i < srv->srv_numcli; i++, cli++) {
! 75: v = io_array(vals, i, ait_val_t*);
1.2 misho 76: if (!cli->cli_sa.sa_family) {
1.3.2.3 ! misho 77: AIT_SET_STR(v, "");
1.1 misho 78: continue;
1.2 misho 79: }
1.1 misho 80:
1.3 misho 81: switch (cli->cli_sa.sa_family) {
82: case AF_INET:
83: s = (struct sockaddr_in*) &cli->cli_sa;
84: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
85: break;
86: case AF_INET6:
87: s6 = (struct sockaddr_in6*) &cli->cli_sa;
88: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
89: break;
90: case AF_LOCAL:
91: su = (struct sockaddr_un*) &cli->cli_sa;
92: str = su->sun_path;
93: break;
1.1 misho 94: }
1.2 misho 95: if (str)
1.3.2.3 ! misho 96: AIT_SET_STR(v, (char*) str);
1.2 misho 97: else
1.3.2.3 ! misho 98: AIT_SET_STR(v, "0.0.0.0");
1.1 misho 99: }
100:
101: return 0;
102: }
103:
104: int
1.3.2.3 ! misho 105: rpcServerCalls(rpc_func_t *call, int ic, array_t *iv)
1.1 misho 106: {
1.2 misho 107: rpc_srv_t *srv;
1.3.2.3 ! misho 108: array_t *vals;
! 109: ait_val_t *v;
1.1 misho 110: rpc_func_t *f;
111: register int i;
112: char str[MAXPATHLEN];
113:
1.2 misho 114: RPC_CALLBACK_CHECK_INPUT(call);
115: if (!call->func_parent)
1.1 misho 116: return -1;
1.2 misho 117: else
118: srv = call->func_parent;
1.1 misho 119:
120: for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
1.3 misho 121: if (!(vals = rpc_srv_returnVars(call, i)))
1.1 misho 122: return -1;
123:
1.3.2.3 ! misho 124: for (f = srv->srv_funcs, i = 0; f; f = f->func_next) {
1.1 misho 125: if (*f->func_name) {
1.3 misho 126: memset(str, 0, sizeof str);
127: snprintf(str, sizeof str, "/%s/%s()", f->func_file, f->func_name);
1.3.2.3 ! misho 128: v = io_array(vals, i++, ait_val_t*);
! 129: AIT_SET_STR(v, str);
1.1 misho 130: }
131: }
132:
133: return 0;
134: }
135:
136: int
1.3.2.3 ! misho 137: rpcServerSessions(rpc_func_t *call, int ic, array_t *iv)
1.1 misho 138: {
1.2 misho 139: rpc_srv_t *srv;
1.3.2.3 ! misho 140: array_t *vals;
! 141: ait_val_t *v;
1.1 misho 142:
1.2 misho 143: RPC_CALLBACK_CHECK_INPUT(call);
144: if (!call->func_parent)
1.1 misho 145: return -1;
1.2 misho 146: else
147: srv = call->func_parent;
1.1 misho 148:
1.3 misho 149: if (!(vals = rpc_srv_returnVars(call, 4)))
1.1 misho 150: return -1;
151:
1.3.2.3 ! misho 152: v = io_array(vals, 0, ait_val_t*);
! 153: AIT_SET_U8(v, srv->srv_session.sess_version);
! 154: v = io_array(vals, 1, ait_val_t*);
! 155: AIT_SET_U32(v, srv->srv_session.sess_program);
! 156: v = io_array(vals, 2, ait_val_t*);
! 157: AIT_SET_U32(v, srv->srv_session.sess_process);
! 158: v = io_array(vals, 3, ait_val_t*);
! 159: AIT_SET_I32(v, srv->srv_numcli);
1.1 misho 160:
161: return 0;
162: }
1.2 misho 163:
164: int
1.3.2.3 ! misho 165: rpcServerShutdown(rpc_func_t *call, int ic, array_t *iv)
1.2 misho 166: {
167: rpc_srv_t *srv;
168:
169: RPC_CALLBACK_CHECK_INPUT(call);
170: if (!call->func_parent)
171: return -1;
172: else
173: srv = call->func_parent;
174:
175: pthread_mutex_lock(&srv->srv_mtx);
1.3 misho 176: srv->srv_kill = kill;
1.2 misho 177: pthread_mutex_unlock(&srv->srv_mtx);
178:
179: return 0;
180: }
181:
182: // ----------------------------------------------------
183:
184: int
1.3.2.3 ! misho 185: rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_t *iv)
1.2 misho 186: {
187: rpc_srv_t *srv;
188:
189: RPC_CALLBACK_CHECK_INPUT(call);
190: if (!call->func_parent)
191: return -1;
192: else
193: srv = call->func_parent;
194:
195: pthread_mutex_lock(&srv->srv_blob.mtx);
1.3 misho 196: srv->srv_blob.state = kill;
1.2 misho 197: pthread_mutex_unlock(&srv->srv_blob.mtx);
198:
199: return 0;
200: }
201:
202: int
1.3.2.3 ! misho 203: rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *iv)
1.2 misho 204: {
205: rpc_srv_t *srv;
1.3.2.3 ! misho 206: array_t *vals;
! 207: ait_val_t *v;
1.2 misho 208: rpc_blob_t *b;
209: register int i;
210:
211: RPC_CALLBACK_CHECK_INPUT(call);
212: if (!call->func_parent)
213: return -1;
214: else
215: srv = call->func_parent;
216:
217: pthread_mutex_lock(&srv->srv_blob.mtx);
218: for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
1.3 misho 219: if (!(vals = rpc_srv_returnVars(call, i))) {
1.2 misho 220: pthread_mutex_unlock(&srv->srv_blob.mtx);
221: return 0;
222: }
223:
1.3.2.3 ! misho 224: for (b = srv->srv_blob.blobs, i = 0; b; i++, b = b->blob_next) {
! 225: v = io_array(vals, i, ait_val_t*);
! 226: AIT_SET_U32(v, b->blob_var);
! 227: }
1.2 misho 228: pthread_mutex_unlock(&srv->srv_blob.mtx);
229:
230: return 0;
231: }
232:
233: int
1.3.2.3 ! misho 234: rpcBLOBServerState(rpc_func_t *call, int ic, array_t *iv)
1.2 misho 235: {
236: rpc_srv_t *srv;
237:
238: RPC_CALLBACK_CHK_ARGS(call, ic);
239: if (!call->func_parent)
240: return -1;
241: else
242: srv = call->func_parent;
243:
1.3.2.3 ! misho 244: if (AIT_TYPE(io_array(iv, 0, ait_val_t*)) != i32)
1.2 misho 245: return -1;
246:
1.3.2.3 ! misho 247: srv->srv_blob.state = AIT_GET_I32(io_array(iv, 0, ait_val_t*));
1.2 misho 248: return 0;
249: }
250:
251: int
1.3.2.3 ! misho 252: rpcBLOBServerClients(rpc_func_t *call, int ic, array_t *iv)
1.2 misho 253: {
254: rpc_srv_t *srv;
1.3.2.3 ! misho 255: array_t *vals;
! 256: ait_val_t *v;
1.2 misho 257: rpc_cli_t *cli;
258: register int i;
1.3 misho 259: const char *str = NULL;
1.2 misho 260: char wrk[INET6_ADDRSTRLEN];
261: struct sockaddr_in *s;
262: struct sockaddr_in6 *s6;
1.3 misho 263: struct sockaddr_un *su;
1.2 misho 264:
265: RPC_CALLBACK_CHECK_INPUT(call);
266: if (!call->func_parent)
267: return -1;
268: else
269: srv = call->func_parent;
270:
1.3 misho 271: if (!(vals = rpc_srv_returnVars(call, srv->srv_numcli)))
1.2 misho 272: return -1;
273:
1.3.2.3 ! misho 274: for (i = 0, cli = srv->srv_blob.clients; i < srv->srv_numcli; i++, cli++) {
! 275: v = io_array(vals, i, ait_val_t*);
! 276:
1.2 misho 277: if (!cli->cli_sa.sa_family) {
1.3.2.3 ! misho 278: AIT_SET_STR(v, "");
1.2 misho 279: continue;
280: }
281:
1.3 misho 282: switch (cli->cli_sa.sa_family) {
283: case AF_INET:
284: s = (struct sockaddr_in*) &cli->cli_sa;
285: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
286: break;
287: case AF_INET6:
288: s6 = (struct sockaddr_in6*) &cli->cli_sa;
289: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
290: break;
291: case AF_LOCAL:
292: su = (struct sockaddr_un*) &cli->cli_sa;
293: str = su->sun_path;
294: break;
1.2 misho 295: }
296: if (str)
1.3.2.3 ! misho 297: AIT_SET_STR(v, (char*) str);
1.2 misho 298: else
1.3.2.3 ! misho 299: AIT_SET_STR(v, "0.0.0.0");
1.2 misho 300: }
301:
302: return 0;
303: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>