diff options
author | chriszero <zerov83@gmail.com> | 2015-12-15 22:15:35 +0100 |
---|---|---|
committer | chriszero <zerov83@gmail.com> | 2015-12-15 22:15:35 +0100 |
commit | 7b64bf5062f3eb6ddff5d7606e44367bd5077e4c (patch) | |
tree | 258cbbc0d4edbe3bcabf58c6dee495d19384ed14 /PlexServer.cpp | |
parent | 135ed5d0ce1613f70f4b2ddcb9e8bca721ffca9e (diff) | |
download | vdr-plugin-plex-7b64bf5062f3eb6ddff5d7606e44367bd5077e4c.tar.gz vdr-plugin-plex-7b64bf5062f3eb6ddff5d7606e44367bd5077e4c.tar.bz2 |
Added SSL support, started support for remote
resources (servers). Browsing remote servers is
working. plex.tv login is mandatory.
Diffstat (limited to 'PlexServer.cpp')
-rw-r--r-- | PlexServer.cpp | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/PlexServer.cpp b/PlexServer.cpp index 6b3f0ae..687c8d1 100644 --- a/PlexServer.cpp +++ b/PlexServer.cpp @@ -3,15 +3,45 @@ namespace plexclient { + +PlexServer::PlexServer(std::string ip, int port) +{ + m_httpSession = NULL; + + Poco::URI uri; + uri.setHost(ip); + uri.setPort(port); + uri.setScheme("http"); + m_uri = uri.toString(); +} PlexServer::PlexServer(std::string data, std::string ip) { + m_httpSession = NULL; ParseData(data, ip); } +PlexServer::PlexServer(std::string uri, std::string name, std::string uuid, std::string accessToken, bool owned, bool local) +{ + m_httpSession = NULL; + m_sServerName = name; + m_sUuid = uuid; + m_nOwned = owned; + m_bLocal = local; + m_authToken = accessToken; + + m_uri = uri; +} + +PlexServer::~PlexServer() +{ + delete m_httpSession; + m_httpSession = NULL; +} + void PlexServer::ParseData(std::string data, std::string ip) { - m_sIpAddress = ip; + int port = 0; std::istringstream f(data); std::string s; Offline = false; @@ -27,7 +57,7 @@ void PlexServer::ParseData(std::string data, std::string ip) } else if (name == "Name") { m_sServerName = val; } else if (name == "Port") { - m_nPort = atoi(val.c_str()); + port = atoi(val.c_str()); } else if (name == "Updated-At") { m_nUpdated = atol(val.c_str()); } else if (name == "Version") { @@ -35,17 +65,47 @@ void PlexServer::ParseData(std::string data, std::string ip) } } } + delete m_httpSession; + m_httpSession = NULL; + + Poco::URI uri; + + uri.setHost(ip); + uri.setPort(port); + uri.setScheme("http"); + + m_uri = uri.toString(); } -PlexServer::PlexServer(std::string ip, int port) +std::string PlexServer::GetHost() { - m_sIpAddress = ip; - m_nPort = port; + Poco::URI uri(m_uri); + return uri.getHost(); +} + +int PlexServer::GetPort() +{ + Poco::URI uri(m_uri); + return uri.getPort(); +} + +Poco::Net::HTTPClientSession* PlexServer::GetClientSession() +{ + Poco::URI uri(m_uri); + if(m_httpSession == NULL) { + if(uri.getScheme().find("https") != std::string::npos) { + m_httpSession = new Poco::Net::HTTPSClientSession(uri.getHost(), uri.getPort()); + } + else { + m_httpSession = new Poco::Net::HTTPClientSession(uri.getHost(), uri.getPort()); + } + } + return m_httpSession; } std::string PlexServer::GetUri() { - return std::string("http://") + m_sIpAddress + ":" + std::string(itoa(m_nPort)); + return m_uri; } } |