Browse Source

Added proxy support #1

master 0.7.0
tastytea 3 years ago
parent
commit
575fb5b4e2
Signed by: tastytea GPG Key ID: 59346E0EA35C67E5
  1. 2
      CMakeLists.txt
  2. 11
      README.md
  3. 4
      src/expandurl-mastodon.hpp
  4. 23
      src/masto.cpp

2
CMakeLists.txt

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.6.5
VERSION 0.7.0
LANGUAGES CXX
)

11
README.md

@ -25,7 +25,7 @@ or to [@tastytea@soc.ialis.me](https://soc.ialis.me/@tastytea).
* C++ compiler (tested: gcc 6.4)
* [cmake](https://cmake.org/) (tested: 3.9.6)
* [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)
## Get sourcecode
@ -59,9 +59,16 @@ and an access token is generated. The config file can be found in
{
"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
daemon.

4
src/expandurl-mastodon.hpp

@ -94,10 +94,14 @@ private:
bool _running;
Json::Value _config;
const string _configfilepath;
string _proxy;
string _proxy_user;
string _proxy_password;
const bool read_config();
const bool write_config();
const bool register_app();
const void set_proxy(Easy &masto);
};
#endif // EXPANDURL_MASTODON_HPP

23
src/masto.cpp

@ -34,6 +34,9 @@ Listener::Listener()
, _running(false)
, _configfilepath(static_cast<const string>(getenv("HOME")) +
"/.config/expandurl-mastodon.json")
, _proxy("")
, _proxy_user("")
, _proxy_password("")
{
if (read_config())
@ -41,6 +44,7 @@ Listener::Listener()
_masto = std::make_unique<Easy>(_instance, _access_token);
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
global::version);
set_proxy(*_masto);
}
else
{
@ -85,6 +89,9 @@ const bool Listener::read_config()
_instance = _config["account"].asString();
_instance = _instance.substr(_instance.find('@') + 1);
_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;
}
@ -115,6 +122,7 @@ const void Listener::start()
Easy masto(_instance, _access_token);
masto.set_useragent(static_cast<const string>("expandurl-mastodon/") +
global::version);
set_proxy(masto);
ret = masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr);
syslog(LOG_DEBUG, "Connection lost.");
if (ret != 0 && ret != 14) // 14 means canceled by user
@ -372,3 +380,18 @@ const bool Listener::register_app()
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…
Cancel
Save