Annotation of libaitrpc/src/builtin.c, revision 1.2

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.2     ! misho       6: * $Id: builtin.c,v 1.1.1.1.2.9 2011/05/02 23:07:55 misho Exp $
1.1       misho       7: *
1.2     ! misho       8: **************************************************************************
        !             9: The ELWIX and AITNET software is distributed under the following
        !            10: terms:
        !            11: 
        !            12: All of the documentation and software included in the ELWIX and AITNET
        !            13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
        !            14: 
        !            15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
        !            16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
        !            17: 
        !            18: Redistribution and use in source and binary forms, with or without
        !            19: modification, are permitted provided that the following conditions
        !            20: are met:
        !            21: 1. Redistributions of source code must retain the above copyright
        !            22:    notice, this list of conditions and the following disclaimer.
        !            23: 2. Redistributions in binary form must reproduce the above copyright
        !            24:    notice, this list of conditions and the following disclaimer in the
        !            25:    documentation and/or other materials provided with the distribution.
        !            26: 3. All advertising materials mentioning features or use of this software
        !            27:    must display the following acknowledgement:
        !            28: This product includes software developed by Michael Pounov <misho@elwix.org>
        !            29: ELWIX - Embedded LightWeight unIX and its contributors.
        !            30: 4. Neither the name of AITNET nor the names of its contributors
        !            31:    may be used to endorse or promote products derived from this software
        !            32:    without specific prior written permission.
        !            33: 
        !            34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
        !            35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            44: SUCH DAMAGE.
        !            45: */
1.1       misho      46: #include "global.h"
                     47: 
                     48: 
                     49: /* builtin RPC server functions */
                     50: 
                     51: int
1.2     ! misho      52: rpcServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1       misho      53: {
1.2     ! misho      54:        rpc_srv_t *srv;
        !            55:        rpc_val_t *v, *vals;
1.1       misho      56:        rpc_cli_t *cli;
                     57:        register int i;
                     58:        const char *str;
                     59:        char wrk[INET6_ADDRSTRLEN];
                     60:        struct sockaddr_in *s;
                     61:        struct sockaddr_in6 *s6;
                     62: 
1.2     ! misho      63:        RPC_CALLBACK_CHECK_INPUT(call);
        !            64:        if (!call->func_parent)
1.1       misho      65:                return -1;
                     66:        else
1.2     ! misho      67:                srv = call->func_parent;
        !            68: 
        !            69:        if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
1.1       misho      70:                return -1;
                     71: 
1.2     ! misho      72:        for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; i++, cli++) {
        !            73:                if (!cli->cli_sa.sa_family) {
        !            74:                        RPC_SET_STR(v++, "");
1.1       misho      75:                        continue;
1.2     ! misho      76:                }
1.1       misho      77: 
                     78:                if (AF_INET == cli->cli_sa.sa_family) {
                     79:                        s = (struct sockaddr_in*) &cli->cli_sa;
                     80:                        str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
                     81:                } else {
                     82:                        s6 = (struct sockaddr_in6*) &cli->cli_sa;
                     83:                        str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
                     84:                }
1.2     ! misho      85:                if (str)
1.1       misho      86:                        RPC_SET_STR(v++, (char*) str);
1.2     ! misho      87:                else
        !            88:                        RPC_SET_STR(v++, "0.0.0.0");
1.1       misho      89:        }
                     90: 
                     91:        return 0;
                     92: }
                     93: 
                     94: int
1.2     ! misho      95: rpcServerCalls(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1       misho      96: {
1.2     ! misho      97:        rpc_srv_t *srv;
        !            98:        rpc_val_t *v, *vals;
1.1       misho      99:        rpc_func_t *f;
                    100:        register int i;
                    101:        char str[MAXPATHLEN];
                    102: 
1.2     ! misho     103:        RPC_CALLBACK_CHECK_INPUT(call);
        !           104:        if (!call->func_parent)
1.1       misho     105:                return -1;
1.2     ! misho     106:        else
        !           107:                srv = call->func_parent;
1.1       misho     108: 
                    109:        for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
1.2     ! misho     110:        if (!(vals = rpc_srv_retValsCall(call, i)))
1.1       misho     111:                return -1;
                    112: 
                    113:        for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {
                    114:                if (*f->func_name) {
                    115:                        memset(str, 0, MAXPATHLEN);
                    116:                        snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);
                    117:                        RPC_SET_STR(v++, str);
                    118:                }
                    119:        }
                    120: 
                    121:        return 0;
                    122: }
                    123: 
                    124: int
1.2     ! misho     125: rpcServerSessions(rpc_func_t *call, int ic, rpc_val_t *iv)
1.1       misho     126: {
1.2     ! misho     127:        rpc_srv_t *srv;
        !           128:        rpc_val_t *vals;
1.1       misho     129: 
1.2     ! misho     130:        RPC_CALLBACK_CHECK_INPUT(call);
        !           131:        if (!call->func_parent)
1.1       misho     132:                return -1;
1.2     ! misho     133:        else
        !           134:                srv = call->func_parent;
1.1       misho     135: 
1.2     ! misho     136:        if (!(vals = rpc_srv_retValsCall(call, 4)))
1.1       misho     137:                return -1;
                    138: 
                    139:        RPC_SET_U8(&vals[0], srv->srv_session.sess_version);
                    140:        RPC_SET_U32(&vals[1], srv->srv_session.sess_program);
                    141:        RPC_SET_U32(&vals[2], srv->srv_session.sess_process);
                    142:        RPC_SET_I32(&vals[3], srv->srv_numcli);
                    143: 
                    144:        return 0;
                    145: }
1.2     ! misho     146: 
        !           147: int
        !           148: rpcServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
        !           149: {
        !           150:        rpc_srv_t *srv;
        !           151: 
        !           152:        RPC_CALLBACK_CHECK_INPUT(call);
        !           153:        if (!call->func_parent)
        !           154:                return -1;
        !           155:        else
        !           156:                srv = call->func_parent;
        !           157: 
        !           158:        pthread_mutex_lock(&srv->srv_mtx);
        !           159:        rpc_Kill = 1;
        !           160:        pthread_mutex_unlock(&srv->srv_mtx);
        !           161: 
        !           162:        return 0;
        !           163: }
        !           164: 
        !           165: // ----------------------------------------------------
        !           166: 
        !           167: int
        !           168: rpcBLOBServerShutdown(rpc_func_t *call, int ic, rpc_val_t *iv)
        !           169: {
        !           170:        rpc_srv_t *srv;
        !           171: 
        !           172:        RPC_CALLBACK_CHECK_INPUT(call);
        !           173:        if (!call->func_parent)
        !           174:                return -1;
        !           175:        else
        !           176:                srv = call->func_parent;
        !           177: 
        !           178:        pthread_mutex_lock(&srv->srv_blob.mtx);
        !           179:        blob_Kill = 1;
        !           180:        pthread_mutex_unlock(&srv->srv_blob.mtx);
        !           181: 
        !           182:        return 0;
        !           183: }
        !           184: 
        !           185: int
        !           186: rpcBLOBServerVars(rpc_func_t *call, int ic, rpc_val_t *iv)
        !           187: {
        !           188:        rpc_srv_t *srv;
        !           189:        rpc_val_t *v, *vals;
        !           190:        rpc_blob_t *b;
        !           191:        register int i;
        !           192: 
        !           193:        RPC_CALLBACK_CHECK_INPUT(call);
        !           194:        if (!call->func_parent)
        !           195:                return -1;
        !           196:        else
        !           197:                srv = call->func_parent;
        !           198: 
        !           199:        pthread_mutex_lock(&srv->srv_blob.mtx);
        !           200:        for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
        !           201:        if (!(vals = rpc_srv_retValsCall(call, i))) {
        !           202:                pthread_mutex_unlock(&srv->srv_blob.mtx);
        !           203:                return 0;
        !           204:        }
        !           205: 
        !           206:        for (b = srv->srv_blob.blobs, v = vals; b; b = b->blob_next)
        !           207:                RPC_SET_U32(v++, b->blob_var);
        !           208:        pthread_mutex_unlock(&srv->srv_blob.mtx);
        !           209: 
        !           210:        return 0;
        !           211: }
        !           212: 
        !           213: int
        !           214: rpcBLOBServerState(rpc_func_t *call, int ic, rpc_val_t *iv)
        !           215: {
        !           216:        rpc_srv_t *srv;
        !           217: 
        !           218:        RPC_CALLBACK_CHK_ARGS(call, ic);
        !           219:        if (!call->func_parent)
        !           220:                return -1;
        !           221:        else
        !           222:                srv = call->func_parent;
        !           223: 
        !           224:        if (iv[0].val_type != i32)
        !           225:                return -1;
        !           226: 
        !           227:        srv->srv_blob.state = RPC_GET_I32(&iv[0]);
        !           228:        return 0;
        !           229: }
        !           230: 
        !           231: int
        !           232: rpcBLOBServerClients(rpc_func_t *call, int ic, rpc_val_t *iv)
        !           233: {
        !           234:        rpc_srv_t *srv;
        !           235:        rpc_val_t *v, *vals;
        !           236:        rpc_cli_t *cli;
        !           237:        register int i;
        !           238:        const char *str;
        !           239:        char wrk[INET6_ADDRSTRLEN];
        !           240:        struct sockaddr_in *s;
        !           241:        struct sockaddr_in6 *s6;
        !           242: 
        !           243:        RPC_CALLBACK_CHECK_INPUT(call);
        !           244:        if (!call->func_parent)
        !           245:                return -1;
        !           246:        else
        !           247:                srv = call->func_parent;
        !           248: 
        !           249:        if (!(vals = rpc_srv_retValsCall(call, srv->srv_numcli)))
        !           250:                return -1;
        !           251: 
        !           252:        for (i = 0, cli = srv->srv_blob.clients, v = vals; i < srv->srv_numcli; i++, cli++) {
        !           253:                if (!cli->cli_sa.sa_family) {
        !           254:                        RPC_SET_STR(v++, "");
        !           255:                        continue;
        !           256:                }
        !           257: 
        !           258:                if (AF_INET == cli->cli_sa.sa_family) {
        !           259:                        s = (struct sockaddr_in*) &cli->cli_sa;
        !           260:                        str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);
        !           261:                } else {
        !           262:                        s6 = (struct sockaddr_in6*) &cli->cli_sa;
        !           263:                        str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);
        !           264:                }
        !           265:                if (str)
        !           266:                        RPC_SET_STR(v++, (char*) str);
        !           267:                else
        !           268:                        RPC_SET_STR(v++, "0.0.0.0");
        !           269:        }
        !           270: 
        !           271:        return 0;
        !           272: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>