From 55b43d324934f55071441132e88f97637a2db4c3 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 19 Jan 2019 22:04:05 -0500 Subject: Remove pingbot --- bin/pingbot.c | 176 ---------------------------------------------------------- 1 file changed, 176 deletions(-) delete mode 100644 bin/pingbot.c (limited to 'bin') diff --git a/bin/pingbot.c b/bin/pingbot.c deleted file mode 100644 index 41876567..00000000 --- a/bin/pingbot.c +++ /dev/null @@ -1,176 +0,0 @@ -/* Copyright (C) 2019 June 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 -#include -#include -#include -#include - -typedef unsigned uint; - -__attribute__((format(printf, 2, 3))) -static int pdprintf(int fd, const char *format, ...) { - va_list ap; - va_start(ap, format); - vprintf(format, ap); - va_end(ap); - va_start(ap, format); - int len = vdprintf(fd, format, ap); - va_end(ap); - return len; -} - -int main(int argc, char *argv[]) { - int error; - - const char *host = NULL; - const char *port = "6667"; - const char *nick = "pingbot"; - const char *join = NULL; - uint timeout = 120; - uint delay = 30; - - int opt; - while (0 < (opt = getopt(argc, argv, "d:j:n:p:t:"))) { - switch (opt) { - break; case 'd': delay = strtoul(optarg, NULL, 0); - break; case 'j': join = optarg; - break; case 'n': nick = optarg; - break; case 'p': port = optarg; - break; case 't': timeout = strtoul(optarg, NULL, 0); - break; default: return EX_USAGE; - } - } - if (optind < argc) host = argv[optind]; - if (!host || !timeout) return EX_USAGE; - - 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, "getaddrinfo: %s", gai_strerror(error)); - - int client = -1; - struct addrinfo *ai; - for (ai = head; ai; ai = ai->ai_next) { - client = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (client < 0) err(EX_OSERR, "socket"); - - error = connect(client, ai->ai_addr, ai->ai_addrlen); - if (!error) break; - - close(client); - client = -1; - } - if (client < 0) err(EX_UNAVAILABLE, "connect"); - - error = pdprintf(client, "NICK %1$s\r\nUSER %1$s 0 * :%1$s\r\n", nick); - if (error < 0) err(EX_IOERR, "pdprintf"); - - int kq = kqueue(); - if (kq < 0) err(EX_OSERR, "kqueue"); - - struct kevent event; - EV_SET(&event, client, EVFILT_READ, EV_ADD, 0, 0, 0); - int nevents = kevent(kq, &event, 1, NULL, 0, NULL); - if (nevents < 0) err(EX_OSERR, "kevent"); - - char buf[4096]; - size_t len = 0; - bool pong = true; - for (;;) { - nevents = kevent(kq, NULL, 0, &event, 1, NULL); - if (nevents < 0) err(EX_IOERR, "kevent"); - - if (event.filter == EVFILT_TIMER) { - char *ping = event.udata; - if (pong) { - error = pdprintf(client, "PONG %s\r\n", ping); - if (error < 0) err(EX_IOERR, "pdprintf"); - } - pong = true; - free(ping); - continue; - } - - ssize_t rlen = read(client, &buf[len], sizeof(buf) - len); - if (rlen < 0) err(EX_IOERR, "read"); - len += (size_t)rlen; - - char *crlf; - char *line = buf; - while (NULL != (crlf = strnstr(line, "\r\n", &buf[len] - line))) { - crlf[0] = '\0'; - printf("%s\n", line); - - if (line[0] == ':') strsep(&line, " "); - if (!line) errx(EX_PROTOCOL, "unexpected eol"); - char *cmd = strsep(&line, " "); - - if (!strcmp(cmd, "001") && join) { - error = pdprintf(client, "JOIN :%s\r\n", join); - if (error < 0) err(EX_IOERR, "pdprintf"); - - } else if (!strcmp(cmd, "PING")) { - EV_SET( - &event, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, - NOTE_SECONDS, timeout - 1, strdup(line) - ); - nevents = kevent(kq, &event, 1, NULL, 0, NULL); - if (nevents < 0) err(EX_OSERR, "kevent"); - - } else if (!strcmp(cmd, "PRIVMSG") && strcasestr(line, nick)) { - pong = false; - - } else if (!strcmp(cmd, "ERROR")) { - close(client); - sleep(delay); - - client = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (client < 0) err(EX_OSERR, "socket"); - - error = connect(client, ai->ai_addr, ai->ai_addrlen); - if (error) err(EX_UNAVAILABLE, "connect"); - - error = pdprintf( - client, "NICK %1$s\r\nUSER %1$s 0 * :%1$s\r\n", nick - ); - if (error < 0) err(EX_IOERR, "pdprintf"); - - EV_SET(&event, client, EVFILT_READ, EV_ADD, 0, 0, 0); - int nevents = kevent(kq, &event, 1, NULL, 0, NULL); - if (nevents < 0) err(EX_OSERR, "kevent"); - } - - line = &crlf[2]; - } - - len -= line - buf; - memmove(buf, line, len); - } -} -- cgit 1.4.1 r class='nohover-highlight'> 2019-11-14Replace filters with regex replacesJune McEnroe 2019-11-13Refactor filterUserhostInNamesJune McEnroe 2019-11-13Factor out wordcpy for filtersJune McEnroe 2019-11-11Revert "Test getopt_config"June McEnroe This reverts commit c8a771828e1d5fc8c476bbd650fafcfb7ba390a8. It just feels gross... idk. 2019-11-11Test getopt_configJune McEnroe 2019-11-11Add userhost-in-names to manualJune McEnroe 2019-11-11Skip initial NAMES parametersJune McEnroe Channel names can contain '!' so splitting the whole message on it won't work. I hate this code though. 2019-11-11Filter userhost-in-namesJune McEnroe I really want to be writing tests for these functions... 2019-11-10Compare words without copying in filtersJune McEnroe 2019-11-10Separate tags from all targetJune McEnroe 2019-11-10Filter invite-notifyJune McEnroe 2019-11-10Add capsicum note to READMEJune McEnroe 2019-11-10Filter extended-joinJune McEnroe 2019-11-10Expand client configuration documentation and list capabilitiesJune McEnroe 2019-11-10Request all supported caps from serverJune McEnroe 2019-11-10Filter ACCOUNT, AWAY, CHGHOST for incapable clientsJune McEnroe 2019-11-10Rename listen to localJune McEnroe 2019-11-09Remove extended-join and invite-notifyJune McEnroe The remaining caps only generate new commands which can easily be filtered out when sending to clients so will be in the first pass of support. extended-join is probably safe to pass through unaltered, just causing extraneous parameters on JOIN commands, but maybe not. invite-notify reuses the INVITE command where the invited user is not self. 2019-11-09Maintain stateCaps and offer them to clientsJune McEnroe 2019-11-09Parse capabilitiesJune McEnroe The list that I've defined are the ones that I expect to be able to enable probably without any clients breaking... And of course server-time which pounce implements itself. 2019-11-09Avoid the reserved _A names with BIT macroJune McEnroe 2019-11-09Define macro for bit flag enumsJune McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. 2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe