📄 testdns.cxx
字号:
"sip:<hostname>:5080", "sips:<hostname>:5081", "sip:<hostname>", "sips:<hostname>" }; resip::Data ipAddr("127.0.0.1"); Uri uri; for(int i=0; i< 16;++i) { Query query; std::vector<Tuple> expected; for(int j=0;j<3;++j) { if(expectedPorts[i][j]==0) { break; } expected.push_back(Tuple(ipAddr,expectedPorts[i][j],V4,expectedTransports[i][j])); } //query.listener = new VipListener; cerr << "Creating Uri " << uris[i] << endl; uri = Uri(uris[i]); query.handler = new TestDnsHandler(expected,uri); query.uri = uri; cerr << "Creating DnsResult" << endl; DnsResult* res = dns.createDnsResult(query.handler); query.result = res; queries.push_back(query); cerr << rf << "Looking up" << ub << endl; dns.lookup(res, uri); } resip::Data NAPTRstrings[3]={ "", "-brokenNAPTR", "-noNAPTR" }; resip::Data SRVstrings[3]={ "", "-brokenSRV", "-noSRV" }; for(int i=0;i<8;++i) { for(int n=0;n<3;++n) { for(int s=0;s<3;++s) { if(n==0 && s==0) { // .bwc. This is just user.test.resiprocate.org, which we have already done. continue; } if(n==1 && s==2) { // .bwc. broken NAPTR and missing SRV is equivalent to OK NAPTR // and missing SRV (n==0 and s==2). The former is not provisioned // in the DNS zone, but the latter is, so we have already taken // care of this case. continue; } resip::Data hostname(resip::Data("user")+NAPTRstrings[n]+SRVstrings[s]+resip::Data(".test.resiprocate.org")); resip::Data target=subUris[i]; target.replace("<hostname>",hostname); //query.listener = new VipListener; cerr << "Creating Uri " << target << endl; uri = Uri(target); unsigned int port=0; TransportType type=UNKNOWN_TRANSPORT; // .bwc. Choose expected destination. if(uri.exists(p_transport)) { // .bwc. Transport is explicitly specified; no NAPTR query // will be made. State of NAPTR is irrelevant. if(uri.port()!=0) { // .bwc. Port is explicitly specified. No SRV query will // be made. This will be a bare A record lookup. port=uri.port(); type=toTransportType(uri.param(p_transport)); if(uri.scheme()=="sips" && type!=TLS) { // What is the resolver supposed to do in this case? assert(0); } } else { // .bwc. Port is not explicitly specified. SRV query will // be attempted. if(s==0) { // SRV ok. Will land on 127.0.0.1:507[01] on specified // transport. type=toTransportType(uri.param(p_transport)); if(type==TLS) { port=5071; } else { port=5070; } } else if(s==1) { // SRV broken. (Exists, so will be followed into space) // Leave port as 0, since no results will come of this. } else { // SRV missing. DNS fill fail over to A record lookup. type=toTransportType(uri.param(p_transport)); if(type==TLS) { port=5061; } else { port=5060; } } } } else { // transport is not specified if(uri.port()!=0) { // Port is specified, so we need to make an A query. We choose // UDP if scheme is sip, and TLS if scheme is sips. port=uri.port(); if(uri.scheme()=="sip") { type=UDP; } else if(uri.scheme()=="sips") { type=TLS; } else { assert(0); } } else { // Port is not specified, and neither is transport. Full // NAPTR lookup. if(n==0) { // NAPTR ok. if(s==0) { // SRV ok. We know what we're getting at this point. if(uri.scheme()=="sips") { type=TLS; } else if(uri.scheme()=="sip") { type=TCP; } else { assert(0); } if(type==TLS) { port=5071; } else { port=5070; } } else if(s==1) { // SRV broken. We fail. } else { // SRV missing. Do A lookup, default the port. // (We have already chosen transport) if(uri.scheme()=="sips") { type=TLS; } else if(uri.scheme()=="sip") { type=UDP; } else { assert(0); } if(type==TLS) { port=5061; } else { port=5060; } } } else if(n==1) { // NAPTR is broken. This is the same situation as // missing SRVs. if(uri.scheme()=="sips") { type=TLS; } else if(uri.scheme()=="sip") { type=UDP; } else { assert(0); } if(type==TLS) { port=5061; } else { port=5060; } } else { // NAPTR is missing. Next we try SRV. if(uri.scheme()=="sips") { type=TLS; } if(s==0) { // SRV ok. if(type==TLS) { port=5071; } else { port=5070; } } else if(s==1) { // SRV broken. We are hosed. } else { // SRVs missing. Fail over to A records. if(uri.scheme()=="sips") { type=TLS; } else if(uri.scheme()=="sip") { type=UDP; } else { assert(0); } if(type==TLS) { port=5061; } else { port=5060; } } } } } Query query; std::vector<Tuple> expected; if(port) { if(type!=UNKNOWN_TRANSPORT) { expected.push_back(Tuple(ipAddr,port,V4,type)); } else { // .bwc. If we get UNKNOWN_TRANSPORT from the block of // code above, it means we will try all three. (Yes, this // is hackish. At least I documented it.) assert(port%2==0); expected.push_back(Tuple(ipAddr,port,V4,UDP)); expected.push_back(Tuple(ipAddr,port,V4,TCP)); expected.push_back(Tuple(ipAddr,port+1,V4,TLS)); } } query.handler = new TestDnsHandler(expected,uri); query.uri = uri; cerr << "Creating DnsResult" << endl; DnsResult* res = dns.createDnsResult(query.handler); query.result = res; queries.push_back(query); cerr << rf << "Looking up" << ub << endl; dns.lookup(res, uri); } } } // .bwc. Resolves uris from command line, if they are present. while (argc > 1 && args && *args != 0) { Uri uri; Query query; query.handler = new TestDnsHandler; //query.listener = new VipListener; cerr << "Creating Uri: " << *args << endl; try { Data input(*args++); uri = Uri(input); query.uri = uri; cerr << "Creating DnsResult" << endl; DnsResult* res = dns.createDnsResult(query.handler); query.result = res; queries.push_back(query); cerr << rf << "Looking up" << ub << endl; dns.lookup(res, uri); } catch (ParseException& e) { cerr << "Couldn't parse arg " << *(args-1) << ": " << e.getMessage() << endl; } argc--; } // .bwc. Wait for outstanding queries to finish. int count = queries.size(); while (count>0) { for (std::list<Query>::iterator it = queries.begin(); it != queries.end(); ) { if ((*it).handler->complete()) { cerr << rf << "DNS results for " << (*it).uri << ub << endl; for (std::vector<Tuple>::iterator i = (*it).handler->results.begin(); i != (*it).handler->results.end(); ++i) { cerr << rf << (*i) << ub << endl; } --count; (*it).result->destroy(); delete (*it).handler; std::list<Query>::iterator temp = it; ++it; queries.erase(temp); } else { ++it; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -