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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh
20
* Continued development: Barry Leslie
26
* Contains the information about a table.
30
#ifndef __TABLE_MS_H__
31
#define __TABLE_MS_H__
35
#define MS_TABLE_FILE_MAGIC 0x1234ABCD
36
#define MS_TABLE_FILE_VERSION 1
37
#define MS_TABLE_FILE_HEAD_SIZE 128
41
class CSHTTPOutputStream;
43
typedef struct MSTableHead {
44
CSDiskValue4 th_magic_4; /* Table magic number. */
45
CSDiskValue2 th_version_2; /* The header version. */
46
CSDiskValue2 th_head_size_2; /* The size of the header. */
47
CSDiskValue8 th_free_list_8;
49
/* These 3 fields are written together by prepareToDelete()! */
50
CSDiskValue4 th_del_time_4; /* The time this table was deleted. */
51
CSDiskValue4 th_temp_log_id_4; /* The temp log entry for this deleted table. */
52
CSDiskValue4 th_temp_log_offset_4;
54
CSDiskValue4 th_reserved_4;
55
} MSTableHeadRec, *MSTableHeadPtr;
57
/* File offset = th_size_4 + (Blob ID - 1) * sizeof(MSTableBlobRec) */
58
typedef struct MSTableBlob {
59
CSDiskValue1 tb_status_1; /* 0 = free, 1 = inuse*/
61
/* These 3 fields are written together: */
62
CSDiskValue3 tb_repo_id_3; /* File ID (non-zero). */
63
CSDiskValue6 tb_offset_6; /* Offset into the file of the BLOB. */
64
CSDiskValue2 tb_header_size_2; /* Size of the header section of the blob. */
66
CSDiskValue6 tb_size_6; /* Size of the BLOB data. (Where ever it may be stored.) */
67
CSDiskValue4 tb_auth_code_4; /* BLOB authorisation code. */
68
} MSTableBlobRec, *MSTableBlobPtr;
70
typedef struct MSTableFreeBlob {
71
CSDiskValue4 tf_null_4; /* Set to zero */
72
CSDiskValue6 tf_next_6; /* Next record in the free list. */
73
} MSTableFreeBlobRec, *MSTableFreeBlobPtr;
75
class MSTable : public CSSharedRefObject {
77
CSString *myTableName;
79
MSDatabase *myDatabase;
84
CSPath *getTableFile(const char *table_name, bool to_delete);
86
CSPath *getTableFile();
88
CSFile *openTableFile();
90
void prepareToDelete();
92
uint64_t createBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
94
uint64_t findBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
96
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);
98
void updateBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t offset, uint16_t head_size);
100
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);
102
void freeBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint32_t auth_code);
104
/* Make this object hashable: */
105
virtual CSObject *getKey();
106
virtual int compareKey(CSObject *);
107
virtual uint32_t hashKey();
109
off64_t getTableFileSize() { return iTableFileSize; }
110
CSString *getTableName();
111
bool isToDelete() { return iToDelete; }
112
void getDeleteInfo(uint32_t *log, uint32_t *offs, time_t *tim);
113
bool isNoTable() { return myTableName->length() == 0; }
116
off64_t iTableFileSize;
117
size_t iTableHeadSize;
120
uint32_t iTabDeleteTime;
121
uint32_t iTabTempLogID;
122
uint32_t iTabTempLogOffset;
125
static MSTable *newTable(uint32_t tab_id, CSString *name, MSDatabase *db, off64_t file_size, bool to_delete);
127
static MSTable *newTable(uint32_t tab_id, const char *name, MSDatabase *db, off64_t file_size, bool to_delete);