Added proxy support #1
This commit is contained in:
parent
95c9eea3df
commit
575fb5b4e2
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (expandurl-mastodon
|
project (expandurl-mastodon
|
||||||
VERSION 0.6.5
|
VERSION 0.7.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
11
README.md
11
README.md
|
@ -25,7 +25,7 @@ or to [@tastytea@soc.ialis.me](https://soc.ialis.me/@tastytea).
|
||||||
* C++ compiler (tested: gcc 6.4)
|
* C++ compiler (tested: gcc 6.4)
|
||||||
* [cmake](https://cmake.org/) (tested: 3.9.6)
|
* [cmake](https://cmake.org/) (tested: 3.9.6)
|
||||||
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1)
|
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1)
|
||||||
* [mastodon-cpp](https://github.com/tastytea/mastodon-cpp) (at least: 0.13.1)
|
* [mastodon-cpp](https://github.com/tastytea/mastodon-cpp) (at least: 0.15.0)
|
||||||
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.4)
|
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.4)
|
||||||
|
|
||||||
## Get sourcecode
|
## Get sourcecode
|
||||||
|
@ -59,9 +59,16 @@ and an access token is generated. The config file can be found in
|
||||||
|
|
||||||
{
|
{
|
||||||
"account": "expandurl@example.social",
|
"account": "expandurl@example.social",
|
||||||
"access_token": "abc123"
|
"access_token": "abc123",
|
||||||
|
"proxy":
|
||||||
|
{
|
||||||
|
"url": "socks5h://[::1]:1080/",
|
||||||
|
"user": "user23",
|
||||||
|
"password": "supersecure"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
If you want to use a proxy, you have to edit the configuration file manually.
|
||||||
After the configuration file is generated, you can start expandurl-mastodon as
|
After the configuration file is generated, you can start expandurl-mastodon as
|
||||||
daemon.
|
daemon.
|
||||||
|
|
||||||
|
|
|
@ -94,10 +94,14 @@ private:
|
||||||
bool _running;
|
bool _running;
|
||||||
Json::Value _config;
|
Json::Value _config;
|
||||||
const string _configfilepath;
|
const string _configfilepath;
|
||||||
|
string _proxy;
|
||||||
|
string _proxy_user;
|
||||||
|
string _proxy_password;
|
||||||
|
|
||||||
const bool read_config();
|
const bool read_config();
|
||||||
const bool write_config();
|
const bool write_config();
|
||||||
const bool register_app();
|
const bool register_app();
|
||||||
|
const void set_proxy(Easy &masto);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXPANDURL_MASTODON_HPP
|
#endif // EXPANDURL_MASTODON_HPP
|
||||||
|
|
|
@ -34,6 +34,9 @@ Listener::Listener()
|
||||||
, _running(false)
|
, _running(false)
|
||||||
, _configfilepath(static_cast<const string>(getenv("HOME")) +
|
, _configfilepath(static_cast<const string>(getenv("HOME")) +
|
||||||
"/.config/expandurl-mastodon.json")
|
"/.config/expandurl-mastodon.json")
|
||||||
|
, _proxy("")
|
||||||
|
, _proxy_user("")
|
||||||
|
, _proxy_password("")
|
||||||
{
|
{
|
||||||
|
|
||||||
if (read_config())
|
if (read_config())
|
||||||
|
@ -41,6 +44,7 @@ Listener::Listener()
|
||||||
_masto = std::make_unique<Easy>(_instance, _access_token);
|
_masto = std::make_unique<Easy>(_instance, _access_token);
|
||||||
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
||||||
global::version);
|
global::version);
|
||||||
|
set_proxy(*_masto);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -85,6 +89,9 @@ const bool Listener::read_config()
|
||||||
_instance = _config["account"].asString();
|
_instance = _config["account"].asString();
|
||||||
_instance = _instance.substr(_instance.find('@') + 1);
|
_instance = _instance.substr(_instance.find('@') + 1);
|
||||||
_access_token = _config["access_token"].asString();
|
_access_token = _config["access_token"].asString();
|
||||||
|
_proxy = _config["proxy"]["url"].asString();
|
||||||
|
_proxy_user = _config["proxy"]["user"].asString();
|
||||||
|
_proxy_password = _config["proxy"]["password"].asString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +122,7 @@ const void Listener::start()
|
||||||
Easy masto(_instance, _access_token);
|
Easy masto(_instance, _access_token);
|
||||||
masto.set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
masto.set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
||||||
global::version);
|
global::version);
|
||||||
|
set_proxy(masto);
|
||||||
ret = masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr);
|
ret = masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr);
|
||||||
syslog(LOG_DEBUG, "Connection lost.");
|
syslog(LOG_DEBUG, "Connection lost.");
|
||||||
if (ret != 0 && ret != 14) // 14 means canceled by user
|
if (ret != 0 && ret != 14) // 14 means canceled by user
|
||||||
|
@ -372,3 +380,18 @@ const bool Listener::register_app()
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const void Listener::set_proxy(Mastodon::Easy &masto)
|
||||||
|
{
|
||||||
|
if (!_proxy.empty())
|
||||||
|
{
|
||||||
|
if (!_proxy_user.empty())
|
||||||
|
{
|
||||||
|
masto.set_proxy(_proxy, _proxy_user + ':' + _proxy_password);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
masto.set_proxy(_proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user