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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2020-02-24T09:31:39+01:00

core: kemi - convenience function KS.is_proto() to test many transport protos

---

Modified: src/core/kemi.c

---

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

---

diff --git a/src/core/kemi.c b/src/core/kemi.c
index 612e980734..8b5663a39f 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -1105,6 +1105,59 @@ static int sr_kemi_core_is_proto_sctp(sip_msg_t *msg)
        return (msg->rcv.proto == PROTO_SCTP)?SR_KEMI_TRUE:SR_KEMI_FALSE;
 }
 
+/**
+ *
+ */
+static int sr_kemi_core_is_proto(sip_msg_t *msg, str *sproto)
+{
+       int i;
+       if (msg==NULL || sproto==NULL || sproto->s==NULL || sproto->len<=0) {
+               return SR_KEMI_FALSE;
+       }
+       for(i=0; i<sproto->len; i++) {
+               switch(sproto->s[i]) {
+                       case 'e':
+                       case 'E':
+                               if (msg->rcv.proto == PROTO_TLS) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 's':
+                       case 'S':
+                               if (msg->rcv.proto == PROTO_SCTP) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 't':
+                       case 'T':
+                               if (msg->rcv.proto == PROTO_TCP) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'u':
+                       case 'U':
+                               if (msg->rcv.proto == PROTO_UDP) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+                       case 'v':
+                       case 'V':
+                               if (msg->rcv.proto == PROTO_WS) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+
+                       case 'w':
+                       case 'W':
+                               if (msg->rcv.proto == PROTO_WSS) {
+                                       return SR_KEMI_TRUE;
+                               }
+                       break;
+               }
+       }
+       return SR_KEMI_FALSE;
+}
+
 /**
  *
  */
@@ -1717,6 +1770,11 @@ static sr_kemi_t _sr_kemi_core[] = {
                { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init(""), str_init("is_proto"),
+               SR_KEMIP_BOOL, sr_kemi_core_is_proto,
+               { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
        { str_init(""), str_init("is_IPv4"),
                SR_KEMIP_BOOL, sr_kemi_core_is_af_ipv4,
                { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,


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

Reply via email to