Diff for /libaitrpc/src/builtin.c between versions 1.1.1.1.2.1 and 1.7

version 1.1.1.1.2.1, 2010/06/18 13:36:01 version 1.7, 2012/05/14 08:39:05
Line 5 Line 5
 * $Author$  * $Author$
 * $Id$  * $Id$
 *  *
*************************************************************************/**************************************************************************
 The ELWIX and AITNET software is distributed under the following
 terms:
 
 All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
 
 Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
         by Michael Pounov <misho@elwix.org>.  All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. All advertising materials mentioning features or use of this software
    must display the following acknowledgement:
 This product includes software developed by Michael Pounov <misho@elwix.org>
 ELWIX - Embedded LightWeight unIX and its contributors.
 4. Neither the name of AITNET nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
 */
 #include "global.h"  #include "global.h"
   
   
 /* builtin RPC server functions */  /* builtin RPC server functions */
   
 int  int
rpcServerClients(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)rpcServerClients(rpc_func_t *call, int ic, array_t *iv)
 {  {
        rpc_val_t *v, *vals = NULL;        rpc_srv_t *srv;
         array_t *vals;
         rpc_cli_t *cli;          rpc_cli_t *cli;
         register int i;          register int i;
        const char *str;        int len;
        char wrk[INET6_ADDRSTRLEN];        const char *str = NULL;
        struct sockaddr_in *s;        char *val, wrk[INET6_ADDRSTRLEN];
        struct sockaddr_in6 *s6; 
   
        RPC_CALLBACK_CHECK_INPUT(srv, call);        RPC_CALLBACK_CHECK_INPUT(call);
        if (!call->func_parent)
        if (rpc_srv_declValsCall(call, srv->srv_numcli) == -1) 
                 return -1;                  return -1;
         else          else
                rpc_srv_delValsCall(call);                srv = call->func_parent;
        if (rpc_srv_getValsCall(call, &vals) == -1)
         rpc_srv_getVars(call, &vals);
 
         len = srv->srv_numcli * STRSIZ;
         if (!(val = malloc(len))) {
                 LOGERR;
                 return -1;                  return -1;
           } else
                   memset(val, 0, len);
   
        for (i = 0, cli = srv->srv_clients, v = vals; i < srv->srv_numcli; cli++) {        for (i = 0, cli = srv->srv_clients; i < srv->srv_numcli; i++, cli++) {
                if (!cli->cli_sa.sa_family)                if (!cli->cli_sa.sa.sa_family)
                         continue;                          continue;
   
                if (AF_INET == cli->cli_sa.sa_family) {                switch (cli->cli_sa.sa.sa_family) {
                        s = (struct sockaddr_in*) &cli->cli_sa;                        case AF_INET:
                        str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk);                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin.sin_addr, wrk, sizeof wrk);
                } else {                                break;
                        s6 = (struct sockaddr_in6*) &cli->cli_sa;                        case AF_INET6:
                        str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk);                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin6.sin6_addr, wrk, sizeof wrk);
                                 break;
                         case AF_LOCAL:
                                 str = cli->cli_sa.sun.sun_path;
                                 break;
                 }                  }
                if (str) {                if (str)
                        RPC_SET_STR(v++, (char*) str);                        strlcat(val, (char*) str, len);
                        i++;                else
                }                        strlcat(val, "0.0.0.0", len);
                 strlcat(val, " ", len);
         }          }
   
           AIT_SET_STR(io_array(vals, 0, ait_val_t*), val);
           free(val);
         return 0;          return 0;
 }  }
   
 int  int
rpcServerCalls(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)rpcServerCalls(rpc_func_t *call, int ic, array_t *iv)
 {  {
        rpc_val_t *v, *vals = NULL;        rpc_srv_t *srv;
         array_t *vals;
         rpc_func_t *f;          rpc_func_t *f;
         register int i;          register int i;
        char str[MAXPATHLEN];        int len;
         char *val, str[MAXPATHLEN];
   
        RPC_CALLBACK_CHECK_INPUT(srv, call);        RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)
                 return -1;
         else
                 srv = call->func_parent;
   
         for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);          for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next);
           len = i * STRSIZ;
   
        if (rpc_srv_declValsCall(call, i) == -1)        rpc_srv_getVars(call, &vals);
 
         if (!(val = malloc(len))) {
                 LOGERR;
                 return -1;                  return -1;
        else        } else
                rpc_srv_delValsCall(call);                memset(val, 0, len);
        if (rpc_srv_getValsCall(call, &vals) == -1) 
                return -1; 
   
        for (f = srv->srv_funcs, v = vals; f; f = f->func_next) {        for (f = srv->srv_funcs, i = 0; f; f = f->func_next) {
                if (*f->func_name) {                if (*AIT_GET_STR(&f->func_name)) {
                        memset(str, 0, MAXPATHLEN);                        memset(str, 0, sizeof str);
                        snprintf(str, MAXPATHLEN, "/%s/%s()", f->func_file, f->func_name);                        if (AIT_ISEMPTY(&f->func_file))
                        RPC_SET_STR(v++, str);                                snprintf(str, sizeof str, "/*/%s(%d); ", 
                                                 AIT_GET_STR(&f->func_name), io_arraySize(f->func_vars));
                         else
                                 snprintf(str, sizeof str, "/%s/%s(%d); ", AIT_GET_STR(&f->func_file), 
                                                 AIT_GET_STR(&f->func_name), io_arraySize(f->func_vars));
                         strlcat(val, str, len);
                 }                  }
         }          }
   
           AIT_SET_STR(io_array(vals, 0, ait_val_t*), val);
           free(val);
         return 0;          return 0;
 }  }
   
 int  int
rpcServerSessions(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)rpcServerSessions(rpc_func_t *call, int ic, array_t *iv)
 {  {
        rpc_val_t *vals = NULL;        rpc_srv_t *srv;
         array_t *vals;
         ait_val_t *v;
   
        RPC_CALLBACK_CHECK_INPUT(srv, call);        RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)
                 return -1;
         else
                 srv = call->func_parent;
   
        if (rpc_srv_declValsCall(call, 4) == -1)        rpc_srv_getVars(call, &vals);
 
         v = io_array(vals, 0, ait_val_t*);
         AIT_SET_U8(v, srv->srv_session.sess_version);
         v = io_array(vals, 1, ait_val_t*);
         AIT_SET_U32(v, srv->srv_session.sess_program);
         v = io_array(vals, 2, ait_val_t*);
         AIT_SET_U32(v, srv->srv_session.sess_process);
         v = io_array(vals, 3, ait_val_t*);
         AIT_SET_I32(v, srv->srv_numcli);
 
         return 0;
 }
 
 int
 rpcServerShutdown(rpc_func_t *call, int ic, array_t *iv)
 {
         rpc_srv_t *srv;
 
         RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)
                 return -1;                  return -1;
         else          else
                rpc_srv_delValsCall(call);                srv = call->func_parent;
        if (rpc_srv_getValsCall(call, &vals) == -1)
         srv->srv_kill = kill;
 
         return 0;
 }
 
 // ----------------------------------------------------
 
 int
 rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_t *iv)
 {
         rpc_srv_t *srv;
 
         RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)
                 return -1;                  return -1;
           else
                   srv = call->func_parent;
   
        RPC_SET_U8(&vals[0], srv->srv_session.sess_version);        srv->srv_blob.state = kill;
        RPC_SET_U32(&vals[1], srv->srv_session.sess_program); 
        RPC_SET_U32(&vals[2], srv->srv_session.sess_process); 
        RPC_SET_I32(&vals[3], srv->srv_numcli); 
   
         return 0;          return 0;
 }  }
   
 int  int
rpcServerShutdown(rpc_srv_t * __restrict srv, rpc_func_t *call, int ic, rpc_val_t *iv)rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *iv)
 {  {
        RPC_CALLBACK_CHECK_INPUT(srv, call);        rpc_srv_t *srv;
         array_t *vals;
         rpc_blob_t *b;
         register int i;
         char *val, str[64];
         int len;
   
        pthread_mutex_lock(&rpc_mtx);        RPC_CALLBACK_CHECK_INPUT(call);
        rpc_Kill = 1;        if (!call->func_parent)
        pthread_mutex_unlock(&rpc_mtx);                return -1;
         else
                 srv = call->func_parent;
   
           rpc_srv_getVars(call, &vals);
   
           if (srv->srv_blob.state == kill) {
                   AIT_SET_STR(io_array(vals, 0, ait_val_t*), "BLOB Server is killed");
                   return 1;
           }
           if (srv->srv_blob.state == disable) {
                   AIT_SET_STR(io_array(vals, 0, ait_val_t*), "BLOB Server is disabled");
                   return 1;
           }
   
           for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
           len = i * sizeof str;
   
           if (!len) {
                   AIT_SET_STR(io_array(vals, 0, ait_val_t*), "");
                   return 0;
           }
   
           if (!(val = malloc(len))) {
                   LOGERR;
                   return -1;
           } else
                   memset(val, 0, len);
   
           for (b = srv->srv_blob.blobs, i = 0; b; i++, b = b->blob_next) {
                   memset(str, 0, sizeof str);
                   snprintf(str, sizeof str, "0x%0X(%lu)=%p ", b->blob_var, (u_long) b->blob_len, b->blob_data);
                   strlcat(val, str, len);
           }
   
           AIT_SET_STR(io_array(vals, 0, ait_val_t*), val);
           free(val);
           return 0;
   }
   
   int
   rpcBLOBServerState(rpc_func_t *call, int ic, array_t *iv)
   {
           rpc_srv_t *srv;
   
           RPC_CALLBACK_CHK_ARGS(call, ic);
           if (!call->func_parent)
                   return -1;
           else
                   srv = call->func_parent;
   
           if (AIT_TYPE(io_array(iv, 0, ait_val_t*)) != i32)
                   return -1;
   
           srv->srv_blob.state = AIT_GET_I32(io_array(iv, 0, ait_val_t*));
           return 0;
   }
   
   int
   rpcBLOBServerClients(rpc_func_t *call, int ic, array_t *iv)
   {
           rpc_srv_t *srv;
           array_t *vals;
           rpc_cli_t *cli;
           register int i;
           int len;
           const char *str = NULL;
           char *val, wrk[INET6_ADDRSTRLEN];
   
           RPC_CALLBACK_CHECK_INPUT(call);
           if (!call->func_parent)
                   return -1;
           else
                   srv = call->func_parent;
   
           rpc_srv_getVars(call, &vals);
   
           if (srv->srv_blob.state == kill) {
                   AIT_SET_STR(io_array(vals, 0, ait_val_t*), "BLOB Server is killed");
                   return 1;
           }
           if (srv->srv_blob.state == disable) {
                   AIT_SET_STR(io_array(vals, 0, ait_val_t*), "BLOB Server is disabled");
                   return 1;
           }
   
           len = srv->srv_numcli * STRSIZ;
           if (!(val = malloc(len))) {
                   LOGERR;
                   return -1;
           } else
                   memset(val, 0, len);
   
           for (i = 0, cli = srv->srv_blob.clients; i < srv->srv_numcli; i++, cli++) {
                   if (!cli->cli_sa.sa.sa_family)
                           continue;
   
                   switch (cli->cli_sa.sa.sa_family) {
                           case AF_INET:
                                   str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin.sin_addr, wrk, sizeof wrk);
                                   break;
                           case AF_INET6:
                                   str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin6.sin6_addr, wrk, sizeof wrk);
                                   break;
                           case AF_LOCAL:
                                   str = cli->cli_sa.sun.sun_path;
                                   break;
                   }
                   if (str)
                           strlcat(val, (char*) str, len);
                   else
                           strlcat(val, "0.0.0.0", len);
                   strlcat(val, " ", len);
           }
   
           AIT_SET_STR(io_array(vals, 0, ait_val_t*), val);
           free(val);
         return 0;          return 0;
 }  }

Removed from v.1.1.1.1.2.1  
changed lines
  Added in v.1.7


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