Annotation of libaitrpc/src/builtin.c, revision 1.1.1.1.2.8
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.8! misho 6: * $Id: builtin.c,v 1.1.1.1.2.7 2010/07/08 12:29:38 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.7 misho 166: return 0;
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:
1.1.1.1.2.8! misho 181: RPC_CALLBACK_CHK_ARGS(call, ic);
1.1.1.1.2.4 misho 182: if (!call->func_parent)
183: return -1;
184: else
185: srv = call->func_parent;
186:
187: if (iv[0].val_type != i32)
188: return -1;
189:
190: srv->srv_blob.state = RPC_GET_I32(&iv[0]);
191: return 0;
192: }
193:
194: int
195: rpcBLOBServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
196: {
197: rpc_srv_t *srv;
198: rpc_val_t *v, *vals;
199: rpc_cli_t *cli;
200: register int i;
201: const char *str;
202: char wrk[INET6_ADDRSTRLEN];
203: struct sockaddr_in *s;
204: struct sockaddr_in6 *s6;
205:
206: RPC_CALLBACK_CHECK_INPUT(call);
207: if (!call->func_parent)
208: return -1;
209: else
210: srv = call->func_parent;
211:
212: if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
213: return -1;
214:
215: for (i = 0, cli = srv->srv_blob.clients, v = vals; i < srv->srv_numcli; i++, cli++) {
216: if (!cli->cli_sa.sa_family) {
217: RPC_SET_STR(v++, "");
218: continue;
219: }
220:
221: if (AF_INET == cli->cli_sa.sa_family) {
222: s = (struct sockaddr_in*) &cli->cli_sa;
223: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
224: } else {
225: s6 = (struct sockaddr_in6*) &cli->cli_sa;
226: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
227: }
228: if (str)
229: RPC_SET_STR(v++, (char*) str);
230: else
231: RPC_SET_STR(v++, "0.0.0.0");
232: }
233:
234: return 0;
235: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>