If I have a SIP message in a char* variable, then I assume that I can parse it into a struct sip_msg* using a function in ser. The most obvious function seems to be parse_msg(). This does not seem to work to my expectation.
Here is a code snippet (which is close to the code in receive.c):
char* response // contains my message struct sip_msg msg // this is were the result should go
memset(msg, 0, sizeof(struct sip_msg)); response[len] = 0; msg->buf = response; msg->len = len; if (parse_msg(response, len, msg))!=0) { LOG(L_ERR, "ERROR"); } LOG(L_ERR, "After parse msg ...") dump_sip_msg(msg) // this just prints the fields of the message to LOG
dump_sip_msg() works fine on the incoming sip message, so the problem is either in my SIP message or in my use of the parse function. However, I think my message is fine (it is the received message with the first line replaced with SIP/2.0 600 Policy Server Msg date time). I enclose a cut from /var/log/messages.
Stephan
/var/log/messages:
Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: After parse_msg... Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: polserv: dump_sip_msg() Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->id: int = 0 Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->first_line: msg_start (rep) 600 Policy Server Msg 2003-03-07 14:52:24^M Via: SIP/2.0/UDP Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: DEBUG: dump_hdr_field: type=1, name=Via, body=SIP/2.0/UDP 139.153.254.196:5062, parsed=0x80a584c, next=(nil) Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: DEBUG: dump_hdr_field: type=1, name=Via, body=SIP/2.0/UDP 139.153.254.196:5062, parsed=0x80a584c, next=(nil) Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->parsed_flag 1 Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: DEBUG: dump_hdr_field: type=1, name=Via, body=SIP/2.0/UDP 139.153.254.196:5062, parsed=0x80a584c, next=(nil) Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: DEBUG: dump_hdr_field: field is NULL Mar 7 14:52:41 d254196 last message repeated 20 times Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->eoh: (null) Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->unparsed: CSeq: 7635 REGISTER^M To: "Stephan" sip:mrs@cs.stir.ac.uk^M Expires: 900^M From: "Stephan" sip:mrs@cs.stir.ac.uk^M Call-Id: 138108089@139.153.254.196^M User-Agent: KPhone/2.11^M Event: registration^M Allow-Events: presence^M Contact: "root" sip:root@139.153.254.196:5062;transport=UDP;methods="INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK"^M Content-Length: 0^M ^M ^M Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->buf: SIP/2.0 600 Policy Server Msg 2003-03-07 14:52:24^M Via: SIP/2.0/UDP 139.153.254.196:5062^M CSeq: 7635 REGISTER^M To: "Stephan" sip:mrs@cs.stir.ac.uk^M Expires: 900^M From: "Stephan" sip:mrs@cs.stir.ac.uk^M Call-Id: 138108089@139.153.254.196^M User-Agent: KPhone/2.11^M Event: registration^M Allow-Events: presence^M Contact: "root" sip:root@139.153.254.196:5062;transport=UDP;methods="INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK"^M Content-Length: 0^M ^M ^M Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->len: 475 Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: msg->parsed_uri_ok: int = 0 Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: polserv: all fine, returning now ... Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: ERROR: parse_sip_msg_uri: bad uri <600> Mar 7 14:52:41 d254196 /usr/local/sbin/ser[9566]: WARNING: do_action:error in expression
-- Dr Stephan Reiff-Marganiec Research Fellow Department of Computing Science; University of Stirling email: srm@cs.stir.ac.uk tel: 01786 46 7448