Skip to content

Commit

Permalink
client: refactor del_all_accepts to allow skipping own accept list
Browse files Browse the repository at this point in the history
This allows reusing this function for other uses that just need to
remove this client from others' accept lists on nick change and not have
duplicates of this code everywhere
  • Loading branch information
dwfreed authored and spb committed Nov 6, 2023
1 parent fd241b5 commit c1b01bf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ extern struct Client *find_named_person(const char *);
extern struct Client *next_client(struct Client *, const char *);

#define accept_message(s, t) ((s) == (t) || (rb_dlinkFind((s), &((t)->localClient->allow_list))))
extern void del_all_accepts(struct Client *client_p);
extern void del_all_accepts(struct Client *client_p, bool self_too);

extern void dead_link(struct Client *client_p, int sendqex);
extern int show_ip(struct Client *source_p, struct Client *target_p);
Expand Down
16 changes: 12 additions & 4 deletions ircd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ exit_generic_client(struct Client *client_p, struct Client *source_p, struct Cli
}

/* Clean up allow lists */
del_all_accepts(source_p);
del_all_accepts(source_p, true);

whowas_add_history(source_p, 0);
whowas_off_history(source_p);
Expand Down Expand Up @@ -1793,26 +1793,27 @@ count_remote_client_memory(size_t * count, size_t * remote_client_memory_used)
/*
* del_all_accepts
*
* inputs - pointer to exiting client
* inputs - pointer to exiting client, flag to include own allow_list
* output - NONE
* side effects - Walk through given clients allow_list and on_allow_list
* remove all references to this client
*/
void
del_all_accepts(struct Client *client_p)
del_all_accepts(struct Client *client_p, bool self_too)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
struct Client *target_p;

if(MyClient(client_p) && client_p->localClient->allow_list.head)
if(self_too && MyClient(client_p) && client_p->localClient->allow_list.head)
{
/* clear this clients accept list, and remove them from
* everyones on_accept_list
*/
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->allow_list.head)
{
target_p = ptr->data;

rb_dlinkFindDestroy(client_p, &target_p->on_allow_list);
rb_dlinkDestroy(ptr, &client_p->localClient->allow_list);
}
Expand All @@ -1822,6 +1823,13 @@ del_all_accepts(struct Client *client_p)
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
{
target_p = ptr->data;

/* If we're not doing our own, we're doing this because of a nick change.
* Skip those that would see the nick change anyway
*/
if(!self_too && has_common_channel(client_p, target_p))
continue;

rb_dlinkFindDestroy(client_p, &target_p->localClient->allow_list);
rb_dlinkDestroy(ptr, &client_p->on_allow_list);
}
Expand Down
2 changes: 1 addition & 1 deletion ircd/s_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ change_nick_user_host(struct Client *target_p, const char *nick, const char *use
if(changed)
{
monitor_signon(target_p);
del_all_accepts(target_p);
del_all_accepts(target_p, false);
}
}

Expand Down
17 changes: 1 addition & 16 deletions modules/core/m_nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,6 @@ static void
change_local_nick(struct Client *client_p, struct Client *source_p,
char *nick, int dosend)
{
struct Client *target_p;
rb_dlink_node *ptr, *next_ptr;
struct Channel *chptr;
char note[NICKLEN + 10];
int samenick;
Expand Down Expand Up @@ -704,20 +702,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
/* Make sure everyone that has this client on its accept list
* loses that reference.
*/
/* we used to call del_all_accepts() here, but theres no real reason
* to clear a clients own list of accepted clients. So just remove
* them from everyone elses list --anfl
*/
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head)
{
target_p = ptr->data;

if (!has_common_channel(source_p, target_p))
{
rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list);
rb_dlinkDestroy(ptr, &source_p->on_allow_list);
}
}
del_all_accepts(source_p, false);

snprintf(note, sizeof(note), "Nick: %s", nick);
rb_note(client_p->localClient->F, note);
Expand Down
5 changes: 4 additions & 1 deletion modules/m_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ me_rsfnc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source

monitor_signon(target_p);

del_all_accepts(target_p);
/* Make sure everyone that has this client on its accept list
* loses that reference.
*/
del_all_accepts(target_p, false);

snprintf(note, sizeof(note), "Nick: %s", target_p->name);
rb_note(target_p->localClient->F, note);
Expand Down

0 comments on commit c1b01bf

Please sign in to comment.