summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-06 00:49:01 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-06 00:49:01 +0100
commit6d4373e026b3f12c5685e45e35f9f060379ed0f3 (patch)
tree864bd4074f8c795f593e0ed5c64bd7340b9bce50 /common
parentd0e5f69a3a84ee6ef7e774df7a5fc509620b42f8 (diff)
downloadeurephia-6d4373e026b3f12c5685e45e35f9f060379ed0f3.tar.gz
eurephia-6d4373e026b3f12c5685e45e35f9f060379ed0f3.tar.xz
eurephia-6d4373e026b3f12c5685e45e35f9f060379ed0f3.zip
Added eurephia_admin_common.[ch]
Will contain common functions for the administration API. At the moment only a generic function which converts unified field names to proper database field names is implemented. This functions is made especially for sorting keys (ORDER BY <fields>)
Diffstat (limited to 'common')
-rw-r--r--common/eurephia_admin_common.c94
-rw-r--r--common/eurephia_admin_common.h120
2 files changed, 214 insertions, 0 deletions
diff --git a/common/eurephia_admin_common.c b/common/eurephia_admin_common.c
new file mode 100644
index 0000000..7333408
--- /dev/null
+++ b/common/eurephia_admin_common.c
@@ -0,0 +1,94 @@
+/* eurephia_admin_common.c -- Common functions used for the admin 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.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <eurephia_nullsafe.h>
+
+#include "eurephia_admin_common.h"
+
+eFieldMap *eAdminGetTableMap(int table) {
+ eFieldMap *map;
+
+ switch( table ) {
+ case TABLE_USERS:
+ map = eSortkeys_user;
+ break;
+
+ case TABLE_CERTS:
+ map = eSortkeys_certificates;
+ break;
+
+ case TABLE_LASTLOG:
+ map = eSortkeys_lastlog;
+
+ case TABLE_ATTEMPTS:
+ map = eSortkeys_attempts;
+
+ case TABLE_BLACKLIST:
+ map = eSortkeys_blacklist;
+
+ default:
+ map = NULL;
+ }
+ return map;
+}
+
+
+char *eAdminConvertSortKeys(eFieldMap *tfmap, const char *skeys_str) {
+ eFieldMap *sk_map = NULL;
+ long sortmap = 0;
+ int i, j;
+ char *cp = NULL, *tok = NULL, *delims = ",";
+ static char sortkeys[8194];
+
+ // Make sure we have table field map
+ assert( tfmap != NULL );
+
+ // Get the correct table mapping for user input
+ sk_map = eAdminGetTableMap(tfmap[0].tableid);
+ assert( sk_map != NULL );
+
+ // Split up the skeys_str (sort keys string) and build up a map
+ cp = strdup(skeys_str);
+ tok = strtok(cp, delims);
+ memset(&sortkeys, 0, 8194);
+ while( tok != NULL ) {
+ for( i = 0; sk_map[i].fieldname != NULL; i++ ) {
+ // If we find the the field in the unified mapping table ...
+ if( strcmp(tok, sk_map[i].fieldname) == 0 ) {
+ // look up the proper field name for the current database
+ for( j = 0; tfmap[j].fieldname != 0; j++ ) {
+ if( (sk_map[i].sortkeyid & tfmap[j].sortkeyid) == sk_map[i].sortkeyid ) {
+ strncat(sortkeys, tfmap[j].fieldname, (8192-strlen(sortkeys)));
+ strcat(sortkeys,",");
+ }
+ }
+ }
+ }
+ tok = strtok(NULL, delims);
+ }
+ free_nullsafe(cp);
+ sortkeys[strlen(sortkeys)-1] = '\0';
+ return sortkeys;
+}
diff --git a/common/eurephia_admin_common.h b/common/eurephia_admin_common.h
new file mode 100644
index 0000000..7593e2e
--- /dev/null
+++ b/common/eurephia_admin_common.h
@@ -0,0 +1,120 @@
+/* eurephia_admin_common.h -- Common functions used for the admin 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 EUREPHIA_ADMIN_COMMON_H_
+# define EUREPHIA_ADMIN_COMMON_H_
+
+#define TABLE_USERS 0x01
+#define TABLE_CERTS 0x02
+#define TABLE_LASTLOG 0x03
+#define TABLE_ATTEMPTS 0x04
+#define TABLE_BLACKLIST 0x05
+
+#define SORTKEY_NONE 0x00000
+#define SORTKEY_RECID 0x00001 // Primary keys
+#define SORTKEY_UID 0x00002
+#define SORTKEY_CERTID 0x00004
+#define SORTKEY_UNAME 0x00008
+#define SORTKEY_ACTIVATED 0x00010
+#define SORTKEY_DEACTIVATED 0x00020
+#define SORTKEY_LASTACCESS 0x00040
+
+#define SORTKEY_CERTDEPTH 0x00080
+#define SORTKEY_CNAME 0x00100
+#define SORTKEY_EMAIL 0x00200
+#define SORTKEY_ORG 0x00400
+#define SORTKEY_REGISTERED 0x00800
+
+#define SORTKEY_REMOTEIP 0x01000
+#define SORTKEY_VPNIP 0x02000
+#define SORTKEY_ATTEMPTS 0x04000
+#define SORTKEY_LASTATTEMPT 0x08000
+
+#define SORTKEY_SESSTATUS 0x10000
+#define SORTKEY_LOGIN 0x20000
+#define SORTKEY_LOGOUT 0x40000
+
+
+typedef struct {
+ int tableid;
+ long sortkeyid;
+ char *fieldname;
+} eFieldMap;
+
+
+eFieldMap eSortkeys_user[] = {
+ {TABLE_USERS, SORTKEY_RECID, "recid"},
+ {TABLE_USERS, SORTKEY_RECID, "uid"},
+ {TABLE_USERS, SORTKEY_UNAME, "username"},
+ {TABLE_USERS, SORTKEY_ACTIVATED, "activated"},
+ {TABLE_USERS, SORTKEY_DEACTIVATED, "deactivated"},
+ {TABLE_USERS, SORTKEY_LASTACCESS, "lastaccess"},
+ {TABLE_USERS, SORTKEY_NONE, NULL}
+};
+
+eFieldMap eSortkeys_certificates[] = {
+ {TABLE_CERTS, SORTKEY_RECID, "recid"},
+ {TABLE_CERTS, SORTKEY_RECID, "certid"},
+ {TABLE_CERTS, SORTKEY_CERTDEPTH, "depth"},
+ {TABLE_CERTS, SORTKEY_CNAME, "name"},
+ {TABLE_CERTS, SORTKEY_ORG, "org"},
+ {TABLE_CERTS, SORTKEY_EMAIL, "email"},
+ {TABLE_CERTS, SORTKEY_REGISTERED, "registered"},
+ {TABLE_CERTS, SORTKEY_NONE, NULL}
+};
+
+eFieldMap eSortkeys_lastlog[] = {
+ {TABLE_LASTLOG, SORTKEY_UID, "uid"},
+ {TABLE_LASTLOG, SORTKEY_CERTID, "certid"},
+ {TABLE_LASTLOG, SORTKEY_REMOTEIP, "ip"},
+ {TABLE_LASTLOG, SORTKEY_VPNIP, "vpnip"},
+ {TABLE_LASTLOG, SORTKEY_SESSTATUS, "status"},
+ {TABLE_LASTLOG, SORTKEY_LOGIN, "login"},
+ {TABLE_LASTLOG, SORTKEY_LOGOUT, "logout"},
+ {TABLE_LASTLOG, SORTKEY_RECID, "recid"},
+ {TABLE_LASTLOG, SORTKEY_NONE, NULL}
+};
+
+eFieldMap eSortkeys_attempts[] = {
+ {TABLE_ATTEMPTS, SORTKEY_UNAME, "username"},
+ {TABLE_ATTEMPTS, SORTKEY_REMOTEIP, "ip"},
+ {TABLE_ATTEMPTS, SORTKEY_ATTEMPTS, "attempts"},
+ {TABLE_ATTEMPTS, SORTKEY_REGISTERED, "registered"},
+ {TABLE_ATTEMPTS, SORTKEY_LASTATTEMPT, "lastattempt"},
+ {TABLE_ATTEMPTS, SORTKEY_RECID, "recid"},
+ {TABLE_ATTEMPTS, SORTKEY_NONE, NULL}
+};
+
+eFieldMap eSortkeys_blacklist[] = {
+ {TABLE_BLACKLIST, SORTKEY_UNAME, "username"},
+ {TABLE_BLACKLIST, SORTKEY_REMOTEIP, "ip"},
+ {TABLE_BLACKLIST, SORTKEY_REGISTERED, "registered"},
+ {TABLE_BLACKLIST, SORTKEY_LASTACCESS, "lastattempt"},
+ {TABLE_BLACKLIST, SORTKEY_LASTACCESS, "lastaccessed"},
+ {TABLE_BLACKLIST, SORTKEY_RECID, "recid"},
+ {TABLE_BLACKLIST, SORTKEY_NONE, NULL}
+};
+
+
+eFieldMap *eAdminGetTableMap(int table);
+char *eAdminGetSortKey(int table, const char *str);
+
+
+#endif /* !EUREPHIA_ADMIN_COMMON_H_ */