[sr-dev] git:master:2b53f673: pv: new function xavp_params_explode(p, x)
Alex Balashov
abalashov at evaristesys.com
Sun Apr 19 21:40:32 CEST 2015
Daniel,
Is there any interest in a more general split-by-delimiter function that can return an array of AVPs or XAVPs, along the lines of Perl's split() or PHP's explode()?
--
Alex Balashov | Principal | Evariste Systems LLC
303 Perimeter Center North, Suite 300
Atlanta, GA 30346
United States
Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct)
Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
Sent from my BlackBerry.
Original Message
From: Daniel-Constantin Mierla
Sent: Sunday, April 19, 2015 15:37
To: sr-dev at lists.sip-router.org
Reply To: Kamailio (SER) - Development Mailing List
Subject: [sr-dev] git:master:2b53f673: pv: new function xavp_params_explode(p, x)
Module: kamailio
Branch: master
Commit: 2b53f673b5888cf8b88b858d8b9a1da57313217b
URL: https://github.com/kamailio/kamailio/commit/2b53f673b5888cf8b88b858d8b9a1da57313217b
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-04-19T00:09:37+02:00
pv: new function xavp_params_explode(p, x)
- convert a string formatted as SIP params in xavp attributes
- e.g., xavp_params_explode("a=b;c=d;e=d", "x") results in:
$xavp(x=>a) = "b";
$xavp(x=>c) = "d";
$xavp(x=>e) = "f";
---
Modified: modules/pv/pv.c
Modified: modules/pv/pv_xavp.c
Modified: modules/pv/pv_xavp.h
---
Diff: https://github.com/kamailio/kamailio/commit/2b53f673b5888cf8b88b858d8b9a1da57313217b.diff
Patch: https://github.com/kamailio/kamailio/commit/2b53f673b5888cf8b88b858d8b9a1da57313217b.patch
---
diff --git a/modules/pv/pv.c b/modules/pv/pv.c
index 2f99a53..d969adc 100644
--- a/modules/pv/pv.c
+++ b/modules/pv/pv.c
@@ -475,6 +475,7 @@ static int pv_unset(struct sip_msg* msg, char* pvid, char *foo);
static int is_int(struct sip_msg* msg, char* pvar, char* s2);
static int pv_typeof(sip_msg_t *msg, char *pv, char *t);
static int pv_not_empty(sip_msg_t *msg, char *pv, char *s2);
+static int w_xavp_params_explode(sip_msg_t *msg, char *pparams, char *pxname);
static int pv_init_rpc(void);
static cmd_export_t cmds[]={
@@ -494,6 +495,9 @@ static cmd_export_t cmds[]={
{"not_empty", (cmd_function)pv_not_empty, 1, fixup_pvar_null,
fixup_free_pvar_null,
ANY_ROUTE},
+ {"xavp_params_explode", (cmd_function)w_xavp_params_explode,
+ 2, fixup_spve_spve, fixup_free_spve_spve,
+ ANY_ROUTE},
{0,0,0,0,0,0}
};
@@ -663,6 +667,29 @@ static int is_int(struct sip_msg* msg, char* pvar, char* s2)
return -1;
}
+/**
+ *
+ */
+static int w_xavp_params_explode(sip_msg_t *msg, char *pparams, char *pxname)
+{
+ str sparams;
+ str sxname;
+
+ if(fixup_get_svalue(msg, (gparam_t*)pparams, &sparams)!=0) {
+ LM_ERR("cannot get the params\n");
+ return -1;
+ }
+ if(fixup_get_svalue(msg, (gparam_t*)pxname, &sxname)!=0) {
+ LM_ERR("cannot get the xavp name\n");
+ return -1;
+ }
+
+ if(xavp_params_explode(&sparams, &sxname)<0)
+ return -1;
+
+ return 1;
+}
+
static const char* rpc_shv_set_doc[2] = {
"Set a shared variable (args: name type value)",
0
diff --git a/modules/pv/pv_xavp.c b/modules/pv/pv_xavp.c
index 1cf65c0..53fd99a 100644
--- a/modules/pv/pv_xavp.c
+++ b/modules/pv/pv_xavp.c
@@ -21,6 +21,7 @@
#include "../../dprint.h"
#include "../../xavp.h"
#include "../../pvapi.h"
+#include "../../parser/parse_param.h"
#include "pv_xavp.h"
@@ -555,4 +556,61 @@ int pv_xavp_print(struct sip_msg* msg, char* s1, char *s2)
return 1;
}
+/**
+ *
+ */
+int xavp_params_explode(str *params, str *xname)
+{
+ param_t* params_list = NULL;
+ param_hooks_t phooks;
+ param_t *pit=NULL;
+ str s;
+ sr_xavp_t *xavp=NULL;
+ sr_xval_t xval;
+
+ if(params==NULL || xname==NULL || params->s==NULL || xname->s==NULL
+ || params->len<=0 || xname->len<=0)
+ {
+ LM_ERR("invalid parameters\n");
+ return -1;
+ }
+
+ s.s = params->s;
+ s.len = params->len;
+ if(s.s[s.len-1]==';')
+ s.len--;
+ if (parse_params(&s, CLASS_ANY, &phooks, ¶ms_list)<0) {
+ LM_DBG("invalid formatted values [%.*s]\n", params->len, params->s);
+ return -1;
+ }
+
+ if(params_list==NULL) {
+ return -1;
+ }
+
+
+ for (pit = params_list; pit; pit=pit->next)
+ {
+ memset(&xval, 0, sizeof(sr_xval_t));
+ xval.type = SR_XTYPE_STR;
+ xval.v.s = pit->body;
+ if(xavp_add_value(&pit->name, &xval, &xavp)==NULL) {
+ free_params(params_list);
+ xavp_destroy_list(&xavp);
+ return -1;
+ }
+ }
+ free_params(params_list);
+
+ /* add main xavp in root list */
+ memset(&xval, 0, sizeof(sr_xval_t));
+ xval.type = SR_XTYPE_XAVP;
+ xval.v.xavp = xavp;
+ if(xavp_add_value(xname, &xval, NULL)==NULL) {
+ xavp_destroy_list(&xavp);
+ return -1;
+ }
+
+ return 0;
+}
#endif
diff --git a/modules/pv/pv_xavp.h b/modules/pv/pv_xavp.h
index a8020e7..3c8238e 100644
--- a/modules/pv/pv_xavp.h
+++ b/modules/pv/pv_xavp.h
@@ -29,5 +29,7 @@ int pv_parse_xavp_name(pv_spec_p sp, str *in);
int pv_xavp_print(struct sip_msg* msg, char* s1, char *s2);
+int xavp_params_explode(str *params, str *xname);
+
#endif
#endif
_______________________________________________
sr-dev mailing list
sr-dev at lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
More information about the sr-dev
mailing list