Add support for IGD version 2

This commit is contained in:
Chocobo1 2015-07-06 20:33:29 +08:00
parent 1c708cca28
commit f92df7f782
1 changed files with 33 additions and 52 deletions

View File

@ -848,20 +848,11 @@ namespace
struct parse_state
{
parse_state(): in_service(false), service_type(0) {}
void reset(char const* st)
{
in_service = false;
service_type = st;
tag_stack.clear();
control_url.clear();
model.clear();
url_base.clear();
}
parse_state(): in_service(false) {}
bool in_service;
std::list<std::string> tag_stack;
std::string control_url;
char const* service_type;
std::string service_type;
std::string model;
std::string url_base;
bool top_tags(const char* str1, const char* str2)
@ -898,13 +889,18 @@ TORRENT_EXTRA_EXPORT void find_control_url(int type, char const* string, parse_s
else if (type == xml_string)
{
if (state.tag_stack.empty()) return;
// std::cout << " " << string << std::endl;
// std::cout << " " << string << std::endl;}
if (!state.in_service && state.top_tags("service", "servicetype"))
{
if (string_equal_no_case(string, state.service_type))
if (string_equal_no_case(string, "urn:schemas-upnp-org:service:WANIPConnection:1")
|| string_equal_no_case(string, "urn:schemas-upnp-org:service:WANIPConnection:2")
|| string_equal_no_case(string, "urn:schemas-upnp-org:service:WANPPPConnection:1"))
{
state.service_type = string;
state.in_service = true;
}
else if (state.control_url.empty() && state.in_service && state.top_tags("service", "controlurl"))
}
else if (state.control_url.empty() && state.in_service && state.top_tags("service", "controlurl") && strlen(string) > 0)
{
// default to the first (or only) control url in the router's listing
state.control_url = string;
@ -966,27 +962,9 @@ void upnp::on_upnp_xml(error_code const& e
}
parse_state s;
s.reset("urn:schemas-upnp-org:service:WANIPConnection:1");
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
, boost::bind(&find_control_url, _1, _2, boost::ref(s)));
if (!s.control_url.empty())
{
d.service_namespace = s.service_type;
if (!s.model.empty()) m_model = s.model;
}
else
{
// we didn't find the WAN IP connection, look for
// a PPP connection
s.reset("urn:schemas-upnp-org:service:WANPPPConnection:1");
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
, boost::bind(&find_control_url, _1, _2, boost::ref(s)));
if (!s.control_url.empty())
{
d.service_namespace = s.service_type;
if (!s.model.empty()) m_model = s.model;
}
else
if (s.control_url.empty())
{
char msg[500];
snprintf(msg, sizeof(msg), "could not find a port mapping interface in response from: %s"
@ -995,7 +973,10 @@ void upnp::on_upnp_xml(error_code const& e
d.disabled = true;
return;
}
}
static std::string service_type;
service_type.swap(s.service_type);
d.service_namespace = service_type.c_str();
if (!s.model.empty()) m_model = s.model;
if (!s.url_base.empty() && s.control_url.substr(0, 7) != "http://")
{