]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - modules/m_whois.c
presence: m_presence module: Use safer get_metadata() where appropriate, to avoid...
[irc/rqf/shadowircd.git] / modules / m_whois.c
index 54c71a1d5647c61a9389dc59c9496d066c8d8543..a111e91887af464067b10757e311a14f5304e88a 100644 (file)
@@ -69,7 +69,6 @@ DECLARE_MODULE_AV1(whois, NULL, NULL, whois_clist, whois_hlist, NULL, "$Revision
 
 /*
  * m_whois
- *      parv[0] = sender prefix
  *      parv[1] = nickname masklist
  */
 static int
@@ -115,7 +114,6 @@ m_whois(struct Client *client_p, struct Client *source_p, int parc, const char *
 
 /*
  * ms_whois
- *      parv[0] = sender prefix
  *      parv[1] = server to reply
  *      parv[2] = nickname to whois
  */
@@ -200,7 +198,7 @@ do_whois(struct Client *client_p, struct Client *source_p, int parc, const char
                {
                        char buffer[BUFSIZE];
 
-                       snprintf(buffer, sizeof(buffer), "%s!%s@%s %s",
+                       rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s %s",
                                target_p->name, target_p->username,
                                target_p->host, target_p->servptr->name);
                        report_operspy(source_p, "WHOIS", buffer);
@@ -230,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;
@@ -239,15 +238,10 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
        char *t;
        int tlen;
        hook_data_client hdata;
-       char *name;
-       char quest[] = "?";
        int visible;
        int extra_space = 0;
-
-       if(target_p->name[0] == '\0')
-               name = quest;
-       else
-               name = target_p->name;
+       struct DictionaryIter iter;
+       struct MetadataEntry *md;
 
        if(target_p->user == NULL)
        {
@@ -313,9 +307,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(!IsCapable(source_p, CLICAP_PRESENCE) && (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))
        {
@@ -375,6 +369,17 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
                }
        }
 
+       DICTIONARY_FOREACH(md, &iter, target_p->user->metadata)
+       {
+               /* XXX: hack around "away" for legacy clients. --nenolod */
+               if (!IsCapable(source_p, CLICAP_PRESENCE) && !irccmp(md->key, "away"))
+                       continue;
+
+               sendto_one_numeric(source_p, RPL_WHOISMETADATA,
+                                  form_str(RPL_WHOISMETADATA),
+                                  target_p->name, md->key, md->value);
+       }
+
        hdata.client = source_p;
        hdata.target = target_p;