diff options
author | June McEnroe <june@causal.agency> | 2022-03-29 19:15:30 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-03-29 19:15:30 -0400 |
commit | 78daf36f34b2b59618ee971cbb797bbd2ec41fd5 (patch) | |
tree | 7099abca0cae8a2f6686e09d48c3812578c57021 | |
parent | Send 900 as part of stateSync (diff) | |
download | pounce-78daf36f34b2b59618ee971cbb797bbd2ec41fd5.tar.gz pounce-78daf36f34b2b59618ee971cbb797bbd2ec41fd5.zip |
Rename client->error to client->remove
-rw-r--r-- | bounce.c | 2 | ||||
-rw-r--r-- | bounce.h | 2 | ||||
-rw-r--r-- | client.c | 61 |
3 files changed, 33 insertions, 32 deletions
diff --git a/bounce.c b/bounce.c index 69783f8..cd4898a 100644 --- a/bounce.c +++ b/bounce.c @@ -424,7 +424,7 @@ int main(int argc, char *argv[]) { } } if (revents & POLLIN) clientRecv(client); - if (client->error || revents & (POLLHUP | POLLERR)) { + if (client->remove || revents & (POLLHUP | POLLERR)) { clientFree(client); eventRemove(i); } diff --git a/bounce.h b/bounce.h index 8987e38..fa810a2 100644 --- a/bounce.h +++ b/bounce.h @@ -212,7 +212,7 @@ enum Need { BIT(NeedCapEnd), }; struct Client { - bool error; + bool remove; int sock; struct tls *tls; time_t time; diff --git a/client.c b/client.c index 6b75681..a20700d 100644 --- a/client.c +++ b/client.c @@ -43,10 +43,28 @@ #include "bounce.h" enum Cap clientCaps = CapServerTime | CapConsumer | CapPassive | CapSTS; -char *clientOrigin = "irc.invalid"; +char *clientOrigin; char *clientPass; char *clientAway; +static size_t active; + +static void activeIncr(const struct Client *client) { + if (client->need) return; + if (client->caps & CapPassive) return; + if (!active++) { + serverEnqueue("AWAY\r\n"); + } +} + +static void activeDecr(const struct Client *client) { + if (client->need) return; + if (client->caps & CapPassive) return; + if (!--active && !stateAway) { + serverEnqueue("AWAY :%s\r\n", clientAway); + } +} + struct Client *clientAlloc(int sock, struct tls *tls) { struct Client *client = calloc(1, sizeof(*client)); if (!client) err(EX_OSERR, "calloc"); @@ -65,7 +83,7 @@ static void clientHandshake(struct Client *client) { if (error == TLS_WANT_POLLIN || error == TLS_WANT_POLLOUT) return; if (error) { warnx("client tls_handshake: %s", tls_error(client->tls)); - client->error = true; + client->remove = true; return; } client->need &= ~NeedHandshake; @@ -74,24 +92,6 @@ static void clientHandshake(struct Client *client) { } } -static size_t active; - -static void activeIncr(const struct Client *client) { - if (client->need) return; - if (client->caps & CapPassive) return; - if (!active++) { - serverEnqueue("AWAY\r\n"); - } -} - -static void activeDecr(const struct Client *client) { - if (client->need) return; - if (client->caps & CapPassive) return; - if (!--active && !stateAway) { - serverEnqueue("AWAY :%s\r\n", clientAway); - } -} - void clientFree(struct Client *client) { activeDecr(client); tls_close(client->tls); @@ -107,7 +107,7 @@ void clientSend(struct Client *client, const char *ptr, size_t len) { if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) continue; if (ret < 0) { warnx("client tls_write: %s", tls_error(client->tls)); - client->error = true; + client->remove = true; break; } ptr += ret; @@ -134,7 +134,7 @@ static void passRequired(struct Client *client) { "ERROR :Password incorrect\r\n", clientOrigin ); - client->error = true; + client->remove = true; } static void maybeSync(struct Client *client) { @@ -156,7 +156,7 @@ static void handleNick(struct Client *client, struct Message *msg) { static void handleUser(struct Client *client, struct Message *msg) { if (!msg->params[0]) { - client->error = true; + client->remove = true; return; } if (client->need & NeedPass) { @@ -172,7 +172,7 @@ static void handleUser(struct Client *client, struct Message *msg) { static void handlePass(struct Client *client, struct Message *msg) { if (!clientPass) return; if (!msg->params[0]) { - client->error = true; + client->remove = true; return; } #ifdef __OpenBSD__ @@ -180,13 +180,13 @@ static void handlePass(struct Client *client, struct Message *msg) { #else int error = strcmp(crypt(msg->params[0], clientPass), clientPass); #endif + explicit_bzero(msg->params[0], strlen(msg->params[0])); if (error) { passRequired(client); } else { client->need &= ~NeedPass; maybeSync(client); } - explicit_bzero(msg->params[0], strlen(msg->params[0])); } static void handleCap(struct Client *client, struct Message *msg) { @@ -238,7 +238,8 @@ static void handleCap(struct Client *client, struct Message *msg) { } else { clientFormat( client, ":%s CAP * NAK :%s\r\n", - clientOrigin, msg->params[1]); + clientOrigin, msg->params[1] + ); } } else if (!strcmp(msg->params[0], "LIST")) { @@ -280,7 +281,7 @@ static void handleAuthenticate(struct Client *client, struct Message *msg) { static void handleQuit(struct Client *client, struct Message *msg) { (void)msg; clientFormat(client, "ERROR :Detaching\r\n"); - client->error = true; + client->remove = true; } static bool hasTag(const char *tags, const char *tag) { @@ -395,7 +396,7 @@ static void clientParse(struct Client *client, char *line) { Handlers[i].fn(client, &msg); return; } - client->error = true; + client->remove = true; } static bool intercept(const char *line, size_t len) { @@ -429,7 +430,7 @@ void clientRecv(struct Client *client) { if (read == TLS_WANT_POLLIN || read == TLS_WANT_POLLOUT) return; if (read <= 0) { if (read < 0) warnx("client tls_read: %s", tls_error(client->tls)); - client->error = true; + client->remove = true; return; } client->len += read; @@ -657,5 +658,5 @@ void clientConsume(struct Client *client) { } else { clientFormat(client, "%s\r\n", line); } - if (!client->error) ringConsume(NULL, client->consumer); + if (!client->remove) ringConsume(NULL, client->consumer); } |