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

Author: Riccardo Villa <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2022-01-11T12:45:40+01:00

dialog: add filter based on start timestamp to dlg.list_match

---

Modified: src/modules/dialog/dialog.c

---

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

---

diff --git a/src/modules/dialog/dialog.c b/src/modules/dialog/dialog.c
index da3ce7cbfd..a25224318c 100644
--- a/src/modules/dialog/dialog.c
+++ b/src/modules/dialog/dialog.c
@@ -2932,6 +2932,8 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
        str mop = {NULL, 0};
        str mval = {NULL, 0};
        str sval = {NULL, 0};
+       unsigned int ival = 0;
+       unsigned int mival = 0;
        int n = 0;
        int m = 0;
        int vkey = 0;
@@ -2960,6 +2962,8 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
                vkey = 2;
        } else if(mkey.len==6 && strncmp(mkey.s, "callid", mkey.len)==0) {
                vkey = 3;
+       } else if(mkey.len==8 && strncmp(mkey.s, "start_ts", mkey.len)==0) {
+               vkey = 4;
        } else {
                LM_ERR("invalid key %.*s\n", mkey.len, mkey.s);
                rpc->fault(c, 500, "Invalid matching key parameter");
@@ -2983,6 +2987,10 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
                }
        } else if(strncmp(mop.s, "sw", 2)==0) {
                vop = 2;
+       } else if(strncmp(mop.s, "gt", 2)==0) {
+               vop = 3;
+       } else if(strncmp(mop.s, "lt", 2)==0) {
+               vop = 4;
        } else {
                LM_ERR("invalid matching operator %.*s\n", mop.len, mop.s);
                rpc->fault(c, 500, "Invalid matching operator parameter");
@@ -2992,6 +3000,18 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
                n = 0;
        }
 
+       if (vkey == 4  && vop <= 2) {
+               LM_ERR("Matching operator %.*s not supported with start_ts 
key\n", mop.len, mop.s);
+               rpc->fault(c, 500, "Matching operator not supported with 
start_ts key");
+               return;
+       }
+
+       if (vkey != 4  && vop >= 3) {
+               LM_ERR("Matching operator %.*s not supported with key %.*s\n", 
mop.len, mop.s, mkey.len, mkey.s);
+               rpc->fault(c, 500, "Matching operator not supported");
+               return;
+       }
+
        for(i=0; i<d_table->size; i++) {
                dlg_lock(d_table, &(d_table->entries[i]));
                for(dlg=d_table->entries[i].first; dlg!=NULL; dlg=dlg->next) {
@@ -3009,6 +3029,9 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
                                case 3:
                                        sval = dlg->callid;
                                break;
+                               case 4:
+                                       ival = dlg->start_ts;
+                               break;
                        }
                        switch(vop) {
                                case 0:
@@ -3031,6 +3054,17 @@ static void rpc_dlg_list_match_ex(rpc_t *rpc, void *c, 
int with_context)
                                                matched = 1;
                                        }
                                break;
+                               case 3:         
+                                       /* greater than */
+                                       if (str2int(&mval, &mival) == 0 && ival 
> mival) {
+                                               matched = 1;
+                                       }
+                               break;
+                               case 4:
+                                       if (str2int(&mval, &mival) == 0 && ival 
< mival) {
+                                               matched = 1;
+                                       }
+                               break;
                        }
                        if (matched==1) {
                                m++;


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to