[asterisk-commits] file: branch file/res_sorcery_realtime r384087 - in /team/file/res_sorcery_re...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 27 12:48:52 CDT 2013


Author: file
Date: Wed Mar 27 12:48:49 2013
New Revision: 384087

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384087
Log:
Expose the ability to pass in ast_variable lists.

Modified:
    team/file/res_sorcery_realtime/include/asterisk/config.h
    team/file/res_sorcery_realtime/main/config.c

Modified: team/file/res_sorcery_realtime/include/asterisk/config.h
URL: http://svnview.digium.com/svn/asterisk/team/file/res_sorcery_realtime/include/asterisk/config.h?view=diff&rev=384087&r1=384086&r2=384087
==============================================================================
--- team/file/res_sorcery_realtime/include/asterisk/config.h (original)
+++ team/file/res_sorcery_realtime/include/asterisk/config.h Wed Mar 27 12:48:49 2013
@@ -363,6 +363,7 @@
  * \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
@@ -373,6 +374,23 @@
  *
  * \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);
+
+/*!
+ * \brief Retrieve realtime configuration
+ *
+ * \param family which family/config to lookup
+ *
+ * \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
  *
  * \note You should use the constant SENTINEL to terminate arguments, in
  * order to preserve cross-platform compatibility.
@@ -385,6 +403,21 @@
  * \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);
+
+/*!
+ * \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.
  *
  * \details
  * This function is used to update a parameter in realtime configuration space.
@@ -400,6 +433,8 @@
  * \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.
@@ -408,6 +443,21 @@
  * 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);
+
+/*!
+ * \brief Update realtime configuration
+ *
+ * \param family which family/config to be updated
+ *
+ * \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.
  *
  * \note You should use the constant SENTINEL to terminate arguments, in
  * order to preserve cross-platform compatibility.
@@ -418,6 +468,7 @@
  * \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.
@@ -428,11 +479,44 @@
  * 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);
+
+/*!
+ * \brief Create realtime configuration
+ *
+ * \param family which family/config to be created
+ *
+ * \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.
  *
  * \note You should use the constant SENTINEL to terminate arguments, in
  * order to preserve cross-platform compatibility.
  */
 int ast_store_realtime(const char *family, ...) attribute_sentinel;
+
+/*!
+ * \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);
 
 /*!
  * \brief Destroy realtime configuration

Modified: team/file/res_sorcery_realtime/main/config.c
URL: http://svnview.digium.com/svn/asterisk/team/file/res_sorcery_realtime/main/config.c?view=diff&rev=384087&r1=384086&r2=384087
==============================================================================
--- team/file/res_sorcery_realtime/main/config.c (original)
+++ team/file/res_sorcery_realtime/main/config.c Wed Mar 27 12:48:49 2013
@@ -2683,19 +2683,13 @@
 	return res;
 }
 
-struct ast_config *ast_load_realtime_multientry(const char *family, ...)
-{
-	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+struct ast_config *ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
+{
 	struct ast_config_engine *eng;
 	char db[256];
 	char table[256];
 	struct ast_config *res = NULL;
-	va_list ap;
 	int i;
-
-	va_start(ap, family);
-	fields = realtime_arguments_to_fields(ap);
-	va_end(ap);
 
 	for (i = 1; ; i++) {
 		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
@@ -2715,18 +2709,24 @@
 	return res;
 }
 
-int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
+struct ast_config *ast_load_realtime_multientry(const char *family, ...)
 {
 	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+	va_list ap;
+
+	va_start(ap, family);
+	fields = realtime_arguments_to_fields(ap);
+	va_end(ap);
+
+	return ast_load_realtime_multientry_fields(family, fields);
+}
+
+int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
+{
 	struct ast_config_engine *eng;
 	int res = -1, i;
 	char db[256];
 	char table[256];
-	va_list ap;
-
-	va_start(ap, lookup);
-	fields = realtime_arguments_to_fields(ap);
-	va_end(ap);
 
 	for (i = 1; ; i++) {
 		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
@@ -2742,14 +2742,42 @@
 	return res;
 }
 
-int ast_update2_realtime(const char *family, ...)
-{
-	RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
-	RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
+int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
+{
+	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+	va_list ap;
+
+	va_start(ap, lookup);
+	fields = realtime_arguments_to_fields(ap);
+	va_end(ap);
+
+	return ast_update_realtime_fields(family, keyfield, lookup, fields);
+}
+
+int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
+{
 	struct ast_config_engine *eng;
 	int res = -1, i;
 	char db[256];
 	char table[256];
+
+	for (i = 1; ; i++) {
+		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
+			if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
+				break;
+			}
+		} else {
+			break;
+		}
+	}
+
+	return res;
+}
+
+int ast_update2_realtime(const char *family, ...)
+{
+	RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
+	RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
 	va_list ap;
 
 	va_start(ap, family);
@@ -2757,31 +2785,15 @@
 	update_fields = realtime_arguments_to_fields(ap);
 	va_end(ap);
 
-	for (i = 1; ; i++) {
-		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
-			if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
-				break;
-			}
-		} else {
-			break;
-		}
-	}
-
-	return res;
-}
-
-int ast_store_realtime(const char *family, ...)
-{
-	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+	return ast_update2_realtime_fields(family, lookup_fields, update_fields);
+}
+
+int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
+{
 	struct ast_config_engine *eng;
 	int res = -1, i;
 	char db[256];
 	char table[256];
-	va_list ap;
-
-	va_start(ap, family);
-	fields = realtime_arguments_to_fields(ap);
-	va_end(ap);
 
 	for (i = 1; ; i++) {
 		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
@@ -2797,18 +2809,24 @@
 	return res;
 }
 
-int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...)
+int ast_store_realtime(const char *family, ...)
 {
 	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+	va_list ap;
+
+	va_start(ap, family);
+	fields = realtime_arguments_to_fields(ap);
+	va_end(ap);
+
+	return ast_store_realtime_fields(family, fields);
+}
+
+int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
+{
 	struct ast_config_engine *eng;
 	int res = -1, i;
 	char db[256];
 	char table[256];
-	va_list ap;
-
-	va_start(ap, lookup);
-	fields = realtime_arguments_to_fields(ap);
-	va_end(ap);
 
 	for (i = 1; ; i++) {
 		if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
@@ -2821,6 +2839,18 @@
 	}
 
 	return res;
+}
+
+int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...)
+{
+	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
+	va_list ap;
+
+	va_start(ap, lookup);
+	fields = realtime_arguments_to_fields(ap);
+	va_end(ap);
+
+	return ast_destroy_realtime_fields(family, keyfield, lookup, fields);
 }
 
 char *ast_realtime_decode_chunk(char *chunk)




More information about the asterisk-commits mailing list