1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_REGISTRY_SOURCE_REFLCNST_HXX
21 #define INCLUDED_REGISTRY_SOURCE_REFLCNST_HXX
23 #include <registry/types.hxx>
27 #define REGTYPE_IEEE_NATIVE 1
29 extern const sal_uInt32 magic
;
30 extern const sal_uInt16 minorVersion
;
31 extern const sal_uInt16 majorVersion
;
33 #define OFFSET_MAGIC 0
34 #define OFFSET_SIZE static_cast<sal_uInt32>(OFFSET_MAGIC + sizeof(magic))
35 #define OFFSET_MINOR_VERSION static_cast<sal_uInt32>(OFFSET_SIZE + sizeof(sal_uInt32))
36 #define OFFSET_MAJOR_VERSION static_cast<sal_uInt32>(OFFSET_MINOR_VERSION + sizeof(minorVersion))
37 #define OFFSET_N_ENTRIES static_cast<sal_uInt32>(OFFSET_MAJOR_VERSION + sizeof(majorVersion))
38 #define OFFSET_TYPE_SOURCE static_cast<sal_uInt32>(OFFSET_N_ENTRIES + sizeof(sal_uInt16))
39 #define OFFSET_TYPE_CLASS static_cast<sal_uInt32>(OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
40 #define OFFSET_THIS_TYPE static_cast<sal_uInt32>(OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
41 #define OFFSET_UIK static_cast<sal_uInt32>(OFFSET_THIS_TYPE + sizeof(sal_uInt16))
42 #define OFFSET_DOKU static_cast<sal_uInt32>(OFFSET_UIK + sizeof(sal_uInt16))
43 #define OFFSET_FILENAME static_cast<sal_uInt32>(OFFSET_DOKU + sizeof(sal_uInt16))
45 #define OFFSET_N_SUPERTYPES static_cast<sal_uInt32>(OFFSET_FILENAME + sizeof(sal_uInt16))
46 #define OFFSET_SUPERTYPES static_cast<sal_uInt32>(OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
48 #define OFFSET_CP_SIZE static_cast<sal_uInt32>(OFFSET_SUPERTYPES + sizeof(sal_uInt16))
49 #define OFFSET_CP static_cast<sal_uInt32>(OFFSET_CP_SIZE + sizeof(sal_uInt16))
51 #define CP_OFFSET_ENTRY_SIZE 0
52 #define CP_OFFSET_ENTRY_TAG static_cast<sal_uInt32>(CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32))
53 #define CP_OFFSET_ENTRY_DATA static_cast<sal_uInt32>(CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16))
54 #define CP_OFFSET_ENTRY_UIK1 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_DATA)
55 #define CP_OFFSET_ENTRY_UIK2 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32))
56 #define CP_OFFSET_ENTRY_UIK3 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16))
57 #define CP_OFFSET_ENTRY_UIK4 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16))
58 #define CP_OFFSET_ENTRY_UIK5 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32))
60 #define FIELD_OFFSET_ACCESS 0
61 #define FIELD_OFFSET_NAME static_cast<sal_uInt32>(FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
62 #define FIELD_OFFSET_TYPE static_cast<sal_uInt32>(FIELD_OFFSET_NAME + sizeof(sal_uInt16))
63 #define FIELD_OFFSET_VALUE static_cast<sal_uInt32>(FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
64 #define FIELD_OFFSET_DOKU static_cast<sal_uInt32>(FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
65 #define FIELD_OFFSET_FILENAME static_cast<sal_uInt32>(FIELD_OFFSET_DOKU + sizeof(sal_uInt16))
67 #define PARAM_OFFSET_TYPE 0
68 #define PARAM_OFFSET_MODE static_cast<sal_uInt32>(PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
69 #define PARAM_OFFSET_NAME static_cast<sal_uInt32>(PARAM_OFFSET_MODE + sizeof(sal_uInt16))
71 #define METHOD_OFFSET_SIZE 0
72 #define METHOD_OFFSET_MODE static_cast<sal_uInt32>(METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
73 #define METHOD_OFFSET_NAME static_cast<sal_uInt32>(METHOD_OFFSET_MODE + sizeof(sal_uInt16))
74 #define METHOD_OFFSET_RETURN static_cast<sal_uInt32>(METHOD_OFFSET_NAME + sizeof(sal_uInt16))
75 #define METHOD_OFFSET_DOKU static_cast<sal_uInt32>(METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
76 #define METHOD_OFFSET_PARAM_COUNT static_cast<sal_uInt32>(METHOD_OFFSET_DOKU + sizeof(sal_uInt16))
78 #define REFERENCE_OFFSET_TYPE 0
79 #define REFERENCE_OFFSET_NAME static_cast<sal_uInt32>(REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
80 #define REFERENCE_OFFSET_DOKU static_cast<sal_uInt32>(REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
81 #define REFERENCE_OFFSET_ACCESS static_cast<sal_uInt32>(REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16))
85 CP_TAG_INVALID
= RT_TYPE_NONE
,
86 CP_TAG_CONST_BOOL
= RT_TYPE_BOOL
,
87 CP_TAG_CONST_BYTE
= RT_TYPE_BYTE
,
88 CP_TAG_CONST_INT16
= RT_TYPE_INT16
,
89 CP_TAG_CONST_UINT16
= RT_TYPE_UINT16
,
90 CP_TAG_CONST_INT32
= RT_TYPE_INT32
,
91 CP_TAG_CONST_UINT32
= RT_TYPE_UINT32
,
92 CP_TAG_CONST_INT64
= RT_TYPE_INT64
,
93 CP_TAG_CONST_UINT64
= RT_TYPE_UINT64
,
94 CP_TAG_CONST_FLOAT
= RT_TYPE_FLOAT
,
95 CP_TAG_CONST_DOUBLE
= RT_TYPE_DOUBLE
,
96 CP_TAG_CONST_STRING
= RT_TYPE_STRING
,
101 inline sal_uInt32
writeBYTE(sal_uInt8
* buffer
, sal_uInt8 v
)
105 return sizeof(sal_uInt8
);
108 inline sal_uInt32
writeINT16(sal_uInt8
* buffer
, sal_Int16 v
)
110 buffer
[0] = static_cast<sal_uInt8
>((v
>> 8) & 0xFF);
111 buffer
[1] = static_cast<sal_uInt8
>((v
>> 0) & 0xFF);
113 return sizeof(sal_Int16
);
116 inline sal_uInt32
writeUINT16(sal_uInt8
* buffer
, sal_uInt16 v
)
118 buffer
[0] = static_cast<sal_uInt8
>((v
>> 8) & 0xFF);
119 buffer
[1] = static_cast<sal_uInt8
>((v
>> 0) & 0xFF);
121 return sizeof(sal_uInt16
);
124 inline sal_uInt32
readUINT16(const sal_uInt8
* buffer
, sal_uInt16
& v
)
126 //This is untainted data which comes from a controlled source
127 //so, using a byte-swapping pattern which coverity doesn't
129 //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
130 v
= *buffer
++; v
<<= 8;
132 return sizeof(sal_uInt16
);
135 inline sal_uInt32
writeINT32(sal_uInt8
* buffer
, sal_Int32 v
)
137 buffer
[0] = static_cast<sal_uInt8
>((v
>> 24) & 0xFF);
138 buffer
[1] = static_cast<sal_uInt8
>((v
>> 16) & 0xFF);
139 buffer
[2] = static_cast<sal_uInt8
>((v
>> 8) & 0xFF);
140 buffer
[3] = static_cast<sal_uInt8
>((v
>> 0) & 0xFF);
142 return sizeof(sal_Int32
);
145 inline sal_uInt32
readINT32(const sal_uInt8
* buffer
, sal_Int32
& v
)
154 return sizeof(sal_Int32
);
157 inline sal_uInt32
writeUINT32(sal_uInt8
* buffer
, sal_uInt32 v
)
159 buffer
[0] = static_cast<sal_uInt8
>((v
>> 24) & 0xFF);
160 buffer
[1] = static_cast<sal_uInt8
>((v
>> 16) & 0xFF);
161 buffer
[2] = static_cast<sal_uInt8
>((v
>> 8) & 0xFF);
162 buffer
[3] = static_cast<sal_uInt8
>((v
>> 0) & 0xFF);
164 return sizeof(sal_uInt32
);
167 inline sal_uInt32
readUINT32(const sal_uInt8
* buffer
, sal_uInt32
& v
)
169 //This is untainted data which comes from a controlled source
170 //so, using a byte-swapping pattern which coverity doesn't
172 //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
173 v
= *buffer
++; v
<<= 8;
174 v
|= *buffer
++; v
<<= 8;
175 v
|= *buffer
++; v
<<= 8;
177 return sizeof(sal_uInt32
);
180 inline sal_uInt32
writeUINT64(sal_uInt8
* buffer
, sal_uInt64 v
)
182 buffer
[0] = static_cast<sal_uInt8
>((v
>> 56) & 0xFF);
183 buffer
[1] = static_cast<sal_uInt8
>((v
>> 48) & 0xFF);
184 buffer
[2] = static_cast<sal_uInt8
>((v
>> 40) & 0xFF);
185 buffer
[3] = static_cast<sal_uInt8
>((v
>> 32) & 0xFF);
186 buffer
[4] = static_cast<sal_uInt8
>((v
>> 24) & 0xFF);
187 buffer
[5] = static_cast<sal_uInt8
>((v
>> 16) & 0xFF);
188 buffer
[6] = static_cast<sal_uInt8
>((v
>> 8) & 0xFF);
189 buffer
[7] = static_cast<sal_uInt8
>((v
>> 0) & 0xFF);
191 return sizeof(sal_uInt64
);
194 inline sal_uInt32
writeUtf8(sal_uInt8
* buffer
, const sal_Char
* v
)
196 sal_uInt32 size
= strlen(v
) + 1;
198 memcpy(buffer
, v
, size
);
203 inline sal_uInt32
readUtf8(const sal_uInt8
* buffer
, sal_Char
* v
, sal_uInt32 maxSize
)
205 sal_uInt32 size
= strlen(reinterpret_cast<const char*>(buffer
)) + 1;
211 memcpy(v
, buffer
, size
);
213 if (size
== maxSize
) v
[size
- 1] = '\0';
219 sal_uInt32
writeFloat(sal_uInt8
* buffer
, float v
);
220 sal_uInt32
writeDouble(sal_uInt8
* buffer
, double v
);
221 sal_uInt32
writeString(sal_uInt8
* buffer
, const sal_Unicode
* v
);
222 sal_uInt32
readString(const sal_uInt8
* buffer
, sal_Unicode
* v
, sal_uInt32 maxSize
);
224 sal_uInt32
UINT16StringLen(const sal_uInt8
* wstring
);
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */