Skip to content

Commit

Permalink
#51 Fixed config writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
xmrig committed Mar 1, 2018
1 parent 49973cc commit a089f26
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool Options::save()
doc.AddMember("background", m_background, allocator);
doc.AddMember("colors", m_colors, allocator);
doc.AddMember("donate-level", m_donateLevel, allocator);
doc.AddMember("log-file", m_logFile ? rapidjson::Value(rapidjson::StringRef(algoName())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
doc.AddMember("log-file", m_logFile ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
doc.AddMember("print-time", m_printTime, allocator);
doc.AddMember("retries", m_retries, allocator);
doc.AddMember("retry-pause", m_retryPause, allocator);
Expand Down Expand Up @@ -258,13 +258,10 @@ bool Options::save()
}

rapidjson::Value pools(rapidjson::kArrayType);
char tmp[256];

for (const Url *url : m_pools) {
rapidjson::Value obj(rapidjson::kObjectType);
snprintf(tmp, sizeof(tmp) - 1, "%s:%d", url->host(), url->port());

obj.AddMember("url", rapidjson::StringRef(tmp), allocator);
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
obj.AddMember("keepalive", url->isKeepAlive(), allocator);
Expand Down
36 changes: 35 additions & 1 deletion src/net/Url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2016-2017 XMRig <[email protected]>
* Copyright 2016-2018 XMRig <[email protected]>
*
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -41,6 +41,7 @@ Url::Url() :
m_host(nullptr),
m_password(nullptr),
m_user(nullptr),
m_url(nullptr),
m_port(kDefaultPort)
{
}
Expand All @@ -63,6 +64,7 @@ Url::Url(const char *url) :
m_host(nullptr),
m_password(nullptr),
m_user(nullptr),
m_url(nullptr),
m_port(kDefaultPort)
{
parse(url);
Expand All @@ -74,6 +76,7 @@ Url::Url(const char *host, uint16_t port, const char *user, const char *password
m_nicehash(nicehash),
m_password(password ? strdup(password) : nullptr),
m_user(user ? strdup(user) : nullptr),
m_url(nullptr),
m_port(port)
{
m_host = strdup(host);
Expand All @@ -85,6 +88,10 @@ Url::~Url()
free(m_host);
free(m_password);
free(m_user);

if (m_url) {
delete [] m_url;
}
}


Expand Down Expand Up @@ -139,6 +146,19 @@ bool Url::setUserpass(const char *userpass)
}


const char *Url::url() const
{
if (!m_url) {
const size_t size = strlen(m_host) + 8;
m_url = new char[size];

snprintf(m_url, size - 1, "%s:%d", m_host, m_port);
}

return m_url;
}


void Url::applyExceptions()
{
if (!isValid()) {
Expand Down Expand Up @@ -178,6 +198,20 @@ void Url::setUser(const char *user)
}


bool Url::operator==(const Url &other) const
{
if (m_port != other.m_port || m_keepAlive != other.m_keepAlive || m_nicehash != other.m_nicehash) {
return false;
}

if (strcmp(host(), other.host()) != 0 || strcmp(user(), other.user()) != 0 || strcmp(password(), other.password()) != 0) {
return false;
}

return true;
}


Url &Url::operator=(const Url *other)
{
m_keepAlive = other->m_keepAlive;
Expand Down
5 changes: 4 additions & 1 deletion src/net/Url.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2016-2017 XMRig <[email protected]>
* Copyright 2016-2018 XMRig <[email protected]>
*
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -52,10 +52,12 @@ class Url

bool parse(const char *url);
bool setUserpass(const char *userpass);
const char *url() const;
void applyExceptions();
void setPassword(const char *password);
void setUser(const char *user);

bool operator==(const Url &other) const;
Url &operator=(const Url *other);

private:
Expand All @@ -64,6 +66,7 @@ class Url
char *m_host;
char *m_password;
char *m_user;
mutable char *m_url;
uint16_t m_port;
};

Expand Down

0 comments on commit a089f26

Please sign in to comment.