Mercurial > irccd
changeset 111:1ed760f6e0c6
Irccd: new brace styles, #487
line wrap: on
line diff
--- a/irccd/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/irccd/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -95,12 +95,14 @@ result = parser::read(argc, argv, options); for (const auto &pair : result) { - if (pair.first == "--help") + if (pair.first == "--help") { usage(); // NOTREACHED + } - if (pair.first == "-v" || pair.first == "--verbose") + if (pair.first == "-v" || pair.first == "--verbose") { log::setVerbose(true); + } } } catch (const std::exception &ex) { log::warning() << sys::programName() << ": " << ex.what() << std::endl; @@ -108,7 +110,6 @@ } instance = std::make_unique<Irccd>(); - instance->load(Config{result}); instance->run();
--- a/lib/irccd/alias.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/alias.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -27,10 +27,11 @@ { assert(!value.empty()); - if ((m_isPlaceholder = std::regex_match(value, std::regex("^%\\d+$")))) + if ((m_isPlaceholder = std::regex_match(value, std::regex("^%\\d+$")))) { m_value = value.substr(1); - else + } else { m_value = std::move(value); + } } unsigned AliasArg::index() const noexcept @@ -49,10 +50,11 @@ std::ostream &operator<<(std::ostream &out, const AliasArg &arg) { - if (arg.m_isPlaceholder) + if (arg.m_isPlaceholder) { out << "%" << arg.m_value; - else + } else { out << arg.m_value; + } return out; }
--- a/lib/irccd/cmd-help.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-help.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -43,10 +43,11 @@ { auto it = irccdctl.commands().find(args.arg(0U)); - if (it == irccdctl.commands().end()) + if (it == irccdctl.commands().end()) { log::warning() << "there is no command named: " << args.arg(0U) << std::endl; - else + } else { log::warning() << it->second->usage() << std::flush; + } return nullptr; }
--- a/lib/irccd/cmd-plugin-list.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-plugin-list.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -42,8 +42,9 @@ json::Value response = RemoteCommand::exec(irccd, request); json::Value list = json::array({}); - for (const auto &plugin : irccd.plugins()) + for (const auto &plugin : irccd.plugins()) { list.append(plugin.first); + } response.insert("list", std::move(list)); @@ -60,8 +61,9 @@ { RemoteCommand::result(irccdctl, object); - for (const auto &n : object.valueOr("list", json::Type::Array, json::array({}))) + for (const auto &n : object.valueOr("list", json::Type::Array, json::array({}))) { std::cout << n.toString() << std::endl; + } } } // !command
--- a/lib/irccd/cmd-server-connect.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-connect.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -33,10 +33,12 @@ { auto it = object.find("name"); - if (it == object.end()) + if (it == object.end()) { throw std::invalid_argument("missing 'name' property"); - if (!it->isString() || !util::isIdentifierValid(it->toString())) + } + if (!it->isString() || !util::isIdentifierValid(it->toString())) { throw std::invalid_argument("invalid server name"); + } return it->toString(); } @@ -45,10 +47,12 @@ { auto it = object.find("host"); - if (it == object.end()) + if (it == object.end()) { throw std::invalid_argument("missing 'host' property"); - if (!it->isString()) + } + if (!it->isString()) { throw std::invalid_argument("invalid host"); + } return it->toString(); } @@ -58,9 +62,11 @@ auto it = object.find("port"); uint16_t port = 6667; - if (it != object.end()) - if (it->isInt() && it->toInt() >= 0 && it->toInt() <= std::numeric_limits<std::uint16_t>::max()) + if (it != object.end()) { + if (it->isInt() && it->toInt() >= 0 && it->toInt() <= std::numeric_limits<std::uint16_t>::max()) { port = static_cast<std::uint16_t>(it->toInt()); + } + } return port; } @@ -83,8 +89,9 @@ throw std::invalid_argument("ssl is disabled"); #endif - if (object.valueOr("sslVerify", json::Type::Boolean, false).toBool()) + if (object.valueOr("sslVerify", json::Type::Boolean, false).toBool()) { info.flags |= ServerInfo::SslVerify; + } return info; } @@ -149,8 +156,9 @@ { auto server = std::make_shared<Server>(readInfo(request), readIdentity(request), readSettings(request)); - if (irccd.hasServer(server->info().name)) + if (irccd.hasServer(server->info().name)) { throw std::invalid_argument("server '" + server->info().name + "' already exists"); + } irccd.addServer(std::move(server));
--- a/lib/irccd/cmd-server-disconnect.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-disconnect.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -42,10 +42,11 @@ { auto it = request.find("server"); - if (it == request.end()) + if (it == request.end()) { irccd.clearServers(); - else + } else { irccd.removeServer(it->toString()); + } return RemoteCommand::exec(irccd, request); }
--- a/lib/irccd/cmd-server-info.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-info.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -63,18 +63,22 @@ response.insert("realname", server->identity().realname); /* Optional stuff */ - if (server->info().flags & irccd::ServerInfo::Ipv6) + if (server->info().flags & irccd::ServerInfo::Ipv6) { response.insert("ipv6", true); - if (server->info().flags & irccd::ServerInfo::Ssl) + } + if (server->info().flags & irccd::ServerInfo::Ssl) { response.insert("ssl", true); - if (server->info().flags & irccd::ServerInfo::SslVerify) + } + if (server->info().flags & irccd::ServerInfo::SslVerify) { response.insert("sslVerify", true); + } /* Channel list */ auto channels = json::array({}); - for (const auto &c : server->settings().channels) + for (const auto &c : server->settings().channels) { channels.append(c.name); + } response.insert("channels", std::move(channels)); @@ -97,8 +101,9 @@ /* Channels */ std::cout << "Channels : "; - for (const json::Value &v : response.valueOr("channels", json::Type::Array, json::array({}))) + for (const json::Value &v : response.valueOr("channels", json::Type::Array, json::array({}))) { std::cout << v.toString() << " "; + } std::cout << std::endl;
--- a/lib/irccd/cmd-server-join.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-join.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -49,8 +49,9 @@ { "channel", args.args()[1] } }); - if (args.length() == 3) + if (args.length() == 3) { req.insert("password", args.args()[2]); + } return req; }
--- a/lib/irccd/cmd-server-kick.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-kick.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -51,8 +51,9 @@ { "channel", args.arg(2) } }); - if (args.length() == 4) + if (args.length() == 4) { req.insert("reason", args.arg(3)); + } return req; }
--- a/lib/irccd/cmd-server-list.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-list.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -40,8 +40,9 @@ auto json = json::object({}); auto list = json::array({}); - for (const auto &pair : irccd.servers()) + for (const auto &pair : irccd.servers()) { list.append(pair.first); + } json.insert("list", std::move(list)); @@ -50,8 +51,9 @@ void ServerList::result(Irccdctl &, const json::Value &response) const { - for (const auto &n : response.valueOr("list", json::Type::Array, json::array({}))) + for (const auto &n : response.valueOr("list", json::Type::Array, json::array({}))) { std::cout << n.toString() << std::endl; + } } } // !command
--- a/lib/irccd/cmd-server-part.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-part.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -49,8 +49,9 @@ { "channel", args.arg(1) } }); - if (args.length() == 3) + if (args.length() == 3) { req.insert("reason", args.arg(2)); + } return req; }
--- a/lib/irccd/cmd-server-reconnect.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-server-reconnect.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -47,11 +47,13 @@ { auto server = request.find("server"); - if (server != request.end() && server->isString()) + if (server != request.end() && server->isString()) { irccd.requireServer(server->toString())->reconnect(); - else - for (auto &pair : irccd.servers()) + } else { + for (auto &pair : irccd.servers()) { pair.second->reconnect(); + } + } return nullptr; }
--- a/lib/irccd/cmd-watch.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/cmd-watch.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -212,8 +212,9 @@ { std::string format = request.optionOr("format", "native"); - if (format != "native" && format != "json") + if (format != "native" && format != "json") { throw std::invalid_argument("invalid format given: " + format); + } while (ctl.connection().isConnected()) { try { @@ -221,8 +222,9 @@ auto it = events.find(object.valueOr("event", "").toString()); /* Silently ignore to avoid breaking user output */ - if (it == events.end()) + if (it == events.end()) { continue; + } if (format == "json") { std::cout << object.toJson() << std::endl;
--- a/lib/irccd/command.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/command.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -35,15 +35,17 @@ oss << "usage: " << sys::programName() << " " << m_name; /* Options summary */ - if (options().size() > 0) + if (options().size() > 0) { oss << " [options...]"; + } /* Arguments summary */ if (args().size() > 0) { oss << " "; - for (const auto &arg : args()) + for (const auto &arg : args()) { oss << (arg.required() ? "" : "[") << arg.name() << (arg.required() ? "" : "]") << " "; + } } /* Description */ @@ -99,8 +101,9 @@ { auto it = response.find("error"); - if (it != response.end() && it->isString()) + if (it != response.end() && it->isString()) { log::warning() << "irccdctl: " << it->toString() << std::endl; + } } } // !irccd
--- a/lib/irccd/config.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/config.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -74,23 +74,27 @@ if (daemonize && sc != config.end()) { it = sc->find("foreground"); - if (it != sc->end()) + if (it != sc->end()) { daemonize = !util::isBoolean(it->value()); + } } - if (daemonize) + if (daemonize) { daemon(1, 0); + } #endif if (sc != config.end()) { try { #if defined(HAVE_SETGID) - if ((it = sc->find("gid")) != sc->end()) + if ((it = sc->find("gid")) != sc->end()) { sys::setGid(it->value()); + } #endif #if defined(HAVE_SETUID) - if ((it = sc->find("uid")) != sc->end()) + if ((it = sc->find("uid")) != sc->end()) { sys::setUid(it->value()); + } #endif } catch (const std::exception &ex) { log::warning() << "irccd: could not set " << it->key() << ": " << ex.what() << std::endl; @@ -113,10 +117,12 @@ ini::Section::const_iterator it; - if ((it = sc.find("path-logs")) != sc.end()) + if ((it = sc.find("path-logs")) != sc.end()) { normal = it->value(); - if ((it = sc.find("path-errors")) != sc.end()) + } + if ((it = sc.find("path-errors")) != sc.end()) { errors = it->value(); + } log::setInterface(make_unique<log::File>(move(normal), move(errors))); } @@ -134,21 +140,24 @@ { ini::Document::const_iterator sc = config.find("logs"); - if (sc == config.end()) + if (sc == config.end()) { return; + } ini::Section::const_iterator it; - if ((it = sc->find("verbose")) != sc->end() && m_options.count("-v") == 0 && m_options.count("--verbose")) + if ((it = sc->find("verbose")) != sc->end() && m_options.count("-v") == 0 && m_options.count("--verbose")) { log::setVerbose(util::isBoolean(it->value())); + } if ((it = sc->find("type")) != sc->end()) { /* Console is the default, no test case */ - if (it->value() == "file") + if (it->value() == "file") { loadLogFile(*sc); - else if (it->value() == "syslog") + } else if (it->value() == "syslog") { loadLogSyslog(); - else + } else { log::warning() << "irccd: unknown log type: " << it->value() << std::endl; + } } } @@ -157,10 +166,11 @@ #if defined(WITH_JS) for (const ini::Option &option : sc) { try { - if (option.value().empty()) + if (option.value().empty()) { irccd.loadPlugin(option.key(), option.key(), true); - else + } else { irccd.loadPlugin(option.key(), option.value(), false); + } } catch (const std::exception &ex) { log::warning() << "plugin " << option.key() << ": " << ex.what() << std::endl; } @@ -176,8 +186,9 @@ #if defined(WITH_JS) PluginConfig config; - for (const ini::Option &option : sc) + for (const ini::Option &option : sc) { config.emplace(option.key(), option.value()); + } irccd.addPluginConfig(std::move(name), std::move(config)); #else @@ -197,14 +208,17 @@ * Load plugin configurations before we load plugins since we use them * when we load the plugin itself. */ - for (const ini::Section §ion : config) - if (regex_match(section.key(), match, regex)) + for (const ini::Section §ion : config) { + if (regex_match(section.key(), match, regex)) { loadPluginConfig(irccd, section, match[1]); + } + } ini::Document::const_iterator it = config.find("plugins"); - if (it != config.end()) + if (it != config.end()) { loadPlugins(irccd, *it); + } #else (void)irccd; (void)config; @@ -222,24 +236,27 @@ /* Name */ ini::Section::const_iterator it; - if ((it = sc.find("name")) == sc.end()) + if ((it = sc.find("name")) == sc.end()) { throw std::invalid_argument("server: missing name"); - else if (!util::isIdentifierValid(it->value())) + } else if (!util::isIdentifierValid(it->value())) { throw std::invalid_argument("server " + it->value() + ": name is not valid"); - else if (irccd.hasServer(it->value())) + } else if (irccd.hasServer(it->value())) { throw std::invalid_argument("server " + it->value() + ": already exists"); + } info.name = it->value(); /* Host */ - if ((it = sc.find("host")) == sc.end()) + if ((it = sc.find("host")) == sc.end()) { throw std::invalid_argument("server " + info.name + ": missing host"); + } info.host = it->value(); /* Optional identity */ - if ((it = sc.find("identity")) != sc.end()) + if ((it = sc.find("identity")) != sc.end()) { identity = irccd.findIdentity(it->value()); + } /* Optional port */ if ((it = sc.find("port")) != sc.end()) { @@ -251,33 +268,39 @@ } /* Optional password */ - if ((it = sc.find("password")) != sc.end()) + if ((it = sc.find("password")) != sc.end()) { info.password = it->value(); + } /* Optional flags */ - if ((it = sc.find("ipv6")) != sc.end() && util::isBoolean(it->value())) + if ((it = sc.find("ipv6")) != sc.end() && util::isBoolean(it->value())) { info.flags |= ServerInfo::Ipv6; - if ((it = sc.find("ssl")) != sc.end()) - if (util::isBoolean(it->value())) + } + if ((it = sc.find("ssl")) != sc.end()) { + if (util::isBoolean(it->value())) { #if defined(WITH_SSL) info.flags |= ServerInfo::Ssl; #else throw std::invalid_argument("server " + info.name + ": ssl is disabled"); #endif - - if ((it = sc.find("ssl-verify")) != sc.end()) - if (util::isBoolean(it->value())) + } + } + if ((it = sc.find("ssl-verify")) != sc.end()) { + if (util::isBoolean(it->value())) { #if defined(WITH_SSL) info.flags |= ServerInfo::SslVerify; #else throw std::invalid_argument("server " + info.name + ": ssl is disabled"); #endif - + } + } /* Options */ - if ((it = sc.find("auto-rejoin")) != sc.end() && util::isBoolean(it->value())) + if ((it = sc.find("auto-rejoin")) != sc.end() && util::isBoolean(it->value())) { settings.flags |= ServerSettings::AutoRejoin; - if ((it = sc.find("join-invite")) != sc.end() && util::isBoolean(it->value())) + } + if ((it = sc.find("join-invite")) != sc.end() && util::isBoolean(it->value())) { settings.flags |= ServerSettings::JoinInvite; + } /* Channels */ if ((it = sc.find("channels")) != sc.end()) { @@ -294,17 +317,21 @@ settings.channels.push_back(std::move(channel)); } } - if ((it = sc.find("command-char")) != sc.end()) + if ((it = sc.find("command-char")) != sc.end()) { settings.command = it->value(); + } /* Reconnect */ try { - if ((it = sc.find("reconnect-tries")) != sc.end()) + if ((it = sc.find("reconnect-tries")) != sc.end()) { settings.reconnect_tries = std::stoi(it->value()); - if ((it = sc.find("reconnect-timeout")) != sc.end()) + } + if ((it = sc.find("reconnect-timeout")) != sc.end()) { settings.reconnect_timeout = std::stoi(it->value()); - if ((it = sc.find("ping-timeout")) != sc.end()) + } + if ((it = sc.find("ping-timeout")) != sc.end()) { settings.ping_timeout = std::stoi(it->value()); + } } catch (const std::exception &) { throw std::invalid_argument("server " + info.name + ": invalid number for " + it->key() + ": " + it->value()); } @@ -339,14 +366,18 @@ identity.name = it->value(); /* Optional stuff */ - if ((it = sc.find("username")) != sc.end()) + if ((it = sc.find("username")) != sc.end()) { identity.username = it->value(); - if ((it = sc.find("realname")) != sc.end()) + } + if ((it = sc.find("realname")) != sc.end()) { identity.realname = it->value(); - if ((it = sc.find("nickname")) != sc.end()) + } + if ((it = sc.find("nickname")) != sc.end()) { identity.nickname = it->value(); - if ((it = sc.find("ctcp-version")) != sc.end()) + } + if ((it = sc.find("ctcp-version")) != sc.end()) { identity.ctcpversion = it->value(); + } log::debug() << "identity " << identity.name << ": "; log::debug() << "nickname=" << identity.nickname << ", username=" << identity.username << ", "; @@ -381,26 +412,33 @@ /* Get the sets */ ini::Section::const_iterator it; - if ((it = sc.find("servers")) != sc.end()) + if ((it = sc.find("servers")) != sc.end()) { servers = toSet(*it); - if ((it = sc.find("channels")) != sc.end()) + } + if ((it = sc.find("channels")) != sc.end()) { channels = toSet(*it); - if ((it = sc.find("origins")) != sc.end()) + } + if ((it = sc.find("origins")) != sc.end()) { origins = toSet(*it); - if ((it = sc.find("plugins")) != sc.end()) + } + if ((it = sc.find("plugins")) != sc.end()) { plugins = toSet(*it); - if ((it = sc.find("channels")) != sc.end()) + } + if ((it = sc.find("channels")) != sc.end()) { channels = toSet(*it); + } /* Get the action */ - if ((it = sc.find("action")) == sc.end()) + if ((it = sc.find("action")) == sc.end()) { throw std::invalid_argument("missing action parameter"); - if (it->value() == "drop") + } + if (it->value() == "drop") { action = RuleAction::Drop; - else if (it->value() == "accept") + } else if (it->value() == "accept") { action = RuleAction::Accept; - else + } else { throw std::invalid_argument("invalid action given: " + it->value()); + } irccd.addRule(Rule(move(servers), move(channels), move(origins), move(plugins), move(events), action)); } @@ -428,8 +466,9 @@ /* Port */ int port; - if ((it = sc.find("port")) == sc.end()) + if ((it = sc.find("port")) == sc.end()) { throw invalid_argument("missing port"); + } try { port = stoi(it->value()); @@ -440,8 +479,9 @@ /* Address*/ std::string address = "*"; - if ((it = sc.find("address")) != sc.end()) + if ((it = sc.find("address")) != sc.end()) { address = it->value(); + } /* Domain */ if ((it = sc.find("domain")) != sc.end()) { @@ -449,19 +489,22 @@ ipv4 = false; for (const string &v : *it) { - if (v == "ipv4") + if (v == "ipv4") { ipv4 = true; - if (v == "ipv6") + } + if (v == "ipv6") { ipv6 = true; + } } } - if (ipv6) + if (ipv6) { irccd.addTransport(std::make_shared<TransportServerIp>(AF_INET6, move(address), port, !ipv4)); - else if (ipv4) + } else if (ipv4) { irccd.addTransport(std::make_shared<TransportServerIp>(AF_INET, move(address), port)); - else + } else { throw std::invalid_argument("domain must at least have ipv4 or ipv6"); + } } void Config::loadTransportUnix(Irccd &irccd, const ini::Section &sc) const @@ -492,14 +535,15 @@ try { ini::Section::const_iterator it = sc.find("type"); - if (it == sc.end()) + if (it == sc.end()) { log::warning() << "transport: missing type parameter" << std::endl; - else if (it->value() == "ip") + } else if (it->value() == "ip") { loadTransportIp(irccd, sc); - else if (it->value() == "unix") + } else if (it->value() == "unix") { loadTransportUnix(irccd, sc); - else + } else { log::warning() << "transport: invalid type given: " << std::endl; + } } catch (const net::Error &error) { log::warning() << "transport: " << error.function() << ": " << error.what() << std::endl; } catch (const exception &ex) { @@ -545,11 +589,11 @@ auto it = m_options.find("-c"); auto found = false; - if (it != m_options.end()) + if (it != m_options.end()) { found = openConfig(irccd, it->second); - else if ((it = m_options.find("--config")) != m_options.end()) + } else if ((it = m_options.find("--config")) != m_options.end()) { found = openConfig(irccd, it->second); - else { + } else { /* Search for a configuration file */ for (const string &path : path::list(path::PathConfig)) { string fullpath = path + "irccd.conf";
--- a/lib/irccd/connection.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/connection.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -28,8 +28,9 @@ while (isConnected()) { json::Value object = next(clamp(timeout)); - if (object.isObject() && object["response"].toString() == name) + if (object.isObject() && object["response"].toString() == name) { return object; + } } throw std::runtime_error("connection lost"); @@ -40,8 +41,9 @@ auto object = next(name, timeout); auto value = object.at("status").toString(); - if (!value.empty() && value != "ok") + if (!value.empty() && value != "ok") { throw std::runtime_error(object.at("error").toString()); + } } } // !irccd
--- a/lib/irccd/connection.hpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/connection.hpp Wed Apr 27 21:37:09 2016 +0200 @@ -205,8 +205,9 @@ } /* Timeout? */ - if (!msg.empty()) + if (!msg.empty()) { throw std::runtime_error("operation timed out while sending to irccd"); + } } template <typename Address> @@ -229,13 +230,15 @@ buffer = util::nextNetwork(m_input); } - if (!isConnected()) + if (!isConnected()) { throw std::runtime_error("connection lost"); + } json::Value value(json::Buffer{buffer}); - if (!value.isObject()) + if (!value.isObject()) { throw std::invalid_argument("invalid message received"); + } return value; }
--- a/lib/irccd/irccd.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/irccd.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -38,8 +38,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onChannelMode:\n"; log::debug() << " origin: " << origin << "\n"; @@ -72,8 +73,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onChannelNotice:\n"; log::debug() << " origin: " << origin << "\n"; @@ -104,8 +106,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onConnect" << std::endl; @@ -130,8 +133,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onInvite:\n"; log::debug() << " origin: " << origin << "\n"; @@ -161,8 +165,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onJoin:\n"; log::debug() << " origin: " << origin << "\n"; @@ -191,8 +196,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onKick:\n"; log::debug() << " origin: " << origin << "\n"; @@ -225,8 +231,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onMessage:\n"; log::debug() << " origin: " << origin << "\n"; @@ -262,8 +269,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onMe:\n"; log::debug() << " origin: " << origin << "\n"; @@ -294,8 +302,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onMode\n"; log::debug() << " origin: " << origin << "\n"; @@ -324,8 +333,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onNames:\n"; log::debug() << " channel: " << channel << "\n"; @@ -356,8 +366,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onNick:\n"; log::debug() << " origin: " << origin << "\n"; @@ -386,8 +397,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onNotice:\n"; log::debug() << " origin: " << origin << "\n"; @@ -416,8 +428,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onPart:\n"; log::debug() << " origin: " << origin << "\n"; @@ -448,8 +461,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onQuery:\n"; log::debug() << " origin: " << origin << "\n"; @@ -483,8 +497,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onTopic:\n"; log::debug() << " origin: " << origin << "\n"; @@ -515,8 +530,9 @@ { std::shared_ptr<Server> server = ptr.lock(); - if (!server) + if (!server) { return; + } log::debug() << "server " << server->info().name << ": event onWhois\n"; log::debug() << " nickname: " << whois.nick << "\n"; @@ -553,8 +569,9 @@ /* 0. Be sure the object still exists */ auto tc = ptr.lock(); - if (!tc) + if (!tc) { return; + } /* 1. Check if the Json object is valid */ auto name = object.find("command"); @@ -580,8 +597,9 @@ response = it->second->exec(*this, object); /* Adjust if command has returned something else */ - if (!response.isObject()) + if (!response.isObject()) { response = json::object({}); + } response.insert("status", true); } catch (const std::exception &ex) { @@ -604,8 +622,9 @@ auto tc = ptr.lock(); - if (tc) + if (tc) { m_lookupTransportClients.erase(tc->handle()); + } }); } @@ -622,15 +641,17 @@ void Irccd::processTransportClients(fd_set &input, fd_set &output) { - for (auto &pair : m_lookupTransportClients) + for (auto &pair : m_lookupTransportClients) { pair.second->sync(input, output); + } } void Irccd::processTransportServers(fd_set &input) { for (auto &pair : m_lookupTransportServers) { - if (!FD_ISSET(pair.second->handle(), &input)) + if (!FD_ISSET(pair.second->handle(), &input)) { continue; + } log::debug("transport: new client connected"); @@ -665,8 +686,9 @@ void Irccd::processServers(fd_set &input, fd_set &output) { - for (auto &pair : m_servers) + for (auto &pair : m_servers) { pair.second->sync(input, output); + } } void Irccd::process(fd_set &setinput, fd_set &setoutput) @@ -750,8 +772,9 @@ { auto it = m_servers.find(name); - if (it == m_servers.end()) + if (it == m_servers.end()) { return nullptr; + } return it->second; } @@ -760,8 +783,9 @@ { auto it = m_servers.find(name); - if (it == m_servers.end()) + if (it == m_servers.end()) { throw std::invalid_argument("server " + name + " not found"); + } return it->second; } @@ -778,8 +802,9 @@ void Irccd::clearServers() noexcept { - for (auto &pair : m_servers) + for (auto &pair : m_servers) { pair.second->disconnect(); + } m_servers.clear(); } @@ -803,8 +828,9 @@ { auto it = m_plugins.find(name); - if (it == m_plugins.end()) + if (it == m_plugins.end()) { return nullptr; + } return it->second; } @@ -813,8 +839,9 @@ { auto it = m_plugins.find(name); - if (it == m_plugins.end()) + if (it == m_plugins.end()) { throw std::out_of_range(std::string("plugin ") + name + " not found"); + } return it->second; } @@ -846,11 +873,13 @@ std::vector<string> paths; std::shared_ptr<Plugin> plugin; - if (find) - for (const std::string &dir : path::list(path::PathPlugins)) + if (find) { + for (const std::string &dir : path::list(path::PathPlugins)) { paths.push_back(dir + source + ".js"); - else + } + } else { paths.push_back(source); + } /* Iterate over all paths */ log::info(fmt::format("plugin {}: trying to load:", name)); @@ -866,18 +895,20 @@ } } - if (plugin) + if (plugin) { addPlugin(std::move(plugin)); - else + } else { throw std::runtime_error("no suitable plugin found"); + } } void Irccd::reloadPlugin(const std::string &name) { auto plugin = getPlugin(name); - if (plugin) + if (plugin) { plugin->onReload(); + } } void Irccd::unloadPlugin(const std::string &name) @@ -906,8 +937,9 @@ post([this, ptr, timer] (Irccd &) { auto plugin = ptr.lock(); - if (!plugin) + if (!plugin) { return; + } auto &ctx = plugin->context(); @@ -978,8 +1010,9 @@ } /* 4. Add transport servers */ - for (auto &pair : m_lookupTransportServers) + for (auto &pair : m_lookupTransportServers) { set(setinput, pair.first); + } /* 5. Do the selection */ struct timeval tv; @@ -990,8 +1023,9 @@ int error = select(max + 1, &setinput, &setoutput, nullptr, &tv); /* Skip anyway */ - if (!m_running) + if (!m_running) { return; + } /* Skip on error */ if (error < 0 && errno != EINTR) { @@ -1019,11 +1053,13 @@ m_events.clear(); } - if (copy.size() > 0) + if (copy.size() > 0) { log::debug() << "irccd: dispatching " << copy.size() << " event" << (copy.size() > 1 ? "s" : "") << endl; + } - for (auto &ev : copy) + for (auto &ev : copy) { ev(*this); + } } void Irccd::stop()
--- a/lib/irccd/irccd.hpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/irccd.hpp Wed Apr 27 21:37:09 2016 +0200 @@ -95,8 +95,6 @@ #endif -class ServerEvent; - /** * \class Irccd * \brief Irccd main instance
--- a/lib/irccd/irccdctl.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/irccdctl.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -127,16 +127,18 @@ /* host */ std::string host; - if ((it = sc.find("host")) == sc.end()) + if ((it = sc.find("host")) == sc.end()) { throw std::invalid_argument("missing host parameter"); + } host = it->value(); /* port */ int port; - if ((it = sc.find("port")) == sc.end()) + if ((it = sc.find("port")) == sc.end()) { throw std::invalid_argument("missing port parameter"); + } try { port = std::stoi(it->value()); @@ -148,12 +150,13 @@ Ip::Type domain{Ip::v4}; if ((it = sc.find("domain")) != sc.end()) { - if (it->value() == "ipv6") + if (it->value() == "ipv6") { domain = Ip::v6; - else if (it->value() == "ipv4") + } else if (it->value() == "ipv4") { domain = Ip::v4; - else + } else { throw std::invalid_argument("invalid domain: " + it->value()); + } } m_connection = std::make_unique<ConnectionBase<Ip>>(Ip{host, port, domain}); @@ -164,8 +167,9 @@ #if !defined(IRCCD_SYSTEM_WINDOWS) auto it = sc.find("path"); - if (it == sc.end()) + if (it == sc.end()) { throw std::invalid_argument("missing path parameter"); + } m_connection = std::make_unique<ConnectionBase<Local>>(Local{it->value(), false}); #else @@ -179,23 +183,26 @@ { auto it = sc.find("type"); - if (it == sc.end()) + if (it == sc.end()) { throw std::invalid_argument("missing type parameter"); + } - if (it->value() == "ip") + if (it->value() == "ip") { readConnectIp(sc); - else if (it->value() == "unix") + } else if (it->value() == "unix") { readConnectUnix(sc); - else + } else { throw std::invalid_argument("invalid type given: " + it->value()); + } } void Irccdctl::readGeneral(const ini::Section &sc) { auto verbose = sc.find("verbose"); - if (verbose != sc.end()) + if (verbose != sc.end()) { log::setVerbose(util::isBoolean(verbose->value())); + } } void Irccdctl::readAliases(const ini::Section &sc) @@ -204,16 +211,18 @@ /* This is the alias name */ Alias alias(option.key()); - if (m_commands.count(option.key()) > 0) + if (m_commands.count(option.key()) > 0) { throw std::invalid_argument("there is already a command named " + option.key()); + } /* Iterate over the list of commands to execute for this alias */ for (const std::string &repl : option) { /* This is the alias split string */ std::vector<std::string> list = util::split(repl, " \t"); - if (list.size() < 1) + if (list.size() < 1) { throw std::invalid_argument("alias require at least one argument"); + } /* First argument is the command/alias to execute */ std::string command = list[0]; @@ -221,8 +230,9 @@ /* This is the alias arguments */ std::vector<AliasArg> args; - for (auto it = list.begin() + 1; it != list.end(); ++it) + for (auto it = list.begin() + 1; it != list.end(); ++it) { args.push_back(std::move(*it)); + } alias.push_back({std::move(command), std::move(args)}); } @@ -244,12 +254,15 @@ ini::Document::const_iterator it = doc.find("connect"); /* Do not try to read [connect] if specified at command line */ - if (it != doc.end() && options.count("-t") == 0 && options.count("--type") == 0) + if (it != doc.end() && options.count("-t") == 0 && options.count("--type") == 0) { readConnect(*it); - if ((it = doc.find("general")) != doc.end()) + } + if ((it = doc.find("general")) != doc.end()) { readGeneral(*it); - if ((it = doc.find("alias")) != doc.end()) + } + if ((it = doc.find("alias")) != doc.end()) { readAliases(*it); + } } /* @@ -264,16 +277,18 @@ /* host (-h or --host) */ std::string host; - if ((it = options.find("-h")) == options.end() && (it = options.find("--host")) == options.end()) + if ((it = options.find("-h")) == options.end() && (it = options.find("--host")) == options.end()) { throw std::invalid_argument("missing host argument (-h or --host)"); + } host = it->second; /* port (-p or --port) */ int port; - if ((it = options.find("-p")) == options.end() && (it = options.find("--port")) == options.end()) + if ((it = options.find("-p")) == options.end() && (it = options.find("--port")) == options.end()) { throw std::invalid_argument("missing port argument (-p or --port)"); + } try { port = std::stoi(it->second); @@ -289,8 +304,9 @@ #if !defined(IRCCD_SYSTEM_WINDOWS) parser::Result::const_iterator it; - if ((it = options.find("-P")) == options.end() && (it = options.find("--path")) == options.end()) + if ((it = options.find("-P")) == options.end() && (it = options.find("--path")) == options.end()) { throw std::invalid_argument("missing path parameter (-P or --path)"); + } m_connection = std::make_unique<ConnectionBase<Local>>(Local{it->second, false}); #else @@ -306,12 +322,15 @@ auto it = options.find("-t"); - if (it == options.end()) + if (it == options.end()) { it = options.find("--type"); - if (it->second == "ip" || it->second == "ipv6") + } + if (it->second == "ip" || it->second == "ipv6") { return parseConnectIp(options, it->second == "ipv6"); - if (it->second == "unix") + } + if (it->second == "unix") { return parseConnectUnix(options); + } throw std::invalid_argument("invalid type given: " + it->second); } @@ -340,12 +359,14 @@ try { result = parser::read(argc, argv, def); - if (result.count("--help") != 0) + if (result.count("--help") != 0) { usage(); // NOTREACHED + } - if (result.count("-v") != 0 || result.count("--verbose") != 0) + if (result.count("-v") != 0 || result.count("--verbose") != 0) { log::setVerbose(true); + } } catch (const std::exception &ex) { log::warning("{}: {}"_format(sys::programName(), ex.what())); usage(); @@ -361,10 +382,12 @@ for (const auto &opt : cmd.options()) { /* parser::read needs '-' and '--' so add them */ - if (!opt.simpleKey().empty()) + if (!opt.simpleKey().empty()) { def.emplace("-"s + opt.simpleKey(), !opt.arg().empty()); - if (!opt.longKey().empty()) + } + if (!opt.longKey().empty()) { def.emplace("--"s + opt.longKey(), !opt.arg().empty()); + } } /* 2. Parse them, remove them from args (in parser::read) and build the map with id. */ @@ -380,16 +403,19 @@ } /* 3. Check number of arguments. */ - if (args.size() < cmd.min()) + if (args.size() < cmd.min()) { throw std::runtime_error("too few arguments"); - if (args.size() > cmd.max()) + } + if (args.size() > cmd.max()) { throw std::runtime_error("too many arguments"); + } /* 4. Construct the request, if the returned value is not an object, do not send anything (e.g. help). */ json::Value request = cmd.request(*this, RemoteCommandRequest(std::move(requestOptions), std::move(args))); - if (!request.isObject()) + if (!request.isObject()) { return; + } request.insert("command", cmd.name()); @@ -412,13 +438,15 @@ for (const AliasArg &arg : cmd.args()) { if (arg.isPlaceholder()) { - if (args.size() < arg.index() + 1) + if (args.size() < arg.index() + 1) { throw std::invalid_argument("missing argument for placeholder %" + std::to_string(arg.index())); + } cmdArgs.push_back(args[arg.index()]); - if (arg.index() + 1 > toremove) + if (arg.index() + 1 > toremove) { toremove = arg.index() + 1; + } } else { cmdArgs.push_back(arg.value()); } @@ -452,10 +480,11 @@ } else { auto cmd = m_commands.find(name); - if (cmd != m_commands.end()) + if (cmd != m_commands.end()) { exec(*cmd->second, args); - else + } else { throw std::invalid_argument("no alias or command named " + name); + } } } @@ -469,8 +498,9 @@ /* Get irccd information */ json::Value object = m_connection->next(30000); - if (!object.contains("program") || object.at("program").toString() != "irccd") + if (!object.contains("program") || object.at("program").toString() != "irccd") { throw std::runtime_error("not an irccd server"); + } /* Get values */ m_major = object.at("major").toInt(); @@ -499,8 +529,9 @@ * 3. From the configuration file searched through directories */ try { - if (result.count("-t") > 0 || result.count("--type") > 0) + if (result.count("-t") > 0 || result.count("--type") > 0) { parseConnect(result); + } auto it = result.find("-c"); @@ -510,8 +541,9 @@ for (const std::string &dir : path::list(path::PathConfig)) { std::string path = dir + "irccdctl.conf"; - if (fs::exists(path)) + if (fs::exists(path)) { read(path, result); + } } } } catch (const std::exception &ex) { @@ -537,8 +569,9 @@ /* Build a vector of arguments */ std::vector<std::string> args; - for (int i = 0; i < argc; ++i) + for (int i = 0; i < argc; ++i) { args.push_back(argv[i]); + } exec(args); }
--- a/lib/irccd/js-directory.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-directory.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -39,13 +39,15 @@ duk::push(ctx, duk::This{}); duk::getProperty<void>(ctx, -1, "path"); - if (duk::type(ctx, -1) != DUK_TYPE_STRING) + if (duk::type(ctx, -1) != DUK_TYPE_STRING) { duk::raise(ctx, duk::TypeError("invalid this binding")); + } std::string ret = duk::get<std::string>(ctx, -1); - if (ret.empty()) + if (ret.empty()) { duk::raise(ctx, duk::TypeError("invalid directory with empty path")); + } duk::pop(ctx, 2); @@ -71,20 +73,24 @@ */ auto entries = fs::readdir(base); - for (const auto &entry : entries) - if (entry.type != fs::Entry::Dir && pred(entry.name)) + for (const auto &entry : entries) { + if (entry.type != fs::Entry::Dir && pred(entry.name)) { return base + entry.name; + } + } - if (!recursive) + if (!recursive) { return ""; + } for (const auto &entry : entries) { if (entry.type == fs::Entry::Dir) { std::string next = base + entry.name + fs::separator(); std::string path = findPath(next, true, pred); - if (!path.empty()) + if (!path.empty()) { return path; + } } } @@ -139,14 +145,16 @@ duk::pop(ctx); - if (isRegex) + if (isRegex) { path = findRegex(base, duk::getProperty<std::string>(ctx, patternIndex, "source"), recursive); - else + } else { duk::raise(ctx, duk::TypeError("pattern must be a string or a regex expression")); + } } - if (path.empty()) + if (path.empty()) { return 0; + } duk::push(ctx, path); } catch (const std::exception &ex) { @@ -164,8 +172,9 @@ */ duk::Ret remove(duk::ContextPtr ctx, const std::string &path, bool recursive) { - if (!fs::isDirectory(path)) + if (!fs::isDirectory(path)) { duk::raise(ctx, SystemError(EINVAL, "not a directory")); + } if (!recursive) { #if defined(_WIN32) @@ -240,15 +249,17 @@ */ duk::Ret constructor(duk::ContextPtr ctx) { - if (!duk_is_constructor_call(ctx)) + if (!duk_is_constructor_call(ctx)) { return 0; + } try { std::string path = duk::require<std::string>(ctx, 0); std::int8_t flags = duk::optional<int>(ctx, 1, 0); - if (!fs::isDirectory(path)) + if (!fs::isDirectory(path)) { duk::raise(ctx, SystemError(EINVAL, "not a directory")); + } std::vector<fs::Entry> list = fs::readdir(path, flags);
--- a/lib/irccd/js-file.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-file.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -106,8 +106,9 @@ /* Remove trailing \r for CRLF line style */ inline std::string clearCr(std::string input) { - if (input.length() > 0 && input.back() == '\r') + if (input.length() > 0 && input.back() == '\r') { input.pop_back(); + } return input; } @@ -194,12 +195,14 @@ } /* Maybe an error in the stream */ - if (std::ferror(fp)) + if (std::ferror(fp)) { duk::raise(ctx, SystemError()); + } /* Missing '\n' in end of file */ - if (!buffer.empty()) + if (!buffer.empty()) { duk::putProperty(ctx, -1, i++, clearCr(buffer)); + } return 1; } @@ -222,8 +225,9 @@ auto amount = duk::optional<int>(ctx, 0, -1); auto file = duk::self<duk::Pointer<File>>(ctx); - if (amount == 0 || file->handle() == nullptr) + if (amount == 0 || file->handle() == nullptr) { return 0; + } try { std::string data; @@ -236,8 +240,9 @@ while (!std::feof(file->handle())) { nread = std::fread(&buffer[0], sizeof (buffer[0]), buffer.size(), file->handle()); - if (std::ferror(file->handle())) + if (std::ferror(file->handle())) { duk::raise(ctx, SystemError()); + } std::copy(buffer.begin(), buffer.begin() + nread, std::back_inserter(data)); total += nread; @@ -246,8 +251,9 @@ data.resize((std::size_t)amount); total = std::fread(&data[0], sizeof (data[0]), (std::size_t)amount, file->handle()); - if (std::ferror(file->handle())) + if (std::ferror(file->handle())) { duk::raise(ctx, SystemError()); + } data.resize(total); } @@ -276,14 +282,17 @@ std::FILE *fp = duk::self<duk::Pointer<File>>(ctx)->handle(); std::string result; - if (fp == nullptr || std::feof(fp)) + if (fp == nullptr || std::feof(fp)) { return 0; + } - for (int ch; (ch = std::fgetc(fp)) != EOF && ch != '\n'; ) + for (int ch; (ch = std::fgetc(fp)) != EOF && ch != '\n'; ) { result += (char)ch; + } - if (std::ferror(fp)) + if (std::ferror(fp)) { duk::raise(ctx, SystemError()); + } duk::push(ctx, clearCr(result)); @@ -301,8 +310,9 @@ */ duk::Ret methodRemove(duk::ContextPtr ctx) { - if (::remove(duk::self<duk::Pointer<File>>(ctx)->path().c_str()) < 0) + if (::remove(duk::self<duk::Pointer<File>>(ctx)->path().c_str()) < 0) { duk::raise(ctx, SystemError()); + } return 0; } @@ -325,8 +335,9 @@ auto amount = duk::require<int>(ctx, 1); auto fp = duk::self<duk::Pointer<File>>(ctx)->handle(); - if (fp != nullptr && std::fseek(fp, amount, type) != 0) + if (fp != nullptr && std::fseek(fp, amount, type) != 0) { duk::raise(ctx, SystemError()); + } return 0; } @@ -349,10 +360,11 @@ struct stat st; auto file = duk::self<duk::Pointer<File>>(ctx); - if (file->handle() == nullptr && ::stat(file->path().c_str(), &st) < 0) + if (file->handle() == nullptr && ::stat(file->path().c_str(), &st) < 0) { duk::raise(ctx, SystemError()); - else + } else { duk::push(ctx, st); + } return 1; } @@ -375,13 +387,15 @@ auto fp = duk::self<duk::Pointer<File>>(ctx)->handle(); long pos; - if (fp == nullptr) + if (fp == nullptr) { return 0; + } - if ((pos = std::ftell(fp)) == -1L) + if ((pos = std::ftell(fp)) == -1L) { duk::raise(ctx, SystemError()); - else + } else { duk::push(ctx, (int)pos); + } return 1; } @@ -404,13 +418,15 @@ std::FILE *fp = duk::self<duk::Pointer<File>>(ctx)->handle(); std::string data = duk::require<std::string>(ctx, 0); - if (fp == nullptr) + if (fp == nullptr) { return 0; + } std::size_t nwritten = std::fwrite(data.c_str(), 1, data.length(), fp); - if (std::ferror(fp)) + if (std::ferror(fp)) { duk::raise(ctx, SystemError()); + } duk::push(ctx, (int)nwritten); @@ -452,8 +468,9 @@ */ duk::Ret constructor(duk::ContextPtr ctx) { - if (!duk_is_constructor_call(ctx)) + if (!duk_is_constructor_call(ctx)) { return 0; + } std::string path = duk::require<std::string>(ctx, 0); std::string mode = duk::require<std::string>(ctx, 1); @@ -536,8 +553,9 @@ */ duk::Ret functionRemove(duk::ContextPtr ctx) { - if (::remove(duk::require<std::string>(ctx, 0).c_str()) < 0) + if (::remove(duk::require<std::string>(ctx, 0).c_str()) < 0) { duk::raise(ctx, SystemError()); + } return 0; } @@ -561,8 +579,9 @@ { struct stat st; - if (::stat(duk::require<std::string>(ctx, 0).c_str(), &st) < 0) + if (::stat(duk::require<std::string>(ctx, 0).c_str(), &st) < 0) { duk::raise(ctx, SystemError()); + } duk::push(ctx, st);
--- a/lib/irccd/js-plugin.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-plugin.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -94,8 +94,9 @@ duk::push(ctx, duk::Array{}); int i = 0; - for (const auto &pair : duk::getGlobal<duk::RawPointer<Irccd>>(ctx, "\xff""\xff""irccd")->plugins()) + for (const auto &pair : duk::getGlobal<duk::RawPointer<Irccd>>(ctx, "\xff""\xff""irccd")->plugins()) { duk::putProperty(ctx, -1, i++, pair.first); + } return 1; }
--- a/lib/irccd/js-server.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-server.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -93,8 +93,9 @@ duk::push(ctx, duk::Array{}); int i = 0; - for (const auto &channel : server->settings().channels) + for (const auto &channel : server->settings().channels) { duk::putProperty(ctx, -1, i++, channel.name); + } duk::putProperty(ctx, -2, "channels"); @@ -375,8 +376,9 @@ info.port = duk::optionalProperty<int>(ctx, 0, "port", (int)info.port); info.password = duk::optionalProperty<std::string>(ctx, 0, "password", ""); - if (duk::optionalProperty<bool>(ctx, 0, "ipv6", false)) + if (duk::optionalProperty<bool>(ctx, 0, "ipv6", false)) { info.flags |= ServerInfo::Ipv6; + } /* Identity part */ identity.nickname = duk::optionalProperty<std::string>(ctx, 0, "nickname", identity.nickname); @@ -385,16 +387,19 @@ identity.ctcpversion = duk::optionalProperty<std::string>(ctx, 0, "version", identity.ctcpversion); /* Settings part */ - for (const auto &chan: duk::getProperty<std::vector<std::string>>(ctx, 0, "channels")) + for (const auto &chan: duk::getProperty<std::vector<std::string>>(ctx, 0, "channels")) { settings.channels.push_back(Server::splitChannel(chan)); + } settings.reconnect_tries = duk::optionalProperty<int>(ctx, 0, "recoTries", (int)settings.reconnect_tries); settings.reconnect_timeout = duk::optionalProperty<int>(ctx, 0, "recoTimeout", (int)settings.reconnect_timeout); - if (duk::optionalProperty<bool>(ctx, 0, "joinInvite", false)) + if (duk::optionalProperty<bool>(ctx, 0, "joinInvite", false)) { settings.flags |= ServerSettings::JoinInvite; - if (duk::optionalProperty<bool>(ctx, 0, "autoRejoin", false)) + } + if (duk::optionalProperty<bool>(ctx, 0, "autoRejoin", false)) { settings.flags |= ServerSettings::AutoRejoin; + } try { duk::construct(ctx, duk::Shared<Server>{std::make_shared<Server>(std::move(info), std::move(identity), std::move(settings))}); @@ -418,8 +423,9 @@ { auto server = duk::get<duk::Shared<Server>>(ctx, 0); - if (server) + if (server) { duk::getGlobal<duk::RawPointer<Irccd>>(ctx, "\xff""\xff""irccd")->addServer(server); + } return 0; } @@ -462,8 +468,9 @@ { duk::push(ctx, duk::Object{}); - for (const auto &pair : duk::getGlobal<duk::RawPointer<Irccd>>(ctx, "\xff""\xff""irccd")->servers()) + for (const auto &pair : duk::getGlobal<duk::RawPointer<Irccd>>(ctx, "\xff""\xff""irccd")->servers()) { duk::putProperty(ctx, -1, pair.first, duk::Shared<Server>{pair.second}); + } return 1; }
--- a/lib/irccd/js-system.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-system.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -121,8 +121,9 @@ { auto fp = ::popen(duk::require<const char *>(ctx, 0), duk::require<const char *>(ctx, 1)); - if (fp == nullptr) + if (fp == nullptr) { duk::raise(ctx, SystemError{}); + } duk::push(ctx, duk::Pointer<File>{new File(fp, [] (std::FILE *fp) { ::pclose(fp); })});
--- a/lib/irccd/js-timer.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-timer.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -55,8 +55,9 @@ { auto timer = duk::self<duk::Shared<Timer>>(ctx); - if (!timer->isRunning()) + if (!timer->isRunning()) { timer->start(); + } return 0; } @@ -71,8 +72,9 @@ { auto timer = duk::self<duk::Shared<Timer>>(ctx); - if (timer->isRunning()) + if (timer->isRunning()) { timer->stop(); + } return 0; } @@ -98,8 +100,9 @@ int type = duk::require<int>(ctx, 0); int delay = duk::require<int>(ctx, 1); - if (!duk::is<duk::Function>(ctx, 2)) + if (!duk::is<duk::Function>(ctx, 2)) { duk::raise(ctx, duk::TypeError("missing callback function")); + } auto timer = std::make_shared<Timer>(static_cast<TimerType>(type), delay);
--- a/lib/irccd/js-util.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/js-util.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -43,14 +43,16 @@ { util::Substitution params; - if (!duk::is<Object>(ctx, index)) + if (!duk::is<Object>(ctx, index)) { return params; + } duk::enumerate(ctx, index, 0, true, [&] (ContextPtr) { - if (duk::get<std::string>(ctx, -2) == "date") + if (duk::get<std::string>(ctx, -2) == "date") { params.time = static_cast<time_t>(duk::get<double>(ctx, -1) / 1000); - else + } else { params.keywords.insert({duk::get<std::string>(ctx, -2), duk::get<std::string>(ctx, -1)}); + } }); return params;
--- a/lib/irccd/path.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/path.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -87,8 +87,9 @@ result.resize(size); - if (!(size = GetModuleFileNameA(nullptr, &result[0], size))) + if (!(size = GetModuleFileNameA(nullptr, &result[0], size))) { throw std::runtime_error("GetModuleFileName error"); + } result.resize(size); @@ -105,8 +106,9 @@ auto size = readlink("/proc/self/exe", &result[0], 2048); - if (size < 0) + if (size < 0) { throw std::invalid_argument(std::strerror(errno)); + } result.resize(size); @@ -123,8 +125,9 @@ result.resize(size); - if (sysctl(mib.data(), 4, &result[0], &size, nullptr, 0) < 0) + if (sysctl(mib.data(), 4, &result[0], &size, nullptr, 0) < 0) { throw std::runtime_error(std::strerror(errno)); + } result.resize(size); @@ -140,8 +143,9 @@ result.resize(size); - if ((size = proc_pidpath(getpid(), &result[0], size)) == 0) + if ((size = proc_pidpath(getpid(), &result[0], size)) == 0) { throw std::runtime_error(std::strerror(errno)); + } result.resize(size); @@ -245,8 +249,9 @@ } catch (const std::exception &) { const char *home = getenv("HOME"); - if (home != nullptr) + if (home != nullptr) { oss << home; + } oss << "/.config/irccd/"; } @@ -277,9 +282,9 @@ #if defined(IRCCD_SYSTEM_WINDOWS) char path[MAX_PATH]; - if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK) + if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK) { oss << ""; - else { + } else { oss << path; oss << "\\irccd\\share"; } @@ -292,8 +297,9 @@ } catch (const std::exception &) { const char *home = getenv("HOME"); - if (home != nullptr) + if (home != nullptr) { oss << home; + } oss << "/.local/share/irccd/"; } @@ -336,8 +342,9 @@ } catch (const std::exception &) { const char *home = getenv("HOME"); - if (home != nullptr) + if (home != nullptr) { oss << home; + } oss << "/.cache/irccd/"; } @@ -402,16 +409,18 @@ } /* Not found in PATH? add dummy value */ - if (base.empty()) + if (base.empty()) { base = std::string(".") + fs::separator() + WITH_BINDIR + fs::separator() + "dummy"; + } } } /* Find bin/<progname> */ auto pos = base.rfind(std::string(WITH_BINDIR) + fs::separator() + fs::baseName(base)); - if (pos != std::string::npos) + if (pos != std::string::npos) { base.erase(pos); + } /* Add trailing / or \\ for convenience */ base = clean(base); @@ -421,8 +430,9 @@ std::string clean(std::string input) { - if (input.empty()) + if (input.empty()) { return input; + } /* First, remove any duplicates */ input.erase(std::unique(input.begin(), input.end(), [&] (char c1, char c2) { @@ -431,8 +441,9 @@ /* Add a trailing / or \\ */ char c = input[input.length() - 1]; - if (c != '/' && c != '\\') + if (c != '/' && c != '\\') { input += fs::separator(); + } /* Now converts all / to \\ for Windows and the opposite for Unix */ #if defined(IRCCD_SYSTEM_WINDOWS)
--- a/lib/irccd/plugin.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/plugin.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -101,8 +101,9 @@ } /* Use the system as default */ - if (!found) + if (!found) { foundpath = path::clean(path::get(type, path::OwnerSystem) + append); + } duk::getGlobal<void>(m_context, "Irccd"); duk::getProperty<void>(m_context, -1, "Plugin"); @@ -139,8 +140,9 @@ duk::push(m_context, duk::Object{}); } - for (const auto &pair : config) + for (const auto &pair : config) { duk::putProperty(m_context, -1, pair.first, pair.second); + } duk::putProperty(m_context, -2, "config"); duk::pop(m_context, 2); @@ -160,8 +162,9 @@ #if defined(HAVE_STAT) struct stat st; - if (stat(m_info.path.c_str(), &st) < 0) + if (stat(m_info.path.c_str(), &st) < 0) { throw std::runtime_error(std::strerror(errno)); + } #endif /* @@ -172,10 +175,11 @@ * If path is absolute, the parent is the directory name, otherwise * we use the current working directory (needed for some tests). */ - if (fs::isAbsolute(m_info.path)) + if (fs::isAbsolute(m_info.path)) { m_info.parent = fs::dirName(m_info.path); - else + } else { m_info.parent = fs::cwd(); + } /* Load standard irccd API */ loadJsIrccd(m_context); @@ -194,8 +198,9 @@ putPaths(); /* Try to load the file (does not call onLoad yet) */ - if (duk::pevalFile(m_context, m_info.path) != 0) + if (duk::pevalFile(m_context, m_info.path) != 0) { throw duk::error(m_context, -1); + } duk::pop(m_context); @@ -223,8 +228,9 @@ Plugin::~Plugin() { - for (auto &timer : m_timers) + for (auto &timer : m_timers) { timer->stop(); + } } const PluginInfo &Plugin::info() const @@ -243,14 +249,16 @@ timer->onSignal.connect([this, ptr] () { auto timer = ptr.lock(); - if (timer) + if (timer) { onTimerSignal(move(timer)); + } }); timer->onEnd.connect([this, ptr] () { auto timer = ptr.lock(); - if (timer) + if (timer) { onTimerEnd(move(timer)); + } }); m_timers.insert(move(timer));
--- a/lib/irccd/rule.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/rule.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -76,8 +76,9 @@ << " events: " << util::join(rule.m_events.begin(), rule.m_events.end()) << "\n" << " action: " << ((rule.m_action == RuleAction::Accept) ? "accept" : "drop") << std::endl; - if (rule.match(server, channel, origin, plugin, event)) + if (rule.match(server, channel, origin, plugin, event)) { result = rule.action() == RuleAction::Accept; + } } return result; @@ -96,9 +97,11 @@ , m_events(std::move(events)) , m_action(action) { - for (const std::string &n : m_events) - if (validEvents.count(n) == 0) + for (const std::string &n : m_events) { + if (validEvents.count(n) == 0) { throw std::invalid_argument(n + " is not a valid event name"); + } + } } bool Rule::match(const std::string &server,
--- a/lib/irccd/server-event.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/server-event.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -53,10 +53,12 @@ } catch (const duk::ErrorInfo &info) { log::warning() << "plugin " << pair.second->info().name << ": error: " << info.what() << std::endl; - if (!info.fileName.empty()) + if (!info.fileName.empty()) { log::warning() << " " << info.fileName << ":" << info.lineNumber << std::endl; - if (!info.stack.empty()) + } + if (!info.stack.empty()) { log::warning() << " " << info.stack << std::endl; + } } } }
--- a/lib/irccd/server-state-connecting.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/server-state-connecting.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -45,10 +45,12 @@ /* libircclient requires # for SSL connection */ #if defined(WITH_SSL) - if (info.flags & ServerInfo::Ssl) + if (info.flags & ServerInfo::Ssl) { host.insert(0, 1, '#'); - if (!(info.flags & ServerInfo::SslVerify)) + } + if (!(info.flags & ServerInfo::SslVerify)) { irc_option_set(server.session(), LIBIRC_OPTION_SSL_NO_VERIFY); + } #endif if (info.flags & ServerInfo::Ipv6) { @@ -94,9 +96,10 @@ log::warning() << "server " << info.name << ": error while connecting: "; log::warning() << irc_strerror(irc_errno(server.session())) << std::endl; - if (settings.reconnect_tries != 0) + if (settings.reconnect_tries != 0) { log::warning() << "server " << info.name << ": retrying in " << settings.reconnect_timeout << " seconds" << std::endl; + } server.next(std::make_unique<state::Disconnected>()); } else {
--- a/lib/irccd/server.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/server.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -76,24 +76,27 @@ std::string buf = line.substr(7); std::map<ServerChanMode, char> modes; - for (int i = 0; i < 16; ++i) + for (int i = 0; i < 16; ++i) { table[i] = std::make_pair(-1, -1); + } int j = 0; bool read_modes = true; for (size_t i = 0; i < buf.size(); ++i) { - if (buf[i] == '(') + if (buf[i] == '(') { continue; + } if (buf[i] == ')') { j = 0; read_modes = false; continue; } - if (read_modes) + if (read_modes) { table[j++].first = buf[i]; - else + } else { table[j++].second = buf[i]; + } } /* Put these as a map of mode to prefix */ @@ -151,8 +154,9 @@ void Server::handleInvite(const char *orig, const char **params) noexcept { /* If joininvite is set, join the channel */ - if ((m_settings.flags & ServerSettings::JoinInvite) && isSelf(strify(params[0]))) + if ((m_settings.flags & ServerSettings::JoinInvite) && isSelf(strify(params[0]))) { join(strify(params[1])); + } /* * The libircclient says that invite contains the target nickname, it's quite @@ -170,8 +174,9 @@ void Server::handleKick(const char *orig, const char **params) noexcept { /* Rejoin the channel if the option has been set and I was kicked. */ - if ((m_settings.flags & ServerSettings::AutoRejoin) && isSelf(strify(params[1]))) + if ((m_settings.flags & ServerSettings::AutoRejoin) && isSelf(strify(params[1]))) { join(strify(params[0])); + } onKick(strify(orig), strify(params[0]), strify(params[1]), strify(params[2])); } @@ -184,8 +189,9 @@ void Server::handleNick(const char *orig, const char **params) noexcept { /* Update our nickname. */ - if (isSelf(strify(orig))) + if (isSelf(strify(orig))) { m_identity.nickname = strify(params[0]); + } onNick(strify(orig), strify(params[0])); } @@ -211,14 +217,16 @@ * * IDEA for the future: maybe give the appropriate mode as a second parameter in onNames. */ - if (c < 4 || params[2] == nullptr || params[3] == nullptr) + if (c < 4 || params[2] == nullptr || params[3] == nullptr) { return; + } std::vector<std::string> users = util::split(params[3], " \t"); /* The listing may add some prefixes, remove them if needed */ - for (std::string u : users) + for (std::string u : users) { m_cache.names_map[params[2]].insert(cleanPrefix(m_info, u)); + } } else if (event == LIBIRC_RFC_RPL_ENDOFNAMES) { /* * Called when end of name listing has finished on a channel. @@ -228,8 +236,9 @@ * params[2] == End of NAMES list */ - if (c < 3 || params[1] == nullptr) + if (c < 3 || params[1] == nullptr) { return; + } auto it = m_cache.names_map.find(params[1]); if (it != m_cache.names_map.end()) { @@ -249,8 +258,9 @@ * params[4] == * (no idea what is that) * params[5] == realname */ - if (c < 6 || !params[1] || !params[2] || !params[3] || !params[5]) + if (c < 6 || !params[1] || !params[2] || !params[3] || !params[5]) { return; + } ServerWhois info; @@ -268,16 +278,18 @@ * params[1] == nickname * params[2] == list of channels with their prefixes */ - if (c < 3 || !params[1] || !params[2]) + if (c < 3 || !params[1] || !params[2]) { return; + } auto it = m_cache.whois_map.find(params[1]); if (it != m_cache.whois_map.end()) { std::vector<std::string> channels = util::split(params[2], " \t"); /* Clean their prefixes */ - for (auto &s : channels) + for (auto &s : channels) { s = cleanPrefix(m_info, s); + } /* Insert */ it->second.channels = std::move(channels); @@ -339,8 +351,9 @@ { auto pos = value.find(':'); - if (pos != std::string::npos) + if (pos != std::string::npos) { return ServerChannel{value.substr(0, pos), value.substr(pos + 1)}; + } return ServerChannel{value, ""}; } @@ -463,10 +476,11 @@ bool done = false; while (!m_queue.empty() && !done) { - if (m_queue.front()()) + if (m_queue.front()()) { m_queue.pop(); - else + } else { done = true; + } } /* 2. Read data */ @@ -564,8 +578,9 @@ void Server::part(std::string channel, std::string reason) { m_queue.push([=] () -> bool { - if (reason.empty()) + if (reason.empty()) { return irc_cmd_part(*m_session, channel.c_str()) == 0; + } return irc_send_raw(*m_session, "PART %s :%s", channel.c_str(), reason.c_str()); });
--- a/lib/irccd/system.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/system.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -115,10 +115,11 @@ } } - if (setter(id) < 0) + if (setter(id) < 0) { log::warning() << "irccd: could not set " << typeName << ": " << std::strerror(errno) << std::endl; - else + } else { log::info() << "irccd: setting " << typeName << " to " << value << std::endl; + } } /* @@ -174,8 +175,9 @@ #else struct utsname uts; - if (uname(&uts) < 0) + if (uname(&uts) < 0) { throw std::runtime_error(std::strerror(errno)); + } return std::string(uts.release); #endif @@ -188,8 +190,9 @@ #elif defined(IRCCD_SYSTEM_LINUX) struct sysinfo info; - if (sysinfo(&info) < 0) + if (sysinfo(&info) < 0) { throw std::runtime_error(std::strerror(errno)); + } return info.uptime; #elif defined(IRCCD_SYSTEM_MAC) @@ -197,8 +200,9 @@ size_t length = sizeof (boottime); int mib[2] = { CTL_KERN, KERN_BOOTTIME }; - if (sysctl(mib, 2, &boottime, &length, nullptr, 0) < 0) + if (sysctl(mib, 2, &boottime, &length, nullptr, 0) < 0) { throw std::runtime_error(std::strerror(errno)); + } time_t bsec = boottime.tv_sec, csec = time(nullptr); @@ -207,8 +211,9 @@ /* BSD */ struct timespec ts; - if (clock_gettime(CLOCK_UPTIME, &ts) < 0) + if (clock_gettime(CLOCK_UPTIME, &ts) < 0) { throw std::runtime_error(std::strerror(errno)); + } return ts.tv_sec; #endif @@ -236,8 +241,9 @@ #if defined(IRCCD_SYSTEM_WINDOWS) char path[MAX_PATH]; - if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK) + if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK) { return ""; + } return std::string(path); #else @@ -249,8 +255,9 @@ { auto value = std::getenv(var.c_str()); - if (value == nullptr) + if (value == nullptr) { return ""; + } return value; }
--- a/lib/irccd/timer.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/timer.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -33,8 +33,9 @@ return m_state != Paused; }); - if (m_state != Running) + if (m_state != Running) { continue; + } /* Wait the timer delay or the interrupt */ m_condition.wait_for(lock, std::chrono::milliseconds(m_delay), [&] () { @@ -45,8 +46,9 @@ /* Signal process */ onSignal(); - if (m_type == TimerType::Single) + if (m_type == TimerType::Single) { m_state = Stopped; + } } }
--- a/lib/irccd/transport-client.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/transport-client.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -26,8 +26,9 @@ { json::Value document(json::Buffer{message}); - if (!document.isObject()) + if (!document.isObject()) { throw std::invalid_argument("the message is not a valid JSON object"); + } onCommand(document); } @@ -44,27 +45,6 @@ } } -#if 0 - -void TransportClient::ok(const std::string &command) -{ - m_output += "{"; - m_output += "\"response\":\"" + command + "\","; - m_output += "\"status\":\"ok\""; - m_output += "}\r\n\r\n"; -} - -void TransportClient::error(const std::string &command, std::string message) -{ - m_output += "{"; - m_output += "\"response\":\"" + command + "\","; - m_output += "\"status\":\"error\","; - m_output += "\"error\": \"" + json::escape(message) + "\""; - m_output += "}\r\n\r\n"; -} - -#endif - void TransportClient::send(std::string message) { m_output += message;
--- a/lib/irccd/transport-client.hpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/transport-client.hpp Wed Apr 27 21:37:09 2016 +0200 @@ -91,23 +91,6 @@ */ void sync(fd_set &setinput, fd_set &setoutput); -#if 0 - /** - * Notify the client that the command succeeded. - * - * \param command the command name - */ - void ok(const std::string &command); - - /** - * Send an error message to the client. - * - * \param command the command name - * \param message the error message - */ - void error(const std::string &command, std::string message); -#endif - /** * Send some data, it will be pushed to the outgoing buffer. * @@ -174,8 +157,9 @@ try { auto message = m_socket.recv(512); - if (message.empty()) + if (message.empty()) { onDie(); + } m_input += message; } catch (const std::exception &) {
--- a/lib/irccd/transport-server.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/transport-server.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -39,8 +39,9 @@ m_socket.set(net::option::SockReuseAddress{true}); /* Disable or enable IPv4 when using IPv6 */ - if (domain == AF_INET6) + if (domain == AF_INET6) { m_socket.set(net::option::Ipv6Only{ipv6only}); + } m_socket.bind(net::address::Ip{address, port, static_cast<net::address::Ip::Type>(domain)}); m_socket.listen();
--- a/lib/irccd/util.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/util.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -89,8 +89,9 @@ { auto value = params.keywords.find(content); - if (value != params.keywords.end()) + if (value != params.keywords.end()) { return value->second; + } return ""; } @@ -99,8 +100,9 @@ { auto value = std::getenv(content.c_str()); - if (value != nullptr) + if (value != nullptr) { return value; + } return ""; } @@ -115,8 +117,9 @@ oss << attributesTable.at("reset"); } else { /* Remove useless spaces */ - for (auto &a : list) + for (auto &a : list) { a = strip(a); + } /* * 0: foreground @@ -130,19 +133,22 @@ /* Foreground */ auto it = colorTable.find(foreground); - if (it != colorTable.end()) + if (it != colorTable.end()) { oss << it->second; + } /* Background */ - if (list.size() >= 2 && (it = colorTable.find(list[1])) != colorTable.end()) + if (list.size() >= 2 && (it = colorTable.find(list[1])) != colorTable.end()) { oss << "," << it->second; + } /* Attributes */ for (std::size_t i = 2; i < list.size(); ++i) { auto attribute = attributesTable.find(list[i]); - if (attribute != attributesTable.end()) + if (attribute != attributesTable.end()) { oss << attribute->second; + } } } } @@ -154,14 +160,17 @@ { std::string content, value; - if (it == end) + if (it == end) { return ""; + } - while (it != end && *it != '}') + while (it != end && *it != '}') { content += *it++; + } - if (*it != '}' || it == end) + if (*it != '}' || it == end) { throw std::invalid_argument("unclosed "s + token + " construct"s); + } it++; @@ -216,11 +225,13 @@ oss << token; /* Do we have a double token followed by a { for escaping? */ - if (++it == end) + if (++it == end) { continue; + } - if (*it != '{') + if (*it != '{') { oss << token; + } } else { oss << *it++; } @@ -249,8 +260,9 @@ int count = 1; bool finished = false; - if (list.empty()) + if (list.empty()) { return result; + } do { std::string val; @@ -289,20 +301,22 @@ * is a space, we check until we find a space, if not * typing "!foo123123" will trigger foo plugin. */ - if (pos == std::string::npos) + if (pos == std::string::npos) { iscommand = result == fullcommand; - else + } else { iscommand = result.length() >= fullcommand.length() && result.compare(0, pos, fullcommand) == 0; + } if (iscommand) { /* * If no space is found we just set the message to "" otherwise * the plugin name will be passed through onCommand */ - if (pos == std::string::npos) + if (pos == std::string::npos) { result = ""; - else + } else { result = message.substr(pos + 1); + } } } @@ -316,8 +330,9 @@ bool isInt(const std::string &str, int base) noexcept { - if (str.empty()) + if (str.empty()) { return false; + } char *ptr; @@ -328,8 +343,9 @@ bool isReal(const std::string &str) noexcept { - if (str.empty()) + if (str.empty()) { return false; + } char *ptr;
--- a/lib/irccd/util.hpp Wed Apr 27 18:53:30 2016 +0200 +++ b/lib/irccd/util.hpp Wed Apr 27 21:37:09 2016 +0200 @@ -152,8 +152,9 @@ if (first != last) { oss << *first; - while (++first != last) + while (++first != last) { oss << delim << *first; + } } return oss.str();
--- a/tests/js-elapsedtimer/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/tests/js-elapsedtimer/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -40,13 +40,15 @@ TEST_F(TestElapsedTimer, standard) { try { - if (duk::pevalString(m_context, "timer = new Irccd.ElapsedTimer();") != 0) + if (duk::pevalString(m_context, "timer = new Irccd.ElapsedTimer();") != 0) { throw duk::error(m_context, -1); + } std::this_thread::sleep_for(300ms); - if (duk::pevalString(m_context, "result = timer.elapsed();") != 0) + if (duk::pevalString(m_context, "result = timer.elapsed();") != 0) { throw duk::error(m_context, -1); + } ASSERT_GE(duk::getGlobal<int>(m_context, "result"), 250); ASSERT_LE(duk::getGlobal<int>(m_context, "result"), 350); @@ -58,13 +60,15 @@ TEST_F(TestElapsedTimer, reset) { try { - if (duk::pevalString(m_context, "timer = new Irccd.ElapsedTimer();") != 0) + if (duk::pevalString(m_context, "timer = new Irccd.ElapsedTimer();") != 0) { throw duk::error(m_context, -1); + } std::this_thread::sleep_for(300ms); - if (duk::pevalString(m_context, "timer.reset(); result = timer.elapsed();") != 0) + if (duk::pevalString(m_context, "timer.reset(); result = timer.elapsed();") != 0) { throw duk::error(m_context, -1); + } ASSERT_LE(duk::getGlobal<int>(m_context, "result"), 100); } catch (const std::exception &ex) {
--- a/tests/js-file/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/tests/js-file/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -33,8 +33,9 @@ loadJsFile(ctx); try { - if (duk::pevalString(ctx, "result = Irccd.File.basename('/usr/local/etc/irccd.conf');") != 0) + if (duk::pevalString(ctx, "result = Irccd.File.basename('/usr/local/etc/irccd.conf');") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("irccd.conf", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -94,9 +95,7 @@ TEST(TestJsFile, functionRemove) { // First create a dummy file - { - std::ofstream out("test-js-fs.remove"); - } + std::ofstream("test-js-fs.remove"); duk::Context ctx; @@ -104,8 +103,9 @@ loadJsFile(ctx); try { - if (duk::pevalString(ctx, "Irccd.File.remove('test-js-fs.remove');") != 0) + if (duk::pevalString(ctx, "Irccd.File.remove('test-js-fs.remove');") != 0) { throw duk::error(ctx, -1); + } } catch (const std::exception &ex) { FAIL() << ex.what(); } @@ -130,8 +130,9 @@ "result = f.basename();" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("file-1.txt", duk::getGlobal<std::string>(ctx,"result")); } catch (const std::exception &ex) { @@ -155,8 +156,9 @@ "result = f.basename();" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("file-1.txt", duk::getGlobal<std::string>(ctx,"result")); } catch (const std::exception &ex) { @@ -179,8 +181,9 @@ "result = f.dirname();" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(std::string{IRCCD_TESTS_DIRECTORY "/level-1"}, duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -204,8 +207,9 @@ "result = f.dirname();" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(std::string{IRCCD_TESTS_DIRECTORY "/level-1"}, duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -227,8 +231,9 @@ "lines = new Irccd.File(directory + '/lines.txt', 'r').lines();" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } std::vector<std::string> expected{"a", "b", "c"}; @@ -254,8 +259,9 @@ "result = f.read(1);" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(".", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -263,7 +269,6 @@ } } - TEST(TestJsFile, methodSeek1Closed) { duk::Context ctx; @@ -282,9 +287,9 @@ "result = typeof (result) === \"undefined\";" ); - - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_TRUE(duk::getGlobal<bool>(ctx, "result")); } catch (const std::exception &ex) { @@ -310,8 +315,9 @@ ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(".", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -338,9 +344,9 @@ "result = typeof (result) === \"undefined\";" ); - - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_TRUE(duk::getGlobal<bool>(ctx, "result")); } catch (const std::exception &ex) { @@ -364,9 +370,9 @@ "result = f.read(1);" ); - - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("x", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -392,9 +398,9 @@ "result = typeof (result) === \"undefined\";" ); - - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_TRUE(duk::getGlobal<bool>(ctx, "result")); } catch (const std::exception &ex) { @@ -420,8 +426,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } std::vector<std::string> expected{"a", "b", "c"}; @@ -450,8 +457,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } std::vector<std::string> expected;
--- a/tests/js-irccd/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/tests/js-irccd/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -38,8 +38,9 @@ "patch = Irccd.version.patch;" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(IRCCD_VERSION_MAJOR, duk::getGlobal<int>(ctx, "major")); ASSERT_EQ(IRCCD_VERSION_MINOR, duk::getGlobal<int>(ctx, "minor")); @@ -68,8 +69,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(1, duk::getGlobal<int>(ctx, "errno")); ASSERT_EQ("SystemError", duk::getGlobal<std::string>(ctx, "name")); @@ -108,8 +110,9 @@ "}" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ(EINVAL, duk::getGlobal<int>(ctx, "errno")); ASSERT_EQ("SystemError", duk::getGlobal<std::string>(ctx, "name"));
--- a/tests/js-logger/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/tests/js-logger/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -62,8 +62,9 @@ try { duk::putGlobal(ctx, "\xff""\xff""name", "test"); - if (duk::pevalString(ctx, "Irccd.Logger.info(\"hello!\");") != 0) + if (duk::pevalString(ctx, "Irccd.Logger.info(\"hello!\");") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("plugin test: hello!", lineInfo); } catch (const std::exception &ex) { @@ -81,8 +82,9 @@ try { duk::putGlobal(ctx, "\xff""\xff""name", "test"); - if (duk::pevalString(ctx, "Irccd.Logger.warning(\"FAIL!\");") != 0) + if (duk::pevalString(ctx, "Irccd.Logger.warning(\"FAIL!\");") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("plugin test: FAIL!", lineWarning); } catch (const std::exception &ex) { @@ -102,8 +104,9 @@ try { duk::putGlobal(ctx, "\xff""\xff""name", "test"); - if (duk::pevalString(ctx, "Irccd.Logger.debug(\"starting\");") != 0) + if (duk::pevalString(ctx, "Irccd.Logger.debug(\"starting\");") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("plugin test: starting", lineDebug); } catch (const std::exception &ex) {
--- a/tests/js-util/main.cpp Wed Apr 27 18:53:30 2016 +0200 +++ b/tests/js-util/main.cpp Wed Apr 27 21:37:09 2016 +0200 @@ -35,8 +35,9 @@ "result = Irccd.Util.format(\"#{target}\", { target: \"markand\" })" ); - if (ret != 0) + if (ret != 0) { throw duk::error(ctx, -1); + } } catch (const std::exception &ex) { FAIL() << ex.what(); } @@ -50,8 +51,9 @@ loadJsUtil(ctx); try { - if (duk::pevalString(ctx, "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0) + if (duk::pevalString(ctx, "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("user", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) { @@ -67,8 +69,9 @@ loadJsUtil(ctx); try { - if (duk::pevalString(ctx, "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0) + if (duk::pevalString(ctx, "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0) { throw duk::error(ctx, -1); + } ASSERT_EQ("!~user@hyper/super/host", duk::getGlobal<std::string>(ctx, "result")); } catch (const std::exception &ex) {