Module: kamailio Branch: 5.2 Commit: d6bc471aa41447d605eab42ee0596a2e47e3be29 URL: https://github.com/kamailio/kamailio/commit/d6bc471aa41447d605eab42ee0596a2e...
Author: Alexey Vasilyev alexei.vasilyev@gmail.com Committer: Henning Westerholt hw@skalatan.de Date: 2019-09-09T21:54:00+02:00
db_postgres: database URL supports IPv6 address as hostname
- changed parsing of db_url to accept IPv6 address for hostname
(cherry picked from commit f99b4926c817e181f83f92ffa15510ff133d0a15)
---
Modified: src/modules/db_postgres/pg_uri.c
---
Diff: https://github.com/kamailio/kamailio/commit/d6bc471aa41447d605eab42ee0596a2e... Patch: https://github.com/kamailio/kamailio/commit/d6bc471aa41447d605eab42ee0596a2e...
---
diff --git a/src/modules/db_postgres/pg_uri.c b/src/modules/db_postgres/pg_uri.c index 3e4f9a32bc..ce7ac1d989 100644 --- a/src/modules/db_postgres/pg_uri.c +++ b/src/modules/db_postgres/pg_uri.c @@ -109,12 +109,13 @@ static int parse_postgres_uri(struct pg_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;
@@ -172,6 +173,11 @@ static int parse_postgres_uri(struct pg_uri *res, str *uri) begin = uri->s + i + 1; break;
+ case '[': + st = ST_HOST6; + begin = uri->s + i + 1; + break; + case '/': if(memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL) @@ -212,9 +218,14 @@ static int parse_postgres_uri(struct pg_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) + if(dupl_string(&res->host, begin, uri->s + i - ipv6_flag) < 0) goto err; begin = uri->s + i + 1; break; @@ -223,7 +234,7 @@ static int parse_postgres_uri(struct pg_uri *res, str *uri) if(memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL) break; - if(dupl_string(&res->host, begin, uri->s + i) < 0) + 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) @@ -233,6 +244,15 @@ static int parse_postgres_uri(struct pg_uri *res, str *uri) } 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 '/':