Annotation of libaitrpc/src/builtin.c, revision 1.1.1.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 $
6: * $Id: aitcli.c,v 1.2.2.17 2010/06/09 09:32:30 misho Exp $
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:
25: if (!srv || !call) {
26: rpc_SetErr(EINVAL, "Error:: invalid parameters ...\n");
27: return -1;
28: }
29: if (rpc_srv_declValsCall(call, srv->srv_numcli) == -1)
30: return -1;
31: else
32: rpc_srv_delValsCall(call);
33: if (rpc_srv_getValsCall(call, &vals) == -1)
34: return -1;
35:
36: for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; cli++) {
37: if (!cli->cli_sa.sa_family)
38: continue;
39:
40: if (AF_INET == cli->cli_sa.sa_family) {
41: s = (struct sockaddr_in*) &cli->cli_sa;
42: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
43: } else {
44: s6 = (struct sockaddr_in6*) &cli->cli_sa;
45: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
46: }
47: if (str) {
48: RPC_SET_STR(v++, (char*) str);
49: i++;
50: }
51: }
52:
53: return 0;
54: }
55:
56: int
57: rpcServerCalls(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
58: {
59: rpc_val_t *v, *vals = NULL;
60: rpc_func_t *f;
61: register int i;
62: char str[MAXPATHLEN];
63:
64: if (!srv || !call) {
65: rpc_SetErr(EINVAL, "Error:: invalid parameters ...\n");
66: return -1;
67: }
68:
69: for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
70:
71: if (rpc_srv_declValsCall(call, i) == -1)
72: return -1;
73: else
74: rpc_srv_delValsCall(call);
75: if (rpc_srv_getValsCall(call, &vals) == -1)
76: return -1;
77:
78: for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {
79: if (*f->func_name) {
80: memset(str, 0, MAXPATHLEN);
81: snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);
82: RPC_SET_STR(v++, str);
83: }
84: }
85:
86: return 0;
87: }
88:
89: int
90: rpcServerSessions(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)
91: {
92: rpc_val_t *vals = NULL;
93:
94: if (!srv || !call) {
95: rpc_SetErr(EINVAL, "Error:: invalid parameters ...\n");
96: return -1;
97: }
98:
99: if (rpc_srv_declValsCall(call, 4) == -1)
100: return -1;
101: else
102: rpc_srv_delValsCall(call);
103: if (rpc_srv_getValsCall(call, &vals) == -1)
104: return -1;
105:
106: RPC_SET_U8(&vals[0], srv->srv_session.sess_version);
107: RPC_SET_U32(&vals[1], srv->srv_session.sess_program);
108: RPC_SET_U32(&vals[2], srv->srv_session.sess_process);
109: RPC_SET_I32(&vals[3], srv->srv_numcli);
110:
111: return 0;
112: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>