summary refs log tree commit diff
path: root/bounce.c
diff options
context:
space:
mode:
Diffstat (limited to 'bounce.c')
-rw-r--r--bounce.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/bounce.c b/bounce.c
new file mode 100644
index 0000000..b3d8b33
--- /dev/null
+++ b/bounce.c
@@ -0,0 +1,108 @@
+/* Copyright (C) 2019  C. McEnroe <june@causal.agency>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <err.h>
+#include <limits.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <tls.h>
+#include <unistd.h>
+
+#include "bounce.h"
+
+static char *censor(char *arg) {
+	char *dup = strdup(arg);
+	if (!dup) err(EX_OSERR, "strdup");
+	memset(arg, '\0', strlen(dup));
+	arg[0] = '*';
+	return dup;
+}
+
+int main(int argc, char *argv[]) {
+	const char *localHost = "localhost";
+	const char *localPort = "6697";
+	const char *localPass = NULL;
+	char certPath[PATH_MAX] = "";
+	char privPath[PATH_MAX] = "";
+
+	const char *host = NULL;
+	const char *port = "6697";
+	const char *pass = NULL;
+	const char *auth = NULL;
+	const char *nick = NULL;
+	const char *user = NULL;
+	const char *real = NULL;
+	const char *join = NULL;
+
+	int opt;
+	while (0 < (opt = getopt(argc, argv, "C:H:K:P:W:a:h:j:n:p:r:u:w:"))) {
+		switch (opt) {
+			break; case 'C': strlcpy(certPath, optarg, sizeof(certPath));
+			break; case 'H': localHost = optarg;
+			break; case 'K': strlcpy(privPath, optarg, sizeof(privPath));
+			break; case 'P': localPort = optarg;
+			break; case 'W': localPass = censor(optarg);
+			break; case 'a': auth = censor(optarg);
+			break; case 'h': host = optarg;
+			break; case 'j': join = optarg;
+			break; case 'n': nick = optarg;
+			break; case 'p': port = optarg;
+			break; case 'r': real = optarg;
+			break; case 'u': user = optarg;
+			break; case 'w': pass = censor(optarg);
+			break; default:  return EX_USAGE;
+		}
+	}
+
+	if (!certPath[0]) {
+		snprintf(certPath, sizeof(certPath), DEFAULT_CERT_PATH, localHost);
+	}
+	if (!privPath[0]) {
+		snprintf(privPath, sizeof(privPath), DEFAULT_PRIV_PATH, localHost);
+	}
+
+	if (!host) errx(EX_USAGE, "no host");
+	if (!nick) {
+		nick = getenv("USER");
+		if (!nick) errx(EX_CONFIG, "USER unset");
+	}
+	if (!user) user = nick;
+	if (!real) real = nick;
+
+	listenConfig(certPath, privPath);
+
+	enum { BindCap = 8 };
+	int bind[BindCap];
+	size_t bindLen = listenBind(bind, BindCap, localHost, localPort);
+
+	// Wishing for struct-of-arrays...
+	struct pollfd fds[BindCap];
+	for (size_t i = 0; i < bindLen; ++i) {
+		fds[i].fd = bind[i];
+		fds[i].events = POLLIN;
+	}
+
+	while (0 < poll(fds, bindLen, -1)) {
+		for (size_t i = 0; i < bindLen; ++i) {
+			if (!fds[i].revents) continue;
+			struct tls *client;
+			int fd = listenAccept(&client, fds[i].fd);
+		}
+	}
+}
2018-08-07Factor out allocating conversion between wcs and mbsJune McEnroe 2018-08-07Match commands case-insensitivelyJune McEnroe Also include the slash in their names so that they can be added to tab-complete later. 2018-08-07Convert input to multibyte before handlingJune McEnroe 2018-08-07Populate tab-complete listJune McEnroe 2018-08-07Fix /me formatting side-effectsJune McEnroe NEVER pass side-effects to a macro. 2018-08-07Define ui.c BUF_LEN with enumJune McEnroe 2018-08-07Hack clang into checking uiFmt format stringsJune McEnroe 2018-08-07Handle PART and QUIT without messagesJune McEnroe 2018-08-07Make safe filling the who bufferJune McEnroe 2018-08-07Add reverse and reset IRC formatting codesJune McEnroe 2018-08-06Rewrite line editing again, add formattingJune McEnroe 2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe