--- libaitrpc/src/builtin.c 2011/09/07 07:24:21 1.4 +++ libaitrpc/src/builtin.c 2012/05/15 23:28:20 1.7.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: builtin.c,v 1.4 2011/09/07 07:24:21 misho Exp $ +* $Id: builtin.c,v 1.7.2.1 2012/05/15 23:28:20 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -52,15 +52,12 @@ int rpcServerClients(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]; - struct sockaddr_in *s; - struct sockaddr_in6 *s6; - struct sockaddr_un *su; + char *val; + ait_val_t v; RPC_CALLBACK_CHECK_INPUT(call); if (!call->func_parent) @@ -68,41 +65,28 @@ rpcServerClients(rpc_func_t *call, int ic, array_t *iv else srv = call->func_parent; - rpc_srv_getVars(call, &vals); - - len = srv->srv_numcli * STRSIZ; + len = io_arraySize(srv->srv_clients) * STRSIZ; if (!(val = malloc(len))) { LOGERR; return -1; } else memset(val, 0, len); - for (i = 0, cli = srv->srv_clients; i < srv->srv_numcli; i++, cli++) { - if (!cli->cli_sa.sa_family) + for (i = 0; i < io_arraySize(srv->srv_clients); i++) { + cli = io_array(srv->srv_clients, i, rpc_cli_t*); + if (!cli) continue; - switch (cli->cli_sa.sa_family) { - case AF_INET: - s = (struct sockaddr_in*) &cli->cli_sa; - str = inet_ntop(cli->cli_sa.sa_family, &s->sin_addr, wrk, sizeof wrk); - break; - case AF_INET6: - s6 = (struct sockaddr_in6*) &cli->cli_sa; - str = inet_ntop(cli->cli_sa.sa_family, &s6->sin6_addr, wrk, sizeof wrk); - break; - case AF_LOCAL: - su = (struct sockaddr_un*) &cli->cli_sa; - str = su->sun_path; - break; - } + str = io_n2addr(&cli->cli_sa, &v); if (str) strlcat(val, (char*) str, len); else strlcat(val, "0.0.0.0", len); strlcat(val, " ", len); + AIT_FREE_VAL(&v); } - AIT_SET_STR(io_array(vals, 0, ait_val_t*), val); + AIT_SET_STR(io_array(call->func_vars, 0, ait_val_t*), val); free(val); return 0; } @@ -111,9 +95,8 @@ int rpcServerCalls(rpc_func_t *call, int ic, array_t *iv) { rpc_srv_t *srv; - array_t *vals; rpc_func_t *f; - register int i; + register int i = 0; int len; char *val, str[MAXPATHLEN]; @@ -123,27 +106,25 @@ rpcServerCalls(rpc_func_t *call, int ic, array_t *iv) else srv = call->func_parent; - for (i = 0, f = srv->srv_funcs; f; i++, f = f->func_next); + TAILQ_FOREACH(f, &srv->srv_funcs, func_node) + i++; len = i * STRSIZ; - rpc_srv_getVars(call, &vals); - if (!(val = malloc(len))) { LOGERR; return -1; } else memset(val, 0, len); - for (f = srv->srv_funcs, i = 0; f; f = f->func_next) { - if (*f->func_name) { + TAILQ_FOREACH(f, &srv->srv_funcs, func_node) + if (AIT_ADDR(&f->func_name)) { memset(str, 0, sizeof str); - snprintf(str, sizeof str, "/%s/%s(%d); ", - f->func_file, f->func_name, io_arraySize(f->func_vars)); + snprintf(str, sizeof str, "/%hu/0x%p(%d); ", AIT_KEY(&f->func_name), + AIT_ADDR(&f->func_name), io_arraySize(f->func_vars)); strlcat(val, str, len); } - } - AIT_SET_STR(io_array(vals, 0, ait_val_t*), val); + AIT_SET_STR(io_array(f->func_vars, 0, ait_val_t*), val); free(val); return 0; } @@ -152,7 +133,6 @@ int rpcServerSessions(rpc_func_t *call, int ic, array_t *iv) { rpc_srv_t *srv; - array_t *vals; ait_val_t *v; RPC_CALLBACK_CHECK_INPUT(call); @@ -161,16 +141,14 @@ rpcServerSessions(rpc_func_t *call, int ic, array_t *i else srv = call->func_parent; - rpc_srv_getVars(call, &vals); - - v = io_array(vals, 0, ait_val_t*); + v = io_array(call->func_vars, 0, ait_val_t*); AIT_SET_U8(v, srv->srv_session.sess_version); - v = io_array(vals, 1, ait_val_t*); + v = io_array(call->func_vars, 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); + v = io_array(call->func_vars, 2, ait_val_t*); + AIT_SET_U8(v, srv->srv_session.sess_process); + v = io_array(call->func_vars, 3, ait_val_t*); + AIT_SET_I32(v, io_arraySize(srv->srv_clients)); return 0; } @@ -186,15 +164,14 @@ rpcServerShutdown(rpc_func_t *call, int ic, array_t *i else srv = call->func_parent; - pthread_mutex_lock(&srv->srv_mtx); srv->srv_kill = kill; - pthread_mutex_unlock(&srv->srv_mtx); return 0; } -// ---------------------------------------------------- +/* ---------------------------------------------------- */ +#if 0 int rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_t *iv) { @@ -206,9 +183,7 @@ rpcBLOBServerShutdown(rpc_func_t *call, int ic, array_ else srv = call->func_parent; - pthread_mutex_lock(&srv->srv_blob.mtx); srv->srv_blob.state = kill; - pthread_mutex_unlock(&srv->srv_blob.mtx); return 0; } @@ -240,19 +215,16 @@ rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i return 1; } - pthread_mutex_lock(&srv->srv_blob.mtx); 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*), ""); - pthread_mutex_unlock(&srv->srv_blob.mtx); return 0; } if (!(val = malloc(len))) { LOGERR; - pthread_mutex_unlock(&srv->srv_blob.mtx); return -1; } else memset(val, 0, len); @@ -265,7 +237,6 @@ rpcBLOBServerVars(rpc_func_t *call, int ic, array_t *i AIT_SET_STR(io_array(vals, 0, ait_val_t*), val); free(val); - pthread_mutex_unlock(&srv->srv_blob.mtx); return 0; } @@ -283,9 +254,7 @@ rpcBLOBServerState(rpc_func_t *call, int ic, array_t * if (AIT_TYPE(io_array(iv, 0, ait_val_t*)) != i32) return -1; - pthread_mutex_lock(&srv->srv_mtx); srv->srv_blob.state = AIT_GET_I32(io_array(iv, 0, ait_val_t*)); - pthread_mutex_unlock(&srv->srv_mtx); return 0; } @@ -299,9 +268,6 @@ rpcBLOBServerClients(rpc_func_t *call, int ic, array_t int len; const char *str = NULL; char *val, wrk[INET6_ADDRSTRLEN]; - struct sockaddr_in *s; - struct sockaddr_in6 *s6; - struct sockaddr_un *su; RPC_CALLBACK_CHECK_INPUT(call); if (!call->func_parent) @@ -328,21 +294,18 @@ rpcBLOBServerClients(rpc_func_t *call, int ic, array_t memset(val, 0, len); for (i = 0, cli = srv->srv_blob.clients; i < srv->srv_numcli; i++, cli++) { - if (!cli->cli_sa.sa_family) + if (!cli->cli_sa.sa.sa_family) continue; - switch (cli->cli_sa.sa_family) { + switch (cli->cli_sa.sa.sa_family) { case AF_INET: - s = (struct sockaddr_in*) &cli->cli_sa; - 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); break; case AF_INET6: - s6 = (struct sockaddr_in6*) &cli->cli_sa; - 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: - su = (struct sockaddr_un*) &cli->cli_sa; - str = su->sun_path; + str = cli->cli_sa.sun.sun_path; break; } if (str) @@ -356,3 +319,4 @@ rpcBLOBServerClients(rpc_func_t *call, int ic, array_t free(val); return 0; } +#endif