hirc

IRC client
Log | Files | Refs

commit 0ef2216f3085adafdc47a1bc85d6ff7eb6ff012f
parent 28231193bcde7cf550c6e1709babef9f09764a75
Author: hhvn <dev@hhvn.uk>
Date:   Tue,  8 Feb 2022 12:12:52 +0000

s/handle.c s/serv.c s/commands.c s/hirc.h: move expect functions to serv.c

Diffstat:
Msrc/commands.c | 16++++++++--------
Msrc/handle.c | 61+++++++++++++++++++++----------------------------------------
Msrc/hirc.h | 6+++---
Msrc/serv.c | 17+++++++++++++++++
4 files changed, 49 insertions(+), 51 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -346,7 +346,7 @@ command_ctcp(struct Server *server, char *str) { chan = chan_get(&server->privs, target, -1); /* XXX: if we CTCP a channel, responses should go to that channel. - * This requires more than just handle_expect, so might never be + * This requires more than just expect_set, so might never be * implemented. */ ircprintf(server, "PRIVMSG %s :%c%s%c\r\n", target, 1, ctcp, 1); if (chan) { @@ -410,7 +410,7 @@ command_join(struct Server *server, char *str) { /* Perhaps we should update expect from schedule? * That'd make more sense if different stuff gets * scheduled for events that happen at different times */ - handle_expect(server, Expect_join, str); + expect_set(server, Expect_join, str); } static void @@ -437,7 +437,7 @@ command_part(struct Server *server, char *str) { snprintf(msg, sizeof(msg), "PART %s :%s\r\n", channel, reason ? reason : config_gets("misc.partmessage")); ircprintf(server, "%s", msg); - handle_expect(server, Expect_part, channel); + expect_set(server, Expect_part, channel); } static void @@ -497,7 +497,7 @@ command_mode(struct Server *server, char *str) { if (modes) { ircprintf(server, "MODE %s %s\r\n", channel, modes); } else { - handle_expect(server, Expect_channelmodeis, channel); + expect_set(server, Expect_channelmodeis, channel); ircprintf(server, "MODE %s\r\n", channel); } } @@ -515,7 +515,7 @@ command_nick(struct Server *server, char *str) { } ircprintf(server, "NICK %s\r\n", str); - handle_expect(server, Expect_nicknameinuse, str); + expect_set(server, Expect_nicknameinuse, str); } static void @@ -577,7 +577,7 @@ command_ping(struct Server *server, char *str) { } ircprintf(server, "PING :%s\r\n", str); - handle_expect(server, Expect_pong, str); + expect_set(server, Expect_pong, str); } static void @@ -881,7 +881,7 @@ command_names(struct Server *server, char *str) { } ircprintf(server, "NAMES %s\r\n", channel); - handle_expect(server, Expect_names, channel); + expect_set(server, Expect_names, channel); } static void @@ -932,7 +932,7 @@ command_topic(struct Server *server, char *str) { if (!topic) { ircprintf(server, "TOPIC %s\r\n", channel); - handle_expect(server, Expect_topic, channel); + expect_set(server, Expect_topic, channel); } else ircprintf(server, "TOPIC %s :%s\r\n", channel, topic); } diff --git a/src/handle.c b/src/handle.c @@ -97,9 +97,9 @@ handle_PONG(struct Server *server, struct History *msg) { /* RFC1459 says that PONG should have a list of daemons, * but that's not how PONG seems to work in modern IRC. * Therefore, consider the last parameter as the "message" */ - if (strcmp_n(*(msg->params + len - 1), handle_expect_get(server, Expect_pong)) == 0) { + if (strcmp_n(*(msg->params + len - 1), expect_get(server, Expect_pong)) == 0) { hist_addp(server->history, msg, Activity_status, HIST_DFL); - handle_expect(server, Expect_pong, NULL); + expect_set(server, Expect_pong, NULL); } } @@ -125,11 +125,11 @@ handle_JOIN(struct Server *server, struct History *msg) { hist_addp(chan->history, msg, Activity_status, HIST_SHOW); if (nick_isself(nick)) { - if (strcmp_n(target, handle_expect_get(server, Expect_join)) == 0) + if (strcmp_n(target, expect_get(server, Expect_join)) == 0) ui_select(server, chan); else windows[Win_buflist].refresh = 1; - handle_expect(server, Expect_join, NULL); + expect_set(server, Expect_join, NULL); } else if (selected.channel == chan) { windows[Win_nicklist].refresh = 1; } @@ -152,9 +152,9 @@ handle_PART(struct Server *server, struct History *msg) { if (nick_isself(nick)) { chan_setold(chan, 1); nick_free_list(&chan->nicks); - if (chan == selected.channel && strcmp_n(target, handle_expect_get(server, Expect_part)) == 0) { + if (chan == selected.channel && strcmp_n(target, expect_get(server, Expect_part)) == 0) { ui_select(selected.server, NULL); - handle_expect(server, Expect_part, NULL); + expect_set(server, Expect_part, NULL); } windows[Win_buflist].refresh = 1; } else { @@ -341,9 +341,9 @@ handle_RPL_CHANNELMODEIS(struct Server *server, struct History *msg) { free(chan->mode); chan->mode = estrdup(*(msg->params+3)); - if (handle_expect_get(server, Expect_channelmodeis)) { + if (expect_get(server, Expect_channelmodeis)) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); - handle_expect(server, Expect_channelmodeis, NULL); + expect_set(server, Expect_channelmodeis, NULL); } else { hist_addp(chan->history, msg, Activity_status, HIST_LOG); } @@ -367,7 +367,7 @@ handle_RPL_NAMREPLY(struct Server *server, struct History *msg) { if ((chan = chan_get(&server->channels, target, -1)) == NULL) chan = chan_add(server, &server->channels, target, 0); - if (strcmp_n(target, handle_expect_get(server, Expect_names)) == 0) + if (strcmp_n(target, expect_get(server, Expect_names)) == 0) hist_addp(chan->history, msg, Activity_status, HIST_DFL); else hist_addp(chan->history, msg, Activity_status, HIST_LOG); @@ -408,8 +408,8 @@ handle_RPL_ENDOFNAMES(struct Server *server, struct History *msg) { return; target = *(msg->params+2); - if (strcmp_n(target, handle_expect_get(server, Expect_names)) == 0) - handle_expect(server, Expect_names, NULL); + if (strcmp_n(target, expect_get(server, Expect_names)) == 0) + expect_set(server, Expect_names, NULL); } static void @@ -418,14 +418,14 @@ handle_ERR_NICKNAMEINUSE(struct Server *server, struct History *msg) { hist_addp(server->history, msg, Activity_status, HIST_DFL); - if (handle_expect_get(server, Expect_nicknameinuse) == NULL) { + if (expect_get(server, Expect_nicknameinuse) == NULL) { snprintf(nick, sizeof(nick), "%s_", server->self->nick); nick_free(server->self); server->self = nick_create(nick, ' ', server); server->self->self = 1; ircprintf(server, "NICK %s\r\n", nick); } else { - handle_expect(server, Expect_nicknameinuse, NULL); + expect_set(server, Expect_nicknameinuse, NULL); } } @@ -451,7 +451,7 @@ handle_NICK(struct Server *server, struct History *msg) { nick_free(server->self); server->self = nick_create(newnick, ' ', server); server->self->self = 1; - handle_expect(server, Expect_nicknameinuse, NULL); + expect_set(server, Expect_nicknameinuse, NULL); } for (chan = server->channels; chan; chan = chan->next) { @@ -495,9 +495,9 @@ handle_RPL_NOTOPIC(struct Server *server, struct History *msg) { if ((chan = chan_get(&server->channels, target, -1)) == NULL) return; - if (strcmp_n(target, handle_expect_get(server, Expect_topic)) == 0) { + if (strcmp_n(target, expect_get(server, Expect_topic)) == 0) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); - handle_expect(server, Expect_topic, NULL); + expect_set(server, Expect_topic, NULL); } else { hist_addp(chan->history, msg, Activity_status, HIST_LOG); } @@ -520,10 +520,10 @@ handle_RPL_TOPIC(struct Server *server, struct History *msg) { free(chan->topic); chan->topic = topic ? estrdup(topic) : NULL; - if (strcmp_n(target, handle_expect_get(server, Expect_topic)) == 0) { + if (strcmp_n(target, expect_get(server, Expect_topic)) == 0) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); - handle_expect(server, Expect_topic, NULL); - handle_expect(server, Expect_topicwhotime, target); + expect_set(server, Expect_topic, NULL); + expect_set(server, Expect_topicwhotime, target); } else { hist_addp(chan->history, msg, Activity_status, HIST_LOG); } @@ -542,9 +542,9 @@ handle_RPL_TOPICWHOTIME(struct Server *server, struct History *msg) { if ((chan = chan_get(&server->channels, target, -1)) == NULL) return; - if (strcmp_n(target, handle_expect_get(server, Expect_topicwhotime)) == 0) { + if (strcmp_n(target, expect_get(server, Expect_topicwhotime)) == 0) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); - handle_expect(server, Expect_topicwhotime, NULL); + expect_set(server, Expect_topicwhotime, NULL); } else { hist_addp(chan->history, msg, Activity_status, HIST_LOG); } @@ -563,25 +563,6 @@ handle_RPL_ENDOFMOTD(struct Server *server, struct History *msg) { hist_addp(server->history, msg, Activity_status, HIST_DFL); } -/* Expect stuff should probably be moved to serv.c. - * Also, it might be better to have an enum for all commands and numerics somewhere */ -void -handle_expect(struct Server *server, enum Expect cmd, char *about) { - if (cmd >= Expect_last || cmd < 0 || readingconf) - return; - - free(server->expect[cmd]); - server->expect[cmd] = about ? estrdup(about) : NULL; -} - -char * -handle_expect_get(struct Server *server, enum Expect cmd) { - if (cmd >= Expect_last || cmd < 0) - return NULL; - else - return server->expect[cmd]; -} - void handle_logonly(struct Server *server, struct History *msg) { hist_addp(server->history, msg, Activity_status, HIST_LOG); diff --git a/src/hirc.h b/src/hirc.h @@ -108,16 +108,16 @@ int serv_poll(struct Server **head, int timeout); int serv_remove(struct Server **head, char *name); int serv_selected(struct Server *server); void serv_disconnect(struct Server *server, int reconnect, char *msg); +int serv_ischannel(struct Server *server, char *str); char * support_get(struct Server *server, char *key); void support_set(struct Server *server, char *key, char *value); void schedule_push(struct Server *server, char *tmsg, char *msg); char * schedule_pull(struct Server *server, char *tmsg); -int serv_ischannel(struct Server *server, char *str); +void expect_set(struct Server *server, enum Expect cmd, char *about); +char * expect_get(struct Server *server, enum Expect cmd); /* handle.c */ void handle(struct Server *server, char *msg); -void handle_expect(struct Server *server, enum Expect cmd, char *about); -char * handle_expect_get(struct Server *server, enum Expect cmd); /* ui.c */ void ui_init(void); diff --git a/src/serv.c b/src/serv.c @@ -489,3 +489,20 @@ schedule_pull(struct Server *server, char *tmsg) { ret = NULL; return NULL; } + +void +expect_set(struct Server *server, enum Expect cmd, char *about) { + if (cmd >= Expect_last || cmd < 0 || readingconf) + return; + + free(server->expect[cmd]); + server->expect[cmd] = about ? estrdup(about) : NULL; +} + +char * +expect_get(struct Server *server, enum Expect cmd) { + if (cmd >= Expect_last || cmd < 0) + return NULL; + else + return server->expect[cmd]; +}