📄 testsipmessage.cxx
字号:
#include <iostream>
#include <memory>
#include "rutil/DataStream.hxx"
#include "resip/stack/SipMessage.hxx"
#include "resip/stack/Helper.hxx"
#include "resip/stack/Uri.hxx"
#include "resip/stack/Helper.hxx"
#include "resip/stack/SdpContents.hxx"
#include "resip/stack/test/TestSupport.hxx"
#include "resip/stack/PlainContents.hxx"
#include "resip/stack/UnknownHeaderType.hxx"
#include "resip/stack/UnknownParameterType.hxx"
#include "rutil/Logger.hxx"
#include "rutil/ParseBuffer.hxx"
#include "rutil/Inserter.hxx"
using namespace resip;
using namespace std;
#define RESIPROCATE_SUBSYSTEM Subsystem::TEST
#define CRLF "\r\n"
#define RESIP_COOKIE "-d8754z-"
//vis -o to make binary bodies text
int
main(int argc, char** argv)
{
Log::initialize(Log::Cout, Log::Debug, argv[0]);
#
Data txt(
"SIP/2.0 401 Unauthorized\r\n"
"To: <sip:6309790007@ahenc1.ascc.lucent.com>;tag=43822895-1132606320408559\r\n"
"From: \"Kit LDAP\"<sip:6309790007@ahenc1.ascc.lucent.com>;tag=64505823\r\n"
"Call-ID: 7574556ad424b15c@aW5zcDc1MDAudW5pY29uLWludGwuY29t\r\n"
"CSeq: 1 PUBLISH\r\n"
"Via: SIP/2.0/UDP 67.184.22.204:33001;received=67.184.22.204;branch=z9hG4bK" RESIP_COOKIE "861ee62db418b378-1-" RESIP_COOKIE "\r\n"
"Server: Lucent SIPTRANS 1.2\r\n"
"WWW-Authenticate: Digest realm=\"aP3nFt10ziWg41Su4s8\", \r\n"
" nonce=\"d6cb083cced5583c140c5f99eb81feda\", algorithm=MD5, qop=\"auth\", \r\n"
" opaque=\"f2a62109ee6526c8760e4e7497861aac\"\r\n"
"Content-Length: 0\r\n"
"\r\n"
);
initNetwork();
auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
assert(msg.get());
cerr << Inserter(msg->header(h_WWWAuthenticates)) << endl;
cerr << "[" << msg->header(h_WWWAuthenticates).back().param(p_opaque) << "]" << endl;
assert(msg->header(h_WWWAuthenticates).back().param(p_opaque) == "f2a62109ee6526c8760e4e7497861aac");
{
Data txt(
"To: sip:fluffy@h1.cs.sipit.net\r\n"
"From: tofu <sip:tofu@ua.ntt.sipit.net>;tag=5494179792598219348\r\n"
"CSeq: 1 SUBSCRIBE\r\n"
"Call-ID: 1129541551360711705\r\n"
"Contact: sip:tofu@ua.ntt.sipit.net:5060\r\n"
"Event: presence\r\n"
"Content-Length: 0\r\n"
"Expires: 3600\r\n"
"User-Agent: NTT SecureSession User-Agent\r\n"
"\r\n"
"--Dfk2rISgfWIirrOJ\r\n"
"Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
"Content-Transfer-Encoding: binary\r\n"
"Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
"0\202\004\201\327\006 *\206H\206\367\001\007\002\201\240\202\004\201\3100\202\004\201\304\002\001\0011\0130 \006\005+\003\002\032\005\000\201\260\013\006 \201\252\206\201\310\206\367\001\007\001\201\240\202\003\201\376\201\260\202\003\201\372\201\260\202\002\201\343\201\240\003\002\001\002\002\007\201\322\000\002\000\201\327\003\201\313\201\260\006 \201\252\206\201\310\206\367\001\001\005\005\000\201\260\201\360\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023r\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\201\260\036\027\201\260\201\264\201\260\201\270\201\262\201\265\201\260\201\262\201\261\201\270\201\264\201\270\201\332\027\201\260\201\267\201\260\201\270\201\262\201\265\201\260\201\262\201\261\201\270\201\264\201\270\201\332\201\260\201\345\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\005\201\363\201\351\201\360\201\351\201\364\201\261\036\201\260\034\006\003\201\325\004\003\024\025\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\201\260\201\237\201\260\006 \201\252\206\201\310\206\367\001\001\001\005\000\003\201\215\000\201\260\201\211\002\201\201\000\201\331\201\322\201\267\201\345\201\263\201\337\201\201\365\201\246\201\317\201\337\201\314\201\343\201\350\201\370\201\332\201\372\201\366\201\356\227\201\260\010\201\304\201\326\005\201\253\014\201\316\201\335\201\362\201\253\201\336\036\201\326\201\247\201\365\201\321\201\342\201\312\201\336\201\310\030\201\310\034\201\325\201\274\201\255\201\336\201\372\201\306\201\277\201\303\201\364\201\343\201\355\201\240\201\323\201\374\201\347\201\240\004\201\363\205\316\230\205\320\205\261\205\255\211\205\205\261\205\276\205\333\205\277\205\350\205\274\205\361\021\201\260\201\255\201\265\201\276\201\373\203\201\267\201\356\201\355\201\256\201\337\201\262\201\244\201\305\033\023\000\201\266\206\021\201\303\201\252\201\265\201\364\001\201\246\201\251\030\201\372\235\201\325\201\273\037\201\251\201\332\201\354\201\331\201\371\201\263\201\261\201\347\236\201\322\201\376\201\274\201\332\201\377\002\003\001\000\001\201\243\202\001\201\247\201\260\202\001\201\243\201\260\201\332\006\003\201\325\035\021\004\201\323\201\260\201\321\206\031\201\363\201\351\201\360\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\206\030\201\351\201\355\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\206\032\201\360\201\362\201\345\201\363\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\201\260 \006\003\201\325\035\023\004\002\201\260\000\201\260\035\006\003\201\325\035\004\026\004\024 \026\201\307\201\306l\201\242\234\013\201\261\034\237\201\247\201\262\035\201\254B\201\357\201\324\201\2660\201\232\006\003U\035#\004\201\2220\201\217\200\024kF\027\024\201\352\224v%\200Tn\023T\201\332\201\241\201\343T\024\201\241\201\266\201\241t\201\244r0p1\0130 \006\003U\004\006\023\002US1\0230\021\006\003U\004\010\023California1\0210\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\202\001\000\201\260\006 \201\252\206\201\310\206\367\001\001\005\005\000\003\201\201\000\201\241\201\311\201\336\226\201\321\201\365\201\256\201\256\005\201\245\215\310\215\320\215\260\024\201\351\201\301\201\377\201\270\201\337\201\260\201\306\203\201\241\201\307\203\355\032\201\246\003\201\334\201\264\010\201\321\000\201\261\201\255\201\261\201\366\201\304\201\346\201\270\201\313\226\210\201\363\014\201\256\201\277\201\302\201\240\201\361\201\366\201\352\201\344\201\255\201\327\201\263\236\201\355\201\272\010\236\201\277\201\245\201\267\201\316\201\300\201\311\201\357\201\336\201\277\201\360\201\366\201\302\201\262\201\373\201\261\201\351\201\345\201\243\201\330\201\325\201\271\201\277\201\264\234\201\363\007\021\201\247\201\314\201\265\201\243\201\242\201\253\201\353\201\266\201\313\201\341\201\341\201\340\201\316\232\205\244\205\324\205\267\205\363\205\351\205\257\205\373\205\267\010\201\362\201\240\201\273\201\324\201\265\211\264\030\201\372\201\356\201\326\201\323\201\261\202\001\201\241\201\260\202\001\035\002\001\001\201\260\201\373\201\260\201\360\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\002\007\201\322\000\002\000\201\327\003\201\313\201\260 \006\005\201\253\003\002\032\005\000\201\260\006 \201\252\206\201\310\206\367\001\001\001\005\000\004\201\200\201\246\201\255\202\350\202\242\202\261\207\227\033\027\201\375 \201\332\201\267\201\246\201\375\031\201\326\201\255\001\201\271\201\333\201\306\201\351\201\367\201\344\031\201\356\233\201\353\031\003\201\336 \003\201\353\201\260\201\323\201\267\026\022\201\307\233\201\316\201\362\201\304\201\256\201\247\201\243\201\256\201\261\211\202\243\202\324\202\314\027\222\027\222\034\230\201\240\201\323\037\201\345\034\220\201\372\201\261\201\377\201\333\201\310\201\343\201\300\201\335\201\310 \236\201\274\201\315\201\301\201\352\202\201\261\201\324\201\347\222\203\333\203\316\203\336\203\360<\211\236\203\276[\203\301\003\010\201\373rR\236\201\322\027\201\242\201\374b\027d:\225(\030\225\217\032\202\025\201\373\226\201\255\201\255\201\304\201\346\201\353\201\262\201\362\201\311\201\323\201\347\201\346\201\327\201\311\201\351\201\362\201\362\201\317\201\312\201\255\201\255" );
auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
// !ah! deleted cerr output that was messing up terminals
}
{
SipMessage empty;
try
{
cerr << empty.brief() << endl;
empty.header(h_CSeq);
cerr << empty.brief() << endl;
empty.header(h_Vias).push_back(Via());
cerr << empty.brief() << endl;
}
catch (SipMessage::Exception& e)
{}
}
{
Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
"To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
"From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
"Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
"Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
"Call-ID: 6c64b42fce01b007\r\n"
"CSeq: 2 INVITE\r\n"
"Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
"Contact: <sip:192.168.2.15:5100>\r\n"
"Content-Length: 0\r\n"
"\r\n");
auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
msg->header(h_Routes).pop_back();
cerr << *msg << endl;
}
{
Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
"To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
"From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
"Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
"Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
"Call-ID: 6c64b42fce01b007\r\n"
"CSeq: 2 INVITE\r\n"
"Record-Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
"Contact: <sip:192.168.2.15:5100>\r\n"
"Max-Forwards: 69\r\n"
"Content-Type: application/sdp\r\n"
"Content-Length: 307\r\n"
"\r\n"
"v=0\r\n"
"o=M2TUA 1589993278 1032390928 IN IP4 192.168.2.15\r\n"
"s=-\r\n"
"c=IN IP4 192.168.2.15\r\n"
"t=0 0\r\n"
"m=audio 9000 RTP/AVP 103 97 100 101 0 8 102\r\n"
"a=rtpmap:103 ISAC/16000\r\n"
"a=rtpmap:97 IPCMWB/16000\r\n"
"a=rtpmap:100 EG711U/8000\r\n"
"a=rtpmap:101 EG711A/8000\r\n"
"a=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:8 PCMA/8000\r\n"
"a=rtpmap:102 iLBC/8000\r\n");
auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
SdpContents* sdp = dynamic_cast<SdpContents*>(msg->getContents());
sdp->session().media().front();
SdpContents osdp;
osdp.session().version() = 0;
osdp.session().name() = "-";
osdp.session().origin() = SdpContents::Session::Origin(Data("M2TUA"),
77,
99,
SdpContents::IP4,
"localhost");
osdp.session().addTime(SdpContents::Session::Time(0,0));
osdp.session().connection() =
SdpContents::Session::Connection(SdpContents::IP4, "localhost", 0);
SdpContents::Session::Medium medium(Symbols::audio, 0, 1, Symbols::RTP_AVP);
SdpContents::Session::Codec codec1("iLBC", 102, 8000);
medium.addCodec(codec1);
SdpContents::Session::Codec codec2("PCMA", 8, 8000);
medium.addCodec(codec2);
SdpContents::Session::Codec codec3("PCMU", 0, 8000);
medium.addCodec(codec3);
SdpContents::Session::Codec codec4("EG711A", 101, 8000);
medium.addCodec(codec4);
SdpContents::Session::Codec codec5("EG711U", 100, 8000);
medium.addCodec(codec5);
SdpContents::Session::Codec codec6("IPCMWB", 97, 16000);
medium.addCodec(codec6);
SdpContents::Session::Codec codec7("ISAC", 103, 16000);
medium.addCodec(codec7);
osdp.session().addMedium(medium);
SdpContents::Session::Medium& myMedium = osdp.session().media().front();
SdpContents csdp;
csdp = *sdp;
SdpContents::Session::Medium& my1Medium = csdp.session().media().front();
cerr << myMedium.protocol() << " : " << my1Medium.protocol() << endl;
SdpContents c2sdp;
c2sdp = *sdp;
SdpContents::Session::Medium& myMedium2 = c2sdp.session().media().front();
cerr << myMedium2.protocol() << endl;
}
{
Data txt1 = "SIP/2.0 407 Proxy Authentication Required\r\n"
"To: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>\r\n"
"From: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>;tag=113cba09\r\n"
"Via: SIP/2.0/64.124.66.32:9091;branch=z9hG4bK-c87542-5b42cb698e8c6827790212ac5bdade1a-1-PA32768-c87542-;rport;received=64.124.66.32\r\n"
"Via: SIP/2.0/UDP 192.168.1.102:5100;branch=z9hG4bK-c87542-175255966-1--c87542-;rport\r\n"
"Call-ID: d8023c1dc2559a21\r\n"
"CSeq: 1 REGISTER\r\n"
"Contact: <sip:64.124.66.32:5060>\r\n"
"Content-Length: 0\r\n\r\n";
auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
try
{
cerr << "transport=" << message1->header(h_Vias).front().transport() << endl;
assert(false);
}
catch (ParseBuffer::Exception& e)
{
}
}
{
cerr << "test CRLFs before the start line" << endl;
Data txt1 = "\r\n\r\n\r\nSIP/2.0 407 Proxy Authentication Required\r\n"
"To: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>\r\n"
"From: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>;tag=113cba09\r\n"
"Via: SIP/2.0/UDP 64.124.66.32:9091;branch=z9hG4bK-c87542-5b42cb698e8c6827790212ac5bdade1a-1-PA32768-c87542-;rport;received=64.124.66.32\r\n"
"Via: SIP/2.0/UDP 192.168.1.102:5100;branch=z9hG4bK-c87542-175255966-1--c87542-;rport\r\n"
"Call-ID: d8023c1dc2559a21\r\n"
"CSeq: 1 REGISTER\r\n"
"Contact: <sip:64.124.66.32:5060>\r\n"
"Content-Length: 0\r\n\r\n";
try
{
auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
message1->header(h_StatusLine).statusCode() == 407;
}
catch (BaseException& e)
{
assert(false);
}
}
{
cerr << "test complex content copy" << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -