mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-24 22:58:21 +00:00
This commit closes bug 7605, and half-closes 7638. The AEL code has been redistributed/repartitioned to allow code re-use both inside and outside of Asterisk. This commit introduces the utils/conf2ael program, and an external config-file reader, for both normal config files, and for extensions.conf (context, exten, prio); It provides an API for programs outside of asterisk to use to play with the dialplan and config files.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@79595 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -21,8 +21,67 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ast_channel
|
||||
{
|
||||
char x; /* basically empty! */
|
||||
};
|
||||
|
||||
#include <../include/asterisk/compat.h>
|
||||
#include <../include/asterisk/ast_expr.h>
|
||||
#define AST_API_MODULE 1
|
||||
#include "asterisk/inline_api.h"
|
||||
#include "asterisk/strings.h"
|
||||
|
||||
/* I included this from utils.c, so as not to have everything in that .c
|
||||
file included */
|
||||
/*!
|
||||
* core handler for dynamic strings.
|
||||
* This is not meant to be called directly, but rather through the
|
||||
* various wrapper macros
|
||||
* ast_str_set(...)
|
||||
* ast_str_append(...)
|
||||
* ast_str_set_va(...)
|
||||
* ast_str_append_va(...)
|
||||
*/
|
||||
int __ast_str_helper(struct ast_str **buf, size_t max_len,
|
||||
int append, const char *fmt, va_list ap)
|
||||
{
|
||||
int res, need;
|
||||
int offset = (append && (*buf)->len) ? (*buf)->used : 0;
|
||||
|
||||
if (max_len < 0)
|
||||
max_len = (*buf)->len; /* don't exceed the allocated space */
|
||||
/*
|
||||
* Ask vsnprintf how much space we need. Remember that vsnprintf
|
||||
* does not count the final '\0' so we must add 1.
|
||||
*/
|
||||
res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap);
|
||||
|
||||
need = res + offset + 1;
|
||||
/*
|
||||
* If there is not enough space and we are below the max length,
|
||||
* reallocate the buffer and return a message telling to retry.
|
||||
*/
|
||||
if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
|
||||
if (max_len && max_len < need) /* truncate as needed */
|
||||
need = max_len;
|
||||
else if (max_len == 0) /* if unbounded, give more room for next time */
|
||||
need += 16 + need/4;
|
||||
if (ast_str_make_space(buf, need)) {
|
||||
return AST_DYNSTR_BUILD_FAILED;
|
||||
}
|
||||
(*buf)->str[offset] = '\0'; /* Truncate the partial write. */
|
||||
|
||||
/* va_end() and va_start() must be done before calling
|
||||
* vsnprintf() again. */
|
||||
return AST_DYNSTR_BUILD_RETRY;
|
||||
}
|
||||
/* update space used, keep in mind the truncation */
|
||||
(*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int global_lineno = 1;
|
||||
static int global_expr_count=0;
|
||||
@@ -83,6 +142,8 @@ char *find_var(const char *varname) /* the list should be pretty short, if there
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_var(const char *varname, const char *varval);
|
||||
|
||||
void set_var(const char *varname, const char *varval)
|
||||
{
|
||||
struct varz *t = (struct varz*)calloc(1,sizeof(struct varz));
|
||||
@@ -162,6 +223,8 @@ unsigned int check_expr(char* buffer, char* error_report)
|
||||
return warn_found;
|
||||
}
|
||||
|
||||
int check_eval(char *buffer, char *error_report);
|
||||
|
||||
struct ast_custom_function *ast_custom_function_find(const char *name);
|
||||
|
||||
struct ast_custom_function *ast_custom_function_find(const char *name)
|
||||
@@ -240,6 +303,8 @@ int check_eval(char *buffer, char *error_report)
|
||||
}
|
||||
|
||||
|
||||
void parse_file(const char *fname);
|
||||
|
||||
void parse_file(const char *fname)
|
||||
{
|
||||
FILE *f = fopen(fname,"r");
|
||||
|
Reference in New Issue
Block a user