mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-05 04:35:46 +00:00
Refactor and fix edge cases in switch_split_user_domain
We were incorrectly parsing usernames and domains starting with "sip" if there was no sip: or sips: scheme in the string. We were also incorrectly parsing usernames containing a colon even if a scheme was given. This also refactors the function for hopefully greater clarity.
This commit is contained in:
parent
b0d7551c80
commit
5aab272bb3
@ -3115,55 +3115,24 @@ SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val)
|
|||||||
|
|
||||||
SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domain)
|
SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domain)
|
||||||
{
|
{
|
||||||
char *p = NULL, *h = NULL, *u;
|
char *p = NULL, *h = NULL, *u = NULL;
|
||||||
|
|
||||||
if (!in) {
|
if (!in) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strncasecmp(in, "sip", 3)) {
|
/* Remove URL scheme */
|
||||||
in += 3;
|
if (!strncasecmp(in, "sip:", 4)) in += 4;
|
||||||
if (*in == 's') in++;
|
if (!strncasecmp(in, "sips:", 5)) in += 5;
|
||||||
if (*in == ':') in++;
|
|
||||||
}
|
|
||||||
|
|
||||||
u = in;
|
/* Isolate the host part from the user part */
|
||||||
|
if ((h = in, p = strchr(h, '@'))) *p = '\0', u = in, h = p+1;
|
||||||
/* First isolate the host part from the user part */
|
|
||||||
if ((h = strchr(u, '@'))) {
|
|
||||||
*h++ = '\0';
|
|
||||||
} else {
|
|
||||||
u = NULL;
|
|
||||||
h = in;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean out the user part of its protocol prefix (if any) */
|
|
||||||
if (u && (p = strchr(u, ':'))) {
|
|
||||||
*p++ = '\0';
|
|
||||||
u = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean out the host part of any suffix */
|
/* Clean out the host part of any suffix */
|
||||||
if (h) {
|
if ((p = strchr(h, ':'))) *p = '\0';
|
||||||
if ((p = strchr(h, ':'))) {
|
if ((p = strchr(h, ';'))) *p = '\0';
|
||||||
*p = '\0';
|
if ((p = strchr(h, ' '))) *p = '\0';
|
||||||
}
|
|
||||||
|
|
||||||
if ((p = strchr(h, ';'))) {
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((p = strchr(h, ' '))) {
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
*user = u;
|
|
||||||
}
|
|
||||||
if (domain) {
|
|
||||||
*domain = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (user) *user = u;
|
||||||
|
if (domain) *domain = h;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user