40 #define VARIANT_BUCKETS 7 43 #define INDEX_BUCKETS 157 64 size_t str_sz = strlen(variant_str) + 1;
73 memcpy(variant->
variant, variant_str, str_sz);
113 size_t name_sz = strlen(name) + 1;
122 memcpy(info->
name, name, name_sz);
144 const char *
name = (flags &
OBJ_KEY) ? arg : opt2->name;
164 size_t base_dir_sz = strlen(base_dir) + 1;
171 memcpy(index->
base_dir, base_dir, base_dir_sz);
349 const char *file_identifier = filename_stripped;
350 char *file_id_str =
NULL;
361 if (
ast_asprintf(&file_id_str,
"%s/%s", subdir, filename_stripped) == -1) {
365 file_identifier = file_id_str;
382 const char *variant_str,
383 const char *filename,
384 const char *match_filename)
388 char *file_id_persist =
NULL;
391 #if defined(LOW_MEMORY) 397 if (!description_file_path || !cumulative_description) {
402 ast_str_set(&description_file_path, 0,
"%s/%s/%s", index->
base_dir, variant_str, filename);
404 ast_str_set(&description_file_path, 0,
"%s/%s/%s/%s", index->
base_dir, variant_str, subdir, filename);
414 if (!fgets(buf,
sizeof(buf), f)) {
422 if (strlen(buf) ==
sizeof(buf) - 1 && buf[
sizeof(buf) - 1] !=
'\n') {
424 while (fgets(buf,
sizeof(buf), f)) {
425 if (strlen(buf) !=
sizeof(buf) - 1 || buf[
sizeof(buf) - 1] ==
'\n') {
442 file_identifier =
strsep(&description,
":");
445 if (file_id_persist) {
446 ast_str_append(&cumulative_description, 0,
"\n%s", file_identifier);
458 if (
ast_strlen_zero(match_filename) || strcmp(match_filename, file_id_persist) == 0) {
459 variant =
alloc_variant(index, file_id_persist, variant_str);
472 file_id_persist =
ast_strdup(file_identifier);
474 ast_str_set(&cumulative_description, 0,
"%s", description);
486 if (
ast_strlen_zero(match_filename) || strcmp(match_filename, file_id_persist) == 0) {
487 variant =
alloc_variant(index, file_id_persist, variant_str);
510 static int read_dirs_cb(
const char *dir_name,
const char *filename,
void *obj)
516 size_t match_base_len;
517 char *subdirs = (
char *)dir_name + data->
dirname_len;
535 if (*subdirs ==
'/') {
541 match_len = strlen(subdirs) + strlen(filename) + 2;
543 snprintf(match, match_len,
"%s%s%s", subdirs,
548 ext = strrchr(match,
'.');
556 match_base_len = ext -
match;
572 if (strcmp(ext,
".txt") == 0) {
588 const char *
variant,
const char *filename)
590 struct timeval start;
594 size_t dirname_len = strlen(index->
base_dir) + strlen(
S_OR(variant,
"")) + 1;
597 .search_filename_len = strlen(
S_OR(filename,
"")),
598 .search_variant =
S_OR(variant,
""),
602 char *search_dir =
ast_alloca(dirname_len + 1);
607 gettimeofday(&start,
NULL);
609 gettimeofday(&end,
NULL);
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ao2_callback(c, flags, cb_fn, arg)
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ao2_alloc_options(data_size, destructor_fn, options)
const char * search_filename
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_file_read_dirs(const char *dir_name, ast_file_on_file on_file, void *obj, int max_depth)
Recursively iterate through files and directories up to max_depth.
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_strlen_zero(foo)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_debug(level,...)
Log a DEBUG message.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
size_t search_filename_len
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
#define ao2_alloc(data_size, destructor_fn)
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
#define ao2_find(container, arg, flags)
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
const char * search_variant
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
char * strsep(char **str, const char *delims)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
struct ast_media_index * index
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ao2_link(container, obj)