<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8920">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cdr_mysql: my_connect_db(): reduce indentation<br><br>ASTERISK-27572<br><br>Change-Id: I00bd5363ac94c764c56d8626a5945ed7f3934fcb<br>---<br>M addons/cdr_mysql.c<br>1 file changed, 85 insertions(+), 82 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c<br>index b194b7e..61d5d5c 100644<br>--- a/addons/cdr_mysql.c<br>+++ b/addons/cdr_mysql.c<br>@@ -492,90 +492,93 @@<br> ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", ast_str_buffer(dbname), ast_str_buffer(hostname));<br> connected = 0;<br> records = 0;<br>- } else {<br>- ast_debug(1, "Successfully connected to MySQL database.\n");<br>- connected = 1;<br>- records = 0;<br>- connect_time = time(NULL);<br> <br>- /* Get table description */<br>- snprintf(sqldesc, sizeof(sqldesc), "DESC %s", dbtable ? ast_str_buffer(dbtable) : "cdr");<br>- if (mysql_query(&mysql, sqldesc)) {<br>- ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");<br>- mysql_close(&mysql);<br>- connected = 0;<br>-<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>-<br>- if (!(result = mysql_store_result(&mysql))) {<br>- ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");<br>- mysql_close(&mysql);<br>- connected = 0;<br>-<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>-<br>- while ((row = mysql_fetch_row(result))) {<br>- struct column *entry;<br>- char *cdrvar = "", *staticvalue = "";<br>-<br>- ast_debug(1, "Got a field '%s' of type '%s'\n", row[0], row[1]);<br>- /* Check for an alias or a static value */<br>- for (var = ast_variable_browse(cfg, "columns"); var; var = var->next) {<br>- if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, row[0]) == 0 ) {<br>- char *alias = ast_strdupa(var->name + 5);<br>- cdrvar = ast_strip(alias);<br>- ast_verb(3, "Found alias %s for column %s\n", cdrvar, row[0]);<br>- break;<br>- } else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, row[0]) == 0) {<br>- char *item = ast_strdupa(var->name + 6);<br>- item = ast_strip(item);<br>- if (item[0] == '"' && item[strlen(item) - 1] == '"') {<br>- /* Remove surrounding quotes */<br>- item[strlen(item) - 1] = '\0';<br>- item++;<br>- }<br>- staticvalue = item;<br>- }<br>- }<br>-<br>- entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(row[0]) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1 + strlen(row[1]) + 1);<br>- if (!entry) {<br>- ast_log(LOG_ERROR, "Out of memory creating entry for column '%s'\n", row[0]);<br>- mysql_free_result(result);<br>- return AST_MODULE_LOAD_DECLINE;<br>- }<br>-<br>- entry->name = (char *)entry + sizeof(*entry);<br>- strcpy(entry->name, row[0]);<br>-<br>- if (!ast_strlen_zero(cdrvar)) {<br>- entry->cdrname = entry->name + strlen(row[0]) + 1;<br>- strcpy(entry->cdrname, cdrvar);<br>- } else { /* Point to same place as the column name */<br>- entry->cdrname = (char *)entry + sizeof(*entry);<br>- }<br>-<br>- if (!ast_strlen_zero(staticvalue)) {<br>- entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;<br>- strcpy(entry->staticvalue, staticvalue);<br>- ast_debug(1, "staticvalue length: %d\n", (int) strlen(staticvalue) );<br>- entry->type = entry->staticvalue + strlen(entry->staticvalue) + 1;<br>- } else {<br>- entry->type = entry->cdrname + strlen(entry->cdrname) + 1;<br>- }<br>- strcpy(entry->type, row[1]);<br>-<br>- ast_debug(1, "Entry name '%s'\n", entry->name);<br>- ast_debug(1, " cdrname '%s'\n", entry->cdrname);<br>- ast_debug(1, " static '%s'\n", entry->staticvalue);<br>- ast_debug(1, " type '%s'\n", entry->type);<br>-<br>- AST_LIST_INSERT_TAIL(&columns, entry, list);<br>- }<br>- mysql_free_result(result);<br>+ return AST_MODULE_LOAD_SUCCESS; /* May be reconnected later */<br> }<br>+<br>+ ast_debug(1, "Successfully connected to MySQL database.\n");<br>+ connected = 1;<br>+ records = 0;<br>+ connect_time = time(NULL);<br>+<br>+ /* Get table description */<br>+ snprintf(sqldesc, sizeof(sqldesc), "DESC %s", dbtable ? ast_str_buffer(dbtable) : "cdr");<br>+ if (mysql_query(&mysql, sqldesc)) {<br>+ ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");<br>+ mysql_close(&mysql);<br>+ connected = 0;<br>+<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+<br>+ if (!(result = mysql_store_result(&mysql))) {<br>+ ast_log(LOG_ERROR, "Unable to query table description!! Logging disabled.\n");<br>+ mysql_close(&mysql);<br>+ connected = 0;<br>+<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+<br>+ while ((row = mysql_fetch_row(result))) {<br>+ struct column *entry;<br>+ char *cdrvar = "", *staticvalue = "";<br>+<br>+ ast_debug(1, "Got a field '%s' of type '%s'\n", row[0], row[1]);<br>+ /* Check for an alias or a static value */<br>+ for (var = ast_variable_browse(cfg, "columns"); var; var = var->next) {<br>+ if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, row[0]) == 0 ) {<br>+ char *alias = ast_strdupa(var->name + 5);<br>+ cdrvar = ast_strip(alias);<br>+ ast_verb(3, "Found alias %s for column %s\n", cdrvar, row[0]);<br>+ break;<br>+ } else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, row[0]) == 0) {<br>+ char *item = ast_strdupa(var->name + 6);<br>+ item = ast_strip(item);<br>+ if (item[0] == '"' && item[strlen(item) - 1] == '"') {<br>+ /* Remove surrounding quotes */<br>+ item[strlen(item) - 1] = '\0';<br>+ item++;<br>+ }<br>+ staticvalue = item;<br>+ }<br>+ }<br>+<br>+ entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(row[0]) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1 + strlen(row[1]) + 1);<br>+ if (!entry) {<br>+ ast_log(LOG_ERROR, "Out of memory creating entry for column '%s'\n", row[0]);<br>+ mysql_free_result(result);<br>+ return AST_MODULE_LOAD_DECLINE;<br>+ }<br>+<br>+ entry->name = (char *)entry + sizeof(*entry);<br>+ strcpy(entry->name, row[0]);<br>+<br>+ if (!ast_strlen_zero(cdrvar)) {<br>+ entry->cdrname = entry->name + strlen(row[0]) + 1;<br>+ strcpy(entry->cdrname, cdrvar);<br>+ } else { /* Point to same place as the column name */<br>+ entry->cdrname = (char *)entry + sizeof(*entry);<br>+ }<br>+<br>+ if (!ast_strlen_zero(staticvalue)) {<br>+ entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;<br>+ strcpy(entry->staticvalue, staticvalue);<br>+ ast_debug(1, "staticvalue length: %d\n", (int) strlen(staticvalue) );<br>+ entry->type = entry->staticvalue + strlen(entry->staticvalue) + 1;<br>+ } else {<br>+ entry->type = entry->cdrname + strlen(entry->cdrname) + 1;<br>+ }<br>+ strcpy(entry->type, row[1]);<br>+<br>+ ast_debug(1, "Entry name '%s'\n", entry->name);<br>+ ast_debug(1, " cdrname '%s'\n", entry->cdrname);<br>+ ast_debug(1, " static '%s'\n", entry->staticvalue);<br>+ ast_debug(1, " type '%s'\n", entry->type);<br>+<br>+ AST_LIST_INSERT_TAIL(&columns, entry, list);<br>+ }<br>+ mysql_free_result(result);<br>+<br> return AST_MODULE_LOAD_SUCCESS;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8920">change 8920</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8920"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I00bd5363ac94c764c56d8626a5945ed7f3934fcb </div>
<div style="display:none"> Gerrit-Change-Number: 8920 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen@xorcom.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Oron Peled <oron.peled@xorcom.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>