pgsqldb.c revision 8befe9e546443b25d5a61237abfa52c348c4ae8e
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: pgsqldb.c,v 1.6 2000/11/20 19:34:12 bwelling Exp $ */
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pgsql/libpq-fe.h>
/*
* A simple database driver that interfaces to a PostgreSQL database. This
* is not complete, and not designed for general use. It opens one
* connection to the database per zone, which is inefficient. It also may
* not support multiple threads and probably doesn't handle quoting correctly.
*
* The table must contain the fields "name", "rdtype", and "rdata", and
* is expected to contain a properly constructed zone. The program "zonetodb"
* creates such a table.
*/
struct dbinfo {
char *table;
};
/*
* Canonicalize a string before writing it to the database.
* "dest" must be an array of at least size 2*strlen(source) + 1.
*/
static void
while (*source != 0) {
*dest++ = '\\';
}
*dest++ = 0;
}
/*
* This database operates on absolute names.
*
* Queries are converted into SQL queries and issued synchronously. Errors
* are handled really badly.
*/
static isc_result_t
{
char str[1500];
char *canonname;
int i;
return (ISC_R_NOMEMORY);
"SELECT TTL,RDTYPE,RDATA FROM \"%s\" WHERE "
return (ISC_R_FAILURE);
}
return (ISC_R_NOTFOUND);
}
char *endp;
if (*endp != '\0') {
return (DNS_R_BADTTL);
}
if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
}
}
return (ISC_R_SUCCESS);
}
/*
* Issue an SQL query to return all nodes in the database and fill the
* allnodes structure.
*/
static isc_result_t
char str[1500];
int i;
"SELECT TTL,NAME,RDTYPE,RDATA FROM \"%s\" ORDER BY NAME",
return (ISC_R_FAILURE);
}
return (ISC_R_NOTFOUND);
}
char *endp;
if (*endp != '\0') {
return (DNS_R_BADTTL);
}
if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
}
}
return (ISC_R_SUCCESS);
}
/*
* Create a connection to the database and save a copy of the table name.
* Save these in dbdata. argv[0] is the name of the database and
* argv[1] is the name of the table.
*/
static isc_result_t
void *driverdata, void **dbdata)
{
if (argc < 2)
return (ISC_R_FAILURE);
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
}
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
}
/*
* Close the connection to the database.
*/
static void
}
/*
* Since the SQL database corresponds to a zone, the authority data should
* be returned by the lookup() function. Therefore the authority() function
* is NULL.
*/
static dns_sdbmethods_t pgsqldb_methods = {
NULL, /* authority */
};
/*
* Wrapper around dns_sdb_register().
*/
pgsqldb_init(void) {
unsigned int flags;
flags = 0;
}
/*
* Wrapper around dns_sdb_unregister().
*/
void
pgsqldb_clear(void) {
}