int exec_pre_rpl_cb( struct sip_msg *msg) { return exec_pre_cb( msg, pre_rpl_cb); }
/* WARNING: buf must be 0 terminated (buf[len]=0) or some things might * break (e.g.: modules/textops) */ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) { struct sip_msg* msg; int ret; #ifdef STATS int skipped = 1; struct timeval tvb, tve; struct timezone tz; unsigned int diff; #endif msg=pkg_malloc(sizeof(struct sip_msg)); if (msg==0) { LOG(L_ERR, "ERROR: receive_msg: no mem for sip_msg\n"); goto error00; } msg_no++; /* number of vias parsed -- good for diagnostic info in replies */ via_cnt=0; memset(msg,0, sizeof(struct sip_msg)); /* init everything to 0 */ /* fill in msg */ msg->buf=buf; msg->len=len; /* zero termination (termination of orig message bellow not that useful as most of the work is done with scrath-pad; -jiri */ /* buf[len]=0; */ /* WARNING: zero term removed! */ msg->rcv=*rcv_info; msg->id=msg_no; msg->set_global_address=default_global_address; msg->set_global_port=default_global_port; if (parse_msg(buf,len, msg)!=0) { LOG(L_ERR, "ERROR: receive_msg: parse_msg failed\n"); goto error02; } DBG("After parse_msg...\n"); /* ... clear branches from previous message */ clear_branches(); if (msg->first_line.type==SIP_REQUEST) { /* sanity checks */ 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"); goto error; } /* check if neccesarry to add receive?->moved to forward_req */ DBG("preparing to run routing scripts...\n"); #ifdef STATS gettimeofday( & tvb, &tz ); #endif /* execute pre-script callbacks, if any; -jiri */ /* if some of the callbacks said not to continue with script processing, don't do so if we are here basic sanity checks are already done (like presence of at least one via), so you can count on via1 being parsed in a pre-script callback --andrei */ ret=exec_pre_cb(msg); if (ret<=0) { if (ret<0) goto error; else goto end; /* drop the message -- no error -- andrei */ } /* exec the routing script */ if (run_actions(rlist[0], msg)<0) { LOG(L_WARN, "WARNING: receive_msg: " "error while trying script\n"); goto error; } #ifdef STATS gettimeofday( & tve, &tz ); diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec); stats->processed_requests++; stats->acc_req_time += diff; DBG("succesfully ran routing scripts...(%d usec)\n", diff); STATS_RX_REQUEST( msg->first_line.u.request.method_value ); #endif } else if (msg->first_line.type==SIP_REPLY) { /* sanity checks */ 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"); goto error; } #if 0 if ((msg->via2==0) || (msg->via2->error!=PARSE_OK)) { /* no second via => error? */ LOG(L_ERR, "ERROR: receive_msg: no 2nd via found in reply\n"); goto error; } /* check if via1 == us */ #endif #ifdef STATS gettimeofday( & tvb, &tz ); STATS_RX_RESPONSE ( msg->first_line.u.reply.statuscode / 100 ); #endif /* execute pre-script callbacks, if any; -jiri */ /* if some of the callbacks said not to continue with script processing, don't do so if we are here basic sanity checks are already done (like presence of at least one via), so you can count on via1 being parsed in a pre-script callback --andrei */ ret=exec_pre_cb(msg); if (ret<=0) { if (ret<0) goto error; else goto end; /* drop the message -- no error -- andrei */ } /* send the msg */ forward_reply(msg); #ifdef STATS gettimeofday( & tve, &tz ); diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec); stats->processed_responses++; stats->acc_res_time+=diff; DBG("succesfully ran reply processing...(%d usec)\n", diff); #endif } end: #ifdef STATS skipped = 0; #endif /* execute post-script callbacks, if any; -jiri */ exec_post_cb(msg); /* free possible loaded avps -bogdan */ reset_avps(); DBG("receive_msg: cleaning up\n"); free_sip_msg(msg); pkg_free(msg); #ifdef STATS if (skipped) STATS_RX_DROPS; #endif return 0; error: DBG("error:...\n"); /* execute post-script callbacks, if any; -jiri */ exec_post_cb(msg); /* free possible loaded avps -bogdan */ reset_avps(); error02: free_sip_msg(msg); pkg_free(msg); error00: STATS_RX_DROPS; return -1; }