capability: add capability_index_list() to build a list of capabilities given an index and mask
This commit is contained in:
parent
64b56afd8c
commit
5e773521a9
2 changed files with 30 additions and 0 deletions
|
@ -31,4 +31,6 @@ extern void capability_orphan(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);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -114,3 +114,31 @@ capability_index_destroy(struct CapabilityIndex *index)
|
|||
irc_dictionary_destroy(index->cap_dict, capability_destroy, NULL);
|
||||
rb_free(index);
|
||||
}
|
||||
|
||||
const char *
|
||||
capability_index_list(struct CapabilityIndex *index, unsigned int cap_mask)
|
||||
{
|
||||
struct DictionaryIter iter;
|
||||
struct CapabilityEntry *entry;
|
||||
static char buf[BUFSIZE];
|
||||
char *t = buf;
|
||||
int tl;
|
||||
|
||||
s_assert(index != NULL);
|
||||
|
||||
*t = '\0';
|
||||
|
||||
DICTIONARY_FOREACH(entry, &iter, index->cap_dict)
|
||||
{
|
||||
if (entry->value & cap_mask)
|
||||
{
|
||||
tl = rb_sprintf(t, "%s ", iter.cur->key);
|
||||
t += tl;
|
||||
}
|
||||
}
|
||||
|
||||
t--;
|
||||
*t = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue