From fd7052681020b775be253fd936dde8f76a85e198 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 5 Apr 2017 08:45:33 +0200 Subject: [PATCH] keepalive: declare variables at the beginning of functions - fix for C standard older than C99 --- src/modules/keepalive/keepalive.h | 8 +++----- src/modules/keepalive/keepalive_api.c | 7 ++++--- src/modules/keepalive/keepalive_mod.c | 4 ++-- src/modules/keepalive/keepalive_rpc.c | 29 +++++++++++++++------------ 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/modules/keepalive/keepalive.h b/src/modules/keepalive/keepalive.h index e495fb60028..11c06aeaf35 100644 --- a/src/modules/keepalive/keepalive.h +++ b/src/modules/keepalive/keepalive.h @@ -1,6 +1,6 @@ /** * keepalive module - remote destinations probing - * + * * Copyright (C) 2017 Guillaume Bour * * This file is part of Kamailio, a free SIP server. @@ -15,8 +15,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -57,7 +57,6 @@ typedef struct _ka_dest time_t last_checked, last_up, last_down; - //ds_attrs_t attrs; void *user_attr; ka_statechanged_f statechanged_clb; @@ -66,7 +65,6 @@ typedef struct _ka_dest struct ip_addr ip_address; /*!< IP-Address of the entry */ unsigned short int port; /*!< Port of the URI */ unsigned short int proto; /*!< Protocol of the URI */ - //int message_count; struct _ka_dest *next; } ka_dest_t; diff --git a/src/modules/keepalive/keepalive_api.c b/src/modules/keepalive/keepalive_api.c index 768de452f8a..29de0f6238f 100644 --- a/src/modules/keepalive/keepalive_api.c +++ b/src/modules/keepalive/keepalive_api.c @@ -60,9 +60,12 @@ int bind_keepalive(keepalive_api_t* api) * Add a new destination in keepalive pool */ int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void *user_attr) { + struct sip_uri _uri; + ka_dest_t *dest; + LM_INFO("adding destination: %.*s\n", uri.len, uri.s); - ka_dest_t *dest = (ka_dest_t *) shm_malloc(sizeof(ka_dest_t)); + dest = (ka_dest_t *) shm_malloc(sizeof(ka_dest_t)); if(dest == NULL) { LM_ERR("no more memory.\n"); goto err; @@ -79,7 +82,6 @@ int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void } // checking uri is valid - struct sip_uri _uri; if (parse_uri(dest->uri.s, dest->uri.len, &_uri) != 0) { LM_ERR("invalid uri <%.*s>\n", dest->uri.len, dest->uri.s); goto err; @@ -132,4 +134,3 @@ ka_state ka_destination_state(str destination) { return ka_dest->state; } - diff --git a/src/modules/keepalive/keepalive_mod.c b/src/modules/keepalive/keepalive_mod.c index 769503acaf6..2db3f1e8901 100644 --- a/src/modules/keepalive/keepalive_mod.c +++ b/src/modules/keepalive/keepalive_mod.c @@ -142,7 +142,7 @@ int ka_parse_flags( char* flag_str, int flag_len ) * Function callback executer per module param "destination". * Is just a wrapper to ka_add_dest() api function */ -static int ka_mod_add_destination(modparam_t type, void *val) +static int ka_mod_add_destination(modparam_t type, void *val) { if (ka_alloc_destinations_list() < 0) return -1; @@ -156,7 +156,7 @@ static int ka_mod_add_destination(modparam_t type, void *val) /* * Allocate global variable *ka_destination_list* if not already done - * WHY: when specifying static destinations as module param, ka_mod_add_destination() is + * WHY: when specifying static destinations as module param, ka_mod_add_destination() is * executed BEFORE mod_init() */ int ka_alloc_destinations_list() diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index e1749b56bae..cb080ca1ee7 100644 --- a/src/modules/keepalive/keepalive_rpc.c +++ b/src/modules/keepalive/keepalive_rpc.c @@ -61,38 +61,41 @@ static const char *keepalive_rpc_list_doc[2] = { "Return the content of dispatcher sets", 0}; static void keepalive_rpc_list(rpc_t *rpc, void *ctx) { + void *foo, *bar, *baz; + void *sub; + ka_dest_t *dest; + char *_ctime; + char *_utime; + char *_dtime; str text = str_init("foobar"); - if (rpc->add(ctx, "Sd", &text, 42) < 0) - LM_ERR("%s: error creating RPC struct\n", __FUNCTION__); - if (rpc->add(ctx, "Sd", &text, 42) < 0) - LM_ERR("%s: error creating RPC struct\n", __FUNCTION__); - void *foo; + if (rpc->add(ctx, "Sd", &text, 42) < 0) + LM_ERR("failed creating RPC struct\n"); + if (rpc->add(ctx, "Sd", &text, 42) < 0) + LM_ERR("failed creating RPC struct\n"); + rpc->add(ctx, "{", &foo); rpc->struct_add(foo, "Sd", "text", &text, "number", 42); - void *bar, *baz; rpc->add(ctx, "{", &bar); rpc->struct_add(bar, "[", "list", &baz); rpc->struct_add(baz, "d", "nn", 17); rpc->struct_add(baz, "d", "nn", 22); - - for(ka_dest_t *dest = ka_destinations_list->first; dest != NULL; dest = dest->next) { - void *sub; + for(dest = ka_destinations_list->first; dest != NULL; dest = dest->next) { rpc->add(ctx, "{", &sub); - rpc->struct_add(sub, "SS", + rpc->struct_add(sub, "SS", "uri" , &dest->uri, "owner", &dest->owner); - char *_ctime = ctime(&dest->last_checked); + _ctime = ctime(&dest->last_checked); _ctime[strlen(_ctime) - 1] = '\0'; rpc->struct_add(sub, "s", "last checked", _ctime); - char *_utime = ctime(&dest->last_up); + _utime = ctime(&dest->last_up); _utime[strlen(_utime) - 1] = '\0'; rpc->struct_add(sub, "s", "last up", _utime); - char *_dtime = ctime(&dest->last_down); + _dtime = ctime(&dest->last_down); _dtime[strlen(_dtime) - 1] = '\0'; rpc->struct_add(sub, "s", "last down", _dtime); }