hirc

IRC client
Log | Files | Refs

commit e582dd50ad0c78089b214a1732cb56445caf2bf7
parent 3670e6e98a528d7f9c93cfb8a2628f9bd7d752de
Author: hhvn <dev@hhvn.uk>
Date:   Mon,  1 Nov 2021 20:10:29 +0000

{hist,main,ui,serv,handle,commands}.c {hirc,struct}.h: hist functions use histinfo->server

Diffstat:
Mcommands.c | 2+-
Mhandle.c | 30+++++++++++++++---------------
Mhirc.h | 8++++----
Mhist.c | 28++++++++++++++--------------
Mmain.c | 4++--
Mserv.c | 10+++++-----
Mstruct.h | 2+-
Mui.c | 8++++----
8 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/commands.c b/commands.c @@ -16,7 +16,7 @@ command_eval(char *str) { // TODO: message splitting snprintf(msg, sizeof(msg), "PRIVMSG %s :%s", selected.channel->name, str); ircprintf(selected.server, "%s\r\n", msg); - hist_format(selected.server, selected.channel->history, Activity_self, HIST_SHOW|HIST_LOG|HIST_SELF, msg); + hist_format(selected.channel->history, Activity_self, HIST_SHOW|HIST_LOG|HIST_SELF, msg); } else ui_error("channel not selected, message ignored", NULL); diff --git a/handle.c b/handle.c @@ -48,8 +48,8 @@ handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) { if (nick_get(&chan->nicks, nick->nick) == NULL) nick_add(&chan->nicks, *params, ' ', server); - hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); - hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); + hist_add(server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); + hist_add(chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); if (nick_isself(nick)) ui_select(server, chan); @@ -84,8 +84,8 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) { windows[Win_nicklist].redraw = 1; } - hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); - hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); + hist_add(server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); + hist_add(chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); nick_free(nick); } @@ -103,11 +103,11 @@ handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) { (void)0; } - hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); + hist_add(server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); for (chan = server->channels; chan; chan = chan->next) { if (nick_get(&chan->nicks, nick->nick) != NULL) { nick_remove(&chan->nicks, nick->nick); - hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); + hist_add(chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); if (chan == selected.channel) windows[Win_nicklist].redraw = 1; } @@ -134,27 +134,27 @@ handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp nick = nick_create(*params, ' ', server); if (strchr(nick->nick, '.')) { /* it's a server */ - hist_add(server, server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); } else if (strcmp(target, server->self->nick) == 0) { /* it's messaging me */ if ((priv = chan_get(&server->privs, nick->nick, -1)) == NULL) priv = chan_add(server, &server->privs, nick->nick); chan_setold(priv, 0); - hist_add(server, priv->history, nick, msg, params, act_direct, timestamp, HIST_DFL); + hist_add(priv->history, nick, msg, params, act_direct, timestamp, HIST_DFL); } else if (nick_isself(nick) && !chrcmp(*target, "#&!+")) { /* i'm messaging someone */ if ((priv = chan_get(&server->privs, target, -1)) == NULL) priv = chan_add(server, &server->privs, target); chan_setold(priv, 0); - hist_add(server, priv->history, nick, msg, params, act_regular, timestamp, HIST_DFL); + hist_add(priv->history, nick, msg, params, act_regular, timestamp, HIST_DFL); } else { /* message to a channel */ if ((chan = chan_get(&server->channels, target, -1)) == NULL) chan = chan_add(server, &server->channels, target); - hist_add(server, chan->history, nick, msg, params, act_regular, timestamp, HIST_DFL); + hist_add(chan->history, nick, msg, params, act_regular, timestamp, HIST_DFL); } nick_free(nick); @@ -164,7 +164,7 @@ void handle_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp) { char *key, *value; - hist_add(server, server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); if (**params == ':') params++; @@ -239,7 +239,7 @@ void handle_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp) { char nick[64]; /* should be limited to 9 chars, but newer servers *shrug*/ - hist_add(server, server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); snprintf(nick, sizeof(nick), "%s_", server->self->nick); nick_free(server->self); server->self = nick_create(nick, ' ', server); @@ -258,7 +258,7 @@ handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) { return; nick = nick_create(*params, ' ', server); - hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, nick, msg, params, Activity_status, timestamp, HIST_DFL); newnick = *(params+2); if (strcmp(nick->nick, newnick) == 0) @@ -298,7 +298,7 @@ handle(int rfd, struct Server *server) { if (!read_line(rfd, buf, sizeof(buf))) { if (buf[0] == EOF || buf[0] == 3 || buf[0] == 4) { serv_disconnect(server, 1); - hist_format(server, server->history, Activity_error, HIST_SHOW, + hist_format(server->history, Activity_error, HIST_SHOW, "SELF_CONNECTLOST %s %s %s :EOF received", server->name, server->host, server->port); } @@ -335,5 +335,5 @@ handle(int rfd, struct Server *server) { } /* add it to server->history if there is no handler */ - hist_add(server, server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); } diff --git a/hirc.h b/hirc.h @@ -50,13 +50,13 @@ void nick_sort(struct Nick **head, struct Server *server); /* hist.c */ void hist_free(struct History *history); void hist_free_list(struct HistInfo *histinfo); -struct History *hist_create(struct Server *server, struct Nick *from, char *msg, +struct History *hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, char **params, enum Activity activity, time_t timestamp, enum HistOpt options); -struct History *hist_add(struct Server *server, struct HistInfo *histinfo, +struct History *hist_add(struct HistInfo *histinfo, struct Nick *from, char *msg, char **params, enum Activity activity, time_t timestamp, enum HistOpt options); -struct History *hist_format(struct Server *server, struct HistInfo *history, - enum Activity activity, enum HistOpt options, char *format, ...); +struct History *hist_format(struct HistInfo *history, enum Activity activity, + enum HistOpt options, char *format, ...); int hist_len(struct History **history); int hist_log(char *msg, struct Nick *from, time_t timestamp, struct Server *server); diff --git a/hist.c b/hist.c @@ -33,7 +33,7 @@ hist_free_list(struct HistInfo *histinfo) { } struct History * -hist_create(struct Server *server, struct Nick *from, char *msg, +hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, char **params, enum Activity activity, time_t timestamp, enum HistOpt options) { struct History *new; @@ -45,12 +45,12 @@ hist_create(struct Server *server, struct Nick *from, char *msg, new->raw = estrdup(msg); new->params = params; new->options = options; - new->origin = server; + new->origin = histinfo; if (from) { - new->from = nick_dup(from, server); + new->from = nick_dup(from, histinfo->server); } else if (**params == ':') { - new->from = nick_create(*params, ' ', server); + new->from = nick_create(*params, ' ', histinfo->server); } else { new->from = NULL; } @@ -59,23 +59,23 @@ hist_create(struct Server *server, struct Nick *from, char *msg, } struct History * -hist_add(struct Server *server, struct HistInfo *histinfo, struct Nick *from, +hist_add(struct HistInfo *histinfo, struct Nick *from, char *msg, char **params, enum Activity activity, time_t timestamp, enum HistOpt options) { struct History *new, *p; int i; if (options & HIST_MAIN) { - if (histinfo->history != main_buf->history) - hist_add(server, main_buf, from, msg, params, activity, timestamp, HIST_SHOW); + if (histinfo != main_buf) + hist_add(main_buf, from, msg, params, activity, timestamp, HIST_SHOW); else ui_error("HIST_MAIN specified, but history is &main_buf", NULL); } - if (options & HIST_SELF && server) - from = server->self; + if (options & HIST_SELF && histinfo->server) + from = histinfo->server->self; - new = hist_create(server, from, msg, params, activity, timestamp, options); + new = hist_create(histinfo, from, msg, params, activity, timestamp, options); if (histinfo && options & HIST_SHOW && activity > histinfo->activity) histinfo->activity = activity; @@ -102,8 +102,8 @@ hist_add(struct Server *server, struct HistInfo *histinfo, struct Nick *from, windows[Win_main].redraw = 1; if (options & HIST_LOG) { - if (server) - hist_log(new->raw, new->from, new->timestamp, server); + if (histinfo->server) + hist_log(new->raw, new->from, new->timestamp, histinfo->server); else ui_error("HIST_LOG specified, but server is NULL", NULL); } @@ -112,7 +112,7 @@ hist_add(struct Server *server, struct HistInfo *histinfo, struct Nick *from, } struct History * -hist_format(struct Server *server, struct HistInfo *histinfo, enum Activity activity, enum HistOpt options, char *format, ...) { +hist_format(struct HistInfo *histinfo, enum Activity activity, enum HistOpt options, char *format, ...) { char msg[1024], **params; va_list ap; @@ -122,7 +122,7 @@ hist_format(struct Server *server, struct HistInfo *histinfo, enum Activity acti params = param_create(msg); - return hist_add(server, histinfo, NULL, msg, params, Activity_status, 0, options); + return hist_add(histinfo, NULL, msg, params, Activity_status, 0, options); } int diff --git a/main.c b/main.c @@ -125,7 +125,7 @@ ircprintf(struct Server *server, char *format, ...) { if (ret == -1 && server->status == ConnStatus_connected) { serv_disconnect(server, 1); - hist_format(server, server->history, Activity_error, HIST_SHOW, + hist_format(server->history, Activity_error, HIST_SHOW, "SELF_CONNECTLOST %s %s %s :%s", server->name, server->host, server->port, strerror(errno)); } else if (ret == -1 && server->status != ConnStatus_connecting) { @@ -218,7 +218,7 @@ main(int argc, char **argv) { /* haven't gotten a response in pinginact seconds since * sending ping, this connexion is probably dead now */ serv_disconnect(sp, 1); - hist_format(sp, sp->history, Activity_error, HIST_SHOW, + hist_format(sp->history, Activity_error, HIST_SHOW, "SELF_CONNECTLOST %s %s %s :No ping reply in %d seconds", sp->name, sp->host, sp->port, pinginact); } else if (sp->status == ConnStatus_notconnected && sp->reconnect && diff --git a/serv.c b/serv.c @@ -105,7 +105,7 @@ serv_create(char *name, char *host, char *port, char *nick, tls_config_free(conf); #else if (tls) - hist_format(server, server->history, Activity_error, HIST_SHOW, + hist_format(server->history, Activity_error, HIST_SHOW, "SELF_TLSNOTCOMPILED %s", server->name); #endif /* TLS */ @@ -193,7 +193,7 @@ serv_connect(struct Server *server) { int fd, ret, serrno; server->status = ConnStatus_connecting; - hist_format(server, server->history, Activity_status, HIST_SHOW|HIST_MAIN, + hist_format(server->history, Activity_status, HIST_SHOW|HIST_MAIN, "SELF_CONNECTING %s %s", server->host, server->port); memset(&hints, 0, sizeof(hints)); @@ -201,13 +201,13 @@ serv_connect(struct Server *server) { hints.ai_socktype = SOCK_STREAM; if ((ret = getaddrinfo(server->host, server->port, &hints, &ai)) != 0 || ai == NULL) { - hist_format(server, server->history, Activity_error, HIST_SHOW, + hist_format(server->history, Activity_error, HIST_SHOW, "SELF_LOOKUPFAIL %s %s %s :%s", server->name, server->host, server->port, gai_strerror(ret)); goto fail; } if ((fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1 || connect(fd, ai->ai_addr, ai->ai_addrlen) == -1) { - hist_format(server, server->history, Activity_error, HIST_SHOW, + hist_format(server->history, Activity_error, HIST_SHOW, "SELF_CONNECTFAIL %s %s %s :%s", server->name, server->host, server->port, strerror(errno)); goto fail; @@ -216,7 +216,7 @@ serv_connect(struct Server *server) { server->connectfail = 0; server->status = ConnStatus_connected; server->rfd = server->wfd = fd; - hist_format(server, server->history, Activity_status, HIST_SHOW|HIST_MAIN, + hist_format(server->history, Activity_status, HIST_SHOW|HIST_MAIN, "SELF_CONNECTED %s %s %s", server->name, server->host, server->port); freeaddrinfo(ai); diff --git a/struct.h b/struct.h @@ -43,7 +43,7 @@ struct History { enum HistOpt options; char *raw; char **params; - struct Server *origin; + struct HistInfo *origin; struct Nick *from; struct History *next; }; diff --git a/ui.c b/ui.c @@ -32,14 +32,14 @@ ui_error_(char *file, int line, char *format, ...) { vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); - hist_format(NULL, main_buf, Activity_error, HIST_SHOW, + hist_format(main_buf, Activity_error, HIST_SHOW, "SELF_ERROR %s %d :%s", file, line, msg); } void ui_perror_(char *file, int line, char *str) { - hist_format(NULL, main_buf, Activity_error, HIST_SHOW, + hist_format(main_buf, Activity_error, HIST_SHOW, "SELF_ERROR %s %d :%s: %s", file, line, str, strerror(errno)); } @@ -47,14 +47,14 @@ ui_perror_(char *file, int line, char *str) { #ifdef TLS void ui_tls_config_error_(char *file, int line, struct tls_config *config, char *str) { - hist_format(NULL, main_buf, Activity_error, HIST_SHOW, + hist_format(main_buf, Activity_error, HIST_SHOW, "SELF_ERROR %s %d :%s: %s", file, line, str, tls_config_error(config)); } void ui_tls_error_(char *file, int line, struct tls *ctx, char *str) { - hist_format(NULL, main_buf, Activity_error, HIST_SHOW, + hist_format(main_buf, Activity_error, HIST_SHOW, "SELF_ERROR %s %d :%s: %s", file, line, str, tls_error(ctx)); }