summaryrefslogtreecommitdiffstats
path: root/database/eurephiadb_mapping.h
blob: 6168a0a026a73c0b9afa996b39e82037e1db16d6 (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
/* eurephiadb_mapping.h  -- eurephiaDB table/field mapping
 *                          This mapping system, makes it possible
 *                          to access specific database table fields
 *                          through a unified API
 *
 *  GPLv2 - Copyright (C) 2008  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

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


typedef enum eDBfieldType_e { ft_UNDEF, ft_INT, ft_STRING, ft_DATETIME, ft_PASSWD, ft_SETNULL } eDBfieldType;

typedef struct _eDBfieldMap_s {
        int tableid;
        char *table_alias;
        long field_id;
        eDBfieldType field_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_LASTLOG       0x03
#define TABLE_ATTEMPTS      0x04
#define TABLE_BLACKLIST     0x05

#define FIELD_NONE        0x000000
#define FIELD_RECID       0x000001  // Primary keys
#define FIELD_UID         0x000002
#define FIELD_CERTID      0x000004
#define FIELD_UNAME       0x000008
#define FIELD_ACTIVATED   0x000010
#define FIELD_DEACTIVATED 0x000020
#define FIELD_LASTACCESS  0x000040

#define FIELD_CERTDEPTH   0x000080
#define FIELD_CNAME       0x000100
#define FIELD_EMAIL       0x000200
#define FIELD_ORG         0x000400
#define FIELD_REGISTERED  0x000800

#define FIELD_REMOTEIP    0x001000
#define FIELD_VPNIP       0x002000
#define FIELD_ATTEMPTS    0x004000
#define FIELD_LASTATTEMPT 0x008000

#define FIELD_SESSTATUS   0x010000
#define FIELD_LOGIN       0x020000
#define FIELD_LOGOUT      0x040000
#define FIELD_PASSWD      0x080000
#define FIELD_CERTDIGEST  0x100000

#ifdef EUREPHIADB_MAPPING_C

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

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

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

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

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

#endif // #ifdef EUREPHIADB_MAPPING_C

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

#endif
#endif 	    // !EUREPHIADB_MAPPING_H