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

Author: Xenofon Karamanos <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-02-12T19:30:53+01:00

dlgs: add RPC command to count records by filter

---

Modified: src/modules/dlgs/dlgs_records.c

---

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

---

diff --git a/src/modules/dlgs/dlgs_records.c b/src/modules/dlgs/dlgs_records.c
index 38ecb3d5ee3..ae0dc8d65b5 100644
--- a/src/modules/dlgs/dlgs_records.c
+++ b/src/modules/dlgs/dlgs_records.c
@@ -44,7 +44,7 @@
 #include "dlgs_records.h"
 
 #define dlgs_compute_hash(_s) core_case_hash(_s, 0, 0)
-#define dlgs_get_index(_h, _size) (_h) & ((_size)-1)
+#define dlgs_get_index(_h, _size) (_h) & ((_size) - 1)
 
 extern int _dlgs_active_lifetime;
 extern int _dlgs_init_lifetime;
@@ -1255,6 +1255,9 @@ static void dlgs_rpc_get(rpc_t *rpc, void *ctx)
 static const char *dlgs_rpc_getall_doc[2] = {
                "Get all the dlgs records by filter", 0};
 
+static const char *dlgs_rpc_count_doc[2] = {
+               "Count the dlgs records by filter", 0};
+
 /*
  * RPC command to get all dlgs records by filter
  */
@@ -1263,6 +1266,36 @@ static void dlgs_rpc_getall(rpc_t *rpc, void *ctx)
        dlgs_rpc_get_limit(rpc, ctx, 0);
 }
 
+/*
+ * RPC command to count dlgs records by filter
+ */
+static void dlgs_rpc_count(rpc_t *rpc, void *ctx)
+{
+       str vfield = STR_NULL;
+       str vop = STR_NULL;
+       str vdata = STR_NULL;
+       int n;
+
+       if(_dlgs_htb == NULL) {
+               rpc->fault(ctx, 500, "DLGS not initialized");
+               return;
+       }
+
+       n = rpc->scan(ctx, "SSS", &vfield, &vop, &vdata);
+       if(n < 3) {
+               rpc->fault(ctx, 500, "Invalid Parameters");
+               return;
+       }
+
+       n = dlgs_count(NULL, &vfield, &vop, &vdata);
+       if(n < 0) {
+               rpc->fault(ctx, 500, "Error counting dialogs");
+               return;
+       }
+
+       rpc->add(ctx, "d", n);
+}
+
 /* clang-format off */
 rpc_export_t dlgs_rpc_cmds[] = {
        {"dlgs.stats", dlgs_rpc_stats,
@@ -1275,6 +1308,8 @@ rpc_export_t dlgs_rpc_cmds[] = {
                dlgs_rpc_get_doc, RET_ARRAY},
        {"dlgs.getall",  dlgs_rpc_getall,
                dlgs_rpc_getall_doc, RET_ARRAY},
+       {"dlgs.count", dlgs_rpc_count,
+               dlgs_rpc_count_doc, 0},
 
        {0, 0, 0, 0}
 };

_______________________________________________
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