Debian Codegraph @

database/eurephiadb_mapping.h

raw
1 /* eurephiadb_mapping.h -- eurephiaDB table/field mapping
2 * This mapping system, makes it possible
3 * to access specific database table fields
4 * through a unified API
5 *
6 * GPLv2 only - Copyright (C) 2008 - 2012
7 * David Sommerseth <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2
12 * of the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *
23 */
24
25 /**
26 * @file eurephiadb_mapping.h
27 * @author David Sommerseth <[email protected]>
28 * @date 2008-12-06
29 *
30 * @brief Database field mapping between database and the C code/programs
31 *
32 * This feature makes it possible to let each database driver implementation to
33 * use its own table and column/field names in the database, while having a
34 * unified interface for table names and field names in the application.
35 *
36 * @remark The database may not have all assigned fields in the table as indicated here,
37 * as this is a way how to get around queries which uses JOIN between more tables.
38 */
39
40 #ifndef EUREPHIADB_MAPPING_H
41 # define EUREPHIADB_MAPPING_H
42
43 /**
44 * Enumeration of different field types
45 */
46 typedef enum eDBfieldType_e { ft_UNDEF, ft_INT, ft_STRING, ft_STRING_LOWER, ft_DATETIME, ft_PASSWD, ft_SETNULL } eDBfieldType;
47
48 /**
49 * Enumeration of different SQL filter types (IS NULL, =, !=, <=, >=, >, <, etc)
50 */
51 typedef enum eDBfieldFilterType_e { flt_NOTSET, flt_EQ, flt_NEQ, flt_LT, flt_LTE, flt_GT, flt_GTE } eDBfieldFilterType;
52
53 /**
54 * Definition of the eDBfieldMap structure which maps a given numeric table ID and field ID
55 * to a specific field name. This structure can also holds values for these fields to be used
56 * when doing SELECT, UPDATE or DELETE queries with WHERE sections and new values when doing
57 * INSERT INTO and UPDATE
58 */
59 typedef struct _eDBfieldMap_s {
60 int tableid; /**< @see TABLE_USERS */
61 char *table_alias; /**< If the table needs an alias in the SQL query,
62 it should be set here*/
63 long field_id; /**< @see FIELD_NONE */
64 eDBfieldType field_type; /**< Defines what kind of data this field stores */
65 eDBfieldFilterType filter_type; /**< Only for WHERE sections, defines what kind of filter
66 mode to use */
67 char *field_name; /**< Name of the field as a string */
68 char *value; /**< Value of the field */
69 struct _eDBfieldMap_s *next; /**< Creates a pointer chain */
70 } eDBfieldMap;
71
72 extern const char *SESSION_STATUS[];
73
74 /**
75 * TABLE ID definitions
76 *
77 * Gives each table needed for eurephia a numeric ID. These IDs are sequential numbers, starting on 1
78 * and being increased by 1.
79 * @{
80 */
81 #define TABLE_USERS 0x01
82 #define TABLE_CERTS 0x02
83 #define TABLE_USERCERTS 0x03
84 #define TABLE_LASTLOG 0x04
85 #define TABLE_ATTEMPTS 0x05
86 #define TABLE_BLACKLIST 0x06
87 #define TABLE_EUREPHIAADMACC 0x07
88 #define TABLE_FWPROFILES 0x08
89 /**
90 * @}
91 */
92
93 /**
94 * FIELD ID definitions
95 *
96 * Gives each table needed for eurephia a numeric ID. These IDs are increased by 2^x as these
97 * fields can be processed in a bit-wise manner by some functions.
98 * @{
99 */
100 #define FIELD_NONE 0x0000000 /**< Special field */
101 #define FIELD_RECID 0x0000001 /**< Special field, should be used to indicate primary key of the table */
102 #define FIELD_UID 0x0000002
103 #define FIELD_CERTID 0x0000004
104 #define FIELD_UNAME 0x0000008
105 #define FIELD_ACTIVATED 0x0000010
106 #define FIELD_DEACTIVATED 0x0000020
107 #define FIELD_LASTACCESS 0x0000040
108
109 #define FIELD_CERTDEPTH 0x0000080
110 #define FIELD_CNAME 0x0000100
111 #define FIELD_EMAIL 0x0000200
112 #define FIELD_ORG 0x0000400
113 #define FIELD_REGISTERED 0x0000800
114
115 #define FIELD_REMOTEIP 0x0001000
116 #define FIELD_VPNIP 0x0002000
117 #define FIELD_ATTEMPTS 0x0004000
118 #define FIELD_LASTATTEMPT 0x0008000
119
120 #define FIELD_SESSTATUS 0x0010000
121 #define FIELD_LOGIN 0x0020000
122 #define FIELD_LOGOUT 0x0040000
123 #define FIELD_PASSWD 0x0080000
124 #define FIELD_CERTDIGEST 0x0100000
125
126 #define FIELD_ACCPROFILE 0x0200000
127
128 #define FIELD_INTERFACE 0x0400000
129 #define FIELD_ACCESSLVL 0x0800000
130
131 #define FIELD_MACADDR 0x1000000
132 #define FIELD_UICID 0x2000000
133
134 #define FIELD_DESCR 0x4000000
135 #define FIELD_FWPROFILE 0x8000000
136 /**
137 * @}
138 */
139
140
141 #ifdef EUREPHIADB_MAPPING_C
142
143 /**
144 * Unified eurephia field names for the 'users' table
145 */
146 static eDBfieldMap eTblMap_user[] = {
147 {TABLE_USERS, NULL, FIELD_RECID, ft_INT, flt_EQ, "uid", NULL, NULL},
148 {TABLE_USERS, NULL, FIELD_UNAME, ft_STRING, flt_EQ, "username", NULL, NULL},
149 {TABLE_USERS, NULL, FIELD_PASSWD, ft_PASSWD, flt_EQ, "password", NULL, NULL},
150 {TABLE_USERS, NULL, FIELD_ACTIVATED, ft_DATETIME, flt_EQ, "activated", NULL, NULL},
151 {TABLE_USERS, NULL, FIELD_DEACTIVATED, ft_DATETIME, flt_EQ, "deactivated", NULL, NULL},
152 {TABLE_USERS, NULL, FIELD_LASTACCESS, ft_DATETIME, flt_EQ, "lastaccess", NULL, NULL},
153 {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
154 };
155
156 /**
157 * Unified eurephia field names for the 'certificates' table
158 */
159 static eDBfieldMap eTblMap_certificates[] = {
160 {TABLE_CERTS, NULL, FIELD_RECID, ft_INT , flt_EQ, "certid", NULL, NULL},
161 {TABLE_CERTS, NULL, FIELD_CERTDEPTH, ft_INT , flt_EQ, "depth", NULL, NULL},
162 {TABLE_CERTS, NULL, FIELD_CERTDIGEST, ft_STRING_LOWER, flt_EQ, "digest", NULL, NULL},
163 {TABLE_CERTS, NULL, FIELD_CNAME, ft_STRING , flt_EQ, "cname", NULL, NULL},
164 {TABLE_CERTS, NULL, FIELD_ORG, ft_STRING , flt_EQ, "org", NULL, NULL},
165 {TABLE_CERTS, NULL, FIELD_EMAIL, ft_STRING , flt_EQ, "email", NULL, NULL},
166 {TABLE_CERTS, NULL, FIELD_REGISTERED, ft_DATETIME , flt_EQ, "registered", NULL, NULL},
167 {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
168 };
169
170 /**
171 * Unified eurephia field names for the 'lastlog' table
172 */
173 static eDBfieldMap eTblMap_lastlog[] = {
174 {TABLE_LASTLOG, NULL, FIELD_UID, ft_INT, flt_EQ, "uid", NULL, NULL},
175 {TABLE_LASTLOG, NULL, FIELD_CERTID, ft_INT, flt_EQ, "certid", NULL, NULL},
176 {TABLE_LASTLOG, NULL, FIELD_REMOTEIP, ft_STRING, flt_EQ, "ip", NULL, NULL},
177 {TABLE_LASTLOG, NULL, FIELD_VPNIP, ft_STRING, flt_EQ, "vpnip", NULL, NULL},
178 {TABLE_LASTLOG, NULL, FIELD_SESSTATUS, ft_STRING, flt_EQ, "status", NULL, NULL},
179 {TABLE_LASTLOG, NULL, FIELD_LOGIN, ft_DATETIME, flt_EQ, "login", NULL, NULL},
180 {TABLE_LASTLOG, NULL, FIELD_LOGOUT, ft_DATETIME, flt_EQ, "logout", NULL, NULL},
181 {TABLE_LASTLOG, NULL, FIELD_RECID, ft_INT, flt_EQ, "id", NULL, NULL},
182 {TABLE_LASTLOG, NULL, FIELD_UNAME, ft_STRING, flt_EQ, "username", NULL, NULL},
183 {TABLE_LASTLOG, NULL, FIELD_MACADDR, ft_STRING, flt_EQ, "macaddr", NULL, NULL},
184 {TABLE_LASTLOG, NULL, FIELD_UICID, ft_STRING, flt_EQ, "uicid", NULL, NULL},
185 {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
186 };
187
188 /**
189 * Unified eurephia field names for the 'attempts log' table
190 */
191 static eDBfieldMap eTblMap_attempts[] = {
192 {TABLE_ATTEMPTS, NULL, FIELD_UNAME, ft_STRING , flt_EQ, "username", NULL, NULL},
193 {TABLE_ATTEMPTS, NULL, FIELD_REMOTEIP, ft_STRING , flt_EQ, "ip", NULL, NULL},
194 {TABLE_ATTEMPTS, NULL, FIELD_CERTDIGEST, ft_STRING_LOWER, flt_EQ, "digest", NULL, NULL},
195 {TABLE_ATTEMPTS, NULL, FIELD_ATTEMPTS, ft_INT , flt_EQ, "attempts", NULL, NULL},
196 {TABLE_ATTEMPTS, NULL, FIELD_REGISTERED, ft_DATETIME , flt_EQ, "registered", NULL, NULL},
197 {TABLE_ATTEMPTS, NULL, FIELD_LASTATTEMPT, ft_DATETIME , flt_EQ, "lastattempt", NULL, NULL},
198 {TABLE_ATTEMPTS, NULL, FIELD_RECID, ft_INT , flt_EQ, "id", NULL, NULL },
199 {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
200 };
201
202
203 /**
204 * Unified eurephia field names for the 'blacklist' table
205 */
206 static eDBfieldMap eTblMap_blacklist[] = {
207 {TABLE_BLACKLIST, NULL, FIELD_UNAME, ft_STRING , flt_EQ, "username", NULL, NULL},
208 {TABLE_BLACKLIST, NULL, FIELD_REMOTEIP, ft_STRING , flt_EQ, "ip", NULL, NULL},
209 {TABLE_BLACKLIST, NULL, FIELD_CERTDIGEST, ft_STRING_LOWER, flt_EQ, "digest", NULL, NULL},
210 {TABLE_BLACKLIST, NULL, FIELD_REGISTERED, ft_DATETIME , flt_EQ, "registered", NULL, NULL},
211 {TABLE_BLACKLIST, NULL, FIELD_LASTACCESS, ft_DATETIME , flt_EQ, "lastaccessed", NULL, NULL},
212 {TABLE_BLACKLIST, NULL, FIELD_RECID, ft_INT , flt_EQ, "id", NULL, NULL},
213 {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
214 };
215
216
217 /**
218 * Unified eurephia field names for the 'usercerts' table
219 */
220 static eDBfieldMap eTblMap_usercerts[] = {
221 {TABLE_USERCERTS, NULL, FIELD_UID, ft_INT, flt_EQ, "uid", NULL, NULL},
222 {TABLE_USERCERTS, NULL, FIELD_CERTID, ft_INT, flt_EQ, "certid", NULL, NULL},
223 {TABLE_USERCERTS, NULL, FIELD_ACCPROFILE, ft_INT, flt_EQ, "accessprofile", NULL, NULL},
224 {TABLE_USERCERTS, NULL, FIELD_REGISTERED, ft_INT, flt_EQ, "registered", NULL, NULL},
225 {TABLE_USERCERTS, NULL, FIELD_RECID, ft_INT, flt_EQ, "uicid", NULL, NULL},
226 {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
227 };
228
229
230 /**
231 * Unified eurephia field names for the 'eurephia_adminaccess' table
232 */
233 static eDBfieldMap eTblMap_eurephiaadmacc[] = {
234 {TABLE_EUREPHIAADMACC, NULL, FIELD_UID, ft_INT, flt_EQ, "uid", NULL, NULL},
235 {TABLE_EUREPHIAADMACC, NULL, FIELD_INTERFACE, ft_STRING, flt_EQ, "interface", NULL, NULL},
236 {TABLE_EUREPHIAADMACC, NULL, FIELD_ACCESSLVL, ft_STRING, flt_EQ, "accesslevel", NULL, NULL},
237 {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
238 };
239
240 /**
241 * Unified eurephia field names for the 'accessprofiles' table
242 */
243 static eDBfieldMap eTblMap_fwprofiles[] = {
244 {TABLE_FWPROFILES, NULL, FIELD_DESCR, ft_STRING , flt_EQ, "description", NULL, NULL},
245 {TABLE_FWPROFILES, NULL, FIELD_FWPROFILE, ft_STRING , flt_EQ, "fwprofile", NULL, NULL},
246 {TABLE_FWPROFILES, NULL, FIELD_RECID, ft_INT , flt_EQ, "accessprofile", NULL, NULL},
247 {TABLE_FWPROFILES, NULL, FIELD_UID, ft_INT , flt_EQ, "uid", NULL, NULL},
248 {TABLE_FWPROFILES, NULL, FIELD_UNAME, ft_STRING , flt_EQ, "username", NULL, NULL},
249 {TABLE_FWPROFILES, NULL, FIELD_CERTID, ft_INT , flt_EQ, "certid", NULL, NULL},
250 {TABLE_FWPROFILES, NULL, FIELD_CNAME, ft_STRING , flt_EQ, "cname", NULL, NULL},
251 {TABLE_FWPROFILES, NULL, FIELD_ORG, ft_STRING , flt_EQ, "org", NULL, NULL},
252 {TABLE_FWPROFILES, NULL, FIELD_EMAIL, ft_STRING , flt_EQ, "email", NULL, NULL},
253 {TABLE_FWPROFILES, NULL, FIELD_CERTDIGEST, ft_STRING_LOWER, flt_EQ, "digest", NULL, NULL},
254 {TABLE_FWPROFILES, NULL, FIELD_REGISTERED, ft_DATETIME, flt_EQ, "registered", NULL, NULL},
255 {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
256 };
257
258 #endif // #ifdef EUREPHIADB_MAPPING_C
259
260 #ifdef HAVE_LIBXML2
261 #include <libxml/tree.h>
262
263 void eDBfreeMapping(eDBfieldMap *p);
264 eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tblalias, xmlNode *fmap_n);
265 const char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str);
266 long int eDBmappingFieldsPresent(eDBfieldMap *map);
267 const char *eDBmappingGetValue(eDBfieldMap *map, long field_id);
268
269 #endif // HAVE_LIBXML2
270 #endif // !EUREPHIADB_MAPPING_H