Browse code

core: two more events for handling http and msrp

- one to be called for http/1.1 end of headers for checking on '100
Continue' request
- one to be called when a msrp message is received

Daniel-Constantin Mierla authored on 13/01/2012 11:46:20
Showing 4 changed files
... ...
@@ -86,6 +86,16 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
86 86
 					_sr_events_list.net_dgram_in = f;
87 87
 				else return -1;
88 88
 			break;
89
+		case SREV_TCP_HTTP_100C:
90
+				if(_sr_events_list.tcp_http_100c==0)
91
+					_sr_events_list.tcp_http_100c = f;
92
+				else return -1;
93
+			break;
94
+		case SREV_TCP_MSRP_FRAME:
95
+				if(_sr_events_list.tcp_msrp_frame==0)
96
+					_sr_events_list.tcp_msrp_frame = f;
97
+				else return -1;
98
+			break;
89 99
 		default:
90 100
 			return -1;
91 101
 	}
... ...
@@ -165,6 +175,18 @@ int sr_event_exec(int type, void *data)
165 165
 					ret = _sr_events_list.net_dgram_in(data);
166 166
 					return ret;
167 167
 				} else return 1;
168
+		case SREV_TCP_HTTP_100C:
169
+				if(unlikely(_sr_events_list.tcp_http_100c!=0))
170
+				{
171
+					ret = _sr_events_list.tcp_http_100c(data);
172
+					return ret;
173
+				} else return 1;
174
+		case SREV_TCP_MSRP_FRAME:
175
+				if(unlikely(_sr_events_list.tcp_msrp_frame!=0))
176
+				{
177
+					ret = _sr_events_list.tcp_msrp_frame(data);
178
+					return ret;
179
+				} else return 1;
168 180
 		default:
169 181
 			return -1;
170 182
 	}
... ...
@@ -190,6 +212,10 @@ int sr_event_enabled(int type)
190 190
 				return (_sr_events_list.pkg_set_real_used!=0)?1:0;
191 191
 		case SREV_NET_DGRAM_IN:
192 192
 				return (_sr_events_list.net_dgram_in!=0)?1:0;
193
+		case SREV_TCP_HTTP_100C:
194
+				return (_sr_events_list.tcp_http_100c!=0)?1:0;
195
+		case SREV_TCP_MSRP_FRAME:
196
+				return (_sr_events_list.tcp_msrp_frame!=0)?1:0;
193 197
 	}
194 198
 	return 0;
195 199
 }
... ...
@@ -30,6 +30,9 @@
30 30
 #define SREV_PKG_SET_USED		5
31 31
 #define SREV_PKG_SET_REAL_USED	6
32 32
 #define SREV_NET_DGRAM_IN		7
33
+#define SREV_TCP_HTTP_100C		8
34
+#define SREV_TCP_MSRP_FRAME		9
35
+
33 36
 
34 37
 typedef int (*sr_event_cb_f)(void *data);
35 38
 
... ...
@@ -41,6 +44,8 @@ typedef struct sr_event_cb {
41 41
 	sr_event_cb_f pkg_set_used;
42 42
 	sr_event_cb_f pkg_set_real_used;
43 43
 	sr_event_cb_f net_dgram_in;
44
+	sr_event_cb_f tcp_http_100c;
45
+	sr_event_cb_f tcp_msrp_frame;
44 46
 } sr_event_cb_t;
45 47
 
46 48
 void sr_event_cb_init(void);
... ...
@@ -342,6 +342,14 @@ struct tcp_connection* tcpconn_get(int id, struct ip_addr* ip, int port,
342 342
 									union sockaddr_union* local_addr,
343 343
 									ticks_t timeout);
344 344
 
345
+typedef struct tcp_event_info {
346
+	int type;
347
+	char *buf;
348
+	unsigned int len;
349
+	struct receive_info *rcv;
350
+	struct tcp_connection *con;
351
+} tcp_event_info_t;
352
+
345 353
 #endif
346 354
 
347 355
 
... ...
@@ -96,6 +96,7 @@
96 96
 #include <fcntl.h> /* must be included after io_wait.h if SIGIO_RT is used */
97 97
 #include "tsend.h"
98 98
 #include "forward.h"
99
+#include "events.h"
99 100
 
100 101
 #ifdef USE_STUN
101 102
 #include "ser_stun.h"
... ...
@@ -994,8 +995,23 @@ skip:
994 994
 int msrp_process_msg(char* tcpbuf, unsigned int len,
995 995
 		struct receive_info* rcv_info, struct tcp_connection* con)
996 996
 {
997
+	int ret;
998
+	tcp_event_info_t tev;
999
+
1000
+	ret = 0;
997 1001
 	LM_DBG("MSRP Message: [[>>>\n%.*s<<<]]\n", len, tcpbuf);
998
-	return 0;
1002
+	if(likely(sr_event_enabled(SREV_TCP_MSRP_FRAME))) {
1003
+		memset(&tev, 0, sizeof(tcp_event_info_t));
1004
+		tev.type = SREV_TCP_MSRP_FRAME;
1005
+		tev.buf = tcpbuf;
1006
+		tev.len = len;
1007
+		tev.rcv = rcv_info;
1008
+		tev.con = con;
1009
+		ret = sr_event_exec(SREV_TCP_MSRP_FRAME, (void*)(&tev));
1010
+	} else {
1011
+		LM_DBG("no callback registering for handling MSRP - dropping!\n");
1012
+	}
1013
+	return ret;
999 1014
 }
1000 1015
 #endif
1001 1016