Minor code refactor, code is more consistent

This commit is contained in:
Baldomo
2020-12-28 01:15:49 +01:00
parent 99b9474f3b
commit 132a258a82
3 changed files with 25 additions and 23 deletions

View File

@@ -24,16 +24,24 @@ class ipc {
int socklen_;
public:
ipc() : ipc(DEFAULT_SOCK){};
ipc(const char *sockpath);
~ipc();
ipc() : ipc(DEFAULT_SOCK) {};
/*
* Constructor for oim::ipc
*/
ipc(const char *sockpath);
/*
* Destructor for oim::ipc
*/
~ipc() { close(sockfd_); };
/*
* Sends a raw command string to the internal socket at DEFAULT_SOCK
*/
bool send(string cmd);
};
/*
* Constructor for oim::ipc
*/
ipc::ipc(const char *sockpath) {
sockfd_ = socket(AF_UNIX, SOCK_STREAM, 0);
sockaddress_.sun_family = AF_UNIX;
@@ -43,14 +51,6 @@ ipc::ipc(const char *sockpath) {
connect(sockfd_, (const sockaddr *)&sockaddress_, socklen_);
}
/*
* Destructor for oim::ipc
*/
ipc::~ipc() { close(sockfd_); }
/*
* Sends a raw command string to the internal socket at DEFAULT_SOCK
*/
bool ipc::send(string cmd) {
return write(sockfd_, cmd.c_str(), cmd.length()) != -1;
}

View File

@@ -109,8 +109,8 @@ void options::parse(const char *url_s) {
if (u.query().empty())
throw string("Empty query");
url_ = oim::url_decode(u.query_value("url"));
flags_ = oim::url_decode(u.query_value("flags"));
url_ = oim::percent_decode(u.query_value("url"));
flags_ = oim::percent_decode(u.query_value("flags"));
player_ = u.query_value("player", "mpv");
fullscreen_ = u.query_value("fullscreen") == "1";

View File

@@ -51,12 +51,7 @@ class url {
url(const string &url_s);
/* Move constructor for oim::url */
url(url &&other) {
protocol_ = std::move(other.protocol_);
host_ = std::move(other.host_);
path_ = std::move(other.path_);
query_ = std::move(other.query_);
};
url(url &&other);
/* Accessor for the URL's protocol string */
string protocol() { return protocol_; }
@@ -109,6 +104,13 @@ url::url(const string &url_s) {
query_.assign(query_i, url_s.end());
}
url::url(url &&other) {
protocol_ = std::move(other.protocol_);
host_ = std::move(other.host_);
path_ = std::move(other.path_);
query_ = std::move(other.query_);
}
string url::query_value(string key) {
// Find the beginning of the last occurrence of `key` in `query`
auto pos = query_.rfind(key + "=");
@@ -137,7 +139,7 @@ string url::query_value(string key, string fallback) {
/*
* Percent-decodes a URL
*/
string url_decode(const string encoded) {
string percent_decode(const string encoded) {
string ret = "";
for (auto i = encoded.begin(); i < encoded.end(); i++) {
if (*i == '%') {