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

Function check_hostname

modules/sipmsgops/sipmsgops.c:1499–1538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1497
1498
1499static int check_hostname(str *domain)
1500{
1501 char *p, *end;
1502
1503 if (!domain || domain->len < 0) {
1504 LM_DBG("inexistent domain\n");
1505 return -1;
1506 }
1507
1508 /* always starts with a ALPHANUM */
1509 if (!_isalnum(domain->s[0]) && (domain->s[0] != '[')) {
1510 LM_DBG("invalid starting character in domain: %c[%d]\n",
1511 domain->s[0], domain->s[0]);
1512 return -1;
1513 }
1514
1515 /* check the last character separately, as it cannot contain '-' */
1516 end = domain->s + domain->len - 1;
1517
1518 for (p = domain->s + 1; p < end; p++) {
1519 if (!_isalnum(*p) && (*p != '-') && (*p != ':')) {
1520 if (*p != '.') {
1521 LM_DBG("invalid character in hostname: %c[%d]\n", *p, *p);
1522 return -1;
1523 } else if (*(p - 1) == '.') {
1524 LM_DBG("two consecutive '.' are not allowed in hostname\n");
1525 return -1;
1526 }
1527 }
1528 }
1529
1530 /* check if the last character is a '-' */
1531 if (!_isalnum(*end) && (*end != '.') && (*end != ']')) {
1532 LM_DBG("invalid character at the end of the domain: %c[%d]\n",
1533 *end, *end);
1534 return -1;
1535 }
1536 return 0;
1537
1538}
1539
1540
1541#define CHECK_HEADER(_m, _h) \

Callers 1

w_sip_validateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected