diff options
author | stefan11111 <stefan11111@shitposting.expert> | 2024-10-08 13:53:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-08 06:53:09 -0400 |
commit | cb595c56d41b0c38be69a2265d820d4107b0c8a4 (patch) | |
tree | 89644b68d18d76657059cfeffd6752d165d50585 /kirc.h | |
parent | some code improvements and a new feature (#137) (diff) | |
download | kirc-cb595c56d41b0c38be69a2265d820d4107b0c8a4.tar.gz kirc-cb595c56d41b0c38be69a2265d820d4107b0c8a4.tar.bz2 kirc-cb595c56d41b0c38be69a2265d820d4107b0c8a4.tar.xz kirc-cb595c56d41b0c38be69a2265d820d4107b0c8a4.tar.zst kirc-cb595c56d41b0c38be69a2265d820d4107b0c8a4.zip |
remove some magic numbers, clean up DCC ipv4/ipv6 global variable mess and use a union to save memory. (#139)
Co-authored-by: Emeka Nkurumeh <emekankurumeh@outlook.com>
Diffstat (limited to 'kirc.h')
-rw-r--r-- | kirc.h | 56 |
1 files changed, 40 insertions, 16 deletions
@@ -10,12 +10,18 @@ #define CTCP_CMDS "ACTION VERSION TIME CLIENTINFO PING DCC" #define VERSION "0.3.2" #define TESTCHARS "\xe1\xbb\xa4" -#define MSG_MAX 512 +#define MSG_MAX 512 /* irc rfc says lines are 512 char's max, but servers can accept more */ #define CHA_MAX 200 #define WRAP_LEN 26 +#define ABUF_LEN (sizeof("\r") - 1 + CHA_MAX + sizeof("> ") - 1 + MSG_MAX + sizeof("\x1b[0K") - 1 + 32 + 1) + /* this is as big as the ab buffer can get */ #define HIS_MAX 100 #define FNM_MAX 255 +#define DIR_MAX 256 +#define ERR_MAX 1 /* number of read/write errors before DCC slot is discarded */ +#define POLL_TIMEOUT 180000 /* 3 minutes */ /* argument is in miliseconds */ #define CON_MAX 20 +#define BACKLOG 100 /* DCC SEND listen() backlog */ #define CBUF_SIZ 1024 #define DCC_FLAGS (O_WRONLY | O_APPEND) #define DCC_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) @@ -43,11 +49,16 @@ #include <sys/stat.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <signal.h> static int conn; /* connection socket */ -static int verb = 0; /* verbose output */ -static int sasl = 0; /* SASL method */ -static int isu8 = 0; /* UTF-8 flag */ +static int hint_family = AF_UNSPEC; /* desired ip version */ +static char verb = 0; /* verbose output */ +static char sasl = 0; /* SASL method */ +static char isu8 = 0; /* UTF-8 flag */ +static char dcc = 0; /* DCC flag */ +static char filter = 0; /* flag to filter ansi colors */ +static char* dcc_dir = NULL; /* DCC download directory */ static const char *host = "irc.libera.chat"; /* host address */ static const char *port = "6667"; /* port */ static char chan[MSG_MAX]; /* channel and prompt */ @@ -58,23 +69,30 @@ static char *auth = NULL; /* PLAIN SASL token */ static char *real = NULL; /* real name */ static char *olog = NULL; /* chat log path */ static char *inic = NULL; /* additional server command */ -static int cmds = 0; /* indicates additional server commands */ +static char cmds = 0; /* indicates additional server commands */ static char cbuf[CBUF_SIZ]; /* additional stdin server commands */ -static short ipv6 = 0; /* define function macros */ #define htonll(x) ((1==htonl(1)) ? (x) : (((uint64_t)htonl((x) & 0xFFFFFFFFUL)) << 32) | htonl((uint32_t)((x) >> 32))) +#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#undef htonll +#define htonll(x) ((x)) +#endif +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#undef htonll +#define htonll(x) ((((uint64_t)htonl((x) & 0xFFFFFFFFUL)) << 32) | htonl((uint32_t)((x) >> 32))) +#endif + #define buffer_position_move(l, dest, src, size) memmove(l->buf + l->posb + dest, l->buf + l->posb + src, size) #define buffer_position_move_end(l, dest, src) buffer_position_move(l, dest, src, l->lenb - (l->posb + src) + 1) #define u8_character_start(c) (isu8 ? (c & 0x80) == 0x00 || (c & 0xC0) == 0xC0 : 1) static int ttyinfd = STDIN_FILENO; static struct termios orig; -static int rawmode = 0; -static int atexit_registered = 0; static int history_len = 0; -static char **history = NULL; -static short small_screen; +static char history_wrap = 0; +static char history[HIS_MAX][MSG_MAX]; +static char small_screen; typedef struct PARAMETERS { char *prefix; @@ -91,7 +109,6 @@ typedef struct PARAMETERS { typedef struct STATE { char buf[MSG_MAX]; /* Edited line buffer. */ - size_t buflen; /* Edited line buffer size. */ size_t plenb; /* Prompt length. */ size_t plenu8; /* Prompt length. */ size_t posb; /* Current cursor position. */ @@ -106,17 +123,24 @@ typedef struct STATE { } state_t, *state; struct abuf { - char *b; + char b[ABUF_LEN]; int len; }; -struct dcc_connection { - char filename[FNM_MAX + 1]; +union sockaddr_in46 { struct sockaddr_in sin; struct sockaddr_in6 sin6; - size_t bytes_read; - size_t file_size; + sa_family_t sin_family; +}; + +struct dcc_connection { + unsigned long long bytes_read; + unsigned long long file_size; + union sockaddr_in46 sin46; int file_fd; + int err_cnt; + int write; + char filename[FNM_MAX + 1]; }; static struct { |