#2018-010, parseCpp method added

This commit is contained in:
avujic 2018-03-27 21:31:25 +02:00
parent 70a7863897
commit 0e11379e69
3 changed files with 48 additions and 11 deletions

View file

@ -25,16 +25,11 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include "net/Url.h"
#ifdef _MSC_VER
# define strncasecmp(x,y,z) _strnicmp(x,y,z)
#endif
Url::Url() :
m_keepAlive(false),
m_nicehash(false),
@ -87,7 +82,12 @@ Url::~Url()
free(m_user);
}
/*---------------------------------------------------------------------
* NAME : bool Url::parse(const char *url)
* SYNOPSIS : Parse URL string, xmrig original version
* DESCRIPTION:
*
---------------------------------------------------------------------*/
bool Url::parse(const char *url)
{
const char *p = strstr(url, "://");
@ -120,6 +120,37 @@ bool Url::parse(const char *url)
return true;
}
/*---------------------------------------------------------------------
* NAME : bool Url::parseCpp(const char *url)
* SYNOPSIS : Parse url string, C++ version
* DESCRIPTION:
*
---------------------------------------------------------------------*/
bool Url::parseCpp(const char *url)
{
std::stringstream strStream;
std::string strURL;
std::size_t found, il, ir;
//---
strStream << url;
strStream >> strURL;
found = strURL.find("//");
if (found == std::string::npos) il = 0;
else il = found + 2;
found = strURL.rfind(":");
if (found == std::string::npos) return(false);
else ir = found;
m_host_cpp.assign( strURL.substr(il, ir-il) );
m_port = std::stoi( strURL.substr( ir+1, strURL.length() - ir) );
//---
return(true);
}
bool Url::setUserpass(const char *userpass)
{

View file

@ -51,6 +51,7 @@ public:
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
bool parse(const char *url);
bool parseCpp(const char *url); //C++ version of parse
bool setUserpass(const char *userpass);
void applyExceptions();
void setPassword(const char *password);
@ -64,6 +65,11 @@ private:
char *m_host;
char *m_password;
char *m_user;
//---
std::string m_host_cpp;
std::string m_password_cpp;
std::string m_user_cpp;
//---
uint16_t m_port;
};