]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-sql: driver-sqlite - Support options
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 16 Sep 2021 07:39:54 +0000 (10:39 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
No spaces or '=' are permitted in filename after this.

src/lib-sql/driver-sqlite.c

index 4249a53058136fed30935d50b3a2732bdca12e52..da8ab9456b64deba5c20f29b5cbfbdc5c6f2e3f0 100644 (file)
@@ -6,6 +6,7 @@
 #include "str.h"
 #include "hex-binary.h"
 #include "sql-api-private.h"
+#include "strfuncs.h"
 
 #ifdef BUILD_SQLITE
 #include <sqlite3.h>
@@ -76,9 +77,29 @@ static void driver_sqlite_disconnect(struct sql_db *_db)
 
 static int driver_sqlite_parse_connect_string(struct sqlite_db *db,
                                              const char *connect_string,
-                                             const char **error_r ATTR_UNUSED)
+                                             const char **error_r)
 {
-       db->dbfile = p_strdup(db->pool, connect_string);
+       const char *const *params = t_strsplit_spaces(connect_string, " ");
+       const char *file = NULL;
+
+       if (str_array_length(params) < 1) {
+               *error_r = "Empty connect_string";
+               return -1;
+       }
+
+       for (; *params != NULL; params++) {
+               if (strchr(*params, '=') != NULL) {
+                       *error_r = t_strdup_printf("Unsupported parameter '%s'", *params);
+                       return -1;
+               } else if (file == NULL) {
+                       file = *params;
+               } else {
+                       *error_r = "Multiple filenames provided";
+                       return -1;
+               }
+       }
+
+       db->dbfile = p_strdup(db->pool, file);
        return 0;
 }