From b239eecc04df76322c93e34180b4de6d224db62d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 5 May 2007 22:06:26 +0000 Subject: [PATCH] updates to upnp code --- include/libtorrent/upnp.hpp | 3 ++- src/upnp.cpp | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index acf234d20..818b21871 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -134,6 +134,7 @@ private: { rootdevice(): lease_duration(default_lease_time) , supports_specific_external(true) + , service_namespace(0) { mapping[0].protocol = 0; mapping[1].protocol = 1; @@ -146,7 +147,7 @@ private: // the url to the WANIP or WANPPP interface std::string control_url; // either the WANIP namespace or the WANPPP namespace - std::string service_namespace; + char const* service_namespace; mapping_t mapping[num_mappings]; diff --git a/src/upnp.cpp b/src/upnp.cpp index c4c9981db..a5f00437c 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -394,6 +394,8 @@ void upnp::map_port(rootdevice& d, int i) } d.mapping[i].need_update = false; assert(!d.upnp_connection); + assert(d.service_namespace); + d.upnp_connection.reset(new http_connection(m_socket.io_service() , m_cc, m_strand.wrap(bind(&upnp::on_upnp_map_response, this, _1, _2 , boost::ref(d), i)))); @@ -553,15 +555,29 @@ void upnp::on_upnp_xml(asio::error_code const& e s.reset("urn:schemas-upnp-org:service:WANIPConnection:1"); xml_parse((char*)p.get_body().begin, (char*)p.get_body().end , m_strand.wrap(bind(&find_control_url, _1, _2, boost::ref(s)))); - d.service_namespace = "urn:schemas-upnp-org:service:WANIPConnection:1"; - if (!s.found_service) + if (s.found_service) + { + d.service_namespace = s.service_type; + } + else { // we didn't find the WAN IP connection, look for - // a PPP IP connection - s.reset("urn:schemas-upnp-org:service:PPPIPConnection:1"); + // a PPP connection + s.reset("urn:schemas-upnp-org:service:WANPPPConnection:1"); xml_parse((char*)p.get_body().begin, (char*)p.get_body().end , m_strand.wrap(bind(&find_control_url, _1, _2, boost::ref(s)))); - d.service_namespace = "urn:schemas-upnp-org:service:WANPPPConnection:1"; + if (s.found_service) + { + d.service_namespace = s.service_type; + } + else + { +#ifdef TORRENT_UPNP_LOGGING + m_log << time_now_string() + << " <== Rootdevice response, did not find a port mapping interface" << std::endl; +#endif + return; + } } #ifdef TORRENT_UPNP_LOGGING