main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "IRCAppWindow.h"
  27. #include "IRCClient.h"
  28. #include <LibGUI/Application.h>
  29. #include <LibGUI/MessageBox.h>
  30. #include <stdio.h>
  31. int main(int argc, char** argv)
  32. {
  33. if (pledge("stdio inet dns unix shared_buffer cpath rpath fattr wpath cpath", nullptr) < 0) {
  34. perror("pledge");
  35. return 1;
  36. }
  37. if (getuid() == 0) {
  38. fprintf(stderr, "Refusing to run as root\n");
  39. return 1;
  40. }
  41. GUI::Application app(argc, argv);
  42. if (pledge("stdio inet dns unix shared_buffer rpath wpath cpath", nullptr) < 0) {
  43. perror("pledge");
  44. return 1;
  45. }
  46. URL url = "";
  47. if (app.args().size() >= 1) {
  48. url = URL::create_with_url_or_path(app.args()[0]);
  49. if (url.protocol().to_lowercase() == "ircs") {
  50. fprintf(stderr, "Secure IRC over SSL/TLS (ircs) is not supported\n");
  51. return 1;
  52. }
  53. if (url.protocol().to_lowercase() != "irc") {
  54. fprintf(stderr, "Unsupported protocol\n");
  55. return 1;
  56. }
  57. if (url.host().is_empty()) {
  58. fprintf(stderr, "Invalid URL\n");
  59. return 1;
  60. }
  61. if (!url.port() || url.port() == 80)
  62. url.set_port(6667);
  63. }
  64. auto app_window = IRCAppWindow::construct(url.host(), url.port());
  65. app_window->show();
  66. return app.exec();
  67. }