From 633fa601b9561edc5b079b8280e70672e7f63c1a Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Wed, 11 Dec 2024 10:45:05 +0100 Subject: [PATCH 1/4] db_sqlite: Change my_ prefix to sqlite_ for names in the module --- modules/db_sqlite/db_sqlite.c | 2 +- modules/db_sqlite/dbase.c | 2 +- modules/db_sqlite/res.c | 2 +- modules/db_sqlite/row.c | 2 +- modules/db_sqlite/{my_con.c => sqlite_con.c} | 16 ++++----- modules/db_sqlite/{my_con.h => sqlite_con.h} | 34 ++++++++++---------- modules/db_sqlite/val.c | 2 +- 7 files changed, 30 insertions(+), 30 deletions(-) rename modules/db_sqlite/{my_con.c => sqlite_con.c} (91%) rename modules/db_sqlite/{my_con.h => sqlite_con.h} (66%) diff --git a/modules/db_sqlite/db_sqlite.c b/modules/db_sqlite/db_sqlite.c index 301316aa1d0..117b1782ee1 100644 --- a/modules/db_sqlite/db_sqlite.c +++ b/modules/db_sqlite/db_sqlite.c @@ -46,7 +46,7 @@ static int db_sqlite_add_extension(modparam_t type, void *val); struct db_sqlite_extension_list *extension_list=0; /* - * MySQL database module interface + * SQLite database module interface */ static const cmd_export_t cmds[] = { {"db_bind_api", (cmd_function)db_sqlite_bind_api, {{0,0,0}},0}, diff --git a/modules/db_sqlite/dbase.c b/modules/db_sqlite/dbase.c index 8a47098297d..3632d769d55 100644 --- a/modules/db_sqlite/dbase.c +++ b/modules/db_sqlite/dbase.c @@ -34,7 +34,7 @@ #include "../../db/db_ut.h" #include "../../db/db_insertq.h" #include "../../db/db_res.h" -#include "my_con.h" +#include "sqlite_con.h" #include "val.h" #include "res.h" #include "row.h" diff --git a/modules/db_sqlite/res.c b/modules/db_sqlite/res.c index f502001ebeb..ea438d13f95 100644 --- a/modules/db_sqlite/res.c +++ b/modules/db_sqlite/res.c @@ -34,7 +34,7 @@ #include "../../db/db_insertq.h" #include "../../db/db_res.h" #include "../../ut.h" -#include "my_con.h" +#include "sqlite_con.h" #include "row.h" diff --git a/modules/db_sqlite/row.c b/modules/db_sqlite/row.c index a6d6066d715..9acc396dc87 100644 --- a/modules/db_sqlite/row.c +++ b/modules/db_sqlite/row.c @@ -29,7 +29,7 @@ #include "../../db/db_ut.h" #include "../../db/db_val.h" #include "../../db/db_row.h" -#include "my_con.h" +#include "sqlite_con.h" #include "val.h" #include "row.h" diff --git a/modules/db_sqlite/my_con.c b/modules/db_sqlite/sqlite_con.c similarity index 91% rename from modules/db_sqlite/my_con.c rename to modules/db_sqlite/sqlite_con.c index fe317e59ff3..c3566cb4e87 100644 --- a/modules/db_sqlite/my_con.c +++ b/modules/db_sqlite/sqlite_con.c @@ -34,7 +34,7 @@ #include "../../db/db_insertq.h" #include "../../db/db_id.h" #include "../../mem/mem.h" -#include "my_con.h" +#include "sqlite_con.h" #include "db_sqlite.h" extern struct db_sqlite_extension_list *extension_list; @@ -43,7 +43,7 @@ extern struct db_sqlite_extension_list *extension_list; #define URL_BUFSIZ 1024 char url_buf[URL_BUFSIZ]; -int db_sqlite_connect(struct my_con* ptr) +int db_sqlite_connect(struct sqlite_con* ptr) { sqlite3* con; char* errmsg; @@ -110,23 +110,23 @@ int db_sqlite_connect(struct my_con* ptr) * Create a new connection structure, * open the sqlite connection and set reference count to 1 */ -struct my_con* db_sqlite_new_connection(const struct db_id* id) +struct sqlite_con* db_sqlite_new_connection(const struct db_id* id) { - struct my_con* ptr; + struct sqlite_con* ptr; if (!id) { LM_ERR("invalid parameter value\n"); return 0; } - ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con)); + ptr = (struct sqlite_con*)pkg_malloc(sizeof(struct sqlite_con)); if (!ptr) { LM_ERR("no private memory left\n"); return 0; } - memset(ptr, 0, sizeof(struct my_con)); + memset(ptr, 0, sizeof(struct sqlite_con)); ptr->ref = 1; ptr->id = (struct db_id*)id; @@ -149,8 +149,8 @@ void db_sqlite_free_connection(struct pool_con* con) { if (!con) return; - struct my_con * _c; - _c = (struct my_con*) con; + struct sqlite_con * _c; + _c = (struct sqlite_con*) con; if (_c->id) free_db_id(_c->id); if (_c->con) { diff --git a/modules/db_sqlite/my_con.h b/modules/db_sqlite/sqlite_con.h similarity index 66% rename from modules/db_sqlite/my_con.h rename to modules/db_sqlite/sqlite_con.h index 14d231a8847..d6f8c61c3dd 100644 --- a/modules/db_sqlite/my_con.h +++ b/modules/db_sqlite/sqlite_con.h @@ -22,14 +22,14 @@ * ------- * 2015-02-18 initial version (Ionut Ionita) */ -#ifndef MY_SQLITE_CON_H -#define MY_SQLITE_CON_H +#ifndef SQLITE_CON_H +#define SQLITE_CON_H #define PREP_STMT_VAL_LEN 1024 #include -struct my_con { +struct sqlite_con { struct db_id* id; /**< Connection identifier */ unsigned int ref; /**< Reference count */ struct pool_con *async_pool; /**< Subpool of identical database handles */ @@ -43,38 +43,38 @@ struct my_con { sqlite3* con; /* Connection representation */ sqlite3_stmt* curr_ps; int curr_ps_rows; - unsigned int init; /* If the mysql conn was initialized */ + unsigned int init; /* If the sqlite conn was initialized */ struct prep_stmt *ps_list; /* list of prepared statements */ }; -struct my_stmt_ctx { +struct sqlite_stmt_ctx { sqlite3_stmt *stmt; str query; int query_rows; - struct my_stmt_ctx *next; + struct sqlite_stmt_ctx *next; }; struct prep_stmt { - struct my_stmt_ctx *stmt_list; - struct my_stmt_ctx *ctx; + struct sqlite_stmt_ctx *stmt_list; + struct sqlite_stmt_ctx *ctx; }; -#define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con) -#define CON_ROW(db_con) (((struct my_con*)((db_con)->tail))->row) -#define CON_SQLITE_PS(db_con) (((struct my_con*)((db_con)->tail))->curr_ps) -#define CON_RAW_QUERY(db_con) (((struct my_con*)((db_con)->tail))->raw_query) -#define CON_PS_ROWS(db_con) (((struct my_con*)((db_con)->tail))->curr_ps_rows) -#define CON_DISCON(db_con) (((struct my_con*)((db_con)->tail))->disconnected) +#define CON_CONNECTION(db_con) (((struct sqlite_con*)((db_con)->tail))->con) +#define CON_ROW(db_con) (((struct sqlite_con*)((db_con)->tail))->row) +#define CON_SQLITE_PS(db_con) (((struct sqlite_con*)((db_con)->tail))->curr_ps) +#define CON_RAW_QUERY(db_con) (((struct sqlite_con*)((db_con)->tail))->raw_query) +#define CON_PS_ROWS(db_con) (((struct sqlite_con*)((db_con)->tail))->curr_ps_rows) +#define CON_DISCON(db_con) (((struct sqlite_con*)((db_con)->tail))->disconnected) -int db_sqlite_connect(struct my_con* ptr); -struct my_con* db_sqlite_new_connection(const struct db_id* id); +int db_sqlite_connect(struct sqlite_con* ptr); +struct sqlite_con* db_sqlite_new_connection(const struct db_id* id); void db_sqlite_free_connection(struct pool_con* con); -#endif /* MY_SQLITE_CON_H */ +#endif /* SQLITE_CON_H */ diff --git a/modules/db_sqlite/val.c b/modules/db_sqlite/val.c index 47a34ba89ac..1eec99ce9ed 100644 --- a/modules/db_sqlite/val.c +++ b/modules/db_sqlite/val.c @@ -27,7 +27,7 @@ #include "../../db/db_ut.h" #include "../../db/db_query.h" #include "val.h" -#include "my_con.h" +#include "sqlite_con.h" #include #include From 14c6210a556c3cd2403981b007b67e2648fcc685 Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Wed, 11 Dec 2024 13:21:58 +0100 Subject: [PATCH 2/4] db_sqlite: Fix sqlite3_errmsg call with initialized variable ptr->con is always NULL at this moment --- modules/db_sqlite/sqlite_con.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/db_sqlite/sqlite_con.c b/modules/db_sqlite/sqlite_con.c index c3566cb4e87..708d71c9d8b 100644 --- a/modules/db_sqlite/sqlite_con.c +++ b/modules/db_sqlite/sqlite_con.c @@ -60,7 +60,7 @@ int db_sqlite_connect(struct sqlite_con* ptr) url_buf[ptr->id->url.len - (sizeof(SQLITE_ID)-1)] = '\0'; if (sqlite3_open(url_buf, &con) != SQLITE_OK) { - LM_ERR("Can't open database: %s\n", sqlite3_errmsg((sqlite3*)ptr->con)); + LM_ERR("Can't open database: %s\n", sqlite3_errmsg(con)); return -1; } @@ -91,8 +91,6 @@ int db_sqlite_connect(struct sqlite_con* ptr) } } - - ptr->con = con; return 0; From 76e581fb85a27d860cce4ad894834fdc49b3c3ad Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Wed, 11 Dec 2024 15:38:56 +0100 Subject: [PATCH 3/4] db_sqlite: Remove unused variables --- modules/db_sqlite/db_sqlite.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/db_sqlite/db_sqlite.c b/modules/db_sqlite/db_sqlite.c index 117b1782ee1..9b1c3899a36 100644 --- a/modules/db_sqlite/db_sqlite.c +++ b/modules/db_sqlite/db_sqlite.c @@ -33,9 +33,6 @@ #define ALLOC_LIMIT 10 #define LDEXT_LIST_DELIM ';' -unsigned int db_sqlite_timeout_interval = 2; /* Default is 6 seconds */ -unsigned int db_sliqte_exec_query_threshold = 0; /* Warning in case DB query - takes too long disabled by default*/ int db_sqlite_alloc_limit=ALLOC_LIMIT; From 778162a2d6dc4df2afe7e6324ed3f469e6360601 Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Fri, 13 Dec 2024 12:25:59 +0100 Subject: [PATCH 4/4] db_sqlite: Free memory after using error message --- modules/db_sqlite/sqlite_con.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/db_sqlite/sqlite_con.c b/modules/db_sqlite/sqlite_con.c index 708d71c9d8b..11d04598def 100644 --- a/modules/db_sqlite/sqlite_con.c +++ b/modules/db_sqlite/sqlite_con.c @@ -80,6 +80,7 @@ int db_sqlite_connect(struct sqlite_con* ptr) "Errmsg [%s]!\n", iter->ldpath, iter->entry_point, errmsg); + sqlite3_free(errmsg); goto out_free; } LM_DBG("Extension [%s] loaded!\n", iter->ldpath);