apps/app_selective.c
static int _db_crawl(struct ast_channel *chan,
	char *parse, struct ast_str *strbuf, char *buf, struct selective_proc *f,
	int (*callback)(char *family, char *key, int res),
	int (*callback2)(int crawlindex, char *family, char *key, struct ast_channel *chan, struct ast_str *strbuf, char *buf, struct selective_proc *f))
{
	size_t parselen = strlen(parse);
	struct ast_db_entry *dbe, *orig_dbe;
	struct ast_str *escape_buf = NULL;
	const char *last = "";
	int crawlindex = 0, res = 0;

	/* Remove leading and trailing slashes */
	while (parse[0] == '/') {
		parse++;
		parselen--;
	}
	while (parse[parselen - 1] == '/') {
		parse[--parselen] = '\0';
	}

	/* Nothing within the database at that prefix? */
	if (!(orig_dbe = dbe = ast_db_gettree(parse, NULL))) {
		return 0;
	}

	for (; dbe; dbe = dbe->next) {
		/* Find the current component */
		char *curkey = &dbe->key[parselen + 1], *slash;
		if (*curkey == '/') {
			curkey++;
		}
		/* Remove everything after the current component */
		if ((slash = strchr(curkey, '/'))) {
			*slash = '\0';
		}

		/* Skip duplicates */
		if (!strcasecmp(last, curkey)) {
			continue;
		}
		last = curkey;

		/* parse = family (at this point, not the parameter when passed in) */
		if (callback) {
			res = callback(parse, curkey, res); /* execute callback function */
		} else if (callback2 && chan && strbuf && buf && f) {
			res = callback2(crawlindex++, parse, curkey, chan, strbuf, buf, f);
			if (res < 0) {
				break;
			}
		} else {
			ast_log(LOG_WARNING, "No callback function available!\n");
		}
	}
	ast_db_freetree(orig_dbe);
	ast_free(escape_buf);
	return res;
}
/*! \brief Crawl AstDB and execute a callback function on each key */
\brief Crawl AstDB and execute a callback function on each key
\ brief Crawl AstDB and execute a callback function on each key
static int _db_crawl(struct ast_channel *chan,
	char *parse, struct ast_str *strbuf, char *buf, struct selective_proc *f,
	int (*callback)(char *family, char *key, int res),
	int (*callback2)(int crawlindex, char *family, char *key, struct ast_channel *chan, struct ast_str *strbuf, char *buf, struct selective_proc *f))
{
	size_t parselen = strlen(parse);
	struct ast_db_entry *dbe, *orig_dbe;
	struct ast_str *escape_buf = NULL;
	const char *last = "";
	int crawlindex = 0, res = 0;
	while (parse[0] == '/') {
		parse++;
		parselen--;
	}
	while (parse[parselen - 1] == '/') {
		parse[--parselen] = '\0';
	}
	if (!(orig_dbe = dbe = ast_db_gettree(parse, NULL))) {
		return 0;
	}
	for (; dbe; dbe = dbe->next) {
		char *curkey = &dbe->key[parselen + 1], *slash;
		if (*curkey == '/') {
			curkey++;
		}
		if ((slash = strchr(curkey, '/'))) {
			*slash = '\0';
		}
		if (!strcasecmp(last, curkey)) {
			continue;
		}
		last = curkey;
		if (callback) {
			res = callback(parse, curkey, res); 
		} else if (callback2 && chan && strbuf && buf && f) {
			res = callback2(crawlindex++, parse, curkey, chan, strbuf, buf, f);
			if (res < 0) {
				break;
			}
		} else {
			ast_log(LOG_WARNING, "No callback function available!\n");
		}
	}
	ast_db_freetree(orig_dbe);
	ast_free(escape_buf);
	return res;
}
static int _db_crawl ( struct ast_channel * chan , char * parse , struct ast_str * strbuf , char * buf , struct selective_proc * f , int ( * callback ) ( char * family , char * key , int res ) , int ( * callback2 ) ( int crawlindex , char * family , char * key , struct ast_channel * chan , struct ast_str * strbuf , char * buf , struct selective_proc * f ) ) { size_t parselen = strlen ( parse ) ; struct ast_db_entry * dbe , * orig_dbe ; struct ast_str * escape_buf = NULL ; const char * last = " " ; int crawlindex = 0 , res = 0 ; while ( parse [ 0 ] == ' ' ) { parse ++ ; parselen -- ; } while ( parse [ parselen - 1 ] == ' ' ) { parse [ -- parselen ] = ' \0 ' ; } if ( ! ( orig_dbe = dbe = ast_db_gettree ( parse , NULL ) ) ) { return 0 ; } for ( ; dbe ; dbe = dbe -> next ) { char * curkey = & dbe -> key [ parselen + 1 ] , * slash ; if ( * curkey == ' ' ) { curkey ++ ; } if ( ( slash = strchr ( curkey , ' ' ) ) ) { * slash = ' \0 ' ; } if ( ! strcasecmp ( last , curkey ) ) { continue ; } last = curkey ; if ( callback ) { res = callback ( parse , curkey , res ) ; } else if ( callback2 && chan && strbuf && buf && f ) { res = callback2 ( crawlindex ++ , parse , curkey , chan , strbuf , buf , f ) ; if ( res < 0 ) { break ; } } else { ast_log ( LOG_WARNING , " \n " ) ; } } ast_db_freetree ( orig_dbe ) ; ast_free ( escape_buf ) ; return res ; }
\brief Crawl AstDB and execute a callback function on each key
\ brief Crawl AstDB and execute a callback function on each key
/* Remove leading and trailing slashes */ /* Nothing within the database at that prefix? */ /* Find the current component */ /* Remove everything after the current component */ /* Skip duplicates */ /* parse = family (at this point, not the parameter when passed in) */ /* execute callback function */