[svn-commits] twilson: branch twilson/config_work r367837 - in /team/twilson/config_work: i...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue May 29 10:49:06 CDT 2012


Author: twilson
Date: Tue May 29 10:49:01 2012
New Revision: 367837

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367837
Log:
Add the ability to match an option value via callback

For example, SIP entries users.conf can contain the hassip and
registersip options which need to be tested against ast_true() to be
able to determine whether the context should create a sip_peer or
sip_registry.

Modified:
    team/twilson/config_work/include/asterisk/config_options.h
    team/twilson/config_work/main/config_options.c

Modified: team/twilson/config_work/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/config_options.h?view=diff&rev=367837&r1=367836&r2=367837
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Tue May 29 10:49:01 2012
@@ -95,6 +95,13 @@
  * \retval non-zero failure, stop processing
  */
 typedef int (*aco_type_prelink)(void *newitem);
+
+/*! \brief A function for determining whether the value for the matchfield in an aco_type is sufficient for a match
+ * \param text The value of the option
+ * \retval -1 The value is sufficient for a match
+ * \retval 0 The value is not sufficient for a match
+ */
+typedef int (*aco_matchvalue_func)(const char *text);
 
 /*! \struct aco_type
  * \brief Type information about a category-level configurable object
@@ -105,6 +112,7 @@
 	const char *category;   /*!< A regular expression for matching categories to be allowed or denied */
 	const char *matchfield; /*!< An option name to match for this type (i.e. a 'type'-like column) */
 	const char *matchvalue; /*!< The value of the option to require for matching (i.e. 'peer' for type= in sip.conf) */
+	aco_matchvalue_func matchfunc;       /*!< A function for determing whether the option value matches (i.e. hassip= requires ast_true()) */
 	enum aco_category_op category_match; /*!< Whether the following category regex is a whitelist or blacklist */
 	size_t item_offset;                  /*!< The offset in the config snapshot for the global config or item config container */
 

Modified: team/twilson/config_work/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/config_options.c?view=diff&rev=367837&r1=367836&r2=367837
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Tue May 29 10:49:01 2012
@@ -249,12 +249,16 @@
 		}
 
 		/* Then, see if we need to match a particular field */
-		if (!ast_strlen_zero(match->matchfield) && !ast_strlen_zero(match->matchvalue)) {
+		if (!ast_strlen_zero(match->matchfield) && (!ast_strlen_zero(match->matchvalue) || match->matchfunc)) {
 			if (!(val = ast_variable_retrieve(cfg, category, match->matchfield))) {
 				ast_log(LOG_ERROR, "Required match field '%s' not found\n", match->matchfield);
 				return NULL;
 			}
-			if (strcasecmp(val, match->matchvalue)) {
+			if (match->matchfunc) {
+				if (!match->matchfunc(val)) {
+					continue;
+				}
+			} else if (strcasecmp(val, match->matchvalue)) {
 				continue;
 			}
 		}




More information about the svn-commits mailing list