From 88b9e3a3cdc9967d8512d818b8dbaf0385d1fa2d Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 22 Oct 2019 22:16:12 -0400 Subject: Implement serverConnect --- Makefile | 1 + server.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 server.c diff --git a/Makefile b/Makefile index 80b5261..2a78fab 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ LDLIBS = -ltls OBJS += bounce.o OBJS += listen.o +OBJS += server.o all: tags linger diff --git a/server.c b/server.c new file mode 100644 index 0000000..b86d769 --- /dev/null +++ b/server.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2019 C. McEnroe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bounce.h" + +static struct tls *client; + +int serverConnect(const char *host, const char *port) { + int error; + + struct tls_config *config = tls_config_new(); + error = tls_config_set_ciphers(config, "compat"); + if (error) errx(EX_SOFTWARE, "tls_config"); + + client = tls_client(); + if (!client) errx(EX_SOFTWARE, "tls_client"); + + error = tls_configure(client, config); + if (error) errx(EX_SOFTWARE, "tls_configure: %s", tls_error(client)); + tls_config_free(config); + + struct addrinfo *head; + struct addrinfo hints = { + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, + .ai_protocol = IPPROTO_TCP, + }; + error = getaddrinfo(host, port, &hints, &head); + if (error) errx(EX_NOHOST, "%s:%s: %s", host, port, gai_strerror(error)); + + int sock = -1; + for (struct addrinfo *ai = head; ai; ai = ai->ai_next) { + sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (sock < 0) err(EX_OSERR, "socket"); + + error = connect(sock, ai->ai_addr, ai->ai_addrlen); + if (!error) break; + + close(sock); + sock = -1; + } + if (sock < 0) err(EX_UNAVAILABLE, "%s:%s", host, port); + freeaddrinfo(head); + + error = tls_connect_socket(client, sock, host); + if (error) errx(EX_PROTOCOL, "tls_connect: %s", tls_error(client)); + + return sock; +} -- cgit 1.4.1 1.9&id=aacee60ce63c1497681eb712718241c2f6aad84e&follow=1'>Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe 2019-02-21Replace "view" with "window"June McEnroe 2019-02-21Remove ROT13June McEnroe 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe> 2018-08-03Handle inputJune McEnroe This turned out a lot better than expected. Still a long way to go in terms of line-editing, but at least backspace works! 2018-08-03Track own usernameJune McEnroe So that we can colour our own messages correctly. 2018-08-03Use a wide pad for the topicJune McEnroe 2018-08-03Ignore NOTICEs not sent to the channelJune McEnroe 2018-08-03Handle KICK and NICKJune McEnroe 2018-08-03Continue on EINTR from pollJune McEnroe Resizing the terminal causes it. 2018-08-03Handle ACTIONsJune McEnroe 2018-08-03Use more octal char literalsJune McEnroe I might be coming around to octal. 2018-08-03Send a WHO in response to NAMES to get usernamesJune McEnroe Other than this slight hack, I think coloring by username rather than nick is a much better idea. 2018-08-03Colorize nicks and channelsJune McEnroe 2018-08-03Add support for mIRC colorsJune McEnroe 2018-08-03Handle bold, italic, underlineJune McEnroe 2018-08-03Add prift function for "prefix shift"June McEnroe Forgive me. 2018-08-03Link with -lcurseswJune McEnroe 2018-08-02Use libtls "compat" ciphersJune McEnroe irc.mozilla.org, using GnuTLS, doesn't support *any* of the "secure" ciphers! 2018-08-02Add UI and handle some kinds of server messagesJune McEnroe Seems like handling input is going to be the worst thing ever. 2018-08-02Add chroot.tar targetJune McEnroe49135c849b6c5dc85a541f30ae5a&follow=1'>Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe I have no idea why I did this. 2018-09-13Rewrite UI againJune McEnroe The persistent topic is gone and the status line is now at the top. The status formatting still needs to be reworked. I also want to try showing the nick in the input window so it really looks like your next message. 2018-09-12Add note about C-oJune McEnroe Why are there so few well usable ctrl key bindings? 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe Ridiculous. 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe