Module: sip-router
Branch: master
Commit: dba9e85e137cc3818a01cccb2930e7580564ecd1
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dba9e85…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Fri Jul 17 17:10:07 2009 +0200
core: expr =~ fixup order fix
The fixup for built-in expressions were in the wrong order: first
RE and then RVE/RVALs, but a RVE/RVALs could be optimized away to
a string => because of the wrong order at runtime the match
operator might end up being used with a normal string instead of a
RE.
Now the order is RVE/RVALs fixup & optimisations, string fixups
(len) and then RE fixups (so that by the time the RE fixup is run
we know the final type of its operand).
Reported-by: Nils Ohlmeier nils at iptel org
---
route.c | 66 +++++++++++++++++++++++++++++++++-----------------------------
1 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/route.c b/route.c
index e22820d..effb608 100644
--- a/route.c
+++ b/route.c
@@ -525,6 +525,41 @@ int fix_expr(struct expr* exp)
exp->op);
}
}else if (exp->type==ELEM_T){
+ /* first fix & optimize rve/rvals (they might be optimized
+ to non-rvals, e.g. string, avp a.s.o) */
+ if (exp->l_type==RVEXP_O){
+ if ((ret=fix_rval_expr(&exp->l.param))<0){
+ ERR("Unable to fix left rval expression\n");
+ return ret;
+ }
+ if (scr_opt_lev>=2)
+ exp_optimize_left(exp);
+ }
+ if (exp->r_type==RVE_ST){
+ if ((ret=fix_rval_expr(&exp->r.param))<0){
+ ERR("Unable to fix right rval expression\n");
+ return ret;
+ }
+ if (scr_opt_lev>=2)
+ exp_optimize_right(exp);
+ }
+
+ /* Calculate lengths of strings */
+ if (exp->l_type==STRING_ST) {
+ int len;
+ if (exp->l.string) len = strlen(exp->l.string);
+ else len = 0;
+ exp->l.str.s = exp->l.string;
+ exp->l.str.len = len;
+ }
+ if (exp->r_type==STRING_ST) {
+ int len;
+ if (exp->r.string) len = strlen(exp->r.string);
+ else len = 0;
+ exp->r.str.s = exp->r.string;
+ exp->r.str.len = len;
+ }
+
if (exp->op==MATCH_OP){
/* right side either has to be string, in which case
* we turn it into regular expression, or it is regular
@@ -562,21 +597,6 @@ int fix_expr(struct expr* exp)
return ret;
}
}
- /* Calculate lengths of strings */
- if (exp->l_type==STRING_ST) {
- int len;
- if (exp->l.string) len = strlen(exp->l.string);
- else len = 0;
- exp->l.str.s = exp->l.string;
- exp->l.str.len = len;
- }
- if (exp->r_type==STRING_ST) {
- int len;
- if (exp->r.string) len = strlen(exp->r.string);
- else len = 0;
- exp->r.str.s = exp->r.string;
- exp->r.str.len = len;
- }
if (exp->l_type==SELECT_O) {
if ((ret=resolve_select(exp->l.select)) < 0) {
BUG("Unable to resolve select\n");
@@ -591,22 +611,6 @@ int fix_expr(struct expr* exp)
return ret;
}
}
- if (exp->l_type==RVEXP_O){
- if ((ret=fix_rval_expr(&exp->l.param))<0){
- ERR("Unable to fix left rval expression\n");
- return ret;
- }
- if (scr_opt_lev>=2)
- exp_optimize_left(exp);
- }
- if (exp->r_type==RVE_ST){
- if ((ret=fix_rval_expr(&exp->r.param))<0){
- ERR("Unable to fix right rval expression\n");
- return ret;
- }
- if (scr_opt_lev>=2)
- exp_optimize_right(exp);
- }
/* PVAR don't need fixing */
ret=0;
}
andrei 2009/07/17 15:37:11 CEST
SER CVS Repository
Modified files:
. cfg.lex cfg.y
Log:
core: config parser listen if names fix
If no quotes were used in listen=x, it was assumed that x was an
ip or a valid hostname (each domain part starts with a letter,
numbers and '_' are not allowed as first chars). However this
assumption failed when interface names were used, e.g. eth0.1 is a
valid interface name, but listen=eth0.1 resulted in error (it
worked only if quotes were used, e.g. listen="eth0.1").
Revision Changes Path
1.126 +30 -13 sip_router/cfg.lex
http://cvs.berlios.de/cgi-bin/viewcvs.cgi/ser/sip_router/cfg.lex.diff?r1=1.…
1.184 +36 -4 sip_router/cfg.y
http://cvs.berlios.de/cgi-bin/viewcvs.cgi/ser/sip_router/cfg.y.diff?r1=1.18…
andrei 2009/07/17 15:37:02 CEST
SER CVS Repository
Modified files:
. cfg.y
Log:
core: config parser listen fix
- do not crash when the listen=host line contains an invalid host (e.g. foo.1)
- more null checks
Reported-by: Cristian Constantin cristian.constantin at iptel org
Revision Changes Path
1.183 +45 -32 sip_router/cfg.y
http://cvs.berlios.de/cgi-bin/viewcvs.cgi/ser/sip_router/cfg.y.diff?r1=1.18…
Module: sip-router
Branch: master
Commit: dd5490500f006f86e520958c5ca2646a1e3a96b7
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dd54905…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Fri Jul 17 00:15:39 2009 +0200
domain: API framework to be used by other modules
Add a new data structure and function bind_domain that can be used by
other modules to gain access to internal functions of domain module.
Implement inline function load_domain_api that does everything that
is necessary to make the API of the domain module available to the
caller.
---
modules_s/domain/domain_api.c | 35 ++++++++++++++++++++++++++
modules_s/domain/domain_api.h | 54 +++++++++++++++++++++++++++++++++++++++++
modules_s/domain/domain_mod.c | 2 +
3 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/modules_s/domain/domain_api.c b/modules_s/domain/domain_api.c
new file mode 100644
index 0000000..c88e5c8
--- /dev/null
+++ b/modules_s/domain/domain_api.c
@@ -0,0 +1,35 @@
+/*
+ * Domain module internal API
+ *
+ * Copyright (C) 2002-2003 Juha Heinanen
+ *
+ * This file is part of sip-router, a free SIP server.
+ *
+ * sip-router 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
+ *
+ * sip-router 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
+ */
+
+#include "domain_api.h"
+#include "../../dprint.h"
+#include "domain.h"
+
+
+int bind_domain(domain_api_t* api)
+{
+ if (api == NULL) {
+ ERR("Invalid parameter value\n");
+ return -1;
+ }
+ return 0;
+}
diff --git a/modules_s/domain/domain_api.h b/modules_s/domain/domain_api.h
new file mode 100644
index 0000000..16ddd1f
--- /dev/null
+++ b/modules_s/domain/domain_api.h
@@ -0,0 +1,54 @@
+/*
+ * Domain module internal API
+ *
+ * Copyright (C) 2002-2003 Juha Heinanen
+ *
+ * This file is part of sip-router, a free SIP server.
+ *
+ * sip-router 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
+ *
+ * sip-router 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
+ */
+
+#ifndef _DOMAIN_API_H
+#define _DOMAIN_API_H
+
+#include "../../sr_module.h"
+#include "../../dprint.h"
+
+typedef struct domain_api {
+
+} domain_api_t;
+
+typedef int (*bind_domain_f)(domain_api_t* api);
+int bind_domain(domain_api_t* api);
+
+static inline int load_domain_api(domain_api_t* api)
+{
+ bind_domain_f bind_domain;
+
+ bind_domain = (bind_domain_f)find_export("bind_domain", 0, 0);
+
+ if (bind_domain == NULL) {
+ ERR("Cannot import bind_domain function from domain module\n");
+ return -1;
+ }
+
+ if (bind_domain(api) == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+
+#endif /* _DOMAIN_API_H */
diff --git a/modules_s/domain/domain_mod.c b/modules_s/domain/domain_mod.c
index 957973f..c7e0515 100644
--- a/modules_s/domain/domain_mod.c
+++ b/modules_s/domain/domain_mod.c
@@ -38,6 +38,7 @@
#include "../../parser/parse_from.h"
#include "../../parser/parse_uri.h"
#include "../../usr_avp.h"
+#include "domain_api.h"
#include "domain_rpc.h"
#include "hash.h"
#include "domain.h"
@@ -124,6 +125,7 @@ static cmd_export_t cmds[] = {
{"lookup_domain", lookup_domain, 2, lookup_domain_fixup,
REQUEST_ROUTE|FAILURE_ROUTE },
{"get_did", (cmd_function)get_did, 0, 0, 0},
+ {"bind_domain", (cmd_function)bind_domain, 0, 0, 0},
{0, 0, 0, 0, 0}
};
Module: sip-router
Branch: master
Commit: c4dbb39571c5e8d801956d8afc5134387de1a59a
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c4dbb39…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Fri Jul 17 11:34:24 2009 +0200
domain: Documentation of internal API
Add docbook documentation for the internal API of domain module.
---
modules_s/domain/doc/domain.xml | 1 +
modules_s/domain/doc/domain_api.xml | 47 +++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/modules_s/domain/doc/domain.xml b/modules_s/domain/doc/domain.xml
index 0e4879f..9c8aa57 100644
--- a/modules_s/domain/doc/domain.xml
+++ b/modules_s/domain/doc/domain.xml
@@ -241,5 +241,6 @@ iptel
<xi:include href="params.xml"/>
<xi:include href="functions.xml"/>
<xi:include href="fifo.xml"/>
+ <xi:include href="domain_api.xml"/>
</section>
diff --git a/modules_s/domain/doc/domain_api.xml b/modules_s/domain/doc/domain_api.xml
new file mode 100644
index 0000000..27c2c10
--- /dev/null
+++ b/modules_s/domain/doc/domain_api.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<section id="domain.api" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Internal API</title>
+ <para>The domain module has an internal API which can be used to access
+ additional functions of the module (i.e. functions that are normally not
+ available from the routing script). Currently the API exports only the
+ function <function>is_domain_local</function>. That function can be used
+ to determine whether a given domain name is on the list of locally
+ configured domain names.</para>
+
+ <para>If you want to use the internal API of domain module from your
+ module then you need to include the header file
+ <filename>domain_api.h</filename> and call
+ <function>load_domain_api</function> first.</para>
+
+ <example>
+ <title>Calling <function>load_domain_api</function></title>
+ <programlisting>
+#include "../domain/domain_api.h"
+
+domain_api_t dom_api;
+
+if (load_domain_api(&dom_api) != 0) {
+ /* error */
+}
+</programlisting>
+ </example>
+
+ <para>After that you can call function
+ <function>is_domain_local</function> whose pointer is stored in the
+ initialized data structure:</para>
+
+ <programlisting>
+str tmp = STR_STATIC_INIT("mydomain.com");
+
+if (dom_api.is_domain_local(&tmp) == 1) {
+ /* Domain is local */
+} else {
+ /* Domain is not local or an error was encountered */
+}
+ </programlisting>
+</section>
+
+
\ No newline at end of file
Module: sip-router
Branch: master
Commit: d8fdebf9c589516185d5c6a4ff9453148f1b76f2
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d8fdebf…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Fri Jul 17 11:10:51 2009 +0200
domain: Add internal function is_domain_local
Add internal function is_domain_local that can be used to determine if
the domain name given in parameter is on the list of local domains. The
comparison of the domain name is always case insensitive.
There already is is_local function that does something similar, so we
can reuse the code from that function. is_domain_local takes a pointer
to str as parameter and this function is then called by is_local which
takes all the usual parameters that function which can be called from
the script take.
Finally, is_domain_local is exported through the internal API of the
domain module.
Function is_domain_local is now located in file domain.c and because of
db_get_did was also moved to file domain.c
---
modules_s/domain/domain.c | 104 +++++++++++++++++++++++++++++++++++++++++
modules_s/domain/domain.h | 17 +++++++
modules_s/domain/domain_api.c | 1 +
modules_s/domain/domain_api.h | 3 +-
modules_s/domain/domain_mod.c | 91 +-----------------------------------
5 files changed, 126 insertions(+), 90 deletions(-)
diff --git a/modules_s/domain/domain.c b/modules_s/domain/domain.c
index cd347bf..cb5cb32 100644
--- a/modules_s/domain/domain.c
+++ b/modules_s/domain/domain.c
@@ -22,6 +22,7 @@
#include <string.h>
#include "domain_mod.h"
+#include "hash.h"
#include "../../dprint.h"
#include "../../mem/shm_mem.h"
#include "../../lib/srdb2/db.h"
@@ -308,3 +309,106 @@ int load_domains(domain_t** dest)
free_domain_list(list);
return 1;
}
+
+
+/* Retrieve did directly from database, without using memory cache. Use 0 as
+ * the value of first parameter if you only want to know whether the entry is
+ * in the database. The function returns 1 if there is such entry, 0 if not,
+ * and -1 on error. The result is allocated using pkg_malloc and must be
+ * freed.
+ */
+int db_get_did(str* did, str* domain)
+{
+ db_res_t* res = NULL;
+ db_rec_t* rec;
+
+ if (!domain) {
+ ERR("BUG:Invalid parameter value\n");
+ goto err;
+ }
+
+ get_did_cmd->match[0].v.lstr = *domain;
+
+ if (db_exec(&res, get_did_cmd) < 0) {
+ ERR("Error in database query\n");
+ goto err;
+ }
+
+ rec = db_first(res);
+ if (rec) {
+ /* Test flags first, we are only interested in rows
+ * that are not disabled
+ */
+ if (rec->fld[1].flags & DB_NULL || (rec->fld[1].v.bitmap &
+ SRDB_DISABLED)) {
+ db_res_free(res);
+ return 0;
+ }
+
+ if (did) {
+ if (rec->fld[0].flags & DB_NULL) {
+ did->len = 0;
+ did->s = 0;
+ WARN("Domain '%.*s' has NULL did\n",
+ domain->len, ZSW(domain->s));
+ } else {
+ did->s = pkg_malloc(rec->fld[0].v.lstr.len);
+ if (!did->s) {
+ ERR("No memory left\n");
+ goto err;
+ }
+ memcpy(did->s, rec->fld[0].v.lstr.s, rec->fld[0].v.lstr.len);
+ did->len = rec->fld[0].v.lstr.len;
+ }
+ }
+
+ db_res_free(res);
+ return 1;
+ } else {
+ db_res_free(res);
+ return 0;
+ }
+
+ err:
+ if (res) db_res_free(res);
+ return -1;
+}
+
+
+/* Check if the domain name given in the parameter is one
+ * of the locally configured domain names.
+ * Returns 1 if yes and -1 otherwise
+ */
+int is_domain_local(str* domain)
+{
+ str tmp;
+
+ /* Make a temporary copy, domain name comparisons are always
+ * case insensitive
+ */
+ tmp.s = pkg_malloc(domain->len);
+ if (!tmp.s) {
+ ERR("No memory left\n");
+ return -1;
+ }
+ memcpy(tmp.s, domain->s, domain->len);
+ tmp.len = domain->len;
+ strlower(&tmp);
+
+ if (!db_mode) {
+ switch(db_get_did(0, &tmp)) {
+ case 1: goto found;
+ default: goto not_found;
+ }
+ } else {
+ if (hash_lookup(0, *active_hash, &tmp) == 1) goto found;
+ else goto not_found;
+ }
+
+ found:
+ pkg_free(tmp.s);
+ return 1;
+ not_found:
+ pkg_free(tmp.s);
+ return -1;
+}
diff --git a/modules_s/domain/domain.h b/modules_s/domain/domain.h
index d79a593..e0d0d37 100644
--- a/modules_s/domain/domain.h
+++ b/modules_s/domain/domain.h
@@ -72,4 +72,21 @@ void free_domain_list(domain_t* list);
typedef int (*domain_get_did_t)(str* did, str* domain);
+
+/* Retrieve did directly from database, without using memory cache. Use 0 as
+ * the value of first parameter if you only want to know whether the entry is
+ * in the database. The function returns 1 if there is such entry, 0 if not,
+ * and -1 on error. The result is allocated using pkg_malloc and must be
+ * freed.
+ */
+int db_get_did(str* did, str* domain);
+
+/* Check if the domain name given in the parameter is one
+ * of the locally configured domain names.
+ * Returns 1 if yes and -1 otherwise
+ */
+typedef int (*is_domain_local_f)(str* domain);
+int is_domain_local(str* domain);
+
+
#endif /* _DOMAIN_H */
diff --git a/modules_s/domain/domain_api.c b/modules_s/domain/domain_api.c
index c88e5c8..0996c67 100644
--- a/modules_s/domain/domain_api.c
+++ b/modules_s/domain/domain_api.c
@@ -31,5 +31,6 @@ int bind_domain(domain_api_t* api)
ERR("Invalid parameter value\n");
return -1;
}
+ api->is_domain_local = is_domain_local;
return 0;
}
diff --git a/modules_s/domain/domain_api.h b/modules_s/domain/domain_api.h
index 16ddd1f..2882332 100644
--- a/modules_s/domain/domain_api.h
+++ b/modules_s/domain/domain_api.h
@@ -25,9 +25,10 @@
#include "../../sr_module.h"
#include "../../dprint.h"
+#include "domain.h"
typedef struct domain_api {
-
+ is_domain_local_f is_domain_local;
} domain_api_t;
typedef int (*bind_domain_f)(domain_api_t* api);
diff --git a/modules_s/domain/domain_mod.c b/modules_s/domain/domain_mod.c
index c7e0515..e5d5cb0 100644
--- a/modules_s/domain/domain_mod.c
+++ b/modules_s/domain/domain_mod.c
@@ -381,107 +381,20 @@ static void destroy(void)
}
-/* Retrieve did directly from database, without using memory cache. Use 0 as
- * the value of first parameter if you only want to know whether the entry is
- * in the database. The function returns 1 if there is such entry, 0 if not,
- * and -1 on error. The result is allocated using pkg_malloc and must be
- * freed.
- */
-static int db_get_did(str* did, str* domain)
-{
- db_res_t* res = NULL;
- db_rec_t* rec;
-
- if (!domain) {
- ERR("BUG:Invalid parameter value\n");
- goto err;
- }
-
- get_did_cmd->match[0].v.lstr = *domain;
-
- if (db_exec(&res, get_did_cmd) < 0) {
- ERR("Error in database query\n");
- goto err;
- }
-
- rec = db_first(res);
- if (rec) {
- /* Test flags first, we are only interested in rows
- * that are not disabled
- */
- if (rec->fld[1].flags & DB_NULL || (rec->fld[1].v.bitmap &
- SRDB_DISABLED)) {
- db_res_free(res);
- return 0;
- }
-
- if (did) {
- if (rec->fld[0].flags & DB_NULL) {
- did->len = 0;
- did->s = 0;
- WARN("Domain '%.*s' has NULL did\n",
- domain->len, ZSW(domain->s));
- } else {
- did->s = pkg_malloc(rec->fld[0].v.lstr.len);
- if (!did->s) {
- ERR("No memory left\n");
- goto err;
- }
- memcpy(did->s, rec->fld[0].v.lstr.s, rec->fld[0].v.lstr.len);
- did->len = rec->fld[0].v.lstr.len;
- }
- }
-
- db_res_free(res);
- return 1;
- } else {
- db_res_free(res);
- return 0;
- }
-
- err:
- if (res) db_res_free(res);
- return -1;
-}
-
/*
* Check if domain is local
*/
static int is_local(struct sip_msg* msg, char* fp, char* s2)
{
- str domain, tmp;
+ str domain;
if (get_str_fparam(&domain, msg, (fparam_t*)fp) != 0) {
ERR("Unable to get domain to check\n");
return -1;
}
- tmp.s = pkg_malloc(domain.len);
- if (!tmp.s) {
- ERR("No memory left\n");
- return -1;
- }
- memcpy(tmp.s, domain.s, domain.len);
- tmp.len = domain.len;
- strlower(&tmp);
-
- if (!db_mode) {
- switch(db_get_did(0, &tmp)) {
- case 1: goto found;
- default: goto not_found;
- }
- } else {
- if (hash_lookup(0, *active_hash, &tmp) == 1) goto found;
- else goto not_found;
- }
-
- found:
- pkg_free(tmp.s);
- return 1;
- not_found:
- pkg_free(tmp.s);
- return -1;
+ return is_domain_local(&domain);
}