From 6ce2be3d09484d393c894a291dc9429525d3d914 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Sun, 15 Jan 2012 23:53:12 +0100 Subject: edb-pgsql: Reworked the prepared statements infrastructure Moved all SQL statements out of each function and into a const struct which is loaded at startup. Implemented a safer way of handling parameters to these prepared statements as well. Signed-off-by: David Sommerseth --- database/postgresql/prepared-sql.h | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 database/postgresql/prepared-sql.h (limited to 'database/postgresql/prepared-sql.h') diff --git a/database/postgresql/prepared-sql.h b/database/postgresql/prepared-sql.h new file mode 100644 index 0000000..0d09f20 --- /dev/null +++ b/database/postgresql/prepared-sql.h @@ -0,0 +1,72 @@ +/* prepared-sql.h -- PostgreSQL database driver for eurephia + * + * GPLv2 only - Copyright (C) 2012 + * David Sommerseth + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/** + * @file prepared-sql.h + * @author David Sommerseth + * @date 2012-01-15 + * + * @brief eurephia database driver for the PostgreSQL database. + * The infrastructure needed for prepared SQL statements + */ + +#ifndef _PREPARED_SQL_H +#define _PREPARED_SQL_H + +#include +#include + +typedef enum { PREPSQL_NONE = 0, PREPSQL_TLS_AUTH, PREPSQL_USERPWD_AUTH, + PREPSQL_BLACKLIST_ATTEMPTUPD, PREPSQL_USERS_LASTACC_UPD, + PREPSQL_USERS_GETUID, PREPSQL_ATTEMPTS_RESET, PREPSQL_ATTEMPTS_INCR, + PREPSQL_ATTEMPTS_REG_CERT, PREPSQL_ATTEMPTS_REG_USERNAME, + PREPSQL_ATTEMPTS_REG_IPADDR, + PREPSQL_BLACKLIST_CHECK_CERT, PREPSQL_BLACKLIST_CHECK_USERNAME, + PREPSQL_BLACKLIST_CHECK_IPADDR, + PREPSQL_BLACKLIST_REG_CERT, PREPSQL_BLACKLIST_REG_USERNAME, + PREPSQL_BLACKLIST_REG_IPADDR, + PREPSQL_SESSIONKEY_GETSEED_SESSION, PREPSQL_SESSIONKEY_GETSEED_AUTH, + PREPSQL_SESSIONKEY_GETMAC, + PREPSQL_SESSIONKEY_UNIQ_ADMIN, PREPSQL_SESSIONKEY_UNIQ_PLAUTH, + PREPSQL_SESSIONKEY_REGISTER, PREPSQL_SESSIONKEY_REMOVE, + PREPSQL_SESSIONVARS_LOAD, PREPSQL_SESSIONVARS_STORE_NEW, + PREPSQL_SESSIONVARS_STORE_UPDATE, PREPSQL_SESSIONVARS_STORE_DELETE, + PREPSQL_SESSIONS_DESTROY_LASTLOG, PREPSQL_SESSIONS_DESTROY_SESS, + PREPSQL_REGISTER_LOGIN, PREPSQL_REGISTER_LOGOUT, + PREPSQL_MACHISTORY_REGISTER, PREPSQL_MACHISTORY_LASTLOG, + PREPSQL_FIREWALL_GETPROFILE +} ePG_prepID; + +typedef struct _ePGprepParam_s { + ePG_prepID prepid; + int index; + char **params; +} ePGprepParams; + +int ePGprepStatementGetID(ePG_prepID prepid); +const char const * ePGprepStatementGetName(eurephiaCTX *ctx, ePG_prepID prepid); +int ePGprepLoadStatements(eurephiaCTX *ctx); +ePGprepParams * ePGprepParamsAlloc(eurephiaCTX *ctx, ePG_prepID prepid); +int ePGprepParamsAddArgument(eurephiaCTX *ctx, ePGprepParams *prms, const char *arg); +int ePGprepParamsAddArgumentInt(eurephiaCTX *ctx, ePGprepParams *prms, const int arg); +PGresult * ePGprepExec(eurephiaCTX *ctx, ePGprepParams *qry_args); + +#endif -- cgit