From 6e6c96d713be2b745c4e033b6e5710dea72088df Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Tue, 21 Feb 2017 09:56:54 -0500 Subject: realtime: Centralize some common realtime backend code All of the realtime backends create artificial ast_categorys to pass back into the core as query results. These categories have no filename or line number information associated with them and the backends differ slightly on how they create them. So create a couple helper macros to help make things more consistent. Also updated the call sites to remove redundant error messages about memory allocation failure. Note that res_config_ldap sets the category filename to the 'table name' but that is not read by anything in the core, so I've dropped it. Change-Id: I3a1fd91e0c807dea1ce3b643b0a6fe5be9002897 --- res/res_config_curl.c | 7 +++++-- res/res_config_ldap.c | 6 ++---- res/res_config_odbc.c | 6 ++---- res/res_config_pgsql.c | 9 ++++++--- res/res_config_sqlite.c | 8 +++----- res/res_config_sqlite3.c | 7 ++++--- 6 files changed, 22 insertions(+), 21 deletions(-) (limited to 'res') diff --git a/res/res_config_curl.c b/res/res_config_curl.c index 9ad7a6e3d..06a6aef89 100644 --- a/res/res_config_curl.c +++ b/res/res_config_curl.c @@ -182,7 +182,8 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse continue; } - if (!(cat = ast_category_new("", "", 99999))) { + cat = ast_category_new_anonymous(); + if (!cat) { continue; } @@ -569,8 +570,10 @@ static struct ast_config *config_curl(const char *url, const char *unused, const } if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) { - if (!(cat = ast_category_new(category, "", 99999))) + cat = ast_category_new_dynamic(category); + if (!cat) { break; + } cur_cat = category; last_cat_metric = cat_metric; ast_category_append(cfg, cat); diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c index 5e95853d4..7bbac0ce0 100644 --- a/res/res_config_ldap.c +++ b/res/res_config_ldap.c @@ -1043,10 +1043,8 @@ static struct ast_config *realtime_multi_ldap(const char *basedn, struct ast_variable **p = vars; while (*p) { - struct ast_category *cat = NULL; - cat = ast_category_new("", table_name, -1); + struct ast_category *cat = ast_category_new_anonymous(); if (!cat) { - ast_log(LOG_ERROR, "Unable to create a new category!\n"); break; } else { struct ast_variable *var = *p; @@ -1195,7 +1193,7 @@ static struct ast_config *config_ldap(const char *basedn, const char *table_name if (!last_category || strcmp(last_category, categories[i].name) || last_category_metric != categories[i].metric) { - cur_cat = ast_category_new(categories[i].name, table_name, -1); + cur_cat = ast_category_new_dynamic(categories[i].name); if (!cur_cat) { break; } diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c index 5a25b6b5a..114708325 100644 --- a/res/res_config_odbc.c +++ b/res/res_config_odbc.c @@ -407,9 +407,8 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char * ast_log(LOG_WARNING, "SQL Fetch error! [%s]\n", ast_str_buffer(sql)); continue; } - cat = ast_category_new("","",99999); + cat = ast_category_new_anonymous(); if (!cat) { - ast_log(LOG_WARNING, "Out of memory!\n"); continue; } for (x=0;xcat_name || strcmp(args->cat_name, argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY])) { - args->cat = ast_category_new(argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY], "", 99999); - + args->cat = ast_category_new_dynamic(argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY]); if (!args->cat) { - ast_log(LOG_WARNING, "Unable to allocate category\n"); return 1; } @@ -1086,8 +1084,8 @@ static int add_rt_multi_cfg_entry(void *arg, int argc, char **argv, char **colum return 1; } - if (!(cat = ast_category_new(cat_name, "", 99999))) { - ast_log(LOG_WARNING, "Unable to allocate category\n"); + cat = ast_category_new_dynamic(cat_name); + if (!cat) { return 1; } diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c index 8c514b07c..087843a68 100644 --- a/res/res_config_sqlite3.c +++ b/res/res_config_sqlite3.c @@ -503,7 +503,8 @@ static int append_row_to_cfg(void *arg, int num_columns, char **values, char **c struct ast_category *cat; int i; - if (!(cat = ast_category_new("", "", 99999))) { + cat = ast_category_new_anonymous(); + if (!cat) { return SQLITE_ABORT; } @@ -723,8 +724,8 @@ static int static_realtime_cb(void *arg, int num_columns, char **values, char ** } if (!args->cat_name || strcmp(args->cat_name, values[COL_CATEGORY])) { - if (!(args->cat = ast_category_new(values[COL_CATEGORY], "", 99999))) { - ast_log(LOG_WARNING, "Unable to allocate category\n"); + args->cat = ast_category_new_dynamic(values[COL_CATEGORY]); + if (!args->cat) { return SQLITE_ABORT; } -- cgit v1.2.3