Module: sip-router
Branch: master
Commit: 47945782e1459935b1f327abb92fbc1a3ffcd86f
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4794578…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Wed May 6 14:47:14 2009 +0200
core: Consolidate append_str macro usage
The definition of append_str macro was scattered across the source tree,
there were multiple definition of the macro, some of them with different
parameters.
This patch brings the definition of append_str macro into ut.h header
file and removes all other definitions from core and modules.
We chose the version with three parameters where the pointer and the
length of the source string are passed separately to the macro. This is
more flexible than passing both of them within one parameter as str
structure.
All references to append_mem_block have been removed because the same
operation can now be achieved with append_str. In addition to that we
updated parameters passed to append_str where needed, converting one
str parameter to <pointer,len> pair of parameters.
Some modules had yet another version of append_str defined, there we
renamed the macro to some other name to make sure that the local
definition does not conflict with the definition on ut.h
---
lib/kcore/km_ut.h | 11 ----
modules/tm/t_fifo.c | 8 ++--
modules/tm/t_funcs.h | 16 ------
modules/tm/t_msgbuilder.c | 96 ++++++++++++++++++------------------
modules/tm/t_serial.c | 8 ++--
modules_s/acc_syslog/acc_syslog.c | 8 ++--
modules_s/sms/sms_funcs.c | 4 --
msg_translator.c | 6 --
ut.h | 12 +++++
9 files changed, 72 insertions(+), 97 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=479…
Module: sip-router
Branch: master
Commit: 00f54c06f2f6d4e4c8a5a004eb07367c93b82329
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=00f54c0…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Wed May 6 11:17:17 2009 +0200
Serial forking functions.
This patch adds two new functions to tm module, t_load_contacts and
t_next_contacts which can be used to implement serial forking.
There are also two new parameters, fr_inv_timer_next and contacts_avp.
Parameter fr_inv_timer_next is similar to fr_inv_timer, the value
of this parameter is used for subsequent branches during serial forking.
The value of contacts_avp is the identifier of the AVP which contains
the list of contacts to be used for serial forking.
The serial forking functions originate from Kamailio where they were
implemented by Juha Heinanen.
---
modules/tm/README | 636 +++++++++++++++++++++--------------------
modules/tm/config.c | 3 +
modules/tm/config.h | 5 +
modules/tm/doc/functions.xml | 79 ++++++
modules/tm/doc/params.xml | 51 ++++
modules/tm/doc/tm.xml | 9 +
modules/tm/t_fifo.c | 22 +--
modules/tm/t_funcs.c | 25 ++-
modules/tm/t_funcs.h | 24 ++-
modules/tm/t_msgbuilder.c | 14 +-
modules/tm/t_serial.c | 519 ++++++++++++++++++++++++++++++++++
modules/tm/t_serial.h | 35 +++
modules/tm/tm.c | 15 +-
13 files changed, 1090 insertions(+), 347 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=00f…
Module: sip-router
Branch: master
Commit: 14839e8ff8da792974058779dc0cf4daf4181ac5
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=14839e8…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Wed May 6 11:10:48 2009 +0200
Splitting fix_sock_str into socket2str and fix_sock_str
This patch splits fix_sock_str into two function, socket2str and
fix_sock_str. The function socket2str is exported and can be used
to print the socket into a pre-allocated memory buffer. Function
fix_sock_str allocates the memory buffer and calls socket2str
internally.
The primary consumer of this change is the serial forking code in
tm module.
This patch also defines a new macro called MAX_SOCKET_STR which
evaluates to the maximum size of textual representation of any
socket.
---
socket_info.c | 73 ++++++++++++++++++++++++++++++++++++++++----------------
socket_info.h | 7 +++++
2 files changed, 59 insertions(+), 21 deletions(-)
diff --git a/socket_info.c b/socket_info.c
index ac2c82f..93c453a 100644
--- a/socket_info.c
+++ b/socket_info.c
@@ -298,6 +298,50 @@ static char* get_proto_name(unsigned short proto)
}
}
+/** Convert socket to its textual representation.
+ *
+ * This function converts the transport protocol, the IP address and the port
+ * number in a comma delimited string of form proto:ip:port. The resulting
+ * string is NOT zero terminated
+ *
+ * @param s is a pointer to the destination memory buffer
+ * @param len is a pointer to an integer variable. Initially the variable
+ * should contain the size of the buffer in s. The value of the variable
+ * will be changed to the length of the resulting string on success and
+ * to the desired size of the destination buffer if it is too small
+ * @param si is a pointer to the socket_info structure to be printed
+ * @return -1 on error and 0 on success
+ */
+int socket2str(char* s, int* len, struct socket_info* si)
+{
+ str proto;
+ int l;
+
+ proto.s = get_proto_name(si->proto);
+ proto.len = strlen(proto.s);
+
+ l = proto.len + si->address_str.len + si->port_no_str.len + 2;
+
+ if (*len < l) {
+ ERR("socket2str: Destionation buffer too short\n");
+ *len = l;
+ return -1;
+ }
+
+ memcpy(s, proto.s, proto.len);
+ s += proto.len;
+ *s = ':'; s++;
+ memcpy(s, si->address_str.s, si->address_str.len);
+ s += si->address_str.len;
+ *s = ':'; s++;
+ memcpy(s, si->port_no_str.s, si->port_no_str.len);
+ s += si->port_no_str.len;
+
+ *len = l;
+ return 0;
+}
+
+
/* Fill si->sock_str with string representing the socket_info structure,
* format of the string is 'proto:address:port'. Returns 0 on success and
@@ -305,33 +349,20 @@ static char* get_proto_name(unsigned short proto)
*/
static int fix_sock_str(struct socket_info* si)
{
- char* p;
- str proto;
+ int len = MAX_SOCKET_STR;
if (si->sock_str.s) pkg_free(si->sock_str.s);
- proto.s = get_proto_name(si->proto);
- proto.len = strlen(proto.s);
-
- si->sock_str.len = proto.len + si->address_str.len +
- si->port_no_str.len + 2;
-
- si->sock_str.s = pkg_malloc(si->sock_str.len + 1);
+ si->sock_str.s = pkg_malloc(len + 1);
if (si->sock_str.s == NULL) {
- LOG(L_ERR, "fix_sock_str: No pkg memory left\n");
+ ERR("fix_sock_str: No memory left\n");
return -1;
}
- p = si->sock_str.s;
- memcpy(p, proto.s, proto.len);
- p += proto.len;
- *p = ':'; p++;
- memcpy(p, si->address_str.s, si->address_str.len);
- p += si->address_str.len;
- *p = ':'; p++;
- memcpy(p, si->port_no_str.s, si->port_no_str.len);
- p += si->port_no_str.len;
- *p = '\0';
-
+ if (socket2str(si->sock_str.s, &len, si) < 0) {
+ BUG("fix_sock_str: Error in socket2str\n");
+ return -1;
+ }
+ si->sock_str.s[len] = '\0';
return 0;
}
diff --git a/socket_info.h b/socket_info.h
index ebe051a..4179869 100644
--- a/socket_info.h
+++ b/socket_info.h
@@ -43,6 +43,13 @@
#include "dprint.h"
#include "globals.h"
+/* This macro evaluates to the maximum length of string buffer needed to print
+ * the text description of any socket, not counting the terminating zero added
+ * by socket2str */
+#define MAX_SOCKET_STR (sizeof("unknown") - 1 + IP_ADDR_MAX_STR_SIZE + \
+ INT2STR_MAX_LEN + 2)
+
+int socket2str(char* s, int* len, struct socket_info* si);
/* struct socket_info is defined in ip_addr.h */
Module: sip-router
Branch: master
Commit: e41bc0575e8a4c22dfd7fbd2b6ae923f3c634a85
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e41bc05…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue May 5 19:43:18 2009 +0200
core: type casts support in the script
Support for casts added: (int) and (str).
E.g.: (int)$v ; (str)$v+"test".
---
NEWS | 5 +++--
cfg.lex | 4 ++++
cfg.y | 5 +++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index ed1ab96..460d70c 100644
--- a/NEWS
+++ b/NEWS
@@ -6,13 +6,14 @@ $Id$
sip-router changes
core:
+ - type casts operators: (int), (str).
- new operators eq, ne for string compares and ieq, ine for interger
compares. The names are not yet final (use them at your own risk).
Future version might use ==/!= only for ints (ieq/ine) and eq/ne for
strings (under debate).
They are almost equivalent to == or !=, but they force the conversion
- of their operands (eq to string and ieq to int), allowing among other
- things better type checking on startup and more optimizations.
+ of their operands (eq to string and ieq to int), allowing among other
+ things better type checking on startup and more optimizations.
Non equiv. examples: 0 == "" (true) is not equivalent to 0 eq ""
(false: it evaluates to "0" eq ""). "a" ieq "b" (true: (int)"a" is 0
and (int)"b" is 0) is not equivalent to "a" == "b" (false).
diff --git a/cfg.lex b/cfg.lex
index b599d13..167fc95 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -252,6 +252,8 @@ STREQ eq
INTEQ ieq
STRDIFF ne
INTDIFF ine
+INTCAST \(int\)
+STRCAST \(str\)
/* Attribute specification */
ATTR_MARK "%"
@@ -783,6 +785,8 @@ EAT_ABLE [\ \t\b\r]
<INITIAL>{INTEQ} { count(); return INTEQ; }
<INITIAL>{STRDIFF} { count(); return STRDIFF; }
<INITIAL>{INTDIFF} { count(); return INTDIFF; }
+<INITIAL>{INTCAST} { count(); return INTCAST; }
+<INITIAL>{STRCAST} { count(); return STRCAST; }
<INITIAL>{SELECT_MARK} { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
<SELECT>{ID} { count(); addstr(&s_buf, yytext, yyleng);
diff --git a/cfg.y b/cfg.y
index 5897914..8480434 100644
--- a/cfg.y
+++ b/cfg.y
@@ -494,6 +494,7 @@ static int case_check_default(struct case_stms* stms);
%left STAR SLASH
%right NOT
%right DEFINED
+%right INTCAST STRCAST
%left DOT
/* no precedence, they use () */
@@ -2269,6 +2270,8 @@ rval_expr: rval { $$=$1;
*/
}
| rve_un_op %prec NOT rval_expr {$$=mk_rve1($1, $2); }
+ | INTCAST rval_expr {$$=mk_rve1(RVE_INT_OP, $2); }
+ | STRCAST rval_expr {$$=mk_rve1(RVE_STR_OP, $2); }
| rval_expr PLUS rval_expr {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
| rval_expr MINUS rval_expr {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
| rval_expr STAR rval_expr {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
@@ -2285,6 +2288,8 @@ rval_expr: rval { $$=$1;
| STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
| DEFINED rval_expr { $$=mk_rve1(RVE_DEFINED_OP, $2);}
| rve_un_op %prec NOT error { $$=0; yyerror("bad expression"); }
+ | INTCAST error { $$=0; yyerror("bad expression"); }
+ | STRCAST error { $$=0; yyerror("bad expression"); }
| rval_expr PLUS error { yyerror("bad expression"); }
| rval_expr MINUS error { yyerror("bad expression"); }
| rval_expr STAR error { yyerror("bad expression"); }
Module: sip-router
Branch: master
Commit: 9c3327d5742b1f8280b159c7ea228b95bb2e8f35
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9c3327d…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue May 5 16:15:01 2009 +0200
core expr: optimizations fixes for $v op 0|1 -> $v
- fix missing cast for the $v <op> c -> $v optimizations
(e.g. $v - 0 -> $v, 1 * $v -> $v): instead of replacing
$v <op> c with $v use (type_of(<op>)) $v. $v without the cast
to the type produced by the operator is used now only when
type_of($v)==type_of(<op>).
E.g.: 1 * $v -> (int)$v
1 * ($v/$w) -> $v/$w ($v/$w produces always an int, so no
need for the cast)
Bug example: 1*"2"+3 was optimized to "2"+3 == "23" instead of
(int)"2"+3 == 5.
- better debugging messages
---
rvalue.c | 370 +++++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 257 insertions(+), 113 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=9c3…