summary refs log tree commit diff
path: root/server.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-28 00:39:16 -0400
committerJune McEnroe <june@causal.agency>2019-10-28 00:39:16 -0400
commit0c964f63c5e9362d856778b0abf81fdaff004d57 (patch)
treec356a244640731ba6e39137bbb3e90e6c75fc8c6 /server.c
parentWait for SASL success before sending CAP END (diff)
downloadpounce-0c964f63c5e9362d856778b0abf81fdaff004d57.tar.gz
pounce-0c964f63c5e9362d856778b0abf81fdaff004d57.zip
Move entire login flow to state and reorganize it
Diffstat (limited to '')
-rw-r--r--server.c60
1 files changed, 0 insertions, 60 deletions
diff --git a/server.c b/server.c
index 5d985cb..d0181bb 100644
--- a/server.c
+++ b/server.c
@@ -29,8 +29,6 @@
 
 #include "bounce.h"
 
-typedef unsigned char byte;
-
 static struct tls *client;
 
 int serverConnect(bool insecure, const char *host, const char *port) {
@@ -106,64 +104,6 @@ void serverFormat(const char *format, ...) {
 	serverSend(buf, len);
 }
 
-static const char Base64[64] = {
-	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-};
-
-static char *base64(const byte *src, size_t len) {
-	char *dst = malloc(1 + (len + 2) / 3 * 4);
-	if (!dst) err(EX_OSERR, "malloc");
-	size_t i = 0;
-	while (len > 2) {
-		dst[i++] = Base64[0x3F & (src[0] >> 2)];
-		dst[i++] = Base64[0x3F & (src[0] << 4 | src[1] >> 4)];
-		dst[i++] = Base64[0x3F & (src[1] << 2 | src[2] >> 6)];
-		dst[i++] = Base64[0x3F & src[2]];
-		src += 3;
-		len -= 3;
-	}
-	if (len) {
-		dst[i++] = Base64[0x3F & (src[0] >> 2)];
-		if (len > 1) {
-			dst[i++] = Base64[0x3F & (src[0] << 4 | src[1] >> 4)];
-			dst[i++] = Base64[0x3F & (src[1] << 2)];
-		} else {
-			dst[i++] = Base64[0x3F & (src[0] << 4)];
-			dst[i++] = '=';
-		}
-		dst[i++] = '=';
-	}
-	dst[i] = '\0';
-	return dst;
-}
-
-static char *authPlain;
-
-void serverLogin(
-	const char *pass, const char *auth,
-	const char *nick, const char *user, const char *real
-) {
-	if (auth) {
-		byte plain[1 + strlen(auth)];
-		plain[0] = 0;
-		for (size_t i = 0; auth[i]; ++i) {
-			plain[1 + i] = (auth[i] == ':' ? 0 : auth[i]);
-		}
-		authPlain = base64(plain, sizeof(plain));
-		serverFormat("CAP REQ :sasl\r\n");
-	}
-	if (pass) serverFormat("PASS :%s\r\n", pass);
-	serverFormat("NICK %s\r\n", nick);
-	serverFormat("USER %s 0 * :%s\r\n", user, real);
-}
-
-void serverAuth(void) {
-	assert(authPlain);
-	serverFormat("AUTHENTICATE %s\r\n", authPlain);
-	free(authPlain);
-	authPlain = NULL;
-}
-
 void serverRecv(void) {
 	static char buf[4096];
 	static size_t len;