res_config_odbc: Preserve empty strings returned by the database
authorSean Bright <sean.bright@gmail.com>
Wed, 29 Jan 2020 14:57:38 +0000 (09:57 -0500)
committerSean Bright <sean.bright@gmail.com>
Wed, 29 Jan 2020 15:15:10 +0000 (09:15 -0600)
When res_config_odbc (and perhaps other realtime backends) reads a SQL
NULL from the database, it coalesces the value to the empty string
which prevents it from being returned to the realtime core.

However, if it instead reads the empty string from the database, it
needs a way to encode that fact without having the value omitted
entirely. It does this by changing the value to a string with a single
space. The realtime code in main/config.c recognizes this special case
and _turns the string back into the empty string_ before passing it to
realtime API consumers.

For all of this to work, we need to ensure that we actually pass the
single-space-string back to the realtime core, which is currently
failing because we are trimming the value before checking its
content. So instead we now special case the single-space-string case
so that empty values are returned properly.

ASTERISK-28719 #close
Reported by: EDV O-TON

Change-Id: I673ed8c31ad037aa224e80c78c7a1dc4e4a4e3de

res/res_config_odbc.c

index fd0078f..45bb214 100644 (file)
@@ -303,7 +303,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
                } else {
                        while (stringp) {
                                chunk = strsep(&stringp, ";");
                } else {
                        while (stringp) {
                                chunk = strsep(&stringp, ";");
-                               if (!ast_strlen_zero(ast_strip(chunk))) {
+                               if (!strcmp(chunk, " ") || !ast_strlen_zero(ast_strip(chunk))) {
                                        if (strchr(chunk, '^')) {
                                                decode_chunk(chunk);
                                        }
                                        if (strchr(chunk, '^')) {
                                                decode_chunk(chunk);
                                        }