Browse code

db_mysql: restore group ending character in db url

- ] was set to \0 to use it for mysql options, but it will break
matching the db url for connection pooling
- reported by Juha Heinanen

Daniel-Constantin Mierla authored on 30/01/2015 06:54:52
Showing 1 changed files
... ...
@@ -43,7 +43,7 @@
43 43
 struct my_con* db_mysql_new_connection(const struct db_id* id)
44 44
 {
45 45
 	struct my_con* ptr;
46
-	char *host, *grp;
46
+	char *host, *grp, *egrp;
47 47
 	unsigned int connection_flag = 0;
48 48
 
49 49
 	if (!id) {
... ...
@@ -57,6 +57,7 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
57 57
 		return 0;
58 58
 	}
59 59
 
60
+	egrp = 0;
60 61
 	memset(ptr, 0, sizeof(struct my_con));
61 62
 	ptr->ref = 1;
62 63
 	
... ...
@@ -68,9 +69,10 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
68 69
 
69 70
 	mysql_init(ptr->con);
70 71
 
71
-	if (id->host[0] == '[' && (host = strchr(id->host, ']')) != NULL) {
72
+	if (id->host[0] == '[' && (egrp = strchr(id->host, ']')) != NULL) {
72 73
 		grp = id->host + 1;
73
-		*host = '\0';
74
+		*egrp = '\0';
75
+		host = egrp;
74 76
 		if (host != id->host + strlen(id->host)-1) {
75 77
 			host += 1; // host found after closing bracket
76 78
 		}
... ...
@@ -129,11 +131,13 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
129 131
 
130 132
 	ptr->timestamp = time(0);
131 133
 	ptr->id = (struct db_id*)id;
134
+	if(egrp) *egrp = ']';
132 135
 	return ptr;
133 136
 
134 137
  err:
135 138
 	if (ptr && ptr->con) pkg_free(ptr->con);
136 139
 	if (ptr) pkg_free(ptr);
140
+	if(egrp) *egrp = ']';
137 141
 	return 0;
138 142
 }
139 143