1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh
20
* Continued development: Barry Leslie
26
* Contains the information about a table.
31
#ifndef __TABLE_MS_H__
32
#define __TABLE_MS_H__
36
#define MS_TABLE_FILE_MAGIC 0x1234ABCD
37
#define MS_TABLE_FILE_VERSION 1
38
#define MS_TABLE_FILE_HEAD_SIZE 128
42
class CSHTTPOutputStream;
44
typedef struct MSTableHead {
45
CSDiskValue4 th_magic_4; /* Table magic number. */
46
CSDiskValue2 th_version_2; /* The header version. */
47
CSDiskValue2 th_head_size_2; /* The size of the header. */
48
CSDiskValue8 th_free_list_8;
50
/* These 3 fields are written together by prepareToDelete()! */
51
CSDiskValue4 th_del_time_4; /* The time this table was deleted. */
52
CSDiskValue4 th_temp_log_id_4; /* The temp log entry for this deleted table. */
53
CSDiskValue4 th_temp_log_offset_4;
55
CSDiskValue4 th_reserved_4;
56
} MSTableHeadRec, *MSTableHeadPtr;
58
/* File offset = th_size_4 + (Blob ID - 1) * sizeof(MSTableBlobRec) */
59
typedef struct MSTableBlob {
60
CSDiskValue1 tb_status_1; /* 0 = free, 1 = inuse*/
62
/* These 3 fields are written together: */
63
CSDiskValue3 tb_repo_id_3; /* File ID (non-zero). */
64
CSDiskValue6 tb_offset_6; /* Offset into the file of the BLOB. */
65
CSDiskValue2 tb_header_size_2; /* Size of the header section of the blob. */
67
CSDiskValue6 tb_size_6; /* Size of the BLOB data. (Where ever it may be stored.) */
68
CSDiskValue4 tb_auth_code_4; /* BLOB authorisation code. */
69
} MSTableBlobRec, *MSTableBlobPtr;
71
typedef struct MSTableFreeBlob {
72
CSDiskValue4 tf_null_4; /* Set to zero */
73
CSDiskValue6 tf_next_6; /* Next record in the free list. */
74
} MSTableFreeBlobRec, *MSTableFreeBlobPtr;
76
class MSTable : public CSSharedRefObject {
78
CSString *myTableName;
80
MSDatabase *myDatabase;
85
CSPath *getTableFile(const char *table_name, bool to_delete);
87
CSPath *getTableFile();
89
CSFile *openTableFile();
91
void prepareToDelete();
93
uint64_t createBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
95
uint64_t findBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
97
void setBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
99
void updateBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t offset, uint16_t head_size);
101
bool readBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t *auth_code, uint32_t *repo_id, uint64_t *offset, uint64_t *data_size, uint16_t *head_size, bool throw_error);
103
void freeBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint32_t auth_code);
105
/* Make this object hashable: */
106
virtual CSObject *getKey();
107
virtual int compareKey(CSObject *);
108
virtual uint32_t hashKey();
110
off64_t getTableFileSize() { return iTableFileSize; }
111
CSString *getTableName();
112
bool isToDelete() { return iToDelete; }
113
void getDeleteInfo(uint32_t *log, uint32_t *offs, time_t *tim);
114
bool isNoTable() { return myTableName->length() == 0; }
117
off64_t iTableFileSize;
118
size_t iTableHeadSize;
121
uint32_t iTabDeleteTime;
122
uint32_t iTabTempLogID;
123
uint32_t iTabTempLogOffset;
126
static MSTable *newTable(uint32_t tab_id, CSString *name, MSDatabase *db, off64_t file_size, bool to_delete);
128
static MSTable *newTable(uint32_t tab_id, const char *name, MSDatabase *db, off64_t file_size, bool to_delete);