]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - modules/m_links.c
Allow /ojoin !#channel/%#channel, if admin/halfop are enabled.
[irc/rqf/shadowircd.git] / modules / m_links.c
index 30f23e59bdd4c2867b3639cd14c5c49a366c3e01..bc28ad8bc17b22f60be453a76ed757a942091ac9 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "stdinc.h"
 #include "client.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "s_serv.h"
 #include "parse.h"
 #include "modules.h"
 #include "hook.h"
-#include "cache.h"
+#include "scache.h"
 
 static int m_links(struct Client *, struct Client *, int, const char **);
 static int mo_links(struct Client *, struct Client *, int, const char **);
+static char * clean_string(char *dest, const unsigned char *src, size_t len);
 
 struct Message links_msgtab = {
        "LINKS", 0, 0, 0, MFLG_SLOW,
@@ -56,14 +57,10 @@ mapi_hlist_av1 links_hlist[] = {
 
 DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision: 254 $");
 
-static void send_links_cache(struct Client *source_p);
-
 /*
  * m_links - LINKS message handler
- *      parv[0] = sender prefix
  *      parv[1] = servername mask
  * or
- *      parv[0] = sender prefix
  *      parv[1] = server to query 
  *      parv[2] = servername mask
  */
@@ -71,7 +68,7 @@ static int
 m_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        if(ConfigServerHide.flatten_links && !IsExemptShide(source_p))
-               send_links_cache(source_p);
+               scache_send_flattened_links(source_p);
        else
                mo_links(client_p, source_p, parc, parv);
 
@@ -86,10 +83,12 @@ mo_links(struct Client *client_p, struct Client *source_p, int parc, const char
        char clean_mask[2 * HOSTLEN + 4];
        hook_data hd;
 
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
        if(parc > 2)
        {
+               if(strlen(parv[2]) > HOSTLEN)
+                       return 0;
                if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
                   != HUNTED_ISME)
                        return 0;
@@ -109,7 +108,7 @@ mo_links(struct Client *client_p, struct Client *source_p, int parc, const char
 
        call_hook(doing_links_hook, &hd);
 
-       DLINK_FOREACH(ptr, global_serv_list.head)
+       RB_DLINK_FOREACH(ptr, global_serv_list.head)
        {
                target_p = ptr->data;
 
@@ -120,7 +119,7 @@ mo_links(struct Client *client_p, struct Client *source_p, int parc, const char
                 * or theyre an oper..  
                 */
                sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS),
-                                  target_p->name, target_p->serv->up,
+                                  target_p->name, target_p->servptr->name,
                                   target_p->hopcount,
                                   target_p->info[0] ? target_p->info : "(Unknown Location)");
        }
@@ -131,26 +130,38 @@ mo_links(struct Client *client_p, struct Client *source_p, int parc, const char
        return 0;
 }
 
-/* send_links_cache()
- *
- * inputs      - client to send to
- * outputs     - the cached links, us, and RPL_ENDOFLINKS
- * side effects        -
- */
-static void
-send_links_cache(struct Client *source_p)
+static char *
+clean_string(char *dest, const unsigned char *src, size_t len)
 {
-       dlink_node *ptr;
+       char *d = dest;
+       s_assert(0 != dest);
+       s_assert(0 != src);
 
-       DLINK_FOREACH(ptr, links_cache_list.head)
+       if(dest == NULL || src == NULL)
+               return NULL;
+
+       while (*src && (len > 1))
        {
-               sendto_one(source_p, ":%s 364 %s %s",
-                          me.name, source_p->name, (const char *)ptr->data);
+               if(*src & 0x80) /* if high bit is set */
+               {
+                       *d++ = '.';
+                       --len;
+                       if(len <= 1)
+                               break;
+               }
+               else if(!IsPrint(*src)) /* if NOT printable */
+               {
+                       *d++ = '^';
+                       --len;
+                       if(len <= 1)
+                               break;
+                       *d++ = 0x40 + *src;     /* turn it into a printable */
+               }
+               else
+                       *d++ = *src;
+               ++src;
+               --len;
        }
-
-       sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), 
-                          me.name, me.name, 0, me.info);
-
-       sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), "*");
+       *d = '\0';
+       return dest;
 }
-