Module: sip-router
Branch: tmp/core_events
Commit: 88b792e4932b33700f5240be3923c19394c8e4d0
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=88b792e4932b33700f5240be3923c19394c8e4d0

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Tue Aug  4 16:43:30 2009 +0200

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

---

 forward.h |   18 ++++++++++++++----
 receive.c |    6 ++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/forward.h b/forward.h
index 0a5750a..b486694 100644
--- a/forward.h
+++ b/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;
 }
 
diff --git a/receive.c b/receive.c
index 824e693..579a6c2 100644
--- a/receive.c
+++ b/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) {


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to