Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,277 +0,0 @@
1
-/* 
2
- * MySQL module interface
3
- *
4
- * Copyright (C) 2001-2003 FhG FOKUS
5
- * Copyright (C) 2006-2007 iptelorg GmbH
6
- *
7
- * This file is part of Kamailio, a free SIP server.
8
- *
9
- * Kamailio is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
13
- *
14
- * Kamailio is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License 
20
- * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
- */
23
-
24
-#include "my_uri.h"
25
-
26
-#include "../../dprint.h"
27
-#include "../../mem/mem.h"
28
-#include "../../ut.h"
29
-#include "../../lib/srdb2/db_gen.h"
30
-
31
-#include <stdlib.h>
32
-#include <string.h>
33
-
34
-
35
-/* compare s1 & s2  with a function f (which should return 0 if ==);
36
- * s1 & s2 can be null
37
- * return 0 if match, 1 if not */
38
-#define cmpstr(s1, s2, f) \
39
-	((s1)!=(s2)) && ((s1)==0 || (s2)==0 || (f)((s1), (s2))!=0)
40
-
41
-/*
42
- * Compare two connection identifiers
43
- */
44
-static unsigned char my_uri_cmp(db_uri_t* uri1, db_uri_t* uri2)
45
-{
46
-	struct my_uri* muri1, *muri2;
47
-
48
-	if (!uri1 || !uri2) return 0;
49
-
50
-	muri1 = DB_GET_PAYLOAD(uri1);
51
-	muri2 = DB_GET_PAYLOAD(uri2);
52
-	if (muri1->port != muri2->port) return 0;
53
-
54
-	if (cmpstr(muri1->username, muri2->username, strcmp)) return 0;
55
-	if (cmpstr(muri1->password, muri2->password, strcmp)) return 0;
56
-	if (cmpstr(muri1->host, muri2->host, strcasecmp)) return 0;
57
-	if (cmpstr(muri1->database, muri2->database, strcmp)) return 0;
58
-	return 1;
59
-}
60
-
61
-
62
-
63
-/*
64
- * Duplicate a string
65
- */
66
-static int dupl_string(char** dst, const char* begin, const char* end)
67
-{
68
-	if (*dst) pkg_free(*dst);
69
-
70
-	*dst = pkg_malloc(end - begin + 1);
71
-	if ((*dst) == NULL) {
72
-		return -1;
73
-	}
74
-
75
-	memcpy(*dst, begin, end - begin);
76
-	(*dst)[end - begin] = '\0';
77
-	return 0;
78
-}
79
-
80
-
81
-/*
82
- * Parse mysql URI of form 
83
- * //[username[:password]@]hostname[:port]/database
84
- *
85
- * Returns 0 if parsing was successful and -1 otherwise
86
- */
87
-static int parse_mysql_uri(struct my_uri* res, str* uri)
88
-{
89
-#define SHORTEST_DB_URL "//a/b"
90
-#define SHORTEST_DB_URL_LEN (sizeof(SHORTEST_DB_URL) - 1)
91
-
92
-	enum state {
93
-		ST_SLASH1,     /* First slash */
94
-		ST_SLASH2,     /* Second slash */
95
-		ST_USER_HOST,  /* Username or hostname */
96
-		ST_PASS_PORT,  /* Password or port part */
97
-		ST_HOST,       /* Hostname part */
98
-		ST_PORT,       /* Port part */
99
-		ST_DB          /* Database part */
100
-	};
101
-
102
-	enum state st;
103
-	int  i;
104
-	const char* begin;
105
-	char* prev_token;
106
-
107
-	prev_token = 0;
108
-
109
-	if (!res || !uri) {
110
-		goto err;
111
-	}
112
-	
113
-	if (uri->len < SHORTEST_DB_URL_LEN) {
114
-		goto err;
115
-	}
116
-	
117
-	st = ST_SLASH1;
118
-	begin = uri->s;
119
-
120
-	for(i = 0; i < uri->len; i++) {
121
-		switch(st) {
122
-		case ST_SLASH1:
123
-			switch(uri->s[i]) {
124
-			case '/':
125
-				st = ST_SLASH2;
126
-				break;
127
-
128
-			default:
129
-				goto err;
130
-			}
131
-			break;
132
-
133
-		case ST_SLASH2:
134
-			switch(uri->s[i]) {
135
-			case '/':
136
-				st = ST_USER_HOST;
137
-				begin = uri->s + i + 1;
138
-				break;
139
-				
140
-			default:
141
-				goto err;
142
-			}
143
-			break;
144
-
145
-		case ST_USER_HOST:
146
-			switch(uri->s[i]) {
147
-			case '@':
148
-				st = ST_HOST;
149
-				if (dupl_string(&res->username, begin, uri->s + i) < 0) goto err;
150
-				begin = uri->s + i + 1;
151
-				break;
152
-
153
-			case ':':
154
-				st = ST_PASS_PORT;
155
-				if (dupl_string(&prev_token, begin, uri->s + i) < 0) goto err;
156
-				begin = uri->s + i + 1;
157
-				break;
158
-
159
-			case '/':
160
-				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
161
-				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
162
-				return 0;
163
-			}
164
-			break;
165
-
166
-		case ST_PASS_PORT:
167
-			switch(uri->s[i]) {
168
-			case '@':
169
-				st = ST_HOST;
170
-				res->username = prev_token;
171
-				prev_token = 0;
172
-				if (dupl_string(&res->password, begin, uri->s + i) < 0) goto err;
173
-				begin = uri->s + i + 1;
174
-				break;
175
-
176
-			case '/':
177
-				res->host = prev_token;
178
-				prev_token = 0;
179
-				res->port = str2s(begin, uri->s + i - begin, 0);
180
-				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
181
-				return 0;
182
-			}
183
-			break;
184
-
185
-		case ST_HOST:
186
-			switch(uri->s[i]) {
187
-			case ':':
188
-				st = ST_PORT;
189
-				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
190
-				begin = uri->s + i + 1;
191
-				break;
192
-
193
-			case '/':
194
-				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
195
-				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
196
-				return 0;
197
-			}
198
-			break;
199
-
200
-		case ST_PORT:
201
-			switch(uri->s[i]) {
202
-			case '/':
203
-				res->port = str2s(begin, uri->s + i - begin, 0);
204
-				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
205
-				return 0;
206
-			}
207
-			break;
208
-			
209
-		case ST_DB:
210
-			break;
211
-		}
212
-	}
213
-
214
-	if (st != ST_DB) goto err;
215
-	return 0;
216
-
217
- err:
218
-	if (prev_token) pkg_free(prev_token);
219
-	if (res == NULL) return -1;
220
-	if (res->username) {
221
-		pkg_free(res->username);
222
-		res->username = NULL;
223
-	}
224
-	if (res->password) {
225
-		pkg_free(res->password);
226
-		res->password = NULL;
227
-	}
228
-	if (res->host) {
229
-		pkg_free(res->host);
230
-		res->host = NULL;
231
-	}
232
-	if (res->database) {
233
-		pkg_free(res->database);
234
-		res->database = NULL;
235
-	}
236
-	return -1;
237
-}
238
-
239
-
240
-
241
-static void my_uri_free(db_uri_t* uri, struct my_uri* payload)
242
-{
243
-	if (payload == NULL) return;
244
-	db_drv_free(&payload->drv);
245
-	if (payload->username) pkg_free(payload->username);
246
-	if (payload->password) pkg_free(payload->password);
247
-	if (payload->host) pkg_free(payload->host);
248
-	if (payload->database) pkg_free(payload->database);
249
-	pkg_free(payload);
250
-}
251
-
252
-
253
-int my_uri(db_uri_t* uri)
254
-{
255
-	struct my_uri* res;
256
-
257
-	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
258
-	if (res == NULL) {
259
-		ERR("mysql: No memory left\n");
260
-		goto error;
261
-	}
262
-	memset(res, '\0', sizeof(struct my_uri));
263
-	if (db_drv_init(&res->drv, my_uri_free) < 0) goto error;
264
-	if (parse_mysql_uri(res, &uri->body) < 0) goto error;
265
-
266
-	DB_SET_PAYLOAD(uri, res);
267
-	uri->cmp = my_uri_cmp;
268
-	return 0;
269
-
270
- error:
271
-	if (res) {
272
-		db_drv_free(&res->drv);
273
-		if (res) pkg_free(res);
274
-	}
275
-	return -1;
276
-}
277
-
Browse code

db_mysql: Remove SVN ID's, remove history sections

Olle E. Johansson authored on 11/03/2015 15:26:21
Showing 1 changed files
... ...
@@ -1,24 +1,17 @@
1 1
 /* 
2
- * $Id$ 
3
- *
4 2
  * MySQL module interface
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG FOKUS
7 5
  * Copyright (C) 2006-2007 iptelorg GmbH
8 6
  *
9
- * This file is part of ser, a free SIP server.
7
+ * This file is part of Kamailio, a free SIP server.
10 8
  *
11
- * ser is free software; you can redistribute it and/or modify
9
+ * Kamailio is free software; you can redistribute it and/or modify
12 10
  * it under the terms of the GNU General Public License as published by
13 11
  * the Free Software Foundation; either version 2 of the License, or
14 12
  * (at your option) any later version
15 13
  *
16
- * For a license to use the ser software under conditions
17
- * other than those described here, or to purchase support for this
18
- * software, please contact iptel.org by e-mail at the following addresses:
19
- *    info@iptel.org
20
- *
21
- * ser is distributed in the hope that it will be useful,
14
+ * Kamailio is distributed in the hope that it will be useful,
22 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 17
  * GNU General Public License for more details.
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -25,7 +25,7 @@
25 25
  *
26 26
  * You should have received a copy of the GNU General Public License 
27 27
  * along with this program; if not, write to the Free Software 
28
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29 29
  */
30 30
 
31 31
 #include "my_uri.h"
Browse code

db_mysql: reset prev_token to avoid double free in case of url parse error

- when db api v2 is used (ser modules)

Daniel-Constantin Mierla authored on 21/04/2014 15:36:01
Showing 1 changed files
... ...
@@ -175,12 +175,14 @@ static int parse_mysql_uri(struct my_uri* res, str* uri)
175 175
 			case '@':
176 176
 				st = ST_HOST;
177 177
 				res->username = prev_token;
178
+				prev_token = 0;
178 179
 				if (dupl_string(&res->password, begin, uri->s + i) < 0) goto err;
179 180
 				begin = uri->s + i + 1;
180 181
 				break;
181 182
 
182 183
 			case '/':
183 184
 				res->host = prev_token;
185
+				prev_token = 0;
184 186
 				res->port = str2s(begin, uri->s + i - begin, 0);
185 187
 				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
186 188
 				return 0;
Browse code

db_mysql: fixed condition checking the parameter for db uri parsing

- on a report generated by cppcheck sent by David Binderman

Daniel-Constantin Mierla authored on 28/01/2014 17:36:21
Showing 1 changed files
... ...
@@ -113,7 +113,7 @@ static int parse_mysql_uri(struct my_uri* res, str* uri)
113 113
 
114 114
 	prev_token = 0;
115 115
 
116
-	if (!res || !res) {
116
+	if (!res || !uri) {
117 117
 		goto err;
118 118
 	}
119 119
 	
Browse code

Changes necessary to make the module compile in the sip-router tree.

This is a set of changes necessary to make the LDAP module compile in the
sip-router tree. This includes:
* Extra stuff in the Makefile to link with libsrdb2
* Defined SER_MOD_INTERFACE in the makefile
* Updated relative paths to srdb2 header files

Jan Janak authored on 13/02/2009 00:51:33
Showing 1 changed files
... ...
@@ -33,7 +33,7 @@
33 33
 #include "../../dprint.h"
34 34
 #include "../../mem/mem.h"
35 35
 #include "../../ut.h"
36
-#include "../../db/db_gen.h"
36
+#include "../../lib/srdb2/db_gen.h"
37 37
 
38 38
 #include <stdlib.h>
39 39
 #include <string.h>
Browse code

- reordered included header files for better detection of missing headers - disable automatic database reconnects, they do not work with pre-compiled statements - error/info/log message cleanup - auto_reconnect module parameter removed - introduced new module parameter retries which controls the number of times queries are tried to execute on server on failures

Jan Janak authored on 16/01/2008 14:17:28
Showing 1 changed files
... ...
@@ -28,13 +28,15 @@
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 29
  */
30 30
 
31
-#include <stdlib.h>
32
-#include <string.h>
31
+#include "my_uri.h"
32
+
33 33
 #include "../../dprint.h"
34 34
 #include "../../mem/mem.h"
35 35
 #include "../../ut.h"
36 36
 #include "../../db/db_gen.h"
37
-#include "my_uri.h"
37
+
38
+#include <stdlib.h>
39
+#include <string.h>
38 40
 
39 41
 
40 42
 /* compare s1 & s2  with a function f (which should return 0 if ==);
... ...
@@ -259,7 +261,7 @@ int my_uri(db_uri_t* uri)
259 261
 
260 262
 	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
261 263
 	if (res == NULL) {
262
-		ERR("No memory left\n");
264
+		ERR("mysql: No memory left\n");
263 265
 		goto error;
264 266
 	}
265 267
 	memset(res, '\0', sizeof(struct my_uri));
Browse code

- extra debugging messages removed

Jan Janak authored on 04/04/2007 13:59:17
Showing 1 changed files
... ...
@@ -257,8 +257,6 @@ int my_uri(db_uri_t* uri)
257 257
 {
258 258
 	struct my_uri* res;
259 259
 
260
-	ERR("my_uri called\n");
261
-
262 260
 	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
263 261
 	if (res == NULL) {
264 262
 		ERR("No memory left\n");
Browse code

- mysql module updated to new db api

Jan Janak authored on 04/04/2007 11:48:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,282 @@
1
+/* 
2
+ * $Id$ 
3
+ *
4
+ * MySQL module interface
5
+ *
6
+ * Copyright (C) 2001-2003 FhG FOKUS
7
+ * Copyright (C) 2006-2007 iptelorg GmbH
8
+ *
9
+ * This file is part of ser, a free SIP server.
10
+ *
11
+ * ser is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; either version 2 of the License, or
14
+ * (at your option) any later version
15
+ *
16
+ * For a license to use the ser software under conditions
17
+ * other than those described here, or to purchase support for this
18
+ * software, please contact iptel.org by e-mail at the following addresses:
19
+ *    info@iptel.org
20
+ *
21
+ * ser is distributed in the hope that it will be useful,
22
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+ * GNU General Public License for more details.
25
+ *
26
+ * You should have received a copy of the GNU General Public License 
27
+ * along with this program; if not, write to the Free Software 
28
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
+ */
30
+
31
+#include <stdlib.h>
32
+#include <string.h>
33
+#include "../../dprint.h"
34
+#include "../../mem/mem.h"
35
+#include "../../ut.h"
36
+#include "../../db/db_gen.h"
37
+#include "my_uri.h"
38
+
39
+
40
+/* compare s1 & s2  with a function f (which should return 0 if ==);
41
+ * s1 & s2 can be null
42
+ * return 0 if match, 1 if not */
43
+#define cmpstr(s1, s2, f) \
44
+	((s1)!=(s2)) && ((s1)==0 || (s2)==0 || (f)((s1), (s2))!=0)
45
+
46
+/*
47
+ * Compare two connection identifiers
48
+ */
49
+static unsigned char my_uri_cmp(db_uri_t* uri1, db_uri_t* uri2)
50
+{
51
+	struct my_uri* muri1, *muri2;
52
+
53
+	if (!uri1 || !uri2) return 0;
54
+
55
+	muri1 = DB_GET_PAYLOAD(uri1);
56
+	muri2 = DB_GET_PAYLOAD(uri2);
57
+	if (muri1->port != muri2->port) return 0;
58
+
59
+	if (cmpstr(muri1->username, muri2->username, strcmp)) return 0;
60
+	if (cmpstr(muri1->password, muri2->password, strcmp)) return 0;
61
+	if (cmpstr(muri1->host, muri2->host, strcasecmp)) return 0;
62
+	if (cmpstr(muri1->database, muri2->database, strcmp)) return 0;
63
+	return 1;
64
+}
65
+
66
+
67
+
68
+/*
69
+ * Duplicate a string
70
+ */
71
+static int dupl_string(char** dst, const char* begin, const char* end)
72
+{
73
+	if (*dst) pkg_free(*dst);
74
+
75
+	*dst = pkg_malloc(end - begin + 1);
76
+	if ((*dst) == NULL) {
77
+		return -1;
78
+	}
79
+
80
+	memcpy(*dst, begin, end - begin);
81
+	(*dst)[end - begin] = '\0';
82
+	return 0;
83
+}
84
+
85
+
86
+/*
87
+ * Parse mysql URI of form 
88
+ * //[username[:password]@]hostname[:port]/database
89
+ *
90
+ * Returns 0 if parsing was successful and -1 otherwise
91
+ */
92
+static int parse_mysql_uri(struct my_uri* res, str* uri)
93
+{
94
+#define SHORTEST_DB_URL "//a/b"
95
+#define SHORTEST_DB_URL_LEN (sizeof(SHORTEST_DB_URL) - 1)
96
+
97
+	enum state {
98
+		ST_SLASH1,     /* First slash */
99
+		ST_SLASH2,     /* Second slash */
100
+		ST_USER_HOST,  /* Username or hostname */
101
+		ST_PASS_PORT,  /* Password or port part */
102
+		ST_HOST,       /* Hostname part */
103
+		ST_PORT,       /* Port part */
104
+		ST_DB          /* Database part */
105
+	};
106
+
107
+	enum state st;
108
+	int  i;
109
+	const char* begin;
110
+	char* prev_token;
111
+
112
+	prev_token = 0;
113
+
114
+	if (!res || !res) {
115
+		goto err;
116
+	}
117
+	
118
+	if (uri->len < SHORTEST_DB_URL_LEN) {
119
+		goto err;
120
+	}
121
+	
122
+	st = ST_SLASH1;
123
+	begin = uri->s;
124
+
125
+	for(i = 0; i < uri->len; i++) {
126
+		switch(st) {
127
+		case ST_SLASH1:
128
+			switch(uri->s[i]) {
129
+			case '/':
130
+				st = ST_SLASH2;
131
+				break;
132
+
133
+			default:
134
+				goto err;
135
+			}
136
+			break;
137
+
138
+		case ST_SLASH2:
139
+			switch(uri->s[i]) {
140
+			case '/':
141
+				st = ST_USER_HOST;
142
+				begin = uri->s + i + 1;
143
+				break;
144
+				
145
+			default:
146
+				goto err;
147
+			}
148
+			break;
149
+
150
+		case ST_USER_HOST:
151
+			switch(uri->s[i]) {
152
+			case '@':
153
+				st = ST_HOST;
154
+				if (dupl_string(&res->username, begin, uri->s + i) < 0) goto err;
155
+				begin = uri->s + i + 1;
156
+				break;
157
+
158
+			case ':':
159
+				st = ST_PASS_PORT;
160
+				if (dupl_string(&prev_token, begin, uri->s + i) < 0) goto err;
161
+				begin = uri->s + i + 1;
162
+				break;
163
+
164
+			case '/':
165
+				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
166
+				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
167
+				return 0;
168
+			}
169
+			break;
170
+
171
+		case ST_PASS_PORT:
172
+			switch(uri->s[i]) {
173
+			case '@':
174
+				st = ST_HOST;
175
+				res->username = prev_token;
176
+				if (dupl_string(&res->password, begin, uri->s + i) < 0) goto err;
177
+				begin = uri->s + i + 1;
178
+				break;
179
+
180
+			case '/':
181
+				res->host = prev_token;
182
+				res->port = str2s(begin, uri->s + i - begin, 0);
183
+				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
184
+				return 0;
185
+			}
186
+			break;
187
+
188
+		case ST_HOST:
189
+			switch(uri->s[i]) {
190
+			case ':':
191
+				st = ST_PORT;
192
+				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
193
+				begin = uri->s + i + 1;
194
+				break;
195
+
196
+			case '/':
197
+				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
198
+				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
199
+				return 0;
200
+			}
201
+			break;
202
+
203
+		case ST_PORT:
204
+			switch(uri->s[i]) {
205
+			case '/':
206
+				res->port = str2s(begin, uri->s + i - begin, 0);
207
+				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) goto err;
208
+				return 0;
209
+			}
210
+			break;
211
+			
212
+		case ST_DB:
213
+			break;
214
+		}
215
+	}
216
+
217
+	if (st != ST_DB) goto err;
218
+	return 0;
219
+
220
+ err:
221
+	if (prev_token) pkg_free(prev_token);
222
+	if (res == NULL) return -1;
223
+	if (res->username) {
224
+		pkg_free(res->username);
225
+		res->username = NULL;
226
+	}
227
+	if (res->password) {
228
+		pkg_free(res->password);
229
+		res->password = NULL;
230
+	}
231
+	if (res->host) {
232
+		pkg_free(res->host);
233
+		res->host = NULL;
234
+	}
235
+	if (res->database) {
236
+		pkg_free(res->database);
237
+		res->database = NULL;
238
+	}
239
+	return -1;
240
+}
241
+
242
+
243
+
244
+static void my_uri_free(db_uri_t* uri, struct my_uri* payload)
245
+{
246
+	if (payload == NULL) return;
247
+	db_drv_free(&payload->drv);
248
+	if (payload->username) pkg_free(payload->username);
249
+	if (payload->password) pkg_free(payload->password);
250
+	if (payload->host) pkg_free(payload->host);
251
+	if (payload->database) pkg_free(payload->database);
252
+	pkg_free(payload);
253
+}
254
+
255
+
256
+int my_uri(db_uri_t* uri)
257
+{
258
+	struct my_uri* res;
259
+
260
+	ERR("my_uri called\n");
261
+
262
+	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
263
+	if (res == NULL) {
264
+		ERR("No memory left\n");
265
+		goto error;
266
+	}
267
+	memset(res, '\0', sizeof(struct my_uri));
268
+	if (db_drv_init(&res->drv, my_uri_free) < 0) goto error;
269
+	if (parse_mysql_uri(res, &uri->body) < 0) goto error;
270
+
271
+	DB_SET_PAYLOAD(uri, res);
272
+	uri->cmp = my_uri_cmp;
273
+	return 0;
274
+
275
+ error:
276
+	if (res) {
277
+		db_drv_free(&res->drv);
278
+		if (res) pkg_free(res);
279
+	}
280
+	return -1;
281
+}
282
+