hirc

IRC client
Log | Files | Refs

commit e35d7693f100e8135b863ce5a08307c44666fa00
parent 35e3fdea7948608948d3d2444cf7150486e2c4ef
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 17 Apr 2022 13:02:38 +0100

Store more history options in logs (incl HIST_IGN).

Diffstat:
Msrc/hist.c | 35+++++++++++++++++++++++------------
Msrc/struct.h | 26+++++++++++++++-----------
2 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/src/hist.c b/src/hist.c @@ -64,6 +64,9 @@ hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, struct Nick *np; char *nick; + if (!msg) + return NULL; + new = emalloc(sizeof(struct History)); new->prev = new->next = NULL; new->timestamp = timestamp ? timestamp : time(NULL); @@ -124,7 +127,7 @@ hist_add(struct HistInfo *histinfo, struct Ignore *ign; int i; - if (!histinfo) + if (!histinfo || !msg) return NULL; if (options & HIST_MAIN) { @@ -304,12 +307,12 @@ hist_log(struct History *hist) { raw = hist->raw; ret = fprintf(f, - "%lld\t%d\t%d\t%d\t%c\t%s\t%s\t%s\t%s\n", + "v2\t%lld\t%d\t%d\t%d\t%c\t%s\t%s\t%s\t%s\n", (long long)hist->timestamp, hist->activity, - (hist->options & HIST_SHOW) ? 1 : 0, - hist->from ? hist->from->self : 0, /* If from does not exist, it's probably not from us */ - hist->from ? hist->from->priv : ' ', + hist->options, /* write all options - only options ANDing with HIST_LOGACCEPT are read later */ + hist->from ? hist->from->self : 0, /* If from does not exist, it's probably not from us */ + hist->from ? hist->from->priv : ' ', nick, ident, host, raw); if (ret < 0) { @@ -330,10 +333,12 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { char *lines[HIST_MAX]; char buf[2048]; int i, j; - char *tok[9]; - char *save; + char *version; + char *tok[8]; + char *msg; time_t timestamp; enum Activity activity; + enum HistOpt options; char *prefix; size_t len; struct Nick *from; @@ -364,17 +369,23 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { } for (i = 0, prev = NULL; i < HIST_MAX && lines[i]; i++) { - tok[0] = strtok_r(lines[i], "\t", &save); - for (j = 1; j < 9; j++) - tok[j] = strtok_r(NULL, "\t", &save); + if (*lines[i] == 'v') + version = strtok_r(lines[i], "\t", &msg) + 1; /* in future versioning could allow for back-compat */ + else + version = NULL; + tok[0] = strtok_r(lines[i], "\t", &msg); + for (j = 1; j < (sizeof(tok) / sizeof(tok[0])); j++) + tok[j] = strtok_r(NULL, "\t", &msg); /* strtok_r will store remaining text after the tokens in msg. + * This is used instead of a tok[8] as messages can contain tabs. */ if (!tok[0] || !tok[1] || !tok[2] || !tok[3] || !tok[4] || !tok[5] || - !tok[6] || !tok[7] || !tok[8]) + !tok[6] || !tok[7] || !msg) continue; timestamp = (time_t)strtoll(tok[0], NULL, 10); activity = (int)strtol(tok[1], NULL, 10); + options = HIST_RLOG|(strtol(tok[2], NULL, 10) & HIST_LOGACCEPT); len = 1; if (*tok[5] != ' ') @@ -392,7 +403,7 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { if (from) from->self = *tok[3] == '1'; - p = hist_create(hist, from, tok[8], activity, timestamp, HIST_RLOG|(*tok[2] == '1' ? HIST_SHOW : 0)); + p = hist_create(hist, from, msg, activity, timestamp, options); if (!head) head = p; diff --git a/src/struct.h b/src/struct.h @@ -47,19 +47,23 @@ enum Activity { }; enum HistOpt { - HIST_SHOW = 1, /* show in buffer */ - HIST_LOG = 2, /* log to server->logfd */ - HIST_MAIN = 4, /* copy to &main_buf */ - HIST_SELF = 8, /* from = self */ - HIST_TMP = 16, /* purge later */ - HIST_GREP = 32, /* generated by /grep */ - HIST_ERR = 64, /* generated by ui_error and friends */ - HIST_SERR = 128, /* generated by 400-599 numerics (which should be errors) */ - HIST_RLOG = 256, /* messages read from log, useful for clearing the log */ - HIST_IGN = 512, /* added to ignored messages */ - HIST_NIGN = 1024,/* immune to ignoring (SELF_IGNORES_LIST & SELF_ERROR) */ + /* H - options signal hist functions to perform different actions + * C - options are checked later to be handled in different ways + * R - options which are read from logs (in HIST_LOGACCEPT) */ + HIST_SHOW = 1, /* [CR] show in buffer */ + HIST_LOG = 2, /* [H] log to log.dir */ + HIST_MAIN = 4, /* [H] copy to &main_buf */ + HIST_SELF = 8, /* [H] from = self */ + HIST_TMP = 16, /* [C] purge later */ + HIST_GREP = 32, /* [C] generated by /grep */ + HIST_ERR = 64, /* [CR] generated by ui_error and friends */ + HIST_SERR = 128, /* [CR] generated by 400-599 numerics (which should be errors) */ + HIST_RLOG = 256, /* [C] messages read from log, useful for clearing the log */ + HIST_IGN = 512, /* [CR] added to ignored messages */ + HIST_NIGN = 1024,/* [H] immune to ignoring (SELF_IGNORES_LIST & SELF_ERROR) */ HIST_DFL = HIST_SHOW|HIST_LOG, HIST_UI = HIST_SHOW|HIST_TMP|HIST_MAIN, + HIST_LOGACCEPT = HIST_SHOW|HIST_ERR|HIST_SERR|HIST_IGN, HIST_ALL = 0xFFFF };