-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -41,6 +41,7 @@ Url::Url() : | |
m_host(nullptr), | ||
m_password(nullptr), | ||
m_user(nullptr), | ||
m_url(nullptr), | ||
m_port(kDefaultPort) | ||
{ | ||
} | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -85,6 +88,10 @@ Url::~Url() | |
free(m_host); | ||
free(m_password); | ||
free(m_user); | ||
|
||
if (m_url) { | ||
delete [] m_url; | ||
} | ||
} | ||
|
||
|
||
|
@@ -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()) { | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -64,6 +66,7 @@ class Url | |
char *m_host; | ||
char *m_password; | ||
char *m_user; | ||
mutable char *m_url; | ||
uint16_t m_port; | ||
}; | ||
|
||
|