Annotation of libaitrpc/src/builtin.c, revision 1.1.1.1.2.6
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.6! misho 6: * $Id: builtin.c,v 1.1.1.1.2.5 2010/07/08 07:16:36 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:
1.1.1.1.2.6! misho 162: pthread_mutex_lock(&srv->srv_blob.mtx);
1.1.1.1.2.3 misho 163: for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
1.1.1.1.2.6! misho 164: if (!(vals = rpc_srv_retValsCall(call, i))) {
! 165: pthread_mutex_unlock(&srv->srv_blob.mtx);
1.1.1.1.2.3 misho 166: return -1;
1.1.1.1.2.6! misho 167: }
1.1.1.1.2.3 misho 168:
169: for (b = srv->srv_blob.blobs, v = vals; b; b = b->blob_next)
170: RPC_SET_U32(v++, b->blob_var);
1.1.1.1.2.6! misho 171: pthread_mutex_unlock(&srv->srv_blob.mtx);
1.1.1.1.2.3 misho 172:
173: return 0;
174: }
175:
1.1.1.1.2.4 misho 176: int
177: rpcBLOBServerState(rpc_func_t *call, int ic, rpc_val_t *iv)
178: {
179: rpc_srv_t *srv;
180:
181: RPC_CALLBACK_CHECK_INPUT(call);
1.1.1.1.2.5 misho 182: RPC_CALLBACK_CHK_RETARGS(call, ic);
1.1.1.1.2.4 misho 183: if (!call->func_parent)
184: return -1;
185: else
186: srv = call->func_parent;
187:
188: if (iv[0].val_type != i32)
189: return -1;
190:
191: srv->srv_blob.state = RPC_GET_I32(&iv[0]);
192: return 0;
193: }
194:
195: int
196: rpcBLOBServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
197: {
198: rpc_srv_t *srv;
199: rpc_val_t *v, *vals;
200: rpc_cli_t *cli;
201: register int i;
202: const char *str;
203: char wrk[INET6_ADDRSTRLEN];
204: struct sockaddr_in *s;
205: struct sockaddr_in6 *s6;
206:
207: RPC_CALLBACK_CHECK_INPUT(call);
208: if (!call->func_parent)
209: return -1;
210: else
211: srv = call->func_parent;
212:
213: if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
214: return -1;
215:
216: for (i = 0, cli = srv->srv_blob.clients, v = vals; i < srv->srv_numcli; i++, cli++) {
217: if (!cli->cli_sa.sa_family) {
218: RPC_SET_STR(v++, "");
219: continue;
220: }
221:
222: if (AF_INET == cli->cli_sa.sa_family) {
223: s = (struct sockaddr_in*) &cli->cli_sa;
224: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
225: } else {
226: s6 = (struct sockaddr_in6*) &cli->cli_sa;
227: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
228: }
229: if (str)
230: RPC_SET_STR(v++, (char*) str);
231: else
232: RPC_SET_STR(v++, "0.0.0.0");
233: }
234:
235: return 0;
236: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>