/* * Create a connection to the database and save any necessary information * in dbdata. * * argv[0] is the name of the database file * argv[1] is the name of the table */ static isc_result_t sqlitedb_create(const char *zone, int argc, char **argv, void *driverdata, void **dbdata) { dbinfo_t *dbi; isc_result_t result; UNUSED(zone); UNUSED(driverdata); if (argc < 2) return (ISC_R_FAILURE); dbi = isc_mem_get(ns_g_mctx, sizeof(dbinfo_t)); if (dbi == NULL) return (ISC_R_NOMEMORY); dbi->db = NULL; dbi->filename = NULL; dbi->table = NULL; STRDUP_OR_FAIL(dbi->filename, argv[0]); STRDUP_OR_FAIL(dbi->table, argv[1]); result = db_connect(dbi); if (result != ISC_R_SUCCESS) goto cleanup; *dbdata = dbi; return (ISC_R_SUCCESS); cleanup: sqlitedb_destroy(zone, driverdata, (void **)&dbi); return (result); }
/* * Create a connection to the database and save any necessary information * in dbdata. * * argv[0] is the name of the database * argv[1] is the name of the table * argv[2] (if present) is the name of the host to connect to * argv[3] (if present) is the name of the user to connect as * argv[4] (if present) is the name of the password to connect with */ static isc_result_t pgsqldb_create(const char *zone, int argc, char **argv, void *driverdata, void **dbdata) { struct dbinfo *dbi; isc_result_t result; UNUSED(zone); UNUSED(driverdata); if (argc < 2) return (ISC_R_FAILURE); dbi = isc_mem_get(ns_g_mctx, sizeof(struct dbinfo)); if (dbi == NULL) return (ISC_R_NOMEMORY); dbi->conn = NULL; dbi->database = NULL; dbi->table = NULL; dbi->host = NULL; dbi->user = NULL; dbi->passwd = NULL; #define STRDUP_OR_FAIL(target, source) \ do { \ target = isc_mem_strdup(ns_g_mctx, source); \ if (target == NULL) { \ result = ISC_R_NOMEMORY; \ goto cleanup; \ } \ } while (/*CONSTCOND*/0); STRDUP_OR_FAIL(dbi->database, argv[0]); STRDUP_OR_FAIL(dbi->table, argv[1]); if (argc > 2) STRDUP_OR_FAIL(dbi->host, argv[2]); if (argc > 3) STRDUP_OR_FAIL(dbi->user, argv[3]); if (argc > 4) STRDUP_OR_FAIL(dbi->passwd, argv[4]); result = db_connect(dbi); if (result != ISC_R_SUCCESS) goto cleanup; *dbdata = dbi; return (ISC_R_SUCCESS); cleanup: pgsqldb_destroy(zone, driverdata, (void **)&dbi); return (result); }