Minor code refactor, code is more consistent
This commit is contained in:
28
src/ipc.hpp
28
src/ipc.hpp
@@ -24,16 +24,24 @@ class ipc {
|
|||||||
int socklen_;
|
int socklen_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ipc() : ipc(DEFAULT_SOCK){};
|
ipc() : ipc(DEFAULT_SOCK) {};
|
||||||
ipc(const char *sockpath);
|
|
||||||
~ipc();
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
bool send(string cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor for oim::ipc
|
|
||||||
*/
|
|
||||||
ipc::ipc(const char *sockpath) {
|
ipc::ipc(const char *sockpath) {
|
||||||
sockfd_ = socket(AF_UNIX, SOCK_STREAM, 0);
|
sockfd_ = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
sockaddress_.sun_family = AF_UNIX;
|
sockaddress_.sun_family = AF_UNIX;
|
||||||
@@ -43,14 +51,6 @@ ipc::ipc(const char *sockpath) {
|
|||||||
connect(sockfd_, (const sockaddr *)&sockaddress_, socklen_);
|
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) {
|
bool ipc::send(string cmd) {
|
||||||
return write(sockfd_, cmd.c_str(), cmd.length()) != -1;
|
return write(sockfd_, cmd.c_str(), cmd.length()) != -1;
|
||||||
}
|
}
|
||||||
|
@@ -109,8 +109,8 @@ void options::parse(const char *url_s) {
|
|||||||
if (u.query().empty())
|
if (u.query().empty())
|
||||||
throw string("Empty query");
|
throw string("Empty query");
|
||||||
|
|
||||||
url_ = oim::url_decode(u.query_value("url"));
|
url_ = oim::percent_decode(u.query_value("url"));
|
||||||
flags_ = oim::url_decode(u.query_value("flags"));
|
flags_ = oim::percent_decode(u.query_value("flags"));
|
||||||
player_ = u.query_value("player", "mpv");
|
player_ = u.query_value("player", "mpv");
|
||||||
|
|
||||||
fullscreen_ = u.query_value("fullscreen") == "1";
|
fullscreen_ = u.query_value("fullscreen") == "1";
|
||||||
|
16
src/url.hpp
16
src/url.hpp
@@ -51,12 +51,7 @@ class url {
|
|||||||
url(const string &url_s);
|
url(const string &url_s);
|
||||||
|
|
||||||
/* Move constructor for oim::url */
|
/* Move constructor for oim::url */
|
||||||
url(url &&other) {
|
url(url &&other);
|
||||||
protocol_ = std::move(other.protocol_);
|
|
||||||
host_ = std::move(other.host_);
|
|
||||||
path_ = std::move(other.path_);
|
|
||||||
query_ = std::move(other.query_);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Accessor for the URL's protocol string */
|
/* Accessor for the URL's protocol string */
|
||||||
string protocol() { return protocol_; }
|
string protocol() { return protocol_; }
|
||||||
@@ -109,6 +104,13 @@ url::url(const string &url_s) {
|
|||||||
query_.assign(query_i, url_s.end());
|
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) {
|
string url::query_value(string key) {
|
||||||
// Find the beginning of the last occurrence of `key` in `query`
|
// Find the beginning of the last occurrence of `key` in `query`
|
||||||
auto pos = query_.rfind(key + "=");
|
auto pos = query_.rfind(key + "=");
|
||||||
@@ -137,7 +139,7 @@ string url::query_value(string key, string fallback) {
|
|||||||
/*
|
/*
|
||||||
* Percent-decodes a URL
|
* Percent-decodes a URL
|
||||||
*/
|
*/
|
||||||
string url_decode(const string encoded) {
|
string percent_decode(const string encoded) {
|
||||||
string ret = "";
|
string ret = "";
|
||||||
for (auto i = encoded.begin(); i < encoded.end(); i++) {
|
for (auto i = encoded.begin(); i < encoded.end(); i++) {
|
||||||
if (*i == '%') {
|
if (*i == '%') {
|
||||||
|
Reference in New Issue
Block a user