Module: sip-router Branch: master Commit: d4ed4771938ac490a4df2b320236b7b0d462a636 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d4ed4771...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Wed Apr 18 19:54:41 2012 +0200
core: added timeval field inside sip_msg_t
- new parameter msg_time to set the timeval value at receive time (1 (on) by default, set to 0 to disable) - the value is set automatically at received time based if msg_time=1 or first time when it is accessed - the field should bring coherence regarting time of the message - it should be the same no matter where is processed
---
cfg.lex | 3 +++ cfg.y | 3 +++ globals.h | 1 + main.c | 3 +++ parser/msg_parser.c | 13 +++++++++++++ parser/msg_parser.h | 9 +++++++++ receive.c | 2 ++ 7 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/cfg.lex b/cfg.lex index 8769cfc..a626c8c 100644 --- a/cfg.lex +++ b/cfg.lex @@ -510,6 +510,8 @@ LATENCY_LOG latency_log LATENCY_LIMIT_DB latency_limit_db LATENCY_LIMIT_ACTION latency_limit_action
+MSG_TIME msg_time + CFG_DESCRIPTION "description"|"descr"|"desc"
LOADMODULE loadmodule @@ -976,6 +978,7 @@ IMPORTFILE "import_file" return HTTP_REPLY_HACK; } <INITIAL>{SERVER_ID} { count(); yylval.strval=yytext; return SERVER_ID;} <INITIAL>{LATENCY_LOG} { count(); yylval.strval=yytext; return LATENCY_LOG;} +<INITIAL>{MSG_TIME} { count(); yylval.strval=yytext; return MSG_TIME;} <INITIAL>{LATENCY_LIMIT_DB} { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;} <INITIAL>{LATENCY_LIMIT_ACTION} { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;} <INITIAL>{CFG_DESCRIPTION} { count(); yylval.strval=yytext; return CFG_DESCRIPTION; } diff --git a/cfg.y b/cfg.y index 1c62c10..cdd03fc 100644 --- a/cfg.y +++ b/cfg.y @@ -565,6 +565,7 @@ extern char *finame; %token LATENCY_LOG %token LATENCY_LIMIT_DB %token LATENCY_LIMIT_ACTION +%token MSG_TIME
%token FLAGS_DECL %token AVPFLAGS_DECL @@ -1701,6 +1702,8 @@ assign_stm: | LATENCY_LIMIT_DB EQUAL error { yyerror("number expected"); } | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; } | LATENCY_LIMIT_ACTION EQUAL error { yyerror("number expected"); } + | MSG_TIME EQUAL NUMBER { sr_msg_time=$3; } + | MSG_TIME EQUAL error { yyerror("number expected"); } | UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; } | UDP_MTU EQUAL error { yyerror("number expected"); } | FORCE_RPORT EQUAL NUMBER diff --git a/globals.h b/globals.h index 49b8345..6793aff 100644 --- a/globals.h +++ b/globals.h @@ -128,6 +128,7 @@ extern int sock_mode; extern char* chroot_dir; extern char* working_dir; extern int sr_auto_aliases; +extern int sr_msg_time;
#ifdef USE_MCAST extern int mcast_loopback; diff --git a/main.c b/main.c index 07be3c1..306e409 100644 --- a/main.c +++ b/main.c @@ -418,6 +418,9 @@ int sock_mode= S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* rw-rw---- */
int server_id = 0; /* Configurable unique ID of the server */
+/* set timeval for each received sip message */ +int sr_msg_time = 1; + /* more config stuff */ int disable_core_dump=0; /* by default enabled */ int open_files_limit=-1; /* don't touch it by default */ diff --git a/parser/msg_parser.c b/parser/msg_parser.c index 29495d9..929d69d 100644 --- a/parser/msg_parser.c +++ b/parser/msg_parser.c @@ -55,6 +55,7 @@
#include <string.h> #include <stdlib.h> +#include <sys/time.h>
#include "../comp_defs.h" #include "msg_parser.h" @@ -892,3 +893,15 @@ int msg_ctx_id_match(sip_msg_t *msg, msg_ctx_id_t *mid) return 0; return 1; } + +/** + * set msg time value + */ +int msg_set_time(sip_msg_t *msg) +{ + if(unlikely(msg==NULL)) + return -2; + if(msg->tval.tv_sec!=0) + return 0; + return gettimeofday(&msg->tval, NULL); +} diff --git a/parser/msg_parser.h b/parser/msg_parser.h index c633fed..6718b7a 100644 --- a/parser/msg_parser.h +++ b/parser/msg_parser.h @@ -251,10 +251,14 @@ typedef struct msg_body { } msg_body_t;
+/* pre-declaration, to include sys/time.h in .c */ +struct timeval; + /*! \brief The SIP message */ typedef struct sip_msg { unsigned int id; /*!< message id, unique/process*/ int pid; /*!< process id */ + struct timeval tval; /*!< time value associated to message */ snd_flags_t fwd_send_flags; /*!< send flags for forwarding */ snd_flags_t rpl_send_flags; /*!< send flags for replies */ struct msg_start first_line; /*!< Message first line */ @@ -483,4 +487,9 @@ int msg_ctx_id_set(sip_msg_t *msg, msg_ctx_id_t *mid); */ int msg_ctx_id_match(sip_msg_t *msg, msg_ctx_id_t *mid);
+/** + * set msg time value + */ +int msg_set_time(sip_msg_t *msg); + #endif diff --git a/receive.c b/receive.c index c701dd8..4426b6d 100644 --- a/receive.c +++ b/receive.c @@ -139,6 +139,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) msg->set_global_address=default_global_address; msg->set_global_port=default_global_port; + if(likely(sr_msg_time==1)) msg_set_time(msg); + if (parse_msg(buf,len, msg)!=0){ LOG(cfg_get(core, core_cfg, corelog), "ERROR: receive_msg: parse_msg failed\n");