Module: sip-router
Branch: master
Commit: 8cf72b2de1ca86cafe7203433ff411e837d26dfa
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8cf72b2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Apr 28 19:23:23 2009 +0200
kex: added km_append_branch
- K compatible append_branch() function
---
modules_k/kex/kex_mod.c | 5 +++
modules_k/kex/km_core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++
modules_k/kex/km_core.h | 30 +++++++++++++++++++++
3 files changed, 102 insertions(+), 0 deletions(-)
diff --git a/modules_k/kex/kex_mod.c b/modules_k/kex/kex_mod.c
index e4960c0..9baa48d 100644
--- a/modules_k/kex/kex_mod.c
+++ b/modules_k/kex/kex_mod.c
@@ -31,6 +31,7 @@
#include "../../mod_fix.h"
#include "flags.h"
+#include "km_core.h"
#include "mi_core.h"
#include "core_stats.h"
@@ -63,6 +64,10 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE },
{"isbflagset", (cmd_function)w_isbflagset, 2,fixup_igp_igp,
0, ANY_ROUTE },
+ {"km_append_branch", (cmd_function)w_km_append_branch, 0, 0,
+ 0, REQUEST_ROUTE | FAILURE_ROUTE },
+ {"km_append_branch", (cmd_function)w_km_append_branch, 1, fixup_spve_null,
+ 0, REQUEST_ROUTE | FAILURE_ROUTE },
{0,0,0,0,0,0}
};
diff --git a/modules_k/kex/km_core.c b/modules_k/kex/km_core.c
new file mode 100644
index 0000000..beebb35
--- /dev/null
+++ b/modules_k/kex/km_core.c
@@ -0,0 +1,67 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2009
+ *
+ * This file is part of SIP-Router.org, 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
+ *
+ * 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
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../../dprint.h"
+#include "../../dset.h"
+#include "../../flags.h"
+#include "../../mod_fix.h"
+#include "km_core.h"
+
+int w_km_append_branch(struct sip_msg *msg, char *uri, str *sq)
+{
+ str suri;
+ int ret;
+ int q = Q_UNSPECIFIED;
+ flag_t branch_flags = 0;
+
+ getbflagsval(0, &branch_flags);
+ if (uri==NULL) {
+ ret = km_append_branch(msg, 0, &msg->dst_uri, &msg->path_vec,
+ q, branch_flags, msg->force_send_socket);
+ /* reset all branch info */
+ msg->force_send_socket = 0;
+ setbflagsval(0, 0);
+ if(msg->dst_uri.s!=0)
+ pkg_free(msg->dst_uri.s);
+ msg->dst_uri.s = 0;
+ msg->dst_uri.len = 0;
+ if(msg->path_vec.s!=0)
+ pkg_free(msg->path_vec.s);
+ msg->path_vec.s = 0;
+ msg->path_vec.len = 0;
+ } else {
+ if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
+ {
+ LM_ERR("cannot get the URI parameter\n");
+ return -1;
+ }
+ ret = km_append_branch(msg, &suri, &msg->dst_uri,
+ &msg->path_vec, q, branch_flags,
+ msg->force_send_socket);
+ }
+ return ret;
+}
+
diff --git a/modules_k/kex/km_core.h b/modules_k/kex/km_core.h
new file mode 100644
index 0000000..a668c71
--- /dev/null
+++ b/modules_k/kex/km_core.h
@@ -0,0 +1,30 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2009
+ *
+ * This file is part of SIP-Router.org, 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
+ *
+ * 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
+ */
+
+#ifndef _KEX_CORE_H_
+#define _KEX_CORE_H_
+
+#include "../../sr_module.h"
+
+int w_km_append_branch(struct sip_msg *msg, char *uri, str *s2);
+
+#endif
Module: sip-router
Branch: master
Commit: d02a166db83db71b587cd1252db0b4d4954e8c93
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d02a166…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Apr 28 19:21:04 2009 +0200
core: renamed getbflsgs to getblagsval
- match the template of counterpart setblagsval
- swapped the parameters
---
dset.c | 2 +-
dset.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/dset.c b/dset.c
index cbc636b..9409557 100644
--- a/dset.c
+++ b/dset.c
@@ -126,7 +126,7 @@ int resetbflag(unsigned int branch, flag_t flag)
}
-int getbflags(flag_t* res, unsigned int branch)
+int getbflagsval(unsigned int branch, flag_t* res)
{
flag_t* flags;
if (res == NULL) return -1;
diff --git a/dset.h b/dset.h
index e350238..adba10e 100644
--- a/dset.h
+++ b/dset.h
@@ -126,11 +126,11 @@ int isbflagset(unsigned int branch, flag_t flag);
*
* This function returns the value of all branch flags
* combined in a single variable.
- * @param res A pointer to a variable to store the result
* @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param res A pointer to a variable to store the result
* @return 1 on success, -1 on failure
*/
-int getbflags(flag_t* res, unsigned int branch);
+int getbflagsval(unsigned int branch, flag_t* res);
/**
* Set the value of all branch flags at once for a given branch.
Module: sip-router
Branch: andrei/type_conversion
Commit: 3c8fc182ae386713f15e6a0362924e72b257c31e
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=3c8fc18…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue Apr 28 18:34:03 2009 +0200
core expr eval: fix assoc., commut and 0 adding for +, ==
- fix associativity for the generic plus: because of the non-fixed
argument types (can work with strings integers or both in the
same type), RVE_PLUS_OP is associative _only_ if the operand
types match.
Non-assoc. example: "a" + 1 + "2" (can be "a12" or "a3").
Instead of adding extra checks for the same type, rely on the
optimizer having already replaced RVE_PLUS_OP with RVE_IPLUS_OP
or RVE_CONCAT_OP => RVE_PLUS_OP will be used only when the
operands types are mixed or cannot be determined (e.g. AVP), or
when script optimizations are turned off (-O0).
- fix commutativity for the generic plus. Similar to the above.
Non-commut. example: 1 + "2" == 3, but "2" + 1 == "21".
- fix commutativity for the generic == and !=.
Non. commut. example: 0 == "" , but "" != 0.
Similar fix as above, relying on the optimizer and the type specific
operators: RVE_IEQ_OP, RVE_IDIFF_OP, RVE_STREQ_OP and
RVE_STRDIFF_OP.
- fix $v + 0 / 0 + $v -> $v optimizations. Because of the generic
plus and recent changes that allow int + str, even if the result
is an int (left side operant is integer), 0 + $v can be
different from $v. E.g.: 0+"1" == 1, which is different from
"1".
---
rvalue.c | 37 +++++++++++++++++++++++++++----------
1 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/rvalue.c b/rvalue.c
index 7e82503..9a74cda 100644
--- a/rvalue.c
+++ b/rvalue.c
@@ -2281,6 +2281,9 @@ static int rve_op_is_assoc(enum rval_expr_op op)
case RVE_MINUS_OP:
return 0;
case RVE_PLUS_OP:
+ /* the generic plus is not assoc, e.g.
+ "a" + 1 + "2" => "a12" in one case and "a3" in the other */
+ return 0;
case RVE_IPLUS_OP:
case RVE_CONCAT_OP:
case RVE_MUL_OP:
@@ -2308,7 +2311,7 @@ static int rve_op_is_assoc(enum rval_expr_op op)
/** returns true if the operator is commutative. */
-static int rve_op_is_commutative(enum rval_expr_op op, enum rval_type type)
+static int rve_op_is_commutative(enum rval_expr_op op)
{
switch(op){
case RVE_NONE_OP:
@@ -2325,7 +2328,10 @@ static int rve_op_is_commutative(enum rval_expr_op op, enum rval_type type)
case RVE_MINUS_OP:
return 0;
case RVE_PLUS_OP:
- return type==RV_INT; /* commutative only for INT*/
+ /* non commut. when diff. type
+ (e.g 1 + "2" != "2" + 1 ) => non commut. in general
+ (specific same type versions are covered by IPLUS & CONCAT) */
+ return 0;
case RVE_IPLUS_OP:
case RVE_MUL_OP:
case RVE_BAND_OP:
@@ -2345,11 +2351,11 @@ static int rve_op_is_commutative(enum rval_expr_op op, enum rval_type type)
return 0;
case RVE_DIFF_OP:
case RVE_EQ_OP:
-#if !defined(UNDEF_EQ_ALWAYS_FALSE) && !defined(UNDEF_EQ_UNDEF_TRUE)
- return 1;
-#else
+ /* non. commut. in general, only for same type e.g.:
+ "" == 0 diff. 0 == "" ( "" == "0" and 0 == 0)
+ same type versions are covered by IEQ, IDIFF, STREQ, STRDIFF
+ */
return 0 /* asymmetrical undef handling */;
-#endif
}
return 0;
}
@@ -2658,8 +2664,19 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
case RVE_PLUS_OP:
case RVE_IPLUS_OP:
/* we must make sure that this is an int PLUS
- (because "foo"+0 is valid => "foo0") */
- if ((i==0) && ((op==RVE_IPLUS_OP)||(rve_type==RV_INT))){
+ (because "foo"+0 is valid => "foo0")
+ Even if overall type is RV_INT, it's still not safe
+ to optimize a generic PLUS: 0 + $v is not always equivalent
+ to $v (e.g. 0+"1" ==1 != "1") => optimize only if
+ IPLUS (always safe since it converts to int first) or
+ if generic PLUS and result is integer (rve_type) and
+ expression is of the form $v+ct (and not ct+$v).
+ TODO: dropping PLUS_OP all together and relying on the
+ optimizer replacing safe PLUS_OP with IPLUS_OP or CONCAT_OP
+ will simplify things.
+ */
+ if ((i==0) && ((op==RVE_IPLUS_OP)||
+ (rve_type==RV_INT && ct_rve==rve->right.rve))){
/* $v + 0 -> $v
* 0 + $v -> $v */
rve_destroy(ct_rve);
@@ -2908,7 +2925,7 @@ static int rve_optimize(struct rval_expr* rve)
trv->v.s.len, trv->v.s.s, rve->op);
ret=1;
}else if (rve_is_constant(rve->left.rve->left.rve) &&
- rve_op_is_commutative(rve->op, type)){
+ rve_op_is_commutative(rve->op)){
/* op(op(a, $v), b) => op(op(a, b), $v) */
/* rv= op(a, b) */
tmp_rve.op=rve->op;
@@ -2950,7 +2967,7 @@ static int rve_optimize(struct rval_expr* rve)
if ((rve->op==rve->right.rve->op) && rve_op_is_assoc(rve->op)){
/* op(a, op(...)) */
if (rve_is_constant(rve->right.rve->right.rve) &&
- rve_op_is_commutative(rve->op, type)){
+ rve_op_is_commutative(rve->op)){
/* op(a, op($v, b)) => op(op(a, b), $v) */
/* rv= op(a, b) */
tmp_rve.op=rve->op;