Index: res_config_mysql.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_config_mysql.c,v retrieving revision 1.5 diff -u -r1.5 res_config_mysql.c --- res_config_mysql.c 22 Jan 2005 21:09:56 -0000 1.5 +++ res_config_mysql.c 22 Jan 2005 22:53:11 -0000 @@ -344,18 +344,16 @@ return -1; } -static struct ast_config *config_mysql(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur) +static struct ast_config *config_mysql(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, int recur) { MYSQL_RES *result; MYSQL_ROW row; my_ulonglong num_rows; struct ast_config *new; - struct ast_variable *cur_v, *new_v; - struct ast_category *cur_cat, *new_cat; + struct ast_variable *new_v; + struct ast_category *cur_cat; char sql[250] = ""; char last[80] = ""; - int cat_started = 0; - int var_started = 0; int last_cat_metric = 0; last[0] = '\0'; @@ -369,7 +367,6 @@ if(new_config_s) { new = new_config_s; - cat_started++; } else { new = ast_new_config(); } @@ -399,52 +396,24 @@ num_rows = mysql_num_rows(result); ast_log(LOG_DEBUG, "MySQL RealTime: Found %llu rows.\n", num_rows); - cat_started = 0; - cur_cat = *new_cat_p; - cur_v = *new_v_p; - - if(cur_cat) { - cat_started = 1; - } - - if(cur_v) { - var_started = 1; - } /* There might exist a better way to access the column names other than counting, but I believe that would require another loop that we don't need. */ while((row = mysql_fetch_row(result))) { if(!strcmp(row[1], "#include") && recur < MAX_INCLUDE_LEVEL) { - config_mysql(database, table, row[2], new, &cur_cat, &cur_v, recur + 1); + config_mysql(database, table, row[2], new, &cur_cat, recur + 1); } else { if(strcmp(last, row[0]) || last_cat_metric != atoi(row[3])) { strncpy(last, row[0], sizeof(last) - 1); last_cat_metric = atoi(row[3]); - new_cat = (struct ast_category *) ast_new_category(row[0]); - - if(!cat_started) { - cat_started++; - new->root = new_cat; - cur_cat = new->root; - } else { - cur_cat->next = new_cat; - cur_cat = cur_cat->next; - } - var_started = 0; + cur_cat = ast_new_category(row[0]); + ast_category_append(new, cur_cat); } new_v = ast_new_variable(row[1], row[2]); - - if (!var_started) { - var_started++; - cur_cat->root = new_v; - cur_v = cur_cat->root; - } else { - cur_v->next = new_v; - cur_v = cur_v->next; - } + ast_variable_append(cur_cat, new_v); } } mysql_free_result(result);