Module: kamailio Branch: master Commit: 296ed155be83bc854507892f944748cb8864b704 URL: https://github.com/kamailio/kamailio/commit/296ed155be83bc854507892f944748cb...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-10-24T17:16:16+02:00
core: helper function to get proto id from str
---
Modified: src/core/ip_addr.c Modified: src/core/ip_addr.h
---
Diff: https://github.com/kamailio/kamailio/commit/296ed155be83bc854507892f944748cb... Patch: https://github.com/kamailio/kamailio/commit/296ed155be83bc854507892f944748cb...
---
diff --git a/src/core/ip_addr.c b/src/core/ip_addr.c index bc42b4532d8..02c26f969d5 100644 --- a/src/core/ip_addr.c +++ b/src/core/ip_addr.c @@ -705,6 +705,44 @@ char *get_proto_name(unsigned int proto) } }
+/** get protocol id from string value. + * @param protoval - protocol value + * @return int value of the protocol. + */ +int get_valid_proto_id(str *protoval) +{ + if(protoval == NULL || protoval->s == NULL || protoval->len <= 0) { + return PROTO_NONE; + } + switch(protoval->len) { + case 2: + if(strncasecmp(protoval->s, "ws", 2) == 0) { + return PROTO_WS; + } + break; + case 3: + if(strncasecmp(protoval->s, "udp", 3) == 0) { + return PROTO_UDP; + } + if(strncasecmp(protoval->s, "tcp", 3) == 0) { + return PROTO_TCP; + } + if(strncasecmp(protoval->s, "tls", 3) == 0) { + return PROTO_TLS; + } + if(strncasecmp(protoval->s, "wss", 3) == 0) { + return PROTO_WSS; + } + break; + case 4: + if(strncasecmp(protoval->s, "sctp", 4) == 0) { + return PROTO_SCTP; + } + break; + } + return PROTO_NONE; +} + /** get address family name (asciiz). * @param af - address family id * @return string with the adderess family name or "unknown". diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h index c0067b56d2a..cec63fc4fa9 100644 --- a/src/core/ip_addr.h +++ b/src/core/ip_addr.h @@ -338,6 +338,7 @@ char *get_proto_name(unsigned int proto);
int get_valid_proto_string( unsigned int iproto, int utype, int vtype, str *sproto); +int get_valid_proto_id(str *protoval);
char *get_af_name(unsigned int af);