From 4f7ed027b4c4c33dfee8197cc42ce4066722c5aa Mon Sep 17 00:00:00 2001 From: Geo Date: Wed, 15 May 2024 17:30:28 -0400 Subject: [PATCH] Trying out removing m->user --- src/chan.h | 2 +- src/chanprog.c | 6 +++--- src/mod/channels.mod/tclchan.c | 2 +- src/mod/channels.mod/userchan.c | 6 +----- src/mod/irc.mod/chan.c | 27 +++++++++++---------------- src/mod/irc.mod/cmdsirc.c | 25 +++++++++++++------------ src/mod/irc.mod/irc.c | 6 ++---- src/mod/irc.mod/mode.c | 13 +++---------- src/mod/irc.mod/tclirc.c | 33 +++++++++++++++------------------ src/userrec.c | 9 +++++---- 10 files changed, 55 insertions(+), 74 deletions(-) diff --git a/src/chan.h b/src/chan.h index 19a56e5a1..417e55990 100644 --- a/src/chan.h +++ b/src/chan.h @@ -50,7 +50,7 @@ typedef struct memstruct { time_t split; /* in case they were just netsplit */ time_t last; /* for measuring idle time */ time_t delay; /* for delayed autoop */ - struct userrec *user; +// struct userrec *user; int tried_getuser; struct memstruct *next; } memberlist; diff --git a/src/chanprog.c b/src/chanprog.c index e8205f17b..3cdbf63c7 100644 --- a/src/chanprog.c +++ b/src/chanprog.c @@ -136,7 +136,8 @@ struct userrec *check_chanlist(const char *host) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) if (!rfc_casecmp(nick, m->nick) && !strcasecmp(uhost, m->userhost)) - return m->user; +//XXXXXXXX loop? Does this whole func come out? + return get_user_from_channel(m); return NULL; } @@ -152,7 +153,6 @@ void clear_chanlist(void) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - m->user = NULL; m->tried_getuser = 0; } } @@ -170,7 +170,6 @@ void clear_chanlist_member(const char *nick) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) if (!rfc_casecmp(m->nick, nick)) { - m->user = NULL; m->tried_getuser = 0; break; } @@ -190,6 +189,7 @@ void set_chanlist(const char *host, struct userrec *rec) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) if (!rfc_casecmp(nick, m->nick) && !strcasecmp(uhost, m->userhost)) +//XXXXXXXX Does this whole func come out? m->user = rec; } diff --git a/src/mod/channels.mod/tclchan.c b/src/mod/channels.mod/tclchan.c index 512702703..53ea7e1ad 100644 --- a/src/mod/channels.mod/tclchan.c +++ b/src/mod/channels.mod/tclchan.c @@ -1731,7 +1731,7 @@ static int tcl_do_masklist(maskrec *m, Tcl_Interp *irp) list[3] = ts1; snprintf(ts2, sizeof ts2, "%" PRId64, (int64_t) m->lastactive); list[4] = ts2; - list[5] = m->user; + list[5] = get_user_from_channel(m); p = Tcl_Merge(6, list); Tcl_AppendElement(irp, p); Tcl_Free((char *) p); diff --git a/src/mod/channels.mod/userchan.c b/src/mod/channels.mod/userchan.c index 531a802bf..222b1da85 100644 --- a/src/mod/channels.mod/userchan.c +++ b/src/mod/channels.mod/userchan.c @@ -1270,11 +1270,7 @@ static int expired_mask(struct chanset_t *chan, char *who) * present in the channel and has op. */ - if (m->user) - u = m->user; - else { - u = get_user_from_channel(m); - } + u = get_user_from_channel(m); /* Do not expire masks set by bots. */ if (u && u->flags & USER_BOT) return 0; diff --git a/src/mod/irc.mod/chan.c b/src/mod/irc.mod/chan.c index c3d01cc59..cdd8483d1 100644 --- a/src/mod/irc.mod/chan.c +++ b/src/mod/irc.mod/chan.c @@ -110,7 +110,7 @@ static void setaccount(char *nick, char *account) } else { putlog(LOG_MODES, chan->dname, "%s!%s logged in to their account %s", nick, m->userhost, account); } - check_tcl_account(m->nick, m->userhost, m->user, chan->dname, account); + check_tcl_account(m->nick, m->userhost, get_user_from_channel(m), chan->dname, account); } strlcpy(m->account, account, sizeof m->account); } @@ -426,7 +426,7 @@ static void kick_all(struct chanset_t *chan, char *hostmask, char *comment, flushed = 0; kicknick[0] = 0; for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - get_user_flagrec(m->user ? m->user : get_user_from_channel(m), &fr, chan->dname); + get_user_flagrec(get_user_from_channel(m), &fr, chan->dname); if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) && match_addr(hostmask, s) && !chan_sentkick(m) && !match_my_nick(m->nick) && !chan_issplit(m) && @@ -474,7 +474,7 @@ static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick) if (match_addr(b->mask, user)) { struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 }; char c[512]; /* The ban comment. */ - get_user_flagrec(m->user ? m->user : get_user_from_channel(m), &fr, + get_user_flagrec(get_user_from_channel(m), &fr, chan->dname); if (!glob_friend(fr) && !chan_friend(fr)) { add_mode(chan, '-', 'o', nick); /* Guess it can't hurt. */ @@ -866,7 +866,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { check_exemptlist(chan, s); quickban(chan, m->userhost); - p = get_user(&USERENTRY_COMMENT, m->user); + p = get_user(&USERENTRY_COMMENT, get_user_from_channel(m)); dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick, p ? p : IRC_POLITEKICK); m->flags |= SENTKICK; @@ -885,7 +885,7 @@ static void check_this_user(char *hand, int delete, char *host) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = m->user ? m->user : get_user_from_channel(m); + u = get_user_from_channel(m); if ((u && !strcasecmp(u->handle, hand) && delete < 2) || (!u && delete == 2 && match_addr(host, s))) { u = delete ? NULL : u; @@ -910,11 +910,11 @@ static void recheck_channel(struct chanset_t *chan, int dobans) stacking++; /* Okay, sort through who needs to be deopped. */ for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if (!m->user && !m->tried_getuser) { + if (!get_user_from_channel(m) && !m->tried_getuser) { m->tried_getuser = 1; - m->user = get_user_from_channel(m); + u = get_user_from_channel(m); } - get_user_flagrec(m->user, &fr, chan->dname); + get_user_flagrec(u, &fr, chan->dname); if (glob_bot(fr) && chan_hasop(m) && !match_my_nick(m->nick)) stop_reset = 1; /* Perhaps we were halfop and tried to halfop/kick the user earlier but @@ -1078,7 +1078,6 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, simple_sprintf(m->userhost, "%s@%s", user, host); simple_sprintf(userhost, "%s!%s", nick, m->userhost); /* Combine n!u@h */ - m->user = NULL; /* No handle match (yet) */ if (match_my_nick(nick)) /* Is it me? */ strcpy(botuserhost, m->userhost); /* Yes, save my own userhost */ m->flags |= WHO_SYNCED; @@ -1109,7 +1108,6 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, if (chan->need_op[0]) do_tcl("need-op", chan->need_op); } - m->user = get_user_from_channel(m); /* Update accountname in channel records, 0 means logged out */ /* A 0 is not a change from "" */ @@ -2053,7 +2051,6 @@ static int gotjoin(char *from, char *channame) m->last = now; m->delay = 0L; m->flags = (chan_hasop(m) ? WASOP : 0) | (chan_hashalfop(m) ? WASHALFOP : 0); - m->user = u; set_handle_laston(chan->dname, u, now); m->flags |= STOPWHO; putlog(LOG_JOIN, chan->dname, "%s (%s) returned to %s.", nick, uhost, @@ -2069,7 +2066,6 @@ static int gotjoin(char *from, char *channame) m->delay = 0L; strlcpy(m->nick, nick, sizeof m->nick); strlcpy(m->userhost, uhost, sizeof m->userhost); - m->user = u; m->flags |= STOPWHO; if (extjoin) { @@ -2091,7 +2087,6 @@ static int gotjoin(char *from, char *channame) /* The record saved in the channel record always gets updated, * so we can use that. */ - u = m->user; if (match_my_nick(nick)) { /* It was me joining! Need to update the channel record with the @@ -2122,9 +2117,9 @@ static int gotjoin(char *from, char *channame) if (u) { struct laston_info *li = 0; - cr = get_chanrec(m->user, chan->dname); + cr = get_chanrec(get_user_from_channel(m), chan->dname); if (!cr && no_chanrec_info) - li = get_user(&USERENTRY_LASTON, m->user); + li = get_user(&USERENTRY_LASTON, get_user_from_channel(m)); if (channel_greet(chan) && use_info && ((cr && now - cr->laston > wait_info) || (no_chanrec_info && (!li || now - li->laston > wait_info)))) { @@ -2182,7 +2177,7 @@ static int gotjoin(char *from, char *channame) (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { check_exemptlist(chan, from); quickban(chan, from); - p = get_user(&USERENTRY_COMMENT, m->user); + p = get_user(&USERENTRY_COMMENT, get_user_from_channel(m)); dprintf(DP_MODE, "KICK %s %s :%s\n", chname, nick, (p && (p[0] != '@')) ? p : IRC_COMMENTKICK); m->flags |= SENTKICK; diff --git a/src/mod/irc.mod/cmdsirc.c b/src/mod/irc.mod/cmdsirc.c index a06b1a51e..8ec56b71a 100644 --- a/src/mod/irc.mod/cmdsirc.c +++ b/src/mod/irc.mod/cmdsirc.c @@ -379,7 +379,7 @@ static void cmd_halfop(struct userrec *u, int idx, char *par) get_user_flagrec(dcc[idx].user, &user, chan->dname); m = ismember(chan, nick); if (m && !chan_op(user) && (!glob_op(user) || chan_deop(user))) { - u2 = m->user ? m->user : get_user_from_channel(m); + u2 = get_user_from_channel(m); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_halfop(user) && (!glob_halfop(user) || chan_dehalfop(user)))) { @@ -442,7 +442,7 @@ static void cmd_dehalfop(struct userrec *u, int idx, char *par) get_user_flagrec(dcc[idx].user, &user, chan->dname); m = ismember(chan, nick); if (m && !chan_op(user) && (!glob_op(user) || chan_deop(user))) { - u2 = m->user ? m->user : get_user_from_channel(m); + u2 = get_user_from_channel(m); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_halfop(user) && (!glob_halfop(user) || chan_dehalfop(user)))) { dprintf(idx, "You are not a channel op on %s.\n", chan->dname); @@ -519,7 +519,7 @@ static void cmd_voice(struct userrec *u, int idx, char *par) * - stdarg */ if (m && !(chan_op(user) || chan_halfop(user) || (glob_op(user) && !chan_deop(user)) || (glob_halfop(user) && !chan_dehalfop(user)))) { - u2 = m->user ? m->user : get_user_from_channel(m); + u2 = get_user_from_channel(m); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_voice(user) && (!glob_voice(user) || chan_quiet(user)))) { @@ -570,7 +570,7 @@ static void cmd_devoice(struct userrec *u, int idx, char *par) m = ismember(chan, nick); if (m && !(chan_op(user) || chan_halfop(user) || (glob_op(user) && !chan_deop(user)) || (glob_halfop(user) && !chan_dehalfop(user)))) { - u2 = m->user ? m->user : get_user_from_channel(m); + u2 = get_user_from_channel(m); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_voice(user) && (!glob_voice(user) || chan_quiet(user)))) { @@ -706,6 +706,7 @@ static void cmd_channel(struct userrec *u, int idx, char *par) char handle[HANDLEN + 1], s[UHOSTLEN], s1[UHOSTLEN], atrflag, chanflag; struct chanset_t *chan; memberlist *m; + struct userrec *u; int maxnicklen, maxhandlen; chan = get_channel(idx, par); @@ -729,8 +730,9 @@ static void cmd_channel(struct userrec *u, int idx, char *par) for (m = chan->channel.member; m && m->nick[0]; m = m->next) { if (strlen(m->nick) > maxnicklen) maxnicklen = strlen(m->nick); - if ((m->user) && (strlen(m->user->handle) > maxhandlen)) - maxhandlen = strlen(m->user->handle); + u = get_user_from_channel(m); + if (u && (strlen(u->handle) > maxhandlen)) + maxhandlen = strlen(u->handle); } if (maxnicklen < 9) maxnicklen = 9; @@ -750,14 +752,13 @@ static void cmd_channel(struct userrec *u, int idx, char *par) } else strlcpy(s, " --- ", sizeof s); egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); - if (m->user == NULL) { - m->user = get_user_from_channel(m); - } - if (m->user == NULL) + + u = get_user_from_channel(m); + if (u == NULL) strlcpy(handle, "*", sizeof handle); else - strlcpy(handle, m->user->handle, sizeof handle); - get_user_flagrec(m->user, &user, chan->dname); + strlcpy(handle, u->handle, sizeof handle); + get_user_flagrec(u, &user, chan->dname); /* Determine status char to use */ if (glob_bot(user) && (glob_op(user) || chan_op(user))) atrflag = 'B'; diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index 1a61edf2d..53c4756af 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -669,8 +669,7 @@ static void check_expired_chanstuff() for (m = chan->channel.member; m && m->nick[0]; m = m->next) if (now - m->last >= chan->idle_kick * 60 && !match_my_nick(m->nick) && !chan_issplit(m)) { - get_user_flagrec(m->user ? m->user : get_user_from_channel(m), - &fr, chan->dname); + get_user_flagrec(get_user_from_channel(m), &fr, chan->dname); if ((!(glob_bot(fr) || glob_friend(fr) || (glob_op(fr) && !chan_deop(fr)) || chan_friend(fr) || chan_op(fr))) && (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { @@ -683,8 +682,7 @@ static void check_expired_chanstuff() for (m = chan->channel.member; m && m->nick[0]; m = n) { n = m->next; if (m->split && now - m->split > wait_split) { - check_tcl_sign(m->nick, m->userhost, - m->user ? m->user : get_user_from_channel(m), + check_tcl_sign(m->nick, m->userhost, get_user_from_channel(m), chan->dname, "lost in the netsplit"); putlog(LOG_JOIN, chan->dname, "%s (%s) got lost in the net-split.", m->nick, m->userhost); diff --git a/src/mod/irc.mod/mode.c b/src/mod/irc.mod/mode.c index b512af687..00d7d7933 100644 --- a/src/mod/irc.mod/mode.c +++ b/src/mod/irc.mod/mode.c @@ -421,10 +421,7 @@ static void got_op(struct chanset_t *chan, char *nick, char *from, check_chan = 1; strcpy(ch, chan->name); - if (!m->user) - u = get_user_from_channel(m); - else - u = m->user; + u = get_user_from_channel(m); get_user_flagrec(u, &victim, chan->dname); /* Flags need to be set correctly right from the beginning now, so that @@ -518,10 +515,7 @@ static void got_halfop(struct chanset_t *chan, char *nick, char *from, check_chan = 1; strcpy(ch, chan->name); - if (!m->user) - u = get_user_from_channel(m); - else - u = m->user; + u = get_user_from_channel(m); get_user_flagrec(u, &victim, chan->dname); /* Flags need to be set correctly right from the beginning now, so that @@ -1245,8 +1239,7 @@ static int gotmode(char *from, char *origmsg) refresh_who_chan(chan->name); } else { simple_sprintf(s, "%s!%s", m->nick, m->userhost); - get_user_flagrec(m->user ? m->user : get_user_from_channel(m), - &victim, chan->dname); + get_user_flagrec(get_user_from_channel, &victim, chan->dname); if (ms2[0] == '+') { m->flags &= ~SENTVOICE; m->flags |= CHANVOICE; diff --git a/src/mod/irc.mod/tclirc.c b/src/mod/irc.mod/tclirc.c index ff1ab666a..732bfc518 100644 --- a/src/mod/irc.mod/tclirc.c +++ b/src/mod/irc.mod/tclirc.c @@ -54,10 +54,8 @@ static int tcl_chanlist STDVAR minus.match = plus.match ^ (FR_AND | FR_OR); for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if (!m->user) { - m->user = get_user_from_channel(m); - } - get_user_flagrec(m->user, &user, argv[1]); + u = get_user_from_channel(m); + get_user_flagrec(u, &user, argv[1]); user.match = plus.match; if (flagrec_eq(&plus, &user)) { if (!f || !flagrec_eq(&minus, &user)) @@ -346,6 +344,7 @@ static int tcl_onchan STDVAR static int tcl_handonchan STDVAR { struct chanset_t *chan, *thechan = NULL; + struct userrec *u; memberlist *m; BADARGS(2, 3, " handle ?channel?"); @@ -362,10 +361,8 @@ static int tcl_handonchan STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if (!m->user) { - m->user = get_user_from_channel(m); - } - if (m->user && !strcasecmp(m->user->handle, argv[1])) { + u = get_user_from_channel(m); + if (u && !strcasecmp(u->handle, argv[1])) { Tcl_AppendResult(irp, "1", NULL); return TCL_OK; } @@ -1025,6 +1022,7 @@ static int tcl_hand2nicks STDVAR { memberlist *m; struct chanset_t *chan, *thechan = NULL; + struct userrec *u; Tcl_Obj *nicks; Tcl_Obj **nicksv = NULL; int nicksc = 0, i, found; @@ -1045,12 +1043,12 @@ static int tcl_hand2nicks STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { found = 0; + u = get_user_from_channel(m); /* Does this user have the account we're looking for? */ - if (!m->user && !m->tried_getuser) { + if (!u && !m->tried_getuser) { m->tried_getuser = 1; - m->user = get_user_from_channel(m); } - if (m->user && !strcasecmp(m->user->handle, argv[1])) { + if (u && !strcasecmp(u->handle, argv[1])) { /* Is the nick of the user already in the list? */ Tcl_ListObjGetElements(irp, nicks, &nicksc, &nicksv); for (i = 0; i < nicksc; i++) { @@ -1074,6 +1072,7 @@ static int tcl_hand2nick STDVAR { memberlist *m; struct chanset_t *chan, *thechan = NULL; + struct userrec *u; BADARGS(2, 3, " handle ?channel?"); @@ -1089,11 +1088,11 @@ static int tcl_hand2nick STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if (!m->user && !m->tried_getuser) { + u = get_user_from_channel(m); + if (!u && !m->tried_getuser) { m->tried_getuser = 1; - m->user = get_user_from_channel(m); } - if (m->user && !strcasecmp(m->user->handle, argv[1])) { + if (u && !strcasecmp(u->handle, argv[1])) { Tcl_AppendResult(irp, m->nick, NULL); return TCL_OK; } @@ -1123,10 +1122,8 @@ static int tcl_nick2hand STDVAR while (chan && (thechan == NULL || thechan == chan)) { m = ismember(chan, argv[1]); if (m) { - if (!m->user) { - m->user = get_user_from_channel(m); - } - Tcl_AppendResult(irp, m->user ? m->user->handle : "*", NULL); + u = get_user_from_channel(m); + Tcl_AppendResult(irp, u ? u->handle : "*", NULL); return TCL_OK; } chan = chan->next; diff --git a/src/userrec.c b/src/userrec.c index f1faa5173..8083cc262 100644 --- a/src/userrec.c +++ b/src/userrec.c @@ -80,6 +80,7 @@ static int expmem_mask(struct maskrec *m) for (; m; m = m->next) { result += sizeof(struct maskrec); result += strlen(m->mask) + 1; +//XXXXXXXX How to handle this one? if (m->user) result += strlen(m->user) + 1; if (m->desc) @@ -176,12 +177,14 @@ static struct userrec *check_dcclist_hand(char *handle) static struct userrec *check_chanlist_hand(const char *hand) { struct chanset_t *chan; + struct userrec *u; memberlist *m; for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) - if (m->user && !strcasecmp(m->user->handle, hand)) - return m->user; + u = get_user_from_channel(m); + if (u && !strcasecmp(u->handle, hand)) + return u; return NULL; } @@ -288,8 +291,6 @@ void clear_masks(maskrec *m) temp = m->next; if (m->mask) nfree(m->mask); - if (m->user) - nfree(m->user); if (m->desc) nfree(m->desc); nfree(m);