[sr-dev] git:master:f99b4926: db_postgres: database URL supports IPv6 address as hostname

Henning Westerholt hw at skalatan.de
Mon Sep 9 21:52:05 CEST 2019


Module: kamailio
Branch: master
Commit: f99b4926c817e181f83f92ffa15510ff133d0a15
URL: https://github.com/kamailio/kamailio/commit/f99b4926c817e181f83f92ffa15510ff133d0a15

Author: Alexey Vasilyev <alexei.vasilyev at gmail.com>
Committer: Henning Westerholt <hw at skalatan.de>
Date: 2019-09-09T21:51:59+02:00

db_postgres: database URL supports IPv6 address as hostname

- changed parsing of db_url to accept IPv6 address for hostname

---

Modified: src/modules/db_postgres/pg_uri.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f99b4926c817e181f83f92ffa15510ff133d0a15.diff
Patch: https://github.com/kamailio/kamailio/commit/f99b4926c817e181f83f92ffa15510ff133d0a15.patch

---

diff --git a/src/modules/db_postgres/pg_uri.c b/src/modules/db_postgres/pg_uri.c
index 89c12dc069..50132c16f9 100644
--- a/src/modules/db_postgres/pg_uri.c
+++ b/src/modules/db_postgres/pg_uri.c
@@ -110,12 +110,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;
 
@@ -173,6 +174,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)
@@ -213,9 +219,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;
@@ -224,7 +235,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)
@@ -234,6 +245,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 '/':




More information about the sr-dev mailing list