xref: /aoo4110/main/registry/source/reflread.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_registry.hxx"
26 
27 #include <memory>
28 #include <new>
29 
30 #include <string.h>
31 #include <sal/types.h>
32 #include <osl/endian.h>
33 #include <registry/reflread.hxx>
34 
35 #include "registry/reader.h"
36 #include "registry/version.h"
37 
38 #include "reflcnst.hxx"
39 
40 #include <cstddef>
41 
42 static sal_Char NULL_STRING[1] = { 0 };
43 static sal_Unicode NULL_WSTRING[1] = { 0 };
44 
45 const sal_uInt32    magic = 0x12345678;
46 const sal_uInt16 minorVersion = 0x0000;
47 const sal_uInt16 majorVersion = 0x0001;
48 
49 #if defined ( GCC ) && ( defined ( SCO ) )
50 ORealDynamicLoader* ODynamicLoader<RegistryTypeReader_Api>::m_pLoader = NULL;
51 #endif
52 
53 /**************************************************************************
54 
55     class BlopObject
56 
57     holds any data in a flat memory buffer
58 
59 **************************************************************************/
60 
61 class BlopObject
62 {
63 public:
64     const sal_uInt8* m_pBuffer;
65     sal_uInt32      m_bufferLen;
66     sal_Bool        m_isCopied;
67 
68     BlopObject(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer);
69         // throws std::bad_alloc
70 
71     ~BlopObject();
72 
readBYTE(sal_uInt32 index) const73     inline sal_uInt8 readBYTE(sal_uInt32 index) const
74     {
75         return m_pBuffer[index];
76     }
77 
readINT16(sal_uInt32 index) const78     inline sal_Int16 readINT16(sal_uInt32 index) const
79     {
80         return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0));
81     }
82 
readUINT16(sal_uInt32 index) const83     inline sal_uInt16 readUINT16(sal_uInt32 index) const
84     {
85         return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0));
86     }
87 
readINT32(sal_uInt32 index) const88     inline sal_Int32 readINT32(sal_uInt32 index) const
89     {
90         return (
91             (m_pBuffer[index]   << 24) |
92             (m_pBuffer[index+1] << 16) |
93             (m_pBuffer[index+2] << 8)  |
94             (m_pBuffer[index+3] << 0)
95         );
96     }
97 
readUINT32(sal_uInt32 index) const98     inline sal_uInt32 readUINT32(sal_uInt32 index) const
99     {
100         return (
101             (m_pBuffer[index]   << 24) |
102             (m_pBuffer[index+1] << 16) |
103             (m_pBuffer[index+2] << 8)  |
104             (m_pBuffer[index+3] << 0)
105         );
106     }
107 
readINT64(sal_uInt32 index) const108     inline sal_Int64 readINT64(sal_uInt32 index) const
109     {
110 		return (
111             ((sal_Int64)m_pBuffer[index]   << 56) |
112             ((sal_Int64)m_pBuffer[index+1] << 48) |
113             ((sal_Int64)m_pBuffer[index+2] << 40) |
114             ((sal_Int64)m_pBuffer[index+3] << 32) |
115             ((sal_Int64)m_pBuffer[index+4] << 24) |
116             ((sal_Int64)m_pBuffer[index+5] << 16) |
117             ((sal_Int64)m_pBuffer[index+6] << 8)  |
118             ((sal_Int64)m_pBuffer[index+7] << 0)
119         );
120     }
121 
readUINT64(sal_uInt32 index) const122     inline sal_uInt64 readUINT64(sal_uInt32 index) const
123     {
124         return (
125             ((sal_uInt64)m_pBuffer[index]   << 56) |
126             ((sal_uInt64)m_pBuffer[index+1] << 48) |
127             ((sal_uInt64)m_pBuffer[index+2] << 40) |
128             ((sal_uInt64)m_pBuffer[index+3] << 32) |
129             ((sal_uInt64)m_pBuffer[index+4] << 24) |
130             ((sal_uInt64)m_pBuffer[index+5] << 16) |
131             ((sal_uInt64)m_pBuffer[index+6] << 8)  |
132             ((sal_uInt64)m_pBuffer[index+7] << 0)
133         );
134     }
135 };
136 
BlopObject(const sal_uInt8 * buffer,sal_uInt32 len,sal_Bool copyBuffer)137 BlopObject::BlopObject(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer)
138     : m_bufferLen(len)
139     , m_isCopied(copyBuffer)
140 {
141     if (m_isCopied)
142     {
143         m_pBuffer = 0;
144         sal_uInt8* newBuffer = new sal_uInt8[len];
145         memcpy(newBuffer, buffer, len);
146         m_pBuffer = newBuffer;
147     }
148     else
149     {
150         m_pBuffer = buffer;
151     }
152 }
153 
~BlopObject()154 BlopObject::~BlopObject()
155 {
156     if (m_isCopied)
157     {
158         delete[] const_cast<sal_uInt8*>(m_pBuffer);
159     }
160 }
161 
162 /**************************************************************************
163 
164     class StringCache
165 
166 **************************************************************************/
167 
168 class StringCache
169 {
170 public:
171     sal_Unicode**   m_stringTable;
172     sal_uInt16      m_numOfStrings;
173     sal_uInt16      m_stringsCopied;
174 
175     StringCache(sal_uInt16 size); // throws std::bad_alloc
176     ~StringCache();
177 
178     const sal_Unicode*  getString(sal_uInt16 index);
179     sal_uInt16 createString(const sal_uInt8* buffer); // throws std::bad_alloc
180 };
181 
StringCache(sal_uInt16 size)182 StringCache::StringCache(sal_uInt16 size)
183     : m_stringTable(NULL)
184     , m_numOfStrings(size)
185     , m_stringsCopied(0)
186 {
187     m_stringTable = new sal_Unicode*[m_numOfStrings];
188 
189     for (sal_uInt16 i = 0; i < m_numOfStrings; i++)
190     {
191         m_stringTable[i] = NULL;
192     }
193 }
194 
~StringCache()195 StringCache::~StringCache()
196 {
197     if (m_stringTable)
198     {
199         for (sal_uInt16 i = 0; i < m_stringsCopied; i++)
200         {
201             delete[] m_stringTable[i];
202         }
203 
204         delete[] m_stringTable;
205     }
206 }
207 
getString(sal_uInt16 index)208 const sal_Unicode* StringCache::getString(sal_uInt16 index)
209 {
210     if ((index > 0) && (index <= m_stringsCopied))
211         return m_stringTable[index - 1];
212     else
213         return NULL;
214 }
215 
createString(const sal_uInt8 * buffer)216 sal_uInt16 StringCache::createString(const sal_uInt8* buffer)
217 {
218     if (m_stringsCopied < m_numOfStrings)
219     {
220         sal_uInt32 len = UINT16StringLen(buffer);
221 
222         m_stringTable[m_stringsCopied] = new sal_Unicode[len + 1];
223 
224         readString(buffer, m_stringTable[m_stringsCopied], (len + 1) * sizeof(sal_Unicode));
225 
226         return ++m_stringsCopied;
227     }
228     else
229         return 0;
230 }
231 
232 /**************************************************************************
233 
234     class ConstantPool
235 
236 **************************************************************************/
237 
238 class ConstantPool : public BlopObject
239 {
240 public:
241 
242     sal_uInt16  m_numOfEntries;
243     sal_Int32*  m_pIndex;           // index values may be < 0 for cached string constants
244 
245     StringCache* m_pStringCache;
246 
ConstantPool(const sal_uInt8 * buffer,sal_uInt16 numEntries)247     ConstantPool(const sal_uInt8* buffer, sal_uInt16 numEntries)
248         : BlopObject(buffer, 0, sal_False)
249         , m_numOfEntries(numEntries)
250         , m_pIndex(NULL)
251         , m_pStringCache(NULL)
252     {
253     }
254 
255     ~ConstantPool();
256 
257     sal_uInt32 parseIndex(); // throws std::bad_alloc
258 
259     CPInfoTag       readTag(sal_uInt16 index);
260 
261     const sal_Char* 	readUTF8NameConstant(sal_uInt16 index);
262     sal_Bool        	readBOOLConstant(sal_uInt16 index);
263     sal_uInt8       	readBYTEConstant(sal_uInt16 index);
264     sal_Int16       	readINT16Constant(sal_uInt16 index);
265     sal_uInt16      	readUINT16Constant(sal_uInt16 index);
266     sal_Int32       	readINT32Constant(sal_uInt16 index);
267     sal_uInt32      	readUINT32Constant(sal_uInt16 index);
268     sal_Int64       	readINT64Constant(sal_uInt16 index);
269     sal_uInt64      	readUINT64Constant(sal_uInt16 index);
270     float           	readFloatConstant(sal_uInt16 index);
271     double          	readDoubleConstant(sal_uInt16 index);
272     const sal_Unicode*  readStringConstant(sal_uInt16 index);
273         // throws std::bad_alloc
274     void            	readUIK(sal_uInt16 index, RTUik* uik);
275 };
276 
~ConstantPool()277 ConstantPool::~ConstantPool()
278 {
279     delete[] m_pIndex;
280     delete m_pStringCache;
281 }
282 
parseIndex()283 sal_uInt32 ConstantPool::parseIndex()
284 {
285     if (m_pIndex)
286     {
287         delete[] m_pIndex;
288         m_pIndex = NULL;
289     }
290 
291     if (m_pStringCache)
292     {
293         delete m_pStringCache;
294         m_pStringCache = NULL;
295     }
296 
297     sal_uInt32  offset = 0;
298     sal_uInt16  numOfStrings = 0;
299 
300     if (m_numOfEntries)
301     {
302         m_pIndex = new sal_Int32[m_numOfEntries];
303 
304         for (int i = 0; i < m_numOfEntries; i++)
305         {
306             m_pIndex[i] = offset;
307 
308             offset += readUINT32(offset);
309 
310             if ( ((CPInfoTag) readUINT16(m_pIndex[i] + CP_OFFSET_ENTRY_TAG)) ==
311                  CP_TAG_CONST_STRING )
312             {
313                 numOfStrings++;
314             }
315 
316         }
317     }
318 
319     if (numOfStrings)
320     {
321         m_pStringCache = new StringCache(numOfStrings);
322     }
323 
324     m_bufferLen = offset;
325 
326     return offset;
327 }
328 
readTag(sal_uInt16 index)329 CPInfoTag ConstantPool::readTag(sal_uInt16 index)
330 {
331     CPInfoTag tag = CP_TAG_INVALID;
332 
333     if (m_pIndex && (index > 0) && (index <= m_numOfEntries))
334     {
335         tag = (CPInfoTag) readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG);
336     }
337 
338     return tag;
339 }
340 
readUTF8NameConstant(sal_uInt16 index)341 const sal_Char* ConstantPool::readUTF8NameConstant(sal_uInt16 index)
342 {
343     const sal_Char* aName = NULL_STRING;
344 
345     if (m_pIndex && (index > 0) && (index <= m_numOfEntries))
346     {
347         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_UTF8_NAME)
348         {
349             aName = (const sal_Char*) (m_pBuffer + m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
350         }
351     }
352 
353     return aName;
354 }
355 
readBOOLConstant(sal_uInt16 index)356 sal_Bool ConstantPool::readBOOLConstant(sal_uInt16 index)
357 {
358     sal_Bool aBool = sal_False;
359 
360     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
361     {
362         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BOOL)
363         {
364             aBool = (sal_Bool) readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
365         }
366     }
367 
368     return aBool;
369 }
370 
readBYTEConstant(sal_uInt16 index)371 sal_uInt8 ConstantPool::readBYTEConstant(sal_uInt16 index)
372 {
373     sal_uInt8 aByte = sal_False;
374 
375     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
376     {
377         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BYTE)
378         {
379             aByte = readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
380         }
381     }
382 
383     return aByte;
384 }
385 
readINT16Constant(sal_uInt16 index)386 sal_Int16 ConstantPool::readINT16Constant(sal_uInt16 index)
387 {
388     sal_Int16 aINT16 = sal_False;
389 
390     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
391     {
392         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT16)
393         {
394             aINT16 = readINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
395         }
396     }
397 
398     return aINT16;
399 }
400 
readUINT16Constant(sal_uInt16 index)401 sal_uInt16 ConstantPool::readUINT16Constant(sal_uInt16 index)
402 {
403     sal_uInt16 asal_uInt16 = sal_False;
404 
405     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
406     {
407         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT16)
408         {
409             asal_uInt16 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
410         }
411     }
412 
413     return asal_uInt16;
414 }
415 
readINT32Constant(sal_uInt16 index)416 sal_Int32 ConstantPool::readINT32Constant(sal_uInt16 index)
417 {
418     sal_Int32 aINT32 = sal_False;
419 
420     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
421     {
422         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT32)
423         {
424             aINT32 = readINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
425         }
426     }
427 
428     return aINT32;
429 }
430 
readUINT32Constant(sal_uInt16 index)431 sal_uInt32 ConstantPool::readUINT32Constant(sal_uInt16 index)
432 {
433     sal_uInt32 aUINT32 = sal_False;
434 
435     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
436     {
437         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT32)
438         {
439             aUINT32 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
440         }
441     }
442 
443     return aUINT32;
444 }
445 
readINT64Constant(sal_uInt16 index)446 sal_Int64 ConstantPool::readINT64Constant(sal_uInt16 index)
447 {
448     sal_Int64 aINT64 = sal_False;
449 
450     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
451     {
452         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT64)
453         {
454             aINT64 = readINT64(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
455         }
456     }
457 
458     return aINT64;
459 }
460 
readUINT64Constant(sal_uInt16 index)461 sal_uInt64 ConstantPool::readUINT64Constant(sal_uInt16 index)
462 {
463     sal_uInt64 aUINT64 = sal_False;
464 
465     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
466     {
467         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT64)
468         {
469             aUINT64 = readUINT64(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
470         }
471     }
472 
473     return aUINT64;
474 }
475 
readFloatConstant(sal_uInt16 index)476 float ConstantPool::readFloatConstant(sal_uInt16 index)
477 {
478     union
479     {
480         float   v;
481         sal_uInt32  b;
482     } x = { 0.0f };
483 
484     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
485     {
486         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_FLOAT)
487         {
488 #ifdef REGTYPE_IEEE_NATIVE
489             x.b = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
490 #else
491 #   error no IEEE
492 #endif
493         }
494     }
495 
496     return  x.v;
497 }
498 
readDoubleConstant(sal_uInt16 index)499 double ConstantPool::readDoubleConstant(sal_uInt16 index)
500 {
501     union
502     {
503         double v;
504         struct
505         {
506             sal_uInt32  b1;
507             sal_uInt32  b2;
508         } b;
509     } x = { 0.0 };
510 
511     if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
512     {
513         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_DOUBLE)
514         {
515 
516 #ifdef REGTYPE_IEEE_NATIVE
517 #   ifdef OSL_BIGENDIAN
518             x.b.b1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
519             x.b.b2 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA + sizeof(sal_uInt32));
520 #   else
521             x.b.b1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA + sizeof(sal_uInt32));
522             x.b.b2 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
523 #   endif
524 #else
525 #   error no IEEE
526 #endif
527         }
528     }
529 
530     return x.v;
531 }
532 
readStringConstant(sal_uInt16 index)533 const sal_Unicode* ConstantPool::readStringConstant(sal_uInt16 index)
534 {
535     const sal_Unicode* aString = NULL_WSTRING;
536 
537     if (m_pIndex && (index> 0) && (index <= m_numOfEntries) && m_pStringCache)
538     {
539         if (m_pIndex[index - 1] >= 0)
540         {
541             // create cached string now
542 
543             if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_STRING)
544             {
545                 m_pIndex[index - 1] = -1 * m_pStringCache->createString(m_pBuffer + m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
546             }
547         }
548 
549         aString = m_pStringCache->getString((sal_uInt16) (m_pIndex[index - 1] * -1));
550     }
551 
552     return aString;
553 }
554 
readUIK(sal_uInt16 index,RTUik * uik)555 void ConstantPool::readUIK(sal_uInt16 index, RTUik* uik)
556 {
557     if (index == 0)
558     {
559         uik->m_Data1 = 0;
560         uik->m_Data2 = 0;
561         uik->m_Data3 = 0;
562         uik->m_Data4 = 0;
563         uik->m_Data5 = 0;
564     }
565     else if (m_pIndex && (index <= m_numOfEntries))
566     {
567         if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_UIK)
568         {
569             uik->m_Data1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK1);
570             uik->m_Data2 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK2);
571             uik->m_Data3 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK3);
572             uik->m_Data4 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK4);
573             uik->m_Data5 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK5);
574         }
575     }
576 }
577 
578 /**************************************************************************
579 
580     class FieldList
581 
582 **************************************************************************/
583 
584 class FieldList : public BlopObject
585 {
586 public:
587 
588     sal_uInt16      m_numOfEntries;
589     sal_uInt16      m_numOfFieldEntries;
590     sal_uInt16      m_FIELD_ENTRY_SIZE;
591     ConstantPool*   m_pCP;
592 
FieldList(const sal_uInt8 * buffer,sal_uInt16 numEntries,ConstantPool * pCP)593     FieldList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP)
594         : BlopObject(buffer, 0, sal_False)
595         , m_numOfEntries(numEntries)
596         , m_pCP(pCP)
597     {
598 		if ( m_numOfEntries > 0 )
599 		{
600 			m_numOfFieldEntries = readUINT16(0);
601 			m_FIELD_ENTRY_SIZE = m_numOfFieldEntries * sizeof(sal_uInt16);
602 		} else
603 		{
604 			m_numOfFieldEntries = 0;
605 			m_FIELD_ENTRY_SIZE = 0;
606 		}
607     }
608 
609     sal_uInt32 parseIndex();
610 
611     const sal_Char* getFieldName(sal_uInt16 index);
612     const sal_Char* getFieldType(sal_uInt16 index);
613     RTFieldAccess getFieldAccess(sal_uInt16 index);
614     RTValueType     getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value);
615         // throws std::bad_alloc
616     const sal_Char* getFieldDoku(sal_uInt16 index);
617     const sal_Char* getFieldFileName(sal_uInt16 index);
618 };
619 
parseIndex()620 sal_uInt32 FieldList::parseIndex()
621 {
622     return ((m_numOfEntries ? sizeof(sal_uInt16) : 0) + (m_numOfEntries * m_FIELD_ENTRY_SIZE));
623 }
624 
getFieldName(sal_uInt16 index)625 const sal_Char* FieldList::getFieldName(sal_uInt16 index)
626 {
627     const sal_Char* aName = NULL;
628 
629     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
630     {
631         aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_NAME));
632     }
633 
634     return aName;
635 }
636 
getFieldType(sal_uInt16 index)637 const sal_Char* FieldList::getFieldType(sal_uInt16 index)
638 {
639     const sal_Char* aName = NULL;
640 
641     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
642     {
643         aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_TYPE));
644     }
645 
646     return aName;
647 }
648 
getFieldAccess(sal_uInt16 index)649 RTFieldAccess FieldList::getFieldAccess(sal_uInt16 index)
650 {
651     RTFieldAccess aAccess = RT_ACCESS_INVALID;
652 
653     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
654     {
655         aAccess = (RTFieldAccess) readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_ACCESS);
656     }
657 
658     return aAccess;
659 }
660 
getFieldConstValue(sal_uInt16 index,RTConstValueUnion * value)661 RTValueType FieldList::getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value)
662 {
663     RTValueType ret = RT_TYPE_NONE;
664 
665     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
666     {
667         sal_uInt16 cpIndex = readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_VALUE);
668 
669         switch (m_pCP->readTag(cpIndex))
670         {
671             case CP_TAG_CONST_BOOL:
672                 value->aBool = m_pCP->readBOOLConstant(cpIndex);
673                 ret = RT_TYPE_BOOL;
674                 break;
675             case CP_TAG_CONST_BYTE:
676                 value->aByte = m_pCP->readBYTEConstant(cpIndex);
677                 ret = RT_TYPE_BYTE;
678                 break;
679             case CP_TAG_CONST_INT16:
680                 value->aShort = m_pCP->readINT16Constant(cpIndex);
681                 ret = RT_TYPE_INT16;
682                 break;
683             case CP_TAG_CONST_UINT16:
684                 value->aUShort = m_pCP->readUINT16Constant(cpIndex);
685                 ret = RT_TYPE_UINT16;
686                 break;
687             case CP_TAG_CONST_INT32:
688                 value->aLong = m_pCP->readINT32Constant(cpIndex);
689                 ret = RT_TYPE_INT32;
690                 break;
691             case CP_TAG_CONST_UINT32:
692                 value->aULong = m_pCP->readUINT32Constant(cpIndex);
693                 ret = RT_TYPE_UINT32;
694                 break;
695             case CP_TAG_CONST_INT64:
696               value->aHyper = m_pCP->readINT64Constant(cpIndex);
697                 ret = RT_TYPE_INT64;
698                 break;
699             case CP_TAG_CONST_UINT64:
700               value->aUHyper = m_pCP->readUINT64Constant(cpIndex);
701                 ret = RT_TYPE_UINT64;
702                 break;
703             case CP_TAG_CONST_FLOAT:
704                 value->aFloat = m_pCP->readFloatConstant(cpIndex);
705                 ret = RT_TYPE_FLOAT;
706                 break;
707             case CP_TAG_CONST_DOUBLE:
708                 value->aDouble = m_pCP->readDoubleConstant(cpIndex);
709                 ret = RT_TYPE_DOUBLE;
710                 break;
711             case CP_TAG_CONST_STRING:
712                 value->aString = m_pCP->readStringConstant(cpIndex);
713                 ret = RT_TYPE_STRING;
714                 break;
715             default:
716                 break;
717         }
718     }
719 
720     return ret;
721 }
722 
getFieldDoku(sal_uInt16 index)723 const sal_Char* FieldList::getFieldDoku(sal_uInt16 index)
724 {
725     const sal_Char* aDoku = NULL;
726 
727     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
728     {
729         aDoku = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_DOKU));
730     }
731 
732     return aDoku;
733 }
734 
getFieldFileName(sal_uInt16 index)735 const sal_Char* FieldList::getFieldFileName(sal_uInt16 index)
736 {
737     const sal_Char* aFileName = NULL;
738 
739     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
740     {
741         aFileName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_FILENAME));
742     }
743 
744     return aFileName;
745 }
746 
747 /**************************************************************************
748 
749     class ReferenceList
750 
751 **************************************************************************/
752 
753 class ReferenceList : public BlopObject
754 {
755 public:
756 
757     sal_uInt16		m_numOfEntries;
758     sal_uInt16		m_numOfReferenceEntries;
759     sal_uInt16		m_REFERENCE_ENTRY_SIZE;
760     ConstantPool*	m_pCP;
761 
ReferenceList(const sal_uInt8 * buffer,sal_uInt16 numEntries,ConstantPool * pCP)762     ReferenceList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP)
763         : BlopObject(buffer, 0, sal_False)
764         , m_numOfEntries(numEntries)
765         , m_pCP(pCP)
766     {
767         if ( m_numOfEntries > 0 )
768 		{
769 			m_numOfReferenceEntries = readUINT16(0);
770 			m_REFERENCE_ENTRY_SIZE = m_numOfReferenceEntries * sizeof(sal_uInt16);
771 		} else
772 		{
773 			m_numOfReferenceEntries = 0;
774 			m_REFERENCE_ENTRY_SIZE = 0;
775 		}
776     }
777 
778     sal_uInt32 parseIndex();
779 
780     const sal_Char* getReferenceName(sal_uInt16 index);
781     RTReferenceType getReferenceType(sal_uInt16 index);
782     const sal_Char* getReferenceDoku(sal_uInt16 index);
783 	RTFieldAccess 	getReferenceAccess(sal_uInt16 index);
784 };
785 
parseIndex()786 sal_uInt32 ReferenceList::parseIndex()
787 {
788     return ((m_numOfEntries ? sizeof(sal_uInt16) : 0) + (m_numOfEntries * m_REFERENCE_ENTRY_SIZE));
789 }
790 
getReferenceName(sal_uInt16 index)791 const sal_Char* ReferenceList::getReferenceName(sal_uInt16 index)
792 {
793     const sal_Char* aName = NULL;
794 
795     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
796     {
797         aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_NAME));
798     }
799 
800     return aName;
801 }
802 
getReferenceType(sal_uInt16 index)803 RTReferenceType ReferenceList::getReferenceType(sal_uInt16 index)
804 {
805     RTReferenceType refType = RT_REF_INVALID;
806 
807     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
808     {
809         refType = (RTReferenceType) readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_TYPE);
810     }
811 
812     return refType;
813 }
814 
getReferenceDoku(sal_uInt16 index)815 const sal_Char* ReferenceList::getReferenceDoku(sal_uInt16 index)
816 {
817     const sal_Char* aDoku = NULL;
818 
819     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
820     {
821         aDoku = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_DOKU));
822     }
823 
824     return aDoku;
825 }
826 
getReferenceAccess(sal_uInt16 index)827 RTFieldAccess ReferenceList::getReferenceAccess(sal_uInt16 index)
828 {
829     RTFieldAccess aAccess = RT_ACCESS_INVALID;
830 
831     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
832     {
833         aAccess = (RTFieldAccess) readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_ACCESS);
834     }
835 
836     return aAccess;
837 }
838 
839 /**************************************************************************
840 
841     class MethodList
842 
843 **************************************************************************/
844 
845 class MethodList : public BlopObject
846 {
847 public:
848 
849     sal_uInt16		m_numOfEntries;
850     sal_uInt16		m_numOfMethodEntries;
851     sal_uInt16		m_numOfParamEntries;
852     sal_uInt16		m_PARAM_ENTRY_SIZE;
853     sal_uInt32*		m_pIndex;
854     ConstantPool*	m_pCP;
855 
MethodList(const sal_uInt8 * buffer,sal_uInt16 numEntries,ConstantPool * pCP)856     MethodList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP)
857         : BlopObject(buffer, 0, sal_False)
858         , m_numOfEntries(numEntries)
859         , m_pIndex(NULL)
860         , m_pCP(pCP)
861     {
862 		if ( m_numOfEntries > 0 )
863 		{
864 			m_numOfMethodEntries = readUINT16(0);
865 			m_numOfParamEntries = readUINT16(sizeof(sal_uInt16));
866 			m_PARAM_ENTRY_SIZE = m_numOfParamEntries * sizeof(sal_uInt16);
867 		} else
868 		{
869 			m_numOfMethodEntries = 0;
870 			m_numOfParamEntries = 0;
871 			m_PARAM_ENTRY_SIZE = 0;
872 		}
873     }
874 
875     ~MethodList();
876 
877     sal_uInt32 parseIndex(); // throws std::bad_alloc
878 
879     const sal_Char* getMethodName(sal_uInt16 index);
880     sal_uInt16      getMethodParamCount(sal_uInt16 index);
881     const sal_Char* getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex);
882     const sal_Char* getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex);
883     RTParamMode     getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex);
884     sal_uInt16      getMethodExcCount(sal_uInt16 index);
885     const sal_Char* getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex);
886     const sal_Char* getMethodReturnType(sal_uInt16 index);
887     RTMethodMode    getMethodMode(sal_uInt16 index);
888     const sal_Char* getMethodDoku(sal_uInt16 index);
889 
890 private:
891 	sal_uInt16 calcMethodParamIndex( const sal_uInt16 index );
892 };
893 
~MethodList()894 MethodList::~MethodList()
895 {
896     if (m_pIndex) delete[] m_pIndex;
897 }
898 
calcMethodParamIndex(const sal_uInt16 index)899 sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index )
900 {
901 	return (METHOD_OFFSET_PARAM_COUNT + sizeof(sal_uInt16) + (index * m_PARAM_ENTRY_SIZE));
902 }
903 
parseIndex()904 sal_uInt32 MethodList::parseIndex()
905 {
906     if (m_pIndex)
907     {
908         delete[] m_pIndex;
909         m_pIndex = NULL;
910     }
911 
912     sal_uInt32 offset = 0;
913 
914     if (m_numOfEntries)
915     {
916 		offset = 2 * sizeof(sal_uInt16);
917         m_pIndex = new sal_uInt32[m_numOfEntries];
918 
919         for (int i = 0; i < m_numOfEntries; i++)
920         {
921             m_pIndex[i] = offset;
922 
923             offset += readUINT16(offset);
924         }
925     }
926 
927     return offset;
928 }
929 
getMethodName(sal_uInt16 index)930 const sal_Char* MethodList::getMethodName(sal_uInt16 index)
931 {
932     const sal_Char* aName = NULL;
933 
934     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
935     {
936         aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_NAME));
937     }
938 
939     return aName;
940 }
941 
getMethodParamCount(sal_uInt16 index)942 sal_uInt16 MethodList::getMethodParamCount(sal_uInt16 index)
943 {
944     sal_uInt16 aCount = 0;
945 
946     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
947     {
948         aCount = readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT);
949     }
950 
951     return aCount;
952 }
953 
getMethodParamType(sal_uInt16 index,sal_uInt16 paramIndex)954 const sal_Char* MethodList::getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex)
955 {
956     const sal_Char* aName = NULL;
957 
958     if ((m_numOfEntries > 0) &&
959 		(index <= m_numOfEntries) &&
960 		(paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
961     {
962         aName = m_pCP->readUTF8NameConstant(
963             readUINT16(
964                 m_pIndex[index] +
965                 calcMethodParamIndex(paramIndex) +
966                 PARAM_OFFSET_TYPE));
967     }
968 
969     return aName;
970 }
971 
getMethodParamName(sal_uInt16 index,sal_uInt16 paramIndex)972 const sal_Char* MethodList::getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex)
973 {
974     const sal_Char* aName = NULL;
975 
976     if ((m_numOfEntries > 0) &&
977 		(index <= m_numOfEntries) &&
978 		(paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
979     {
980         aName = m_pCP->readUTF8NameConstant(
981             readUINT16(
982                 m_pIndex[index] +
983                 calcMethodParamIndex(paramIndex) +
984                 PARAM_OFFSET_NAME));
985     }
986 
987     return aName;
988 }
989 
getMethodParamMode(sal_uInt16 index,sal_uInt16 paramIndex)990 RTParamMode MethodList::getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex)
991 {
992     RTParamMode aMode = RT_PARAM_INVALID;
993 
994     if ((m_numOfEntries > 0) &&
995     	(index <= m_numOfEntries) &&
996 		(paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
997     {
998         aMode = (RTParamMode) readUINT16(
999                 m_pIndex[index] +
1000                 calcMethodParamIndex(paramIndex) +
1001                 PARAM_OFFSET_MODE);
1002     }
1003 
1004     return aMode;
1005 }
1006 
getMethodExcCount(sal_uInt16 index)1007 sal_uInt16 MethodList::getMethodExcCount(sal_uInt16 index)
1008 {
1009     sal_uInt16 aCount = 0;
1010 
1011     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
1012     {
1013         aCount = readUINT16(m_pIndex[index] + calcMethodParamIndex(readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)));
1014     }
1015 
1016     return aCount;
1017 }
1018 
getMethodExcType(sal_uInt16 index,sal_uInt16 excIndex)1019 const sal_Char* MethodList::getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex)
1020 {
1021     const sal_Char* aName = NULL;
1022 
1023     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
1024     {
1025         sal_uInt32 excOffset = m_pIndex[index] + calcMethodParamIndex(readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT));
1026 
1027         if (excIndex <= readUINT16(excOffset))
1028         {
1029             aName = m_pCP->readUTF8NameConstant(
1030                 readUINT16(
1031                     excOffset +
1032                     sizeof(sal_uInt16) +
1033                     (excIndex * sizeof(sal_uInt16))));
1034         }
1035     }
1036 
1037     return aName;
1038 }
1039 
getMethodReturnType(sal_uInt16 index)1040 const sal_Char* MethodList::getMethodReturnType(sal_uInt16 index)
1041 {
1042     const sal_Char* aName = NULL;
1043 
1044     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
1045     {
1046         aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_RETURN));
1047     }
1048 
1049     return aName;
1050 }
1051 
getMethodMode(sal_uInt16 index)1052 RTMethodMode MethodList::getMethodMode(sal_uInt16 index)
1053 {
1054     RTMethodMode aMode = RT_MODE_INVALID;
1055 
1056     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
1057     {
1058         aMode = (RTMethodMode) readUINT16(m_pIndex[index] + METHOD_OFFSET_MODE);
1059     }
1060 
1061     return aMode;
1062 }
1063 
getMethodDoku(sal_uInt16 index)1064 const sal_Char* MethodList::getMethodDoku(sal_uInt16 index)
1065 {
1066     const sal_Char* aDoku = NULL;
1067 
1068     if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
1069     {
1070         aDoku = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_DOKU));
1071     }
1072 
1073     return aDoku;
1074 }
1075 
1076 /**************************************************************************
1077 
1078     class TypeRegistryEntry
1079 
1080 **************************************************************************/
1081 
1082 class TypeRegistryEntry: public BlopObject {
1083 public:
1084     ConstantPool*   m_pCP;
1085     FieldList*      m_pFields;
1086     MethodList*     m_pMethods;
1087     ReferenceList*  m_pReferences;
1088     sal_uInt32      m_refCount;
1089 	sal_uInt16		m_nSuperTypes;
1090 	sal_uInt16		m_offset_SUPERTYPES;
1091 
1092     TypeRegistryEntry(
1093         const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer);
1094         // throws std::bad_alloc
1095 
1096     ~TypeRegistryEntry();
1097 
1098     typereg_Version getVersion() const;
1099 };
1100 
TypeRegistryEntry(const sal_uInt8 * buffer,sal_uInt32 len,sal_Bool copyBuffer)1101 TypeRegistryEntry::TypeRegistryEntry(
1102     const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer):
1103     BlopObject(buffer, len, copyBuffer), m_pCP(NULL), m_pFields(NULL),
1104     m_pMethods(NULL), m_pReferences(NULL), m_refCount(1), m_nSuperTypes(0),
1105     m_offset_SUPERTYPES(0)
1106 {
1107     std::size_t const entrySize = sizeof(sal_uInt16);
1108 	sal_uInt16 nHeaderEntries = readUINT16(OFFSET_N_ENTRIES);
1109 	sal_uInt16 offset_N_SUPERTYPES = OFFSET_N_ENTRIES + entrySize + (nHeaderEntries * entrySize);
1110 	m_offset_SUPERTYPES = offset_N_SUPERTYPES + entrySize;
1111 	m_nSuperTypes = readUINT16(offset_N_SUPERTYPES);
1112 
1113 	sal_uInt16 offset_CP_SIZE = m_offset_SUPERTYPES + (m_nSuperTypes * entrySize);
1114 	sal_uInt16 offset_CP = offset_CP_SIZE + entrySize;
1115 
1116     m_pCP = new ConstantPool(m_pBuffer + offset_CP, readUINT16(offset_CP_SIZE));
1117 
1118     sal_uInt32 offset = offset_CP + m_pCP->parseIndex();
1119 
1120     m_pFields = new FieldList(
1121         m_pBuffer + offset + entrySize, readUINT16(offset), m_pCP);
1122 
1123     offset += sizeof(sal_uInt16) + m_pFields->parseIndex();
1124 
1125     m_pMethods = new MethodList(
1126         m_pBuffer + offset + entrySize, readUINT16(offset), m_pCP);
1127 
1128     offset += sizeof(sal_uInt16) + m_pMethods->parseIndex();
1129 
1130     m_pReferences = new ReferenceList(
1131         m_pBuffer + offset + entrySize, readUINT16(offset), m_pCP);
1132 
1133     m_pReferences->parseIndex();
1134 }
1135 
~TypeRegistryEntry()1136 TypeRegistryEntry::~TypeRegistryEntry()
1137 {
1138     delete m_pCP;
1139     delete m_pFields;
1140     delete m_pMethods;
1141     delete m_pReferences;
1142 }
1143 
getVersion() const1144 typereg_Version TypeRegistryEntry::getVersion() const {
1145     // Assumes two's complement arithmetic with modulo-semantics:
1146     return static_cast< typereg_Version >(readUINT32(OFFSET_MAGIC) - magic);
1147 }
1148 
1149 /**************************************************************************
1150 
1151     C-API
1152 
1153 **************************************************************************/
1154 
1155 extern "C" {
1156 
typereg_reader_create(void const * buffer,sal_uInt32 length,sal_Bool copy,typereg_Version maxVersion,void ** result)1157 sal_Bool typereg_reader_create(
1158     void const * buffer, sal_uInt32 length, sal_Bool copy,
1159     typereg_Version maxVersion, void ** result)
1160     SAL_THROW_EXTERN_C()
1161 {
1162     if (length < OFFSET_CP || length > SAL_MAX_UINT32) {
1163         *result = 0;
1164         return true;
1165     }
1166     std::auto_ptr< TypeRegistryEntry > entry;
1167     try {
1168         entry.reset(
1169             new TypeRegistryEntry(
1170                 static_cast< sal_uInt8 const * >(buffer),
1171                 static_cast< sal_uInt32 >(length), copy));
1172     } catch (std::bad_alloc &) {
1173         return false;
1174     }
1175     if (entry->readUINT32(OFFSET_SIZE) != length) {
1176         *result = 0;
1177         return true;
1178     }
1179     typereg_Version version = entry->getVersion();
1180     if (version < TYPEREG_VERSION_0 || version > maxVersion) {
1181         *result = 0;
1182         return true;
1183     }
1184     *result = entry.release();
1185     return true;
1186 }
1187 
createEntry(const sal_uInt8 * buffer,sal_uInt32 len,sal_Bool copyBuffer)1188 static TypeReaderImpl TYPEREG_CALLTYPE createEntry(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer)
1189 {
1190     void * handle;
1191     typereg_reader_create(buffer, len, copyBuffer, TYPEREG_VERSION_0, &handle);
1192     return handle;
1193 }
1194 
typereg_reader_acquire(void * hEntry)1195 void typereg_reader_acquire(void * hEntry) SAL_THROW_EXTERN_C()
1196 {
1197     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1198 
1199     if (pEntry != NULL)
1200         pEntry->m_refCount++;
1201 }
1202 
typereg_reader_release(void * hEntry)1203 void typereg_reader_release(void * hEntry) SAL_THROW_EXTERN_C()
1204 {
1205     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1206 
1207     if (pEntry != NULL)
1208     {
1209         if (--pEntry->m_refCount == 0)
1210             delete pEntry;
1211     }
1212 }
1213 
typereg_reader_getVersion(void * handle)1214 typereg_Version typereg_reader_getVersion(void * handle) SAL_THROW_EXTERN_C() {
1215     return handle == 0
1216         ? TYPEREG_VERSION_0
1217         : static_cast< TypeRegistryEntry * >(handle)->getVersion();
1218 }
1219 
getMinorVersion(TypeReaderImpl hEntry)1220 static sal_uInt16 TYPEREG_CALLTYPE getMinorVersion(TypeReaderImpl hEntry)
1221 {
1222     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1223 
1224     if (pEntry == NULL) return 0;
1225 
1226     return pEntry->readUINT16(OFFSET_MINOR_VERSION);
1227 }
1228 
getMajorVersion(TypeReaderImpl hEntry)1229 static sal_uInt16 TYPEREG_CALLTYPE getMajorVersion(TypeReaderImpl hEntry)
1230 {
1231     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1232 
1233     if (pEntry == NULL) return 0;
1234 
1235     return pEntry->readUINT16(OFFSET_MAJOR_VERSION);
1236 }
1237 
typereg_reader_getTypeClass(void * hEntry)1238 RTTypeClass typereg_reader_getTypeClass(void * hEntry) SAL_THROW_EXTERN_C()
1239 {
1240     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1241 
1242     if (pEntry == NULL) return RT_TYPE_INVALID;
1243 
1244     return (RTTypeClass)
1245         (pEntry->readUINT16(OFFSET_TYPE_CLASS) & ~RT_TYPE_PUBLISHED);
1246 }
1247 
typereg_reader_isPublished(void * hEntry)1248 sal_Bool typereg_reader_isPublished(void * hEntry) SAL_THROW_EXTERN_C()
1249 {
1250     TypeRegistryEntry * entry = static_cast< TypeRegistryEntry * >(hEntry);
1251     return entry != 0
1252         && (entry->readUINT16(OFFSET_TYPE_CLASS) & RT_TYPE_PUBLISHED) != 0;
1253 }
1254 
typereg_reader_getTypeName(void * hEntry,rtl_uString ** pTypeName)1255 void typereg_reader_getTypeName(void * hEntry, rtl_uString** pTypeName)
1256     SAL_THROW_EXTERN_C()
1257 {
1258     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1259 
1260     if (pEntry == NULL)
1261 	{
1262 		rtl_uString_new(pTypeName);
1263 		return;
1264 	}
1265 
1266     const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_THIS_TYPE));
1267     rtl_string2UString(
1268         pTypeName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1269         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1270 }
1271 
1272 
getSuperTypeName(TypeReaderImpl hEntry,rtl_uString ** pSuperTypeName)1273 static void TYPEREG_CALLTYPE getSuperTypeName(TypeReaderImpl hEntry, rtl_uString** pSuperTypeName)
1274 {
1275     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1276 
1277     if (pEntry == NULL)
1278 	{
1279 		rtl_uString_new(pSuperTypeName);
1280 		return;
1281 	}
1282 
1283     if (pEntry->m_nSuperTypes == 0)
1284 	{
1285 		rtl_uString_new(pSuperTypeName);
1286 		return;
1287 	}
1288 
1289     const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(pEntry->m_offset_SUPERTYPES )); //+ (index * sizeof(sal_uInt16))));
1290     rtl_string2UString(
1291         pSuperTypeName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1292         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1293 }
1294 
getUik(TypeReaderImpl hEntry,RTUik * uik)1295 static void TYPEREG_CALLTYPE getUik(TypeReaderImpl hEntry, RTUik* uik)
1296 {
1297     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1298 
1299     if (pEntry != NULL)
1300     {
1301         pEntry->m_pCP->readUIK(pEntry->readUINT16(OFFSET_UIK), uik);
1302     }
1303 }
1304 
typereg_reader_getDocumentation(void * hEntry,rtl_uString ** pDoku)1305 void typereg_reader_getDocumentation(void * hEntry, rtl_uString** pDoku)
1306     SAL_THROW_EXTERN_C()
1307 {
1308     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1309 
1310     if (pEntry == NULL)
1311 	{
1312 		rtl_uString_new(pDoku);
1313 		return;
1314 	}
1315 
1316     const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_DOKU));
1317     rtl_string2UString(
1318         pDoku, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1319         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1320 }
1321 
typereg_reader_getFileName(void * hEntry,rtl_uString ** pFileName)1322 void typereg_reader_getFileName(void * hEntry, rtl_uString** pFileName)
1323     SAL_THROW_EXTERN_C()
1324 {
1325     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1326 
1327     if (pEntry == NULL)
1328 	{
1329 		rtl_uString_new(pFileName);
1330 		return;
1331 	}
1332 
1333     const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_FILENAME));
1334     rtl_string2UString(
1335         pFileName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1336         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1337 }
1338 
1339 
typereg_reader_getFieldCount(void * hEntry)1340 sal_uInt16 typereg_reader_getFieldCount(void * hEntry) SAL_THROW_EXTERN_C()
1341 {
1342     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1343 
1344     if (pEntry == NULL) return 0;
1345 
1346     return pEntry->m_pFields->m_numOfEntries;
1347 }
1348 
getFieldCount(TypeReaderImpl hEntry)1349 static sal_uInt32 TYPEREG_CALLTYPE getFieldCount(TypeReaderImpl hEntry)
1350 {
1351     return typereg_reader_getFieldCount(hEntry);
1352 }
1353 
typereg_reader_getFieldName(void * hEntry,rtl_uString ** pFieldName,sal_uInt16 index)1354 void typereg_reader_getFieldName(void * hEntry, rtl_uString** pFieldName, sal_uInt16 index)
1355     SAL_THROW_EXTERN_C()
1356 {
1357     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1358 
1359     if (pEntry == NULL)
1360 	{
1361 		rtl_uString_new(pFieldName);
1362 		return;
1363 	}
1364     const sal_Char* pTmp = pEntry->m_pFields->getFieldName(index);
1365     rtl_string2UString(
1366         pFieldName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1367         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1368 }
1369 
typereg_reader_getFieldTypeName(void * hEntry,rtl_uString ** pFieldType,sal_uInt16 index)1370 void typereg_reader_getFieldTypeName(void * hEntry, rtl_uString** pFieldType, sal_uInt16 index)
1371     SAL_THROW_EXTERN_C()
1372 {
1373     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1374 
1375     if (pEntry == NULL)
1376 	{
1377 		rtl_uString_new(pFieldType);
1378 		return;
1379 	}
1380 
1381     const sal_Char* pTmp = pEntry->m_pFields->getFieldType(index);
1382     rtl_string2UString(
1383         pFieldType, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1384         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1385 }
1386 
typereg_reader_getFieldFlags(void * hEntry,sal_uInt16 index)1387 RTFieldAccess typereg_reader_getFieldFlags(void * hEntry, sal_uInt16 index)
1388     SAL_THROW_EXTERN_C()
1389 {
1390     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1391 
1392     if (pEntry == NULL) return RT_ACCESS_INVALID;
1393 
1394     return pEntry->m_pFields->getFieldAccess(index);
1395 }
1396 
typereg_reader_getFieldValue(void * hEntry,sal_uInt16 index,RTValueType * type,RTConstValueUnion * value)1397 sal_Bool typereg_reader_getFieldValue(
1398     void * hEntry, sal_uInt16 index, RTValueType * type,
1399     RTConstValueUnion * value)
1400     SAL_THROW_EXTERN_C()
1401 {
1402     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1403 
1404     if (pEntry == NULL) {
1405         *type = RT_TYPE_NONE;
1406         return true;
1407     }
1408 
1409     try {
1410         *type = pEntry->m_pFields->getFieldConstValue(index, value);
1411     } catch (std::bad_alloc &) {
1412         return false;
1413     }
1414     return true;
1415 }
1416 
getFieldConstValue(TypeReaderImpl hEntry,sal_uInt16 index,RTConstValueUnion * value)1417 static RTValueType TYPEREG_CALLTYPE getFieldConstValue(TypeReaderImpl hEntry, sal_uInt16 index, RTConstValueUnion* value)
1418 {
1419     RTValueType t = RT_TYPE_NONE;
1420     typereg_reader_getFieldValue(hEntry, index, &t, value);
1421     return t;
1422 }
1423 
typereg_reader_getFieldDocumentation(void * hEntry,rtl_uString ** pDoku,sal_uInt16 index)1424 void typereg_reader_getFieldDocumentation(void * hEntry, rtl_uString** pDoku, sal_uInt16 index)
1425     SAL_THROW_EXTERN_C()
1426 {
1427     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1428 
1429     if (pEntry == NULL)
1430 	{
1431 		rtl_uString_new(pDoku);
1432 		return;
1433 	}
1434 
1435     const sal_Char* pTmp = pEntry->m_pFields->getFieldDoku(index);
1436     rtl_string2UString(
1437         pDoku, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1438         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1439 }
1440 
typereg_reader_getFieldFileName(void * hEntry,rtl_uString ** pFieldFileName,sal_uInt16 index)1441 void typereg_reader_getFieldFileName(void * hEntry, rtl_uString** pFieldFileName, sal_uInt16 index)
1442     SAL_THROW_EXTERN_C()
1443 {
1444     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1445 
1446     if (pEntry == NULL)
1447 	{
1448 		rtl_uString_new(pFieldFileName);
1449 		return;
1450 	}
1451 
1452     const sal_Char* pTmp = pEntry->m_pFields->getFieldFileName(index);
1453     rtl_string2UString(
1454         pFieldFileName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1455         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1456 }
1457 
1458 
typereg_reader_getMethodCount(void * hEntry)1459 sal_uInt16 typereg_reader_getMethodCount(void * hEntry) SAL_THROW_EXTERN_C()
1460 {
1461     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1462 
1463     if (pEntry == NULL) return 0;
1464 
1465     return pEntry->m_pMethods->m_numOfEntries;
1466 }
1467 
getMethodCount(TypeReaderImpl hEntry)1468 static sal_uInt32 TYPEREG_CALLTYPE getMethodCount(TypeReaderImpl hEntry)
1469 {
1470     return typereg_reader_getMethodCount(hEntry);
1471 }
1472 
typereg_reader_getMethodName(void * hEntry,rtl_uString ** pMethodName,sal_uInt16 index)1473 void typereg_reader_getMethodName(void * hEntry, rtl_uString** pMethodName, sal_uInt16 index)
1474     SAL_THROW_EXTERN_C()
1475 {
1476     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1477 
1478     if (pEntry == NULL)
1479 	{
1480 		rtl_uString_new(pMethodName);
1481 		return;
1482 	}
1483 
1484     const sal_Char* pTmp = pEntry->m_pMethods->getMethodName(index);
1485     rtl_string2UString(
1486         pMethodName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1487         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1488 }
1489 
typereg_reader_getMethodParameterCount(void * hEntry,sal_uInt16 index)1490 sal_uInt16 typereg_reader_getMethodParameterCount(
1491     void * hEntry, sal_uInt16 index) SAL_THROW_EXTERN_C()
1492 {
1493     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1494 
1495     if (pEntry == NULL) return 0;
1496 
1497     return pEntry->m_pMethods->getMethodParamCount(index);
1498 }
1499 
getMethodParamCount(TypeReaderImpl hEntry,sal_uInt16 index)1500 static sal_uInt32 TYPEREG_CALLTYPE getMethodParamCount(TypeReaderImpl hEntry, sal_uInt16 index)
1501 {
1502     return typereg_reader_getMethodParameterCount(hEntry, index);
1503 }
1504 
typereg_reader_getMethodParameterTypeName(void * hEntry,rtl_uString ** pMethodParamType,sal_uInt16 index,sal_uInt16 paramIndex)1505 void typereg_reader_getMethodParameterTypeName(void * hEntry, rtl_uString** pMethodParamType, sal_uInt16 index, sal_uInt16 paramIndex)
1506     SAL_THROW_EXTERN_C()
1507 {
1508     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1509 
1510     if (pEntry == NULL)
1511 	{
1512 		rtl_uString_new(pMethodParamType);
1513 		return;
1514 	}
1515 
1516     const sal_Char* pTmp = pEntry->m_pMethods->getMethodParamType(index, paramIndex);
1517     rtl_string2UString(
1518         pMethodParamType, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1519         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1520 }
1521 
typereg_reader_getMethodParameterName(void * hEntry,rtl_uString ** pMethodParamName,sal_uInt16 index,sal_uInt16 paramIndex)1522 void typereg_reader_getMethodParameterName(void * hEntry, rtl_uString** pMethodParamName, sal_uInt16 index, sal_uInt16 paramIndex)
1523     SAL_THROW_EXTERN_C()
1524 {
1525     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1526 
1527     if (pEntry == NULL)
1528 	{
1529 		rtl_uString_new(pMethodParamName);
1530 		return;
1531 	}
1532 
1533     const sal_Char* pTmp = pEntry->m_pMethods->getMethodParamName(index, paramIndex);
1534     rtl_string2UString(
1535         pMethodParamName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1536         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1537 }
1538 
typereg_reader_getMethodParameterFlags(void * hEntry,sal_uInt16 index,sal_uInt16 paramIndex)1539 RTParamMode typereg_reader_getMethodParameterFlags(void * hEntry, sal_uInt16 index, sal_uInt16 paramIndex)
1540     SAL_THROW_EXTERN_C()
1541 {
1542     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1543 
1544     if (pEntry == NULL) return RT_PARAM_INVALID;
1545 
1546     return pEntry->m_pMethods->getMethodParamMode(index, paramIndex);
1547 }
1548 
typereg_reader_getMethodExceptionCount(void * hEntry,sal_uInt16 index)1549 sal_uInt16 typereg_reader_getMethodExceptionCount(
1550     void * hEntry, sal_uInt16 index) SAL_THROW_EXTERN_C()
1551 {
1552     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1553 
1554     if (pEntry == NULL) return 0;
1555 
1556     return pEntry->m_pMethods->getMethodExcCount(index);
1557 }
1558 
getMethodExcCount(TypeReaderImpl hEntry,sal_uInt16 index)1559 static sal_uInt32 TYPEREG_CALLTYPE getMethodExcCount(TypeReaderImpl hEntry, sal_uInt16 index)
1560 {
1561     return typereg_reader_getMethodExceptionCount(hEntry, index);
1562 }
1563 
typereg_reader_getMethodExceptionTypeName(void * hEntry,rtl_uString ** pMethodExcpType,sal_uInt16 index,sal_uInt16 excIndex)1564 void typereg_reader_getMethodExceptionTypeName(void * hEntry, rtl_uString** pMethodExcpType, sal_uInt16 index, sal_uInt16 excIndex)
1565     SAL_THROW_EXTERN_C()
1566 {
1567     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1568 
1569     if (pEntry == NULL)
1570 	{
1571 		rtl_uString_new(pMethodExcpType);
1572 		return;
1573 	}
1574 
1575     const sal_Char* pTmp = pEntry->m_pMethods->getMethodExcType(index, excIndex);
1576     rtl_string2UString(
1577         pMethodExcpType, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1578         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1579 }
1580 
typereg_reader_getMethodReturnTypeName(void * hEntry,rtl_uString ** pMethodReturnType,sal_uInt16 index)1581 void typereg_reader_getMethodReturnTypeName(void * hEntry, rtl_uString** pMethodReturnType, sal_uInt16 index)
1582     SAL_THROW_EXTERN_C()
1583 {
1584     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1585 
1586     if (pEntry == NULL)
1587 	{
1588 		rtl_uString_new(pMethodReturnType);
1589 		return;
1590 	}
1591 
1592     const sal_Char* pTmp = pEntry->m_pMethods->getMethodReturnType(index);
1593     rtl_string2UString(
1594         pMethodReturnType, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1595         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1596 }
1597 
typereg_reader_getMethodFlags(void * hEntry,sal_uInt16 index)1598 RTMethodMode typereg_reader_getMethodFlags(void * hEntry, sal_uInt16 index)
1599     SAL_THROW_EXTERN_C()
1600 {
1601     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1602 
1603     if (pEntry == NULL) return RT_MODE_INVALID;
1604 
1605     return pEntry->m_pMethods->getMethodMode(index);
1606 }
1607 
typereg_reader_getMethodDocumentation(void * hEntry,rtl_uString ** pMethodDoku,sal_uInt16 index)1608 void typereg_reader_getMethodDocumentation(void * hEntry, rtl_uString** pMethodDoku, sal_uInt16 index)
1609     SAL_THROW_EXTERN_C()
1610 {
1611     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1612 
1613     if (pEntry == NULL)
1614 	{
1615 		rtl_uString_new(pMethodDoku);
1616 		return;
1617 	}
1618 
1619     const sal_Char* pTmp = pEntry->m_pMethods->getMethodDoku(index);
1620     rtl_string2UString(
1621         pMethodDoku, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1622         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1623 }
1624 
typereg_reader_getReferenceCount(void * hEntry)1625 sal_uInt16 typereg_reader_getReferenceCount(void * hEntry) SAL_THROW_EXTERN_C()
1626 {
1627     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1628 
1629     if (pEntry == NULL) return 0;
1630 
1631     return pEntry->m_pReferences->m_numOfEntries;
1632 }
1633 
getReferenceCount(TypeReaderImpl hEntry)1634 static sal_uInt32 TYPEREG_CALLTYPE getReferenceCount(TypeReaderImpl hEntry)
1635 {
1636     return typereg_reader_getReferenceCount(hEntry);
1637 }
1638 
typereg_reader_getReferenceTypeName(void * hEntry,rtl_uString ** pReferenceName,sal_uInt16 index)1639 void typereg_reader_getReferenceTypeName(void * hEntry, rtl_uString** pReferenceName, sal_uInt16 index)
1640     SAL_THROW_EXTERN_C()
1641 {
1642     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1643 
1644     if (pEntry == NULL)
1645 	{
1646 		rtl_uString_new(pReferenceName);
1647 		return;
1648 	}
1649 
1650     const sal_Char* pTmp = pEntry->m_pReferences->getReferenceName(index);
1651     rtl_string2UString(
1652         pReferenceName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1653         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1654 }
1655 
typereg_reader_getReferenceSort(void * hEntry,sal_uInt16 index)1656 RTReferenceType typereg_reader_getReferenceSort(void * hEntry, sal_uInt16 index)
1657     SAL_THROW_EXTERN_C()
1658 {
1659     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1660 
1661     if (pEntry == NULL) return RT_REF_INVALID;
1662 
1663     return pEntry->m_pReferences->getReferenceType(index);
1664 }
1665 
typereg_reader_getReferenceDocumentation(void * hEntry,rtl_uString ** pReferenceDoku,sal_uInt16 index)1666 void typereg_reader_getReferenceDocumentation(void * hEntry, rtl_uString** pReferenceDoku, sal_uInt16 index)
1667     SAL_THROW_EXTERN_C()
1668 {
1669     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1670 
1671     if (pEntry == NULL)
1672 	{
1673 		rtl_uString_new(pReferenceDoku);
1674 		return;
1675 	}
1676 
1677     const sal_Char* pTmp = pEntry->m_pReferences->getReferenceDoku(index);
1678     rtl_string2UString(
1679         pReferenceDoku, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1680         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1681 }
1682 
typereg_reader_getReferenceFlags(void * hEntry,sal_uInt16 index)1683 RTFieldAccess typereg_reader_getReferenceFlags(void * hEntry, sal_uInt16 index)
1684     SAL_THROW_EXTERN_C()
1685 {
1686     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1687 
1688     if (pEntry == NULL) return RT_ACCESS_INVALID;
1689 
1690     return pEntry->m_pReferences->getReferenceAccess(index);
1691 }
1692 
typereg_reader_getSuperTypeCount(void * hEntry)1693 sal_uInt16 typereg_reader_getSuperTypeCount(void * hEntry)
1694     SAL_THROW_EXTERN_C()
1695 {
1696     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1697 
1698     if (pEntry == NULL) return 0;
1699 
1700     return pEntry->m_nSuperTypes;
1701 }
1702 
typereg_reader_getSuperTypeName(void * hEntry,rtl_uString ** pSuperTypeName,sal_uInt16 index)1703 void typereg_reader_getSuperTypeName(
1704     void * hEntry, rtl_uString ** pSuperTypeName, sal_uInt16 index)
1705     SAL_THROW_EXTERN_C()
1706 {
1707     TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry;
1708 
1709     if (pEntry == NULL)
1710 	{
1711 		rtl_uString_new(pSuperTypeName);
1712 		return;
1713 	}
1714 
1715     OSL_ASSERT(index < pEntry->m_nSuperTypes);
1716     const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(pEntry->m_offset_SUPERTYPES + (index * sizeof(sal_uInt16))));
1717     rtl_string2UString(
1718         pSuperTypeName, pTmp, pTmp == 0 ? 0 : rtl_str_getLength(pTmp),
1719         RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
1720 }
1721 
initRegistryTypeReader_Api(void)1722 RegistryTypeReader_Api* TYPEREG_CALLTYPE initRegistryTypeReader_Api(void)
1723 {
1724     static RegistryTypeReader_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1725     if (!aApi.acquire)
1726     {
1727         aApi.createEntry            = &createEntry;
1728         aApi.acquire                = &typereg_reader_acquire;
1729         aApi.release                = &typereg_reader_release;
1730         aApi.getMinorVersion        = &getMinorVersion;
1731         aApi.getMajorVersion        = &getMajorVersion;
1732         aApi.getTypeClass           = &typereg_reader_getTypeClass;
1733         aApi.getTypeName            = &typereg_reader_getTypeName;
1734         aApi.getSuperTypeName       = &getSuperTypeName;
1735         aApi.getUik                 = &getUik;
1736         aApi.getDoku                = &typereg_reader_getDocumentation;
1737         aApi.getFileName            = &typereg_reader_getFileName;
1738         aApi.getFieldCount          = &getFieldCount;
1739         aApi.getFieldName           = &typereg_reader_getFieldName;
1740         aApi.getFieldType           = &typereg_reader_getFieldTypeName;
1741         aApi.getFieldAccess         = &typereg_reader_getFieldFlags;
1742         aApi.getFieldConstValue     = &getFieldConstValue;
1743         aApi.getFieldDoku           = &typereg_reader_getFieldDocumentation;
1744         aApi.getFieldFileName       = &typereg_reader_getFieldFileName;
1745         aApi.getMethodCount         = &getMethodCount;
1746         aApi.getMethodName          = &typereg_reader_getMethodName;
1747         aApi.getMethodParamCount    = &getMethodParamCount;
1748         aApi.getMethodParamType = &typereg_reader_getMethodParameterTypeName;
1749         aApi.getMethodParamName     = &typereg_reader_getMethodParameterName;
1750         aApi.getMethodParamMode     = &typereg_reader_getMethodParameterFlags;
1751         aApi.getMethodExcCount      = &getMethodExcCount;
1752         aApi.getMethodExcType = &typereg_reader_getMethodExceptionTypeName;
1753         aApi.getMethodReturnType    = &typereg_reader_getMethodReturnTypeName;
1754         aApi.getMethodMode          = &typereg_reader_getMethodFlags;
1755         aApi.getMethodDoku          = &typereg_reader_getMethodDocumentation;
1756         aApi.getReferenceCount      = &getReferenceCount;
1757         aApi.getReferenceName       = &typereg_reader_getReferenceTypeName;
1758         aApi.getReferenceType       = &typereg_reader_getReferenceSort;
1759         aApi.getReferenceDoku       = &typereg_reader_getReferenceDocumentation;
1760         aApi.getReferenceAccess     = &typereg_reader_getReferenceFlags;
1761 
1762         return (&aApi);
1763     }
1764     else
1765     {
1766         return (&aApi);
1767     }
1768 }
1769 
1770 }
1771