summaryrefslogtreecommitdiffabout
path: root/src/dbrw.h
authorSergey Poznyakoff <gray@gnu.org.ua>2013-07-10 12:16:05 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-07-12 08:50:07 (GMT)
commit8afb551c895d6870b0d4f427fa8205ae45ad0bf9 (patch) (side-by-side diff)
tree6e208d7a54d2845035b366a906b35b390ccce96a /src/dbrw.h
downloadvmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.gz
vmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.bz2
Initial commit
Diffstat (limited to 'src/dbrw.h') (more/less context) (ignore whitespace changes)
-rw-r--r--src/dbrw.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/dbrw.h b/src/dbrw.h
new file mode 100644
index 0000000..beebc5e
--- a/dev/null
+++ b/src/dbrw.h
@@ -0,0 +1,70 @@
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <syslog.h>
+
+struct dbrw_connection;
+
+struct dbrw_backend {
+ char *name;
+
+ int (*sql_init) (struct dbrw_connection *);
+ void (*sql_destroy) (struct dbrw_connection *);
+ int (*sql_connect) (struct dbrw_connection *);
+ int (*sql_disconnect) (struct dbrw_connection *);
+ char *(*sql_escape) (struct dbrw_connection *, const char *);
+ int (*sql_query) (struct dbrw_connection *, const char *);
+ unsigned (*sql_num_tuples) (struct dbrw_connection *);
+ unsigned (*sql_num_fields) (struct dbrw_connection *);
+ int (*sql_free_result) (struct dbrw_connection *);
+ const char *(*sql_get_column)(struct dbrw_connection *, unsigned,
+ unsigned);
+};
+
+enum {
+ state_init,
+ state_connected,
+ state_result,
+ state_error,
+ state_disabled
+};
+
+struct dbrw_config {
+ int debug_level;
+ struct dbrw_backend *backend;
+ char **param;
+ char *query;
+};
+
+struct dbrw_connection {
+ int state;
+ struct dbrw_config *conf;
+ void *data;
+};
+
+void dbrw_debug(const char *fmt, ...);
+void dbrw_error(const char *fmt, ...);
+
+#define debug(c,n,a) do { if ((c)->debug_level>=(n)) dbrw_debug a; } while (0)
+
+#ifdef USE_SQL_MYSQL
+struct dbrw_backend mysql_backend;
+#endif
+#ifdef USE_SQL_PGSQL
+struct dbrw_backend pgsql_backend;
+#endif
+
+char *findparam(char **params, char *name);
+
+int sql_init(struct dbrw_connection *);
+int sql_connect(struct dbrw_connection *pd);
+void sql_disconnect(struct dbrw_connection *pd);
+char *sql_escape(struct dbrw_connection *pd, const char *input);
+int sql_query(struct dbrw_connection *pd, const char *input);
+unsigned sql_num_tuples(struct dbrw_connection *pd);
+unsigned sql_num_fields(struct dbrw_connection *pd);
+void sql_free_result(struct dbrw_connection *pd);
+void sql_destroy(struct dbrw_connection *pd);
+const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col);
+

Return to:

Send suggestions and report system problems to the System administrator.