summaryrefslogtreecommitdiffstats
path: root/database/eurephiadb_mapping.h
blob: 4421c6898f7803c0ef41385b0e93e49bfd1357f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* eurephiadb_mapping.h  -- eurephiaDB table/field mapping
 *                          This mapping system, makes it possible
 *                          to access specific database table fields
 *                          through a unified API
 *
 *  GPLv2 only - Copyright (C) 2008, 2009
 *               David Sommerseth <dazo@users.sourceforge.net>
 *
 *  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.
 *
 */

#ifndef   	EUREPHIADB_MAPPING_H
# define   	EUREPHIADB_MAPPING_H

typedef enum eDBfieldType_e { ft_UNDEF, ft_INT, ft_STRING, ft_DATETIME, ft_PASSWD, ft_SETNULL } eDBfieldType;
typedef enum eDBfieldFilterType_e { flt_NOTSET, flt_EQ, flt_NEQ, flt_LT, flt_LTE, flt_GT, flt_GTE } eDBfieldFilterType;

typedef struct _eDBfieldMap_s {
        int tableid;
        char *table_alias;
        long field_id;
        eDBfieldType field_type;
        eDBfieldFilterType filter_type;
        char *field_name;
        char *value;
        struct _eDBfieldMap_s *next;
} eDBfieldMap;

extern const char *SESSION_STATUS[];

#define TABLE_USERS          0x01
#define TABLE_CERTS          0x02
#define TABLE_USERCERTS      0x03
#define TABLE_LASTLOG        0x04
#define TABLE_ATTEMPTS       0x05
#define TABLE_BLACKLIST      0x06
#define TABLE_EUREPHIAADMACC 0x07
#define TABLE_FWPROFILES     0x08

#define FIELD_NONE        0x0000000
#define FIELD_RECID       0x0000001  // Primary keys
#define FIELD_UID         0x0000002
#define FIELD_CERTID      0x0000004
#define FIELD_UNAME       0x0000008
#define FIELD_ACTIVATED   0x0000010
#define FIELD_DEACTIVATED 0x0000020
#define FIELD_LASTACCESS  0x0000040

#define FIELD_CERTDEPTH   0x0000080
#define FIELD_CNAME       0x0000100
#define FIELD_EMAIL       0x0000200
#define FIELD_ORG         0x0000400
#define FIELD_REGISTERED  0x0000800

#define FIELD_REMOTEIP    0x0001000
#define FIELD_VPNIP       0x0002000
#define FIELD_ATTEMPTS    0x0004000
#define FIELD_LASTATTEMPT 0x0008000

#define FIELD_SESSTATUS   0x0010000
#define FIELD_LOGIN       0x0020000
#define FIELD_LOGOUT      0x0040000
#define FIELD_PASSWD      0x0080000
#define FIELD_CERTDIGEST  0x0100000

#define FIELD_ACCPROFILE  0x0200000

#define FIELD_INTERFACE   0x0400000
#define FIELD_ACCESSLVL   0x0800000

#define FIELD_MACADDR     0x1000000
#define FIELD_UICID       0x2000000

#define FIELD_DESCR       0x4000000
#define FIELD_FWPROFILE   0x8000000


#ifdef EUREPHIADB_MAPPING_C

static eDBfieldMap eTblMap_user[] = {
        {TABLE_USERS, NULL, FIELD_RECID,       ft_INT,      flt_EQ, "uid",         NULL, NULL},
        {TABLE_USERS, NULL, FIELD_UNAME,       ft_STRING,   flt_EQ, "username",    NULL, NULL},
        {TABLE_USERS, NULL, FIELD_PASSWD,      ft_PASSWD,   flt_EQ, "password",    NULL, NULL},
        {TABLE_USERS, NULL, FIELD_ACTIVATED,   ft_DATETIME, flt_EQ, "activated",   NULL, NULL},
        {TABLE_USERS, NULL, FIELD_DEACTIVATED, ft_DATETIME, flt_EQ, "deactivated", NULL, NULL},
        {TABLE_USERS, NULL, FIELD_LASTACCESS,  ft_DATETIME, flt_EQ, "lastaccess",  NULL, NULL},
        {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_certificates[] = {
        {TABLE_CERTS, NULL, FIELD_RECID,       ft_INT,      flt_EQ, "certid",      NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_CERTDEPTH,   ft_INT,      flt_EQ, "depth",       NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_CERTDIGEST,  ft_STRING,   flt_EQ, "digest",      NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_CNAME,       ft_STRING,   flt_EQ, "cname",       NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_ORG,         ft_STRING,   flt_EQ, "org",         NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_EMAIL,       ft_STRING,   flt_EQ, "email",       NULL, NULL},
        {TABLE_CERTS, NULL, FIELD_REGISTERED,  ft_DATETIME, flt_EQ, "registered",  NULL, NULL},
        {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_lastlog[] = {
        {TABLE_LASTLOG, NULL, FIELD_UID,         ft_INT,      flt_EQ, "uid",       NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_CERTID,      ft_INT,      flt_EQ, "certid",    NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_REMOTEIP,    ft_STRING,   flt_EQ, "ip",        NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_VPNIP,       ft_STRING,   flt_EQ, "vpnip",     NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_SESSTATUS,   ft_STRING,   flt_EQ, "status",    NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_LOGIN,       ft_DATETIME, flt_EQ, "login",     NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_LOGOUT,      ft_DATETIME, flt_EQ, "logout",    NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_RECID,       ft_INT,      flt_EQ, "id",        NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_UNAME,       ft_STRING,   flt_EQ, "username",  NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_MACADDR,     ft_STRING,   flt_EQ, "macaddr",   NULL, NULL},
        {TABLE_LASTLOG, NULL, FIELD_UICID,       ft_STRING,   flt_EQ, "uicid",     NULL, NULL},
        {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_attempts[] = {
        {TABLE_ATTEMPTS, NULL, FIELD_UNAME,       ft_STRING,   flt_EQ, "username",    NULL, NULL},
        {TABLE_ATTEMPTS, NULL, FIELD_REMOTEIP,    ft_STRING,   flt_EQ, "ip",          NULL, NULL},
        {TABLE_ATTEMPTS, NULL, FIELD_ATTEMPTS,    ft_INT,      flt_EQ, "attempts",    NULL, NULL},
        {TABLE_ATTEMPTS, NULL, FIELD_REGISTERED,  ft_DATETIME, flt_EQ, "registered",  NULL, NULL},
        {TABLE_ATTEMPTS, NULL, FIELD_LASTATTEMPT, ft_DATETIME, flt_EQ, "lastattempt", NULL, NULL},
        {TABLE_ATTEMPTS, NULL, FIELD_RECID,       ft_INT,      flt_EQ, "id",          NULL, NULL },
        {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_blacklist[] = {
        {TABLE_BLACKLIST, NULL, FIELD_UNAME,       ft_STRING,   flt_EQ, "username",     NULL, NULL},
        {TABLE_BLACKLIST, NULL, FIELD_REMOTEIP,    ft_STRING,   flt_EQ, "ip",           NULL, NULL},
        {TABLE_BLACKLIST, NULL, FIELD_REGISTERED,  ft_DATETIME, flt_EQ, "registered",   NULL, NULL},
        {TABLE_BLACKLIST, NULL, FIELD_LASTACCESS,  ft_DATETIME, flt_EQ, "lastattempt",  NULL, NULL},
        {TABLE_BLACKLIST, NULL, FIELD_LASTACCESS,  ft_DATETIME, flt_EQ, "lastaccessed", NULL, NULL},
        {TABLE_BLACKLIST, NULL, FIELD_RECID,       ft_INT,      flt_EQ, "id",           NULL, NULL},
        {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_usercerts[] = {
        {TABLE_USERCERTS, NULL, FIELD_UID,        ft_INT, flt_EQ,  "uid",            NULL, NULL},
        {TABLE_USERCERTS, NULL, FIELD_CERTID,     ft_INT, flt_EQ,  "certid",         NULL, NULL},
        {TABLE_USERCERTS, NULL, FIELD_ACCPROFILE, ft_INT, flt_EQ,  "accessprofile",  NULL, NULL},
        {TABLE_USERCERTS, NULL, FIELD_REGISTERED, ft_INT, flt_EQ,  "registered",     NULL, NULL},
        {TABLE_USERCERTS, NULL, FIELD_RECID,      ft_INT, flt_EQ,  "uicid",          NULL, NULL},
        {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_eurephiaadmacc[] = {
        {TABLE_EUREPHIAADMACC, NULL, FIELD_UID,       ft_INT,    flt_EQ, "uid",           NULL, NULL},
        {TABLE_EUREPHIAADMACC, NULL, FIELD_INTERFACE, ft_STRING, flt_EQ, "interface",     NULL, NULL},
        {TABLE_EUREPHIAADMACC, NULL, FIELD_ACCESSLVL, ft_STRING, flt_EQ, "accesslevel",   NULL, NULL},
        {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

static eDBfieldMap eTblMap_fwprofiles[] = {
        {TABLE_FWPROFILES,   NULL,     FIELD_DESCR,      ft_STRING  , flt_EQ, "description",   NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_FWPROFILE,  ft_STRING  , flt_EQ, "fwprofile",     NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_RECID,      ft_INT     , flt_EQ, "accessprofile", NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_UID,        ft_INT     , flt_EQ, "uid",           NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_UNAME,      ft_STRING  , flt_EQ, "username",      NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_CERTID,     ft_INT     , flt_EQ, "certid",        NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_CNAME,      ft_STRING  , flt_EQ, "cname",         NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_ORG,        ft_STRING  , flt_EQ, "org",           NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_EMAIL,      ft_STRING  , flt_EQ, "email",         NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_CERTDIGEST, ft_STRING  , flt_EQ, "digest",        NULL, NULL},
        {TABLE_FWPROFILES,   NULL,     FIELD_REGISTERED, ft_DATETIME, flt_EQ, "registered",    NULL, NULL},
        {0, NULL, FIELD_NONE, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
};

#endif // #ifdef EUREPHIADB_MAPPING_C

#ifdef HAVE_LIBXML2
#include <libxml/tree.h>

void eDBfreeMapping(eDBfieldMap *p);
eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tblalias, xmlNode *fmap_n);
char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str);
long int eDBmappingFieldsPresent(eDBfieldMap *map);

#endif      // HAVE_LIBXML2
#endif 	    // !EUREPHIADB_MAPPING_H