Annotation of libaitrpc/src/builtin.c, revision 1.1.1.1.2.2
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.1.1.1.2.2! misho 6: * $Id: builtin.c,v 1.1.1.1.2.1 2010/06/18 13:36:01 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #include "global.h"
10:
11:
12: /* builtin RPC server functions */
13:
14: int
15: rpcServerClients(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
16: {
17: rpc_val_t *v, *vals = NULL;
18: rpc_cli_t *cli;
19: register int i;
20: const char *str;
21: char wrk[INET6_ADDRSTRLEN];
22: struct sockaddr_in *s;
23: struct sockaddr_in6 *s6;
24:
1.1.1.1.2.1 misho 25: RPC_CALLBACK_CHECK_INPUT(srv, call);
26:
1.1 misho 27: if (rpc_srv_declValsCall(call, srv->srv_numcli) == -1)
28: return -1;
29: else
30: rpc_srv_delValsCall(call);
31: if (rpc_srv_getValsCall(call, &vals) == -1)
32: return -1;
33:
34: for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; cli++) {
35: if (!cli->cli_sa.sa_family)
36: continue;
37:
38: if (AF_INET == cli->cli_sa.sa_family) {
39: s = (struct sockaddr_in*) &cli->cli_sa;
40: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
41: } else {
42: s6 = (struct sockaddr_in6*) &cli->cli_sa;
43: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
44: }
45: if (str) {
46: RPC_SET_STR(v++, (char*) str);
47: i++;
48: }
49: }
50:
51: return 0;
52: }
53:
54: int
55: rpcServerCalls(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
56: {
57: rpc_val_t *v, *vals = NULL;
58: rpc_func_t *f;
59: register int i;
60: char str[MAXPATHLEN];
61:
1.1.1.1.2.1 misho 62: RPC_CALLBACK_CHECK_INPUT(srv, call);
1.1 misho 63:
64: for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
65:
66: if (rpc_srv_declValsCall(call, i) == -1)
67: return -1;
68: else
69: rpc_srv_delValsCall(call);
70: if (rpc_srv_getValsCall(call, &vals) == -1)
71: return -1;
72:
73: for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {
74: if (*f->func_name) {
75: memset(str, 0, MAXPATHLEN);
76: snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);
77: RPC_SET_STR(v++, str);
78: }
79: }
80:
81: return 0;
82: }
83:
84: int
85: rpcServerSessions(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
86: {
87: rpc_val_t *vals = NULL;
88:
1.1.1.1.2.1 misho 89: RPC_CALLBACK_CHECK_INPUT(srv, call);
1.1 misho 90:
91: if (rpc_srv_declValsCall(call, 4) == -1)
92: return -1;
93: else
94: rpc_srv_delValsCall(call);
95: if (rpc_srv_getValsCall(call, &vals) == -1)
96: return -1;
97:
98: RPC_SET_U8(&vals[0], srv->srv_session.sess_version);
99: RPC_SET_U32(&vals[1], srv->srv_session.sess_program);
100: RPC_SET_U32(&vals[2], srv->srv_session.sess_process);
101: RPC_SET_I32(&vals[3], srv->srv_numcli);
102:
103: return 0;
104: }
1.1.1.1.2.1 misho 105:
106: int
107: rpcServerShutdown(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
108: {
109: RPC_CALLBACK_CHECK_INPUT(srv, call);
110:
1.1.1.1.2.2! misho 111: pthread_mutex_lock(&srv->srv_mtx);
1.1.1.1.2.1 misho 112: rpc_Kill = 1;
1.1.1.1.2.2! misho 113: pthread_mutex_unlock(&srv->srv_mtx);
1.1.1.1.2.1 misho 114:
115: return 0;
116: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>