Module: kamailio Branch: master Commit: 072c88653e280004f86b4c41cfc4d92f3b21af1d URL: https://github.com/kamailio/kamailio/commit/072c88653e280004f86b4c41cfc4d92f...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-01-12T14:09:54+01:00
core: earlier execution of SREV_NET_DATA_RECV event
- allow capturing the traffic before topoh decodes it
---
Modified: receive.c
---
Diff: https://github.com/kamailio/kamailio/commit/072c88653e280004f86b4c41cfc4d92f... Patch: https://github.com/kamailio/kamailio/commit/072c88653e280004f86b4c41cfc4d92f...
---
diff --git a/receive.c b/receive.c index a9e1fc3..1c65266 100644 --- a/receive.c +++ b/receive.c @@ -74,6 +74,39 @@ unsigned int inc_msg_no(void) return ++msg_no; }
+/** + * + */ +int sip_check_fline(char* buf, unsigned int len) +{ + char *p; + int m; + + m = 0; + for(p=buf; p<buf+len; p++) { + /* first check if is a reply - starts with SIP/2.0 */ + if(m==0) { + if(*p==' ' || *p=='\t' || *p=='\r' || *p=='\n') continue; + if(buf+len-p<10) return -1; + if(strncmp(p, "SIP/2.0 ", 8)==0) { + LM_DBG("first line indicates a SIP reply\n"); + return 0; + } + m=1; + } else { + /* check if a request - before end of first line is SIP/2.0 */ + if(*p!='\r' && *p!='\n') continue; + if(p-10>=buf) { + if(strncmp(p-8, " SIP/2.0", 8)==0) { + LM_DBG("first line indicates a SIP request\n"); + return 0; + } + } + return -1; + } + } + return -1; +}
/** Receive message * WARNING: buf must be 0 terminated (buf[len]=0) or some things might @@ -93,6 +126,16 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) str inb; sr_net_info_t netinfo;
+ if(sr_event_enabled(SREV_NET_DATA_RECV)) { + if(sip_check_fline(buf, len)==0) { + memset(&netinfo, 0, sizeof(sr_net_info_t)); + netinfo.data.s = buf; + netinfo.data.len = len; + netinfo.rcv = rcv_info; + sr_event_exec(SREV_NET_DATA_RECV, (void*)&netinfo); + } + } + inb.s = buf; inb.len = len; sr_event_exec(SREV_NET_DATA_IN, (void*)&inb); @@ -140,14 +183,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) /* ... clear branches from previous message */ clear_branches();
- if(sr_event_enabled(SREV_NET_DATA_RECV)) { - memset(&netinfo, 0, sizeof(sr_net_info_t)); - netinfo.data.s = msg->buf; - netinfo.data.len = msg->len; - netinfo.rcv = rcv_info; - sr_event_exec(SREV_NET_DATA_RECV, (void*)&netinfo); - } - if (msg->first_line.type==SIP_REQUEST){ ruri_mark_new(); /* ruri is usable for forking (not consumed yet) */ if (!IS_SIP(msg)){