[sr-dev] git:master: pv: new pv class $version(key)

Daniel-Constantin Mierla miconda at gmail.com
Thu Aug 16 20:26:04 CEST 2012


Module: sip-router
Branch: master
Commit: e159eb090c9355431aa1e69a9d1dc622eb94cd89
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e159eb090c9355431aa1e69a9d1dc622eb94cd89

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Aug 16 20:24:28 2012 +0200

pv: new pv class $version(key)

- return attributes of the software version
- key can be:
	- num - return version number
	- full - return all version string
	- hash - return git hash code and status

---

 modules_k/pv/pv.c       |    2 +
 modules_k/pv/pv_stats.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 modules_k/pv/pv_stats.h |    3 ++
 3 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index 6b7dccb..aff1ee1 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -407,6 +407,8 @@ static pv_export_t mod_pvs[] = {
 		0, pv_parse_timeval_name, 0, 0, 0},
 	{ {"nh", (sizeof("nh")-1)}, PVT_OTHER, pv_get_nh,
 		0, pv_parse_nh_name, 0, 0, 0},
+	{ {"version", (sizeof("version")-1)}, PVT_OTHER, pv_get_sr_version,
+		0, pv_parse_sr_version_name, 0, 0, 0},
 
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
diff --git a/modules_k/pv/pv_stats.c b/modules_k/pv/pv_stats.c
index c8a1f29..9ca4f5c 100644
--- a/modules_k/pv/pv_stats.c
+++ b/modules_k/pv/pv_stats.c
@@ -26,8 +26,12 @@
  */
 
 #include "../../lib/kcore/statistics.h"
+#include "../../ver.h"
 #include "pv_stats.h"
 
+/**
+ *
+ */
 int pv_parse_stat_name(pv_spec_p sp, str *in)
 {
 	if (in == NULL || in->s == NULL || sp == NULL)
@@ -39,6 +43,9 @@ int pv_parse_stat_name(pv_spec_p sp, str *in)
 }
 
 
+/**
+ *
+ */
 int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	stat_var *stat;
@@ -53,3 +60,57 @@ int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 			(unsigned int)get_stat_val(stat));
 }
 
+/**
+ *
+ */
+int pv_parse_sr_version_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, "num", 3)==0)
+				sp->pvp.pvn.u.isname.name.n = 0;
+			else goto error;
+		break;
+		case 4:
+			if(strncmp(in->s, "full", 4)==0)
+				sp->pvp.pvn.u.isname.name.n = 1;
+			else if(strncmp(in->s, "hash", 4)==0)
+				sp->pvp.pvn.u.isname.name.n = 2;
+			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 version name %.*s\n", in->len, in->s);
+	return -1;
+}
+
+/**
+ *
+ */
+int pv_get_sr_version(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+	if(param==NULL)
+		return -1;
+
+	switch(param->pvn.u.isname.name.n)
+	{
+		case 1:
+			return pv_get_strzval(msg, param, res, (char*)full_version);
+		case 2:
+			return pv_get_strzval(msg, param, res, (char*)ver_id);
+		default:
+			return pv_get_strzval(msg, param, res, (char*)ver_version);
+	}
+}
+
diff --git a/modules_k/pv/pv_stats.h b/modules_k/pv/pv_stats.h
index 7ddeae3..b0356ea 100644
--- a/modules_k/pv/pv_stats.h
+++ b/modules_k/pv/pv_stats.h
@@ -33,4 +33,7 @@
 int pv_parse_stat_name(pv_spec_p sp, str *in);
 int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
 
+int pv_parse_sr_version_name(pv_spec_p sp, str *in);
+int pv_get_sr_version(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+
 #endif




More information about the sr-dev mailing list