1999-10-27 00:56:38 +00:00
|
|
|
/*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-10-27 00:56:38 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
1999-10-27 00:56:38 +00:00
|
|
|
*
|
2005-01-25 06:10:20 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-10-27 00:56:38 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
1999-10-27 00:56:38 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-08-30 18:32:10 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
|
|
|
* \brief Configuration File Parser
|
1999-10-27 00:56:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASTERISK_CONFIG_H
|
|
|
|
#define _ASTERISK_CONFIG_H
|
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
#include "asterisk/utils.h"
|
2008-06-09 22:51:59 +00:00
|
|
|
#include "asterisk/inline_api.h"
|
2005-01-25 06:10:20 +00:00
|
|
|
|
1999-10-27 00:56:38 +00:00
|
|
|
struct ast_config;
|
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
struct ast_category;
|
2002-04-23 19:05:55 +00:00
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
/*! Options for ast_config_load()
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/*! Load the configuration, including comments */
|
|
|
|
CONFIG_FLAG_WITHCOMMENTS = (1 << 0),
|
|
|
|
/*! On a reload, give us a -1 if the file hasn't changed. */
|
|
|
|
CONFIG_FLAG_FILEUNCHANGED = (1 << 1),
|
|
|
|
/*! Don't attempt to cache mtime on this config file. */
|
|
|
|
CONFIG_FLAG_NOCACHE = (1 << 2),
|
2010-07-20 19:35:02 +00:00
|
|
|
/*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */
|
|
|
|
CONFIG_FLAG_NOREALTIME = (1 << 3),
|
2007-08-16 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a
context C(T) that doesn't specify VAR1. If you read C, the effective value
of VAR1 is ON. Now you change T VAR1 to OFF and call
ast_config_text_file_save. The current behavior is that the file gets
re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this
is a bug. It's preserving the effective state of C even though I didn't
specify C/VAR1 in th first place. I believe the behavior should be that if
I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should
continue to follow the inherited state. Now, if I DID explicitly specify
C/VAR1, the it should be preserved even if the template changes.
Even though I think the existing behavior is a bug, it's been that way forever
so I'm not changing it. Instead, I've created ast_config_text_file_save2()
that takes a bitmask of flags, one of which is to preserve the effective context
(the current behavior). The original ast_config_text_file_save calls *2 with
the preserve flag. If you want the new behavior, call *2 directly without a
flag.
I've also updated Manager UpdateConfig with a new parameter
'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior
with UpdateConfig, set 'PreserveEffectiveContext: no'.
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4297/
........
Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07 16:56:59 +00:00
|
|
|
/*! Flags for ast_config_text_file_save2()
|
|
|
|
*/
|
|
|
|
enum config_save_flags {
|
|
|
|
CONFIG_SAVE_FLAG_NONE = (0),
|
|
|
|
/*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */
|
|
|
|
CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT = (1 << 0),
|
|
|
|
};
|
|
|
|
|
2008-09-12 23:30:03 +00:00
|
|
|
#define CONFIG_STATUS_FILEMISSING (void *)0
|
2007-08-16 21:09:46 +00:00
|
|
|
#define CONFIG_STATUS_FILEUNCHANGED (void *)-1
|
2008-09-12 23:30:03 +00:00
|
|
|
#define CONFIG_STATUS_FILEINVALID (void *)-2
|
2007-08-16 21:09:46 +00:00
|
|
|
|
2008-06-05 19:07:27 +00:00
|
|
|
/*!
|
|
|
|
* \brief Types used in ast_realtime_require_field
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2008-06-09 22:51:59 +00:00
|
|
|
RQ_INTEGER1,
|
|
|
|
RQ_UINTEGER1,
|
|
|
|
RQ_INTEGER2,
|
|
|
|
RQ_UINTEGER2,
|
|
|
|
RQ_INTEGER3,
|
|
|
|
RQ_UINTEGER3,
|
|
|
|
RQ_INTEGER4,
|
|
|
|
RQ_UINTEGER4,
|
|
|
|
RQ_INTEGER8,
|
|
|
|
RQ_UINTEGER8,
|
2008-06-05 19:07:27 +00:00
|
|
|
RQ_CHAR,
|
|
|
|
RQ_FLOAT,
|
|
|
|
RQ_DATE,
|
|
|
|
RQ_DATETIME,
|
|
|
|
} require_type;
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*! \brief Structure for variables, used for configurations and for channel variables */
|
1999-10-27 00:56:38 +00:00
|
|
|
struct ast_variable {
|
2011-09-02 17:19:17 +00:00
|
|
|
/*! Variable name. Stored in stuff[] at struct end. */
|
2007-11-14 13:18:40 +00:00
|
|
|
const char *name;
|
2011-09-02 17:19:17 +00:00
|
|
|
/*! Variable value. Stored in stuff[] at struct end. */
|
2007-11-14 13:18:40 +00:00
|
|
|
const char *value;
|
2011-09-02 17:19:17 +00:00
|
|
|
|
|
|
|
/*! Next node in the list. */
|
2007-11-14 13:18:40 +00:00
|
|
|
struct ast_variable *next;
|
|
|
|
|
2011-09-02 17:19:17 +00:00
|
|
|
/*! Filename where variable found. Stored in stuff[] at struct end. */
|
|
|
|
const char *file;
|
2007-11-14 13:18:40 +00:00
|
|
|
|
2001-04-23 16:50:12 +00:00
|
|
|
int lineno;
|
2005-10-24 20:12:06 +00:00
|
|
|
int object; /*!< 0 for variable, 1 for object */
|
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a
context C(T) that doesn't specify VAR1. If you read C, the effective value
of VAR1 is ON. Now you change T VAR1 to OFF and call
ast_config_text_file_save. The current behavior is that the file gets
re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this
is a bug. It's preserving the effective state of C even though I didn't
specify C/VAR1 in th first place. I believe the behavior should be that if
I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should
continue to follow the inherited state. Now, if I DID explicitly specify
C/VAR1, the it should be preserved even if the template changes.
Even though I think the existing behavior is a bug, it's been that way forever
so I'm not changing it. Instead, I've created ast_config_text_file_save2()
that takes a bitmask of flags, one of which is to preserve the effective context
(the current behavior). The original ast_config_text_file_save calls *2 with
the preserve flag. If you want the new behavior, call *2 directly without a
flag.
I've also updated Manager UpdateConfig with a new parameter
'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior
with UpdateConfig, set 'PreserveEffectiveContext: no'.
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4297/
........
Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07 16:56:59 +00:00
|
|
|
int blanklines; /*!< Number of blanklines following entry */
|
|
|
|
int inherited; /*!< 1 for inherited from template or other base */
|
2002-04-23 19:05:55 +00:00
|
|
|
struct ast_comment *precomments;
|
|
|
|
struct ast_comment *sameline;
|
2007-09-05 14:47:45 +00:00
|
|
|
struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
|
2011-09-02 17:19:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Contents of file, name, and value in that order stuffed here.
|
|
|
|
* \note File must be stuffed before name because of ast_include_rename().
|
|
|
|
*/
|
2004-10-05 06:46:11 +00:00
|
|
|
char stuff[0];
|
1999-10-27 00:56:38 +00:00
|
|
|
};
|
|
|
|
|
2008-03-11 22:55:16 +00:00
|
|
|
typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked);
|
2013-04-27 12:01:29 +00:00
|
|
|
typedef struct ast_variable *realtime_var_get(const char *database, const char *table, const struct ast_variable *fields);
|
|
|
|
typedef struct ast_config *realtime_multi_get(const char *database, const char *table, const struct ast_variable *fields);
|
|
|
|
typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
|
|
|
|
typedef int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
|
|
|
|
typedef int realtime_store(const char *database, const char *table, const struct ast_variable *fields);
|
|
|
|
typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
|
2009-03-09 20:58:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function pointer called to ensure database schema is properly configured for realtime use
|
|
|
|
* \since 1.6.1
|
|
|
|
*/
|
2008-06-05 19:07:27 +00:00
|
|
|
typedef int realtime_require(const char *database, const char *table, va_list ap);
|
2009-03-09 20:58:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function pointer called to clear the database cache and free resources used for such
|
|
|
|
* \since 1.6.1
|
|
|
|
*/
|
2008-06-05 19:07:27 +00:00
|
|
|
typedef int realtime_unload(const char *database, const char *table);
|
2005-01-25 06:10:20 +00:00
|
|
|
|
2007-02-24 20:29:41 +00:00
|
|
|
/*! \brief Configuration engine structure, used to define realtime drivers */
|
2005-01-25 06:10:20 +00:00
|
|
|
struct ast_config_engine {
|
|
|
|
char *name;
|
|
|
|
config_load_func *load_func;
|
|
|
|
realtime_var_get *realtime_func;
|
|
|
|
realtime_multi_get *realtime_multi_func;
|
|
|
|
realtime_update *update_func;
|
2008-10-14 00:08:52 +00:00
|
|
|
realtime_update2 *update2_func;
|
2007-03-27 14:09:12 +00:00
|
|
|
realtime_store *store_func;
|
|
|
|
realtime_destroy *destroy_func;
|
2008-06-05 19:07:27 +00:00
|
|
|
realtime_require *require_func;
|
|
|
|
realtime_unload *unload_func;
|
2005-01-25 06:10:20 +00:00
|
|
|
struct ast_config_engine *next;
|
|
|
|
};
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load a config file
|
|
|
|
*
|
|
|
|
* \param filename path of file to open. If no preceding '/' character,
|
|
|
|
* path is considered relative to AST_CONFIG_DIR
|
2008-03-11 22:55:16 +00:00
|
|
|
* \param who_asked The module which is making this request.
|
2007-08-16 21:09:46 +00:00
|
|
|
* \param flags Optional flags:
|
|
|
|
* CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
|
|
|
|
* CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
|
|
|
|
* CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
|
2005-01-25 06:10:20 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \details
|
|
|
|
* Create a config structure from a given configuration file.
|
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return an ast_config data structure on success
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval NULL on error
|
2001-10-31 15:28:08 +00:00
|
|
|
*/
|
2008-03-11 22:55:16 +00:00
|
|
|
struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags);
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load a config file
|
|
|
|
*
|
|
|
|
* \param filename path of file to open. If no preceding '/' character,
|
|
|
|
* path is considered relative to AST_CONFIG_DIR
|
|
|
|
* \param flags Optional flags:
|
|
|
|
* CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
|
|
|
|
* CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
|
|
|
|
* CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Create a config structure from a given configuration file.
|
|
|
|
*
|
|
|
|
* \return an ast_config data structure on success
|
|
|
|
* \retval NULL on error
|
|
|
|
*/
|
2008-03-26 18:39:06 +00:00
|
|
|
#define ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags)
|
2001-10-31 15:28:08 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Destroys a config
|
|
|
|
*
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param cfg pointer to config data structure
|
2005-01-25 06:10:20 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \details
|
|
|
|
* Free memory associated with a given config
|
2001-10-31 15:28:08 +00:00
|
|
|
*/
|
2021-11-19 15:47:25 +00:00
|
|
|
void ast_config_destroy(struct ast_config *cfg);
|
2001-10-31 15:28:08 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief returns the root ast_variable of a config
|
|
|
|
*
|
2007-08-06 16:54:51 +00:00
|
|
|
* \param config pointer to an ast_config data structure
|
|
|
|
* \param cat name of the category for which you want the root
|
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \return the category specified
|
2007-08-06 16:54:51 +00:00
|
|
|
*/
|
|
|
|
struct ast_variable *ast_category_root(struct ast_config *config, char *cat);
|
|
|
|
|
2012-07-11 18:33:36 +00:00
|
|
|
/*!
|
|
|
|
* \brief Sorts categories in a config in the order of a numerical value contained within them.
|
|
|
|
*
|
|
|
|
* \param config The config structure you wish to sort
|
2012-08-30 14:23:28 +00:00
|
|
|
* \param comparator variable Which numerical value you wish to sort by
|
2012-07-11 18:33:36 +00:00
|
|
|
* \param descending If true, we sort highest to lowest instead of lowest to highest
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function will assume a value of 0 for any non-numerical strings and NULL fields.
|
|
|
|
*/
|
|
|
|
void ast_config_sort_categories(struct ast_config *config, int descending,
|
|
|
|
int (*comparator)(struct ast_category *p, struct ast_category *q));
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
2014-10-13 16:12:17 +00:00
|
|
|
* \brief Browse categories with filters
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2005-01-25 06:10:20 +00:00
|
|
|
* \param config Which config structure you wish to "browse"
|
2014-10-13 16:12:17 +00:00
|
|
|
* \param category_name An optional category name.
|
|
|
|
* Pass NULL to not restrict by category name.
|
|
|
|
* \param prev A pointer to the starting category structure.
|
|
|
|
* Pass NULL to start at the beginning.
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param filter An optional comma-separated list of \<name_regex\>=\<value_regex\>
|
2014-10-13 16:12:17 +00:00
|
|
|
* pairs. Only categories with matching variables will be returned.
|
|
|
|
* The special name 'TEMPLATES' can be used with the special values
|
|
|
|
* 'include' or 'restrict' to include templates in the result or
|
|
|
|
* restrict the result to only templates.
|
|
|
|
*
|
|
|
|
* \retval a category on success
|
|
|
|
* \retval NULL on failure/no-more-categories
|
|
|
|
*/
|
|
|
|
struct ast_category *ast_category_browse_filtered(struct ast_config *config,
|
|
|
|
const char *category_name, struct ast_category *prev, const char *filter);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Browse categories
|
|
|
|
*
|
|
|
|
* \param config Which config structure you wish to "browse"
|
|
|
|
* \param prev_name A pointer to a previous category name.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is kind of non-intuitive in it's use.
|
|
|
|
* To begin, one passes NULL as the second argument.
|
|
|
|
* It will return a pointer to the string of the first category in the file.
|
|
|
|
* From here on after, one must then pass the previous usage's return value
|
|
|
|
* as the second pointer, and it will return a pointer to the category name
|
|
|
|
* afterwards.
|
2005-01-25 06:10:20 +00:00
|
|
|
*
|
2014-10-13 16:12:17 +00:00
|
|
|
* \retval a category name on success
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval NULL on failure/no-more-categories
|
2014-10-16 17:32:16 +00:00
|
|
|
*
|
|
|
|
* \note ast_category_browse maintains internal state. Therefore is not thread
|
|
|
|
* safe, cannot be called recursively, and it is not safe to add or remove
|
|
|
|
* categories while browsing.
|
|
|
|
* ast_category_browse_filtered does not have these restrictions.
|
2001-10-31 15:28:08 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
char *ast_category_browse(struct ast_config *config, const char *prev_name);
|
2001-10-31 15:28:08 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
2014-10-13 16:12:17 +00:00
|
|
|
* \brief Browse variables
|
|
|
|
* \param config Which config structure you wish to "browse"
|
|
|
|
* \param category_name Which category to "browse"
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param filter an optional comma-separated list of \<name_regex\>=\<value_regex\>
|
2014-10-13 16:12:17 +00:00
|
|
|
* pairs. Only categories with matching variables will be browsed.
|
|
|
|
* The special name 'TEMPLATES' can be used with the special values
|
|
|
|
* 'include' or 'restrict' to include templates in the result or
|
|
|
|
* restrict the result to only templates.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2005-01-25 06:10:20 +00:00
|
|
|
* Somewhat similar in intent as the ast_category_browse.
|
|
|
|
* List variables of config file category
|
|
|
|
*
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval ast_variable list on success
|
|
|
|
* \retval NULL on failure
|
2001-10-31 15:28:08 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
struct ast_variable *ast_variable_browse_filtered(const struct ast_config *config,
|
|
|
|
const char *category_name, const char *filter);
|
|
|
|
struct ast_variable *ast_variable_browse(const struct ast_config *config,
|
|
|
|
const char *category_name);
|
2001-10-31 15:28:08 +00:00
|
|
|
|
2007-11-16 10:07:24 +00:00
|
|
|
/*!
|
|
|
|
* \brief given a pointer to a category, return the root variable.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2007-11-16 10:07:24 +00:00
|
|
|
* This is equivalent to ast_variable_browse(), but more efficient if we
|
|
|
|
* already have the struct ast_category * (e.g. from ast_category_get())
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_category_first(struct ast_category *cat);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
2014-10-13 16:12:17 +00:00
|
|
|
* \brief Gets a variable by context and variable names
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2001-10-31 15:28:08 +00:00
|
|
|
* \param config which (opened) config to use
|
2005-01-25 06:10:20 +00:00
|
|
|
* \param category category under which the variable lies
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param variable which variable you wish to get the data for
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param filter an optional comma-separated list of \<name_regex\>=\<value_regex\>
|
2014-10-13 16:12:17 +00:00
|
|
|
* pairs. Only categories with matching variables will be searched.
|
|
|
|
* The special name 'TEMPLATES' can be used with the special values
|
|
|
|
* 'include' or 'restrict' to include templates in the result or
|
|
|
|
* restrict the result to only templates.
|
|
|
|
*
|
|
|
|
* \retval The variable value on success
|
|
|
|
* \retval NULL if unable to find it.
|
|
|
|
*/
|
|
|
|
const char *ast_variable_retrieve_filtered(struct ast_config *config,
|
|
|
|
const char *category, const char *variable, const char *filter);
|
|
|
|
const char *ast_variable_retrieve(struct ast_config *config,
|
|
|
|
const char *category, const char *variable);
|
|
|
|
|
|
|
|
/*!
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
* \brief Gets a variable value from a specific category structure by name
|
2014-10-13 16:12:17 +00:00
|
|
|
*
|
|
|
|
* \param category category structure under which the variable lies
|
|
|
|
* \param variable which variable you wish to get the data for
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2014-10-13 16:12:17 +00:00
|
|
|
* Goes through a given category and searches for the given variable
|
2005-01-25 06:10:20 +00:00
|
|
|
*
|
2009-03-09 20:58:17 +00:00
|
|
|
* \retval The variable value on success
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval NULL if unable to find it.
|
2005-01-25 06:10:20 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
const char *ast_variable_find(const struct ast_category *category, const char *variable);
|
2001-10-31 15:28:08 +00:00
|
|
|
|
2014-12-02 00:38:56 +00:00
|
|
|
/*!
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
* \brief Gets the value of a variable from a variable list by name
|
2014-12-02 00:38:56 +00:00
|
|
|
*
|
|
|
|
* \param list variable list to search
|
|
|
|
* \param variable which variable you wish to get the data for
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Goes through a given variable list and searches for the given variable
|
|
|
|
*
|
|
|
|
* \retval The variable value on success
|
|
|
|
* \retval NULL if unable to find it.
|
|
|
|
*/
|
|
|
|
const char *ast_variable_find_in_list(const struct ast_variable *list, const char *variable);
|
|
|
|
|
2015-05-14 23:01:56 +00:00
|
|
|
/*!
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
* \brief Gets the value of the LAST occurrence of a variable from a variable list
|
2015-05-14 23:01:56 +00:00
|
|
|
*
|
|
|
|
* \param list The ast_variable list to search
|
|
|
|
* \param variable The name of the ast_variable you wish to fetch data for
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Iterates over a given ast_variable list to search for the last occurrence of an
|
|
|
|
* ast_variable entry with a name attribute matching the given name (variable).
|
|
|
|
* This is useful if the list has duplicate entries (such as in cases where entries
|
|
|
|
* are created by a template)
|
|
|
|
*
|
|
|
|
* \retval The variable value on success
|
|
|
|
* \retval NULL if unable to find it.
|
|
|
|
*/
|
|
|
|
const char *ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable);
|
|
|
|
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
/*!
|
|
|
|
* \brief Gets a variable from a variable list by name
|
|
|
|
* \since 13.9.0
|
|
|
|
*
|
|
|
|
* \param list variable list to search
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param variable_name name you wish to get the data for
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Goes through a given variable list and searches for the given variable
|
|
|
|
*
|
|
|
|
* \retval The variable (not the value) on success
|
|
|
|
* \retval NULL if unable to find it.
|
|
|
|
*/
|
|
|
|
const struct ast_variable *ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
2007-07-16 02:51:56 +00:00
|
|
|
* \brief Retrieve a category if it exists
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2005-01-22 22:13:11 +00:00
|
|
|
* \param config which config to use
|
|
|
|
* \param category_name name of the category you're looking for
|
2014-10-13 16:12:17 +00:00
|
|
|
* \param filter If a config contains more than 1 category with the same name,
|
|
|
|
* you can specify a filter to narrow the search. The filter is a comma-separated
|
2021-11-19 15:47:25 +00:00
|
|
|
* list of \<name_regex\>=\<value_regex\> pairs. Only a category with matching
|
2014-10-13 16:12:17 +00:00
|
|
|
* variables will be returned. The special name 'TEMPLATES' can be used with the
|
|
|
|
* special values 'include' or 'restrict' to include templates in the result or
|
|
|
|
* restrict the result to only templates.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2005-01-25 06:10:20 +00:00
|
|
|
* This will search through the categories within a given config file for a match.
|
|
|
|
*
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval pointer to category if found
|
|
|
|
* \retval NULL if not.
|
2005-01-25 06:10:20 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
struct ast_category *ast_category_get(const struct ast_config *config,
|
|
|
|
const char *category_name, const char *filter);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Return the name of the category
|
|
|
|
*
|
|
|
|
* \param category category structure
|
|
|
|
*
|
|
|
|
* \retval pointer to category name if found
|
|
|
|
* \retval NULL if not.
|
|
|
|
*/
|
|
|
|
const char *ast_category_get_name(const struct ast_category *category);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Check if category is a template
|
|
|
|
*
|
|
|
|
* \param category category structure
|
|
|
|
*
|
|
|
|
* \retval 1 if a template.
|
|
|
|
* \retval 0 if not.
|
|
|
|
*/
|
|
|
|
int ast_category_is_template(const struct ast_category *category);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Return the template names this category inherits from
|
|
|
|
*
|
|
|
|
* \param category category structure
|
|
|
|
*
|
|
|
|
* \return an ast_str (which must be freed after use) with a comma
|
|
|
|
* separated list of templates names or NULL if there were no templates.
|
|
|
|
*/
|
|
|
|
struct ast_str *ast_category_get_templates(const struct ast_category *category);
|
2005-01-22 22:13:11 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Check for category duplicates
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2001-10-31 15:28:08 +00:00
|
|
|
* \param config which config to use
|
|
|
|
* \param category_name name of the category you're looking for
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param filter an optional comma-separated list of \<name_regex\>=\<value_regex\>
|
2014-10-13 16:12:17 +00:00
|
|
|
* pairs. Only categories with matching variables will be returned.
|
|
|
|
* The special name 'TEMPLATES' can be used with the special values
|
|
|
|
* 'include' or 'restrict' to include templates in the result or
|
|
|
|
* restrict the result to only templates.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2005-01-25 06:10:20 +00:00
|
|
|
* This will search through the categories within a given config file for a match.
|
|
|
|
*
|
2007-07-16 02:51:56 +00:00
|
|
|
* \return non-zero if found
|
2005-01-25 06:10:20 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
int ast_category_exist(const struct ast_config *config, const char *category_name,
|
|
|
|
const char *filter);
|
1999-10-27 00:56:38 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2004-10-05 06:46:11 +00:00
|
|
|
* \param family which family/config to lookup
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param fields which fields to lookup
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2009-03-09 20:58:17 +00:00
|
|
|
* This will use builtin configuration backends to look up a particular
|
2010-06-30 17:15:46 +00:00
|
|
|
* entity in realtime and return a variable list of its parameters.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* Unlike the variables in ast_config, the resulting list of variables
|
2006-03-07 01:12:09 +00:00
|
|
|
* MUST be freed with ast_variables_destroy() as there is no container.
|
2008-10-14 00:08:52 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note
|
2009-02-18 19:05:15 +00:00
|
|
|
* The difference between these two calls is that ast_load_realtime excludes
|
|
|
|
* fields whose values are NULL, while ast_load_realtime_all loads all columns.
|
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note
|
|
|
|
* You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
2004-10-05 06:46:11 +00:00
|
|
|
*/
|
2013-04-27 12:01:29 +00:00
|
|
|
struct ast_variable *ast_load_realtime_fields(const char *family, const struct ast_variable *fields);
|
2008-05-02 02:56:39 +00:00
|
|
|
struct ast_variable *ast_load_realtime(const char *family, ...) attribute_sentinel;
|
2013-04-27 12:01:29 +00:00
|
|
|
struct ast_variable *ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields);
|
2008-05-02 02:56:39 +00:00
|
|
|
struct ast_variable *ast_load_realtime_all(const char *family, ...) attribute_sentinel;
|
2004-10-05 06:46:11 +00:00
|
|
|
|
2008-06-05 19:07:27 +00:00
|
|
|
/*!
|
|
|
|
* \brief Release any resources cached for a realtime family
|
2010-06-30 17:15:46 +00:00
|
|
|
* \since 1.6.1
|
|
|
|
*
|
2008-06-05 19:07:27 +00:00
|
|
|
* \param family which family/config to destroy
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2008-06-05 19:07:27 +00:00
|
|
|
* Various backends may cache attributes about a realtime data storage
|
|
|
|
* facility; on reload, a front end resource may request to purge that cache.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \retval 0 If any cache was purged
|
|
|
|
* \retval -1 If no cache was found
|
2008-06-05 19:07:27 +00:00
|
|
|
*/
|
|
|
|
int ast_unload_realtime(const char *family);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Inform realtime what fields that may be stored
|
2010-06-30 17:15:46 +00:00
|
|
|
* \since 1.6.1
|
|
|
|
*
|
2008-06-05 19:07:27 +00:00
|
|
|
* \param family which family/config is referenced
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2008-06-05 19:07:27 +00:00
|
|
|
* This will inform builtin configuration backends that particular fields
|
|
|
|
* may be updated during the use of that configuration section. This is
|
|
|
|
* mainly to be used during startup routines, to ensure that various fields
|
|
|
|
* exist in the backend. The backends may take various actions, such as
|
|
|
|
* creating new fields in the data store or warning the administrator that
|
|
|
|
* new fields may need to be created, in order to ensure proper function.
|
2008-06-13 22:52:20 +00:00
|
|
|
*
|
|
|
|
* The arguments are specified in groups of 3: column name, column type,
|
|
|
|
* and column size. The column types are specified as integer constants,
|
|
|
|
* defined by the enum require_type. Note that the size is specified as
|
|
|
|
* the number of equivalent character fields that a field may take up, even
|
|
|
|
* if a field is otherwise specified as an integer type. This is due to
|
|
|
|
* the fact that some fields have historically been specified as character
|
|
|
|
* types, even if they contained integer values.
|
|
|
|
*
|
|
|
|
* A family should always specify its fields to the minimum necessary
|
|
|
|
* requirements to fulfill all possible values (within reason; for example,
|
|
|
|
* a timeout value may reasonably be specified as an INTEGER2, with size 5.
|
|
|
|
* Even though values above 32767 seconds are possible, they are unlikely
|
|
|
|
* to be useful, and we should not complain about that size).
|
2008-10-14 00:08:52 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \retval 0 Required fields met specified standards
|
|
|
|
* \retval -1 One or more fields was missing or insufficient
|
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
res_odbc: Remove connection management
Asterisk by default will create a single database connection and share
it among all threads that attempt to access the database. In previous
versions of Asterisk, this was tolerable, because the most used channel
driver, chan_sip, mostly accessed the database from a single thread.
With PJSIP, however, many threads may be attempting to perform database
operations, and there is the potential for many more database accesses,
meaning the concurrency is a horrible bottleneck if only one connection
is shared.
Asterisk has a connection pooling facility built into it, but the
implementation has flaws. For one, there is a strict limit on the number
of simultaneous connections that could be made to the database. Anything
beyond the maximum would result in a failed operation. Attempting to
predict what the maximum should be is nearly impossible even for someone
intimately familiar with Asterisk's threading model. In addition, use of
transactions in the dialplan can cause some severe bugs if connection
pooling is enabled.
This commit seeks to fix the concurrency problem by removing all
connection management code from Asterisk and leaving that to the
underlying unixODBC code instead. Now, Asterisk does not share a single
connection, nor does it try to maintain a connection pool. Instead, all
Asterisk ever does is request a connection from unixODBC and allow
unixODBC to either allocate those connections or retrieve them from a
pool.
Doing this has a bit of a ripple effect. For one, since connections are
not long-lived objects, several of the safeguards that previously
existed have been removed. We don't have to worry about trying to use a
connection that has gone stale. In every case, when we request a
connection, it has just been made and we don't need to perform any
sanity checks to be sure it's still active.
Another major player affected by this change is transactions.
Transactions and their respective connections were so tightly coupled
that it was almost pornographic. This code change moves
transaction-related code to its own file separate from the core ODBC
functionality. This way, the core of ODBC does not even have to know
that transactions exist.
In making this large change, I had to look at a lot of code and
understand it. When making this change, I discovered several places
where the behavior is definitely not ideal, but it seemed outside the
scope of this change to be fixing it. Instead, any place where I saw
some sort of room for improvement has had a XXX comment added explaining
what could be altered to improve it.
Change-Id: I37a84def5ea4ddf93868ce8105f39de078297fbf
2015-12-23 21:07:05 +00:00
|
|
|
*
|
|
|
|
* TODO The return value of this function is routinely ignored. Ignoring
|
|
|
|
* the return value means that it's mostly pointless to be calling this.
|
|
|
|
* You'll see some warning messages potentially, but that's it.
|
|
|
|
*
|
|
|
|
* XXX This function is super useful for detecting configuration problems
|
|
|
|
* early, but unfortunately, the latest in configuration management, sorcery,
|
|
|
|
* doesn't work well with this. Users of sorcery are familiar with the fields
|
|
|
|
* they will need to write but don't know if realtime is being used. Sorcery
|
|
|
|
* knows what storage mechanism is being used but has no high-level knowledge
|
|
|
|
* of what sort of data is going to be written.
|
2008-06-05 19:07:27 +00:00
|
|
|
*/
|
2008-06-13 22:52:20 +00:00
|
|
|
int ast_realtime_require_field(const char *family, ...) attribute_sentinel;
|
2008-06-05 19:07:27 +00:00
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve realtime configuration
|
|
|
|
*
|
|
|
|
* \param family which family/config to lookup
|
|
|
|
* \param fields list of fields
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This will use builtin configuration backends to look up a particular
|
|
|
|
* entity in realtime and return a variable list of its parameters. Unlike
|
|
|
|
* the ast_load_realtime, this function can return more than one entry and
|
|
|
|
* is thus stored inside a traditional ast_config structure rather than
|
|
|
|
* just returning a linked list of variables.
|
|
|
|
*
|
|
|
|
* \return An ast_config with one or more results
|
|
|
|
* \retval NULL Error or no results returned
|
|
|
|
*/
|
|
|
|
struct ast_config *ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2004-10-08 18:20:49 +00:00
|
|
|
* \param family which family/config to lookup
|
2009-02-17 20:50:03 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \details
|
2009-03-09 20:58:17 +00:00
|
|
|
* This will use builtin configuration backends to look up a particular
|
2004-10-08 18:20:49 +00:00
|
|
|
* entity in realtime and return a variable list of its parameters. Unlike
|
|
|
|
* the ast_load_realtime, this function can return more than one entry and
|
2009-03-09 20:58:17 +00:00
|
|
|
* is thus stored inside a traditional ast_config structure rather than
|
2004-10-08 18:20:49 +00:00
|
|
|
* just returning a linked list of variables.
|
2008-10-14 00:08:52 +00:00
|
|
|
*
|
2011-10-25 01:29:32 +00:00
|
|
|
* \return An ast_config with one or more results
|
|
|
|
* \retval NULL Error or no results returned
|
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
2004-10-08 18:20:49 +00:00
|
|
|
*/
|
2008-05-02 02:56:39 +00:00
|
|
|
struct ast_config *ast_load_realtime_multientry(const char *family, ...) attribute_sentinel;
|
2004-10-08 18:20:49 +00:00
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Update realtime configuration
|
|
|
|
*
|
|
|
|
* \param family which family/config to be updated
|
|
|
|
* \param keyfield which field to use as the key
|
|
|
|
* \param lookup which value to look for in the key field to match the entry.
|
|
|
|
* \param fields fields to update
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is used to update a parameter in realtime configuration space.
|
|
|
|
*
|
|
|
|
* \return Number of rows affected, or -1 on error.
|
|
|
|
*/
|
|
|
|
int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Update realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2004-10-05 06:46:11 +00:00
|
|
|
* \param family which family/config to be updated
|
|
|
|
* \param keyfield which field to use as the key
|
|
|
|
* \param lookup which value to look for in the key field to match the entry.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2004-10-05 06:46:11 +00:00
|
|
|
* This function is used to update a parameter in realtime configuration space.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return Number of rows affected, or -1 on error.
|
2004-10-05 06:46:11 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
2004-10-05 06:46:11 +00:00
|
|
|
*/
|
2008-05-02 02:56:39 +00:00
|
|
|
int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
|
2002-04-23 19:05:55 +00:00
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Update realtime configuration
|
|
|
|
*
|
|
|
|
* \param family which family/config to be updated
|
|
|
|
* \param lookup_fields fields used to look up entries
|
|
|
|
* \param update_fields fields to update
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is used to update a parameter in realtime configuration space.
|
|
|
|
* It includes the ability to lookup a row based upon multiple key criteria.
|
|
|
|
* As a result, this function includes two sentinel values, one to terminate
|
|
|
|
* lookup values and the other to terminate the listing of fields to update.
|
|
|
|
*
|
|
|
|
* \return Number of rows affected, or -1 on error.
|
|
|
|
*/
|
|
|
|
int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Update realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2008-10-14 00:08:52 +00:00
|
|
|
* \param family which family/config to be updated
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2008-10-14 00:08:52 +00:00
|
|
|
* This function is used to update a parameter in realtime configuration space.
|
|
|
|
* It includes the ability to lookup a row based upon multiple key criteria.
|
|
|
|
* As a result, this function includes two sentinel values, one to terminate
|
|
|
|
* lookup values and the other to terminate the listing of fields to update.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return Number of rows affected, or -1 on error.
|
2008-10-14 00:08:52 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
|
|
|
*/
|
|
|
|
int ast_update2_realtime(const char *family, ...) attribute_sentinel;
|
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create realtime configuration
|
|
|
|
*
|
|
|
|
* \param family which family/config to be created
|
|
|
|
* \param fields fields themselves
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is used to create a parameter in realtime configuration space.
|
|
|
|
*
|
|
|
|
* \return Number of rows affected, or -1 on error.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* On the MySQL engine only, for reasons of backwards compatibility, the return
|
|
|
|
* value is the insert ID. This value is nonportable and may be changed in a
|
|
|
|
* future version to match the other engines.
|
|
|
|
*/
|
|
|
|
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2007-04-11 13:41:17 +00:00
|
|
|
* \param family which family/config to be created
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2007-04-11 13:41:17 +00:00
|
|
|
* This function is used to create a parameter in realtime configuration space.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return Number of rows affected, or -1 on error.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \note
|
2009-02-18 19:05:15 +00:00
|
|
|
* On the MySQL engine only, for reasons of backwards compatibility, the return
|
|
|
|
* value is the insert ID. This value is nonportable and may be changed in a
|
|
|
|
* future version to match the other engines.
|
2007-04-11 13:41:17 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
2007-04-11 13:41:17 +00:00
|
|
|
*/
|
2008-05-02 02:56:39 +00:00
|
|
|
int ast_store_realtime(const char *family, ...) attribute_sentinel;
|
2007-04-11 13:41:17 +00:00
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Destroy realtime configuration
|
|
|
|
*
|
|
|
|
* \param family which family/config to be destroyed
|
|
|
|
* \param keyfield which field to use as the key
|
|
|
|
* \param lookup which value to look for in the key field to match the entry.
|
|
|
|
* \param fields fields themselves
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is used to destroy an entry in realtime configuration space.
|
|
|
|
* Additional params are used as keys.
|
|
|
|
*
|
|
|
|
* \return Number of rows affected, or -1 on error.
|
|
|
|
*/
|
|
|
|
int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Destroy realtime configuration
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2007-04-11 13:41:17 +00:00
|
|
|
* \param family which family/config to be destroyed
|
|
|
|
* \param keyfield which field to use as the key
|
|
|
|
* \param lookup which value to look for in the key field to match the entry.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2007-04-11 13:41:17 +00:00
|
|
|
* This function is used to destroy an entry in realtime configuration space.
|
|
|
|
* Additional params are used as keys.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return Number of rows affected, or -1 on error.
|
2007-04-11 13:41:17 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \note You should use the constant SENTINEL to terminate arguments, in
|
2008-10-14 00:08:52 +00:00
|
|
|
* order to preserve cross-platform compatibility.
|
2007-04-11 13:41:17 +00:00
|
|
|
*/
|
2008-05-02 02:56:39 +00:00
|
|
|
int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
|
2007-04-11 13:41:17 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Check if realtime engine is configured for family
|
2005-10-24 20:12:06 +00:00
|
|
|
* \param family which family/config to be checked
|
2007-07-16 02:51:56 +00:00
|
|
|
* \return 1 if family is configured in realtime and engine exists
|
2010-06-30 17:15:46 +00:00
|
|
|
*/
|
2005-08-23 01:44:28 +00:00
|
|
|
int ast_check_realtime(const char *family);
|
|
|
|
|
2007-02-14 20:22:20 +00:00
|
|
|
/*! \brief Check if there's any realtime engines loaded */
|
|
|
|
int ast_realtime_enabled(void);
|
|
|
|
|
2011-11-01 21:02:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Duplicate variable list
|
|
|
|
* \param var the linked list of variables to clone
|
|
|
|
* \return A duplicated list which you'll need to free with
|
|
|
|
* ast_variables_destroy or NULL when out of memory.
|
|
|
|
*
|
|
|
|
* \note Do not depend on this to copy more than just name, value and filename
|
|
|
|
* (the arguments to ast_variables_new).
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variables_dup(struct ast_variable *var);
|
|
|
|
|
2014-06-06 21:44:16 +00:00
|
|
|
/*!
|
|
|
|
* \brief Reverse a variable list
|
|
|
|
* \param var the linked list of variables to reverse
|
|
|
|
* \return The head of the reversed variable list
|
|
|
|
*
|
|
|
|
* \note The variable list var is not preserved in this function and should
|
|
|
|
* not be used after reversing it.
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variables_reverse(struct ast_variable *var);
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Free variable list
|
2004-10-05 06:46:11 +00:00
|
|
|
* \param var the linked list of variables to free
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2005-01-25 06:10:20 +00:00
|
|
|
* This function frees a list of variables.
|
2004-10-05 06:46:11 +00:00
|
|
|
*/
|
2005-01-25 06:10:20 +00:00
|
|
|
void ast_variables_destroy(struct ast_variable *var);
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Register config engine
|
2009-02-18 19:05:15 +00:00
|
|
|
* \retval 1 Always
|
|
|
|
*/
|
2005-01-26 02:39:22 +00:00
|
|
|
int ast_config_engine_register(struct ast_config_engine *newconfig);
|
2005-10-24 20:12:06 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Deregister config engine
|
2009-02-18 19:05:15 +00:00
|
|
|
* \retval 0 Always
|
|
|
|
*/
|
2005-01-25 06:10:20 +00:00
|
|
|
int ast_config_engine_deregister(struct ast_config_engine *del);
|
2005-10-24 20:12:06 +00:00
|
|
|
|
2012-07-11 18:33:36 +00:00
|
|
|
/*!
|
|
|
|
* \brief Determine if a mapping exists for a given family
|
|
|
|
*
|
|
|
|
* \param family which family you are looking to see if a mapping exists for
|
|
|
|
* \retval 1 if it is mapped
|
|
|
|
* \retval 0 if it is not
|
|
|
|
*/
|
|
|
|
int ast_realtime_is_mapping_defined(const char *family);
|
|
|
|
|
2013-04-27 12:01:29 +00:00
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
/*!
|
|
|
|
* \brief Add an explicit mapping for a family
|
|
|
|
*
|
|
|
|
* \param name Family name
|
|
|
|
* \param driver Driver to use
|
|
|
|
* \param database Database to access
|
|
|
|
* \param table Table to use
|
|
|
|
* \param priority Priority of this mapping
|
|
|
|
*/
|
|
|
|
int ast_realtime_append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority);
|
|
|
|
#endif
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Exposed initialization method for core process
|
|
|
|
*
|
|
|
|
* \details
|
2009-02-18 19:05:15 +00:00
|
|
|
* This method is intended for use only with the core initialization and is
|
|
|
|
* not designed to be called from any user applications.
|
|
|
|
*/
|
2005-01-25 06:10:20 +00:00
|
|
|
int register_config_cli(void);
|
2009-02-18 19:05:15 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*! \brief Create a new base configuration structure */
|
2005-01-25 06:10:20 +00:00
|
|
|
struct ast_config *ast_config_new(void);
|
2009-02-18 19:05:15 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve the current category name being built.
|
|
|
|
*
|
|
|
|
* \details
|
2009-02-18 19:05:15 +00:00
|
|
|
* API for backend configuration engines while building a configuration set.
|
|
|
|
*/
|
2005-01-25 06:10:20 +00:00
|
|
|
struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
|
2009-02-18 19:05:15 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Set the category within the configuration as being current.
|
|
|
|
*
|
|
|
|
* \details
|
2009-02-18 19:05:15 +00:00
|
|
|
* API for backend configuration engines while building a configuration set.
|
|
|
|
*/
|
2005-01-25 06:10:20 +00:00
|
|
|
void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat);
|
2009-02-18 19:05:15 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve a configuration variable within the configuration set.
|
|
|
|
*
|
|
|
|
* \details
|
2009-02-18 19:05:15 +00:00
|
|
|
* Retrieves the named variable \p var within category \p cat of configuration
|
|
|
|
* set \p cfg. If not found, attempts to retrieve the named variable \p var
|
|
|
|
* from within category \em general.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2009-02-18 19:05:15 +00:00
|
|
|
* \return Value of \p var, or NULL if not found.
|
|
|
|
*/
|
2006-09-20 20:40:39 +00:00
|
|
|
const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var);
|
2005-01-25 06:10:20 +00:00
|
|
|
|
2014-10-13 16:12:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create a category
|
|
|
|
*
|
|
|
|
* \param name name of new category
|
|
|
|
* \param in_file filename which contained the new config
|
|
|
|
* \param lineno line number
|
|
|
|
*/
|
2007-08-29 20:55:40 +00:00
|
|
|
struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno);
|
2014-10-13 16:12:17 +00:00
|
|
|
|
2017-02-21 14:56:54 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create a category that is not backed by a file
|
|
|
|
*
|
|
|
|
* \param name name of new category
|
|
|
|
*/
|
|
|
|
#define ast_category_new_dynamic(name) ast_category_new(name, "", -1)
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Create a nameless category that is not backed by a file
|
|
|
|
*/
|
|
|
|
#define ast_category_new_anonymous() ast_category_new_dynamic("")
|
|
|
|
|
2014-10-13 16:12:17 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create a category making it a template
|
|
|
|
*
|
|
|
|
* \param name name of new template
|
|
|
|
* \param in_file filename which contained the new config
|
|
|
|
* \param lineno line number
|
|
|
|
*/
|
|
|
|
struct ast_category *ast_category_new_template(const char *name, const char *in_file, int lineno);
|
2008-02-12 00:24:36 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
2008-02-12 00:24:36 +00:00
|
|
|
* \brief Inserts new category
|
2017-12-22 14:23:22 +00:00
|
|
|
*
|
2008-02-12 00:24:36 +00:00
|
|
|
* \param config which config to use
|
|
|
|
* \param cat newly created category to insert
|
|
|
|
* \param match which category to insert above
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
|
|
|
* \details
|
2008-02-12 00:24:36 +00:00
|
|
|
* This function is used to insert a new category above another category
|
|
|
|
* matching the match parameter.
|
2014-09-18 14:46:12 +00:00
|
|
|
*
|
|
|
|
* \retval 0 if succeeded
|
2014-10-13 16:12:17 +00:00
|
|
|
* \retval -1 if the specified match category wasn't found
|
2008-02-12 00:24:36 +00:00
|
|
|
*/
|
2014-09-18 14:46:12 +00:00
|
|
|
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match);
|
2009-02-18 19:05:15 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
2014-10-13 16:12:17 +00:00
|
|
|
* \brief Delete a category
|
|
|
|
*
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param cfg which config to use
|
|
|
|
* \param cat category to delete
|
2014-10-13 16:12:17 +00:00
|
|
|
*
|
|
|
|
* \return the category after the deleted one which could be NULL.
|
2014-10-14 20:48:06 +00:00
|
|
|
*
|
|
|
|
* \note It is not safe to call ast_category_delete while browsing with
|
|
|
|
* ast_category_browse. It is safe with ast_category_browse_filtered.
|
2014-10-13 16:12:17 +00:00
|
|
|
*/
|
2021-11-19 15:47:25 +00:00
|
|
|
struct ast_category *ast_category_delete(struct ast_config *cfg, struct ast_category *cat);
|
2014-10-13 16:12:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Appends a category to a config
|
|
|
|
*
|
|
|
|
* \param config which config to use
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param category category to insert
|
2014-10-13 16:12:17 +00:00
|
|
|
*/
|
2021-11-19 15:47:25 +00:00
|
|
|
void ast_category_append(struct ast_config *config, struct ast_category *category);
|
2014-10-13 16:12:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Applies base (template) to category.
|
|
|
|
*
|
|
|
|
* \param existing existing category
|
|
|
|
* \param base base category
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* This function is used to apply a base (template) to an existing category
|
2015-03-17 22:15:42 +00:00
|
|
|
*
|
|
|
|
* \retval 0 if succeeded
|
|
|
|
* \retval -1 if the memory allocation failed
|
2014-10-13 16:12:17 +00:00
|
|
|
*/
|
2015-03-17 22:15:42 +00:00
|
|
|
int ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
|
2014-10-13 16:12:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Removes and destroys all variables in a category
|
|
|
|
*
|
|
|
|
* \param category category to empty
|
|
|
|
*
|
|
|
|
* \retval 0 if succeeded
|
2021-10-31 01:04:30 +00:00
|
|
|
* \retval -1 if category is NULL
|
2009-02-18 19:05:15 +00:00
|
|
|
*/
|
2014-10-13 16:12:17 +00:00
|
|
|
int ast_category_empty(struct ast_category *category);
|
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
void ast_category_destroy(struct ast_category *cat);
|
|
|
|
struct ast_variable *ast_category_detach_variables(struct ast_category *cat);
|
|
|
|
void ast_category_rename(struct ast_category *cat, const char *name);
|
|
|
|
|
2008-10-14 22:38:06 +00:00
|
|
|
struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno);
|
2015-02-24 23:00:24 +00:00
|
|
|
#define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
2018-02-20 01:55:50 +00:00
|
|
|
|
2007-08-29 20:55:40 +00:00
|
|
|
struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size);
|
|
|
|
struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);
|
|
|
|
void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file);
|
2005-01-25 06:10:20 +00:00
|
|
|
void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
|
2008-02-12 00:24:36 +00:00
|
|
|
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line);
|
|
|
|
int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line);
|
2014-03-06 22:39:54 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Performs an in-place sort on the variable list by ascending name
|
|
|
|
*
|
|
|
|
* \param head The variable list head
|
|
|
|
*
|
|
|
|
* \return The new list head
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variable_list_sort(struct ast_variable *head);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Appends a variable list to the end of another list
|
|
|
|
*
|
|
|
|
* \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL
|
|
|
|
* but the content may be to initialize a new list. If so, upon return, this parameter will be updated
|
|
|
|
* with a pointer to the new list head.
|
|
|
|
* \param search_hint The place in the current list to start searching for the end of the list.
|
|
|
|
* Might help performance on longer lists. If NULL, it defaults to head.
|
|
|
|
* \param new_var The head of the new variable list to be appended
|
|
|
|
*
|
|
|
|
* \return The tail of the resulting list.
|
|
|
|
*
|
|
|
|
* \note If the existing *head is NULL, it will be updated to new_var. This allows you to call
|
|
|
|
* ast_variable_list_append in a loop or callback without initializing the list first.
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint,
|
|
|
|
struct ast_variable *new_var);
|
|
|
|
#define ast_variable_list_append(head, new_var) ast_variable_list_append_hint(head, NULL, new_var)
|
2008-08-05 18:25:16 +00:00
|
|
|
|
2019-09-11 20:58:29 +00:00
|
|
|
/*!
|
|
|
|
* \brief Replace a variable in the given list with a new value
|
|
|
|
* \since 13.30.0
|
|
|
|
*
|
|
|
|
* \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL
|
|
|
|
* but the content may be to initialize a new list. If so, upon return, this parameter will be updated
|
|
|
|
* with a pointer to the new list head.
|
|
|
|
* \param replacement The variable that replaces another variable in the list with the
|
|
|
|
* same name.
|
|
|
|
*
|
|
|
|
* \retval 0 if a variable was replaced in the list
|
|
|
|
* \retval -1 if no replacement occured
|
|
|
|
*
|
|
|
|
* \note The variable name comparison is performed case-sensitively
|
|
|
|
* \note If a variable is replaced, its memory is freed.
|
|
|
|
*/
|
|
|
|
int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement);
|
|
|
|
|
2022-02-20 20:16:22 +00:00
|
|
|
/*!
|
|
|
|
* \brief Replace a variable in the given list with a new variable
|
|
|
|
*
|
2022-04-19 15:36:12 +00:00
|
|
|
* \param head A pointer to the current variable list head. Since the variable to be
|
|
|
|
* replaced, this pointer may be updated with the new head.
|
|
|
|
* \param oldvar A pointer to the existing variable to be replaced.
|
|
|
|
* \param newvar A pointer to the new variable that will replace the old one.
|
2022-02-20 20:16:22 +00:00
|
|
|
*
|
|
|
|
* \retval 0 if a variable was replaced in the list
|
|
|
|
* \retval -1 if no replacement occured
|
|
|
|
*
|
|
|
|
* \note The search for the old variable is done simply on the pointer.
|
|
|
|
* \note If a variable is replaced, its memory is freed.
|
|
|
|
*/
|
2022-04-19 15:36:12 +00:00
|
|
|
int ast_variable_list_replace_variable(struct ast_variable **head,
|
|
|
|
struct ast_variable *oldvar,
|
|
|
|
struct ast_variable *newvar);
|
2022-02-20 20:16:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Join an ast_variable list with specified separators and quoted values
|
|
|
|
*
|
|
|
|
* \param head A pointer to an ast_variable list head.
|
|
|
|
* \param item_separator The string to use to separate the list items.
|
|
|
|
* If NULL, "," will be used.
|
|
|
|
* \param name_value_separator The string to use to separate each item's name and value.
|
|
|
|
* If NULL, "=" will be used.
|
|
|
|
* \param str A pointer to a pre-allocated ast_str in which to put the results.
|
|
|
|
* If NULL, one will be allocated and returned.
|
|
|
|
* \param quote_char The quote char to use for the values.
|
|
|
|
* May be NULL or empty for no quoting.
|
|
|
|
*
|
|
|
|
* \retval A pointer to the result ast_str. This may NOT be the same as the pointer
|
|
|
|
* passed in if the original ast_str wasn't large enough to hold the result.
|
|
|
|
* Regardless, the pointer MUST be freed after use.
|
|
|
|
* \retval NULL if there was an error.
|
|
|
|
*/
|
|
|
|
struct ast_str *ast_variable_list_join(const struct ast_variable *head, const char *item_separator,
|
|
|
|
const char *name_value_separator, const char *quote_char, struct ast_str **str);
|
|
|
|
|
2022-03-02 14:57:26 +00:00
|
|
|
/*!
|
|
|
|
* \brief Parse a string into an ast_variable list. The reverse of ast_variable_list_join
|
|
|
|
*
|
|
|
|
* \param input The name-value pair string to parse.
|
|
|
|
* \param item_separator The string used to separate the list items.
|
|
|
|
* Only the first character in the string will be used.
|
|
|
|
* If NULL, "," will be used.
|
|
|
|
* \param name_value_separator The string used to separate each item's name and value.
|
|
|
|
* Only the first character in the string will be used.
|
|
|
|
* If NULL, "=" will be used.
|
|
|
|
*
|
|
|
|
* \retval A pointer to a list of ast_variables.
|
|
|
|
* \retval NULL if there was an error or no variables could be parsed.
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variable_list_from_string(const char *input, const char *item_separator,
|
|
|
|
const char *name_value_separator);
|
|
|
|
|
2022-06-27 17:31:04 +00:00
|
|
|
/*!
|
|
|
|
* \brief Parse a string into an ast_variable list. The reverse of ast_variable_list_join
|
|
|
|
*
|
|
|
|
* \param input The name-value pair string to parse.
|
|
|
|
* \param item_separator The string used to separate the list items.
|
|
|
|
* Only the first character in the string will be used.
|
|
|
|
* If NULL, "," will be used.
|
|
|
|
* \param name_value_separator The string used to separate each item's name and value.
|
|
|
|
* Only the first character in the string will be used.
|
|
|
|
* If NULL, "=" will be used.
|
|
|
|
* \param quote_str The string used to quote values.
|
|
|
|
* Only the first character in the string will be used.
|
|
|
|
* If NULL, '"' will be used.
|
|
|
|
*
|
|
|
|
* \retval A pointer to a list of ast_variables.
|
|
|
|
* \retval NULL if there was an error or no variables could be parsed.
|
|
|
|
*/
|
|
|
|
struct ast_variable *ast_variable_list_from_quoted_string(const char *input, const char *item_separator,
|
|
|
|
const char *name_value_separator, const char *quote_str);
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Update variable value within a config
|
|
|
|
*
|
2008-08-05 18:25:16 +00:00
|
|
|
* \param category Category element within the config
|
|
|
|
* \param variable Name of the variable to change
|
|
|
|
* \param value New value of the variable
|
|
|
|
* \param match If set, previous value of the variable (if NULL or zero-length, no matching will be done)
|
|
|
|
* \param object Boolean of whether to make the new variable an object
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2008-08-05 18:25:16 +00:00
|
|
|
* \return 0 on success or -1 on failure.
|
|
|
|
*/
|
2009-03-09 20:58:17 +00:00
|
|
|
int ast_variable_update(struct ast_category *category, const char *variable,
|
2007-08-29 20:55:40 +00:00
|
|
|
const char *value, const char *match, unsigned int object);
|
2005-01-25 06:10:20 +00:00
|
|
|
|
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a
context C(T) that doesn't specify VAR1. If you read C, the effective value
of VAR1 is ON. Now you change T VAR1 to OFF and call
ast_config_text_file_save. The current behavior is that the file gets
re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this
is a bug. It's preserving the effective state of C even though I didn't
specify C/VAR1 in th first place. I believe the behavior should be that if
I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should
continue to follow the inherited state. Now, if I DID explicitly specify
C/VAR1, the it should be preserved even if the template changes.
Even though I think the existing behavior is a bug, it's been that way forever
so I'm not changing it. Instead, I've created ast_config_text_file_save2()
that takes a bitmask of flags, one of which is to preserve the effective context
(the current behavior). The original ast_config_text_file_save calls *2 with
the preserve flag. If you want the new behavior, call *2 directly without a
flag.
I've also updated Manager UpdateConfig with a new parameter
'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior
with UpdateConfig, set 'PreserveEffectiveContext: no'.
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4297/
........
Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07 16:56:59 +00:00
|
|
|
/*!
|
|
|
|
* \brief Save a config text file
|
|
|
|
* \since 13.2.0
|
|
|
|
*
|
|
|
|
* \param filename Filename
|
|
|
|
* \param cfg ast_config
|
|
|
|
* \param generator generator
|
|
|
|
* \param flags List of config_save_flags
|
|
|
|
*
|
2021-11-19 15:47:25 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a
context C(T) that doesn't specify VAR1. If you read C, the effective value
of VAR1 is ON. Now you change T VAR1 to OFF and call
ast_config_text_file_save. The current behavior is that the file gets
re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this
is a bug. It's preserving the effective state of C even though I didn't
specify C/VAR1 in th first place. I believe the behavior should be that if
I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should
continue to follow the inherited state. Now, if I DID explicitly specify
C/VAR1, the it should be preserved even if the template changes.
Even though I think the existing behavior is a bug, it's been that way forever
so I'm not changing it. Instead, I've created ast_config_text_file_save2()
that takes a bitmask of flags, one of which is to preserve the effective context
(the current behavior). The original ast_config_text_file_save calls *2 with
the preserve flag. If you want the new behavior, call *2 directly without a
flag.
I've also updated Manager UpdateConfig with a new parameter
'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior
with UpdateConfig, set 'PreserveEffectiveContext: no'.
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4297/
........
Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07 16:56:59 +00:00
|
|
|
*/
|
|
|
|
int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Save a config text file preserving the pre 13.2 behavior
|
|
|
|
*
|
|
|
|
* \param filename Filename
|
|
|
|
* \param cfg ast_config
|
|
|
|
* \param generator generator
|
|
|
|
*
|
2021-11-19 15:47:25 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a
context C(T) that doesn't specify VAR1. If you read C, the effective value
of VAR1 is ON. Now you change T VAR1 to OFF and call
ast_config_text_file_save. The current behavior is that the file gets
re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this
is a bug. It's preserving the effective state of C even though I didn't
specify C/VAR1 in th first place. I believe the behavior should be that if
I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should
continue to follow the inherited state. Now, if I DID explicitly specify
C/VAR1, the it should be preserved even if the template changes.
Even though I think the existing behavior is a bug, it's been that way forever
so I'm not changing it. Instead, I've created ast_config_text_file_save2()
that takes a bitmask of flags, one of which is to preserve the effective context
(the current behavior). The original ast_config_text_file_save calls *2 with
the preserve flag. If you want the new behavior, call *2 directly without a
flag.
I've also updated Manager UpdateConfig with a new parameter
'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior
with UpdateConfig, set 'PreserveEffectiveContext: no'.
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4297/
........
Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07 16:56:59 +00:00
|
|
|
*/
|
2008-11-04 18:47:20 +00:00
|
|
|
int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
|
2005-01-25 06:10:20 +00:00
|
|
|
|
2008-03-11 22:55:16 +00:00
|
|
|
struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked);
|
2012-06-04 20:26:12 +00:00
|
|
|
/*!
|
|
|
|
* \brief
|
|
|
|
* Copies the contents of one ast_config into another
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* This creates a config on the heap. The caller of this must
|
|
|
|
* be prepared to free the memory returned.
|
|
|
|
*
|
|
|
|
* \param orig the config to copy
|
|
|
|
* \return The new config on success, NULL on failure.
|
|
|
|
*/
|
|
|
|
struct ast_config *ast_config_copy(const struct ast_config *orig);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief
|
|
|
|
* Flags that affect the behaviour of config hooks.
|
|
|
|
*/
|
|
|
|
enum config_hook_flags {
|
|
|
|
butt,
|
|
|
|
};
|
|
|
|
|
2021-11-27 19:11:37 +00:00
|
|
|
/*!
|
2012-06-04 20:26:12 +00:00
|
|
|
* \brief Callback when configuration is updated
|
|
|
|
*
|
|
|
|
* \param cfg A copy of the configuration that is being changed.
|
|
|
|
* This MUST be freed by the callback before returning.
|
|
|
|
*/
|
|
|
|
typedef int (*config_hook_cb)(struct ast_config *cfg);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief
|
|
|
|
* Register a config hook for a particular file and module
|
|
|
|
*
|
|
|
|
* \param name The name of the hook you are registering.
|
|
|
|
* \param filename The file whose config you wish to hook into.
|
|
|
|
* \param module The module that is reloading the config. This
|
|
|
|
* can be useful if multiple modules may possibly
|
|
|
|
* reload the same file, but you are only interested
|
|
|
|
* when a specific module reloads the file
|
|
|
|
* \param flags Flags that affect the way hooks work.
|
|
|
|
* \param hook The callback to be called when config is loaded.
|
|
|
|
* return 0 Success
|
|
|
|
* return -1 Unsuccess, also known as UTTER AND COMPLETE FAILURE
|
|
|
|
*/
|
|
|
|
int ast_config_hook_register(const char *name,
|
|
|
|
const char *filename,
|
|
|
|
const char *module,
|
|
|
|
enum config_hook_flags flags,
|
|
|
|
config_hook_cb hook);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief
|
|
|
|
* Unregister a config hook
|
|
|
|
*
|
|
|
|
* \param name The name of the hook to unregister
|
|
|
|
*/
|
|
|
|
void ast_config_hook_unregister(const char *name);
|
add some macros to simplify parsing the config file,
see description in config.h .
They are a variant of the set of macros i used in chan_oss.c,
structured in a way to be more robust to the presence of
spurious ';' - basically, they define wrappers for 'do {'
and '} while (0)', plus some helper functions to deal with simple
cases such as ast_copy_string, ast_malloc, strtoul, ast_true ...
The prefix (CV_ as 'Config Variable') tries to be easy to remember
and has been chosen to not conflict with other existing macros in the tree.
For the time being, I have only updated the three source files in the
tree that used the old M_* macros. Hopefully, more files will be
converted.
NOTE:
I understand that inventing my own dialect of C is generally wrong;
however, the lack of adequate support in the language encourages
lazy programming practices (such as ignoring errors, bounds, etc.)
and this increases the chance of vulnerability in the code, especially
because we are parsing user input here.
Hopefully, these macros and the use of ast_parse_arg (in config.h)
should encourage the programmer to write more robust code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94191 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-20 12:56:07 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief Support code to parse config file arguments
|
2007-07-17 14:32:15 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \details
|
2007-07-17 14:32:15 +00:00
|
|
|
* The function ast_parse_arg() provides a generic interface to parse
|
|
|
|
* strings (e.g. numbers, network addresses and so on) in a flexible
|
|
|
|
* way, e.g. by doing proper error and bound checks, provide default
|
|
|
|
* values, and so on.
|
|
|
|
* The function (described later) takes a string as an argument,
|
|
|
|
* a set of flags to specify the result format and checks to perform,
|
|
|
|
* a pointer to the result, and optionally some additional arguments.
|
|
|
|
*
|
2021-11-19 15:47:25 +00:00
|
|
|
* \return 0 on success, != 0 otherwise.
|
2007-07-17 14:32:15 +00:00
|
|
|
*/
|
|
|
|
enum ast_parse_flags {
|
|
|
|
/* low 4 bits of flags are used for the operand type */
|
|
|
|
PARSE_TYPE = 0x000f,
|
|
|
|
/* numeric types, with optional default value and bound checks.
|
|
|
|
* Additional arguments are passed by value.
|
|
|
|
*/
|
2007-12-19 15:15:03 +00:00
|
|
|
PARSE_INT32 = 0x0001,
|
|
|
|
PARSE_UINT32 = 0x0002,
|
|
|
|
PARSE_DOUBLE = 0x0003,
|
|
|
|
#if 0 /* not supported yet */
|
|
|
|
PARSE_INT16 = 0x0004,
|
|
|
|
PARSE_UINT16 = 0x0005,
|
|
|
|
#endif
|
2010-07-08 22:08:07 +00:00
|
|
|
|
2017-07-10 19:04:58 +00:00
|
|
|
/* Returns an int processed by ast_app_parse_timelen.
|
|
|
|
* The first argument is an enum ast_timelen value (required).
|
|
|
|
*/
|
|
|
|
PARSE_TIMELEN = 0x0006,
|
|
|
|
|
2010-07-08 22:08:07 +00:00
|
|
|
/* Returns a struct ast_sockaddr, with optional default value
|
|
|
|
* (passed by reference) and port handling (accept, ignore,
|
|
|
|
* require, forbid). The format is 'ipaddress[:port]'. IPv6 address
|
|
|
|
* literals need square brackets around them if a port is specified.
|
|
|
|
*/
|
|
|
|
PARSE_ADDR = 0x000e,
|
|
|
|
|
2007-07-17 14:32:15 +00:00
|
|
|
/* Returns a struct sockaddr_in, with optional default value
|
|
|
|
* (passed by reference) and port handling (accept, ignore,
|
|
|
|
* require, forbid). The format is 'host.name[:port]'
|
|
|
|
*/
|
2007-12-19 15:15:03 +00:00
|
|
|
PARSE_INADDR = 0x000f,
|
2007-07-17 14:32:15 +00:00
|
|
|
|
|
|
|
/* Other data types can be added as needed */
|
|
|
|
|
|
|
|
/* If PARSE_DEFAULT is set, next argument is a default value
|
|
|
|
* which is returned in case of error. The argument is passed
|
|
|
|
* by value in case of numeric types, by reference in other cases.
|
|
|
|
*/
|
|
|
|
PARSE_DEFAULT = 0x0010, /* assign default on error */
|
|
|
|
|
|
|
|
/* Request a range check, applicable to numbers. Two additional
|
|
|
|
* arguments are passed by value, specifying the low-high end of
|
|
|
|
* the range (inclusive). An error is returned if the value
|
|
|
|
* is outside or inside the range, respectively.
|
|
|
|
*/
|
2012-06-01 16:33:25 +00:00
|
|
|
PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
|
|
|
|
PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
|
|
|
|
PARSE_RANGE_DEFAULTS = 0x0080, /* default to range min/max on range error */
|
2007-07-17 14:32:15 +00:00
|
|
|
|
2010-07-08 22:08:07 +00:00
|
|
|
/* Port handling, for ast_sockaddr. accept/ignore/require/forbid
|
2007-07-17 14:32:15 +00:00
|
|
|
* port number after the hostname or address.
|
|
|
|
*/
|
|
|
|
PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
|
|
|
|
PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
|
|
|
|
PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
|
|
|
|
PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
|
|
|
|
};
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief The argument parsing routine.
|
|
|
|
*
|
2007-07-17 14:32:15 +00:00
|
|
|
* \param arg the string to parse. It is not modified.
|
|
|
|
* \param flags combination of ast_parse_flags to specify the
|
2012-08-30 14:23:28 +00:00
|
|
|
* return type and additional checks.
|
2021-11-19 15:47:25 +00:00
|
|
|
* \param p_result pointer to the result. NULL is valid here, and can
|
2012-08-30 14:23:28 +00:00
|
|
|
* be used to perform only the validity checks.
|
2007-07-17 14:32:15 +00:00
|
|
|
* \param ... extra arguments are required according to flags.
|
2010-06-30 17:15:46 +00:00
|
|
|
*
|
2007-07-17 14:32:15 +00:00
|
|
|
* \retval 0 in case of success, != 0 otherwise.
|
|
|
|
* \retval result returns the parsed value in case of success,
|
2012-06-01 16:33:25 +00:00
|
|
|
* the default value in case of error, or it is left unchanged
|
|
|
|
* in case of error and no default specified. Note that in certain
|
|
|
|
* cases (e.g. sockaddr_in, with multi-field return values) some
|
|
|
|
* of the fields in result may be changed even if an error occurs.
|
2007-07-17 14:32:15 +00:00
|
|
|
*
|
2010-06-30 17:15:46 +00:00
|
|
|
* \details
|
2007-07-17 14:32:15 +00:00
|
|
|
* Examples of use:
|
2012-06-01 16:33:25 +00:00
|
|
|
* ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, &a, -1000, 1000);
|
|
|
|
* returns 0, a = 223
|
|
|
|
* ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, &a, 9999, 10, 100);
|
|
|
|
* returns 1, a = 9999
|
|
|
|
* ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100);
|
|
|
|
* returns 1, b unchanged
|
|
|
|
* ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10);
|
|
|
|
* returns 1, a = 10
|
2017-07-10 19:04:58 +00:00
|
|
|
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000);
|
|
|
|
* returns 0, a = 1000
|
|
|
|
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000);
|
|
|
|
* returns 0, a = 223000
|
|
|
|
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000);
|
|
|
|
* returns 0, a = 9999
|
2012-06-01 16:33:25 +00:00
|
|
|
* ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa);
|
|
|
|
* returns 0, sa contains address and port
|
|
|
|
* ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa);
|
|
|
|
* returns 1 because port is missing, sa contains address
|
2007-07-17 14:32:15 +00:00
|
|
|
*/
|
|
|
|
int ast_parse_arg(const char *arg, enum ast_parse_flags flags,
|
2021-11-19 15:47:25 +00:00
|
|
|
void *p_result, ...);
|
2007-07-17 14:32:15 +00:00
|
|
|
|
add some macros to simplify parsing the config file,
see description in config.h .
They are a variant of the set of macros i used in chan_oss.c,
structured in a way to be more robust to the presence of
spurious ';' - basically, they define wrappers for 'do {'
and '} while (0)', plus some helper functions to deal with simple
cases such as ast_copy_string, ast_malloc, strtoul, ast_true ...
The prefix (CV_ as 'Config Variable') tries to be easy to remember
and has been chosen to not conflict with other existing macros in the tree.
For the time being, I have only updated the three source files in the
tree that used the old M_* macros. Hopefully, more files will be
converted.
NOTE:
I understand that inventing my own dialect of C is generally wrong;
however, the lack of adequate support in the language encourages
lazy programming practices (such as ignoring errors, bounds, etc.)
and this increases the chance of vulnerability in the code, especially
because we are parsing user input here.
Hopefully, these macros and the use of ast_parse_arg (in config.h)
should encourage the programmer to write more robust code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94191 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-20 12:56:07 +00:00
|
|
|
/*
|
|
|
|
* Parsing config file options in C is slightly annoying because we cannot use
|
|
|
|
* string in a switch() statement, yet we need a similar behaviour, with many
|
|
|
|
* branches and a break on a matching one.
|
|
|
|
* The following somehow simplifies the job: we create a block using
|
2012-06-01 16:33:25 +00:00
|
|
|
* the CV_START and CV_END macros, and then within the block we can run
|
add some macros to simplify parsing the config file,
see description in config.h .
They are a variant of the set of macros i used in chan_oss.c,
structured in a way to be more robust to the presence of
spurious ';' - basically, they define wrappers for 'do {'
and '} while (0)', plus some helper functions to deal with simple
cases such as ast_copy_string, ast_malloc, strtoul, ast_true ...
The prefix (CV_ as 'Config Variable') tries to be easy to remember
and has been chosen to not conflict with other existing macros in the tree.
For the time being, I have only updated the three source files in the
tree that used the old M_* macros. Hopefully, more files will be
converted.
NOTE:
I understand that inventing my own dialect of C is generally wrong;
however, the lack of adequate support in the language encourages
lazy programming practices (such as ignoring errors, bounds, etc.)
and this increases the chance of vulnerability in the code, especially
because we are parsing user input here.
Hopefully, these macros and the use of ast_parse_arg (in config.h)
should encourage the programmer to write more robust code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94191 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-20 12:56:07 +00:00
|
|
|
* actions such as "if (condition) { body; break; }"
|
|
|
|
* Additional macros are present to run simple functions (e.g. ast_copy_string)
|
|
|
|
* or to pass arguments to ast_parse_arg()
|
|
|
|
*
|
|
|
|
* As an example:
|
|
|
|
|
|
|
|
CV_START(v->name, v->value); // start the block
|
|
|
|
CV_STR("foo", x_foo); // static string
|
|
|
|
CV_DSTR("bar", y_bar); // malloc'ed string
|
|
|
|
CV_F("bar", ...); // call a generic function
|
|
|
|
CV_END; // end the block
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \brief the macro to open a block for variable parsing */
|
|
|
|
#define CV_START(__in_var, __in_val) \
|
|
|
|
do { \
|
|
|
|
const char *__var = __in_var; \
|
|
|
|
const char *__val = __in_val;
|
|
|
|
|
|
|
|
/*! \brief close a variable parsing block */
|
|
|
|
#define CV_END } while (0)
|
|
|
|
|
|
|
|
/*! \brief call a generic function if the name matches. */
|
|
|
|
#define CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; }
|
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*!
|
|
|
|
* \brief helper macros to assign the value to a BOOL, UINT, static string and
|
add some macros to simplify parsing the config file,
see description in config.h .
They are a variant of the set of macros i used in chan_oss.c,
structured in a way to be more robust to the presence of
spurious ';' - basically, they define wrappers for 'do {'
and '} while (0)', plus some helper functions to deal with simple
cases such as ast_copy_string, ast_malloc, strtoul, ast_true ...
The prefix (CV_ as 'Config Variable') tries to be easy to remember
and has been chosen to not conflict with other existing macros in the tree.
For the time being, I have only updated the three source files in the
tree that used the old M_* macros. Hopefully, more files will be
converted.
NOTE:
I understand that inventing my own dialect of C is generally wrong;
however, the lack of adequate support in the language encourages
lazy programming practices (such as ignoring errors, bounds, etc.)
and this increases the chance of vulnerability in the code, especially
because we are parsing user input here.
Hopefully, these macros and the use of ast_parse_arg (in config.h)
should encourage the programmer to write more robust code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94191 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-20 12:56:07 +00:00
|
|
|
* dynamic string
|
|
|
|
*/
|
|
|
|
#define CV_BOOL(__x, __dst) CV_F(__x, (__dst) = ast_true(__val) )
|
|
|
|
#define CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) )
|
|
|
|
#define CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst)))
|
2010-06-30 17:17:05 +00:00
|
|
|
#define CV_DSTR(__x, __dst) CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val))
|
2007-12-31 15:53:11 +00:00
|
|
|
#define CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val))
|
add some macros to simplify parsing the config file,
see description in config.h .
They are a variant of the set of macros i used in chan_oss.c,
structured in a way to be more robust to the presence of
spurious ';' - basically, they define wrappers for 'do {'
and '} while (0)', plus some helper functions to deal with simple
cases such as ast_copy_string, ast_malloc, strtoul, ast_true ...
The prefix (CV_ as 'Config Variable') tries to be easy to remember
and has been chosen to not conflict with other existing macros in the tree.
For the time being, I have only updated the three source files in the
tree that used the old M_* macros. Hopefully, more files will be
converted.
NOTE:
I understand that inventing my own dialect of C is generally wrong;
however, the lack of adequate support in the language encourages
lazy programming practices (such as ignoring errors, bounds, etc.)
and this increases the chance of vulnerability in the code, especially
because we are parsing user input here.
Hopefully, these macros and the use of ast_parse_arg (in config.h)
should encourage the programmer to write more robust code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94191 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-20 12:56:07 +00:00
|
|
|
|
2010-06-30 17:15:46 +00:00
|
|
|
/*! \brief Check if require type is an integer type */
|
2008-06-09 22:51:59 +00:00
|
|
|
AST_INLINE_API(
|
|
|
|
int ast_rq_is_int(require_type type),
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case RQ_INTEGER1:
|
|
|
|
case RQ_UINTEGER1:
|
|
|
|
case RQ_INTEGER2:
|
|
|
|
case RQ_UINTEGER2:
|
|
|
|
case RQ_INTEGER3:
|
|
|
|
case RQ_UINTEGER3:
|
|
|
|
case RQ_INTEGER4:
|
|
|
|
case RQ_UINTEGER4:
|
|
|
|
case RQ_INTEGER8:
|
|
|
|
case RQ_UINTEGER8:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2010-07-17 17:39:28 +00:00
|
|
|
/*!
|
|
|
|
* \brief Remove standard encoding from realtime values, which ensures
|
|
|
|
* that a semicolon embedded within a single value is not treated upon
|
|
|
|
* retrieval as multiple values.
|
|
|
|
* \param chunk Data to be decoded
|
|
|
|
* \return The decoded data, in the original buffer
|
|
|
|
* \since 1.8
|
2012-08-30 14:23:28 +00:00
|
|
|
* \warning This function modifies the original buffer
|
2010-07-17 17:39:28 +00:00
|
|
|
*/
|
|
|
|
char *ast_realtime_decode_chunk(char *chunk);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Encodes a chunk of data for realtime
|
|
|
|
* \param dest Destination buffer
|
|
|
|
* \param maxlen Length passed through to ast_str_* functions
|
|
|
|
* \param chunk Source data to be encoded
|
|
|
|
* \return Buffer within dest
|
|
|
|
* \since 1.8
|
|
|
|
*/
|
|
|
|
char *ast_realtime_encode_chunk(struct ast_str **dest, ssize_t maxlen, const char *chunk);
|
|
|
|
|
sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.
A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0. One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.
This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare. The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.
They do now.
The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator. For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'". If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.
The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container. However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.
So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function. Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex. If the operator is like or regex, the
right string should be a %-pattern or a regex expression. If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.
To use this new function on ast_variables, 2 new functions were added to
config.c. One that compares 2 ast_variables, and one that compares 2
ast_variable lists. The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list. The latter will traverse the right list and return true if all
the variables in it match the left list.
Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines. The realtime backend just passes
the variable list unaltered to the engine. The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.
Only one more change to sorcery was done... A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)
Now on to res_pjsip...
pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors. Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.
res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.
res_pjsip_registrar_expire was completely refactored. It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them. A new
contact_expiration_check_interval was added to global with a default of
30 seconds.
Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.
There are still objects that can't be filtered at the database like
identifies, transports, and registrations. These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.
Back to allow_unqualified_fetch. If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :) Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache. Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts. It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.
Example sorcery.conf:
[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error
ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer
Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-08 21:55:30 +00:00
|
|
|
/*!
|
|
|
|
* \brief Tests 2 variable values to see if they match
|
|
|
|
* \since 13.9.0
|
|
|
|
*
|
|
|
|
* \param left Variable to test
|
|
|
|
* \param right Variable to match against with an optional realtime-style operator in the name
|
|
|
|
*
|
|
|
|
* \retval 1 matches
|
|
|
|
* \retval 0 doesn't match
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
*
|
|
|
|
* The values of the variables are passed to ast_strings_match.
|
|
|
|
* If right->name is suffixed with a space and an operator, that operator
|
|
|
|
* is also passed to ast_strings_match.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
*
|
|
|
|
* left->name = "id" (ignored)
|
|
|
|
* left->value = "abc"
|
|
|
|
* right->name = "id regex" (id is ignored)
|
|
|
|
* right->value = "a[bdef]c"
|
|
|
|
*
|
|
|
|
* will result in ast_strings_match("abc", "regex", "a[bdef]c") which will return 1.
|
|
|
|
*
|
|
|
|
* left->name = "id" (ignored)
|
|
|
|
* left->value = "abc"
|
|
|
|
* right->name = "id" (ignored)
|
|
|
|
* right->value = "abc"
|
|
|
|
*
|
|
|
|
* will result in ast_strings_match("abc", NULL, "abc") which will return 1.
|
|
|
|
*
|
|
|
|
* See the documentation for ast_strings_match for the valid operators.
|
|
|
|
*/
|
|
|
|
int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Tests 2 variable lists to see if they match
|
|
|
|
* \since 13.9.0
|
|
|
|
*
|
|
|
|
* \param left Variable list to test
|
|
|
|
* \param right Variable list with an optional realtime-style operator in the names
|
|
|
|
* \param exact_match If true, all variables in left must match all variables in right
|
|
|
|
* and vice versa. This does exact value matches only. Operators aren't supported.
|
|
|
|
* Except for order, the left and right lists must be equal.
|
|
|
|
*
|
|
|
|
* If false, every variable in the right list must match some variable in the left list
|
|
|
|
* using the operators supplied. Variables in the left list that aren't in the right
|
|
|
|
* list are ignored for matching purposes.
|
|
|
|
*
|
|
|
|
* \retval 1 matches
|
|
|
|
* \retval 0 doesn't match
|
|
|
|
*
|
|
|
|
* \details
|
|
|
|
* Iterates over the variable lists calling ast_variables_match. If any match fails
|
|
|
|
* or a variable in the right list isn't in the left list, 0 is returned.
|
|
|
|
*/
|
|
|
|
int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right,
|
|
|
|
int exact_match);
|
|
|
|
|
1999-10-27 00:56:38 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-30 18:32:10 +00:00
|
|
|
#endif /* _ASTERISK_CONFIG_H */
|