diff options
-rw-r--r-- | bounce.h | 18 | ||||
-rw-r--r-- | client.c | 24 | ||||
-rw-r--r-- | state.c | 60 |
3 files changed, 51 insertions, 51 deletions
diff --git a/bounce.h b/bounce.h index fd64a27..7b9f4f8 100644 --- a/bounce.h +++ b/bounce.h @@ -32,24 +32,24 @@ bool verbose; enum { ParamCap = 15 }; -struct Command { +struct Message { const char *origin; - const char *name; + const char *cmd; const char *params[ParamCap]; }; -static inline struct Command parse(char *line) { - struct Command cmd = {0}; - if (line[0] == ':') cmd.origin = 1 + strsep(&line, " "); - cmd.name = strsep(&line, " "); +static inline struct Message parse(char *line) { + struct Message msg = {0}; + if (line[0] == ':') msg.origin = 1 + strsep(&line, " "); + msg.cmd = strsep(&line, " "); for (size_t i = 0; line && i < ParamCap; ++i) { if (line[0] == ':') { - cmd.params[i] = &line[1]; + msg.params[i] = &line[1]; break; } - cmd.params[i] = strsep(&line, " "); + msg.params[i] = strsep(&line, " "); } - return cmd; + return msg; } void listenConfig(const char *cert, const char *priv); diff --git a/client.c b/client.c index 442ed2d..185a277 100644 --- a/client.c +++ b/client.c @@ -98,25 +98,25 @@ static void passRequired(struct Client *client) { client->close = true; } -typedef void Handler(struct Client *client, struct Command cmd); +typedef void Handler(struct Client *client, struct Message msg); -static void handleNick(struct Client *client, struct Command cmd) { - (void)cmd; +static void handleNick(struct Client *client, struct Message msg) { + (void)msg; client->need &= ~NeedNick; if (!client->need) stateSync(client); if (client->need == NeedPass) passRequired(client); } -static void handleUser(struct Client *client, struct Command cmd) { - (void)cmd; +static void handleUser(struct Client *client, struct Message msg) { + (void)msg; // TODO: Identify client by username. client->need &= ~NeedUser; if (!client->need) stateSync(client); if (client->need == NeedPass) passRequired(client); } -static void handlePass(struct Client *client, struct Command cmd) { - if (!cmd.params[0] || strcmp(clientPass, cmd.params[0])) { +static void handlePass(struct Client *client, struct Message msg) { + if (!msg.params[0] || strcmp(clientPass, msg.params[0])) { passRequired(client); } else { client->need &= ~NeedPass; @@ -124,7 +124,7 @@ static void handlePass(struct Client *client, struct Command cmd) { } } -static void handleCap(struct Client *client, struct Command cmd) { +static void handleCap(struct Client *client, struct Message msg) { // TODO... } @@ -139,16 +139,16 @@ static const struct { }; static void clientParse(struct Client *client, char *line) { - struct Command cmd = parse(line); - if (!cmd.name) { + struct Message msg = parse(line); + if (!msg.cmd) { // FIXME: Identify client in message. warnx("no command"); client->close = true; return; } for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) { - if (strcmp(cmd.name, Handlers[i].cmd)) continue; - Handlers[i].fn(client, cmd); + if (strcmp(msg.cmd, Handlers[i].cmd)) continue; + Handlers[i].fn(client, msg); break; } } diff --git a/state.c b/state.c index 161fd90..48f7185 100644 --- a/state.c +++ b/state.c @@ -66,46 +66,46 @@ static void supportSet(const char *token) { set(&support.tokens[support.len++], token); } -typedef void Handler(struct Command); +typedef void Handler(struct Message); -static void handleCap(struct Command cmd) { - bool ack = cmd.params[1] && !strcmp(cmd.params[1], "ACK"); - bool sasl = cmd.params[2] && !strcmp(cmd.params[2], "sasl"); +static void handleCap(struct Message msg) { + bool ack = msg.params[1] && !strcmp(msg.params[1], "ACK"); + bool sasl = msg.params[2] && !strcmp(msg.params[2], "sasl"); if (!ack || !sasl) errx(EX_CONFIG, "server does not support SASL"); serverAuth(); } -static void handleReplyWelcome(struct Command cmd) { - if (!cmd.params[1]) errx(EX_PROTOCOL, "RPL_WELCOME without message"); - set(&intro.origin, cmd.origin); - set(&nick, cmd.params[0]); - set(&intro.welcome, cmd.params[1]); +static void handleReplyWelcome(struct Message msg) { + if (!msg.params[1]) errx(EX_PROTOCOL, "RPL_WELCOME without message"); + set(&intro.origin, msg.origin); + set(&nick, msg.params[0]); + set(&intro.welcome, msg.params[1]); } -static void handleReplyYourHost(struct Command cmd) { - if (!cmd.params[1]) errx(EX_PROTOCOL, "RPL_YOURHOST without message"); - set(&intro.yourHost, cmd.params[1]); +static void handleReplyYourHost(struct Message msg) { + if (!msg.params[1]) errx(EX_PROTOCOL, "RPL_YOURHOST without message"); + set(&intro.yourHost, msg.params[1]); } -static void handleReplyCreated(struct Command cmd) { - if (!cmd.params[1]) errx(EX_PROTOCOL, "RPL_CREATED without message"); - set(&intro.created, cmd.params[1]); +static void handleReplyCreated(struct Message msg) { + if (!msg.params[1]) errx(EX_PROTOCOL, "RPL_CREATED without message"); + set(&intro.created, msg.params[1]); } -static void handleReplyMyInfo(struct Command cmd) { - if (!cmd.params[4]) errx(EX_PROTOCOL, "RPL_MYINFO without 4 parameters"); - set(&intro.myInfo[0], cmd.params[1]); - set(&intro.myInfo[1], cmd.params[2]); - set(&intro.myInfo[2], cmd.params[3]); - set(&intro.myInfo[3], cmd.params[4]); +static void handleReplyMyInfo(struct Message msg) { + if (!msg.params[4]) errx(EX_PROTOCOL, "RPL_MYINFO without 4 parameters"); + set(&intro.myInfo[0], msg.params[1]); + set(&intro.myInfo[1], msg.params[2]); + set(&intro.myInfo[2], msg.params[3]); + set(&intro.myInfo[3], msg.params[4]); } -static void handleReplyISupport(struct Command cmd) { +static void handleReplyISupport(struct Message msg) { for (size_t i = 1; i < ParamCap; ++i) { - if (!cmd.params[i] || strchr(cmd.params[i], ' ')) break; - supportSet(cmd.params[i]); + if (!msg.params[i] || strchr(msg.params[i], ' ')) break; + supportSet(msg.params[i]); } } -static void handleError(struct Command cmd) { - errx(EX_UNAVAILABLE, "%s", cmd.params[0]); +static void handleError(struct Message msg) { + errx(EX_UNAVAILABLE, "%s", msg.params[0]); } static const struct { @@ -122,11 +122,11 @@ static const struct { }; void stateParse(char *line) { - struct Command cmd = parse(line); - if (!cmd.name) errx(EX_PROTOCOL, "no command"); + struct Message msg = parse(line); + if (!msg.cmd) errx(EX_PROTOCOL, "no command"); for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) { - if (strcmp(cmd.name, Handlers[i].cmd)) continue; - Handlers[i].fn(cmd); + if (strcmp(msg.cmd, Handlers[i].cmd)) continue; + Handlers[i].fn(msg); break; } } |