10 #include "msg_parser.h"
14 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
17 struct route_elem *re;
20 /* make a copy of the message */
21 orig=(char*) malloc(len);
23 DPrint("ERROR: memory allocation failure\n");
26 memcpy(orig, buf, len);
28 if (parse_msg(buf,len, &msg)!=0){
32 if (msg.first_line.type==SIP_REQUEST){
34 if (msg.via1.error!=VIA_PARSE_OK){
35 /* no via, send back error ? */
38 /* check if neccesarry to add receive? */
41 re=route_match( msg.first_line.u.request.method,
42 msg.first_line.u.request.uri,
46 /* no route found, send back error msg? */
47 DPrint("WARNING: no route found!\n");
52 DPrint(" found route to: %s\n", re->host.h_name);
53 forward_request(orig, buf, len, &msg, re, src_ip);
54 }else if (msg.first_line.type==SIP_REPLY){
56 if (msg.via1.error!=VIA_PARSE_OK){
57 /* no via, send back error ? */
60 if (msg.via2.error!=VIA_PARSE_OK){
61 /* no second via => error? */
64 /* check if via1 == us */
67 if (forward_reply(orig, buf, len, &msg)==0){
68 DPrint(" reply forwarded to %s:%d\n",
70 (unsigned short) msg.via2.port);