#include "stdinc.h"
#include "capability.h"
-#include "irc_dictionary.h"
+#include "rb_dictionary.h"
#include "s_assert.h"
static rb_dlink_list capability_indexes = { NULL, NULL, 0 };
-struct CapabilityIndex {
- char *name;
- struct Dictionary *cap_dict;
- unsigned int highest_bit;
- rb_dlink_node node;
-};
-
-#define CAP_ORPHANED 0x1
-#define CAP_REQUIRED 0x2
+struct CapabilityEntry *
+capability_find(struct CapabilityIndex *idx, const char *cap)
+{
+ s_assert(idx != NULL);
+ if (cap == NULL)
+ return NULL;
-struct CapabilityEntry {
- char *cap;
- unsigned int value;
- unsigned int flags;
- void *ownerdata;
-};
+ return rb_dictionary_retrieve(idx->cap_dict, cap);
+}
unsigned int
capability_get(struct CapabilityIndex *idx, const char *cap, void **ownerdata)
if (cap == NULL)
return 0;
- entry = irc_dictionary_retrieve(idx->cap_dict, cap);
+ entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL && !(entry->flags & CAP_ORPHANED))
{
if (ownerdata != NULL)
if (!idx->highest_bit)
return 0xFFFFFFFF;
- if ((entry = irc_dictionary_retrieve(idx->cap_dict, cap)) != NULL)
+ if ((entry = rb_dictionary_retrieve(idx->cap_dict, cap)) != NULL)
{
entry->flags &= ~CAP_ORPHANED;
+ if (ownerdata != NULL)
+ {
+ s_assert(entry->ownerdata == NULL);
+ entry->ownerdata = ownerdata;
+ }
return (1 << entry->value);
}
entry->value = idx->highest_bit;
entry->ownerdata = ownerdata;
- irc_dictionary_add(idx->cap_dict, entry->cap, entry);
+ rb_dictionary_add(idx->cap_dict, entry->cap, entry);
idx->highest_bit++;
if (idx->highest_bit % (sizeof(unsigned int) * 8) == 0)
s_assert(idx != NULL);
- entry = irc_dictionary_retrieve(idx->cap_dict, cap);
+ entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL)
{
entry->flags &= ~CAP_REQUIRED;
entry->flags |= CAP_ORPHANED;
+ entry->ownerdata = NULL;
}
}
s_assert(idx != NULL);
- entry = irc_dictionary_retrieve(idx->cap_dict, cap);
+ entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL)
entry->flags |= CAP_REQUIRED;
}
static void
-capability_destroy(struct DictionaryElement *delem, void *privdata)
+capability_destroy(rb_dictionary_element *delem, void *privdata)
{
s_assert(delem != NULL);
- rb_free(delem->data);
+ struct CapabilityEntry *entry = delem->data;
+ rb_free((char *)entry->cap);
+ rb_free(entry);
}
struct CapabilityIndex *
struct CapabilityIndex *idx;
idx = rb_malloc(sizeof(struct CapabilityIndex));
- idx->name = rb_strdup(name);
- idx->cap_dict = irc_dictionary_create(name, strcasecmp);
+ idx->name = name;
+ idx->cap_dict = rb_dictionary_create(name, rb_strcasecmp);
idx->highest_bit = 1;
rb_dlinkAdd(idx, &idx->node, &capability_indexes);
rb_dlinkDelete(&idx->node, &capability_indexes);
- irc_dictionary_destroy(idx->cap_dict, capability_destroy, NULL);
+ rb_dictionary_destroy(idx->cap_dict, capability_destroy, NULL);
rb_free(idx);
}
const char *
capability_index_list(struct CapabilityIndex *idx, unsigned int cap_mask)
{
- struct DictionaryIter iter;
+ rb_dictionary_iter iter;
struct CapabilityEntry *entry;
static char buf[BUFSIZE];
char *t = buf;
*t = '\0';
- DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
+ RB_DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
{
if ((1 << entry->value) & cap_mask)
{
unsigned int
capability_index_mask(struct CapabilityIndex *idx)
{
- struct DictionaryIter iter;
+ rb_dictionary_iter iter;
struct CapabilityEntry *entry;
unsigned int mask = 0;
s_assert(idx != NULL);
- DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
+ RB_DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
{
if (!(entry->flags & CAP_ORPHANED))
mask |= (1 << entry->value);
unsigned int
capability_index_get_required(struct CapabilityIndex *idx)
{
- struct DictionaryIter iter;
+ rb_dictionary_iter iter;
struct CapabilityEntry *entry;
unsigned int mask = 0;
s_assert(idx != NULL);
- DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
+ RB_DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
{
if (!(entry->flags & CAP_ORPHANED) && (entry->flags & CAP_REQUIRED))
mask |= (1 << entry->value);
RB_DLINK_FOREACH(node, capability_indexes.head)
{
struct CapabilityIndex *idx = node->data;
- struct DictionaryIter iter;
+ rb_dictionary_iter iter;
struct CapabilityEntry *entry;
snprintf(buf, sizeof buf, "'%s': allocated bits - %d", idx->name, (idx->highest_bit - 1));
cb(buf, privdata);
- DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
+ RB_DICTIONARY_FOREACH(entry, &iter, idx->cap_dict)
{
snprintf(buf, sizeof buf, "bit %d: '%s'", entry->value, entry->cap);
cb(buf, privdata);