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