Skip to content

Commit

Permalink
keepalive: declare variables at the beginning of functions
Browse files Browse the repository at this point in the history
- fix for C standard older than C99
  • Loading branch information
miconda committed Apr 5, 2017
1 parent e564247 commit fd70526
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
8 changes: 3 additions & 5 deletions src/modules/keepalive/keepalive.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* keepalive module - remote destinations probing
*
*
* Copyright (C) 2017 Guillaume Bour <guillaume@bour.cc>
*
* This file is part of Kamailio, a free SIP server.
Expand All @@ -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
*/

Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions src/modules/keepalive/keepalive_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -132,4 +134,3 @@ ka_state ka_destination_state(str destination) {

return ka_dest->state;
}

4 changes: 2 additions & 2 deletions src/modules/keepalive/keepalive_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
29 changes: 16 additions & 13 deletions src/modules/keepalive/keepalive_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit fd70526

Please sign in to comment.