1
#ifdef NOT_USED_IN_ANY_THING
3
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
5
* PrimeBase Media Stream for MySQL
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
#include "cslib/CSConfig.h"
30
#include "cslib/CSGlobal.h"
31
#include "cslib/CSLog.h"
32
#include "cslib/CSStrUtil.h"
33
#include "cslib/CSHTTPStream.h"
34
#include "cslib/CSStream.h"
36
#include "repository_ms.h"
37
#include "open_table_ms.h"
40
//-----------------------------------------------------------------------------------------------
41
void PBMSGetError(void *v_bs_thread, PBMSResultPtr result)
43
CSThread *ms_thread = (CSThread*)v_bs_thread;
46
memset(result, 0, sizeof(PBMSResultRec));
48
result->mr_code = ms_thread->myException.getErrorCode();
49
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, ms_thread->myException.getMessage());
52
//-----------------------------------------------------------------------------------------------
53
void *PBMSInitBlobStreamingThread(char *thread_name, PBMSResultPtr result)
55
CSThread *ms_thread = new CSThread( NULL);
58
memset(result, 0, sizeof(PBMSResultRec));
59
result->mr_code = ENOMEM;
60
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, "CSThread::newThread() failed.");
64
ms_thread->pbms_api_owner = true;
65
if (!CSThread::attach(ms_thread)) {
66
memset(result, 0, sizeof(PBMSResultRec));
67
result->mr_code = ms_thread->myException.getErrorCode();
68
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, ms_thread->myException.getMessage());
72
ms_thread->threadName = CSString::newString(thread_name);
78
//-----------------------------------------------------------------------------------------------
79
void PBMSDeinitBlobStreamingThread(void *v_bs_thread)
81
CSThread *ms_thread = (CSThread*)v_bs_thread;
85
CSThread::detach(ms_thread);
86
// ms_thread->release(); Don't do this. Ownership of the thread is passed to the attach call so the thread is released when it is detached.
89
//-----------------------------------------------------------------------------------------------
90
bool PBMSCreateBlob(PBMSBlobIDPtr blob_id, char *database_name, uint64_t size)
92
MSOpenTable *otab = NULL;
93
CSString *iTableURI = NULL;
94
CSString *CSContenttype = NULL;
100
otab = MSTableList::getOpenTableForDB(MSDatabase::getDatabaseID(database_name, false));
102
otab->createBlob(blob_id, size, NULL, 0);
112
otab->returnToPool();
115
CSContenttype->release();
118
iTableURI->release();
123
//-----------------------------------------------------------------------------------------------
124
bool PBMSWriteBlob(PBMSBlobIDPtr blob_id, char *data, size_t size, size_t offset)
127
MSRepoFile *repo_file;
133
if (!(otab = MSTableList::getOpenTableForDB(blob_id->bi_db_id))) {
134
char buffer[CS_EXC_MESSAGE_SIZE];
137
snprintf(id_str, 12, "%"PRIu32"", blob_id->bi_db_id);
139
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Unknown database id # ");
140
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, id_str);
141
CSException::throwException(CS_CONTEXT, MS_ERR_UNKNOWN_DB, buffer);
144
repo_file = otab->getDB()->getRepoFileFromPool( blob_id->bi_tab_id, false);
145
frompool_(repo_file);
146
// It is assumed that at this point the blob is a repository blob and so the
147
// blob_id->bi_blob_id is actually the repository blob offset.
148
repo_file->writeBlobChunk(blob_id, blob_id->bi_blob_id, offset, size, data);
149
backtopool_(repo_file);
162
//-----------------------------------------------------------------------------------------------
163
bool PBMSReadBlob(PBMSBlobIDPtr blob_id, char *buffer, size_t *size, size_t offset)
166
MSRepoFile *repo_file;
167
bool done_ok = true, is_repository_blob;
171
is_repository_blob = (blob_id->bi_blob_type == MS_URL_TYPE_REPO);
173
if (!(otab = MSTableList::getOpenTableByID(blob_id->bi_db_id, blob_id->bi_tab_id))) {
174
char buffer[CS_EXC_MESSAGE_SIZE];
178
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Unknown database: ID # ");
179
snprintf(id_str, 12, "%"PRIu32"", blob_id->bi_db_id);
180
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, id_str);
181
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, " or table: ID #");
182
snprintf(id_str, 12, "%"PRIu32"", blob_id->bi_tab_id);
183
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, id_str);
184
CSException::throwException(CS_CONTEXT, MS_ERR_UNKNOWN_DB, buffer);
191
if (is_repository_blob) {
192
repo_id = blob_id->bi_tab_id;
193
rep_offset = blob_id->bi_blob_id;
196
uint16_t header_size;
197
otab->getDBTable()->readBlobHandle(otab, blob_id->bi_blob_id, &(blob_id->bi_auth_code), &repo_id, &rep_offset, &blob_size, &header_size, true);
200
repo_file = otab->getDB()->getRepoFileFromPool( repo_id, false);
201
frompool_(repo_file);
202
*size = repo_file->readBlobChunk(blob_id, rep_offset, offset, *size, buffer);
203
backtopool_(repo_file);
216
//-----------------------------------------------------------------------------------------------
217
bool PBMSIDToURL(PBMSBlobIDPtr blob_id, PBMSBlobURLPtr url)
221
ms_blob.bu_db_id = blob_id->bi_db_id;
222
ms_blob.bu_blob_id = blob_id->bi_blob_id;
223
ms_blob.bu_blob_ref_id = blob_id->bi_blob_ref_id;
224
ms_blob.bu_tab_id = blob_id->bi_tab_id;
225
ms_blob.bu_auth_code = blob_id->bi_auth_code;
226
ms_blob.bu_type = blob_id->bi_blob_type;
227
ms_blob.bu_blob_size = blob_id->bi_blob_size;
228
ms_blob.bu_server_id = ms_my_get_server_id();
230
PBMSBlobURLTools::buildBlobURL(&ms_blob, url);
234
//-----------------------------------------------------------------------------------------------
235
bool PBMSURLToID(char *url, PBMSBlobIDPtr blob_id)
243
if (!PBMSBlobURLTools::couldBeURL(url, &ms_blob)){
244
char buffer[CS_EXC_MESSAGE_SIZE];
246
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Incorrect URL: ");
247
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, url);
248
CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer);
251
blob_id->bi_db_id = ms_blob.bu_db_id;
252
blob_id->bi_blob_id = ms_blob.bu_blob_id;
253
blob_id->bi_blob_ref_id = ms_blob.bu_blob_ref_id;
254
blob_id->bi_tab_id = ms_blob.bu_tab_id;
255
blob_id->bi_auth_code = ms_blob.bu_auth_code;
256
blob_id->bi_blob_type = ms_blob.bu_type;
257
blob_id->bi_blob_size = ms_blob.bu_blob_size;
270
#endif // NOT_USED_IN_ANY_THING