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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2018-02-22T09:49:13+01:00

core: kemi - added KSR.is_method_in("mflags")

- check if current method matches one listed in the flags
- flags are: I (INVITE), A (ACK), B (BYE), C (CANCEL), R (REGISTER),
  P (PUBLISH), S (SUBSCRIBE), N (NOTIFY), O (OPTIONS)
- KSR.is_method_in("IABC")
- more compact alternative to KSR.is_method(...)

---

Modified: src/core/kemi.c

---

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

---

diff --git a/src/core/kemi.c b/src/core/kemi.c
index 5aa94e17b9..655d98a767 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -675,6 +675,94 @@ static int sr_kemi_core_is_method(sip_msg_t *msg, str 
*vmethod)
                        get_cseq(msg)->method_id);
 }
 
+/**
+ *
+ */
+static int sr_kemi_core_is_method_in(sip_msg_t *msg, str *vmethod)
+{
+       int imethod;
+       int i;
+
+       if(msg==NULL || vmethod==NULL || vmethod->s==NULL || vmethod->len<=0) {
+               LM_WARN("invalid parameters\n");
+               return SR_KEMI_FALSE;
+       }
+
+       if(msg->first_line.type==SIP_REQUEST) {
+               imethod = msg->first_line.u.request.method_value;
+       } else {
+               if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) {
+                       LM_ERR("cannot parse cseq header\n");
+                       return SR_KEMI_FALSE;
+               }
+               imethod = get_cseq(msg)->method_id;
+       }
+
+       if(imethod==METHOD_OTHER) {
+               return SR_KEMI_FALSE;
+       }
+
+       for(i=0; i<vmethod->len; i++) {
+               switch(vmethod->s[i]) {
+                       case 'I':
+                       case 'i':
+                               if(imethod==METHOD_INVITE) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'A':
+                       case 'a':
+                               if(imethod==METHOD_ACK) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'B':
+                       case 'b':
+                               if(imethod==METHOD_BYE) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'C':
+                       case 'c':
+                               if(imethod==METHOD_CANCEL) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'R':
+                       case 'r':
+                               if(imethod==METHOD_REGISTER) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'P':
+                       case 'p':
+                               if(imethod==METHOD_PUBLISH) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'S':
+                       case 's':
+                               if(imethod==METHOD_SUBSCRIBE) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'N':
+                       case 'n':
+                               if(imethod==METHOD_NOTIFY) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'O':
+                       case 'o':
+                               if(imethod==METHOD_OPTIONS) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+               }
+       }
+       return SR_KEMI_FALSE;
+}
+
 /**
  *
  */
@@ -999,6 +1087,11 @@ static sr_kemi_t _sr_kemi_core[] = {
                { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init(""), str_init("is_method_in"),
+               SR_KEMIP_BOOL, sr_kemi_core_is_method_in,
+               { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
        { str_init(""), str_init("forward"),
                SR_KEMIP_INT, sr_kemi_core_forward,
                { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,


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

Reply via email to