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 115
  *         that generated them; use 0 if you don't want this)
115 116
  * buf, len = buffer
116 117
  * returns: 0 if ok, -1 on error*/
118
+
117 119
 static inline int msg_send(struct dest_info* dst, char* buf, int len)
118 120
 {
119 121
 	struct dest_info new_dst;
122
+	str outb;
123
+	outb.s = buf;
124
+	outb.len = len;
125
+	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
120 126
 	
121 127
 	if (likely(dst->proto==PROTO_UDP)){
122 128
 		if (unlikely((dst->send_sock==0) || 
... ...
@@ -129,7 +135,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
129 135
 			}
130 136
 			dst=&new_dst;
131 137
 		}
132
-		if (unlikely(udp_send(dst, buf, len)==-1)){
138
+		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
133 139
 			STATS_TX_DROPS;
134 140
 			LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
135 141
 			goto error;
... ...
@@ -143,7 +149,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
143 149
 					" support is disabled\n");
144 150
 			goto error;
145 151
 		}else{
146
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
152
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
147 153
 				STATS_TX_DROPS;
148 154
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
149 155
 				goto error;
... ...
@@ -158,7 +164,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
158 164
 					" support is disabled\n");
159 165
 			goto error;
160 166
 		}else{
161
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
167
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
162 168
 				STATS_TX_DROPS;
163 169
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
164 170
 				goto error;
... ...
@@ -184,7 +190,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
184 190
 				}
185 191
 				dst=&new_dst;
186 192
 			}
187
-			if (unlikely(sctp_msg_send(dst, buf, len)<0)){
193
+			if (unlikely(sctp_msg_send(dst, outb.s, outb.len)<0)){
188 194
 				STATS_TX_DROPS;
189 195
 				LOG(L_ERR, "msg_send: ERROR: sctp_msg_send failed\n");
190 196
 				goto error;
... ...
@@ -196,8 +202,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
196 202
 			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
197 203
 			goto error;
198 204
 	}
205
+	if(outb.s != buf)
206
+		pkg_free(outb.s);
199 207
 	return 0;
200 208
 error:
209
+	if(outb.s != buf)
210
+		pkg_free(outb.s);
201 211
 	return -1;
202 212
 }
203 213
 
... ...
@@ -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) {