From 132a258a82b744489d1aff24a1e8770fe487043e Mon Sep 17 00:00:00 2001 From: Baldomo Date: Mon, 28 Dec 2020 01:15:49 +0100 Subject: [PATCH] Minor code refactor, code is more consistent --- src/ipc.hpp | 28 ++++++++++++++-------------- src/options.hpp | 4 ++-- src/url.hpp | 16 +++++++++------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/ipc.hpp b/src/ipc.hpp index 408e085..ea0fced 100644 --- a/src/ipc.hpp +++ b/src/ipc.hpp @@ -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; } diff --git a/src/options.hpp b/src/options.hpp index 082709b..47634d8 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -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"; diff --git a/src/url.hpp b/src/url.hpp index 996b918..ffc849e 100644 --- a/src/url.hpp +++ b/src/url.hpp @@ -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 == '%') {