Skip to content

Commit

Permalink
persence: port script functions to new param interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu authored and liviuchircu committed Apr 4, 2019
1 parent 1567c75 commit 4824d92
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 67 deletions.
62 changes: 17 additions & 45 deletions modules/presence/presence.c
Expand Up @@ -35,7 +35,6 @@
#include <time.h>
#include <fnmatch.h>

#include "../../mod_fix.h"
#include "../../sr_module.h"
#include "../../db/db.h"
#include "../../dprint.h"
Expand Down Expand Up @@ -94,8 +93,8 @@ static int mod_init(void);
static int child_init(int);
static void destroy(void);
int stored_pres_info(struct sip_msg* msg, char* pres_uri, char* s);
static int fixup_presence(void** param, int param_no);
static int fixup_subscribe(void** param, int param_no);
static int fixup_presence(void** param);
static int fixup_subscribe(void** param);
static mi_response_t *mi_refreshWatchers(const mi_params_t *params,
struct mi_handler *async_hdl);
static mi_response_t *mi_cleanup(const mi_params_t *params,
Expand Down Expand Up @@ -148,21 +147,16 @@ static str presence_exposed_event = str_init("E_PRESENCE_EXPOSED");
event_id_t presence_event_id = EVI_ERROR;
event_id_t exposed_event_id = EVI_ERROR;

static cmd_export_t cmds[]=
{
{"handle_publish", (cmd_function)handle_publish, 0,
fixup_presence,0, REQUEST_ROUTE},
{"handle_publish", (cmd_function)handle_publish, 1,
fixup_presence, 0, REQUEST_ROUTE},
{"handle_subscribe",(cmd_function)handle_subscribe, 0,
fixup_subscribe,0, REQUEST_ROUTE},
{"handle_subscribe",(cmd_function)handle_subscribe, 1,
fixup_subscribe,0, REQUEST_ROUTE},
{"handle_subscribe",(cmd_function)handle_subscribe, 2,
fixup_subscribe,0, REQUEST_ROUTE},
{"bind_presence", (cmd_function)bind_presence, 1,
0, 0, 0},
{ 0, 0, 0, 0, 0, 0}
static cmd_export_t cmds[]={
{"handle_publish", (cmd_function)handle_publish, {
{CMD_PARAM_STR,fixup_presence,0}, {0,0,0}},
REQUEST_ROUTE},
{"handle_subscribe",(cmd_function)handle_subscribe, {
{CMD_PARAM_INT|CMD_PARAM_OPT,fixup_subscribe,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,fixup_subscribe,0},
{0,0,0}},
REQUEST_ROUTE},
{0,0,{{0,0,0}},0}
};

static param_export_t params[]={
Expand Down Expand Up @@ -516,49 +510,27 @@ static void destroy(void)
destroy_evlist();
}

static int fixup_presence(void** param, int param_no)
static int fixup_presence(void** param)
{
pv_elem_t *model;
str s;

if(library_mode)
{
LM_ERR("Bad config - you can not call 'handle_publish' function"
" (db_url not set)\n");
return -1;
}
if(param_no== 0)
return 0;

if(*param)
{
s.s = (char*)(*param); s.len = strlen(s.s);
if(pv_parse_format(&s, &model)<0)
{
LM_ERR( "wrong format[%s]\n",(char*)(*param));
return E_UNSPEC;
}

*param = (void*)model;
return 0;
}
LM_ERR( "null format\n");
return E_UNSPEC;

return 0;
}

static int fixup_subscribe(void** param, int param_no)
static int fixup_subscribe(void** param)
{
if(library_mode)
{
LM_ERR("Bad config - you can not call 'handle_subscribe' function"
" (db_url not set)\n");
return -1;
} else {
if (param_no==2)
/* second parameter is the sharing tag, which can be string
* or variable */
return fixup_sgp(param);
}

return 0;
}

Expand Down
18 changes: 4 additions & 14 deletions modules/presence/publish.c
Expand Up @@ -400,7 +400,7 @@ void msg_presentity_clean(unsigned int ticks,void *interval)
* - sends a reply in all cases (success or error).
**/

int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
int handle_publish(struct sip_msg* msg, str* sender_uri)
{
struct sip_uri puri;
str body;
Expand All @@ -411,8 +411,6 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
str etag={NULL, 0};
str extra_hdrs={NULL, 0};
str* sender= NULL;
static char buf[256];
int buf_len= 255;
pres_ev_t* event= NULL;
str pres_user;
str pres_domain;
Expand Down Expand Up @@ -558,24 +556,16 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
{
ERR_MEM(PKG_MEM_STR);
}
if(pv_printf(msg, (pv_elem_t*)sender_uri, buf, &buf_len)<0)
{
LM_ERR("cannot print the format\n");
reply_code= 500;
reply_str= pu_500_rpl;
goto error;
}
if(parse_uri(buf, buf_len, &puri)!=0)
if(parse_uri(sender_uri->s, sender_uri->len, &puri)!=0)
{
LM_ERR("bad sender SIP address!\n");
goto error;
}
else
{
LM_DBG("using user id [%.*s]\n",buf_len,buf);
LM_DBG("using user id [%.*s]\n",sender_uri->len,sender_uri->s);
}
sender->s= buf;
sender->len= buf_len;
*sender = *sender_uri;
}
/* call event specific handling function*/
if(event->evs_publ_handl)
Expand Down
2 changes: 1 addition & 1 deletion modules/presence/publish.h
Expand Up @@ -42,7 +42,7 @@

void msg_presentity_clean(unsigned int ticks,void *param);

int handle_publish(struct sip_msg* msg, char* str1 ,char* str2);
int handle_publish(struct sip_msg* msg, str* str1);

extern event_id_t presence_event_id;
extern event_id_t exposed_event_id;
Expand Down
9 changes: 3 additions & 6 deletions modules/presence/subscribe.c
Expand Up @@ -486,7 +486,7 @@ void msg_watchers_clean(unsigned int ticks,void *param)
* - sends a reply in all cases (success or error).
* TODO replace -1 return code in error case with 0 ( exit from the script)
* */
int handle_subscribe(struct sip_msg* msg, char* force_active_param, char* tag)
int handle_subscribe(struct sip_msg* msg, int* force_active_param, str* tag)
{
int init_req = 0;
subs_t subs;
Expand Down Expand Up @@ -574,10 +574,7 @@ int handle_subscribe(struct sip_msg* msg, char* force_active_param, char* tag)
reply_str= pu_500_rpl;

if (tag) {
if (fixup_get_svalue(msg, (gparam_p)tag, &subs.sh_tag)<0) {
LM_ERR("failed to get value from sh tag param\n");
goto error;
}
subs.sh_tag = *tag;
if (c_api.shtag_get( &subs.sh_tag, pres_cluster_id)<0) {
LM_ERR("failed to lookup the <%.*s> sharing tag\n",
subs.sh_tag.len, subs.sh_tag.s);
Expand Down Expand Up @@ -629,7 +626,7 @@ int handle_subscribe(struct sip_msg* msg, char* force_active_param, char* tag)
/* if dialog initiation Subscribe - get subscription state */
if(init_req)
{
if(!event->req_auth ||(force_active_param && force_active_param[0] == '1'))
if(!event->req_auth ||(force_active_param && *force_active_param == 1))
subs.status = ACTIVE_STATUS;
else
{
Expand Down
2 changes: 1 addition & 1 deletion modules/presence/subscribe.h
Expand Up @@ -76,7 +76,7 @@ void msg_active_watchers_clean(unsigned int ticks,void *param);

void msg_watchers_clean(unsigned int ticks,void *param);

int handle_subscribe(struct sip_msg*, char*, char*);
int handle_subscribe(struct sip_msg*, int*, str*);

int delete_db_subs(str pres_uri, str ev_stored_name, str to_tag);

Expand Down

0 comments on commit 4824d92

Please sign in to comment.