]> jfr.im git - solanum.git/blobdiff - src/capability.c
update NEWS
[solanum.git] / src / capability.c
index c999d6467c45eba5b392efbd4c2004da796d53a6..daf72657bdb98e8556d04784f0c4af27fbc38390 100644 (file)
@@ -21,6 +21,7 @@
 #include "stdinc.h"
 #include "capability.h"
 #include "irc_dictionary.h"
+#include "s_assert.h"
 
 static rb_dlink_list capability_indexes = { NULL, NULL, 0 };
 
@@ -46,6 +47,8 @@ capability_get(struct CapabilityIndex *idx, const char *cap)
        struct CapabilityEntry *entry;
 
        s_assert(idx != NULL);
+       if (cap == NULL)
+               return 0;
 
        entry = irc_dictionary_retrieve(idx->cap_dict, cap);
        if (entry != NULL && !(entry->flags & CAP_ORPHANED))
@@ -83,6 +86,21 @@ capability_put(struct CapabilityIndex *idx, const char *cap)
        return (1 << entry->value);
 }
 
+unsigned int
+capability_put_anonymous(struct CapabilityIndex *idx)
+{
+       unsigned int value;
+
+       s_assert(idx != NULL);
+       if (!idx->highest_bit)
+               return 0xFFFFFFFF;
+       value = 1 << idx->highest_bit;
+       idx->highest_bit++;
+       if (idx->highest_bit % (sizeof(unsigned int) * 8) == 0)
+               idx->highest_bit = 0;
+       return value;
+}
+
 void
 capability_orphan(struct CapabilityIndex *idx, const char *cap)
 {
@@ -229,8 +247,8 @@ capability_index_stats(void (*cb)(const char *line, void *privdata), void *privd
                        cb(buf, privdata);
                }
 
-               rb_snprintf(buf, sizeof buf, "'%s': remaining bits - %ld", idx->name,
-                           (sizeof(unsigned int) * 8) - (idx->highest_bit - 1));
+               rb_snprintf(buf, sizeof buf, "'%s': remaining bits - %u", idx->name,
+                           (unsigned int)((sizeof(unsigned int) * 8) - (idx->highest_bit - 1)));
                cb(buf, privdata);
        }