[sr-dev] git:master:3bce7841: pv: new class of pseudo-variable - $msg(attr)
Daniel-Constantin Mierla
miconda at gmail.com
Wed Jun 29 18:07:52 CEST 2016
Module: kamailio
Branch: master
Commit: 3bce7841290b2ff2840c79d63e210973acfa71f9
URL: https://github.com/kamailio/kamailio/commit/3bce7841290b2ff2840c79d63e210973acfa71f9
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-06-29T18:06:36+02:00
pv: new class of pseudo-variable - $msg(attr)
- return attributes of sip message
* $msg(len) - sip message lenght
* $msg(buf) - sip message buffer
* $msg(body) - sip message body
* $msg(body_len) - sip message body lenght
* $msg(hdrs) - sip message headers
* $msg(fline) - sip message first line
---
Modified: modules/pv/pv.c
Modified: modules/pv/pv_core.c
Modified: modules/pv/pv_core.h
---
Diff: https://github.com/kamailio/kamailio/commit/3bce7841290b2ff2840c79d63e210973acfa71f9.diff
Patch: https://github.com/kamailio/kamailio/commit/3bce7841290b2ff2840c79d63e210973acfa71f9.patch
---
diff --git a/modules/pv/pv.c b/modules/pv/pv.c
index 1aa53ed..3e33596 100644
--- a/modules/pv/pv.c
+++ b/modules/pv/pv.c
@@ -470,6 +470,8 @@ static pv_export_t mod_pvs[] = {
pv_parse_K_name, 0, 0, 0 },
{ {"expires", (sizeof("expires")-1)}, PVT_OTHER, pv_get_expires, 0,
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 },
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};
diff --git a/modules/pv/pv_core.c b/modules/pv/pv_core.c
index 5836e23..6c1ec41 100644
--- a/modules/pv/pv_core.c
+++ b/modules/pv/pv_core.c
@@ -32,6 +32,7 @@
#include "../../lib/kcore/cmpapi.h"
#include "../../tcp_conn.h"
#include "../../pvapi.h"
+#include "../../trim.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_uri.h"
@@ -3112,3 +3113,104 @@ int pv_get_expires(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_null(msg, param, res);
}
}
+
+/**
+ *
+ */
+int pv_parse_msg_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, "len", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 0;
+ else if(strncmp(in->s, "buf", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 1;
+ else goto error;
+ break;
+ case 4:
+ if(strncmp(in->s, "body", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 2;
+ else if(strncmp(in->s, "hdrs", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 3;
+ else goto error;
+ case 5:
+ if(strncmp(in->s, "fline", 5)==0)
+ sp->pvp.pvn.u.isname.name.n = 4;
+ else goto error;
+ case 8:
+ if(strncmp(in->s, "body_len", 8)==0)
+ sp->pvp.pvn.u.isname.name.n = 5;
+ else goto error;
+ default:
+ goto error;
+ }
+ sp->pvp.pvn.type = PV_NAME_INTSTR;
+ sp->pvp.pvn.u.isname.type = 0;
+
+ return 0;
+
+error:
+ LM_ERR("unknown PV expires key: %.*s\n", in->len, in->s);
+ return -1;
+}
+
+/**
+ *
+ */
+int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ str s;
+ if(msg==NULL)
+ return pv_get_null(msg, param, res);
+
+ if(param==NULL)
+ return pv_get_null(msg, param, res);
+
+ if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
+ LM_ERR("failed to parse headers\n");
+ return pv_get_null(msg, param, res);
+ }
+
+ switch(param->pvn.u.isname.name.n)
+ {
+ case 0: /* length */
+ return pv_get_uintval(msg, param, res, msg->len);
+ case 1: /* buffer */
+ s.s = msg->buf;
+ s.len = msg->len;
+ return pv_get_strval(msg, param, res, &s);
+ case 2: /* body */
+ s.s = get_body(msg);
+ if(s.s == NULL) {
+ LM_DBG("no message body\n");
+ return pv_get_null(msg, param, res);
+ }
+ s.len = msg->buf + msg->len - s.s;
+ return pv_get_strval(msg, param, res, &s);
+ case 3: /* headers */
+ if(msg->unparsed==NULL)
+ return pv_get_null(msg, param, res);
+ s.s = msg->buf + msg->first_line.len;
+ s.len = msg->unparsed - s.s;
+ trim(&s);
+ return pv_get_strval(msg, param, res, &s);
+ case 4: /* first line */
+ s.s = msg->buf;
+ s.len = msg->first_line.len;
+ trim(&s);
+ return pv_get_strval(msg, param, res, &s);
+ case 5: /* body size */
+ s.s = get_body( msg );
+ s.len = 0;
+ if (s.s != NULL)
+ s.len = msg->buf + msg->len - s.s;
+ return pv_get_sintval(msg, param, res, s.len);
+
+ default:
+ return pv_get_null(msg, param, res);
+ }
+}
diff --git a/modules/pv/pv_core.h b/modules/pv/pv_core.h
index 6d6c1a5..c994e90 100644
--- a/modules/pv/pv_core.h
+++ b/modules/pv/pv_core.h
@@ -330,5 +330,9 @@ int pv_parse_expires_name(pv_spec_p sp, str *in);
int pv_get_expires(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res);
+int pv_parse_msg_attrs_name(pv_spec_p sp, str *in);
+
+int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res);
#endif
More information about the sr-dev
mailing list