23 #include "asterisk/logger_category.h"
39 struct categories_t categories;
49 if (level->id_pool == 0) {
51 }
else if (level->id_pool >= (UINTMAX_MAX / 2)) {
58 return level->id_pool;
61 static int cmp_by_name(
const struct category_t *category,
const char *name)
63 return !strcmp(category->name, name);
76 ast_log(LOG_ERROR,
"Cannot register logger category '%s'. "
77 "Name already used for type.\n", name);
81 category =
ast_calloc(1,
sizeof(*category) + strlen(name) + 1);
87 category->id = get_next_id(level);
88 category->sublevel = AST_LOG_CATEGORY_DISABLED;
89 strcpy(category->name, name);
93 ast_log(LOG_ERROR,
"Cannot register logger category '%s'. "
94 "Unable to append.\n", name);
113 static int casecmp_by_name(
const struct category_t *category,
const char *name)
115 return !strcasecmp(category->name, name);
119 const char *name,
int sublevel)
144 category->sublevel = sublevel;
146 if (category->sublevel == AST_LOG_CATEGORY_DISABLED) {
147 level->state &= ~category->id;
149 level->state |= category->id;
160 const char *
const *names,
size_t size,
int default_sublevel)
164 if (!names || !size) {
165 level->state = default_sublevel;
168 level, NULL, default_sublevel);
173 for (i = 0; i < size; ++i) {
174 const char *sublevel;
175 int num = default_sublevel;
177 sublevel = strchr(names[i],
':');
179 size_t len = ++sublevel - names[i];
187 category_set_sublevel(NULL, level, name, num);
189 category_set_sublevel(NULL, level, names[i], num);
196 static char *category_complete(
struct categories_level_t *level,
const char *
const *argv,
197 int argc,
const char *word,
int state)
199 int wordlen = strlen(word);
213 if (!strncasecmp(word, category->name, wordlen) && (++which > state)) {
215 for (j = 0; j < argc; ++j) {
216 if (!strncasecmp(category->name, argv[j], strlen(category->name))) {
241 static int category_is_allowed(
int sublevel,
struct categories_level_t *level, uintmax_t ids)
244 if (ids & level->state) {
247 if (sublevel == AST_LOG_CATEGORY_ENABLED || sublevel == 0) {
260 if ((category->id & ids) && category->sublevel != AST_LOG_CATEGORY_DISABLED &&
261 (category->sublevel == AST_LOG_CATEGORY_ENABLED || category->sublevel >= sublevel)) {
279 uintmax_t ast_debug_category_register(
const char *name)
281 return category_register(&debug_categories, name);
284 int ast_debug_category_unregister(
const char *name)
286 return category_unregister(&debug_categories, name);
289 int ast_debug_category_set_sublevel(
const char *name,
int sublevel)
291 return category_set_sublevel(NULL, &debug_categories, name, sublevel);
294 int ast_debug_category_set_sublevels(
const char *
const *names,
295 size_t size,
int default_sublevel)
297 return category_set_sublevels(&debug_categories, names, size, default_sublevel);
300 char *ast_debug_category_complete(
const char *
const *argv,
int argc,
301 const char *word,
int state)
303 return category_complete(&debug_categories, argv, argc, word, state);
306 int ast_debug_category_is_allowed(
int sublevel, uintmax_t ids)
308 return category_is_allowed(sublevel, &debug_categories, ids);
311 int ast_logger_category_unload(
void)
317 int ast_logger_category_load(
void)
#define AST_VECTOR_RW_INIT(vec, size)
Initialize a vector with a read/write lock.
#define AST_VECTOR_GET_INDEX(vec, value, cmp)
Get the 1st index from a vector that matches the given comparison.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
#define AST_VECTOR_RW_UNLOCK(vec)
Unlock vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR_RW_RDLOCK(vec)
Obtain read lock on vector.
#define ast_strdup(str)
A wrapper for strdup()
#define AST_VECTOR_RW_FREE(vec)
Deallocates this locked vector.
Conversion utility functions.
int ast_str_to_int(const char *str, int *res)
Convert the given string to a signed integer.
AST_VECTOR_RW(ast_sorcery_object_wizards, struct ast_sorcery_object_wizard *)
Interface for a sorcery object type wizards.
#define AST_VECTOR_RW_WRLOCK(vec)
Obtain write lock on vector.
#define ast_calloc(num, len)
A wrapper for calloc()
Vector container support.
#define AST_VECTOR_GET_CMP(vec, value, cmp)
Get an element from a vector that matches the given comparison.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.