1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
1 |
#ifdef NOT_USED_IN_ANY_THING
|
2 |
||
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
3 |
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
|
4 |
*
|
|
5 |
* PrimeBase Media Stream for MySQL
|
|
6 |
*
|
|
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.
|
|
11 |
*
|
|
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.
|
|
16 |
*
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
*
|
|
21 |
* Barry Leslie
|
|
22 |
*
|
|
23 |
* 2007-11-25
|
|
24 |
*
|
|
25 |
* H&G2JCtL
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
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" |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
35 |
|
1548.2.10
by Barry.Leslie at PrimeBase
Merge from trunk. |
36 |
#include "repository_ms.h" |
37 |
#include "open_table_ms.h" |
|
38 |
#include "mysql_ms.h" |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
39 |
|
40 |
//-----------------------------------------------------------------------------------------------
|
|
41 |
void PBMSGetError(void *v_bs_thread, PBMSResultPtr result) |
|
42 |
{
|
|
43 |
CSThread *ms_thread = (CSThread*)v_bs_thread; |
|
44 |
||
45 |
ASSERT(ms_thread); |
|
46 |
memset(result, 0, sizeof(PBMSResultRec)); |
|
47 |
||
48 |
result->mr_code = ms_thread->myException.getErrorCode(); |
|
49 |
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, ms_thread->myException.getMessage()); |
|
50 |
}
|
|
51 |
||
52 |
//-----------------------------------------------------------------------------------------------
|
|
53 |
void *PBMSInitBlobStreamingThread(char *thread_name, PBMSResultPtr result) |
|
54 |
{
|
|
55 |
CSThread *ms_thread = new CSThread( NULL); |
|
56 |
||
57 |
if (!ms_thread) { |
|
58 |
memset(result, 0, sizeof(PBMSResultRec)); |
|
59 |
result->mr_code = ENOMEM; |
|
60 |
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, "CSThread::newThread() failed."); |
|
61 |
return NULL; |
|
62 |
}
|
|
63 |
||
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()); |
|
69 |
ms_thread->release(); |
|
70 |
ms_thread = NULL; |
|
71 |
} else |
|
72 |
ms_thread->threadName = CSString::newString(thread_name); |
|
73 |
||
74 |
return ms_thread; |
|
75 |
}
|
|
76 |
||
77 |
||
78 |
//-----------------------------------------------------------------------------------------------
|
|
79 |
void PBMSDeinitBlobStreamingThread(void *v_bs_thread) |
|
80 |
{
|
|
81 |
CSThread *ms_thread = (CSThread*)v_bs_thread; |
|
82 |
||
83 |
ASSERT(ms_thread); |
|
84 |
||
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.
|
|
87 |
}
|
|
88 |
||
89 |
//-----------------------------------------------------------------------------------------------
|
|
1548.2.27
by Barry.Leslie at PrimeBase
Cleanup for solaris build. |
90 |
bool PBMSCreateBlob(PBMSBlobIDPtr blob_id, char *database_name, uint64_t size) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
91 |
{
|
92 |
MSOpenTable *otab = NULL; |
|
93 |
CSString *iTableURI = NULL; |
|
94 |
CSString *CSContenttype = NULL; |
|
95 |
bool done_ok = true; |
|
96 |
||
97 |
enter_(); |
|
98 |
||
99 |
try_(a) { |
|
100 |
otab = MSTableList::getOpenTableForDB(MSDatabase::getDatabaseID(database_name, false)); |
|
101 |
||
102 |
otab->createBlob(blob_id, size, NULL, 0); |
|
103 |
}
|
|
104 |
||
105 |
catch_(a) { |
|
106 |
done_ok = false; |
|
107 |
}
|
|
108 |
cont_(a); |
|
109 |
||
110 |
exit: |
|
111 |
if (otab) |
|
112 |
otab->returnToPool(); |
|
113 |
||
114 |
if (CSContenttype) |
|
115 |
CSContenttype->release(); |
|
116 |
||
117 |
if (iTableURI) |
|
118 |
iTableURI->release(); |
|
119 |
||
120 |
return_(done_ok); |
|
121 |
}
|
|
122 |
||
123 |
//-----------------------------------------------------------------------------------------------
|
|
124 |
bool PBMSWriteBlob(PBMSBlobIDPtr blob_id, char *data, size_t size, size_t offset) |
|
125 |
{
|
|
126 |
MSOpenTable *otab; |
|
127 |
MSRepoFile *repo_file; |
|
128 |
bool done_ok = true; |
|
129 |
||
130 |
enter_(); |
|
131 |
||
132 |
try_(a) { |
|
133 |
if (!(otab = MSTableList::getOpenTableForDB(blob_id->bi_db_id))) { |
|
134 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
|
135 |
char id_str[12]; |
|
136 |
||
137 |
snprintf(id_str, 12, "%"PRIu32"", blob_id->bi_db_id); |
|
138 |
||
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); |
|
142 |
}
|
|
143 |
frompool_(otab); |
|
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); |
|
150 |
backtopool_(otab); |
|
151 |
||
152 |
}
|
|
153 |
catch_(a) { |
|
154 |
done_ok = false; |
|
155 |
}
|
|
156 |
||
157 |
cont_(a); |
|
158 |
||
159 |
return_(done_ok); |
|
160 |
}
|
|
161 |
||
162 |
//-----------------------------------------------------------------------------------------------
|
|
163 |
bool PBMSReadBlob(PBMSBlobIDPtr blob_id, char *buffer, size_t *size, size_t offset) |
|
164 |
{
|
|
165 |
MSOpenTable *otab; |
|
166 |
MSRepoFile *repo_file; |
|
167 |
bool done_ok = true, is_repository_blob; |
|
168 |
||
169 |
enter_(); |
|
170 |
||
171 |
is_repository_blob = (blob_id->bi_blob_type == MS_URL_TYPE_REPO); |
|
172 |
try_(a) { |
|
173 |
if (!(otab = MSTableList::getOpenTableByID(blob_id->bi_db_id, blob_id->bi_tab_id))) { |
|
174 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
|
175 |
char id_str[12]; |
|
176 |
||
177 |
||
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); |
|
185 |
}
|
|
186 |
uint32_t repo_id; |
|
187 |
uint64_t rep_offset; |
|
188 |
||
189 |
||
190 |
frompool_(otab); |
|
191 |
if (is_repository_blob) { |
|
192 |
repo_id = blob_id->bi_tab_id; |
|
193 |
rep_offset = blob_id->bi_blob_id; |
|
194 |
} else { |
|
195 |
uint64_t blob_size; |
|
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); |
|
198 |
}
|
|
199 |
||
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); |
|
204 |
backtopool_(otab); |
|
205 |
||
206 |
}
|
|
207 |
catch_(a) { |
|
208 |
done_ok = false; |
|
209 |
}
|
|
210 |
||
211 |
cont_(a); |
|
212 |
||
213 |
return_(done_ok); |
|
214 |
}
|
|
215 |
||
216 |
//-----------------------------------------------------------------------------------------------
|
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
217 |
bool PBMSIDToURL(PBMSBlobIDPtr blob_id, PBMSBlobURLPtr url) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
218 |
{
|
219 |
MSBlobURL ms_blob; |
|
220 |
||
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(); |
|
229 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
230 |
PBMSBlobURLTools::buildBlobURL(&ms_blob, url); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
231 |
return true; |
232 |
}
|
|
233 |
||
234 |
//-----------------------------------------------------------------------------------------------
|
|
235 |
bool PBMSURLToID(char *url, PBMSBlobIDPtr blob_id) |
|
236 |
{
|
|
237 |
MSBlobURL ms_blob; |
|
238 |
bool done_ok = true; |
|
239 |
enter_(); |
|
240 |
||
241 |
try_(a) { |
|
242 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
243 |
if (!PBMSBlobURLTools::couldBeURL(url, &ms_blob)){ |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
244 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
245 |
||
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); |
|
249 |
}
|
|
250 |
||
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; |
|
258 |
||
259 |
}
|
|
260 |
catch_(a) { |
|
261 |
done_ok = false; |
|
262 |
}
|
|
263 |
||
264 |
cont_(a); |
|
265 |
||
266 |
return_(done_ok); |
|
267 |
}
|
|
268 |
||
269 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
270 |
#endif // NOT_USED_IN_ANY_THING |