From 05aebf593fff9f225e4ccf1264db3722acf8468e Mon Sep 17 00:00:00 2001 From: Michael Czigler <37268479+mcpcpc@users.noreply.github.com> Date: Wed, 23 Sep 2020 16:01:35 -0400 Subject: squash commits to address README and defaults Update README.md update logo Update README.md add multi-channel join argument option simplify printw() return after channel join Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Add files via upload Delete googled3f6f6cc852fad22.html Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md increase chan variable size Delete test remove fixed chan buffer size --- .github/example2.png | Bin 0 -> 964934 bytes .github/kirc.png | Bin 442070 -> 449970 bytes README.md | 56 ++++++++++++++++----------------- kirc.c | 85 +++++++++++++++++++++++++-------------------------- 4 files changed, 67 insertions(+), 74 deletions(-) create mode 100644 .github/example2.png diff --git a/.github/example2.png b/.github/example2.png new file mode 100644 index 0000000..fe654fa Binary files /dev/null and b/.github/example2.png differ diff --git a/.github/kirc.png b/.github/kirc.png index 52a6075..260e13f 100644 Binary files a/.github/kirc.png and b/.github/kirc.png differ diff --git a/README.md b/README.md index 87dd210..95cd6f8 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,33 @@ Packaging status +Codacy status

-## Objectives +## Features + +* Excellent cross-platform compatibility (due to [POSIX](https://opensource.com/article/19/7/what-posix-richard-stallman-explains) standard compliance). +* No dependencies other than a [C99 compiler](https://en.wikipedia.org/wiki/C99). +* Native [PLAIN SASL](https://tools.ietf.org/html/rfc4422) authentication support. +* [TLS/SSL](https://en.m.wikipedia.org/wiki/Transport_Layer_Security) protocol capable (via external TLS utilities). +* Chat history logging. +* Multi-channel joining at server connection. +* Simple shortcut commands and full support for all IRC commands in the [RFC 2812](https://tools.ietf.org/html/rfc2812) standard: + +```shell + Send a PRIVMSG to the current channel. +/ Send command to IRC server (see RFC 2812 for full list). +/# Assign new default message channel. +/? Print current message channel. +``` -_"Do one thing and do it well"_ — Emphasis was placed on building simple, short, clear, modular, and extensible code that can be easily maintained and repurposed (per the [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy)). +* Color scheme definition via [ANSI 8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code). Therefore, one could theoretically achieve uniform color definition across all shell applications and tools. -_Portability_ — [POSIX](https://en.wikipedia.org/wiki/POSIX) compliance ensures seamless compatibility and interoperability between variants of Unix and other operating systems. +## Screenshots -_Usability_ — Commands and shortcuts should feel "natural" when using a [standard 104-key US keyboard layout](https://en.wikipedia.org/wiki/Keyboard_layout). Where possible, the number of keystrokes have been minimized. +![Screenshot 1](/.github/example.png) + +![Screenshot 1](/.github/example2.png) ## Usage @@ -20,7 +38,7 @@ _Usability_ — Commands and shortcuts should feel "natural" when using a [stand usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name] [-u username] [-k password] [-x init command] [-w columns] [-W columns] [-o path] [-h|v|V] -s server address (default: 'irc.freenode.org') -p server port (default: '6667') --c channel name (default: 'kirc') +-c channel name(s), delimited by a "," or "|" character (default: 'kirc') -n nickname (required) -u server username (optional) -k server password (optional) @@ -30,33 +48,11 @@ usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-r real name] [-u us -V verbose output (e.g. raw stream) -o output path to log irc stream -x send command to irc server after inital connection --w maximum width of the printed left column (default: '10') +-w maximum width of the printed left column (default: '20') -W maximum width of the entire printed stream (default '80') -h basic usage information ``` -## Features - -* No dependencies other than a [C99 compiler](https://gcc.gnu.org/). -* Supports IPv4 and IPv6 connections. -* Supports [PLAIN SASL](https://tools.ietf.org/html/rfc4422) authentication methods. -* Can be used in conjunction with an [TLS/SSL](https://en.m.wikipedia.org/wiki/Transport_Layer_Security) client to communicate across a network in a way designed to prevent eavesdropping and tampering. -* Ability to log the entire chat history (see _Usage_ section for more information). -* Simple commands and full support for all IRC commands in the [RFC 2812](https://tools.ietf.org/html/rfc2812) standard: - -```shell - Send a PRIVMSG to the current channel. -/ Send command to IRC server (see RFC 2812 for full list). -/# Assign new default message channel. -/? Print current message channel. -``` - -* Color scheme definition via [ANSI 8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code). Therefore, one could theoretically achieve uniform color definition across all shell applications and tools. - -## Screenshots - -![Screenshot 1](/.github/example.png) - ## Installation Building and installing on **KISS Linux** using the Community repository: @@ -87,14 +83,14 @@ make install There is no native TLS/SSL support. Instead, users can achieve this functionality by using third-party tools (e.g. stunnel, socat, ghosttunnel). -* _socat_ example: +* _socat_ example: ```shell socat tcp-listen:6667,reuseaddr,fork,bind=127.0.0.1 ssl::6697 kirc -s 127.0.0.1 -c 'channel' -n 'name' -r 'realname' ``` -## PLAIN SASL Support +## PLAIN SASL Authentication In order to connect using PLAIN SASL authentication, the user must provide the required token during the initial connection. If the authentication token is base64 encoded and, therefore, can be generated a number of ways. For example, using Python, one could use the following: diff --git a/kirc.c b/kirc.c index 5719917..28bec21 100644 --- a/kirc.c +++ b/kirc.c @@ -21,12 +21,13 @@ [-w columns] [-W columns] [-o path] [-h|v|V]" static int conn; /* connection socket */ +static char chan_default[MSG_MAX]; /* default channel for PRIVMSG */ static int verb = 0; /* verbose output (e.g. raw stream) */ static size_t cmax = 80; /* max number of chars per line */ static size_t gutl = 20; /* max char width of left column */ -static char chan[CHA_MAX] = "kirc"; /* channel */ static char * host = "irc.freenode.org"; /* irc host address */ static char * port = "6667"; /* server port */ +static char * chan = NULL; /* channel(s) */ static char * nick = NULL; /* nickname */ static char * pass = NULL; /* server password */ static char * user = NULL; /* server user name */ @@ -117,24 +118,10 @@ connection_initialize(void) { } static void -printw(const char *format, ...) { +message_wrap(char *line, size_t offset) { - va_list argptr; - char *tok, line[MSG_MAX]; - size_t i, wordwidth, spaceleft = cmax, spacewidth = 1; - - va_start(argptr, format); - vsnprintf(line, MSG_MAX, format, argptr); - va_end(argptr); - - if (olog) log_append(line, olog); - - for (i = 0; line[i] == ' '; ++i) { - putchar(line[i]); - } - - //spaceleft -= i - 1; - spaceleft -= i - 1 - 9; /* _temporary_ fix */ + char *tok; + size_t wordwidth, spaceleft = cmax - gutl - offset, spacewidth = 1; for(tok = strtok(line, " "); tok != NULL; tok = strtok(NULL, " ")) { wordwidth = strlen(tok); @@ -151,45 +138,55 @@ printw(const char *format, ...) { } static void -raw_parser(char *usrin) { +raw_parser(char *string) { - if (verb) printf(">> %s\n", usrin); + if (verb) printf(">> %s\n", string); - if (!strncmp(usrin, "PING", 4)) { - usrin[1] = 'O'; - raw("%s\r\n", usrin); + if (!strncmp(string, "PING", 4)) { + string[1] = 'O'; + raw("%s\r\n", string); return; } - if (!strncmp(usrin, "AUTHENTICATE +", 14)) { + if (!strncmp(string, "AUTHENTICATE +", 14)) { raw("AUTHENTICATE %s\r\n", auth); return; } - if (usrin[0] != ':') return; + if (string[0] != ':') return; + + if (olog) log_append(string, olog); - char *prefix = strtok(usrin, " ") + 1, *suffix = strtok(NULL, ":"), + char *tok, *prefix = strtok(string, " ") + 1, *suffix = strtok(NULL, ":"), *message = strtok(NULL, "\r"), *nickname = strtok(prefix, "!"), *command = strtok(suffix, "#& "), *channel = strtok(NULL, " "); int g = gutl, s = gutl - (strlen(nickname) <= gutl ? strlen(nickname) : gutl); + size_t offset = 0; - if (!strncmp(command, "001", 3)) { - raw("JOIN #%s\r\n", chan); + if (!strncmp(command, "001", 3) && chan != NULL) { + for (tok = strtok(chan, ",|"); tok != NULL; tok = strtok(NULL, ",|")) { + strcpy(chan_default, tok); + raw("JOIN #%s\r\n", tok); + } return; } else if (!strncmp(command, "90", 2)) { raw("CAP END\r\n"); } else if (!strncmp(command, "QUIT", 4)) { - printw("%*s<-- \x1b[34;1m%s\x1b[0m", g - 3, "", nickname); + printf("%*s<-- \x1b[34;1m%s\x1b[0m\n", g - 3, "", nickname); + return; } else if (!strncmp(command, "JOIN", 4)) { - printw("%*s--> \x1b[32;1m%s\x1b[0m", g - 3, "", nickname); + printf("%*s--> \x1b[32;1m%s\x1b[0m\n", g - 3, "", nickname); + return; } else if (!strncmp(command, "PRIVMSG", 7) && strcmp(channel, nick) == 0) { - printw("%*s\x1b[43;1m%-.*s\x1b[0m %s", s, "", g, nickname, message); - } else if (!strncmp(command, "PRIVMSG", 7) && strstr(channel, chan) == NULL) { - printw("%*s\x1b[33;1m%-.*s\x1b[0m [\x1b[33m%s\x1b[0m] %s", s, "", \ - g, nickname, channel, message); - } else printw("%*s\x1b[33;1m%-.*s\x1b[0m %s", s, "", g, nickname, message); + printf("%*s\x1b[43;1m%-.*s\x1b[0m ", s, "", g, nickname); + } else if (!strncmp(command, "PRIVMSG", 7) && strstr(channel, chan_default) == NULL) { + printf("%*s\x1b[33;1m%-.*s\x1b[0m [\x1b[33m%s\x1b[0m] ", s, "", \ + g, nickname, channel); + offset += 12 + strlen(channel); + } else printf("%*s\x1b[33;1m%-.*s\x1b[0m ", s, "", g, nickname); + message_wrap((message ? message : " "), offset); } -static char message_buffer[MSG_MAX + 1]; +static char message_buffer[MSG_MAX + 1]; static size_t message_end = 0; static int @@ -243,15 +240,15 @@ handle_user_input(void) { if (usrin[0] == '/') { if (usrin[1] == '#') { - strcpy(chan, usrin + 2); - printf("new channel: #%s\n", chan); + strcpy(chan_default, usrin + 2); + printf("new channel: #%s\n", chan_default); } else if (usrin[1] == '?' && msg_len == 3) { - printf("current channel: #%s\n", chan); + printf("current channel: #%s\n", chan_default); } else { raw("%s\r\n", usrin + 1); } } else { - raw("privmsg #%s :%s\r\n", chan, usrin); + raw("privmsg #%s :%s\r\n", chan_default, usrin); } } @@ -259,7 +256,7 @@ static int keyboard_hit() { struct termios save, tp; - int byteswaiting; + int byteswaiting; tcgetattr(STDIN_FILENO, &tp); save = tp; @@ -280,8 +277,6 @@ main(int argc, char **argv) { switch (cval) { case 'V' : verb = 1; break; case 's' : host = optarg; break; - case 'w' : gutl = atoi(optarg); break; - case 'W' : cmax = atoi(optarg); break; case 'p' : port = optarg; break; case 'r' : real = optarg; break; case 'u' : user = optarg; break; @@ -289,8 +284,10 @@ main(int argc, char **argv) { case 'o' : olog = optarg; break; case 'n' : nick = optarg; break; case 'k' : pass = optarg; break; - case 'c' : strcpy(chan, optarg); break; + case 'c' : chan = optarg; break; case 'x' : inic = optarg; break; + case 'w' : gutl = atoi(optarg); break; + case 'W' : cmax = atoi(optarg); break; case 'v' : printf("kirc %s\n", VERSION); return EXIT_SUCCESS; case 'h' : printf("usage: %s\n", USAGE); return EXIT_SUCCESS; case '?' : return EXIT_FAILURE; -- cgit v1.2.3