From ba4e1160420358f351c5a1217f63b4008865a6a7 Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 18 Oct 2023 23:21:05 +0300 Subject: [PATCH] get rid of stdbool.h --- irc.c | 14 +++++++------- main.c | 4 ++-- net.c | 13 ++++++------- net.h | 3 +-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/irc.c b/irc.c index 5ba0eb9..0ccd815 100644 --- a/irc.c +++ b/irc.c @@ -123,12 +123,12 @@ int parsePacket(struct client_data *client) { *--end = '\n'; if (memchr(p, '\0', end-p)) { fprintf(stderr, "Client %"PRISocket" sent a NULL\n", client->FD); - killConnection(client, false); + killConnection(client, 0); return 1; // null detected } if (memchr(p, '\r', end-p)) { fprintf(stderr, "Client %"PRISocket" sent an extra CR\n", client->FD); - killConnection(client, false); + killConnection(client, 0); return 1; // internal \r detected } } @@ -356,7 +356,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a return 0; // FIXME: error message if (client == cl) return 0; // FIXME: error message - killConnection(cl, false); + killConnection(cl, 0); } else if(strcmp(command, "WALLOPS") == 0) { if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0; @@ -393,7 +393,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a sendbuf(cl2); } while (trie_findnext(&f) == 1); // FIXME: add appropraite QUIT message - killConnection(cl, false); + killConnection(cl, 0); } else if(strcmp(command, "JEDGAR") == 0) { if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0; @@ -570,7 +570,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a (strstr(args[1], "irc.supernets.org") || strstr(args[1], "IRC.SUPERNETS.ORG"))) { msg_quit(client, "Quit: eel bearing atlantean", ""); sendbuf_visible(client); - killConnection(client, true); + killConnection(client, 1); return 1; } @@ -592,7 +592,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a if (!(client->umode & UMODE_REGISTERED)) { msg_quit(client, "Quit: eel bearing atlantean", ""); sendbuf_visible(client); - killConnection(client, true); + killConnection(client, 1); return 1; } struct client_data *cl = findClient(args[0]); @@ -607,7 +607,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a } else if(strcmp(command, "QUIT") == 0) { msg_quit(client, "Quit: ", args[0] ? args[0] : ""); sendbuf_visible(client); - killConnection(client, true); + killConnection(client, 1); return 1; } else if(strcmp(command, "PONG") == 0) { // Do nothing diff --git a/main.c b/main.c index 39bafd5..8f555a6 100644 --- a/main.c +++ b/main.c @@ -132,7 +132,7 @@ SOCKET create_listen_sock(const char *ip, const char *port) void accept_from_sock(struct listener *listener) { - while (true) { + for (;;) { struct sockaddr_storage addr; socklen_t len = sizeof(addr); SOCKET newSocket = accept(listener->sock, (struct sockaddr *)&addr, &len); @@ -376,7 +376,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "[PatchyIRCD]: Cleaning up...\n"); for (struct client_data *cl = clients; cl;) { struct client_data *next = cl->next; - killConnection(cl, false); + killConnection(cl, 0); cl = next; } net_cleanup(); diff --git a/net.c b/net.c index 6bb682d..e5c1788 100644 --- a/net.c +++ b/net.c @@ -1,7 +1,6 @@ #include "net.h" #include "irc.h" #include "ircfmt.h" -#include #ifndef _WIN32 #include #endif @@ -31,7 +30,7 @@ static void block(struct client_data *cl, int out) } #endif -void killConnection(struct client_data *cl, bool byChoice) { +void killConnection(struct client_data *cl, int byChoice) { if (!cl) return; for (struct client_data **next = &clients; *next; next = &(*next)->next) { if (*next == cl) { @@ -108,19 +107,19 @@ void recvProc(struct client_data *cl) { cl->want_write_for_read = 0; while(1){ // I hate you - if(cl->bufLen == sizeof(cl->buf)) { killConnection(cl, false); return; } + if(cl->bufLen == sizeof(cl->buf)) { killConnection(cl, 0); return; } #if HAS_TLS if (cl->cctx) { bytesRead = tls_read(cl->cctx, cl->buf + cl->bufLen, sizeof(cl->buf) - cl->bufLen); switch (bytesRead) { // Disconnect case 0: - killConnection(cl, false); + killConnection(cl, 0); return; // Error case -1: fprintf(stderr, "tls_read: %s\n", tls_error(cl->cctx)); - killConnection(cl, false); + killConnection(cl, 0); return; case TLS_WANT_POLLIN: return; @@ -136,13 +135,13 @@ void recvProc(struct client_data *cl) { switch(bytesRead){ // Disconnect case 0: - killConnection(cl, false); + killConnection(cl, 0); return; // Error case -1: if(!net_wouldblock()){ net_perror("RECV"); - killConnection(cl, false); + killConnection(cl, 0); } return; } diff --git a/net.h b/net.h index 0c3daf1..fb76e30 100644 --- a/net.h +++ b/net.h @@ -1,12 +1,11 @@ #ifndef _net_h #define _net_h #include "common.h" -#include void sendbuf(struct client_data *client); void sendbuf_visible(struct client_data *client); struct client_data *allocClient(); -void killConnection(struct client_data *client, bool byChoice); +void killConnection(struct client_data *client, int byChoice); void recvProc(struct client_data *cl); void sendClient(struct client_data *cl, const char *buf, size_t len); -- 2.56.0