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

version 1.3.2.3, 2011/08/31 17:11:58 version 1.7, 2012/05/14 08:39:05
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 53  rpcServerClients(rpc_func_t *call, int ic, array_t *iv Line 53  rpcServerClients(rpc_func_t *call, int ic, array_t *iv
 {  {
         rpc_srv_t *srv;          rpc_srv_t *srv;
         array_t *vals;          array_t *vals;
         ait_val_t *v;  
         rpc_cli_t *cli;          rpc_cli_t *cli;
         register int i;          register int i;
           int len;
         const char *str = NULL;          const char *str = NULL;
        char wrk[INET6_ADDRSTRLEN];        char *val, wrk[INET6_ADDRSTRLEN];
        struct sockaddr_in *s; 
        struct sockaddr_in6 *s6; 
        struct sockaddr_un *su; 
   
         RPC_CALLBACK_CHECK_INPUT(call);          RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)          if (!call->func_parent)
Line 68  rpcServerClients(rpc_func_t *call, int ic, array_t *iv Line 65  rpcServerClients(rpc_func_t *call, int ic, array_t *iv
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
        if (!(vals = rpc_srv_returnVars(call, srv->srv_numcli)))        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; i < srv->srv_numcli; i++, cli++) {          for (i = 0, cli = srv->srv_clients; i < srv->srv_numcli; i++, cli++) {
                v = io_array(vals, i, ait_val_t*);                if (!cli->cli_sa.sa.sa_family)
                if (!cli->cli_sa.sa_family) { 
                        AIT_SET_STR(v, ""); 
                         continue;                          continue;
                 }  
   
                switch (cli->cli_sa.sa_family) {                switch (cli->cli_sa.sa.sa_family) {
                         case AF_INET:                          case AF_INET:
                                s = (struct sockaddr_in*) &cli->cli_sa;                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin.sin_addr, wrk, sizeof wrk);
                                str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk); 
                                 break;                                  break;
                         case AF_INET6:                          case AF_INET6:
                                s6 = (struct sockaddr_in6*) &cli->cli_sa;                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin6.sin6_addr, wrk, sizeof wrk);
                                str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk); 
                                 break;                                  break;
                         case AF_LOCAL:                          case AF_LOCAL:
                                su = (struct sockaddr_un*) &cli->cli_sa;                                str = cli->cli_sa.sun.sun_path;
                                str = su->sun_path; 
                                 break;                                  break;
                 }                  }
                 if (str)                  if (str)
                        AIT_SET_STR(v, (char*) str);                        strlcat(val, (char*) str, len);
                 else                  else
                        AIT_SET_STR(v, "0.0.0.0");                        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;
 }  }
   
Line 106  rpcServerCalls(rpc_func_t *call, int ic, array_t *iv) Line 106  rpcServerCalls(rpc_func_t *call, int ic, array_t *iv)
 {  {
         rpc_srv_t *srv;          rpc_srv_t *srv;
         array_t *vals;          array_t *vals;
         ait_val_t *v;  
         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(call);          RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)          if (!call->func_parent)
Line 118  rpcServerCalls(rpc_func_t *call, int ic, array_t *iv) Line 118  rpcServerCalls(rpc_func_t *call, int ic, array_t *iv)
                 srv = call->func_parent;                  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);
        if (!(vals = rpc_srv_returnVars(call, i)))        len = i * STRSIZ;
 
         rpc_srv_getVars(call, &vals);
 
         if (!(val = malloc(len))) {
                 LOGERR;
                 return -1;                  return -1;
           } else
                   memset(val, 0, len);
   
         for (f = srv->srv_funcs, i = 0; 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, sizeof str);                          memset(str, 0, sizeof str);
                        snprintf(str, sizeof str, "/%s/%s()", f->func_file, f->func_name);                        if (AIT_ISEMPTY(&f->func_file))
                        v = io_array(vals, i++, ait_val_t*);                                snprintf(str, sizeof str, "/*/%s(%d); ", 
                        AIT_SET_STR(v, str);                                                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;
 }  }
   
Line 146  rpcServerSessions(rpc_func_t *call, int ic, array_t *i Line 159  rpcServerSessions(rpc_func_t *call, int ic, array_t *i
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
        if (!(vals = rpc_srv_returnVars(call, 4)))        rpc_srv_getVars(call, &vals);
                return -1; 
   
         v = io_array(vals, 0, ait_val_t*);          v = io_array(vals, 0, ait_val_t*);
         AIT_SET_U8(v, srv->srv_session.sess_version);          AIT_SET_U8(v, srv->srv_session.sess_version);
Line 172  rpcServerShutdown(rpc_func_t *call, int ic, array_t *i Line 184  rpcServerShutdown(rpc_func_t *call, int ic, array_t *i
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
         pthread_mutex_lock(&srv->srv_mtx);  
         srv->srv_kill = kill;          srv->srv_kill = kill;
         pthread_mutex_unlock(&srv->srv_mtx);  
   
         return 0;          return 0;
 }  }
Line 192  rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_ Line 202  rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
         pthread_mutex_lock(&srv->srv_blob.mtx);  
         srv->srv_blob.state = kill;          srv->srv_blob.state = kill;
         pthread_mutex_unlock(&srv->srv_blob.mtx);  
   
         return 0;          return 0;
 }  }
Line 204  rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i Line 212  rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i
 {  {
         rpc_srv_t *srv;          rpc_srv_t *srv;
         array_t *vals;          array_t *vals;
         ait_val_t *v;  
         rpc_blob_t *b;          rpc_blob_t *b;
         register int i;          register int i;
           char *val, str[64];
           int len;
   
         RPC_CALLBACK_CHECK_INPUT(call);          RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)          if (!call->func_parent)
Line 214  rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i Line 223  rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
        pthread_mutex_lock(&srv->srv_blob.mtx);        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);          for (i = 0, b = srv->srv_blob.blobs; b; i++, b = b->blob_next);
        if (!(vals = rpc_srv_returnVars(call, i))) {        len = i * sizeof str;
                pthread_mutex_unlock(&srv->srv_blob.mtx);
         if (!len) {
                 AIT_SET_STR(io_array(vals, 0, ait_val_t*), "");
                 return 0;                  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) {          for (b = srv->srv_blob.blobs, i = 0; b; i++, b = b->blob_next) {
                v = io_array(vals, i, ait_val_t*);                memset(str, 0, sizeof str);
                AIT_SET_U32(v, b->blob_var);                snprintf(str, sizeof str, "0x%0X(%lu)=%p ", b->blob_var, (u_long) b->blob_len, b->blob_data);
                 strlcat(val, str, len);
         }          }
         pthread_mutex_unlock(&srv->srv_blob.mtx);  
   
           AIT_SET_STR(io_array(vals, 0, ait_val_t*), val);
           free(val);
         return 0;          return 0;
 }  }
   
Line 253  rpcBLOBServerClients(rpc_func_t *call, int ic, array_t Line 282  rpcBLOBServerClients(rpc_func_t *call, int ic, array_t
 {  {
         rpc_srv_t *srv;          rpc_srv_t *srv;
         array_t *vals;          array_t *vals;
         ait_val_t *v;  
         rpc_cli_t *cli;          rpc_cli_t *cli;
         register int i;          register int i;
           int len;
         const char *str = NULL;          const char *str = NULL;
        char wrk[INET6_ADDRSTRLEN];        char *val, wrk[INET6_ADDRSTRLEN];
        struct sockaddr_in *s; 
        struct sockaddr_in6 *s6; 
        struct sockaddr_un *su; 
   
         RPC_CALLBACK_CHECK_INPUT(call);          RPC_CALLBACK_CHECK_INPUT(call);
         if (!call->func_parent)          if (!call->func_parent)
Line 268  rpcBLOBServerClients(rpc_func_t *call, int ic, array_t Line 294  rpcBLOBServerClients(rpc_func_t *call, int ic, array_t
         else          else
                 srv = call->func_parent;                  srv = call->func_parent;
   
        if (!(vals = rpc_srv_returnVars(call, srv->srv_numcli)))        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;                  return -1;
           } else
                   memset(val, 0, len);
   
         for (i = 0, cli = srv->srv_blob.clients; i < srv->srv_numcli; i++, cli++) {          for (i = 0, cli = srv->srv_blob.clients; i < srv->srv_numcli; i++, cli++) {
                v = io_array(vals, i, ait_val_t*);                if (!cli->cli_sa.sa.sa_family)
 
                if (!cli->cli_sa.sa_family) { 
                        AIT_SET_STR(v, ""); 
                         continue;                          continue;
                 }  
   
                switch (cli->cli_sa.sa_family) {                switch (cli->cli_sa.sa.sa_family) {
                         case AF_INET:                          case AF_INET:
                                s = (struct sockaddr_in*) &cli->cli_sa;                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin.sin_addr, wrk, sizeof wrk);
                                str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk); 
                                 break;                                  break;
                         case AF_INET6:                          case AF_INET6:
                                s6 = (struct sockaddr_in6*) &cli->cli_sa;                                str = inet_ntop(cli->cli_sa.sa.sa_family, &cli->cli_sa.sin6.sin6_addr, wrk, sizeof wrk);
                                str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk); 
                                 break;                                  break;
                         case AF_LOCAL:                          case AF_LOCAL:
                                su = (struct sockaddr_un*) &cli->cli_sa;                                str = cli->cli_sa.sun.sun_path;
                                str = su->sun_path; 
                                 break;                                  break;
                 }                  }
                 if (str)                  if (str)
                        AIT_SET_STR(v, (char*) str);                        strlcat(val, (char*) str, len);
                 else                  else
                        AIT_SET_STR(v, "0.0.0.0");                        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.3.2.3  
changed lines
  Added in v.1.7


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