Module: kamailio
Branch: 5.2
Commit: d128b3170c6e82ecd5751351885f9098490068f5
URL:
https://github.com/kamailio/kamailio/commit/d128b3170c6e82ecd5751351885f909…
Author: Alexey Vasilyev <alexei.vasilyev(a)gmail.com>
Committer: Henning Westerholt <hw(a)skalatan.de>
Date: 2019-09-09T21:53:50+02:00
db_mysql: database URL supports IPv6 address as hostname
- changed parsing of db_url to accept IPv6 address for hostname
(cherry picked from commit a7588f382605991bef4499de8c89b10a9468c8cf)
---
Modified: src/modules/db_mysql/my_uri.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d128b3170c6e82ecd5751351885f909…
Patch:
https://github.com/kamailio/kamailio/commit/d128b3170c6e82ecd5751351885f909…
---
diff --git a/src/modules/db_mysql/my_uri.c b/src/modules/db_mysql/my_uri.c
index 8ad5b60b61..1da887080a 100644
--- a/src/modules/db_mysql/my_uri.c
+++ b/src/modules/db_mysql/my_uri.c
@@ -95,12 +95,13 @@ static int parse_mysql_uri(struct my_uri* res, str* uri)
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;
- int i;
+ int i, ipv6_flag=0;
const char* begin;
char* prev_token;
@@ -156,6 +157,11 @@ static int parse_mysql_uri(struct my_uri* res, str* uri)
begin = uri->s + i + 1;
break;
+ case '[':
+ st = ST_HOST6;
+ begin = uri->s + i + 1;
+ break;
+
case '/':
if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len)
< 0) goto err;
@@ -184,19 +190,33 @@ static int parse_mysql_uri(struct my_uri* res, str* uri)
case ST_HOST:
switch(uri->s[i]) {
+ case '[':
+ st = ST_HOST6;
+ begin = uri->s + i + 1;
+ break;
+
case ':':
st = ST_PORT;
- if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
+ if (dupl_string(&res->host, begin, uri->s + i - ipv6_flag) < 0) goto
err;
begin = uri->s + i + 1;
break;
case '/':
- if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
+ if (dupl_string(&res->host, begin, uri->s + i - ipv6_flag) < 0) goto
err;
if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len)
< 0) goto err;
return 0;
}
break;
+ case ST_HOST6:
+ switch(uri->s[i]) {
+ case ']':
+ ipv6_flag = 1;
+ st = ST_HOST;
+ break;
+ }
+ break;
+
case ST_PORT:
switch(uri->s[i]) {
case '/':