Browse Source

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 16 years ago
parent
commit
88b792e493
2 changed files with 20 additions and 4 deletions
  1. 14 4
      forward.h
  2. 6 0
      receive.c

+ 14 - 4
forward.h

@@ -60,6 +60,7 @@
 #endif
 
 #include "compiler_opt.h"
+#include "events.h"
 
 
 enum ss_mismatch {
@@ -114,9 +115,14 @@ int forward_reply( struct sip_msg* msg);
  *         that generated them; use 0 if you don't want this)
  * buf, len = buffer
  * returns: 0 if ok, -1 on error*/
+
 static inline int msg_send(struct dest_info* dst, char* buf, int len)
 {
 	struct dest_info new_dst;
+	str outb;
+	outb.s = buf;
+	outb.len = len;
+	sr_event_exec(SREV_NET_DATA_OUT, (void*)&outb);
 	
 	if (likely(dst->proto==PROTO_UDP)){
 		if (unlikely((dst->send_sock==0) || 
@@ -129,7 +135,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 			}
 			dst=&new_dst;
 		}
-		if (unlikely(udp_send(dst, buf, len)==-1)){
+		if (unlikely(udp_send(dst, outb.s, outb.len)==-1)){
 			STATS_TX_DROPS;
 			LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
 			goto error;
@@ -143,7 +149,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 					" support is disabled\n");
 			goto error;
 		}else{
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
 				STATS_TX_DROPS;
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
 				goto error;
@@ -158,7 +164,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 					" support is disabled\n");
 			goto error;
 		}else{
-			if (unlikely(tcp_send(dst, 0, buf, len)<0)){
+			if (unlikely(tcp_send(dst, 0, outb.s, outb.len)<0)){
 				STATS_TX_DROPS;
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
 				goto error;
@@ -184,7 +190,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 				}
 				dst=&new_dst;
 			}
-			if (unlikely(sctp_msg_send(dst, buf, len)<0)){
+			if (unlikely(sctp_msg_send(dst, outb.s, outb.len)<0)){
 				STATS_TX_DROPS;
 				LOG(L_ERR, "msg_send: ERROR: sctp_msg_send failed\n");
 				goto error;
@@ -196,8 +202,12 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
 			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
 			goto error;
 	}
+	if(outb.s != buf)
+		pkg_free(outb.s);
 	return 0;
 error:
+	if(outb.s != buf)
+		pkg_free(outb.s);
 	return -1;
 }
 

+ 6 - 0
receive.c

@@ -98,6 +98,12 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 	struct timezone tz;
 	unsigned int diff;
 #endif
+	str inb;
+
+	inb.s = buf;
+	inb.len = len;
+	sr_event_exec(SREV_NET_DATA_IN, (void*)&inb);
+	len = inb.len;
 
 	msg=pkg_malloc(sizeof(struct sip_msg));
 	if (msg==0) {