Module: kamailio
Branch: master
Commit: 4c52bd84068ca48a09bc971f32fdf028a889ee96
URL:
https://github.com/kamailio/kamailio/commit/4c52bd84068ca48a09bc971f32fdf02…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-07-06T16:01:18+02:00
pv: new class of variables - $ksr(attr)
- get attributes of kamailio sip router instance
- implemented attributes:
* ver - return version string
* verval - return version value
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_core.c
Modified: src/modules/pv/pv_core.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4c52bd84068ca48a09bc971f32fdf02…
Patch:
https://github.com/kamailio/kamailio/commit/4c52bd84068ca48a09bc971f32fdf02…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 096b253b30..ee455ca219 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -511,6 +511,8 @@ static pv_export_t mod_pvs[] = {
pv_parse_expires_name, 0, 0, 0 },
{ {"msg", (sizeof("msg")-1)}, PVT_OTHER, pv_get_msg_attrs, 0,
pv_parse_msg_attrs_name, 0, 0, 0 },
+ { {"ksr", (sizeof("ksr")-1)}, PVT_OTHER, pv_get_ksr_attrs, 0,
+ pv_parse_ksr_attrs_name, 0, 0, 0 },
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 8d8f35f250..8957098895 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -3522,6 +3522,58 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t
*res)
}
}
+/**
+ *
+ */
+int pv_parse_ksr_attrs_name(pv_spec_p sp, str *in)
+{
+ if(sp==NULL || in==NULL || in->len<=0)
+ return -1;
+
+ switch(in->len) {
+ case 3:
+ if(strncmp(in->s, "ver", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 0;
+ else goto error;
+ break;
+ case 6:
+ if(strncmp(in->s, "verval", 6)==0)
+ sp->pvp.pvn.u.isname.name.n = 1;
+ else goto error;
+ break;
+ default:
+ goto error;
+ }
+ sp->pvp.pvn.type = PV_NAME_INTSTR;
+ sp->pvp.pvn.u.isname.type = 0;
+
+ return 0;
+
+error:
+ LM_ERR("unknown PV ksr key: %.*s\n", in->len, in->s);
+ return -1;
+}
+
+
+/**
+ *
+ */
+int pv_get_ksr_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ if(param==NULL)
+ return pv_get_null(msg, param, res);
+
+ switch(param->pvn.u.isname.name.n) {
+ case 0: /* version */
+ return pv_get_strzval(msg, param, res, VERSION);
+ case 1: /* version value */
+ return pv_get_uintval(msg, param, res, VERSIONVAL);
+
+ default:
+ return pv_get_null(msg, param, res);
+ }
+}
+
int pv_parse_env_name(pv_spec_p sp, str *in)
{
char *csname;
diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h
index 453c1c3197..411f2f8aac 100644
--- a/src/modules/pv/pv_core.h
+++ b/src/modules/pv/pv_core.h
@@ -373,5 +373,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param,
int pv_parse_env_name(pv_spec_p sp, str *in);
int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+
+int pv_parse_ksr_attrs_name(pv_spec_p sp, str *in);
+
+int pv_get_ksr_attrs(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res);
+
#endif