1 /* @(#) $Id: db_op.h,v 1.7 2009/06/24 17:06:30 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
15 /* Common API for dealing with databases */
22 /* Connects to the database */
23 void *(*osdb_connect)(char *host, char *user, char *pass, char *db, int port, char *sock);
24 void *mysql_osdb_connect(char *host, char *user, char *pass, char *db, int port, char *sock);
25 void *postgresql_osdb_connect(char *host, char *user, char *pass, char *db, int port, char *sock);
27 /* Sends insert query to the database */
28 int (* osdb_query_insert)(void *db_conn, char *query);
29 int mysql_osdb_query_insert(void *db_conn, char *query);
30 int postgresql_osdb_query_insert(void *db_conn, char *query);
32 /* Sends select query to the database */
33 int (* osdb_query_select)(void *db_conn, char *query);
34 int mysql_osdb_query_select(void *db_conn, char *query);
35 int postgresql_osdb_query_select(void *db_conn, char *query);
37 /* Closes connection to the database */
38 void *(*osdb_close)(void *db_conn);
39 void *mysql_osdb_close(void *db_conn);
40 void *postgresql_osdb_close(void *db_conn);
43 /* escape strings before inserting. */
44 void osdb_escapestr(char *str);
47 /* Allowed characters */
49 * Available chars: a-z, A-Z, 0-9, -, _, ., %, $, @, (, ), +, *, <space> /
50 * Basically: 040-046 (oct)
53 static const unsigned char insert_map[] =
55 '\000', '\000', '\002', '\003', '\004', '\005', '\006', '\007',
56 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
57 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
58 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
59 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\047',
60 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
61 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
62 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
63 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
64 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
65 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
66 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
67 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
68 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
69 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\001',
70 '\001', '\001', '\001', '\001', '\001', '\001', '\001', '\177',
71 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
72 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
73 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
74 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
75 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
76 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
77 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
78 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
79 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
80 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
81 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
82 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
83 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
84 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
85 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
86 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',