Module: kamailio
Branch: 5.2
Commit: 5a4debabd3c6e997200947453503a972b9dcab0f
URL:
https://github.com/kamailio/kamailio/commit/5a4debabd3c6e997200947453503a97…
Author: Alexey Vasilyev <alexei.vasilyev(a)gmail.com>
Committer: Henning Westerholt <hw(a)skalatan.de>
Date: 2019-09-09T21:53:21+02:00
lib: database URL supports IPv6 address as hostname
- changed parsing of db_url to accept IPv6 address for hostname
(cherry picked from commit 9e29e262f0107cedbf2e2d61d045b05c5a5fc410)
---
Modified: src/lib/srdb1/db_id.c
---
Diff:
https://github.com/kamailio/kamailio/commit/5a4debabd3c6e997200947453503a97…
Patch:
https://github.com/kamailio/kamailio/commit/5a4debabd3c6e997200947453503a97…
---
diff --git a/src/lib/srdb1/db_id.c b/src/lib/srdb1/db_id.c
index ef985e52ad..8a43def2d9 100644
--- a/src/lib/srdb1/db_id.c
+++ b/src/lib/srdb1/db_id.c
@@ -100,12 +100,13 @@ static int parse_db_url(struct db_id* id, const str* url)
ST_USER_HOST, /* Username or hostname */
ST_PASS_PORT, /* Password or port part */
ST_HOST, /* Hostname part */
+ ST_HOST6, /* Hostname part IPv6 */
ST_PORT, /* Port part */
ST_DB /* Database part */
};
enum state st;
- unsigned int len, i, j, a, foundanother;
+ unsigned int len, i, j, a, foundanother, ipv6_flag=0;
const char* begin;
char* prev_token;
@@ -188,6 +189,11 @@ static int parse_db_url(struct db_id* id, const str* url)
begin = url->s + i + 1;
break;
+ case '[':
+ st = ST_HOST6;
+ begin = url->s + i + 1;
+ break;
+
case '/':
if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
if (dupl_string_name(&id->database, url->s + i + 1, url->s + len) <
0) goto err;
@@ -224,19 +230,33 @@ static int parse_db_url(struct db_id* id, const str* url)
case ST_HOST:
switch(url->s[i]) {
+ case '[':
+ st = ST_HOST6;
+ begin = url->s + i + 1;
+ break;
+
case ':':
st = ST_PORT;
- if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
+ if (dupl_string(&id->host, begin, url->s + i - ipv6_flag) < 0) goto
err;
begin = url->s + i + 1;
break;
case '/':
- if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
+ if (dupl_string(&id->host, begin, url->s + i - ipv6_flag) < 0) goto
err;
if (dupl_string_name(&id->database, url->s + i + 1, url->s + len) <
0) goto err;
return 0;
}
break;
+ case ST_HOST6:
+ switch(url->s[i]) {
+ case ']':
+ ipv6_flag = 1;
+ st = ST_HOST;
+ break;
+ }
+ break;
+
case ST_PORT:
switch(url->s[i]) {
case '/':