Skip to content
Snippets Groups Projects
Commit 99aa7cb2 authored by Rodrigo Ramírez Norambuena's avatar Rodrigo Ramírez Norambuena
Browse files

dr_adaptive_odbc.c, cel_odbc.c, cel_pgsql.c: REFACTOR Macro LENGTHEN_BUF

Remove repeated code on macro of assigned buffer to SQL vars

Change-Id: Icb19ad013124498e172ea1d0b29ccd0ed17deef0
parent 69824fdf
No related branches found
No related tags found
No related merge requests found
...@@ -358,11 +358,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data) ...@@ -358,11 +358,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
return stmt; return stmt;
} }
#define LENGTHEN_BUF1(size) \ #define LENGTHEN_BUF(size, var_sql) \
do { \ do { \
/* Lengthen buffer, if necessary */ \ /* Lengthen buffer, if necessary */ \
if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) { \ if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) { \
if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 1) / 512 + 1) * 512) != 0) { \ if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 1) / 512 + 1) * 512) != 0) { \
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \ ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
ast_free(sql); \ ast_free(sql); \
ast_free(sql2); \ ast_free(sql2); \
...@@ -372,18 +372,10 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data) ...@@ -372,18 +372,10 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
} \ } \
} while (0) } while (0)
#define LENGTHEN_BUF2(size) \ #define LENGTHEN_BUF1(size) \
do { \ LENGTHEN_BUF(size, sql);
if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) { \ #define LENGTHEN_BUF2(size) \
if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \ LENGTHEN_BUF(size, sql2);
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
ast_free(sql); \
ast_free(sql2); \
AST_RWLIST_UNLOCK(&odbc_tables); \
return -1; \
} \
} \
} while (0)
static int odbc_log(struct ast_cdr *cdr) static int odbc_log(struct ast_cdr *cdr)
{ {
......
...@@ -341,11 +341,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data) ...@@ -341,11 +341,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
return stmt; return stmt;
} }
#define LENGTHEN_BUF1(size) \ #define LENGTHEN_BUF(size, var_sql) \
do { \ do { \
/* Lengthen buffer, if necessary */ \ /* Lengthen buffer, if necessary */ \
if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) { \ if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) { \
if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 1) / 512 + 1) * 512) != 0) { \ if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 1) / 512 + 1) * 512) != 0) { \
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", tableptr->connection, tableptr->table); \ ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
ast_free(sql); \ ast_free(sql); \
ast_free(sql2); \ ast_free(sql2); \
...@@ -355,18 +355,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data) ...@@ -355,18 +355,11 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
} \ } \
} while (0) } while (0)
#define LENGTHEN_BUF2(size) \ #define LENGTHEN_BUF1(size) \
do { \ LENGTHEN_BUF(size, sql);
if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) { \
if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \ #define LENGTHEN_BUF2(size) \
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", tableptr->connection, tableptr->table); \ LENGTHEN_BUF(size, sql2);
ast_free(sql); \
ast_free(sql2); \
AST_RWLIST_UNLOCK(&odbc_tables); \
return; \
} \
} \
} while (0)
static void odbc_log(struct ast_event *event) static void odbc_log(struct ast_event *event)
{ {
......
...@@ -100,11 +100,11 @@ struct columns { ...@@ -100,11 +100,11 @@ struct columns {
static AST_RWLIST_HEAD_STATIC(psql_columns, columns); static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
#define LENGTHEN_BUF1(size) \ #define LENGTHEN_BUF(size, var_sql) \
do { \ do { \
/* Lengthen buffer, if necessary */ \ /* Lengthen buffer, if necessary */ \
if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) { \ if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) { \
if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 3) / 512 + 1) * 512) != 0) { \ if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 3) / 512 + 1) * 512) != 0) { \
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", pghostname, table); \ ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", pghostname, table); \
ast_free(sql); \ ast_free(sql); \
ast_free(sql2); \ ast_free(sql2); \
...@@ -114,18 +114,10 @@ static AST_RWLIST_HEAD_STATIC(psql_columns, columns); ...@@ -114,18 +114,10 @@ static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
} \ } \
} while (0) } while (0)
#define LENGTHEN_BUF1(size) \
LENGTHEN_BUF(size, sql);
#define LENGTHEN_BUF2(size) \ #define LENGTHEN_BUF2(size) \
do { \ LENGTHEN_BUF(size, sql2);
if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) { \
if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \
ast_log(LOG_ERROR, "Unable to allocate sufficient memory. Insert CEL '%s:%s' failed.\n", pghostname, table); \
ast_free(sql); \
ast_free(sql2); \
AST_RWLIST_UNLOCK(&psql_columns); \
return; \
} \
} \
} while (0)
static void pgsql_reconnect(void) static void pgsql_reconnect(void)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment