]> jfr.im git - solanum.git/blobdiff - src/supported.c
Remove s_assert definition from ircd_defs.h and add it to its own header.
[solanum.git] / src / supported.c
index fe90d7976a9903e4e8816397c0beba4916d7bde9..fef441cff429fd7628bf8fe960bf9dec45710319 100644 (file)
  *
  *  All unknown/unlisted modes are treated as type D.
  */
-/* ELIST=[tokens]:
- *
- * M = mask search
- * N = !mask search
- * U = user count search (< >)
- * C = creation time search (C> C<)
- * T = topic search (T> T<)
- */
 
 #include "stdinc.h"
-#include "tools.h"
 #include "client.h"
 #include "common.h"
 #include "numeric.h"
 #include "ircd.h"
 #include "s_conf.h"
+#include "s_user.h"
+#include "supported.h"
+#include "chmode.h"
+#include "send.h"
 
-dlink_list isupportlist;
+rb_dlink_list isupportlist;
 
 struct isupportitem
 {
        const char *name;
-       const char *(*func)(void *);
-       void *param;
-       dlink_node node;
+       const char *(*func)(const void *);
+       const void *param;
+       rb_dlink_node node;
 };
 
 void
-add_isupport(const char *name, const char *(*func)(void *), void *param)
+add_isupport(const char *name, const char *(*func)(const void *), const void *param)
 {
        struct isupportitem *item;
 
-       item = MyMalloc(sizeof(struct isupportitem));
+       item = rb_malloc(sizeof(struct isupportitem));
        item->name = name;
        item->func = func;
        item->param = param;
-       dlinkAddTail(item, &item->node, &isupportlist);
+       rb_dlinkAddTail(item, &item->node, &isupportlist);
+}
+
+const void *
+change_isupport(const char *name, const char *(*func)(const void *), const void *param)
+{
+       rb_dlink_node *ptr;
+       struct isupportitem *item;
+       const void *oldvalue = NULL;
+
+       RB_DLINK_FOREACH(ptr, isupportlist.head)
+       {
+               item = ptr->data;
+
+               if (!strcmp(item->name, name))
+               {
+                       oldvalue = item->param;
+
+                       // item->name = name;
+                       item->func = func;
+                       item->param = param;
+
+                       break;
+               }
+       }
+
+       return oldvalue;
 }
 
 void
 delete_isupport(const char *name)
 {
-       dlink_node *ptr, *next_ptr;
+       rb_dlink_node *ptr, *next_ptr;
        struct isupportitem *item;
 
-       DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head)
        {
                item = ptr->data;
 
                if (!strcmp(item->name, name))
                {
-                       dlinkDelete(ptr, &isupportlist);
-                       MyFree(item);
+                       rb_dlinkDelete(ptr, &isupportlist);
+                       rb_free(item);
                }
        }
 }
@@ -132,12 +153,12 @@ delete_isupport(const char *name)
 void
 show_isupport(struct Client *client_p)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        struct isupportitem *item;
        const char *value;
        char buf[512];
        int extra_space;
-       int nchars, nparams;
+       unsigned int nchars, nparams;
        int l;
 
        extra_space = strlen(client_p->name);
@@ -149,7 +170,7 @@ show_isupport(struct Client *client_p)
        extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT));
 
        nchars = extra_space, nparams = 0, buf[0] = '\0';
-       DLINK_FOREACH(ptr, isupportlist.head)
+       RB_DLINK_FOREACH(ptr, isupportlist.head)
        {
                item = ptr->data;
                value = (*item->func)(item->param);
@@ -162,12 +183,12 @@ show_isupport(struct Client *client_p)
                        nchars = extra_space, nparams = 0, buf[0] = '\0';
                }
                if (nparams > 0)
-                       strlcat(buf, " ", sizeof buf), nchars++;
-               strlcat(buf, item->name, sizeof buf);
+                       rb_strlcat(buf, " ", sizeof buf), nchars++;
+               rb_strlcat(buf, item->name, sizeof buf);
                if (!EmptyString(value))
                {
-                       strlcat(buf, "=", sizeof buf);
-                       strlcat(buf, value, sizeof buf);
+                       rb_strlcat(buf, "=", sizeof buf);
+                       rb_strlcat(buf, value, sizeof buf);
                }
                nchars += l;
                nparams++;
@@ -177,83 +198,97 @@ show_isupport(struct Client *client_p)
 }
 
 const char *
-isupport_intptr(void *ptr)
+isupport_intptr(const void *ptr)
 {
        static char buf[15];
-
-       ircsnprintf(buf, sizeof buf, "%d", *(int *)ptr);
+       rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr);
        return buf;
 }
 
 const char *
-isupport_boolean(void *ptr)
+isupport_boolean(const void *ptr)
 {
 
-       return *(int *)ptr ? "" : NULL;
+       return *(const int *)ptr ? "" : NULL;
 }
 
 const char *
-isupport_string(void *ptr)
+isupport_string(const void *ptr)
 {
 
        return (const char *)ptr;
 }
 
 const char *
-isupport_stringptr(void *ptr)
+isupport_stringptr(const void *ptr)
 {
+       return *(char * const *)ptr;    
+}
+
+static const char *
+isupport_umode(const void *ptr)
+{
+       const char *str;
 
-       return *(const char **)ptr;
+       str = ptr;
+       return ConfigFileEntry.oper_only_umodes &
+               user_modes[(unsigned char)*str] ? NULL : str;
 }
 
-const char *
-isupport_chanmodes(void *ptr)
+static const char *
+isupport_chanmodes(const void *ptr)
 {
        static char result[80];
 
-       ircsnprintf(result, sizeof result, "%s%sbq,k,%slj,imnpst%scgzLP%s",
+       rb_snprintf(result, sizeof result, "%s%sbq,k,%slj,%s",
                        ConfigChannel.use_except ? "e" : "",
                        ConfigChannel.use_invex ? "I" : "",
                        ConfigChannel.use_forward ? "f" : "",
-                       dlink_list_length(&service_list) ? "r" : "",
-                       ConfigChannel.use_forward ? "QF" : "");
+                       cflagsbuf);
        return result;
 }
 
-const char *
-isupport_chanlimit(void *ptr)
+static const char *
+isupport_chantypes(const void *ptr)
+{
+       return ConfigChannel.disable_local_channels ? "#" : "&#";
+}
+
+static const char *
+isupport_chanlimit(const void *ptr)
 {
        static char result[30];
 
-       ircsnprintf(result, sizeof result, "&#:%i", ConfigChannel.max_chans_per_user);
+       rb_snprintf(result, sizeof result, "%s:%i",
+               ConfigChannel.disable_local_channels ? "#" : "&#", ConfigChannel.max_chans_per_user);
        return result;
 }
 
-const char *
-isupport_maxlist(void *ptr)
+static const char *
+isupport_maxlist(const void *ptr)
 {
        static char result[30];
 
-       ircsnprintf(result, sizeof result, "bq%s%s:%i",
+       rb_snprintf(result, sizeof result, "bq%s%s:%i",
                        ConfigChannel.use_except ? "e" : "",
                        ConfigChannel.use_invex ? "I" : "",
                        ConfigChannel.max_bans);
        return result;
 }
 
-const char *
-isupport_targmax(void *ptr)
+static const char *
+isupport_targmax(const void *ptr)
 {
        static char result[200];
 
-       ircsnprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
+       rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
                        ConfigFileEntry.max_targets,
                        ConfigFileEntry.max_targets);
        return result;
 }
 
-const char *
-isupport_extban(void *ptr)
+static const char *
+isupport_extban(const void *ptr)
 {
        const char *p;
        static char result[200];
@@ -261,7 +296,16 @@ isupport_extban(void *ptr)
        p = get_extban_string();
        if (EmptyString(p))
                return NULL;
-       ircsnprintf(result, sizeof result, "$,%s", p);
+       rb_snprintf(result, sizeof result, "$,%s", p);
+       return result;
+}
+
+static const char *
+isupport_nicklen(const void *ptr)
+{
+       static char result[200];
+
+       rb_snprintf(result, sizeof result, "%u", ConfigFileEntry.nicklen - 1);
        return result;
 }
 
@@ -269,11 +313,11 @@ void
 init_isupport(void)
 {
        static int maxmodes = MAXMODEPARAMS;
-       static int nicklen = NICKLEN-1;
        static int channellen = LOC_CHANNELLEN;
        static int topiclen = TOPICLEN;
+       static int maxnicklen = NICKLEN - 1;
 
-       add_isupport("CHANTYPES", isupport_string, "&#");
+       add_isupport("CHANTYPES", isupport_chantypes, NULL);
        add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except);
        add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex);
        add_isupport("CHANMODES", isupport_chanmodes, NULL);
@@ -284,20 +328,21 @@ init_isupport(void)
        add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name);
        add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock);
        add_isupport("STATUSMSG", isupport_string, "@+");
-       add_isupport("CALLERID", isupport_string, "g");
-       add_isupport("SAFELIST", isupport_string, "");
-       add_isupport("ELIST", isupport_string, "U");
+       add_isupport("CALLERID", isupport_umode, "g");
        add_isupport("CASEMAPPING", isupport_string, "rfc1459");
        add_isupport("CHARSET", isupport_string, "ascii");
-       add_isupport("NICKLEN", isupport_intptr, &nicklen);
+       add_isupport("NICKLEN", isupport_nicklen, NULL);
+       add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen);
        add_isupport("CHANNELLEN", isupport_intptr, &channellen);
        add_isupport("TOPICLEN", isupport_intptr, &topiclen);
        add_isupport("ETRACE", isupport_string, "");
        add_isupport("CPRIVMSG", isupport_string, "");
        add_isupport("CNOTICE", isupport_string, "");
-       add_isupport("DEAF", isupport_string, "D");
+       add_isupport("DEAF", isupport_umode, "D");
        add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor);
        add_isupport("FNC", isupport_string, "");
        add_isupport("TARGMAX", isupport_targmax, NULL);
        add_isupport("EXTBAN", isupport_extban, NULL);
+       add_isupport("WHOX", isupport_string, "");
+       add_isupport("CLIENTVER", isupport_string, "3.0");
 }