Skip to content

Commit 3191e3c

Browse files
Added comments for the domain checking
1 parent e94b56a commit 3191e3c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

modules/domain/domain.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ int db_table_lookup(struct sip_msg *msg, str *lookup_domain, str *host, pv_spec_
129129
if (RES_ROW_N(res) > 0) {
130130
values = ROW_VALUES(RES_ROWS(res));
131131

132+
// If we have a row then we need to get the accept_subdomain column first
133+
// If the host does not strictly match this ensures the accept_subdomain can match the subdomain
132134
if (VAL_NULL(values + 2)) {
133135
accept_subdomain = 0;
134136
} else if (VAL_TYPE(values + 2) == DB_INT) {
@@ -188,14 +190,18 @@ int is_domain_local_pvar(struct sip_msg *msg, str* _host, pv_spec_t *pv)
188190

189191
next_domain = strchr(lookup_domain.s, '.');
190192

193+
// If the _host string originally supplied is not a domain eg. sip.com but rather sipcom then strchr will return NULL
194+
// This conditional is for the first strchr check, subsequent runs will not happen based on reverse check in the while condition
191195
if (next_domain == NULL)
192196
break;
193197

194-
next_domain++;
198+
next_domain++; // Remove the '.'
195199

200+
// strlen(next_domain) will not work here as the _host->s char* pointer contains the SIP request domain including port and params
201+
// The bounds checking is done based on the supplied len and this calculation will decrement host part and '.' removed
196202
lookup_domain.len = lookup_domain.len - (next_domain - lookup_domain.s);
197203
lookup_domain.s = next_domain;
198-
} while(strrchr(next_domain, '.') != NULL);
204+
} while(strrchr(next_domain, '.') != NULL); // Exits if the next domain that has been parsed has no '.'
199205

200206
return -1;
201207
}

modules/domain/domain_mod.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ typedef struct param_source {
6262
/*
6363
* Module parameters variables
6464
*/
65-
extern int db_mode; /* Database usage mode: 0 = no cache, 1 = cache */
66-
extern str domain_table; /* Domain table name */
67-
extern str domain_col; /* Domain column name */
68-
extern str domain_attrs_col; /* Domain attributes column name */
69-
extern str domain_accept_subdomain_col; /* Domain accept subdomain column name */
65+
extern int db_mode; /* Database usage mode: 0 = no cache, 1 = cache */
66+
extern str domain_table; /* Domain table name */
67+
extern str domain_col; /* Domain column name */
68+
extern str domain_attrs_col; /* Domain attributes column name */
69+
extern str domain_accept_subdomain_col; /* Domain accept subdomain column name */
7070

7171

7272
/*

0 commit comments

Comments
 (0)