Skip to content

Commit

Permalink
V18 fixes (#58)
Browse files Browse the repository at this point in the history
* got rid of cstdstring and urlsteam, changed to stringutils functions

* fixed bug in strtoll call

* cleaned up, got rid of obsolete functions from client.cpp

* change version to 2.2.0, got rid of .format comments, and the rest of ksooo's suggestions

* more cleanup, also adopted most of ksooo's suggestions
  • Loading branch information
krustyreturns authored and ksooo committed Sep 12, 2017
1 parent d820bf8 commit 7e2cb4b
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 303 deletions.
2 changes: 1 addition & 1 deletion pvr.wmc/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.wmc"
version="2.1.1"
version="2.2.0"
name="PVR WMC Client"
provider-name="KrustyReturns and scarecrow420">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
3 changes: 3 additions & 0 deletions pvr.wmc/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.2.0
- Updated to PVR addon API v5.7.0

2.1.0
- Updated to PVR addon API v5.3.0

Expand Down
52 changes: 24 additions & 28 deletions src/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Socket::~Socket()
close();
}

bool Socket::setHostname ( const CStdString& host )
bool Socket::setHostname ( const std::string& host )
{
if (isalpha(host.c_str()[0]))
{
Expand Down Expand Up @@ -140,7 +140,7 @@ bool Socket::create()
return true;
}

int Socket::send( const CStdString& data )
int Socket::send( const std::string& data )
{
if (!is_valid())
{
Expand Down Expand Up @@ -199,14 +199,14 @@ int Socket::send ( const char* data, const unsigned int len )
}

//Receive until error or \n
bool Socket::ReadResponses(int &code, vector<CStdString> &lines)
bool Socket::ReadResponses(int &code, vector<std::string> &lines)
{
int result;
char buffer[4096]; // this buff size has to be known in server
code = 0;

bool readComplete = false;
CStdString bigString = "";
std::string bigString = "";

do
{
Expand Down Expand Up @@ -235,7 +235,7 @@ bool Socket::ReadResponses(int &code, vector<CStdString> &lines)
if (EndsWith(bigString, "<EOF>"))
{
readComplete = true; // all server data has benn read
lines = split(bigString, "<EOL>", true); // split each reponse by <EOL> delimiters
lines = split(bigString, "<EOL>"); // split each reponse by <EOL> delimiters
lines.erase(lines.end() - 1); // erase <EOF> at end
}
else
Expand All @@ -248,7 +248,7 @@ bool Socket::ReadResponses(int &code, vector<CStdString> &lines)
return readComplete;
}

bool Socket::connect ( const CStdString& host, const unsigned short port )
bool Socket::connect ( const std::string& host, const unsigned short port )
{
if ( !is_valid() )
{
Expand Down Expand Up @@ -559,12 +559,12 @@ void Socket::osCleanup()
#endif //TARGET_WINDOWS || TARGET_LINUX || TARGET_DARWIN || TARGET_FREEBSD


void Socket::SetServerName(CStdString strServerName)
void Socket::SetServerName(std::string strServerName)
{
_serverName = strServerName;
}

void Socket::SetClientName(CStdString strClientName)
void Socket::SetClientName(std::string strClientName)
{
_clientName = strClientName;
}
Expand All @@ -574,10 +574,10 @@ void Socket::SetServerPort(int port)
_port = port;
}

int Socket::SendRequest(CStdString requestStr)
int Socket::SendRequest(std::string requestStr)
{
CStdString sRequest;
sRequest.Format("%s|%s<Client Quit>", _clientName.c_str(), requestStr.c_str()); // build the request string
std::string sRequest;
sRequest = string_format("%s|%s<Client Quit>", _clientName.c_str(), requestStr.c_str()); // build the request string
int status = send(sRequest);
return status;
}
Expand All @@ -588,15 +588,15 @@ void Socket::SetTimeOut(int tSec)
_timeout = tSec;
}

std::vector<CStdString> Socket::GetVector(const CStdString &request, bool allowRetry, bool allowWOL /* = true*/)
std::vector<std::string> Socket::GetVector(const std::string &request, bool allowRetry, bool allowWOL /* = true*/)
{
int maxAttempts = 3;
int sleepAttemptsMs = 1000;

P8PLATFORM::CLockObject lock(m_mutex); // only process one request at a time

int code;
std::vector<CStdString> reponses;
std::vector<std::string> reponses;

int cntAttempts = 1;
while (cntAttempts <= maxAttempts)
Expand All @@ -617,10 +617,10 @@ std::vector<CStdString> Socket::GetVector(const CStdString &request, bool allowR
XBMC->Log(LOG_INFO, "Socket::GetVector> Sending WOL packet to %s", g_strServerMAC.c_str());
if (g_BackendOnline != BACKEND_UNKNOWN)
{
CStdString infoStr = XBMC->GetLocalizedString(30026);
std::string infoStr = XBMC->GetLocalizedString(30026);
XBMC->QueueNotification(QUEUE_INFO, infoStr.c_str()); // Notify WOL is being sent
}
XBMC->WakeOnLan(g_strServerMAC); // Send WOL request
XBMC->WakeOnLan(g_strServerMAC.c_str()); // Send WOL request
}

if (!connect(_serverName, (unsigned short)_port)) // if this fails, it is likely due to server down
Expand Down Expand Up @@ -671,32 +671,28 @@ std::vector<CStdString> Socket::GetVector(const CStdString &request, bool allowR
return reponses; // return responses
}

CStdString Socket::GetString(const CStdString &request, bool allowRetry, bool allowWOL /* = true*/)
std::string Socket::GetString(const std::string &request, bool allowRetry, bool allowWOL /* = true*/)
{
std::vector<CStdString> result = GetVector(request, allowRetry, allowWOL);
std::vector<std::string> result = GetVector(request, allowRetry, allowWOL);
return result[0];
}

bool Socket::GetBool(const CStdString &request, bool allowRetry, bool allowWOL /* = true*/)
bool Socket::GetBool(const std::string &request, bool allowRetry, bool allowWOL /* = true*/)
{
return GetString(request, allowRetry, allowWOL) == "True";
}


int Socket::GetInt(const CStdString &request, bool allowRetry, bool allowWOL /* = true*/)
int Socket::GetInt(const std::string &request, bool allowRetry, bool allowWOL /* = true*/)
{
CStdString valStr = GetString(request, allowRetry, allowWOL);
long val = strtol(valStr, 0, 10);
std::string valStr = GetString(request, allowRetry, allowWOL);
long val = strtol(valStr.c_str(), 0, 10);
return val;
}

long long Socket::GetLL(const CStdString &request, bool allowRetry, bool allowWOL /* = true*/)
long long Socket::GetLL(const std::string &request, bool allowRetry, bool allowWOL /* = true*/)
{
CStdString valStr = GetString(request, allowRetry, allowWOL);
#ifdef TARGET_WINDOWS
long long val = _strtoi64(valStr, 0, 10);
#else
long long val = strtoll(valStr, NULL, 10);
#endif
std::string valStr = GetString(request, allowRetry, allowWOL);
long long val = strtoll(valStr.c_str(), NULL, 10);
return val;
}
28 changes: 14 additions & 14 deletions src/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Socket
_sockaddr.sin_port = htons ( port );
};

bool setHostname ( const CStdString& host );
bool setHostname ( const std::string& host );

// Server initialization

Expand All @@ -205,7 +205,7 @@ class Socket
//bool accept ( Socket& socket ) const;

// Client initialization
bool connect ( const CStdString& host, const unsigned short port );
bool connect ( const std::string& host, const unsigned short port );

bool reconnect();

Expand All @@ -217,7 +217,7 @@ class Socket
* \param data Reference to a std::string with the data to transmit
* \return Number of bytes send or -1 in case of an error
*/
int send ( const CStdString& data );
int send ( const std::string& data );

/*!
* Socket send function
Expand All @@ -230,7 +230,7 @@ class Socket

bool set_non_blocking ( const bool );

bool ReadResponses(int &code, std::vector<CStdString> &lines);
bool ReadResponses(int &code, std::vector<std::string> &lines);

bool is_valid() const;

Expand All @@ -256,19 +256,19 @@ class Socket

// client interface
private:
CStdString _serverName;
CStdString _clientName;
std::string _serverName;
std::string _clientName;
int _port;
int SendRequest(CStdString requestStr);
int SendRequest(std::string requestStr);
public:
void SetServerName(CStdString strServerName);
void SetClientName(CStdString strClientName);
void SetServerName(std::string strServerName);
void SetClientName(std::string strClientName);
void SetServerPort(int port);
std::vector<CStdString> GetVector(const CStdString &request, bool allowRetry, bool allowWOL = true);
CStdString GetString(const CStdString &request, bool allowRetry, bool allowWOL = true);
bool GetBool(const CStdString &request, bool allowRetry, bool allowWOL = true);
int GetInt(const CStdString &request, bool allowRetry, bool allowWOL = true);
long long GetLL(const CStdString &request, bool allowRetry, bool allowWOL = true);
std::vector<std::string> GetVector(const std::string &request, bool allowRetry, bool allowWOL = true);
std::string GetString(const std::string &request, bool allowRetry, bool allowWOL = true);
bool GetBool(const std::string &request, bool allowRetry, bool allowWOL = true);
int GetInt(const std::string &request, bool allowRetry, bool allowWOL = true);
long long GetLL(const std::string &request, bool allowRetry, bool allowWOL = true);

void SetTimeOut(int tSec);
};
Expand Down
Loading

0 comments on commit 7e2cb4b

Please sign in to comment.