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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Thu Aug 20 16:12:35 2009 +0300

pv: new pv class $sel(name)

- access select (ser cfg variables) values via PV framework
- read-only PV
- examples: $sel(@ruri), $sel(@via[2].host)

---

 modules_k/pv/pv.c        |    4 +++
 modules_k/pv/pv_select.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 modules_k/pv/pv_select.h |   36 ++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index f990a55..b284bbd 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -35,6 +35,7 @@
 #include "pv_shv.h"
 #include "pv_time.h"
 #include "pv_trans.h"
+#include "pv_select.h"
 
 
 MODULE_VERSION
@@ -64,6 +65,9 @@ static pv_export_t mod_pvs[] = {
        { {"stat", sizeof("stat")-1}, /* statistics */
                PVT_OTHER, pv_get_stat, 0,
                pv_parse_stat_name, 0, 0, 0 },
+       { {"sel", sizeof("sel")-1}, /* select */
+               PVT_OTHER, pv_get_select, 0,
+               pv_parse_select_name, 0, 0, 0 },
 
        {{"avp", (sizeof("avp")-1)}, PVT_AVP, pv_get_avp, pv_set_avp,
                pv_parse_avp_name, pv_parse_index, 0, 0},
diff --git a/modules_k/pv/pv_select.c b/modules_k/pv/pv_select.c
new file mode 100644
index 0000000..8634052
--- /dev/null
+++ b/modules_k/pv/pv_select.c
@@ -0,0 +1,67 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file
+ * \brief Implementation for Select Pseudo-variables
+ */
+
+#include "../../select.h"
+#include "pv_select.h"
+
+int pv_parse_select_name(pv_spec_p sp, str *in)
+{
+       select_t *sel = 0;
+       char c;
+       char *p;
+       if (in == NULL || in->s == NULL || sp == NULL)
+               return -1;
+
+       c = in->s[in->len];
+       in->s[in->len] = '\0';
+       p = in->s;
+       if(parse_select(&p, &sel)<0)
+       {
+               LM_ERR("invalid select name [%.*s]\n",
+                               in->len, in->s);
+               in->s[in->len] = c;
+               return -1;
+       }
+       in->s[in->len] = c;
+       sp->pvp.pvn.u.dname = (void*)sel;
+       sp->pvp.pvn.type = PV_NAME_OTHER;
+       return 0;
+}
+
+
+int pv_get_select(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+       str s = {0, 0};
+       select_t *sel = 0;
+
+       sel = (select_t*)param->pvn.u.dname;
+
+       if(sel==0 || run_select(&s, sel, msg)<0 || s.s==0)
+               return pv_get_null(msg, param, res);
+       return pv_get_strval(msg, param, res, &s);
+}
+
diff --git a/modules_k/pv/pv_select.h b/modules_k/pv/pv_select.h
new file mode 100644
index 0000000..84c872f
--- /dev/null
+++ b/modules_k/pv/pv_select.h
@@ -0,0 +1,36 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file
+ * \brief Headers for Stats Pseudo-variables
+ */
+
+#ifndef _PV_SELECT_H_
+#define _PV_SELECT_H_
+
+#include "../../pvar.h"
+
+int pv_parse_select_name(pv_spec_p sp, str *in);
+int pv_get_select(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+
+#endif


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to