Browse code

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 authored on 18/04/2012 17:54:41
Showing 7 changed files
... ...
@@ -510,6 +510,8 @@ LATENCY_LOG				latency_log
510 510
 LATENCY_LIMIT_DB		latency_limit_db
511 511
 LATENCY_LIMIT_ACTION	latency_limit_action
512 512
 
513
+MSG_TIME	msg_time
514
+
513 515
 CFG_DESCRIPTION		"description"|"descr"|"desc"
514 516
 
515 517
 LOADMODULE	loadmodule
... ...
@@ -976,6 +978,7 @@ IMPORTFILE      "import_file"
976 976
 									return HTTP_REPLY_HACK; }
977 977
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
978 978
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
979
+<INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
979 980
 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
980 981
 <INITIAL>{LATENCY_LIMIT_ACTION}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;}
981 982
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
... ...
@@ -565,6 +565,7 @@ extern char *finame;
565 565
 %token LATENCY_LOG
566 566
 %token LATENCY_LIMIT_DB
567 567
 %token LATENCY_LIMIT_ACTION
568
+%token MSG_TIME
568 569
 
569 570
 %token FLAGS_DECL
570 571
 %token AVPFLAGS_DECL
... ...
@@ -1701,6 +1702,8 @@ assign_stm:
1701 1701
 	| LATENCY_LIMIT_DB EQUAL error  { yyerror("number  expected"); }
1702 1702
     | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; }
1703 1703
 	| LATENCY_LIMIT_ACTION EQUAL error  { yyerror("number  expected"); }
1704
+    | MSG_TIME EQUAL NUMBER { sr_msg_time=$3; }
1705
+	| MSG_TIME EQUAL error  { yyerror("number  expected"); }
1704 1706
 	| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1705 1707
 	| UDP_MTU EQUAL error { yyerror("number expected"); }
1706 1708
 	| FORCE_RPORT EQUAL NUMBER 
... ...
@@ -128,6 +128,7 @@ extern int sock_mode;
128 128
 extern char* chroot_dir;
129 129
 extern char* working_dir;
130 130
 extern int sr_auto_aliases;
131
+extern int sr_msg_time;
131 132
 
132 133
 #ifdef USE_MCAST
133 134
 extern int mcast_loopback;
... ...
@@ -418,6 +418,9 @@ int sock_mode= S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* rw-rw---- */
418 418
 
419 419
 int server_id = 0; /* Configurable unique ID of the server */
420 420
 
421
+/* set timeval for each received sip message */
422
+int sr_msg_time = 1;
423
+
421 424
 /* more config stuff */
422 425
 int disable_core_dump=0; /* by default enabled */
423 426
 int open_files_limit=-1; /* don't touch it by default */
... ...
@@ -55,6 +55,7 @@
55 55
 
56 56
 #include <string.h>
57 57
 #include <stdlib.h>
58
+#include <sys/time.h>
58 59
 
59 60
 #include "../comp_defs.h"
60 61
 #include "msg_parser.h"
... ...
@@ -892,3 +893,15 @@ int msg_ctx_id_match(sip_msg_t *msg, msg_ctx_id_t *mid)
892 892
 		return 0;
893 893
 	return 1;
894 894
 }
895
+
896
+/**
897
+ * set msg time value
898
+ */
899
+int msg_set_time(sip_msg_t *msg)
900
+{
901
+	if(unlikely(msg==NULL))
902
+		return -2;
903
+	if(msg->tval.tv_sec!=0)
904
+		return 0;
905
+	return gettimeofday(&msg->tval, NULL);
906
+}
... ...
@@ -251,10 +251,14 @@ typedef struct msg_body {
251 251
 } msg_body_t;
252 252
 
253 253
 
254
+/* pre-declaration, to include sys/time.h in .c */
255
+struct timeval;
256
+
254 257
 /*! \brief The SIP message */
255 258
 typedef struct sip_msg {
256 259
 	unsigned int id;               /*!< message id, unique/process*/
257 260
 	int pid;                       /*!< process id */
261
+	struct timeval tval;           /*!< time value associated to message */
258 262
 	snd_flags_t fwd_send_flags;    /*!< send flags for forwarding */
259 263
 	snd_flags_t rpl_send_flags;    /*!< send flags for replies */
260 264
 	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);
483 483
  */
484 484
 int msg_ctx_id_match(sip_msg_t *msg, msg_ctx_id_t *mid);
485 485
 
486
+/**
487
+ * set msg time value
488
+ */
489
+int msg_set_time(sip_msg_t *msg);
490
+
486 491
 #endif
... ...
@@ -139,6 +139,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
139 139
 	msg->set_global_address=default_global_address;
140 140
 	msg->set_global_port=default_global_port;
141 141
 	
142
+	if(likely(sr_msg_time==1)) msg_set_time(msg);
143
+
142 144
 	if (parse_msg(buf,len, msg)!=0){
143 145
 		LOG(cfg_get(core, core_cfg, corelog),
144 146
 				"ERROR: receive_msg: parse_msg failed\n");