diff --git a/src/modules/keepalive/api.h b/src/modules/keepalive/api.h index bd02be8a631..db1ccbfe79b 100644 --- a/src/modules/keepalive/api.h +++ b/src/modules/keepalive/api.h @@ -37,12 +37,13 @@ typedef int ka_state; #define KA_STATE_UP 1 #define KA_STATE_DOWN 2 -typedef int (*ka_add_dest_f)(str *uri, str *owner, int flags, - int ping_interval, ka_statechanged_f statechanged_clb, ka_response_f response_clb, - void *user_attr); +typedef int (*ka_add_dest_f)(str *uri, str *owner, int flags, int ping_interval, + ka_statechanged_f statechanged_clb, ka_response_f response_clb, + void *user_attr); typedef ka_state (*ka_dest_state_f)(str *uri); typedef int (*ka_del_destination_f)(str *uri, str *owner); -typedef int (*ka_find_destination_f)(str *uri, str *owner,ka_dest_t **target,ka_dest_t **head); +typedef int (*ka_find_destination_f)( + str *uri, str *owner, ka_dest_t **target, ka_dest_t **head); typedef int (*ka_lock_destination_list_f)(); typedef int (*ka_unlock_destination_list_f)(); diff --git a/src/modules/keepalive/keepalive.h b/src/modules/keepalive/keepalive.h index f2f90907030..d5a8fcb2197 100644 --- a/src/modules/keepalive/keepalive.h +++ b/src/modules/keepalive/keepalive.h @@ -36,7 +36,7 @@ #include "../tm/tm_load.h" #define KA_INACTIVE_DST 1 /*!< inactive destination */ -#define KA_TRYING_DST 2 /*!< temporary trying destination */ +#define KA_TRYING_DST 2 /*!< temporary trying destination */ #define KA_DISABLED_DST 4 /*!< admin disabled destination */ #define KA_PROBING_DST 8 /*!< checking destination */ #define KA_STATES_ALL 15 /*!< all bits for the states of destination */ @@ -50,7 +50,8 @@ extern int ka_ping_interval; #define KA_PROBE_INACTIVE 2 #define KA_PROBE_ONLYFLAGGED 3 -#define KA_FIRST_TRY_DELAY 500 /* First OPTIONS send is done 500 millis after adding the destination */ +#define KA_FIRST_TRY_DELAY \ + 500 /* First OPTIONS send is done 500 millis after adding the destination */ typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr); typedef void (*ka_response_f)( @@ -70,12 +71,12 @@ typedef struct _ka_dest str uri; str owner; // name of destination "owner" // (module asking to monitor this destination - str uuid; // Universal id for this record + str uuid; // Universal id for this record int flags; int state; time_t last_checked, last_up, last_down; - int counter; // counts unreachable attempts - ticks_t ping_interval; /*!< Actual interval between OPTIONS */ + int counter; // counts unreachable attempts + ticks_t ping_interval; /*!< Actual interval between OPTIONS */ void *user_attr; ka_statechanged_f statechanged_clb; @@ -84,8 +85,9 @@ 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 */ - struct timer_ln *timer; /*!< Timer firing the OPTIONS test */ - gen_lock_t lock; /*!< Lock of this record to prevent being removed while running */ + struct timer_ln *timer; /*!< Timer firing the OPTIONS test */ + gen_lock_t + lock; /*!< Lock of this record to prevent being removed while running */ struct _ka_dest *next; } ka_dest_t; @@ -99,16 +101,17 @@ extern ka_destinations_list_t *ka_destinations_list; extern int ka_counter_del; extern sruid_t ka_sruid; -ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param); +ticks_t ka_check_timer(ticks_t ticks, struct timer_ln *tl, void *param); int ka_add_dest(str *uri, str *owner, int flags, int ping_interval, - ka_statechanged_f statechanged_clb, ka_response_f response_clb, - void *user_attr); + ka_statechanged_f statechanged_clb, ka_response_f response_clb, + void *user_attr); int ka_destination_state(str *uri); int ka_str_copy(str *src, str *dest, char *prefix); -int free_destination(ka_dest_t *dest) ; -int ka_del_destination(str *uri, str *owner) ; -int ka_find_destination(str *uri, str *owner, ka_dest_t **target ,ka_dest_t **head); +int free_destination(ka_dest_t *dest); +int ka_del_destination(str *uri, str *owner); +int ka_find_destination( + str *uri, str *owner, ka_dest_t **target, ka_dest_t **head); int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head); int ka_lock_destination_list(); int ka_unlock_destination_list(); diff --git a/src/modules/keepalive/keepalive_api.c b/src/modules/keepalive/keepalive_api.c index e8b1e044be8..91b7a18c500 100644 --- a/src/modules/keepalive/keepalive_api.c +++ b/src/modules/keepalive/keepalive_api.c @@ -63,16 +63,18 @@ int bind_keepalive(keepalive_api_t *api) * Add a new destination in keepalive pool */ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval, - ka_statechanged_f statechanged_clb, ka_response_f response_clb, void *user_attr) + ka_statechanged_f statechanged_clb, ka_response_f response_clb, + void *user_attr) { struct sip_uri _uri; - ka_dest_t *dest=0,*hollow=0; + ka_dest_t *dest = 0, *hollow = 0; LM_DBG("adding destination: %.*s\n", uri->len, uri->s); ka_lock_destination_list(); - if(ka_find_destination(uri , owner , &dest , &hollow)){ - LM_INFO("uri [%.*s] already in stack --ignoring \r\n",uri->len, uri->s); - dest->counter=0; + if(ka_find_destination(uri, owner, &dest, &hollow)) { + LM_INFO("uri [%.*s] already in stack --ignoring \r\n", uri->len, + uri->s); + dest->counter = 0; ka_unlock_destination_list(); return -2; } @@ -84,8 +86,9 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval, } memset(dest, 0, sizeof(ka_dest_t)); - if(uri->len >= 4 && (!strncasecmp("sip:", uri->s, 4) - || !strncasecmp("sips:", uri->s, 5))) { + if(uri->len >= 4 + && (!strncasecmp("sip:", uri->s, 4) + || !strncasecmp("sips:", uri->s, 5))) { // protocol found if(ka_str_copy(uri, &(dest->uri), NULL) < 0) goto err; @@ -111,20 +114,21 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval, dest->statechanged_clb = statechanged_clb; dest->response_clb = response_clb; dest->user_attr = user_attr; - dest->ping_interval = MS_TO_TICKS((ping_interval == 0 ? ka_ping_interval : ping_interval) * 1000) ; - if (lock_init(&dest->lock)==0){ + dest->ping_interval = MS_TO_TICKS( + (ping_interval == 0 ? ka_ping_interval : ping_interval) * 1000); + if(lock_init(&dest->lock) == 0) { LM_ERR("failed initializing Lock \n"); } - dest->timer = timer_alloc(); - if (dest->timer == NULL) { + dest->timer = timer_alloc(); + if(dest->timer == NULL) { LM_ERR("failed allocating timer\n"); goto err; - } + } timer_init(dest->timer, ka_check_timer, dest, 0); - if(timer_add(dest->timer, MS_TO_TICKS(KA_FIRST_TRY_DELAY)) < 0){ + if(timer_add(dest->timer, MS_TO_TICKS(KA_FIRST_TRY_DELAY)) < 0) { LM_ERR("failed to start timer\n"); goto err; } @@ -157,7 +161,8 @@ ka_state ka_destination_state(str *destination) for(ka_dest = ka_destinations_list->first; ka_dest != NULL; ka_dest = ka_dest->next) { if((destination->len == ka_dest->uri.len - 4) - && (strncmp(ka_dest->uri.s + 4, destination->s, ka_dest->uri.len - 4) + && (strncmp(ka_dest->uri.s + 4, destination->s, + ka_dest->uri.len - 4) == 0)) { break; } @@ -179,22 +184,23 @@ ka_state ka_destination_state(str *destination) * * * @result 1 successful , -1 fail */ -int ka_del_destination(str *uri, str *owner){ +int ka_del_destination(str *uri, str *owner) +{ LM_DBG("removing destination: %.*s\n", uri->len, uri->s); - ka_dest_t *target=0,*head=0; + ka_dest_t *target = 0, *head = 0; ka_lock_destination_list(); - if(!ka_find_destination(uri,owner,&target,&head)){ + if(!ka_find_destination(uri, owner, &target, &head)) { LM_ERR("Couldn't find destination \r\n"); goto err; } - if(!target){ + if(!target) { LM_ERR("Couldn't find destination \r\n"); goto err; } lock_get(&target->lock); - if(!head){ + if(!head) { LM_DBG("There isn't any head so maybe it is first \r\n"); ka_destinations_list->first = target->next; } else { @@ -219,22 +225,25 @@ int ka_del_destination(str *uri, str *owner){ * * * @result 1 successful , -1 fail */ -int ka_find_destination(str *uri, str *owner, ka_dest_t **target, ka_dest_t **head){ +int ka_find_destination( + str *uri, str *owner, ka_dest_t **target, ka_dest_t **head) +{ - ka_dest_t *dest=0 ,*temp=0; + ka_dest_t *dest = 0, *temp = 0; LM_DBG("finding destination: %.*s\n", uri->len, uri->s); - for(dest = ka_destinations_list->first; dest; temp=dest, dest=dest->next) { - if (STR_EQ(*uri, dest->uri) && STR_EQ(*owner, dest->owner)){ + for(dest = ka_destinations_list->first; dest; + temp = dest, dest = dest->next) { + if(STR_EQ(*uri, dest->uri) && STR_EQ(*owner, dest->owner)) { *head = temp; *target = dest; - LM_DBG("destination is found [target : %p] [head : %p] \r\n",target,temp); + LM_DBG("destination is found [target : %p] [head : %p] \r\n", + target, temp); return 1; } } return 0; - } /*! @@ -247,22 +256,24 @@ int ka_find_destination(str *uri, str *owner, ka_dest_t **target, ka_dest_t **he * * * @result 1 successful , 0 fail */ -int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head){ - ka_dest_t *dest=0 ,*temp=0; +int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head) +{ + ka_dest_t *dest = 0, *temp = 0; LM_DBG("finding destination with uuid:%.*s\n", uuid.len, uuid.s); - for(dest = ka_destinations_list->first; dest; temp = dest, dest = dest->next) { - if (STR_EQ(uuid, dest->uuid)){ + for(dest = ka_destinations_list->first; dest; + temp = dest, dest = dest->next) { + if(STR_EQ(uuid, dest->uuid)) { *head = temp; *target = dest; - LM_DBG("destination is found [target : %p] [head : %p] \r\n",target,temp); + LM_DBG("destination is found [target : %p] [head : %p] \r\n", + target, temp); return 1; } } return 0; - } @@ -274,15 +285,17 @@ int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head){ * @result 1 successful , -1 fail */ -int free_destination(ka_dest_t *dest){ - - if(dest){ - if(timer_del(dest->timer) < 0){ - LM_ERR("failed to remove timer for destination <%.*s>\n", dest->uri.len, dest->uri.s); - return -1; - } - - timer_free(dest->timer); +int free_destination(ka_dest_t *dest) +{ + + if(dest) { + if(timer_del(dest->timer) < 0) { + LM_ERR("failed to remove timer for destination <%.*s>\n", + dest->uri.len, dest->uri.s); + return -1; + } + + timer_free(dest->timer); lock_destroy(dest->lock); if(dest->uri.s) shm_free(dest->uri.s); @@ -292,23 +305,25 @@ int free_destination(ka_dest_t *dest){ if(dest->uuid.s) shm_free(dest->uuid.s); - + shm_free(dest); } return 1; } -int ka_lock_destination_list(){ - if(ka_destinations_list){ +int ka_lock_destination_list() +{ + if(ka_destinations_list) { lock_get(ka_destinations_list->lock); return 1; } return 0; } -int ka_unlock_destination_list(){ - if(ka_destinations_list){ +int ka_unlock_destination_list() +{ + if(ka_destinations_list) { lock_release(ka_destinations_list->lock); return 1; } diff --git a/src/modules/keepalive/keepalive_core.c b/src/modules/keepalive/keepalive_core.c index ea16dfdc000..0aaafa8c8da 100644 --- a/src/modules/keepalive/keepalive_core.c +++ b/src/modules/keepalive/keepalive_core.c @@ -43,8 +43,8 @@ struct tm_binds tmb; static void ka_run_route(sip_msg_t *msg, str *uri, char *route); -static void ka_options_callback(struct cell *t, int type, - struct tmcb_params *ps); +static void ka_options_callback( + struct cell *t, int type, struct tmcb_params *ps); extern str ka_ping_from; /*! \brief @@ -52,7 +52,7 @@ extern str ka_ping_from; * * This timer is regularly fired. */ -ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param) +ticks_t ka_check_timer(ticks_t ticks, struct timer_ln *tl, void *param) { ka_dest_t *ka_dest; str ka_ping_method = str_init("OPTIONS"); @@ -61,30 +61,31 @@ ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param) ka_dest = (ka_dest_t *)param; - LM_DBG("dest: %.*s\n", ka_dest->uri.len, ka_dest->uri.s); + LM_DBG("dest: %.*s\n", ka_dest->uri.len, ka_dest->uri.s); - if(ka_counter_del > 0 && ka_dest->counter > ka_counter_del) { - return (ticks_t)(0); /* stops the timer */ - } + if(ka_counter_del > 0 && ka_dest->counter > ka_counter_del) { + return (ticks_t)(0); /* stops the timer */ + } str *uuid = shm_malloc(sizeof(str)); ka_str_copy(&(ka_dest->uuid), uuid, NULL); - /* Send ping using TM-Module. + /* Send ping using TM-Module. * int request(str* m, str* ruri, str* to, str* from, str* h, * str* b, str *oburi, * transaction_cb cb, void* cbp); */ - set_uac_req(&uac_r, &ka_ping_method, 0, 0, 0, TMCB_LOCAL_COMPLETED, - ka_options_callback, (void *)uuid); + set_uac_req(&uac_r, &ka_ping_method, 0, 0, 0, TMCB_LOCAL_COMPLETED, + ka_options_callback, (void *)uuid); - if(tmb.t_request(&uac_r, &ka_dest->uri, &ka_dest->uri, &ka_ping_from, - &ka_outbound_proxy) - < 0) { - LM_ERR("unable to ping [%.*s]\n", ka_dest->uri.len, ka_dest->uri.s); - } + if(tmb.t_request(&uac_r, &ka_dest->uri, &ka_dest->uri, &ka_ping_from, + &ka_outbound_proxy) + < 0) { + LM_ERR("unable to ping [%.*s]\n", ka_dest->uri.len, ka_dest->uri.s); + } - ka_dest->last_checked = time(NULL); + ka_dest->last_checked = time(NULL); - return ka_dest->ping_interval; /* periodical, but based on dest->ping_interval, not on initial_timeout */ + return ka_dest + ->ping_interval; /* periodical, but based on dest->ping_interval, not on initial_timeout */ } /*! \brief @@ -107,15 +108,16 @@ static void ka_options_callback( // Retrieve ka_dest by uuid from destination list ka_lock_destination_list(); - ka_dest_t *ka_dest=0,*hollow=0; - if (!ka_find_destination_by_uuid(*uuid, &ka_dest, &hollow)) { + ka_dest_t *ka_dest = 0, *hollow = 0; + if(!ka_find_destination_by_uuid(*uuid, &ka_dest, &hollow)) { LM_ERR("Couldn't find destination \r\n"); shm_free(uuid->s); shm_free(uuid); ka_unlock_destination_list(); return; } - lock_get(&ka_dest->lock); // Lock record so we prevent to be removed in the meantime + lock_get( + &ka_dest->lock); // Lock record so we prevent to be removed in the meantime shm_free(uuid->s); shm_free(uuid); ka_unlock_destination_list(); @@ -130,7 +132,7 @@ static void ka_options_callback( if(ps->code >= 200 && ps->code <= 299) { state = KA_STATE_UP; ka_dest->last_down = time(NULL); - ka_dest->counter=0; + ka_dest->counter = 0; } else { state = KA_STATE_DOWN; ka_dest->last_up = time(NULL); diff --git a/src/modules/keepalive/keepalive_mod.c b/src/modules/keepalive/keepalive_mod.c index 3146ee6fb8d..6b49603c303 100644 --- a/src/modules/keepalive/keepalive_mod.c +++ b/src/modules/keepalive/keepalive_mod.c @@ -54,7 +54,7 @@ static int ka_mod_add_destination(modparam_t type, void *val); int ka_init_rpc(void); int ka_alloc_destinations_list(); static int w_cmd_is_alive(struct sip_msg *msg, char *str1, char *str2); -static int fixup_add_destination(void** param, int param_no); +static int fixup_add_destination(void **param, int param_no); static int w_add_destination(sip_msg_t *msg, char *uri, char *owner); static int w_del_destination(sip_msg_t *msg, char *uri, char *owner); static int ka_add_initial_destinations(); @@ -70,42 +70,38 @@ str ka_ping_from = str_init("sip:keepalive@kamailio.org"); int ka_counter_del = 5; - -static cmd_export_t cmds[] = { - {"ka_is_alive", (cmd_function)w_cmd_is_alive, 1, - fixup_spve_null, 0, ANY_ROUTE}, - // internal API - {"ka_add_destination", (cmd_function)w_add_destination, 2, - fixup_add_destination, 0, REQUEST_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE}, - {"ka_del_destination", (cmd_function)w_del_destination, 2, - fixup_add_destination, 0, ANY_ROUTE}, - {"bind_keepalive", (cmd_function)bind_keepalive, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; +static cmd_export_t cmds[] = {{"ka_is_alive", (cmd_function)w_cmd_is_alive, 1, + fixup_spve_null, 0, ANY_ROUTE}, + // internal API + {"ka_add_destination", (cmd_function)w_add_destination, 2, + fixup_add_destination, 0, + REQUEST_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE}, + {"ka_del_destination", (cmd_function)w_del_destination, 2, + fixup_add_destination, 0, ANY_ROUTE}, + {"bind_keepalive", (cmd_function)bind_keepalive, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}}; static param_export_t params[] = { - {"ping_interval", PARAM_INT, &ka_ping_interval}, - {"destination", PARAM_STRING | USE_FUNC_PARAM, + {"ping_interval", PARAM_INT, &ka_ping_interval}, + {"destination", PARAM_STRING | USE_FUNC_PARAM, (void *)ka_mod_add_destination}, - {"ping_from", PARAM_STR, &ka_ping_from}, - {"delete_counter", PARAM_INT, &ka_counter_del}, - {0, 0, 0} -}; + {"ping_from", PARAM_STR, &ka_ping_from}, + {"delete_counter", PARAM_INT, &ka_counter_del}, {0, 0, 0}}; /** module exports */ struct module_exports exports = { - "keepalive", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* cmd (cfg function) exports */ - params, /* param exports */ - 0, /* RPC method exports */ - 0, /* pseudo-variables exports */ - 0, /* response handling function */ - mod_init, /* module init function */ - 0, /* per-child init function */ - mod_destroy /* module destroy function */ + "keepalive", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* cmd (cfg function) exports */ + params, /* param exports */ + 0, /* RPC method exports */ + 0, /* pseudo-variables exports */ + 0, /* response handling function */ + mod_init, /* module init function */ + 0, /* per-child init function */ + mod_destroy /* module destroy function */ }; @@ -133,7 +129,7 @@ static int mod_init(void) return -1; } - if (ka_add_initial_destinations() < 0) { + if(ka_add_initial_destinations() < 0) { return -1; } @@ -145,7 +141,7 @@ static int mod_init(void) */ static void mod_destroy(void) { - if(ka_destinations_list){ + if(ka_destinations_list) { lock_release(ka_destinations_list->lock); lock_dealloc(ka_destinations_list->lock); } @@ -162,9 +158,9 @@ int ka_parse_flags(char *flag_str, int flag_len) } -static int fixup_add_destination(void** param, int param_no) +static int fixup_add_destination(void **param, int param_no) { - if (param_no == 1 || param_no == 2) { + if(param_no == 1 || param_no == 2) { return fixup_spve_all(param, param_no); } @@ -182,13 +178,13 @@ static int fixup_add_destination(void** param, int param_no) */ static int w_add_destination(sip_msg_t *msg, char *uri, char *owner) { - str suri ={0,0}; - str sowner={0,0}; - if(fixup_get_svalue(msg, (gparam_t*)uri, &suri)!=0) { + str suri = {0, 0}; + str sowner = {0, 0}; + if(fixup_get_svalue(msg, (gparam_t *)uri, &suri) != 0) { LM_ERR("unable to get uri string\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)owner, &sowner)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)owner, &sowner) != 0) { LM_ERR("unable to get owner regex\n"); return -1; } @@ -221,13 +217,13 @@ static int ki_add_destination(sip_msg_t *msg, str *uri, str *owner) */ static int w_del_destination(sip_msg_t *msg, char *uri, char *owner) { - str suri ={0,0}; - str sowner={0,0}; - if(fixup_get_svalue(msg, (gparam_t*)uri, &suri)!=0) { + str suri = {0, 0}; + str sowner = {0, 0}; + if(fixup_get_svalue(msg, (gparam_t *)uri, &suri) != 0) { LM_ERR("unable to get uri string\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)owner, &sowner)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)owner, &sowner) != 0) { LM_ERR("unable to get owner regex\n"); return -1; } @@ -248,14 +244,16 @@ static int ki_del_destination(sip_msg_t *msg, str *uri, str *owner) * It just adds destinations to an initial list to be added later in mod_init * This is required because of initialization requirements. */ -static int ka_mod_add_destination(modparam_t type, void *val) { +static int ka_mod_add_destination(modparam_t type, void *val) +{ LM_DBG("adding destination to initial list %s\n", (char *)val); char *owner = "_params"; char *uri = (char *)val; ka_initial_dest_t *current_position = NULL; - ka_initial_dest_t *new_destination = (ka_initial_dest_t *) shm_mallocxz(sizeof(ka_initial_dest_t)); + ka_initial_dest_t *new_destination = + (ka_initial_dest_t *)shm_mallocxz(sizeof(ka_initial_dest_t)); new_destination->uri.s = shm_malloc(sizeof(char) * strlen(uri)); new_destination->owner.s = shm_malloc(sizeof(char) * strlen(owner)); @@ -264,14 +262,14 @@ static int ka_mod_add_destination(modparam_t type, void *val) { memcpy(new_destination->owner.s, owner, strlen(owner)); new_destination->owner.len = strlen(owner); - + new_destination->next = NULL; - if (ka_initial_destinations_list == NULL) { + if(ka_initial_destinations_list == NULL) { ka_initial_destinations_list = new_destination; } else { current_position = ka_initial_destinations_list; - while (current_position->next != NULL) { + while(current_position->next != NULL) { current_position = current_position->next; } current_position->next = new_destination; @@ -280,15 +278,19 @@ static int ka_mod_add_destination(modparam_t type, void *val) { return 1; } -static int ka_add_initial_destinations() { +static int ka_add_initial_destinations() +{ LM_DBG("ka_add_initial_destinations called \n"); int res = 1; ka_initial_dest_t *old_position = NULL; ka_initial_dest_t *current_position = ka_initial_destinations_list; - while ( res > 0 && current_position != NULL) { - res = ka_add_dest(&(current_position->uri), &(current_position->owner), 0, ka_ping_interval, 0, 0, 0); - LM_INFO("Added initial destination Via \"destination\" parameter <%.*s> \n", current_position->uri.len, current_position->uri.s); + while(res > 0 && current_position != NULL) { + res = ka_add_dest(&(current_position->uri), &(current_position->owner), + 0, ka_ping_interval, 0, 0, 0); + LM_INFO("Added initial destination Via \"destination\" parameter " + "<%.*s> \n", + current_position->uri.len, current_position->uri.s); shm_free(current_position->uri.s); shm_free(current_position->owner.s); old_position = current_position; @@ -340,7 +342,7 @@ static int w_cmd_is_alive(struct sip_msg *msg, char *str1, char *str2) { str dest = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)str1, &dest)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)str1, &dest) != 0) { LM_ERR("failed to get dest parameter\n"); return -1; } diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index 2cab97c3dc5..c610d5434b4 100644 --- a/src/modules/keepalive/keepalive_rpc.c +++ b/src/modules/keepalive/keepalive_rpc.c @@ -54,13 +54,12 @@ static void keepalive_rpc_get(rpc_t *rpc, void *ctx); static void keepalive_rpc_flush(rpc_t *rpc, void *ctx); rpc_export_t keepalive_rpc_cmds[] = { - {"keepalive.list", keepalive_rpc_list, keepalive_rpc_list_doc, 0}, - {"keepalive.add", keepalive_rpc_add, keepalive_rpc_add_doc, 0}, - {"keepalive.del", keepalive_rpc_del, keepalive_rpc_del_doc, 0}, - {"keepalive.get", keepalive_rpc_get, keepalive_rpc_get_doc, 0}, - {"keepalive.flush", keepalive_rpc_flush, keepalive_rpc_flush_doc, 0}, - {0, 0, 0, 0} -}; + {"keepalive.list", keepalive_rpc_list, keepalive_rpc_list_doc, 0}, + {"keepalive.add", keepalive_rpc_add, keepalive_rpc_add_doc, 0}, + {"keepalive.del", keepalive_rpc_del, keepalive_rpc_del_doc, 0}, + {"keepalive.get", keepalive_rpc_get, keepalive_rpc_get_doc, 0}, + {"keepalive.flush", keepalive_rpc_flush, keepalive_rpc_flush_doc, 0}, + {0, 0, 0, 0}}; int ka_init_rpc(void) { @@ -91,7 +90,7 @@ static void keepalive_rpc_list(rpc_t *rpc, void *ctx) rpc->struct_add(sub, "s", "last up", t_buf); ctime_r(&dest->last_down, t_buf); rpc->struct_add(sub, "s", "last down", t_buf); - rpc->struct_add(sub, "d", "state", (int) dest->state); + rpc->struct_add(sub, "d", "state", (int)dest->state); } return; @@ -99,27 +98,28 @@ static void keepalive_rpc_list(rpc_t *rpc, void *ctx) static void keepalive_rpc_add(rpc_t *rpc, void *ctx) { - str sip_address = {0,0}; - str table_name ={0,0}; + str sip_address = {0, 0}; + str table_name = {0, 0}; int ret = 0; - ret = rpc->scan(ctx, "SS",&sip_address,&table_name); + ret = rpc->scan(ctx, "SS", &sip_address, &table_name); - if (ret < 2) { + if(ret < 2) { LM_ERR("not enough parameters - read so far: %d\n", ret); rpc->fault(ctx, 500, "Not enough parameters or wrong format"); return; } LM_DBG("keepalive add [%.*s]\n", sip_address.len, sip_address.s); - if(sip_address.len<1 || table_name.len <1){ - LM_ERR("parameter is len less than 1 \n" ); + if(sip_address.len < 1 || table_name.len < 1) { + LM_ERR("parameter is len less than 1 \n"); rpc->fault(ctx, 500, "parameter is len less than 1"); return; } - if(ka_add_dest(&sip_address,&table_name,0,ka_ping_interval,0,0,0) < 0 ){ - LM_ERR("couldn't add data to list \n" ); + if(ka_add_dest(&sip_address, &table_name, 0, ka_ping_interval, 0, 0, 0) + < 0) { + LM_ERR("couldn't add data to list \n"); rpc->fault(ctx, 500, "couldn't add data to list"); return; } @@ -127,17 +127,19 @@ static void keepalive_rpc_add(rpc_t *rpc, void *ctx) return; } static const char *keepalive_rpc_add_doc[2] = { - "add new destination to keepalive memory. Usage: keepalive.add sip:user@domain listname", 0}; + "add new destination to keepalive memory. Usage: keepalive.add " + "sip:user@domain listname", + 0}; static void keepalive_rpc_del(rpc_t *rpc, void *ctx) { - str sip_address = {0,0}; - str table_name ={0,0}; + str sip_address = {0, 0}; + str table_name = {0, 0}; int ret = 0; - ret = rpc->scan(ctx, "SS",&sip_address,&table_name); + ret = rpc->scan(ctx, "SS", &sip_address, &table_name); - if (ret < 2) { + if(ret < 2) { LM_ERR("not enough parameters - read so far: %d\n", ret); rpc->fault(ctx, 500, "Not enough parameters or wrong format"); return; @@ -145,14 +147,14 @@ static void keepalive_rpc_del(rpc_t *rpc, void *ctx) LM_DBG("keepalive delete [%.*s]\n", sip_address.len, sip_address.s); - if(sip_address.len < 1 || table_name.len < 1){ + if(sip_address.len < 1 || table_name.len < 1) { LM_ERR("parameter is len less than 1 \n"); rpc->fault(ctx, 500, "parameter is len less than 1"); return; } - if(ka_del_destination(&sip_address,&table_name) < 0 ){ - LM_ERR("couldn't delete data from list \n" ); + if(ka_del_destination(&sip_address, &table_name) < 0) { + LM_ERR("couldn't delete data from list \n"); rpc->fault(ctx, 500, "couldn't delete data from list"); return; } @@ -160,43 +162,45 @@ static void keepalive_rpc_del(rpc_t *rpc, void *ctx) return; } static const char *keepalive_rpc_del_doc[2] = { - "delete destination from keepalive memory. Usage: keepalive.del sip:user@domain listname", 0}; + "delete destination from keepalive memory. Usage: keepalive.del " + "sip:user@domain listname", + 0}; static void keepalive_rpc_get(rpc_t *rpc, void *ctx) { - str sip_address = {0,0}; - str table_name ={0,0}; + str sip_address = {0, 0}; + str table_name = {0, 0}; int ret = 0; - ka_dest_t *target=0 , *head =0; + ka_dest_t *target = 0, *head = 0; void *sub; - ret = rpc->scan(ctx, "SS",&sip_address,&table_name); + ret = rpc->scan(ctx, "SS", &sip_address, &table_name); - if (ret < 2) { + if(ret < 2) { LM_ERR("not enough parameters - read so far: %d\n", ret); rpc->fault(ctx, 500, "Not enough parameters or wrong format"); return; } - LM_DBG("keepalive get [%.*s]\n", sip_address.len , sip_address.s); + LM_DBG("keepalive get [%.*s]\n", sip_address.len, sip_address.s); - if(sip_address.len < 1 || table_name.len < 1){ + if(sip_address.len < 1 || table_name.len < 1) { LM_ERR("parameter is len less than 1 \n"); rpc->fault(ctx, 500, "parameter is len less than 1"); return; } ka_lock_destination_list(); - if(ka_find_destination(&sip_address, &table_name, &target, &head) < 0 ){ - LM_ERR("couldn't get data from list \n" ); + if(ka_find_destination(&sip_address, &table_name, &target, &head) < 0) { + LM_ERR("couldn't get data from list \n"); rpc->fault(ctx, 500, "couldn't get data from list"); ka_unlock_destination_list(); return; } - if(!target){ - LM_ERR("Target is empty \n" ); + if(!target) { + LM_ERR("Target is empty \n"); rpc->fault(ctx, 500, "couldn't get data from list"); ka_unlock_destination_list(); return; @@ -204,14 +208,17 @@ static void keepalive_rpc_get(rpc_t *rpc, void *ctx) rpc->add(ctx, "{", &sub); - rpc->struct_add(sub, "SSd", "uri", &target->uri, "owner", &target->owner,"state", target->state); + rpc->struct_add(sub, "SSd", "uri", &target->uri, "owner", &target->owner, + "state", target->state); ka_unlock_destination_list(); return; } static const char *keepalive_rpc_get_doc[2] = { - "get destination details from keepalive memory. Usage: keepalive.get sip:user@domain listname", 0}; + "get destination details from keepalive memory. Usage: keepalive.get " + "sip:user@domain listname", + 0}; static void keepalive_rpc_flush(rpc_t *rpc, void *ctx)