From 987ef7eb1f6c6e6bfb79fc0e7759702ff372ac7a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 2 Jun 2009 02:03:51 -0500 Subject: [PATCH] presence: Remove user.away, replaced by a metadata entry. Cache the metadata retrieval value where feasible for minimal performance impact. --- include/client.h | 1 - modules/core/m_message.c | 5 +++-- modules/m_away.c | 16 ++++------------ modules/m_invite.c | 5 +++-- modules/m_stats.c | 14 +++----------- modules/m_userhost.c | 4 ++-- modules/m_who.c | 2 +- modules/m_whois.c | 5 +++-- src/client.c | 2 -- src/s_serv.c | 6 ++++-- 10 files changed, 23 insertions(+), 37 deletions(-) diff --git a/include/client.h b/include/client.h index 598108c..c7df24d 100644 --- a/include/client.h +++ b/include/client.h @@ -92,7 +92,6 @@ struct User { rb_dlink_list channel; /* chain of channel pointer blocks */ rb_dlink_list invited; /* chain of invite pointer blocks */ - char *away; /* pointer to away message */ int refcnt; /* Number of times this block is referenced */ char suser[NICKLEN+1]; diff --git a/modules/core/m_message.c b/modules/core/m_message.c index c893250..62db04d 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -744,6 +744,7 @@ static void msg_client(int p_or_n, const char *command, struct Client *source_p, struct Client *target_p, const char *text) { + const char *awaymsg; int do_floodcount = 0; if(MyClient(source_p)) @@ -788,9 +789,9 @@ msg_client(int p_or_n, const char *command, return; } - if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && target_p->user->away) + if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && (awaymsg = get_metadata(target_p, "away")) != NULL) sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); + target_p->name, awaymsg); if(MyClient(target_p)) { diff --git a/modules/m_away.c b/modules/m_away.c index 02b510d..540fd3e 100644 --- a/modules/m_away.c +++ b/modules/m_away.c @@ -78,7 +78,7 @@ m_away(struct Client *client_p, struct Client *source_p, int parc, const char *p if(parc < 2 || EmptyString(parv[1])) { /* Marking as not away */ - if(source_p->user->away != NULL) + if(get_metadata(source_p, "away") != NULL) { /* we now send this only if they were away before --is */ sendto_server(client_p, NULL, CAP_TS6, NOCAPS, @@ -90,18 +90,10 @@ m_away(struct Client *client_p, struct Client *source_p, int parc, const char *p return 0; } - - if(source_p->user->away == NULL) - { - allocate_away(source_p); - rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s AWAY :%s", use_id(source_p), source_p->user->away); + set_metadata(source_p, "away", parv[1]); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s AWAY :%s", use_id(source_p), parv[1]); - } else { - rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); - } - if(MyConnect(source_p)) sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY)); diff --git a/modules/m_invite.c b/modules/m_invite.c index cff1f83..cf475f9 100644 --- a/modules/m_invite.c +++ b/modules/m_invite.c @@ -58,6 +58,7 @@ static void add_invite(struct Channel *, struct Client *); static int m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { + const char *awaymsg; struct Client *target_p; struct Channel *chptr; struct membership *msptr; @@ -165,9 +166,9 @@ m_invite(struct Client *client_p, struct Client *source_p, int parc, const char sendto_one(source_p, form_str(RPL_INVITING), me.name, source_p->name, target_p->name, parv[2]); - if(target_p->user->away) + if((awaymsg = get_metadata(target_p, "away")) != NULL) sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); + target_p->name, awaymsg); } /* invite timestamp */ else if(parc > 3 && !EmptyString(parv[3])) diff --git a/modules/m_stats.c b/modules/m_stats.c index 29e7c7e..12adc9c 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -704,7 +704,7 @@ stats_operedup (struct Client *source_p) if(IsOperInvis(target_p) && !IsOper(source_p)) continue; - if(target_p->user->away) + if(get_metadata(target_p, "away")) continue; count++; @@ -1137,7 +1137,6 @@ stats_memory (struct Client *source_p) int conf_count = 0; /* conf lines */ int users_invited_count = 0; /* users invited */ int user_channels = 0; /* users in channels */ - int aways_counted = 0; size_t number_servers_cached; /* number of servers cached by scache */ size_t channel_memory = 0; @@ -1146,7 +1145,6 @@ stats_memory (struct Client *source_p) size_t channel_invex_memory = 0; size_t channel_quiet_memory = 0; - size_t away_memory = 0; /* memory used by aways */ size_t ww = 0; /* whowas array count */ size_t wwm = 0; /* whowas array memory used */ size_t conf_memory = 0; /* memory used by conf lines */ @@ -1181,11 +1179,6 @@ stats_memory (struct Client *source_p) users_counted++; users_invited_count += rb_dlink_list_length(&target_p->user->invited); user_channels += rb_dlink_list_length(&target_p->user->channel); - if(target_p->user->away) - { - aways_counted++; - away_memory += (strlen(target_p->user->away) + 1); - } } } @@ -1246,10 +1239,9 @@ stats_memory (struct Client *source_p) (unsigned long) users_invited_count * sizeof(rb_dlink_node)); sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :User channels %u(%lu) Aways %u(%d)", + "z :User channels %u(%lu)", user_channels, - (unsigned long) user_channels * sizeof(rb_dlink_node), - aways_counted, (int) away_memory); + (unsigned long) user_channels * sizeof(rb_dlink_node)); sendto_one_numeric(source_p, RPL_STATSDEBUG, "z :Attached confs %u(%lu)", diff --git a/modules/m_userhost.c b/modules/m_userhost.c index 108974e..766334c 100644 --- a/modules/m_userhost.c +++ b/modules/m_userhost.c @@ -84,7 +84,7 @@ m_userhost(struct Client *client_p, struct Client *source_p, int parc, const cha rl = rb_sprintf(response, "%s%s=%c%s@%s ", target_p->name, IsOper(target_p) ? "*" : "", - (target_p->user->away) ? '-' : '+', + (get_metadata(target_p, "away") != NULL) ? '-' : '+', target_p->username, target_p->sockhost); } @@ -93,7 +93,7 @@ m_userhost(struct Client *client_p, struct Client *source_p, int parc, const cha rl = rb_sprintf(response, "%s%s=%c%s@%s ", target_p->name, IsOper(target_p) ? "*" : "", - (target_p->user->away) ? '-' : '+', + (get_metadata(target_p, "away") != NULL) ? '-' : '+', target_p->username, target_p->host); } diff --git a/modules/m_who.c b/modules/m_who.c index b8ffc87..834ab75 100644 --- a/modules/m_who.c +++ b/modules/m_who.c @@ -467,7 +467,7 @@ do_who(struct Client *source_p, struct Client *target_p, struct membership *mspt const char *q; rb_sprintf(status, "%c%s%s", - target_p->user->away ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : ""); + (get_metadata(target_p, "away") != NULL) ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : ""); if (fmt->fields == 0) sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, diff --git a/modules/m_whois.c b/modules/m_whois.c index ca8dc23..c188a9a 100644 --- a/modules/m_whois.c +++ b/modules/m_whois.c @@ -228,6 +228,7 @@ do_whois(struct Client *client_p, struct Client *source_p, int parc, const char static void single_whois(struct Client *source_p, struct Client *target_p, int operspy) { + const char *awaymsg; char buf[BUFSIZE]; rb_dlink_node *ptr; struct membership *msptr; @@ -304,9 +305,9 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy) target_p->name, target_p->servptr->name, target_p->servptr->info); - if(target_p->user->away) + if((awaymsg = get_metadata(target_p, "away")) != NULL) sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); + target_p->name, awaymsg); if(IsOper(target_p)) { diff --git a/src/client.c b/src/client.c index 542729f..5d70b4d 100644 --- a/src/client.c +++ b/src/client.c @@ -1701,8 +1701,6 @@ free_user(struct User *user, struct Client *client_p) { if(--user->refcnt <= 0) { - if(user->away) - rb_free((char *) user->away); /* * sanity check */ diff --git a/src/s_serv.c b/src/s_serv.c index 10c0fab..88fecdd 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -474,6 +474,8 @@ burst_TS6(struct Client *client_p) RB_DLINK_FOREACH(ptr, global_client_list.head) { + const char *awaymsg = NULL; + target_p = ptr->data; if(!IsPerson(target_p)) @@ -516,10 +518,10 @@ burst_TS6(struct Client *client_p) use_id(target_p), target_p->user->suser); } - if(ConfigFileEntry.burst_away && !EmptyString(target_p->user->away)) + if(ConfigFileEntry.burst_away && (awaymsg = get_metadata(target_p, "away")) != NULL) sendto_one(client_p, ":%s AWAY :%s", use_id(target_p), - target_p->user->away); + awaymsg); hclientinfo.target = target_p; call_hook(h_burst_client, &hclientinfo);