00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <string.h>
00046 #include <stdlib.h>
00047 #include <sys/time.h>
00048
00049 #include "receive.h"
00050 #include "globals.h"
00051 #include "dprint.h"
00052 #include "route.h"
00053 #include "parser/msg_parser.h"
00054 #include "forward.h"
00055 #include "action.h"
00056 #include "mem/mem.h"
00057 #include "ip_addr.h"
00058 #include "script_cb.h"
00059 #include "dset.h"
00060 #include "usr_avp.h"
00061 #include "core_stats.h"
00062
00063
00064 #include "tcp_server.h"
00065
00066
00067 #ifdef DEBUG_DMALLOC
00068 #include <mem/dmalloc.h>
00069 #endif
00070
00071 static unsigned int msg_no=0;
00072
00073 str default_global_address={0,0};
00074 str default_global_port={0,0};
00075 str default_via_address={0,0};
00076 str default_via_port={0,0};
00077
00078 unsigned int get_next_msg_no(void)
00079 {
00080 return ++msg_no;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
00097 {
00098 struct sip_msg* msg;
00099
00100 msg=pkg_malloc(sizeof(struct sip_msg));
00101 if (msg==0) {
00102 LM_ERR("no pkg mem left for sip_msg\n");
00103 goto error00;
00104 }
00105 msg_no++;
00106
00107 via_cnt=0;
00108
00109 memset(msg,0, sizeof(struct sip_msg));
00110
00111 msg->buf=buf;
00112 msg->len=len;
00113
00114
00115
00116 msg->rcv=*rcv_info;
00117 msg->id=msg_no;
00118 msg->set_global_address=default_global_address;
00119 msg->set_global_port=default_global_port;
00120
00121 if (parse_msg(buf,len, msg)!=0){
00122 LM_ERR("parse_msg failed\n");
00123 goto error02;
00124 }
00125 LM_DBG("After parse_msg...\n");
00126
00127
00128
00129 clear_branches();
00130
00131 if (msg->first_line.type==SIP_REQUEST) {
00132 update_stat( rcv_reqs, 1);
00133
00134 if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
00135
00136 LM_ERR("no via found in request\n");
00137 update_stat( err_reqs, 1);
00138 goto error02;
00139 }
00140
00141
00142 #ifdef USE_TCP
00143 if (msg->via1->alias && tcp_accept_aliases &&
00144 (((rcv_info->proto==PROTO_TCP) && !tcp_disable)
00145 #ifdef USE_TLS
00146 || ((rcv_info->proto==PROTO_TLS) && !tls_disable)
00147 #endif
00148 )
00149 ){
00150 if (tcpconn_add_alias(rcv_info->proto_reserved1, msg->via1->port,
00151 rcv_info->proto)!=0){
00152 LM_ERR("tcp alias failed\n");
00153
00154 }
00155 }
00156 #endif
00157
00158 LM_DBG("preparing to run routing scripts...\n");
00159
00160 set_route_type( REQUEST_ROUTE );
00161
00162
00163
00164
00165
00166
00167
00168
00169 if (exec_pre_req_cb(msg)==0 ) {
00170 update_stat( drp_reqs, 1);
00171 goto end;
00172 }
00173
00174
00175 run_top_route(rlist[DEFAULT_RT], msg);
00176
00177
00178 exec_post_req_cb(msg);
00179 } else if (msg->first_line.type==SIP_REPLY) {
00180 update_stat( rcv_rpls, 1);
00181
00182 if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
00183
00184 LM_ERR("no via found in reply\n");
00185 update_stat( err_rpls, 1);
00186 goto error02;
00187 }
00188
00189
00190 set_route_type( ONREPLY_ROUTE );
00191
00192
00193
00194
00195
00196
00197
00198
00199 if (exec_pre_rpl_cb(msg)==0 ) {
00200 update_stat( drp_rpls, 1);
00201 goto end;
00202 }
00203
00204
00205 if ( onreply_rlist[DEFAULT_RT]!=0 &&
00206 (run_top_route(onreply_rlist[DEFAULT_RT],msg)&ACT_FL_DROP) ) {
00207 LM_DBG("dropping reply %d\n", msg->REPLY_STATUS);
00208 update_stat( drp_rpls, 1);
00209 goto end;
00210 } else {
00211
00212 forward_reply(msg);
00213
00214 }
00215
00216
00217 exec_post_rpl_cb(msg);
00218 }
00219
00220 end:
00221
00222 reset_avps();
00223 LM_DBG("cleaning up\n");
00224 free_sip_msg(msg);
00225 pkg_free(msg);
00226 return 0;
00227 error02:
00228 free_sip_msg(msg);
00229 pkg_free(msg);
00230 error00:
00231 return -1;
00232 }
00233