Annotation of libaitrpc/src/builtin.c, revision 1.1.1.1.2.3
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.3! misho 6: * $Id: builtin.c,v 1.1.1.1.2.2 2010/06/23 11:33: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:
35: for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; cli++) {
36: if (!cli->cli_sa.sa_family)
37: continue;
38:
39: if (AF_INET == cli->cli_sa.sa_family) {
40: s = (struct sockaddr_in*) &cli->cli_sa;
41: str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
42: } else {
43: s6 = (struct sockaddr_in6*) &cli->cli_sa;
44: str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
45: }
46: if (str) {
47: RPC_SET_STR(v++, (char*) str);
48: i++;
49: }
50: }
51:
52: return 0;
53: }
54:
55: int
1.1.1.1.2.3! misho 56: rpcServerCalls(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1 misho 57: {
1.1.1.1.2.3! misho 58: rpc_srv_t *srv;
! 59: rpc_val_t *v, *vals;
1.1 misho 60: rpc_func_t *f;
61: register int i;
62: char str[MAXPATHLEN];
63:
1.1.1.1.2.3! misho 64: RPC_CALLBACK_CHECK_INPUT(call);
! 65: if (!call->func_parent)
1.1 misho 66: return -1;
67: else
1.1.1.1.2.3! misho 68: srv = call->func_parent;
! 69:
! 70: for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
! 71: if (!(vals = rpc_srv_retValsCall(call, i)))
1.1 misho 72: return -1;
73:
74: for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {
75: if (*f->func_name) {
76: memset(str, 0, MAXPATHLEN);
77: snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);
78: RPC_SET_STR(v++, str);
79: }
80: }
81:
82: return 0;
83: }
84:
85: int
1.1.1.1.2.3! misho 86: rpcServerSessions(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1 misho 87: {
1.1.1.1.2.3! misho 88: rpc_srv_t *srv;
! 89: rpc_val_t *vals;
1.1 misho 90:
1.1.1.1.2.3! misho 91: RPC_CALLBACK_CHECK_INPUT(call);
! 92: if (!call->func_parent)
1.1 misho 93: return -1;
94: else
1.1.1.1.2.3! misho 95: srv = call->func_parent;
! 96:
! 97: if (!(vals = rpc_srv_retValsCall(call, 4)))
1.1 misho 98: return -1;
99:
100: RPC_SET_U8(&vals[0], srv->srv_session.sess_version);
101: RPC_SET_U32(&vals[1], srv->srv_session.sess_program);
102: RPC_SET_U32(&vals[2], srv->srv_session.sess_process);
103: RPC_SET_I32(&vals[3], srv->srv_numcli);
104:
105: return 0;
106: }
1.1.1.1.2.1 misho 107:
108: int
1.1.1.1.2.3! misho 109: rpcServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1.1.1.2.1 misho 110: {
1.1.1.1.2.3! misho 111: rpc_srv_t *srv;
! 112:
! 113: RPC_CALLBACK_CHECK_INPUT(call);
! 114: if (!call->func_parent)
! 115: return -1;
! 116: else
! 117: srv = call->func_parent;
1.1.1.1.2.1 misho 118:
1.1.1.1.2.2 misho 119: pthread_mutex_lock(&srv->srv_mtx);
1.1.1.1.2.1 misho 120: rpc_Kill = 1;
1.1.1.1.2.2 misho 121: pthread_mutex_unlock(&srv->srv_mtx);
1.1.1.1.2.1 misho 122:
123: return 0;
124: }
1.1.1.1.2.3! misho 125:
! 126: // ----------------------------------------------------
! 127:
! 128: int
! 129: rpcBLOBServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
! 130: {
! 131: rpc_srv_t *srv;
! 132:
! 133: RPC_CALLBACK_CHECK_INPUT(call);
! 134: if (!call->func_parent)
! 135: return -1;
! 136: else
! 137: srv = call->func_parent;
! 138:
! 139: pthread_mutex_lock(&srv->srv_blob.mtx);
! 140: blob_Kill = 1;
! 141: pthread_mutex_unlock(&srv->srv_blob.mtx);
! 142:
! 143: return 0;
! 144: }
! 145:
! 146: int
! 147: rpcBLOBServerVars(rpc_func_t *call, int ic, rpc_val_t *iv)
! 148: {
! 149: rpc_srv_t *srv;
! 150: rpc_val_t *v, *vals;
! 151: rpc_blob_t *b;
! 152: register int i;
! 153:
! 154: RPC_CALLBACK_CHECK_INPUT(call);
! 155: if (!call->func_parent)
! 156: return -1;
! 157: else
! 158: srv = call->func_parent;
! 159:
! 160: for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
! 161: if (!(vals = rpc_srv_retValsCall(call, i)))
! 162: return -1;
! 163:
! 164: for (b = srv->srv_blob.blobs, v = vals; b; b = b->blob_next)
! 165: RPC_SET_U32(v++, b->blob_var);
! 166:
! 167: return 0;
! 168: }
! 169:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>