new mdb-array.c and changes to data.c (Karl)

database password stuff from (Carl)
multiple backend support (Carl and Brian)
This commit is contained in:
brianb
2000-04-02 17:08:30 +00:00
parent 418d57bc0c
commit c12b9ec987
20 changed files with 352 additions and 43 deletions

View File

@@ -20,7 +20,7 @@ INSTALL= @INSTALL@
LIBLIST = libmdb.a
INC = -I ../include `glib-config --cflags`
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o backend.o
all: libmdb

View File

@@ -20,7 +20,7 @@ INSTALL= @INSTALL@
LIBLIST = libmdb.a
INC = -I ../include `glib-config --cflags`
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o backend.o
all: libmdb

128
src/libmdb/backend.c Normal file
View File

@@ -0,0 +1,128 @@
/* MDB Tools - A library for reading MS Access database files
* Copyright (C) 2000 Brian Bruns
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
** functions to deal with different backend database engines
*/
#include "mdbtools.h"
/* Access data types */
char *mdb_access_types[] =
{"Unknown 0x00",
"Boolean",
"Byte",
"Integer",
"Long Integer",
"Currency",
"Single",
"Double",
"DateTime (Short)",
"Unknown 0x09",
"Text",
"OLE",
"Memo/Hyperlink",
"Unknown 0x0d",
"Unknown 0x0e",
"Replication ID"};
/* Oracle data types */
char *mdb_oracle_types[] =
{"Oracle_Unknown 0x00",
"CHAR",
"NUMBER",
"NUMBER",
"NUMBER",
"NUMBER",
"NUMBER",
"NUMBER",
"DATE",
"Oracle_Unknown 0x09",
"VARCHAR2",
"BLOB",
"BLOB",
"Oracle_Unknown 0x0d",
"Oracle_Unknown 0x0e",
"NUMBER"};
/* Sybase/MSSQL data types */
char *mdb_sybase_types[] =
{"Sybase_Unknown 0x00",
"bit",
"char",
"smallint",
"int",
"money",
"real",
"float",
"smalldatetime",
"Sybase_Unknown 0x09",
"varchar",
"varbinary",
"text",
"Sybase_Unknown 0x0d",
"Sybase_Unknown 0x0e",
"Sybase_Replication ID"};
char *mdb_get_coltype_string(MdbBackend *backend, int col_type)
{
if (col_type > 0x0f) {
return NULL;
} else {
return backend->types_table[col_type];
}
}
/*
** mdb_init_backends() initializes the mdb_backends hash and loads the builtin
** backends
*/
void mdb_init_backends()
{
MdbBackend *backend;
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
backend->types_table = mdb_access_types;
mdb_register_backend(backend, "access");
backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
backend->types_table = mdb_sybase_types;
mdb_register_backend(backend, "sybase");
backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
backend->types_table = mdb_oracle_types;
mdb_register_backend(backend, "oracle");
}
void mdb_register_backend(MdbBackend *backend, char *backend_name)
{
g_hash_table_insert(mdb_backends,backend_name,backend);
}
int mdb_set_default_backend(MdbHandle *mdb, char *backend_name)
{
MdbBackend *backend;
backend = (MdbBackend *) g_hash_table_lookup(mdb_backends, backend_name);
if (backend) {
mdb->default_backend = backend;
return 1;
} else {
return 0;
}
}

View File

@@ -258,14 +258,14 @@ static char text[256];
break;
case MDB_TEXT:
if (size<0) {
return "(oops)";
return "";
}
strncpy(text, &mdb->pg_buf[start], size);
text[size]='\0';
return text;
case MDB_MEMO:
if (size<MDB_MEMO_OVERHEAD) {
return "(oops)";
return "";
}
strncpy(text, &mdb->pg_buf[start + MDB_MEMO_OVERHEAD],
size - MDB_MEMO_OVERHEAD);

View File

@@ -22,6 +22,8 @@
MdbHandle *mdb_open(char *filename)
{
MdbHandle *mdb;
int key[] = {0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13, 0xb6};
int j,pos;
mdb = mdb_alloc_handle();
mdb->filename = (char *) malloc(strlen(filename)+1);
@@ -47,6 +49,17 @@ MdbHandle *mdb;
mdb->db_key = mdb_get_int32(mdb, 0x3e);
mdb->db_key ^= 0xe15e01b9;
/* get the db password located at 0x42 bytes into the file */
for (pos=0;pos<14;pos++) {
j = mdb_get_int32(mdb,0x42+pos);
j ^= key[pos];
if ( j != 0)
mdb->db_passwd[pos] = j;
else
mdb->db_passwd[pos] = '\0';
}
return mdb;
}

View File

@@ -19,6 +19,17 @@
#include "mdbtools.h"
void mdb_init()
{
mdb_init_backends();
}
void mdb_exit()
{
/* FIX ME -- need to deallocate backend structures */
g_hash_table_destroy(mdb_backends);
}
MdbHandle *mdb_alloc_handle()
{
MdbHandle *mdb;
@@ -26,6 +37,7 @@ MdbHandle *mdb;
mdb = (MdbHandle *) malloc(sizeof(MdbHandle));
memset(mdb, '\0', sizeof(MdbHandle));
mdb->pg_size = MDB_PGSIZE;
mdb_set_default_backend(mdb, "access");
return mdb;
}

View File

@@ -20,38 +20,6 @@
#include "mdbtools.h"
char *mdb_get_coltype_string(int col_type)
{
/*
** These are the Access datatype names, each backend will have to provide
** its own mapping.
*/
static char *type_name[] = {"Unknown 0x00",
"Boolean",
"Byte",
"Integer",
"Long Integer",
"Currency",
"Single",
"Double",
"DateTime (Short)",
"Unknown 0x09",
"Text",
"OLE",
"Memo/Hyperlink",
"Unknown 0x0d",
"Unknown 0x0e",
"Replication ID"
};
if (col_type > 0x0f) {
return NULL;
} else {
return type_name[col_type];
}
}
unsigned char mdb_col_needs_size(int col_type)
{
if (col_type == MDB_TEXT) {
@@ -137,7 +105,7 @@ int i;
fprintf(stdout,"column %d Name: %-20s Type: %s(%d)\n",
i, col->name,
mdb_get_coltype_string(col->col_type),
mdb_get_coltype_string(mdb->default_backend, col->col_type),
col->col_size);
}
}