Advertisement
Guest User

pjsip parse

a guest
Sep 14th, 2010
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <pjsip.h>
  4. #include <pjlib.h>
  5.  
  6. #define THIS_FILE "pjsiptest.cpp"
  7.  
  8. int main()
  9. {
  10.  
  11.     char __MSG[] = {  
  12.         "INVITE sip:user@foo SIP/2.0\n" // 28
  13.         "from: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r" // 73
  14.         "To: Fellow User <sip:user@foo.bar.domain.com>\r\n" // 50
  15.         "Call-ID: 12345678901234567890@bar\r\n" // 35
  16.         "Content-Length: 0\r\n" // 19
  17.         "CSeq: 123456 INVITE\n" // 20
  18.         "Contact: <sip:joe@bar> ; q=0.5;expires=3600,sip:user@host;q=0.500\r" // 66
  19.         "  ,sip:user2@host2\n" // 19
  20.         "Content-Type: text/html ; charset=ISO-8859-4\r" // 45
  21.         "Route: <sip:bigbox3.site3.atlanta.com;lr>,\r\n" // 44
  22.         "  <sip:server10.biloxi.com;lr>\r" // 31
  23.         "Record-Route: <sip:server10.biloxi.com>,\r\n" /* multiple routes+folding*/ // 42
  24.         "  <sip:bigbox3.site3.atlanta.com;lr>\n" // 37
  25.         "v: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n" // 66
  26.         "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n" /* folding. */ // 56
  27.         " ;received=192.0.2.1\r\n" // 22
  28.         "Via: SIP/2.0/UDP 10.2.1.1, SIP/2.0/TCP 192.168.1.1\n" //51
  29.         "Organization: \r" // 15
  30.         "Max-Forwards: 70\n" // 17
  31.         "X-Header: \r\n" //12       /* empty header */
  32.         "P-Associated-URI:\r\n" //19 /* empty header without space */
  33.         "\r\n\0"
  34.     };
  35.  
  36.     char msg2[] = {
  37.         "SIP/2.0 200 OK\r\n"
  38.         "Via: SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1;received=192.0.2.2\r\n"
  39.         "To: Bob <sip:bob@biloxi.com>;tag=a6c85cf\r\n"
  40.         "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
  41.         "Call-ID: a84b4c76e66710@pc33.atlanta.com\r\n"
  42.         "CSeq: 314159 INVITE\r\n"
  43.         ": <sips:bob@192.0.2.4>\r\n"
  44.         "Content-Type: application/sdp\r\n"
  45.         "Content-Length: 150\r\n"
  46.         "\r\n"
  47.         "v=0\r\n"
  48.         "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
  49.         "s=-\r\n"
  50.         "t=0 0\r\n"
  51.         "c=IN IP4 pc33.atlanta.com\r\n"
  52.         "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
  53.         "a=rtpmap:0 PCMU/8000\r\n"
  54.     };
  55.  
  56.     char msg3[] = {
  57.         "ACK sip:odbiorcak@domena-ok.com SIP/2.0"
  58.         "Via: SIP/2.0/UDP domena-n.com:5060;branch=z9hG4bK321g"
  59.         "Max-Forwards: 70"
  60.         "To: Nazwa odbiorcy <sip:odbiorca@domena-o.com>;tag=a53e42"
  61.         "From: Nazwa nadawcy <sip: nadawca@domena-n.com>;tag=76341"
  62.         "Call-ID: 123456789@domena-n.com"
  63.         "CSeq: 1 ACK"
  64.         "Content-Length: 0"
  65.     };
  66.        
  67.     char msg4[] = {
  68.         "ACK sip:odbiorcak@domena-ok.com SIP/2.0\r\n"
  69.     };  
  70.  
  71.     char *testmsg = msg4;
  72.  
  73.     pj_size_t msgsize;
  74.     pj_status_t status;
  75.  
  76.  
  77.     // INIT
  78.     status = pj_init();
  79.     PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
  80.  
  81.     status = pjlib_util_init();
  82.     PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
  83.  
  84.     // PARSING
  85.     pj_caching_pool cp;
  86.     pj_caching_pool_init(&cp, NULL, 1024*1024);
  87.     pj_pool_t *pool = pj_pool_create(&cp.factory, "parser_pool", 4000, 4000, NULL);
  88.     pjsip_parser_err_report err;
  89.  
  90.     int len = strlen(testmsg);
  91.     pjsip_msg *msg = pjsip_parse_msg(pool, testmsg, len, &err);
  92.  
  93.     printf("The end...");
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement