⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsipmessage.cxx

📁 一个著名的SIP协议栈
💻 CXX
📖 第 1 页 / 共 5 页
字号:
      }
   }
#endif

   {
      Data txt(
         "NOTIFY sip:fluffy@212.157.205.40 SIP/2.0\r\n"
         "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
         "To: sip:fluffy@212.157.205.40\r\n"
         "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
         "Max-Forwards: 70\r\n"
         "CSeq: 1 NOTIFY\r\n"
         "Call-ID: 28067261571992032320\r\n"
         "Contact: sip:ntt2@212.157.205.198:5060\r\n"
         "Content-Length: 1929\r\n"
         "Content-Type: multipart/signed;\r\n"
         " protocol=\"application/pkcs7-signature\";\r\n"
         " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
         "\r\n"
         "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
         "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
         "Content-Length: 870\r\n"
         "Content-Disposition: attachment;handling=required\r\n"
         "\r\n"
         "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
         "Content-Type: application/sipfrag\r\n"
         "Content-Length: 320\r\n"
         "\r\n"
         "To: sip:fluffy@212.157.205.40\r\n"
         "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
         "CSeq: 1 NOTIFY\r\n"
         "Call-ID: 28067261571992032320\r\n"
         "Contact: sip:ntt2@212.157.205.198:5060\r\n"
         "Event: presence\r\n"
         "Content-Length: 210\r\n"
         "Content-Type: application/xpidf+xml\r\n"
         "Subscription-State: active\r\n"
         "User-Agent: XXX SecureSession User-Agent\r\n"
         "\r\n"
         "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
         "Content-Type: application/xpidf+xml\r\n"
         "Content-Length: 210\r\n"
         "\r\n"
         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
         "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
         "<tuple id=\"765\">\r\n"
         "<status>\r\n"
         "<basic>open</basic>\r\n"
         "</status>\r\n"
         "</tuple>\r\n"
         "</presence>\r\n"
         "\r\n"
         "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
         "\r\n"
         "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
         "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
         "Content-Transfer-Encoding: base64\r\n"
         "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
         "\r\n"
         "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
         "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
         "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
         "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
         "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
         "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
         "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
         "zhSvTYdki20aiQ==\r\n"
         "\r\n"
         "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
         );
      
      auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
      InfoLog (<< "msg->header(h_ContentLength).value() == " << msg->header(h_ContentLength).value());
      assert( msg->header(h_ContentLength).value() == 1929 );
   }
    {
       Data txt( 
          "MESSAGE sip:fluffy@h1.cisco1.sipit.net:5060;transport=UDP SIP/2.0\r\n"
          "To: <sip:fluffy@h1.cisco1.sipit.net:5060>\r\n"
          "From: <sip:user@localhost:5080>;tag=20f94fd6\r\n"
          "Via: SIP/2.0/UDP 212.157.205.40:5080;branch=z9hG4bK-c87542-1005764096-2--c87542-;rport=5080;received=212.157.205.40\r\n"
          "Call-ID: 16f7f8fd368d8bcd\r\n"
          "CSeq: 1 MESSAGE\r\n"
          "Contact: <sip:user@212.157.205.40:5080>\r\n"
          "Max-Forwards: 70\r\n"
          "Content-Disposition: attachment;handling=required;filename=smime.p7\r\n"
          "Content-Type: application/pkcs7-mime;smime-type=enveloped-data;name=smime.p7m\r\n"
          "User-Agent: SIPimp.org/0.2.3 (curses)\r\n"
          "Content-Length: 4\r\n"
          "\r\n"
          "1234" );

       auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));  

       assert( msg->exists(h_ContentDisposition)  );
       msg->header(h_ContentDisposition);
       assert( msg->header(h_ContentLength).value() == 4 );
    }
   {
      // exercise header remove
      char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
                   "Allow-Events: foo\r\n"
                   "Allow-Events: bar\r\n"
                   "Allow-Events: baz\r\n"
                   "Allow-Events: quux\r\n"
                   "Unsupported: \r\n"
                   "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
                   "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
                   "Call-ID: 643f2f06\r\n"
                   "CSeq: 1 INVITE\r\n"
                   "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
                   "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
                   "Max-Forwards: 69\r\n"
                   "Content-Length: 0\r\n"
                   "Unknown: foobie\r\n"
                   "Unknown: biefoo\r\n"
                   "\r\n");

      auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
      // note message has not been parsed

      message->remove(h_AllowEvents);
      message->remove(h_Unsupporteds);
      message->remove(h_To);
      message->remove(h_From);
      message->remove(h_Vias);
      message->remove(h_CallId);
      message->remove(h_CSeq);
      message->remove(h_ProxyAuthorizations);
      message->remove(h_RecordRoutes);
      message->remove(h_Contacts);
      message->remove(h_MaxForwards);
      message->remove(h_ContentLength);
      message->remove(UnknownHeaderType("Unknown"));

      Data enc;
      {
         DataStream str(enc);
         str << *message;
      }

      InfoLog (<< enc);
      assert(enc == ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
                     "Content-Length: 0\r\n"
                     "\r\n"));
   }

   {
      // exercise header remove
      char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
                   "Allow-Events: foo\r\n"
                   "Allow-Events: bar\r\n"
                   "Allow-Events: baz\r\n"
                   "Allow-Events: quux\r\n"
                   "Unsupported: \r\n"
                   "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
                   "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
                   "Call-ID: 643f2f06\r\n"
                   "CSeq: 1 INVITE\r\n"
                   "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
                   "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
                   "Max-Forwards: 69\r\n"
                   "Content-Length: 0\r\n"
                   "Unknown: foobie\r\n"
                   "Unknown: biefoo\r\n"
                   "\r\n");

      auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));

      message->header(h_AllowEvents).front().value();
      message->header(h_Unsupporteds).empty();
      message->header(h_To).uri().user();
      message->header(h_From);
      message->header(h_Vias).front();
      message->header(h_CallId).value();
      message->header(h_CSeq).sequence();
      message->header(h_ProxyAuthorizations).size();
      message->header(h_RecordRoutes).front().uri().host();
      message->header(h_Contacts).size();
      message->header(h_MaxForwards).value();
      message->header(h_ContentLength).value();
      message->header(UnknownHeaderType("Unknown")).size();

      // note message has been parsed
      message->remove(h_AllowEvents);
      message->remove(h_Unsupporteds);
      message->remove(h_To);
      message->remove(h_From);
      message->remove(h_Vias);
      message->remove(h_CallId);
      message->remove(h_CSeq);
      message->remove(h_ProxyAuthorizations);
      message->remove(h_RecordRoutes);
      message->remove(h_Contacts);
      message->remove(h_MaxForwards);
      message->remove(h_ContentLength);
      message->remove(UnknownHeaderType("Unknown"));
      
      // not present
      message->remove(h_Routes);

      Data enc;
      {
         DataStream str(enc);
         str << *message;
      }

      assert(enc == ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
                     "Content-Length: 0\r\n"
                     "\r\n"));
   }

   {
      // demonstrate comma encoding
      char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
                   "Allow-Events: foo\r\n"
                   "Allow-Events: bar\r\n"
                   "Allow-Events: baz\r\n"
                   "Allow-Events: quux\r\n"
                   "Unsupported: \r\n"
                   "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
                   "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
                   "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
                   "Call-ID: 643f2f06\r\n"
                   "CSeq: 1 INVITE\r\n"
                   "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
                   "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
                   "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
                   "Max-Forwards: 69\r\n"
                   "Content-Length: 0\r\n"
                   "\r\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -