< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

Re: [reSIProcate-users] Parse a INVITE message


Hi Thomas,

You can use the SipMessage::make(...) static method:

char raw[] = "INVITE sip:127.0.0.1:5060 SIP/2.0\r\nVia: SIP/2.0/UDP 456.local;branch=z9hG4bK-d8754z-59be8a04608ebc00-1---d8754z-;rport\r\nMax-Forwards: 70\r\nContact: <sip:contact@xxxxxxxxx>\r\nTo: <sip:target@xxxxxxxxx>;tag=arthur\r\nFrom: <sip:from@xxxxxxxxx>;tag=2fee4d27\r\nCall-ID: ODJiMmU0ODFmOTczZGZjOTM3YTg3YWQ0ZmYwODY3NzU.\r\nCSeq: 1 INVITE\r\nContent-Length: 19\r\nContent-Type: hello/world\r\nDate: Tue, 06 May 2008 14:28:19 GMT\r\nUser-Agent: Agent 1\r\n\r\nThis is my content\n";

SipMessage* pMsg = SipMessage::make(raw, 0);

cout << "From (full): " << Data::from(pMsg->header(h_From)).c_str() << endl;

cout << "From (uri): " << Data::from(pMsg->header(h_From).uri()).c_str() << endl;

delete pMsg;

Which produces:

From (full): <sip:from@xxxxxxxxx>;tag=2fee4d27
From (uri): sip:from@xxxxxxxxx

I hope this helps,
Francis

On Thu, May 5, 2011 at 10:28 AM, thomas collette <tom.collette@xxxxxxxxx> wrote:
Hello,

I'm trying to parse a INVITE SIP message to get the To header, From headre, URI, tag....etc
Here my code to parse the URI From header:

{
char* txt = (char*)buf->get_data(); //To get the INVITE message
resip::SipMessage* msg = new resip::SipMessage();

size_t lentxt = strlen(txt);
char* buffer = new char[lentxt + 5];
msg->addBuffer(buffer);
memcpy(buffer,txt, lentxt);
msg = msg->make(buffer,false);

printf(msg->header(resip::h_From).uri().user().data());
}

The printf give me everything that was after the From Header and not just the URI as I asked:

admin@xxxxxxxxxxxx:5060>;tag=42559c3a
To: "111"<sip:111@xxxxxxxxxxxx:5060>
Call-ID: ZWI2NTZhYWYzMzY1Y2ZiMjJiYWU4ZWM1YdMTg5Y2Y.
CSeq: 1 INVITE
Via: SIP/2.0/UDP 172.16.21.19:16084;rport=16084;branch=z9hGfK-d87543-c65c9a07513afd65-1--d87543-
Max-Forwards: 70
User-Agent: X-Lite release 1006e stamp 34025
Contact: <sip:admin@xxxxxxxxxxxx:16084>
....

It's my first attempt with ReSip, do you know how I can just get the URI ?


Regards

_______________________________________________
resiprocate-users mailing list
resiprocate-users@xxxxxxxxxxxxxxx
List Archive: http://list.resiprocate.org/archive/resiprocate-users/