Browse code

core: execute callbacks for NET_DATA_IN and NET_DATA_OUT

- NET_DATA_IN is executed when a sip message is received. The callback
may replace the content of incoming buffer, assuming BUF_SIZE for its
size
- NET_DATA_OUT is executed when a sip message is sent. The callback may
replace the output buffer content with a new pkg location

Daniel-Constantin Mierla authored on 04/08/2009 14:43:30
Showing 2 changed files
... ...
@@ -60,6 +60,7 @@
60 60
 #endif
61 61
 
62 62
 #include "compiler_opt.h"
63
+#include "events.h"
63 64
 
64 65
 
65 66
 enum ss_mismatch {
... ...
@@ -114,9 +115,14 @@ int forward_reply( struct sip_msg* msg);
114 114
  *         that generated them; use 0 if you don't want this)
115 115
  * buf, len = buffer
116 116
  * returns: 0 if ok, -1 on error*/
117
+
117 118
 static inline int msg_send(struct dest_info* dst, char* buf, int len)
118 119
 {
119 120
 	struct dest_info new_dst;
121
+	str outb;
122
+	outb.s = buf;
123
+	outb.len = len;
124
+	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
120 125
 	
121 126
 	if (likely(dst->proto==PROTO_UDP)){
122 127
 		if (unlikely((dst->send_sock==0) || 
... ...
@@ -129,7 +135,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
129 129
 			}
130 130
 			dst=&new_dst;
131 131
 		}
132
-		if (unlikely(udp_send(dst, buf, len)==-1)){
132
+		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
133 133
 			STATS_TX_DROPS;
134 134
 			LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
135 135
 			goto error;
... ...
@@ -143,7 +149,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
143 143
 					" support is disabled\n");
144 144
 			goto error;
145 145
 		}else{
146
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
146
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
147 147
 				STATS_TX_DROPS;
148 148
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
149 149
 				goto error;
... ...
@@ -158,7 +164,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
158 158
 					" support is disabled\n");
159 159
 			goto error;
160 160
 		}else{
161
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
161
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
162 162
 				STATS_TX_DROPS;
163 163
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
164 164
 				goto error;
... ...
@@ -184,7 +190,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
184 184
 				}
185 185
 				dst=&new_dst;
186 186
 			}
187
-			if (unlikely(sctp_msg_send(dst, buf, len)<0)){
187
+			if (unlikely(sctp_msg_send(dst, outb.s, outb.len)<0)){
188 188
 				STATS_TX_DROPS;
189 189
 				LOG(L_ERR, "msg_send: ERROR: sctp_msg_send failed\n");
190 190
 				goto error;
... ...
@@ -196,8 +202,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
196 196
 			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
197 197
 			goto error;
198 198
 	}
199
+	if(outb.s != buf)
200
+		pkg_free(outb.s);
199 201
 	return 0;
200 202
 error:
203
+	if(outb.s != buf)
204
+		pkg_free(outb.s);
201 205
 	return -1;
202 206
 }
203 207
 
... ...
@@ -98,6 +98,12 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
98 98
 	struct timezone tz;
99 99
 	unsigned int diff;
100 100
 #endif
101
+	str inb;
102
+
103
+	inb.s = buf;
104
+	inb.len = len;
105
+	sr_event_exec(SREV_NET_DATA_IN, (void*)&inb);
106
+	len = inb.len;
101 107
 
102 108
 	msg=pkg_malloc(sizeof(struct sip_msg));
103 109
 	if (msg==0) {