[Asterisk-code-review] cdr mysql: my connect db(): reduce indentation (asterisk[master])
George Joseph
asteriskteam at digium.com
Wed Jun 6 08:12:48 CDT 2018
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/8920 )
Change subject: cdr_mysql: my_connect_db(): reduce indentation
......................................................................
cdr_mysql: my_connect_db(): reduce indentation
ASTERISK-27572
Change-Id: I00bd5363ac94c764c56d8626a5945ed7f3934fcb
---
M addons/cdr_mysql.c
1 file changed, 85 insertions(+), 82 deletions(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
Matthew Fredrickson: Looks good to me, approved
George Joseph: Approved for Submit
diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index b194b7e..61d5d5c 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -492,90 +492,93 @@
ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", ast_str_buffer(dbname), ast_str_buffer(hostname));
connected = 0;
records = 0;
- } else {
- ast_debug(1, "Successfully connected to MySQL database.\n");
- connected = 1;
- records = 0;
- connect_time = time(NULL);
- /* Get table description */
- snprintf(sqldesc, sizeof(sqldesc), "DESC %s", dbtable ? ast_str_buffer(dbtable) : "cdr");
- if (mysql_query(&mysql, sqldesc)) {
- ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");
- mysql_close(&mysql);
- connected = 0;
-
- return AST_MODULE_LOAD_DECLINE;
- }
-
- if (!(result = mysql_store_result(&mysql))) {
- ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");
- mysql_close(&mysql);
- connected = 0;
-
- return AST_MODULE_LOAD_DECLINE;
- }
-
- while ((row = mysql_fetch_row(result))) {
- struct column *entry;
- char *cdrvar = "", *staticvalue = "";
-
- ast_debug(1, "Got a field '%s' of type '%s'\n", row[0], row[1]);
- /* Check for an alias or a static value */
- for (var = ast_variable_browse(cfg, "columns"); var; var = var->next) {
- if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, row[0]) == 0 ) {
- char *alias = ast_strdupa(var->name + 5);
- cdrvar = ast_strip(alias);
- ast_verb(3, "Found alias %s for column %s\n", cdrvar, row[0]);
- break;
- } else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, row[0]) == 0) {
- char *item = ast_strdupa(var->name + 6);
- item = ast_strip(item);
- if (item[0] == '"' && item[strlen(item) - 1] == '"') {
- /* Remove surrounding quotes */
- item[strlen(item) - 1] = '\0';
- item++;
- }
- staticvalue = item;
- }
- }
-
- entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(row[0]) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1 + strlen(row[1]) + 1);
- if (!entry) {
- ast_log(LOG_ERROR, "Out of memory creating entry for column '%s'\n", row[0]);
- mysql_free_result(result);
- return AST_MODULE_LOAD_DECLINE;
- }
-
- entry->name = (char *)entry + sizeof(*entry);
- strcpy(entry->name, row[0]);
-
- if (!ast_strlen_zero(cdrvar)) {
- entry->cdrname = entry->name + strlen(row[0]) + 1;
- strcpy(entry->cdrname, cdrvar);
- } else { /* Point to same place as the column name */
- entry->cdrname = (char *)entry + sizeof(*entry);
- }
-
- if (!ast_strlen_zero(staticvalue)) {
- entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;
- strcpy(entry->staticvalue, staticvalue);
- ast_debug(1, "staticvalue length: %d\n", (int) strlen(staticvalue) );
- entry->type = entry->staticvalue + strlen(entry->staticvalue) + 1;
- } else {
- entry->type = entry->cdrname + strlen(entry->cdrname) + 1;
- }
- strcpy(entry->type, row[1]);
-
- ast_debug(1, "Entry name '%s'\n", entry->name);
- ast_debug(1, " cdrname '%s'\n", entry->cdrname);
- ast_debug(1, " static '%s'\n", entry->staticvalue);
- ast_debug(1, " type '%s'\n", entry->type);
-
- AST_LIST_INSERT_TAIL(&columns, entry, list);
- }
- mysql_free_result(result);
+ return AST_MODULE_LOAD_SUCCESS; /* May be reconnected later */
}
+
+ ast_debug(1, "Successfully connected to MySQL database.\n");
+ connected = 1;
+ records = 0;
+ connect_time = time(NULL);
+
+ /* Get table description */
+ snprintf(sqldesc, sizeof(sqldesc), "DESC %s", dbtable ? ast_str_buffer(dbtable) : "cdr");
+ if (mysql_query(&mysql, sqldesc)) {
+ ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");
+ mysql_close(&mysql);
+ connected = 0;
+
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ if (!(result = mysql_store_result(&mysql))) {
+ ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");
+ mysql_close(&mysql);
+ connected = 0;
+
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ while ((row = mysql_fetch_row(result))) {
+ struct column *entry;
+ char *cdrvar = "", *staticvalue = "";
+
+ ast_debug(1, "Got a field '%s' of type '%s'\n", row[0], row[1]);
+ /* Check for an alias or a static value */
+ for (var = ast_variable_browse(cfg, "columns"); var; var = var->next) {
+ if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, row[0]) == 0 ) {
+ char *alias = ast_strdupa(var->name + 5);
+ cdrvar = ast_strip(alias);
+ ast_verb(3, "Found alias %s for column %s\n", cdrvar, row[0]);
+ break;
+ } else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, row[0]) == 0) {
+ char *item = ast_strdupa(var->name + 6);
+ item = ast_strip(item);
+ if (item[0] == '"' && item[strlen(item) - 1] == '"') {
+ /* Remove surrounding quotes */
+ item[strlen(item) - 1] = '\0';
+ item++;
+ }
+ staticvalue = item;
+ }
+ }
+
+ entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(row[0]) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1 + strlen(row[1]) + 1);
+ if (!entry) {
+ ast_log(LOG_ERROR, "Out of memory creating entry for column '%s'\n", row[0]);
+ mysql_free_result(result);
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ entry->name = (char *)entry + sizeof(*entry);
+ strcpy(entry->name, row[0]);
+
+ if (!ast_strlen_zero(cdrvar)) {
+ entry->cdrname = entry->name + strlen(row[0]) + 1;
+ strcpy(entry->cdrname, cdrvar);
+ } else { /* Point to same place as the column name */
+ entry->cdrname = (char *)entry + sizeof(*entry);
+ }
+
+ if (!ast_strlen_zero(staticvalue)) {
+ entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;
+ strcpy(entry->staticvalue, staticvalue);
+ ast_debug(1, "staticvalue length: %d\n", (int) strlen(staticvalue) );
+ entry->type = entry->staticvalue + strlen(entry->staticvalue) + 1;
+ } else {
+ entry->type = entry->cdrname + strlen(entry->cdrname) + 1;
+ }
+ strcpy(entry->type, row[1]);
+
+ ast_debug(1, "Entry name '%s'\n", entry->name);
+ ast_debug(1, " cdrname '%s'\n", entry->cdrname);
+ ast_debug(1, " static '%s'\n", entry->staticvalue);
+ ast_debug(1, " type '%s'\n", entry->type);
+
+ AST_LIST_INSERT_TAIL(&columns, entry, list);
+ }
+ mysql_free_result(result);
+
return AST_MODULE_LOAD_SUCCESS;
}
--
To view, visit https://gerrit.asterisk.org/8920
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I00bd5363ac94c764c56d8626a5945ed7f3934fcb
Gerrit-Change-Number: 8920
Gerrit-PatchSet: 2
Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
Gerrit-Reviewer: Oron Peled <oron.peled at xorcom.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180606/ec868564/attachment.html>
More information about the asterisk-code-review
mailing list