MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / match_domain

Function match_domain

name_alias.h:63–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61extern struct alias_function* alias_fcts;
62
63static inline int match_domain(char* alias, int alias_len, char* host, int host_len, int accept_subdomain) {
64 int index_offset;
65
66 /* Check if the alias is a subdomain alias and if so calculate the index offset to start the comparison
67 * Given an alias my.domain.com or my.great.domain.com and a subdomain of domain.com the comparison should start at domain.com
68 * a host of domain.com will also match, if the flag is not set then do a strict comparison
69 */
70 if (accept_subdomain) {
71 index_offset = host_len - alias_len;
72 // the host we're checking is a shorter len than the alias so no need to compare
73 if (index_offset < 0) return 0;
74 // if the offset is greater than 0 we need to ensure the host we're checking has a preceding '.' to ensure it's a subdomain
75 else if (index_offset > 0 && !(*((host + index_offset) - 1) == '.')) return 0;
76
77 if (strncasecmp(alias, host + index_offset, alias_len)==0)
78 return 1;
79 } else if (host_len == alias_len && strncasecmp(alias, host, host_len)==0) {
80 return 1;
81 }
82
83 return 0;
84}
85
86/* returns 1 if name is in the alias list; if port=0, port no is ignored
87 * if proto=0, proto is ignored*/

Callers 3

grep_aliasesFunction · 0.85
hash_table_lookupFunction · 0.85
db_table_lookupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected