Browse code

core: execute event_route[core:receive-parse-error] block on error of initial sip message parsing

- note that the SIP message is broken in this case, but it gets access
to source and local socket addresses (ip, port, proto, af) as well as
the whole message buffer and its size

Daniel-Constantin Mierla authored on 22/08/2013 11:01:55
Showing 4 changed files
... ...
@@ -27,11 +27,46 @@
27 27
 
28 28
 #include "dprint.h"
29 29
 #include "mem/mem.h"
30
+#include "route.h"
30 31
 #include "events.h"
31 32
 
32 33
 static sr_event_cb_t _sr_events_list;
33 34
 static int _sr_events_inited = 0;
34 35
 
36
+typedef struct _sr_core_ert {
37
+	int init_parse_error;
38
+} sr_core_ert_t;
39
+
40
+static sr_core_ert_t _sr_core_ert_list;
41
+
42
+/**
43
+ *
44
+ */
45
+void sr_core_ert_init(void)
46
+{
47
+	memset(&_sr_core_ert_list, 0, sizeof(sr_core_ert_t));
48
+	/* 0 - is not a valid index in event_route blocks list */
49
+	_sr_core_ert_list.init_parse_error = route_get(&event_rt,
50
+											"core:receive-parse-error");
51
+	if(_sr_core_ert_list.init_parse_error>=0
52
+			&& event_rt.rlist[_sr_core_ert_list.init_parse_error]!=NULL) {
53
+		_sr_core_ert_list.init_parse_error = -1;
54
+	}
55
+}
56
+
57
+/**
58
+ *
59
+ */
60
+void sr_core_ert_run(sip_msg_t *msg, int e)
61
+{
62
+	switch(e) {
63
+		case SR_CORE_ERT_RECEIVE_PARSE_ERROR:
64
+			if(likely(_sr_core_ert_list.init_parse_error<=0))
65
+				return;
66
+		break;
67
+	}
68
+}
69
+
35 70
 /**
36 71
  *
37 72
  */
... ...
@@ -59,4 +59,12 @@ int sr_event_register_cb(int type, sr_event_cb_f f);
59 59
 int sr_event_exec(int type, void *data);
60 60
 int sr_event_enabled(int type);
61 61
 
62
+
63
+/* shortcut types for core event routes */
64
+/* initial parsing error in message receive function */
65
+#define SR_CORE_ERT_RECEIVE_PARSE_ERROR		1
66
+
67
+void sr_core_ert_init(void);
68
+void sr_core_ert_run(sip_msg_t *msg, int e);
69
+
62 70
 #endif
... ...
@@ -145,6 +145,7 @@
145 145
 #include "script_cb.h"
146 146
 #include "nonsip_hooks.h"
147 147
 #include "ut.h"
148
+#include "events.h"
148 149
 #include "signals.h"
149 150
 #ifdef USE_RAW_SOCKS
150 151
 #include "raw_sock.h"
... ...
@@ -2253,6 +2254,9 @@ try_again:
2253 2253
 	if (pv_reinit_buffer()<0)
2254 2254
 		goto error;
2255 2255
 
2256
+	/* init lookup for core event routes */
2257
+	sr_core_ert_init();
2258
+
2256 2259
 	if (dont_fork_cnt)
2257 2260
 		dont_fork = dont_fork_cnt;	/* override by command line */
2258 2261
 
... ...
@@ -146,6 +146,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
146 146
 				"core parsing of SIP message failed (%s:%d/%d)\n",
147 147
 				ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port,
148 148
 				(int)msg->rcv.proto);
149
+		sr_core_ert_run(msg, SR_CORE_ERT_RECEIVE_PARSE_ERROR);
149 150
 		goto error02;
150 151
 	}
151 152
 	DBG("After parse_msg...\n");