ladybird/Userland/Applications/IRCClient/main.cpp

86 lines
1.9 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "IRCAppWindow.h"
#include "IRCClient.h"
2020-11-02 18:34:29 -03:00
#include <LibCore/StandardPaths.h>
#include <LibGUI/Application.h>
#include <LibGUI/MessageBox.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (pledge("stdio inet unix recvfd sendfd cpath rpath wpath", nullptr) < 0) {
2020-01-11 19:53:54 -03:00
perror("pledge");
return 1;
}
if (getuid() == 0) {
2020-10-06 09:16:35 -03:00
warnln("Refusing to run as root");
return 1;
}
auto app = GUI::Application::construct(argc, argv);
2020-11-02 18:34:29 -03:00
if (unveil("/tmp/portal/lookup", "rw") < 0) {
perror("unveil");
return 1;
}
if (unveil("/tmp/portal/notify", "rw") < 0) {
perror("unveil");
return 1;
}
if (unveil("/etc/passwd", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil(Core::StandardPaths::home_directory().characters(), "rwc") < 0) {
perror("unveil");
return 1;
}
if (unveil("/res", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
URL url = "";
if (app->args().size() >= 1) {
url = URL::create_with_url_or_path(app->args()[0]);
if (url.protocol().to_lowercase() == "ircs") {
2020-10-06 09:16:35 -03:00
warnln("Secure IRC over SSL/TLS (ircs) is not supported");
return 1;
}
if (url.protocol().to_lowercase() != "irc") {
2020-10-06 09:16:35 -03:00
warnln("Unsupported protocol");
return 1;
}
if (url.host().is_empty()) {
2020-10-06 09:16:35 -03:00
warnln("Invalid URL");
return 1;
}
if (!url.port() || url.port() == 80)
url.set_port(6667);
}
auto app_window = IRCAppWindow::construct(url.host(), url.port());
app_window->show();
return app->exec();
}