Browse Source

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
Daniel-Constantin Mierla 13 years ago
parent
commit
d4ed477193
7 changed files with 34 additions and 0 deletions
  1. 3 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 1 0
      globals.h
  4. 3 0
      main.c
  5. 13 0
      parser/msg_parser.c
  6. 9 0
      parser/msg_parser.h
  7. 2 0
      receive.c

+ 3 - 0
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; }

+ 3 - 0
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 

+ 1 - 0
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;

+ 3 - 0
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 */

+ 13 - 0
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);
+}

+ 9 - 0
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

+ 2 - 0
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");