Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg committed Jun 16, 2024
1 parent fd6d85f commit ef0663b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 61 deletions.
10 changes: 2 additions & 8 deletions src/mod/irc.mod/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,14 +2607,8 @@ static int gotmsg(char *from, char *msg)
code = newsplit(&ctcp);
u = NULL;
/* See if we have a channel record from the same nickname */
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)) {
u = lookup_user_record(m, NULL, from);
break;
}
}
}
m = check_all_chan_records(nick);
u = lookup_user_record(m, NULL, from);
if (!ignoring || trigger_on_ignore) {
if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp)) {
chan = findchan(realto);
Expand Down
3 changes: 2 additions & 1 deletion src/mod/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ typedef void (*chanout_butfunc)(int, int, const char *, ...) ATTRIBUTE_FORMAT(pr
#define bind_bind_entry ((int(*)(tcl_bind_list_t *, const char *, const char *, const char *))global[320])
#define unbind_bind_entry ((int(*)(tcl_bind_list_t *, const char *, const char *, const char *))global[321])
#define argv0 ((char *)global[322])
#define lookup_user_record ((struct userrec * (*)(memberlist *, const char *, const char *))global[323])
#define lookup_user_record ((struct userrec * (*)(memberlist *, char *, char *))global[323])
/* 324 - 327 */
#define check_all_chan_records ((memberlist * (*) (char *))global[324])


/* hostmasking */
Expand Down
55 changes: 6 additions & 49 deletions src/mod/server.mod/servmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ static int gotmsg(char *from, char *msg)
*p, *p1, *code;
struct userrec *u;
memberlist *m = NULL;
struct chanset_t *chan;
int found = 0, ctcp_count = 0;
int ctcp_count = 0;
int ignoring;

/* Notice to a channel, not handled here */
Expand Down Expand Up @@ -610,17 +609,7 @@ static int gotmsg(char *from, char *msg)
code, ctcp, nick, uhost, to);
} else {
/* Search existing memberlists for matching 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)) {
found = 1;
break;
}
}
if (found) {
break;
}
}
m = check_all_chan_records(nick);
u = lookup_user_record(m, NULL, from);
if (!ignoring || trigger_on_ignore) {
if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp) && !ignoring) {
Expand Down Expand Up @@ -685,17 +674,7 @@ static int gotmsg(char *from, char *msg)

detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
/* Search existing memberlists for matching 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)) {
found = 1;
break;
}
}
if (found) {
break;
}
}
m = check_all_chan_records(nick);
u = lookup_user_record(m, NULL, from);
code = newsplit(&msg);
rmspace(msg);
Expand All @@ -720,9 +699,8 @@ static int gotnotice(char *from, char *msg)
{
char *to, *nick, ctcpbuf[512], *p, *p1, buf[512], *uhost = buf, *ctcp;
struct userrec *u;
struct chanset_t *chan;
memberlist *m;
int found = 0, ignoring;
int ignoring;

/* Notice to a channel, not handled here */
if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) || (*msg == '@')))
Expand Down Expand Up @@ -759,17 +737,7 @@ static int gotnotice(char *from, char *msg)
nick, uhost, to);
} else {
/* Search existing memberlists for matching 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)) {
found = 1;
break;
}
}
if (found) {
break;
}
}
m = check_all_chan_records(nick);
u = lookup_user_record(m, NULL, from);
if (!ignoring || trigger_on_ignore) {
check_tcl_ctcr(nick, uhost, u, to, code, ctcp);
Expand Down Expand Up @@ -806,18 +774,7 @@ static int gotnotice(char *from, char *msg)
}

detect_flood(nick, uhost, from, FLOOD_NOTICE);
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)) {
found = 1;
break;
}
}
if (found) {
break;
}
}

m = check_all_chan_records(nick);
u = lookup_user_record(m, NULL, from);

if (!ignoring || trigger_on_ignore)
Expand Down
3 changes: 2 additions & 1 deletion src/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,9 @@ Function global_table[] = {
(Function) bind_bind_entry,
(Function) unbind_bind_entry,
(Function) & argv0,
(Function) lookup_user_record
(Function) lookup_user_record,
/* 324 - 327 */
(Function) check_all_chan_records
};

void init_modules(void)
Expand Down
19 changes: 18 additions & 1 deletion src/userrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ static struct userrec *check_dcclist_hand(char *handle)
return NULL;
}

/* Search every channel record for the provided nickname. Used in cases where
* we are searching for a user record but don't have a memberlist to start from
*/
memberlist *check_all_chan_records(char *nick) {
struct chanset_t *chan;
memberlist *m = NULL;

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)) {
return m;
}
}
}
return m;
}

/* Search userlist for a provided account name
* Returns: userrecord for user containing the account
*/
Expand Down Expand Up @@ -266,7 +283,7 @@ struct userrec *get_user_from_member(memberlist *m)
* 'm->account' for the account, use the independent source variable 'account'
* if available. This allows redundant checking in case of unexpected NULLs
*/
struct userrec *lookup_user_record(memberlist *m, const char *host, const char *account)
struct userrec *lookup_user_record(memberlist *m, char *host, char *account)
{
struct userrec *u = NULL;

Expand Down
3 changes: 2 additions & 1 deletion src/users.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ struct userrec *get_user_by_host(char *);
struct userrec *get_user_by_account(char *);
struct userrec *get_user_by_nick(char *);
struct userrec *get_user_from_member(memberlist *);
struct userrec *lookup_user_record(memberlist *, const char *, const char *);
struct userrec *lookup_user_record(memberlist *, char *, char *);
struct userrec *check_chanlist(const char *);
memberlist *check_all_chan_records(char *);

/* All the default userentry stuff, for code re-use
*/
Expand Down

0 comments on commit ef0663b

Please sign in to comment.