From e51d9a67becad60583a648f345d5fdd0017b3863 Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Fri, 6 Nov 2020 23:44:57 +0000 Subject: [PATCH] names: refactor to use multiline --- ircd/channel.c | 61 +++++++++++------------------------------------ modules/m_names.c | 43 ++++++++++----------------------- 2 files changed, 26 insertions(+), 78 deletions(-) diff --git a/ircd/channel.c b/ircd/channel.c index c09a717d..17b840cc 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -487,11 +487,6 @@ channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eo struct membership *msptr; struct Client *target_p; rb_dlink_node *ptr; - char lbuf[BUFSIZE]; - char *t; - int mlen; - int tlen; - int cur_len; int is_member; int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); @@ -499,11 +494,11 @@ channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eo { is_member = IsMember(client_p, chptr); - cur_len = mlen = sprintf(lbuf, form_str(RPL_NAMREPLY), - me.name, client_p->name, - channel_pub_or_secret(chptr), chptr->chname); - - t = lbuf + cur_len; + send_multiline_init(client_p, " ", form_str(RPL_NAMREPLY), + me.name, + client_p->name, + channel_pub_or_secret(chptr), + chptr->chname); RB_DLINK_FOREACH(ptr, chptr->members.head) { @@ -515,49 +510,21 @@ channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eo if (IsCapable(client_p, CLICAP_USERHOST_IN_NAMES)) { - /* space, possible "@+" prefix */ - if (cur_len + strlen(target_p->name) + strlen(target_p->username) + strlen(target_p->host) + 5 >= BUFSIZE - 5) - { - *(t - 1) = '\0'; - sendto_one(client_p, "%s", lbuf); - cur_len = mlen; - t = lbuf + mlen; - } - - tlen = sprintf(t, "%s%s!%s@%s ", find_channel_status(msptr, stack), - target_p->name, target_p->username, target_p->host); + send_multiline_item(client_p, "%s%s!%s@%s", + find_channel_status(msptr, stack), + target_p->name, + target_p->username, + target_p->host); } else { - /* space, possible "@+" prefix */ - if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) - { - *(t - 1) = '\0'; - sendto_one(client_p, "%s", lbuf); - cur_len = mlen; - t = lbuf + mlen; - } - - tlen = sprintf(t, "%s%s ", find_channel_status(msptr, stack), - target_p->name); + send_multiline_item(client_p, "%s%s", + find_channel_status(msptr, stack), + target_p->name); } - - cur_len += tlen; - t += tlen; } - /* The old behaviour here was to always output our buffer, - * even if there are no clients we can show. This happens - * when a client does "NAMES" with no parameters, and all - * the clients on a -sp channel are +i. I dont see a good - * reason for keeping that behaviour, as it just wastes - * bandwidth. --anfl - */ - if(cur_len != mlen) - { - *(t - 1) = '\0'; - sendto_one(client_p, "%s", lbuf); - } + send_multiline_fini(client_p, NULL); } if(show_eon) diff --git a/modules/m_names.c b/modules/m_names.c index bbebb8a4..09c63fe0 100644 --- a/modules/m_names.c +++ b/modules/m_names.c @@ -119,16 +119,11 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ static void names_global(struct Client *source_p) { - int mlen; - int tlen; - int cur_len; bool dont_show = false; rb_dlink_node *lp, *ptr; struct Client *target_p; struct Channel *chptr = NULL; struct membership *msptr; - char buf[BUFSIZE]; - char *t; /* first do all visible channels */ RB_DLINK_FOREACH(ptr, global_channel_list.head) @@ -136,9 +131,12 @@ names_global(struct Client *source_p) chptr = ptr->data; channel_member_names(chptr, source_p, 0); } - cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY), - me.name, source_p->name, "*", "*"); - t = buf + mlen; + + send_multiline_init(source_p, " ", form_str(RPL_NAMREPLY), + me.name, + source_p->name, + "*", + "*"); /* Second, do all clients in one big sweep */ RB_DLINK_FOREACH(ptr, global_client_list.head) @@ -174,33 +172,16 @@ names_global(struct Client *source_p) if (IsCapable(source_p, CLICAP_USERHOST_IN_NAMES)) { - if (cur_len + strlen(target_p->name) + strlen(target_p->username) + strlen(target_p->host) + strlen(" !@") >= BUFSIZE - strlen("\r\n")) - { - *(t - 1) = '\0'; - sendto_one(source_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; - } - - tlen = sprintf(t, "%s!%s@%s ", target_p->name, target_p->username, target_p->host); + send_multiline_item(source_p, "%s!%s@%s", + target_p->name, + target_p->username, + target_p->host); } else { - if(cur_len + strlen(target_p->name) + strlen(" ") >= BUFSIZE - strlen("\r\n")) - { - *(t - 1) = '\0'; - sendto_one(source_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; - } - - tlen = sprintf(t, "%s ", target_p->name); + send_multiline_item(source_p, "%s", target_p->name); } - - cur_len += tlen; - t += tlen; } - if(cur_len > mlen) - sendto_one(source_p, "%s", buf); + send_multiline_fini(source_p, NULL); }