Annotation of libaitrpc/src/builtin.c, revision 1.1.1.1.2.5
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.5! misho 6: * $Id: builtin.c,v 1.1.1.1.2.4 2010/06/28 15:18:43 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #include "global.h"
10:
11:
12: /* builtin RPC server functions */
13:
14: int
1.1.1.1.2.3 misho 15: rpcServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1 misho 16: {
1.1.1.1.2.3 misho 17: rpc_srv_t *srv;
18: rpc_val_t *v, *vals;
1.1 misho 19: rpc_cli_t *cli;
20: register int i;
21: const char *str;
22: char wrk[INET6_ADDRSTRLEN];
23: struct sockaddr_in *s;
24: struct sockaddr_in6 *s6;
25:
1.1.1.1.2.3 misho 26: RPC_CALLBACK_CHECK_INPUT(call);
27: if (!call->func_parent)
1.1 misho 28: return -1;
29: else
1.1.1.1.2.3 misho 30: srv = call->func_parent;
31:
32: if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
1.1 misho 33: return -1;
34:
1.1.1.1.2.4 misho 35: for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; i++, cli++) {
36: if (!cli->cli_sa.sa_family) {
37: RPC_SET_STR(v++, "");
1.1 misho 38: continue;
1.1.1.1.2.4 misho 39: }
1.1 misho 40:
41: if (AF_INET == cli->cli_sa.sa_family) {
42: s = (struct sockaddr_in*) &cli->cli_sa;
43: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
44: } else {
45: s6 = (struct sockaddr_in6*) &cli->cli_sa;
46: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
47: }
1.1.1.1.2.4 misho 48: if (str)
1.1 misho 49: RPC_SET_STR(v++, (char*) str);
1.1.1.1.2.4 misho 50: else
51: RPC_SET_STR(v++, "0.0.0.0");
1.1 misho 52: }
53:
54: return 0;
55: }
56:
57: int
1.1.1.1.2.3 misho 58: rpcServerCalls(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1 misho 59: {
1.1.1.1.2.3 misho 60: rpc_srv_t *srv;
61: rpc_val_t *v, *vals;
1.1 misho 62: rpc_func_t *f;
63: register int i;
64: char str[MAXPATHLEN];
65:
1.1.1.1.2.3 misho 66: RPC_CALLBACK_CHECK_INPUT(call);
67: if (!call->func_parent)
1.1 misho 68: return -1;
69: else
1.1.1.1.2.3 misho 70: srv = call->func_parent;
71:
72: for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
73: if (!(vals = rpc_srv_retValsCall(call, i)))
1.1 misho 74: return -1;
75:
76: for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {
77: if (*f->func_name) {
78: memset(str, 0, MAXPATHLEN);
79: snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);
80: RPC_SET_STR(v++, str);
81: }
82: }
83:
84: return 0;
85: }
86:
87: int
1.1.1.1.2.3 misho 88: rpcServerSessions(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1 misho 89: {
1.1.1.1.2.3 misho 90: rpc_srv_t *srv;
91: rpc_val_t *vals;
1.1 misho 92:
1.1.1.1.2.3 misho 93: RPC_CALLBACK_CHECK_INPUT(call);
94: if (!call->func_parent)
1.1 misho 95: return -1;
96: else
1.1.1.1.2.3 misho 97: srv = call->func_parent;
98:
99: if (!(vals = rpc_srv_retValsCall(call, 4)))
1.1 misho 100: return -1;
101:
102: RPC_SET_U8(&vals[0], srv->srv_session.sess_version);
103: RPC_SET_U32(&vals[1], srv->srv_session.sess_program);
104: RPC_SET_U32(&vals[2], srv->srv_session.sess_process);
105: RPC_SET_I32(&vals[3], srv->srv_numcli);
106:
107: return 0;
108: }
1.1.1.1.2.1 misho 109:
110: int
1.1.1.1.2.3 misho 111: rpcServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1.1.1.2.1 misho 112: {
1.1.1.1.2.3 misho 113: rpc_srv_t *srv;
114:
115: RPC_CALLBACK_CHECK_INPUT(call);
116: if (!call->func_parent)
117: return -1;
118: else
119: srv = call->func_parent;
1.1.1.1.2.1 misho 120:
1.1.1.1.2.2 misho 121: pthread_mutex_lock(&srv->srv_mtx);
1.1.1.1.2.1 misho 122: rpc_Kill = 1;
1.1.1.1.2.2 misho 123: pthread_mutex_unlock(&srv->srv_mtx);
1.1.1.1.2.1 misho 124:
125: return 0;
126: }
1.1.1.1.2.3 misho 127:
128: // ----------------------------------------------------
129:
130: int
131: rpcBLOBServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
132: {
133: rpc_srv_t *srv;
134:
135: RPC_CALLBACK_CHECK_INPUT(call);
136: if (!call->func_parent)
137: return -1;
138: else
139: srv = call->func_parent;
140:
141: pthread_mutex_lock(&srv->srv_blob.mtx);
142: blob_Kill = 1;
143: pthread_mutex_unlock(&srv->srv_blob.mtx);
144:
145: return 0;
146: }
147:
148: int
149: rpcBLOBServerVars(rpc_func_t *call, int ic, rpc_val_t *iv)
150: {
151: rpc_srv_t *srv;
152: rpc_val_t *v, *vals;
153: rpc_blob_t *b;
154: register int i;
155:
156: RPC_CALLBACK_CHECK_INPUT(call);
157: if (!call->func_parent)
158: return -1;
159: else
160: srv = call->func_parent;
161:
162: for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
163: if (!(vals = rpc_srv_retValsCall(call, i)))
164: return -1;
165:
166: for (b = srv->srv_blob.blobs, v = vals; b; b = b->blob_next)
167: RPC_SET_U32(v++, b->blob_var);
168:
169: return 0;
170: }
171:
1.1.1.1.2.4 misho 172: int
173: rpcBLOBServerState(rpc_func_t *call, int ic, rpc_val_t *iv)
174: {
175: rpc_srv_t *srv;
176:
177: RPC_CALLBACK_CHECK_INPUT(call);
1.1.1.1.2.5! misho 178: RPC_CALLBACK_CHK_RETARGS(call, ic);
1.1.1.1.2.4 misho 179: if (!call->func_parent)
180: return -1;
181: else
182: srv = call->func_parent;
183:
184: if (iv[0].val_type != i32)
185: return -1;
186:
187: srv->srv_blob.state = RPC_GET_I32(&iv[0]);
188: return 0;
189: }
190:
191: int
192: rpcBLOBServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
193: {
194: rpc_srv_t *srv;
195: rpc_val_t *v, *vals;
196: rpc_cli_t *cli;
197: register int i;
198: const char *str;
199: char wrk[INET6_ADDRSTRLEN];
200: struct sockaddr_in *s;
201: struct sockaddr_in6 *s6;
202:
203: RPC_CALLBACK_CHECK_INPUT(call);
204: if (!call->func_parent)
205: return -1;
206: else
207: srv = call->func_parent;
208:
209: if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
210: return -1;
211:
212: for (i = 0, cli = srv->srv_blob.clients, v = vals; i < srv->srv_numcli; i++, cli++) {
213: if (!cli->cli_sa.sa_family) {
214: RPC_SET_STR(v++, "");
215: continue;
216: }
217:
218: if (AF_INET == cli->cli_sa.sa_family) {
219: s = (struct sockaddr_in*) &cli->cli_sa;
220: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
221: } else {
222: s6 = (struct sockaddr_in6*) &cli->cli_sa;
223: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
224: }
225: if (str)
226: RPC_SET_STR(v++, (char*) str);
227: else
228: RPC_SET_STR(v++, "0.0.0.0");
229: }
230:
231: return 0;
232: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>