MT#55401 pua and pua_dialoginfo improvements

We are seeing a lot of error messages like:

> ERROR: pua [pua_db.c:895]: get_record_puadb(): Too many rows found (2)

After some investigation I come up with a couple of fixes:

* pua: improve the query to support caller|callee with same pres_id (same dialog)
* pua_dialoginfo: support uuid to generate pres_id to improve randomness

Change-Id: I43d5c58fe20c776b03af217f644443d800c9453e
mr13.0
Victor Seva 2 years ago
parent 37c90781ee
commit 95a5a1678b

@ -54,6 +54,8 @@ sipwise/presence_vqr.patch
sipwise/dialog-dlg_get_ttag.patch
sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch
sipwise/tls-remove-confusing-error-message-when-trying-to-pr.patch
sipwise/pua-get_record_puadb-add-pres_uri-to-the-query.patch
sipwise/pua_dialoginfo-use_uuid.patch
### active development
#
### Don't just put stuff in any order

@ -0,0 +1,83 @@
From: Victor Seva <vseva@sipwise.com>
Date: Tue, 30 Jul 2024 16:13:33 +0200
Subject: pua: get_record_puadb() add pres_uri to the query
---
src/modules/pua/pua_db.c | 17 +++++++++++++----
src/modules/pua/pua_db.h | 4 ++--
src/modules/pua/send_publish.c | 5 +++--
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/modules/pua/pua_db.c b/src/modules/pua/pua_db.c
index f66c3b2..6c1ac77 100644
--- a/src/modules/pua/pua_db.c
+++ b/src/modules/pua/pua_db.c
@@ -790,17 +790,26 @@ int insert_record_puadb(ua_pres_t *pres)
/******************************************************************************/
-ua_pres_t *get_record_puadb(
- str pres_id, str *etag, ua_pres_t *result, db1_res_t **dbres)
+ua_pres_t *get_record_puadb(str *pres_uri, str pres_id, str *etag,
+ ua_pres_t *result, db1_res_t **dbres)
{
- db_key_t q_cols[2];
- db_val_t q_vals[2], *values;
+ db_key_t q_cols[3];
+ db_val_t q_vals[3], *values;
db_row_t *rows;
db1_res_t *res;
int n_query_cols = 0, nr_rows;
db_query_f query_fn =
pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query;
+ if(pres_uri != NULL) {
+ q_cols[n_query_cols] = &str_pres_uri_col;
+ q_vals[n_query_cols].type = DB1_STR;
+ q_vals[n_query_cols].nul = 0;
+ q_vals[n_query_cols].val.str_val.s = pres_uri->s;
+ q_vals[n_query_cols].val.str_val.len = pres_uri->len;
+ n_query_cols++;
+ }
+
q_cols[n_query_cols] = &str_pres_id_col;
q_vals[n_query_cols].type = DB1_STR;
q_vals[n_query_cols].nul = 0;
diff --git a/src/modules/pua/pua_db.h b/src/modules/pua/pua_db.h
index 788d165..5ee2b8c 100644
--- a/src/modules/pua/pua_db.h
+++ b/src/modules/pua/pua_db.h
@@ -58,8 +58,8 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact);
list_entry_t *get_subs_list_puadb(str *did);
int insert_record_puadb(ua_pres_t *pres);
-ua_pres_t *get_record_puadb(
- str pres_id, str *etag, ua_pres_t *result, db1_res_t **res);
+ua_pres_t *get_record_puadb(str *pres_uri, str pres_id, str *etag,
+ ua_pres_t *result, db1_res_t **res);
int delete_record_puadb(ua_pres_t *pres);
int update_record_puadb(ua_pres_t *pres, int expires, str *contact);
int update_version_puadb(ua_pres_t *pres);
diff --git a/src/modules/pua/send_publish.c b/src/modules/pua/send_publish.c
index 5364426..4a06870 100644
--- a/src/modules/pua/send_publish.c
+++ b/src/modules/pua/send_publish.c
@@ -309,7 +309,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
if(pua_dbf.affected_rows != NULL || dbmode != PUA_DB_ONLY) {
if(find_and_update_record(hentity, hash_code, lexpire, &etag) > 0)
goto done;
- } else if((db_presentity = get_record_puadb(
+ } else if((db_presentity = get_record_puadb(hentity->pres_uri,
hentity->id, &hentity->etag, &dbpres, &res))
!= NULL) {
update_record_puadb(hentity, lexpire, &etag);
@@ -468,7 +468,8 @@ int send_publish(publ_info_t *publ)
dbpres.pres_uri = &pres_uri;
dbpres.watcher_uri = &watcher_uri;
dbpres.extra_headers = &extra_headers;
- presentity = get_record_puadb(publ->id, publ->etag, &dbpres, &res);
+ presentity = get_record_puadb(
+ publ->pres_uri, publ->id, publ->etag, &dbpres, &res);
} else {
ua_pres_t pres;

@ -0,0 +1,55 @@
From: Victor Seva <vseva@sipwise.com>
Date: Tue, 20 Aug 2024 14:03:35 +0200
Subject: pua_dialoginfo: use_uuid
---
src/modules/pua_dialoginfo/pua_dialoginfo.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/modules/pua_dialoginfo/pua_dialoginfo.c b/src/modules/pua_dialoginfo/pua_dialoginfo.c
index c8a8a6f..9d3c0f9 100644
--- a/src/modules/pua_dialoginfo/pua_dialoginfo.c
+++ b/src/modules/pua_dialoginfo/pua_dialoginfo.c
@@ -51,6 +51,7 @@
MODULE_VERSION
/* Default module parameter values */
+#define DEF_USE_UUID 0
#define DEF_INCLUDE_CALLID 1
#define DEF_INCLUDE_LOCALREMOTE 1
#define DEF_INCLUDE_TAGS 1
@@ -91,6 +92,7 @@ static str callee_entity_when_publish_disabled = {0, 0}; /* pubruri_callee */
static str local_identity_dlg_var = STR_NULL;
/* Module parameter variables */
+int use_uuid = DEF_USE_UUID;
int include_callid = DEF_INCLUDE_CALLID;
int include_localremote = DEF_INCLUDE_LOCALREMOTE;
int include_tags = DEF_INCLUDE_TAGS;
@@ -120,6 +122,7 @@ static int child_init(int rank);
static cmd_export_t cmds[] = {{0, 0, 0, 0, 0, 0}};
static param_export_t params[] = {
+ {"use_uuid", INT_PARAM, &use_uuid},
{"include_callid", INT_PARAM, &include_callid},
{"include_localremote", INT_PARAM, &include_localremote},
{"include_tags", INT_PARAM, &include_tags},
@@ -732,8 +735,16 @@ struct dlginfo_cell *get_dialog_data(struct dlg_cell *dlg, int type,
int len;
// generate new random uuid
- if(sruid_next_safe(&_puadi_sruid) < 0) {
- return NULL;
+ if(use_uuid) {
+ _puadi_sruid.uid.len = SRUID_SIZE;
+ if(sruid_uuid_generate(_puadi_sruid.uid.s, &_puadi_sruid.uid.len) < 0) {
+ LM_ERR("uuid not generated\n");
+ return NULL;
+ }
+ } else {
+ if(sruid_next_safe(&_puadi_sruid) < 0) {
+ return NULL;
+ }
}
LM_DBG("uuid generated: '%.*s'\n", _puadi_sruid.uid.len,
_puadi_sruid.uid.s);
Loading…
Cancel
Save