Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : #ifndef BENTO_H
57 : #define BENTO_H
58 :
59 : #include <string>
60 : #include <vector>
61 : #include "lwpsvstream.hxx"
62 :
63 : #define BEN_CC __stdcall
64 : #ifdef COMP_BENTO
65 : #define BEN_EXPORT __declspec(dllexport)
66 : #else
67 : #define BEN_EXPORT
68 : #endif
69 :
70 : using namespace std;
71 :
72 : #include "ut.hxx"
73 : #include "utlist.hxx"
74 : #include <tools/stream.hxx>
75 : #include <sot/storage.hxx>
76 :
77 : namespace OpenStormBento
78 : {
79 :
80 : #define BEN_CURR_MAJOR_VERSION 2
81 : #define BEN_CURR_MINOR_VERSION 0
82 : #define BEN_MAGIC_BYTES_SIZE 8
83 : #define BEN_LABEL_SIZE 24
84 :
85 : #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
86 :
87 : enum BenError
88 : {
89 : BenErr_OK = 0,
90 : BenErr_NameConflict = 1,
91 : BenErr_DuplicateObjectID = 2,
92 : BenErr_UnknownBentoFormatVersion = 3,
93 : BenErr_NamedObjectError = 4,
94 : BenErr_NamedObjectIllegalValue = 5,
95 : BenErr_InvalidTOC = 6,
96 : BenErr_64BitOffsetNotSupported = 7,
97 : BenErr_ReadPastEndOfTOC = 8,
98 : BenErr_ContainerWithNoObjects = 9,
99 : BenErr_ObjectWithNoProperties = 10,
100 : BenErr_PropertyWithNoValues = 11,
101 : BenErr_IllegalInMemoryTOC = 12,
102 : BenErr_PropertyAlreadyExists = 13,
103 : BenErr_UnexpectedEndOfFile = 14,
104 : BenErr_InvalidWriteOffset = 15,
105 : BenErr_InvalidImmediateWrite = 16,
106 : BenErr_TOCSeedError = 17,
107 : BenErr_ReadPastEndOfContainer = 18,
108 : BenErr_DuplicateName = 19,
109 : BenErr_BadReferencedList = 20,
110 : BenErr_IllegalContinuedImmediate = 21,
111 : BenErr_NotBentoContainer = 22,
112 : BenErr_PropertyWithMoreThanOneValue = 23
113 :
114 : // IMPORTANT - UtStream errors (UtErr_....) are also valid Bento
115 : // errors. They have codes of 100 and higher. When, say, a Bento
116 : // container open fails due to an access violation (somebody else, say,
117 : // has it open exclusive), will get a UtErr code. If define own
118 : // subclass of UtStream (custom handler), can define own error codes--
119 : // those should start at 200
120 : };
121 :
122 : UtDefClassP(LtcBenContainer);
123 : UtDefClassP(CBenIDListElmt);
124 : UtDefClassP(CBenObject);
125 : UtDefClassP(CBenProperty);
126 : UtDefClassP(CBenReference);
127 : UtDefClassP(CBenValue);
128 : UtDefClassP(CBenValueSegment);
129 : UtDefClassP(CBenNamedObjectListElmt);
130 : UtDefClassP(CBenNamedObject);
131 : UtDefClassP(CBenPropertyName);
132 : UtDefClassP(CBenTypeName);
133 :
134 : typedef unsigned char BenByte;
135 : typedef unsigned short BenWord;
136 : typedef unsigned long BenDWord;
137 : typedef void * BenDataPtr;
138 : typedef const void * BenConstDataPtr;
139 :
140 : typedef unsigned long BenContainerPos;
141 : typedef unsigned long BenObjectID;
142 : typedef unsigned long BenGeneration;
143 :
144 : sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer);
145 :
146 0 : class CBenIDListElmt : public CUtListElmt
147 : {
148 : public: // Internal methods
149 0 : CBenIDListElmt(BenObjectID ID, pCBenIDListElmt pPrev) : CUtListElmt(pPrev)
150 0 : { cID = ID; }
151 0 : CBenIDListElmt(BenObjectID ID) { cID = ID; }
152 0 : BenObjectID GetID() { return cID; }
153 :
154 : private: // Data
155 : BenObjectID cID;
156 : };
157 :
158 0 : class CBenNamedObjectListElmt : public CUtListElmt
159 : {
160 : public: // Methods
161 : // added to remove warning
162 0 : CBenNamedObjectListElmt(pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
163 0 : { cpNamedObject = NULL; }
164 0 : void SetNamedObject(pCBenNamedObject pObj)
165 : {
166 0 : cpNamedObject = pObj;
167 0 : }
168 :
169 : CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
170 : pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
171 : { cpNamedObject = pNamedObject; }
172 0 : pCBenNamedObject GetNamedObject() { return cpNamedObject; }
173 :
174 : private: // Data
175 : pCBenNamedObject cpNamedObject;
176 : };
177 :
178 : class LtcUtBenValueStream : public SvStream
179 : {
180 : public:
181 : LtcUtBenValueStream(pCBenValue pValue);
182 : virtual ~LtcUtBenValueStream();
183 :
184 : public: // Overridden methods
185 :
186 : /* added by */
187 0 : CBenValue * GetValue(){ return cpValue; };
188 0 : sal_uLong GetSize() { return m_ulValueLength; };
189 : protected: // Overridden methods
190 :
191 : virtual sal_uLong GetData( void* pData, sal_uLong nSize ) SAL_OVERRIDE;
192 : virtual sal_uLong PutData( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
193 : virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) SAL_OVERRIDE;
194 : virtual void SetSize( sal_uInt64 nSize ) SAL_OVERRIDE;
195 : virtual void FlushData() SAL_OVERRIDE;
196 :
197 : private: // Data
198 : pCBenValue cpValue;
199 : unsigned long cCurrentPosition;
200 :
201 : sal_uLong m_ulValueLength; // Added by , sum of length of all sub-valuesegments
202 : // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
203 : };
204 :
205 : class LtcBenContainer
206 : {
207 : public:
208 : BenError Open();
209 : BenError Close();
210 : BenError RegisterPropertyName(const char * sPropertyName,
211 : pCBenPropertyName * ppPropertyName);
212 : // Pass NULL to begin iteration. Done when returns NULL.
213 : // Objects are returned in order of increasing ID
214 : pCBenObject GetNextObject(pCBenObject pCurrObject);
215 : pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
216 : BenObjectID PropertyID);
217 :
218 : public: // Internal methods
219 : LtcBenContainer(LwpSvStream * pStream);
220 : ~LtcBenContainer();
221 :
222 : BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
223 : unsigned long * pAmtRead);
224 : BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
225 : BenError SeekToPosition(BenContainerPos Pos);
226 : BenError SeekFromEnd(long Offset);
227 :
228 : BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
229 0 : void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
230 0 : pCUtList GetObjects() { return &cObjects; }
231 0 : pCUtList GetNamedObjects() { return &cNamedObjects; }
232 :
233 : LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
234 : LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
235 : BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
236 :
237 : BenError GetSize(sal_uLong * pLength);
238 : LwpSvStream * GetStream()
239 : {
240 : return cpStream;
241 : };
242 : private: // Data
243 : CUtOwningList cObjects;
244 : CUtList cNamedObjects;
245 : LwpSvStream * cpStream;
246 : sal_uLong m_ulLength; // Added for TOCRead.cpp
247 : BenObjectID cNextAvailObjectID; // for new object
248 : };
249 :
250 0 : class CBenObject : public CBenIDListElmt
251 : {
252 : public:
253 : pCBenProperty UseProperty(BenObjectID PropertyID);
254 : pCBenValue UseValue(BenObjectID PropertyID);
255 : virtual bool IsNamedObject();
256 0 : pLtcBenContainer GetContainer() { return cpContainer; }
257 : BenObjectID GetObjectID() { return GetID(); }
258 : public: // Internal methods
259 0 : CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
260 0 : pCBenIDListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
261 0 : { cpContainer = pContainer; }
262 0 : pCUtList GetProperties() { return &cProperties; }
263 :
264 : private: // Data
265 : pLtcBenContainer cpContainer;
266 : CUtOwningList cProperties;
267 : };
268 :
269 0 : class CBenValue : public CBenIDListElmt
270 : {
271 : public:
272 : unsigned long GetValueSize();
273 : BenError ReadValueData(BenDataPtr pBuffer,
274 : unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
275 :
276 0 : pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
277 :
278 : public: // Internal methods
279 : // added to remove WARNING
280 0 : CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
281 : {
282 0 : cpProperty = NULL;
283 0 : cpReferencedList = NULL;
284 0 : }
285 :
286 0 : void SetProperty(pCBenProperty pProperty)
287 : {
288 0 : cpProperty = pProperty;
289 0 : }
290 :
291 : CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
292 : CBenIDListElmt(TypeID)
293 : {
294 : cpProperty = pProperty;
295 : cpReferencedList = NULL;
296 : }
297 : BenObjectID GetTypeNameID() { return GetID(); }
298 : inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
299 : pCurrValueSegment);
300 : inline pLtcBenContainer GetContainer();
301 0 : pCUtList GetValueSegments() { return &cValueSegments; }
302 : // Currently, no generation support
303 : BenGeneration GetGeneration() { return 1; }
304 :
305 : private: // Data
306 : pCBenProperty cpProperty;
307 : CUtOwningList cValueSegments;
308 : pCBenValue cpReferencedList;
309 : };
310 :
311 0 : class CBenProperty : public CBenIDListElmt
312 : {
313 : public:
314 : // In the Apple Bento, a property can have multiple values, each of a
315 : // different type. But we never use it that way, so in this code a
316 : // property has exactly one value
317 :
318 0 : pCBenValue UseValue() { return &cValue; }
319 0 : pCBenObject GetBenObject() { return cpObject; }
320 0 : pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
321 :
322 : public: // Internal methods
323 : // changed to remove WARNING here
324 0 : CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
325 : BenObjectID TypeID, pCBenIDListElmt pPrevProperty) :
326 0 : CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
327 : {
328 0 : cpObject = pObject;
329 0 : cValue.SetProperty(this);
330 0 : }
331 :
332 : BenObjectID GetPropertyNameID() { return GetID(); }
333 :
334 : private: // Data
335 : pCBenObject cpObject;
336 : CBenValue cValue;
337 : };
338 :
339 : // In our implementation, reference is always just the object ID for the
340 : // object referenced (but you shouldn't assume that)
341 : #define BEN_REFERENCE_SIZE 4
342 :
343 : class CBenReference
344 : {
345 : public: // Methods
346 : BenByte * GetData() { return cData; }
347 :
348 : private: // Data
349 : BenByte cData[BEN_REFERENCE_SIZE];
350 : };
351 :
352 0 : class CBenValueSegment : public CUtListElmt
353 : {
354 : public: // Internal methods
355 0 : CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
356 0 : unsigned long Size) : CUtListElmt(pValue->GetValueSegments())
357 0 : { cpValue = pValue; cImmediate = false; cPos = Pos;
358 0 : cSize = Size; }
359 0 : CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
360 0 : unsigned short Size) : CUtListElmt(pValue->GetValueSegments())
361 0 : { cpValue = pValue; cImmediate = true;
362 0 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
363 : CBenValueSegment(BenContainerPos Pos, unsigned long Size)
364 : { cpValue = NULL; cImmediate = false; cPos = Pos;
365 : cSize = Size; }
366 : CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
367 : { cpValue = NULL; cImmediate = true;
368 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
369 : bool IsLast()
370 : {
371 : return cpValue == NULL || cpValue->GetValueSegments()->GetLast() ==
372 : this;
373 : }
374 0 : bool IsImmediate() { return cImmediate; }
375 0 : BenContainerPos GetPosition() { return cPos; }
376 0 : unsigned long GetSize() { return cSize; }
377 : void SetSize(unsigned long Size) { cSize = Size; }
378 0 : BenByte * GetImmediateData() { return cImmData; }
379 :
380 : private: // Data
381 : pCBenValue cpValue;
382 : bool cImmediate;
383 : union
384 : {
385 : BenContainerPos cPos;
386 : BenByte cImmData[4];
387 : };
388 : unsigned long cSize;
389 : };
390 :
391 0 : inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
392 : pCurrValueSegment)
393 0 : { return (pCBenValueSegment) cValueSegments.GetNextOrNULL(pCurrValueSegment); }
394 :
395 0 : inline pLtcBenContainer CBenValue::GetContainer()
396 0 : { return GetProperty()->GetContainer(); }
397 :
398 0 : class CBenNamedObject : public CBenObject
399 : {
400 : public: // Methods
401 : virtual bool IsNamedObject() SAL_OVERRIDE;
402 : virtual bool IsPropertyName();
403 : virtual bool IsTypeName();
404 :
405 : public: // Internal methods
406 : CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
407 : pCBenObject pPrevObject, const char * sName,
408 : pCBenNamedObjectListElmt pPrevNamedObjectListElmt);
409 : const char * GetName() { return csName.data(); }
410 :
411 0 : const char * GetNameCStr() { return csName.c_str(); }
412 :
413 : void SetPosition(BenContainerPos Pos) { cPos = Pos; }
414 : BenContainerPos GetPosition(void) { return cPos; }
415 : size_t GetLength(void) { return csName.length()+ 1; }
416 : pCBenNamedObjectListElmt GetNameListElmt() { return &cNameListElmt; }
417 :
418 : private: // Data
419 : string csName;
420 : CBenNamedObjectListElmt cNameListElmt;
421 : BenContainerPos cPos;
422 : };
423 :
424 0 : class CBenPropertyName : public CBenNamedObject
425 : {
426 : public: // Internal methods
427 0 : CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
428 : pCBenObject pPrevObject, const char * sName,
429 : pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
430 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
431 0 : pPrevNamedObjectListElmt) { ; }
432 : virtual bool IsPropertyName() SAL_OVERRIDE;
433 : };
434 :
435 0 : class CBenTypeName : public CBenNamedObject
436 : {
437 : public: // Internal methods
438 0 : CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
439 : pCBenObject pPrevObject, const char * sName,
440 : pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
441 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
442 0 : pPrevNamedObjectListElmt) { ; }
443 : virtual bool IsTypeName() SAL_OVERRIDE;
444 : };
445 :
446 : } // end namespace OpenStormBento
447 : #endif
448 :
449 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|