From 1724ce597446f28a3eeda888c565d2fef50de773 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 22 Dec 2007 16:47:46 +0000 Subject: [PATCH] fixed bug in UPnP and added functionality to grab router model --- include/libtorrent/upnp.hpp | 4 ++++ src/upnp.cpp | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 0b799d1e9..69389ad43 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -77,6 +77,8 @@ public: void close(); + std::string router_model() { return m_model; } + private: static address_v4 upnp_multicast_address; @@ -233,6 +235,8 @@ private: connection_queue& m_cc; + std::string m_model; + #ifdef TORRENT_UPNP_LOGGING std::ofstream m_log; #endif diff --git a/src/upnp.cpp b/src/upnp.cpp index 116eb1dfe..5075edb06 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -578,6 +578,7 @@ namespace std::string top_tag; std::string control_url; char const* service_type; + std::string model; }; void find_control_url(int type, char const* string, parse_state& state) @@ -591,6 +592,10 @@ namespace { state.top_tag = string; } + else if (!strcmp(string, "modelName")) + { + state.top_tag = string; + } } else if (type == xml_end_tag) { @@ -614,6 +619,10 @@ namespace state.control_url = string; if (state.found_service) state.exit = true; } + else if (state.top_tag == "modelName") + { + state.model = string; + } } } @@ -663,10 +672,11 @@ void upnp::on_upnp_xml(asio::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 - , m_strand.wrap(bind(&find_control_url, _1, _2, boost::ref(s)))); + , bind(&find_control_url, _1, _2, boost::ref(s))); if (s.found_service) { d.service_namespace = s.service_type; + if (!s.model.empty()) m_model = s.model; } else { @@ -674,10 +684,11 @@ void upnp::on_upnp_xml(asio::error_code const& e // 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)))); + , bind(&find_control_url, _1, _2, boost::ref(s))); if (s.found_service) { d.service_namespace = s.service_type; + if (!s.model.empty()) m_model = s.model; } else { @@ -821,7 +832,7 @@ void upnp::on_upnp_map_response(asio::error_code const& e error_code_parse_state s; xml_parse((char*)p.get_body().begin, (char*)p.get_body().end - , m_strand.wrap(bind(&find_error_code, _1, _2, boost::ref(s)))); + , bind(&find_error_code, _1, _2, boost::ref(s))); #ifdef TORRENT_UPNP_LOGGING if (s.error_code != -1)