Skip to content

Commit

Permalink
http_async_client: propagate route name to https async callback
Browse files Browse the repository at this point in the history
- lookup actions in target process, rather than in originating one
  • Loading branch information
miconda committed Dec 5, 2017
1 parent ad68b65 commit 2469b79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
34 changes: 27 additions & 7 deletions src/modules/http_async_client/async_http.c
Expand Up @@ -124,22 +124,36 @@ void async_http_cb(struct http_m_reply *reply, void *param)
{
async_query_t *aq;
cfg_action_t *act;
int ri;
unsigned int tindex;
unsigned int tlabel;
struct cell *t = NULL;
char *p;
str newbuf = {0, 0};
sip_msg_t *fmsg;

if (reply->result != NULL) {
LM_DBG("query result = %.*s [%d]\n", reply->result->len, reply->result->s, reply->result->len);
}
aq = param;

/* clean process-local result variables */
ah_error.s = NULL;
ah_error.len = 0;
memset(ah_reply, 0, sizeof(struct sip_msg));

ri = route_lookup(&main_rt, aq->cbname);
if(ri<0) {
LM_ERR("unable to find route block [%s]\n", aq->cbname);
goto done;
}
act = main_rt.rlist[ri];
if(act==NULL) {
LM_ERR("empty action lists in route block [%s]\n", aq->cbname);
goto done;
}

if (reply->result != NULL) {
LM_DBG("query result = %.*s [%d]\n", reply->result->len, reply->result->s, reply->result->len);
}

/* set process-local result variables */
if (reply->result == NULL) {
/* error */
Expand Down Expand Up @@ -189,12 +203,10 @@ void async_http_cb(struct http_m_reply *reply, void *param)
}
}

aq = param;
strncpy(q_id, aq->id, strlen(aq->id));

q_id[strlen(aq->id)] = '\0';

act = (cfg_action_t*)aq->param;
cfg_update();

if (aq->query_params.suspend_transaction) {
Expand Down Expand Up @@ -228,6 +240,7 @@ void async_http_cb(struct http_m_reply *reply, void *param)
LM_ERR("failure inside run_top_route\n");
}

done:
free_sip_msg(ah_reply);
free_async_query(aq);

Expand Down Expand Up @@ -391,7 +404,7 @@ int init_socket(async_http_worker_t *worker)
return (0);
}

int async_send_query(sip_msg_t *msg, str *query, cfg_action_t *act)
int async_send_query(sip_msg_t *msg, str *query, str *cbname)
{
async_query_t *aq;
unsigned int tindex = 0;
Expand All @@ -405,6 +418,11 @@ int async_send_query(sip_msg_t *msg, str *query, cfg_action_t *act)
LM_ERR("invalid parameters\n");
return -1;
}
if(cbname->len>=MAX_CBNAME_LEN-1) {
LM_ERR("callback name is too long: %d / %.*s\n", cbname->len,
cbname->len, cbname->s);
return -1;
}

t = tmb.t_gett();
if (t==NULL || t==T_UNDEFINED) {
Expand Down Expand Up @@ -440,7 +458,9 @@ int async_send_query(sip_msg_t *msg, str *query, cfg_action_t *act)
goto error;
}

aq->param = act;
memcpy(aq->cbname, cbname->s, cbname->len);
aq->cbname[cbname->len] = '\0';
aq->cbname_len = cbname->len;
aq->tindex = tindex;
aq->tlabel = tlabel;

Expand Down
6 changes: 4 additions & 2 deletions src/modules/http_async_client/async_http.h
Expand Up @@ -38,6 +38,7 @@
#define ERROR_AVP_NAME "http_error"
#define ERROR_AVP_NAME_LENGTH 10
#define MAX_ID_LEN 32
#define MAX_CBNAME_LEN 64

#include <curl/curl.h>
#include <event2/event.h>
Expand Down Expand Up @@ -107,14 +108,15 @@ typedef struct async_query {
unsigned int tindex;
unsigned int tlabel;
struct query_params query_params;
void *param;
char cbname[MAX_CBNAME_LEN];
int cbname_len;
} async_query_t;

int async_http_init_sockets(async_http_worker_t *worker);
int async_http_init_worker(int prank, async_http_worker_t* worker);
void async_http_run_worker(async_http_worker_t* worker);

int async_send_query(sip_msg_t *msg, str *query, cfg_action_t *act);
int async_send_query(sip_msg_t *msg, str *query, str *cbname);
int async_push_query(async_query_t *aq);

void notification_socket_cb(int fd, short event, void *arg);
Expand Down
18 changes: 3 additions & 15 deletions src/modules/http_async_client/http_async_client_mod.c
Expand Up @@ -383,9 +383,7 @@ static void mod_destroy(void)
static int w_http_async_query(sip_msg_t *msg, char *query, char* rt)
{
str sdata;
cfg_action_t *act;
str rn;
int ri;

if(msg==NULL)
return -1;
Expand All @@ -404,21 +402,11 @@ static int w_http_async_query(sip_msg_t *msg, char *query, char* rt)
LM_ERR("no route block name\n");
return -1;
}

ri = route_lookup(&main_rt, rn.s);
if(ri<0)
{
LM_ERR("unable to find route block [%.*s]\n", rn.len, rn.s);
return -1;
}
act = main_rt.rlist[ri];
if(act==NULL)
{
LM_ERR("empty action lists in route block [%.*s]\n", rn.len, rn.s);
if(rn.s==NULL || rn.len == 0) {
LM_ERR("invalid route name parameter\n");
return -1;
}

return async_send_query(msg, &sdata, act);
return async_send_query(msg, &sdata, &rn);

}

Expand Down

0 comments on commit 2469b79

Please sign in to comment.