diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-07 21:21:48 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-07 21:21:48 +0100 |
| commit | 90da20df8560d301d34d65d63d35ca3bc822bd53 (patch) | |
| tree | 4d42bfa4736e0d148fa9e5712e01ebd565e84288 /database | |
| parent | d1cbea949bf338528a6da4d047ecf62bfabe42bc (diff) | |
| download | eurephia-90da20df8560d301d34d65d63d35ca3bc822bd53.tar.gz eurephia-90da20df8560d301d34d65d63d35ca3bc822bd53.tar.xz eurephia-90da20df8560d301d34d65d63d35ca3bc822bd53.zip | |
Merged eurephiadb_common.[ch] into eurephiadb_mapping.[ch]
The functions in eurephiadb_common.[ch] was only adding functions
which was connected to the unified field mapping interface
Diffstat (limited to 'database')
| -rw-r--r-- | database/eurephiadb_common.c | 97 | ||||
| -rw-r--r-- | database/eurephiadb_common.h | 27 | ||||
| -rw-r--r-- | database/eurephiadb_mapping.c | 74 | ||||
| -rw-r--r-- | database/eurephiadb_mapping.h | 3 |
4 files changed, 76 insertions, 125 deletions
diff --git a/database/eurephiadb_common.c b/database/eurephiadb_common.c deleted file mode 100644 index fef9d15..0000000 --- a/database/eurephiadb_common.c +++ /dev/null @@ -1,97 +0,0 @@ -/* eurephiadb_common.c -- Common database functions, used by drivers - * - * 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_context.h> -#include <eurephiadb_mapping.h> -#include <eurephia_admin_struct.h> -#include <passwd.h> - -eDBfieldMap *eDBprepareFieldMap(eurephiaCTX *ctx, int table, long fields[]) { - eDBfieldMap *map = NULL, *ptr = NULL; - int i = 0; - - for( i = 0; fields[i] != FIELD_NONE; i++ ) { - ptr = (eDBfieldMap *) malloc(sizeof(eDBfieldMap)+2); - memset(ptr, 0, sizeof(eDBfieldMap)+2); - - ptr->tableid = table; - ptr->field_id = fields[i]; - ptr->field_name = NULL; - ptr->value = NULL; - - ptr->next = map; - map = ptr; - } - return map; -} - - -void eDBfreeMapping(eDBfieldMap *p) { - if( p == NULL ) { - return; - } - eDBfreeMapping(p->next); - - // Release value and this pointer. - // Do not attempt to release field_name, as it is a constant char * - free_nullsafe(p->value); - free(p); -} - - -eDBfieldMap *eDBmkMapping_USERINFO(eurephiaCTX *ctx, eDBfieldMap *dbmap, eurephiaUSERINFO *user) { - eDBfieldMap *map = NULL, *ptr = NULL; - char *uid_str = NULL; - long fields[] = {FIELD_LASTACCESS, FIELD_DEACTIVATED, FIELD_ACTIVATED, - FIELD_PASSWD, FIELD_UNAME, FIELD_RECID, FIELD_NONE}; - - map = eDBprepareFieldMap(ctx, TABLE_USERS, fields); - assert( map != NULL ); - - // Convert uid from int to char * - if( user->uid != 0 ) { - uid_str = (char *) malloc(33); - snprintf(uid_str, 32, "%i%c", user->uid, 0); - } else { - uid_str = NULL; - } - - for( ptr = map; ptr != NULL; ptr = ptr->next ) { - // Copy over field name - translated via the db mapping table - ptr->field_name = eDBgetTableField(dbmap, ptr->field_id); - - // Copy over values - switch( ptr->field_id ) { - case FIELD_RECID: ptr->value = uid_str; break; - case FIELD_UNAME: ptr->value = strdup_nullsafe(user->username); break; - case FIELD_PASSWD: ptr->value = passwdhash(user->password); break; - case FIELD_ACTIVATED: ptr->value = strdup_nullsafe(user->activated); break; - case FIELD_DEACTIVATED: ptr->value = strdup_nullsafe(user->deactivated); break; - case FIELD_LASTACCESS: ptr->value = strdup_nullsafe(user->last_accessed); break; - } - } - return map; -} diff --git a/database/eurephiadb_common.h b/database/eurephiadb_common.h deleted file mode 100644 index 969fd1a..0000000 --- a/database/eurephiadb_common.h +++ /dev/null @@ -1,27 +0,0 @@ -/* eurephiadb_common.h -- - * - * 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_COMMON_H_ -# define EUREPHIADB_COMMON_H_ - -void eDBfreeMapping(eDBfieldMap *p); -eDBfieldMap *eDBmkMapping_USERINFO(eurephiaCTX *ctx, eDBfieldMap *dbmap, eurephiaUSERINFO *user); - -#endif /* !EUREPHIADB_COMMON_H_ */ diff --git a/database/eurephiadb_mapping.c b/database/eurephiadb_mapping.c index a12a863..be2123c 100644 --- a/database/eurephiadb_mapping.c +++ b/database/eurephiadb_mapping.c @@ -24,8 +24,45 @@ #include <assert.h> #define EUREPHIADB_MAPPING_C +#include <eurephia_context.h> +#include <eurephia_admin_struct.h> #include <eurephiadb_mapping.h> #include <eurephia_nullsafe.h> +#include <passwd.h> + + +eDBfieldMap *eDBprepareFieldMap(eurephiaCTX *ctx, int table, long fields[]) { + eDBfieldMap *map = NULL, *ptr = NULL; + int i = 0; + + for( i = 0; fields[i] != FIELD_NONE; i++ ) { + ptr = (eDBfieldMap *) malloc(sizeof(eDBfieldMap)+2); + memset(ptr, 0, sizeof(eDBfieldMap)+2); + + ptr->tableid = table; + ptr->field_id = fields[i]; + ptr->field_name = NULL; + ptr->value = NULL; + + ptr->next = map; + map = ptr; + } + return map; +} + + +void eDBfreeMapping(eDBfieldMap *p) { + if( p == NULL ) { + return; + } + eDBfreeMapping(p->next); + + // Release value and this pointer. + // Do not attempt to release field_name, as it is a constant char * + free_nullsafe(p->value); + free(p); +} + eDBfieldMap *eDBgetTableFieldMapping(int table) { eDBfieldMap *map; @@ -54,6 +91,7 @@ eDBfieldMap *eDBgetTableFieldMapping(int table) { return map; } + char *eDBgetTableField(eDBfieldMap *dbmap, int field) { int i = 0; @@ -65,6 +103,42 @@ char *eDBgetTableField(eDBfieldMap *dbmap, int field) { return NULL; } + +eDBfieldMap *eDBmkMapping_USERINFO(eurephiaCTX *ctx, eDBfieldMap *dbmap, eurephiaUSERINFO *user) { + eDBfieldMap *map = NULL, *ptr = NULL; + char *uid_str = NULL; + long fields[] = {FIELD_LASTACCESS, FIELD_DEACTIVATED, FIELD_ACTIVATED, + FIELD_PASSWD, FIELD_UNAME, FIELD_RECID, FIELD_NONE}; + + map = eDBprepareFieldMap(ctx, TABLE_USERS, fields); + assert( map != NULL ); + + // Convert uid from int to char * + if( user->uid != 0 ) { + uid_str = (char *) malloc(33); + snprintf(uid_str, 32, "%i%c", user->uid, 0); + } else { + uid_str = NULL; + } + + for( ptr = map; ptr != NULL; ptr = ptr->next ) { + // Copy over field name - translated via the db mapping table + ptr->field_name = eDBgetTableField(dbmap, ptr->field_id); + + // Copy over values + switch( ptr->field_id ) { + case FIELD_RECID: ptr->value = uid_str; break; + case FIELD_UNAME: ptr->value = strdup_nullsafe(user->username); break; + case FIELD_PASSWD: ptr->value = passwdhash(user->password); break; + case FIELD_ACTIVATED: ptr->value = strdup_nullsafe(user->activated); break; + case FIELD_DEACTIVATED: ptr->value = strdup_nullsafe(user->deactivated); break; + case FIELD_LASTACCESS: ptr->value = strdup_nullsafe(user->last_accessed); break; + } + } + return map; +} + + char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str) { eDBfieldMap *sk_map = NULL; int i, j; diff --git a/database/eurephiadb_mapping.h b/database/eurephiadb_mapping.h index 2f88d60..da4dcc5 100644 --- a/database/eurephiadb_mapping.h +++ b/database/eurephiadb_mapping.h @@ -121,7 +121,8 @@ static eDBfieldMap eTblMap_blacklist[] = { #endif // #ifdef EUREPHIADB_MAPPING_C -char *eDBgetTableField(eDBfieldMap *dbmap, int field); +void eDBfreeMapping(eDBfieldMap *p); +eDBfieldMap *eDBmkMapping_USERINFO(eurephiaCTX *ctx, eDBfieldMap *dbmap, eurephiaUSERINFO *user); char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str); #endif // !EUREPHIADB_MAPPING_H |
