]> jfr.im git - solanum.git/commitdiff
presence: Remove user.away, replaced by a metadata entry.
authorWilliam Pitcock <redacted>
Tue, 2 Jun 2009 07:03:51 +0000 (02:03 -0500)
committerWilliam Pitcock <redacted>
Tue, 2 Jun 2009 07:03:51 +0000 (02:03 -0500)
Cache the metadata retrieval value where feasible for minimal performance impact.

include/client.h
modules/core/m_message.c
modules/m_away.c
modules/m_invite.c
modules/m_stats.c
modules/m_userhost.c
modules/m_who.c
modules/m_whois.c
src/client.c
src/s_serv.c

index 598108ccc522939f99692a23d706aad305ceb5bf..c7df24d7cbe33fc6fabebe90b85b3c8d6d398628 100644 (file)
@@ -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];
index c89325038f371b03baf279ff3df74b64b5049b6c..62db04d783b3c1294391d99c2facada46622921c 100644 (file)
@@ -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))
        {
index 02b510d8ed9caa1cbb6d396f7ff71d38c9081591..540fd3e6976d6a422977bb6314b395b5a1056512 100644 (file)
@@ -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));
 
index cff1f83b8a5fc476550cb138e7f3999494bafabc..cf475f934d1e507af64384f2338f5b4576b040f5 100644 (file)
@@ -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]))
index 29e7c7ed75a81537b476ccdeb9188626491fb93e..12adc9c3ff7ae2652596f94563f942e87bd1b7b3 100644 (file)
@@ -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)",
index 108974e740dcc706544b6d5dae307e4425cc537c..766334caf47e4405ceb923b21a81b357a96052a1 100644 (file)
@@ -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);
                        }
 
index b8ffc873d99ac14aec01ae5c634dee74048a40e5..834ab7544a5fea5dd7d41468787e1ae91dd6daea 100644 (file)
@@ -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,
index ca8dc23848522c87cc16d17c43771469f30de822..c188a9ae872e54ae2c1b52c22d4260150dd54d31 100644 (file)
@@ -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))
        {
index 542729ff78f702261099a8e714a4fbf683912350..5d70b4de2c4772dc09f4b949cf773a8910ef9a69 100644 (file)
@@ -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
                 */
index 10c0fab05a6c971e8ec29e5ff052d2df6c21535f..88fecddc97ed877e64e45285acf3a68e131bac27 100644 (file)
@@ -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);