Module: sip-router Branch: master Commit: 77209fb7fcfc793928719d966ebc2b174681f17d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=77209fb7...
Author: Peter Dunkley peter.dunkley@crocodile-rcs.com Committer: Peter Dunkley peter.dunkley@crocodile-rcs.com Date: Thu Mar 29 15:58:39 2012 +0100
modules/mqueue: Queue names can now be in pseudo variables
- mq_add()/mq_fetch() can use pseudo variables (as well as strings) for queue names. - $mqk()/$mqv() can use pseudo variables (as well as strings) for for queue names.
---
modules/mqueue/mqueue_api.c | 96 +++++++++++++++++++++++++++++++------------ modules/mqueue/mqueue_api.h | 3 +- modules/mqueue/mqueue_mod.c | 33 ++++++++++----- 3 files changed, 93 insertions(+), 39 deletions(-)
diff --git a/modules/mqueue/mqueue_api.c b/modules/mqueue/mqueue_api.c index a86d375..efa6290 100644 --- a/modules/mqueue/mqueue_api.c +++ b/modules/mqueue/mqueue_api.c @@ -33,6 +33,7 @@ #include "../../parser/parse_param.h" #include "../../ut.h" #include "../../shm_init.h" +#include "../../lib/kcore/faked_msg.h"
#include "mqueue_api.h"
@@ -353,21 +354,54 @@ int mq_item_add(str *qname, str *key, str *val) /** * */ -int pv_parse_mqk_name(pv_spec_t *sp, str *in) +int pv_parse_mq_name(pv_spec_t *sp, str *in) { - mq_head_t *mh = NULL; - mh = mq_head_get(in); - if(mh==NULL) - { - LM_ERR("mqueue not found: %.*s\n", in->len, in->s); - return -1; - } sp->pvp.pvn.u.isname.name.s = *in; sp->pvp.pvn.type = PV_NAME_INTSTR; sp->pvp.pvn.u.isname.type = 1; return 0; }
+str *pv_get_mq_name(str *in) +{ + str *queue; + + if (in->s[0] != '$') + queue = in; + else + { + pv_spec_t *pvs; + pv_value_t pvv; + + if (pv_locate_name(in) != in->len) + { + LM_ERR("invalid pv [%.*s]\n", in->len, in->s); + return NULL; + } + if ((pvs = pv_cache_get(in)) == NULL) + { + LM_ERR("failed to get pv spec for [%.*s]\n", in->len, in->s); + return NULL; + } + + memset(&pvv, 0, sizeof(pv_value_t)); + if (faked_msg_init() < 0) + { + LM_ERR("faked_msg_init() failed\n"); + return NULL; + } + if (pv_get_spec_value(faked_msg_next(), pvs, &pvv) != 0) + { + LM_ERR("failed to get pv value for [%.*s]\n", in->len, in->s); + return NULL; + } + + queue = &pvv.rs; + } + + return queue; +} + /** * */ @@ -375,28 +409,24 @@ int pv_get_mqk(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { mq_pv_t *mp = NULL; - mp = mq_pv_get(¶m->pvn.u.isname.name.s); - if(mp==NULL || mp->item==NULL || mp->item->key.len<=0) - return pv_get_null(msg, param, res); - return pv_get_strval(msg, param, res, &mp->item->key); -} + str *in = pv_get_mq_name(¶m->pvn.u.isname.name.s);
-/** - * - */ -int pv_parse_mqv_name(pv_spec_t *sp, str *in) -{ - mq_head_t *mh = NULL; - mh = mq_head_get(in); - if(mh==NULL) + if (in == NULL) + { + LM_ERR("failed to get mq name\n"); + return -1; + } + + if (mq_head_get(in) == NULL) { LM_ERR("mqueue not found: %.*s\n", in->len, in->s); return -1; } - sp->pvp.pvn.u.isname.name.s = *in; - sp->pvp.pvn.type = PV_NAME_INTSTR; - sp->pvp.pvn.u.isname.type = 1; - return 0; + + mp = mq_pv_get(in); + if(mp==NULL || mp->item==NULL || mp->item->key.len<=0) + return pv_get_null(msg, param, res); + return pv_get_strval(msg, param, res, &mp->item->key); }
/** @@ -406,7 +436,21 @@ int pv_get_mqv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { mq_pv_t *mp = NULL; - mp = mq_pv_get(¶m->pvn.u.isname.name.s); + str *in = pv_get_mq_name(¶m->pvn.u.isname.name.s); + + if (in == NULL) + { + LM_ERR("failed to get mq name\n"); + return -1; + } + + if (mq_head_get(in) == NULL) + { + LM_ERR("mqueue not found: %.*s\n", in->len, in->s); + return -1; + } + + mp = mq_pv_get(in); if(mp==NULL || mp->item==NULL || mp->item->val.len<=0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &mp->item->val); diff --git a/modules/mqueue/mqueue_api.h b/modules/mqueue/mqueue_api.h index 11a94ad..04ad1e4 100644 --- a/modules/mqueue/mqueue_api.h +++ b/modules/mqueue/mqueue_api.h @@ -28,10 +28,9 @@ #include "../../pvar.h" #include "../../parser/msg_parser.h"
-int pv_parse_mqk_name(pv_spec_p sp, str *in); +int pv_parse_mq_name(pv_spec_p sp, str *in); int pv_get_mqk(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); -int pv_parse_mqv_name(pv_spec_p sp, str *in); int pv_get_mqv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
diff --git a/modules/mqueue/mqueue_mod.c b/modules/mqueue/mqueue_mod.c index a99a361..b4b9517 100644 --- a/modules/mqueue/mqueue_mod.c +++ b/modules/mqueue/mqueue_mod.c @@ -52,15 +52,15 @@ static int bind_mq(mq_api_t* api);
static pv_export_t mod_pvs[] = { { {"mqk", sizeof("mqk")-1}, PVT_OTHER, pv_get_mqk, 0, - pv_parse_mqk_name, 0, 0, 0 }, + pv_parse_mq_name, 0, 0, 0 }, { {"mqv", sizeof("mqv")-1}, PVT_OTHER, pv_get_mqv, 0, - pv_parse_mqv_name, 0, 0, 0 }, + pv_parse_mq_name, 0, 0, 0 }, { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } };
static cmd_export_t cmds[]={ - {"mq_fetch", (cmd_function)w_mq_fetch, 1, fixup_str_null, + {"mq_fetch", (cmd_function)w_mq_fetch, 1, fixup_spve_null, 0, ANY_ROUTE}, {"mq_add", (cmd_function)w_mq_add, 3, fixup_mq_add, 0, ANY_ROUTE}, @@ -114,8 +114,14 @@ static void mod_destroy(void) static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2) { int ret; + str q;
- ret = mq_head_fetch((str*)mq); + if(fixup_get_svalue(msg, (gparam_t*)mq, &q)<0) + { + LM_ERR("cannot get the queue\n"); + return -1; + } + ret = mq_head_fetch(&q); if(ret<0) return ret; return 1; @@ -123,8 +129,15 @@ static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val) { + str q; str qkey; str qval; + + if(fixup_get_svalue(msg, (gparam_t*)mq, &q)<0) + { + LM_ERR("cannot get the queue\n"); + return -1; + } if(fixup_get_svalue(msg, (gparam_t*)key, &qkey)<0) { LM_ERR("cannot get the key\n"); @@ -135,7 +148,7 @@ static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val) LM_ERR("cannot get the val\n"); return -1; } - if(mq_item_add((str*)mq, &qkey, &qval)<0) + if(mq_item_add(&q, &qkey, &qval)<0) return -1; return 1; } @@ -202,14 +215,12 @@ int mq_param(modparam_t type, void *val)
static int fixup_mq_add(void** param, int param_no) { - if(param_no==2 || param_no==3) { + if(param_no==1 || param_no==2 || param_no==3) { return fixup_spve_null(param, 1); } - if (param_no != 1) { - LM_ERR("invalid parameter number %d\n", param_no); - return E_UNSPEC; - } - return fixup_str_null(param, 1); + + LM_ERR("invalid parameter number %d\n", param_no); + return E_UNSPEC; }
static int bind_mq(mq_api_t* api)