X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Flookups%2Fsqlite.c;h=1619429e5861433a916f7627819ed9073dc05468;hb=aded22555eeb31bc032f9bc58a83762981a58391;hp=0b01fdbce9b1d9df7007c848fc1ea123774df377;hpb=5903c6ff59527362e869fedb565c56935ce8dd68;p=exim.git diff --git a/src/src/lookups/sqlite.c b/src/src/lookups/sqlite.c index 0b01fdbce..1619429e5 100644 --- a/src/src/lookups/sqlite.c +++ b/src/src/lookups/sqlite.c @@ -2,7 +2,7 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2015 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ #include "../exim.h" @@ -41,21 +41,16 @@ return db; /* See local README for interface description. */ -struct strbuf { - uschar *string; - int size; - int len; -}; - -static int sqlite_callback(void *arg, int argc, char **argv, char **azColName) +static int +sqlite_callback(void *arg, int argc, char **argv, char **azColName) { -struct strbuf *res = arg; +gstring * res = *(gstring **)arg; int i; /* For second and subsequent results, insert \n */ -if (res->string != NULL) - res->string = string_catn(res->string, &res->size, &res->len, US"\n", 1); +if (res) + res = string_catn(res, US"\n", 1); if (argc > 1) { @@ -63,18 +58,14 @@ if (argc > 1) for (i = 0; i < argc; i++) { uschar *value = US((argv[i] != NULL)? argv[i]:""); - res->string = lf_quote(US azColName[i], value, Ustrlen(value), res->string, - &res->size, &res->len); + res = lf_quote(US azColName[i], value, Ustrlen(value), res); } } else - { - res->string = string_append(res->string, &res->size, &res->len, 1, - (argv[0] != NULL)? argv[0]:""); - } + res = string_cat(res, argv[0] ? US argv[0] : US ""); -res->string[res->len] = 0; +*(gstring **)arg = res; return 0; } @@ -84,7 +75,7 @@ sqlite_find(void *handle, uschar *filename, const uschar *query, int length, uschar **result, uschar **errmsg, uint *do_cache) { int ret; -struct strbuf res = { NULL, 0, 0 }; +gstring * res = NULL; ret = sqlite3_exec(handle, CS query, sqlite_callback, &res, (char **)errmsg); if (ret != SQLITE_OK) @@ -93,9 +84,9 @@ if (ret != SQLITE_OK) return FAIL; } -if (res.string == NULL) *do_cache = 0; +if (!res) *do_cache = 0; -*result = res.string; +*result = string_from_gstring(res); return OK; }