core: build_req_buf_from_sip_req() has a new parameter
[sip-router] / receive.c
index 3494bf0..9f59933 100644 (file)
--- a/receive.c
+++ b/receive.c
@@ -76,6 +76,13 @@ str default_global_port={0,0};
 str default_via_address={0,0};
 str default_via_port={0,0};
 
+/**
+ * increment msg_no and return the new value
+ */
+unsigned int inc_msg_no(void)
+{
+       return ++msg_no;
+}
 
 
 /* WARNING: buf must be 0 terminated (buf[len]=0) or some things might 
@@ -85,7 +92,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 {
        struct sip_msg* msg;
        int ret;
-       struct run_act_ctx ra_ctx;
 #ifdef STATS
        int skipped = 1;
        struct timeval tvb, tve;        
@@ -123,12 +129,14 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 
        /* ... clear branches from previous message */
        clear_branches();
-       reset_static_buffer();
 
        if (msg->first_line.type==SIP_REQUEST){
                if (!IS_SIP(msg)){
-                       if (nonsip_msg_run_hooks(msg)!=NONSIP_MSG_ACCEPT);
+                       if ((ret=nonsip_msg_run_hooks(msg))!=NONSIP_MSG_ACCEPT){
+                               if (unlikely(ret==NONSIP_MSG_ERROR))
+                                       goto error03;
                                goto end; /* drop the message */
+                       }
                }
                /* sanity checks */
                if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
@@ -166,13 +174,12 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                   (like presence of at least one via), so you can count
                   on via1 being parsed in a pre-script callback --andrei
                */
-               if (exec_pre_req_cb(msg)==0 )
+               if (exec_pre_script_cb(msg, REQUEST_CB_TYPE)==0 )
                        goto end; /* drop the request */
 
                set_route_type(REQUEST_ROUTE);
                /* exec the routing script */
-               init_run_actions_ctx(&ra_ctx);
-               if (run_actions(&ra_ctx, main_rt.rlist[DEFAULT_RT], msg)<0){
+               if (run_top_route(main_rt.rlist[DEFAULT_RT], msg)<0){
                        LOG(L_WARN, "WARNING: receive_msg: "
                                        "error while trying script\n");
                        goto error_req;
@@ -188,7 +195,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 #endif
 
                /* execute post request-script callbacks */
-               exec_post_req_cb(msg);
+               exec_post_script_cb(msg, REQUEST_CB_TYPE);
        }else if (msg->first_line.type==SIP_REPLY){
                /* sanity checks */
                if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
@@ -209,14 +216,13 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
                   (like presence of at least one via), so you can count
                   on via1 being parsed in a pre-script callback --andrei
                */
-               if (exec_pre_rpl_cb(msg)==0 )
+               if (exec_pre_script_cb(msg, ONREPLY_CB_TYPE)==0 )
                        goto end; /* drop the request */
 
                /* exec the onreply routing script */
                if (onreply_rt.rlist[DEFAULT_RT]){
                        set_route_type(ONREPLY_ROUTE);
-                       init_run_actions_ctx(&ra_ctx);
-                       ret=run_actions(&ra_ctx, onreply_rt.rlist[DEFAULT_RT], msg);
+                       ret=run_top_route(onreply_rt.rlist[DEFAULT_RT], msg);
                        if (ret<0){
                                LOG(L_WARN, "WARNING: receive_msg: "
                                                "error while trying onreply script\n");
@@ -236,7 +242,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 #endif
 
                /* execute post reply-script callbacks */
-               exec_post_rpl_cb(msg);
+               exec_post_script_cb(msg, ONREPLY_CB_TYPE);
        }
 
 end:
@@ -254,13 +260,14 @@ end:
        return 0;
 error_rpl:
        /* execute post reply-script callbacks */
-       exec_post_rpl_cb(msg);
+       exec_post_script_cb(msg, ONREPLY_CB_TYPE);
        reset_avps();
        goto error02;
 error_req:
        DBG("receive_msg: error:...\n");
        /* execute post request-script callbacks */
-       exec_post_req_cb(msg);
+       exec_post_script_cb(msg, REQUEST_CB_TYPE);
+error03:
        /* free possible loaded avps -bogdan */
        reset_avps();
 error02: