capability: add capability_require().
This commit is contained in:
parent
0582290f21
commit
f01f67f0ad
2 changed files with 36 additions and 0 deletions
|
@ -27,10 +27,12 @@ struct CapabilityEntry;
|
|||
extern unsigned int capability_get(struct CapabilityIndex *index, const char *cap);
|
||||
extern unsigned int capability_put(struct CapabilityIndex *index, const char *cap);
|
||||
extern void capability_orphan(struct CapabilityIndex *index, const char *cap);
|
||||
extern void capability_require(struct CapabilityIndex *index, const char *cap);
|
||||
|
||||
extern struct CapabilityIndex *capability_index_create(void);
|
||||
extern void capability_index_destroy(struct CapabilityIndex *);
|
||||
extern const char *capability_index_list(struct CapabilityIndex *, unsigned int capability_mask);
|
||||
extern unsigned int capability_index_mask(struct CapabilityIndex *);
|
||||
extern unsigned int capability_index_get_required(struct CapabilityIndex *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@ struct CapabilityIndex {
|
|||
};
|
||||
|
||||
#define CAP_ORPHANED 0x1
|
||||
#define CAP_REQUIRED 0x2
|
||||
|
||||
struct CapabilityEntry {
|
||||
unsigned int value;
|
||||
|
@ -85,8 +86,23 @@ capability_orphan(struct CapabilityIndex *index, const char *cap)
|
|||
|
||||
entry = irc_dictionary_retrieve(index->cap_dict, cap);
|
||||
if (entry != NULL)
|
||||
{
|
||||
entry->flags &= ~CAP_REQUIRED;
|
||||
entry->flags |= CAP_ORPHANED;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
capability_require(struct CapabilityIndex *index, const char *cap)
|
||||
{
|
||||
struct CapabilityEntry *entry;
|
||||
|
||||
s_assert(index != NULL);
|
||||
|
||||
entry = irc_dictionary_retrieve(index->cap_dict, cap);
|
||||
if (entry != NULL)
|
||||
entry->flags |= CAP_REQUIRED;
|
||||
}
|
||||
|
||||
static void
|
||||
capability_destroy(struct DictionaryElement *delem, void *privdata)
|
||||
|
@ -162,3 +178,21 @@ capability_index_mask(struct CapabilityIndex *index)
|
|||
|
||||
return mask;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
capability_index_get_required(struct CapabilityIndex *index)
|
||||
{
|
||||
struct DictionaryIter iter;
|
||||
struct CapabilityEntry *entry;
|
||||
unsigned int mask = 0;
|
||||
|
||||
s_assert(index != NULL);
|
||||
|
||||
DICTIONARY_FOREACH(entry, &iter, index->cap_dict)
|
||||
{
|
||||
if (!(entry->flags & CAP_ORPHANED) && (entry->flags & CAP_REQUIRED))
|
||||
mask |= entry->value;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue