[Asterisk-code-review] Geolocation: Base Asterisk Prereqs (asterisk[development/16/geolocation])

George Joseph asteriskteam at digium.com
Tue Jun 28 07:14:32 CDT 2022


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18692 )


Change subject: Geolocation: Base Asterisk Prereqs
......................................................................

Geolocation: Base Asterisk Prereqs

* Added ast_variable_list_from_quoted_string()
  Parse a quoted string into an ast_variable list.

* Added ast_str_substitute_variables_full2()
  Perform variable/function/expression substitution on an ast_str.

* Added ast_strsep_quoted()
  Like ast_strsep except you can specify a specific quote character.

* Added ast_xml_find_child_element()
  Find a direct child element by name.

* Added ast_xml_doc_dump_memory()
  Dump the specified document to a buffer

* ast_datastore_free() now checks for a NULL datastore
  before attempting to destroy it.

Change-Id: I5dcefed2f5f93a109e8b489e18d80d42e45244ec
---
M include/asterisk/config.h
M include/asterisk/strings.h
M main/config.c
M main/utils.c
M tests/test_config.c
5 files changed, 51 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/92/18692/1

diff --git a/include/asterisk/config.h b/include/asterisk/config.h
index 2d41f81..2f67fe9 100644
--- a/include/asterisk/config.h
+++ b/include/asterisk/config.h
@@ -1027,6 +1027,26 @@
 	const char *name_value_separator, const char *quote_str);
 
 /*!
+ * \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);
+
+/*!
  * \brief Update variable value within a config
  *
  * \param category Category element within the config
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 3169f91..8b3a378 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -311,6 +311,24 @@
 char *ast_strsep_strict(char **s, const char sep, const char quote, uint32_t flags);
 
 /*!
+ * \brief Like ast_strsep() except you can specify a specific quote character
+ *
+  \param s Pointer to address of the string to be processed.
+  Will be modified and can't be constant.
+  \param sep A single character delimiter.
+  \param quote The quote character
+  \param flags Controls post-processing of the result.
+  AST_STRSEP_TRIM trims all leading and trailing whitespace from the result.
+  AST_STRSEP_STRIP does a trim then strips the outermost quotes.  You may want
+  to trim again after the strip.  Just OR both the TRIM and STRIP flags.
+  AST_STRSEP_UNESCAPE unescapes '\' sequences.
+  AST_STRSEP_ALL does all of the above processing.
+  \return The next token or NULL if done or if there are more than 8 levels of
+  nested quotes.
+ */
+char *ast_strsep_quoted(char **s, const char sep, const char quote, uint32_t flags);
+
+/*!
   \brief Strip backslash for "escaped" semicolons,
 	the string to be stripped (will be modified).
   \return The stripped string.
diff --git a/main/config.c b/main/config.c
index dcf1b9a..0e27d76 100644
--- a/main/config.c
+++ b/main/config.c
@@ -722,7 +722,7 @@
 	return local_str;
 }
 
-struct ast_variable *ast_variable_list_from_string(const char *input, const char *item_separator,
+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)
 {
 	char item_sep;
@@ -744,14 +744,14 @@
 	quote = ast_strlen_zero(quote_str) ? '"' : quote_str[0];
 	item_string = ast_strip(ast_strdupa(input));
 
-	while ((item = ast_strsep_strict(&item_string, item_sep, quote, AST_STRSEP_ALL))) {
-		item_name = ast_strsep_strict(&item, nv_sep, quote, AST_STRSEP_ALL);
+	while ((item = ast_strsep_quoted(&item_string, item_sep, quote, AST_STRSEP_ALL))) {
+		item_name = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
 		if (!item_name) {
 			ast_variables_destroy(new_list);
 			return NULL;
 		}
 
-		item_value = ast_strsep_strict(&item, nv_sep, quote, AST_STRSEP_ALL);
+		item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
 		if (!item_value) {
 			ast_variables_destroy(new_list);
 			return NULL;
@@ -767,6 +767,12 @@
 	return new_list;
 }
 
+struct ast_variable *ast_variable_list_from_string(const char *input, const char *item_separator,
+	const char *name_value_separator)
+{
+	return ast_variable_list_from_quoted_string(input, item_separator, name_value_separator, NULL);
+}
+
 const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
 {
 	const char *tmp;
diff --git a/main/utils.c b/main/utils.c
index 38c5b0c..7d1d6bd 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1859,7 +1859,7 @@
 	return st;
 }
 
-char *ast_strsep_strict(char **iss, const char sep, const char quote, uint32_t flags)
+char *ast_strsep_quoted(char **iss, const char sep, const char quote, uint32_t flags)
 {
 	char *st = *iss;
 	char *is;
diff --git a/tests/test_config.c b/tests/test_config.c
index 08c1bb1..166879a 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -1952,7 +1952,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "variable_list_from_string";
+		info->name = "variable_list_from_quoted_string";
 		info->category = "/main/config/";
 		info->summary = "Test parsing a string into a variable list";
 		info->description =	info->summary;
@@ -1962,7 +1962,7 @@
 	}
 
 	parse_string = "abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
-	list = ast_variable_list_from_string(parse_string, ",", "=", "'");
+	list = ast_variable_list_from_quoted_string(parse_string, ",", "=", "'");
 	ast_test_validate(test, list != NULL);
 	str = ast_variable_list_join(list, "|", "^", "@", NULL);
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18692
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: development/16/geolocation
Gerrit-Change-Id: I5dcefed2f5f93a109e8b489e18d80d42e45244ec
Gerrit-Change-Number: 18692
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220628/bf99eefd/attachment.html>


More information about the asterisk-code-review mailing list