X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/c98390004f4f14cd8215302d77313f81e2546e22..320a0f852891ac719c4c3349cfae836f8174bc4f:/modules/m_links.c diff --git a/modules/m_links.c b/modules/m_links.c index 295baa6..3aafbc7 100644 --- a/modules/m_links.c +++ b/modules/m_links.c @@ -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" @@ -40,6 +40,7 @@ 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, @@ -58,10 +59,8 @@ DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision /* * 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 */ @@ -84,7 +83,7 @@ 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) { @@ -107,7 +106,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; @@ -129,3 +128,36 @@ mo_links(struct Client *client_p, struct Client *source_p, int parc, const char return 0; } +static char * +clean_string(char *dest, const unsigned char *src, size_t len) +{ + char *d = dest; + s_assert(0 != dest); + s_assert(0 != src); + + if(dest == NULL || src == NULL) + return NULL; + + len -= 3; /* allow for worst case, '^A\0' */ + + while (*src && (len > 0)) + { + if(*src & 0x80) /* if high bit is set */ + { + *d++ = '.'; + --len; + } + else if(!IsPrint(*src)) /* if NOT printable */ + { + *d++ = '^'; + --len; + *d++ = 0x40 + *src; /* turn it into a printable */ + } + else + *d++ = *src; + ++src; + --len; + } + *d = '\0'; + return dest; +}