Bump ParamCap to 254

Apparently IRCds have decided that the 15-parameter limit doesn't matter
anymore. 254 is the maximum number of single-byte parameters (following
a single-byte command) which fit in a 512-byte CR-LF-terminated line.
When everyone decides that the 512-byte line length limit doesn't matter
either, I will delete my software and people can use some JavaScript
garbage instead.

This makes struct Message 2080 bytes, but there's only ever one or two
of them around at once. Avoid passing it by value to handle.
master
C. McEnroe 2020-06-24 13:36:24 -04:00
parent 4fb94a1a22
commit 94fb9798c5
5 changed files with 15 additions and 16 deletions

2
chat.c
View File

@ -337,7 +337,7 @@ int main(int argc, char *argv[]) {
.cmd = "QUIT", .cmd = "QUIT",
.params[0] = self.quit, .params[0] = self.quit,
}; };
handle(msg); handle(&msg);
ircClose(); ircClose();
logClose(); logClose();

4
chat.h
View File

@ -155,7 +155,7 @@ enum Tag {
TagCap, TagCap,
}; };
enum { ParamCap = 15 }; enum { ParamCap = 254 };
struct Message { struct Message {
char *tags[TagCap]; char *tags[TagCap];
char *nick; char *nick;
@ -204,7 +204,7 @@ extern struct Replies {
uint whois; uint whois;
} replies; } replies;
void handle(struct Message msg); void handle(struct Message *msg);
void command(uint id, char *input); void command(uint id, char *input);
const char *commandIsPrivmsg(uint id, const char *input); const char *commandIsPrivmsg(uint id, const char *input);
const char *commandIsNotice(uint id, const char *input); const char *commandIsNotice(uint id, const char *input);

View File

@ -61,7 +61,7 @@ static void echoMessage(char *cmd, uint id, char *params) {
.params[0] = idNames[id], .params[0] = idNames[id],
.params[1] = params, .params[1] = params,
}; };
handle(msg); handle(&msg);
} }
static void splitMessage(char *cmd, uint id, char *params) { static void splitMessage(char *cmd, uint id, char *params) {
@ -213,9 +213,7 @@ static void channelListMode(uint id, char pm, char l, const char *params) {
for (const char *ch = params; *ch; ++ch) { for (const char *ch = params; *ch; ++ch) {
if (*ch == ' ') count++; if (*ch == ' ') count++;
} }
char modes[ParamCap - 2 + 1] = { char modes[13 + 1] = { l, l, l, l, l, l, l, l, l, l, l, l, l, '\0' };
l, l, l, l, l, l, l, l, l, l, l, l, l, '\0'
};
ircFormat("MODE %s %c%.*s %s\r\n", idNames[id], pm, count, modes, params); ircFormat("MODE %s %c%.*s %s\r\n", idNames[id], pm, count, modes, params);
} }

View File

@ -1228,17 +1228,17 @@ static int compar(const void *cmd, const void *_handler) {
return strcmp(cmd, handler->cmd); return strcmp(cmd, handler->cmd);
} }
void handle(struct Message msg) { void handle(struct Message *msg) {
if (!msg.cmd) return; if (!msg->cmd) return;
if (msg.tags[TagPos]) { if (msg->tags[TagPos]) {
self.pos = strtoull(msg.tags[TagPos], NULL, 10); self.pos = strtoull(msg->tags[TagPos], NULL, 10);
} }
const struct Handler *handler = bsearch( const struct Handler *handler = bsearch(
msg.cmd, Handlers, ARRAY_LEN(Handlers), sizeof(*handler), compar msg->cmd, Handlers, ARRAY_LEN(Handlers), sizeof(*handler), compar
); );
if (handler) { if (handler) {
handler->fn(&msg); handler->fn(msg);
} else if (strcmp(msg.cmd, "400") >= 0 && strcmp(msg.cmd, "599") <= 0) { } else if (strcmp(msg->cmd, "400") >= 0 && strcmp(msg->cmd, "599") <= 0) {
handleErrorGeneric(&msg); handleErrorGeneric(msg);
} }
} }

3
irc.c
View File

@ -279,7 +279,8 @@ void ircRecv(void) {
if (!crlf) break; if (!crlf) break;
*crlf = '\0'; *crlf = '\0';
debug(">>", line); debug(">>", line);
handle(parse(line)); struct Message msg = parse(line);
handle(&msg);
line = crlf + 2; line = crlf + 2;
} }