Makefile.defs: version set 3.4.0-dev2
[sip-router] / receive.c
index 60eefa7..a4018ff 100644 (file)
--- a/receive.c
+++ b/receive.c
  * 2006-11-29 nonsip_msg hooks called for non-sip msg (e.g HTTP) (andrei)
  */
 
+/*!
+ * \file
+ * \brief SIP-router core :: 
+ * \ingroup core
+ * Module: \ref core
+ */
+
 
 #include <string.h>
 #include <stdlib.h>
 #include "nonsip_hooks.h"
 #include "dset.h"
 #include "usr_avp.h"
+#ifdef WITH_XAVP
+#include "xavp.h"
+#endif
 #include "select_buf.h"
 
 #include "tcp_server.h" /* for tcpconn_add_alias */
 #include "tcp_options.h" /* for access to tcp_accept_aliases*/
 #include "cfg/cfg.h"
+#include "core_stats.h"
 
 #ifdef DEBUG_DMALLOC
 #include <mem/dmalloc.h>
@@ -124,11 +135,15 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
        /* buf[len]=0; */ /* WARNING: zero term removed! */
        msg->rcv=*rcv_info;
        msg->id=msg_no;
+       msg->pid=my_pid();
        msg->set_global_address=default_global_address;
        msg->set_global_port=default_global_port;
        
+       if(likely(sr_msg_time==1)) msg_set_time(msg);
+
        if (parse_msg(buf,len, msg)!=0){
-               LOG(L_ERR, "ERROR: receive_msg: parse_msg failed\n");
+               LOG(cfg_get(core, core_cfg, corelog),
+                               "ERROR: receive_msg: parse_msg failed\n");
                goto error02;
        }
        DBG("After parse_msg...\n");
@@ -138,6 +153,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
        clear_branches();
 
        if (msg->first_line.type==SIP_REQUEST){
+               ruri_mark_new(); /* ruri is usable for forking (not consumed yet) */
                if (!IS_SIP(msg)){
                        if ((ret=nonsip_msg_run_hooks(msg))!=NONSIP_MSG_ACCEPT){
                                if (unlikely(ret==NONSIP_MSG_ERROR))
@@ -149,7 +165,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
                        /* no via, send back error ? */
                        LOG(L_ERR, "ERROR: receive_msg: no via found in request\n");
-                       sr_event_exec(SREV_CORE_STATS, (void*)5);
+                       STATS_BAD_MSG();
                        goto error02;
                }
                /* check if necessary to add receive?->moved to forward_req */
@@ -169,7 +185,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                        }
                }
 #endif
-                       
+
        /*      skip: */
                DBG("preparing to run routing scripts...\n");
 #ifdef  STATS
@@ -184,7 +200,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                */
                if (exec_pre_script_cb(msg, REQUEST_CB_TYPE)==0 )
                {
-                       sr_event_exec(SREV_CORE_STATS, (void*)3);
+                       STATS_REQ_FWD_DROP();
                        goto end; /* drop the request */
                }
 
@@ -212,7 +228,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
                        /* no via, send back error ? */
                        LOG(L_ERR, "ERROR: receive_msg: no via found in reply\n");
-                       sr_event_exec(SREV_CORE_STATS, (void*)6);
+                       STATS_BAD_RPL();
                        goto error02;
                }
 
@@ -230,13 +246,13 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                */
                if (exec_pre_script_cb(msg, ONREPLY_CB_TYPE)==0 )
                {
-                       sr_event_exec(SREV_CORE_STATS, (void*)4);
-                       goto end; /* drop the request */
+                       STATS_RPL_FWD_DROP();
+                       goto end; /* drop the reply */
                }
 
                /* exec the onreply routing script */
                if (onreply_rt.rlist[DEFAULT_RT]){
-                       set_route_type(ONREPLY_ROUTE);
+                       set_route_type(CORE_ONREPLY_ROUTE);
                        ret=run_top_route(onreply_rt.rlist[DEFAULT_RT], msg, &ctx);
 #ifndef NO_ONREPLY_ROUTE_ERROR
                        if (unlikely(ret<0)){
@@ -246,7 +262,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                        }else
 #endif /* NO_ONREPLY_ROUTE_ERROR */
                        if (unlikely(ret==0 || (ctx.run_flags&DROP_R_F))){
-                               sr_event_exec(SREV_CORE_STATS, (void*)4);
+                               STATS_RPL_FWD_DROP();
                                goto skip_send_reply; /* drop the message, no error */
                        }
                }
@@ -271,6 +287,9 @@ end:
 #endif
        /* free possible loaded avps -bogdan */
        reset_avps();
+#ifdef WITH_XAVP
+       xavp_reset_list();
+#endif
        DBG("receive_msg: cleaning up\n");
        free_sip_msg(msg);
        pkg_free(msg);
@@ -283,6 +302,9 @@ error_rpl:
        /* execute post reply-script callbacks */
        exec_post_script_cb(msg, ONREPLY_CB_TYPE);
        reset_avps();
+#ifdef WITH_XAVP
+       xavp_reset_list();
+#endif
        goto error02;
 #endif /* NO_ONREPLY_ROUTE_ERROR */
 error_req:
@@ -292,6 +314,9 @@ error_req:
 error03:
        /* free possible loaded avps -bogdan */
        reset_avps();
+#ifdef WITH_XAVP
+       xavp_reset_list();
+#endif
 error02:
        free_sip_msg(msg);
        pkg_free(msg);