Module: kamailio
Branch: master
Commit: d2807756a7aace0b01b54170be89847b9c335074
URL: 
https://github.com/kamailio/kamailio/commit/d2807756a7aace0b01b54170be89847b9c335074

Author: Federico Cabiddu <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2025-12-09T12:10:25+01:00

db_unixodbc: refactor async functions

---

Modified: src/modules/db_unixodbc/dbase.c
Modified: src/modules/db_unixodbc/dbase.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/d2807756a7aace0b01b54170be89847b9c335074.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d2807756a7aace0b01b54170be89847b9c335074.patch

---

diff --git a/src/modules/db_unixodbc/dbase.c b/src/modules/db_unixodbc/dbase.c
index 11724a28b23..a47df4e7707 100644
--- a/src/modules/db_unixodbc/dbase.c
+++ b/src/modules/db_unixodbc/dbase.c
@@ -180,24 +180,21 @@ void db_unixodbc_async_exec_task(void *param)
                LM_ERR("failed to execute query [%.*s] on async worker\n", 
p[1].len,
                                p[1].s);
        }
-       db_unixodbc_close(dbc);
+       pkg_free(dbc);
 }
 /**
  * Execute a raw SQL query via core async framework.
- * \param _h handle for the database
+ * \param _u database URL
  * \param _s raw query string
  * \return zero on success, negative value on failure
  */
-int db_unixodbc_submit_query_async(const db1_con_t *_h, const str *_s)
+int db_unixodbc_submit_query_async(const str *_u, const str *_s)
 {
-       struct db_id *di;
        async_task_t *atask;
        int asize;
        str *p;
 
-       di = ((struct pool_con *)_h->tail)->id;
-
-       asize = sizeof(async_task_t) + 2 * sizeof(str) + di->url.len + _s->len 
+ 2;
+       asize = sizeof(async_task_t) + 2 * sizeof(str) + _u->len + _s->len + 2;
        atask = shm_malloc(asize);
        if(atask == NULL) {
                LM_ERR("no more shared memory to allocate %d\n", asize);
@@ -209,8 +206,8 @@ int db_unixodbc_submit_query_async(const db1_con_t *_h, 
const str *_s)
 
        p = (str *)((char *)atask + sizeof(async_task_t));
        p[0].s = (char *)p + 2 * sizeof(str);
-       p[0].len = di->url.len;
-       strncpy(p[0].s, di->url.s, di->url.len);
+       p[0].len = _u->len;
+       strncpy(p[0].s, _u->s, _u->len);
        p[1].s = p[0].s + p[0].len + 1;
        p[1].len = _s->len;
        strncpy(p[1].s, _s->s, _s->len);
@@ -223,6 +220,14 @@ int db_unixodbc_submit_query_async(const db1_con_t *_h, 
const str *_s)
 
        return 0;
 }
+
+int db_unixodbc_submit_insert_async(const db1_con_t *_h, const str *_s)
+{
+       struct db_id *di;
+       di = ((struct pool_con *)_h->tail)->id;
+       return db_unixodbc_submit_query_async(&di->url, _s);
+}
+
 extern char *db_unixodbc_tquote;
 
 /*
@@ -501,13 +506,13 @@ int db_unixodbc_raw_query(const db1_con_t *_h, const str 
*_s, db1_res_t **_r)
 
 /**
  * Execute a raw SQL query via core async framework.
- * \param _h handle for the database
+ * \param _u database URL
  * \param _s raw query string
  * \return zero on success, negative value on failure
  */
-int db_unixodbc_raw_query_async(const db1_con_t *_h, const str *_s)
+int db_unixodbc_raw_query_async(const str *_u, const str *_s)
 {
-       return db_unixodbc_submit_query_async(_h, _s);
+       return db_unixodbc_submit_query_async(_u, _s);
 }
 /*
  * Insert a row into specified table
@@ -535,7 +540,7 @@ int db_unixodbc_insert_async(const db1_con_t *_h, const 
db_key_t *_k,
                const db_val_t *_v, const int _n)
 {
        return db_do_insert(_h, _k, _v, _n, db_unixodbc_val2str,
-                       db_unixodbc_submit_query_async);
+                       db_unixodbc_submit_insert_async);
 }
 /*
  * Delete a row from the specified table
diff --git a/src/modules/db_unixodbc/dbase.h b/src/modules/db_unixodbc/dbase.h
index 8cd1acafc61..dff954d2b4e 100644
--- a/src/modules/db_unixodbc/dbase.h
+++ b/src/modules/db_unixodbc/dbase.h
@@ -70,7 +70,7 @@ int db_unixodbc_raw_query(const db1_con_t *_h, const str *_s, 
db1_res_t **_r);
 /*! \brief
  *  * Raw SQL query via async framework
  *   */
-int db_unixodbc_raw_query_async(const db1_con_t *_h, const str *_s);
+int db_unixodbc_raw_query_async(const str *_u, const str *_s);
 
 /*
  * Insert a row into table

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to