aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--funcs/func_realtime.c2
-rw-r--r--include/asterisk/config.h1
-rw-r--r--main/config.c31
-rw-r--r--res/res_config_odbc.c22
-rw-r--r--res/res_realtime.c2
5 files changed, 45 insertions, 13 deletions
diff --git a/funcs/func_realtime.c b/funcs/func_realtime.c
index fa9d4a7e7..92a72974e 100644
--- a/funcs/func_realtime.c
+++ b/funcs/func_realtime.c
@@ -75,7 +75,7 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha
if (!args.delim2)
args.delim2 = "=";
- head = ast_load_realtime(args.family, args.fieldmatch, args.value, NULL);
+ head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, NULL);
if (!head) {
ast_module_user_remove(u);
diff --git a/include/asterisk/config.h b/include/asterisk/config.h
index ac752ca99..7ee51d32a 100644
--- a/include/asterisk/config.h
+++ b/include/asterisk/config.h
@@ -128,6 +128,7 @@ int ast_category_exist(const struct ast_config *config, const char *category_nam
* MUST be freed with ast_variables_destroy() as there is no container.
*/
struct ast_variable *ast_load_realtime(const char *family, ...);
+struct ast_variable *ast_load_realtime_all(const char *family, ...);
/*! \brief Retrieve realtime configuration
* \param family which family/config to lookup
diff --git a/main/config.c b/main/config.c
index 4a14d21b5..28e9708a7 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1314,7 +1314,7 @@ struct ast_config *ast_config_load_with_comments(const char *filename)
return result;
}
-struct ast_variable *ast_load_realtime(const char *family, ...)
+struct ast_variable *ast_load_realtime_all(const char *family, ...)
{
struct ast_config_engine *eng;
char db[256]="";
@@ -1331,6 +1331,35 @@ struct ast_variable *ast_load_realtime(const char *family, ...)
return res;
}
+struct ast_variable *ast_load_realtime(const char *family, ...)
+{
+ struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL;
+ va_list ap;
+
+ va_start(ap, family);
+ res = ast_load_realtime_all(family, ap);
+ va_end(ap);
+
+ /* Eliminate blank entries */
+ for (cur = res; cur; cur = cur->next) {
+ if (freeme) {
+ free(freeme);
+ freeme = NULL;
+ }
+
+ if (ast_strlen_zero(cur->value)) {
+ if (prev)
+ prev->next = cur->next;
+ else
+ res = cur->next;
+ freeme = cur;
+ } else {
+ prev = cur;
+ }
+ }
+ return res;
+}
+
/*! \brief Check if realtime engine is configured for family */
int ast_check_realtime(const char *family)
{
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index 3ef3edd33..5c725a0e1 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -168,7 +168,12 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
indicator = 0;
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
if (indicator == SQL_NULL_DATA)
- continue;
+ rowdata[0] = '\0';
+ else if (ast_strlen_zero(rowdata)) {
+ /* Because we encode the empty string for a NULL, we will encode
+ * actual empty strings as a string containing a single whitespace. */
+ ast_copy_string(rowdata, " ", sizeof(rowdata));
+ }
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
@@ -180,15 +185,12 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
stringp = rowdata;
while(stringp) {
chunk = strsep(&stringp, ";");
- if (!ast_strlen_zero(ast_strip(chunk))) {
- if (prev) {
- prev->next = ast_variable_new(coltitle, chunk);
- if (prev->next)
- prev = prev->next;
- } else
- prev = var = ast_variable_new(coltitle, chunk);
-
- }
+ if (prev) {
+ prev->next = ast_variable_new(coltitle, chunk);
+ if (prev->next)
+ prev = prev->next;
+ } else
+ prev = var = ast_variable_new(coltitle, chunk);
}
}
diff --git a/res/res_realtime.c b/res/res_realtime.c
index 1a750d9cf..28525f448 100644
--- a/res/res_realtime.c
+++ b/res/res_realtime.c
@@ -57,7 +57,7 @@ static int cli_realtime_load(int fd, int argc, char **argv)
return RESULT_FAILURE;
}
- var = ast_load_realtime(argv[2], argv[3], argv[4], NULL);
+ var = ast_load_realtime_all(argv[2], argv[3], argv[4], NULL);
if(var) {
ast_cli(fd, header_format, "Column Name", "Column Value");