Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_REGISTRY_SOURCE_REFLCNST_HXX
21 : #define INCLUDED_REGISTRY_SOURCE_REFLCNST_HXX
22 :
23 : #include <registry/refltype.hxx>
24 : #include <sal/macros.h>
25 :
26 : #include <string.h>
27 :
28 : #define REGTYPE_IEEE_NATIVE 1
29 :
30 : extern const sal_uInt32 magic;
31 : extern const sal_uInt16 minorVersion;
32 : extern const sal_uInt16 majorVersion;
33 :
34 : #define OFFSET_MAGIC 0
35 : #define OFFSET_SIZE (OFFSET_MAGIC + sizeof(magic))
36 : #define OFFSET_MINOR_VERSION (OFFSET_SIZE + sizeof(sal_uInt32))
37 : #define OFFSET_MAJOR_VERSION (OFFSET_MINOR_VERSION + sizeof(minorVersion))
38 : #define OFFSET_N_ENTRIES (OFFSET_MAJOR_VERSION + sizeof(sal_uInt16))
39 : #define OFFSET_TYPE_SOURCE (OFFSET_N_ENTRIES + sizeof(sal_uInt16))
40 : #define OFFSET_TYPE_CLASS (OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
41 : #define OFFSET_THIS_TYPE (OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
42 : #define OFFSET_UIK (OFFSET_THIS_TYPE + sizeof(sal_uInt16))
43 : #define OFFSET_DOKU (OFFSET_UIK + sizeof(sal_uInt16))
44 : #define OFFSET_FILENAME (OFFSET_DOKU + sizeof(sal_uInt16))
45 :
46 : #define OFFSET_N_SUPERTYPES (OFFSET_FILENAME + sizeof(sal_uInt16))
47 : #define OFFSET_SUPERTYPES (OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
48 :
49 : #define OFFSET_CP_SIZE (OFFSET_SUPERTYPES + sizeof(sal_uInt16))
50 : #define OFFSET_CP (OFFSET_CP_SIZE + sizeof(sal_uInt16))
51 :
52 : #define CP_OFFSET_ENTRY_SIZE 0
53 : #define CP_OFFSET_ENTRY_TAG (CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32))
54 : #define CP_OFFSET_ENTRY_DATA (CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16))
55 : #define CP_OFFSET_ENTRY_UIK1 CP_OFFSET_ENTRY_DATA
56 : #define CP_OFFSET_ENTRY_UIK2 (CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32))
57 : #define CP_OFFSET_ENTRY_UIK3 (CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16))
58 : #define CP_OFFSET_ENTRY_UIK4 (CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16))
59 : #define CP_OFFSET_ENTRY_UIK5 (CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32))
60 :
61 : #define FIELD_OFFSET_ACCESS 0
62 : #define FIELD_OFFSET_NAME (FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
63 : #define FIELD_OFFSET_TYPE (FIELD_OFFSET_NAME + sizeof(sal_uInt16))
64 : #define FIELD_OFFSET_VALUE (FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
65 : #define FIELD_OFFSET_DOKU (FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
66 : #define FIELD_OFFSET_FILENAME (FIELD_OFFSET_DOKU + sizeof(sal_uInt16))
67 :
68 : #define PARAM_OFFSET_TYPE 0
69 : #define PARAM_OFFSET_MODE (PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
70 : #define PARAM_OFFSET_NAME (PARAM_OFFSET_MODE + sizeof(sal_uInt16))
71 :
72 : #define METHOD_OFFSET_SIZE 0
73 : #define METHOD_OFFSET_MODE (METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
74 : #define METHOD_OFFSET_NAME (METHOD_OFFSET_MODE + sizeof(sal_uInt16))
75 : #define METHOD_OFFSET_RETURN (METHOD_OFFSET_NAME + sizeof(sal_uInt16))
76 : #define METHOD_OFFSET_DOKU (METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
77 : #define METHOD_OFFSET_PARAM_COUNT (METHOD_OFFSET_DOKU + sizeof(sal_uInt16))
78 :
79 : #define REFERENCE_OFFSET_TYPE 0
80 : #define REFERENCE_OFFSET_NAME (REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
81 : #define REFERENCE_OFFSET_DOKU (REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
82 : #define REFERENCE_OFFSET_ACCESS (REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16))
83 :
84 : enum CPInfoTag
85 : {
86 : CP_TAG_INVALID = RT_TYPE_NONE,
87 : CP_TAG_CONST_BOOL = RT_TYPE_BOOL,
88 : CP_TAG_CONST_BYTE = RT_TYPE_BYTE,
89 : CP_TAG_CONST_INT16 = RT_TYPE_INT16,
90 : CP_TAG_CONST_UINT16 = RT_TYPE_UINT16,
91 : CP_TAG_CONST_INT32 = RT_TYPE_INT32,
92 : CP_TAG_CONST_UINT32 = RT_TYPE_UINT32,
93 : CP_TAG_CONST_INT64 = RT_TYPE_INT64,
94 : CP_TAG_CONST_UINT64 = RT_TYPE_UINT64,
95 : CP_TAG_CONST_FLOAT = RT_TYPE_FLOAT,
96 : CP_TAG_CONST_DOUBLE = RT_TYPE_DOUBLE,
97 : CP_TAG_CONST_STRING = RT_TYPE_STRING,
98 : CP_TAG_UTF8_NAME,
99 : CP_TAG_UIK
100 : };
101 :
102 22 : inline sal_uInt32 writeBYTE(sal_uInt8* buffer, sal_uInt8 v)
103 : {
104 22 : buffer[0] = v;
105 :
106 22 : return sizeof(sal_uInt8);
107 : }
108 :
109 : inline sal_uInt16 readBYTE(const sal_uInt8* buffer, sal_uInt8& v)
110 : {
111 : v = buffer[0];
112 :
113 : return sizeof(sal_uInt8);
114 : }
115 :
116 26 : inline sal_uInt32 writeINT16(sal_uInt8* buffer, sal_Int16 v)
117 : {
118 26 : buffer[0] = (sal_uInt8)((v >> 8) & 0xFF);
119 26 : buffer[1] = (sal_uInt8)((v >> 0) & 0xFF);
120 :
121 26 : return sizeof(sal_Int16);
122 : }
123 :
124 : inline sal_uInt32 readINT16(const sal_uInt8* buffer, sal_Int16& v)
125 : {
126 : v = ((buffer[0] << 8) | (buffer[1] << 0));
127 :
128 : return sizeof(sal_Int16);
129 : }
130 :
131 22104 : inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v)
132 : {
133 22104 : buffer[0] = (sal_uInt8)((v >> 8) & 0xFF);
134 22104 : buffer[1] = (sal_uInt8)((v >> 0) & 0xFF);
135 :
136 22104 : return sizeof(sal_uInt16);
137 : }
138 :
139 0 : inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v)
140 : {
141 : //This is untainted data which comes from a controlled source
142 : //so, using a byte-swapping pattern which coverity doesn't
143 : //detect as such
144 : //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
145 0 : v = *buffer++; v <<= 8;
146 0 : v |= *buffer;
147 0 : return sizeof(sal_uInt16);
148 : }
149 :
150 98 : inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v)
151 : {
152 98 : buffer[0] = (sal_uInt8)((v >> 24) & 0xFF);
153 98 : buffer[1] = (sal_uInt8)((v >> 16) & 0xFF);
154 98 : buffer[2] = (sal_uInt8)((v >> 8) & 0xFF);
155 98 : buffer[3] = (sal_uInt8)((v >> 0) & 0xFF);
156 :
157 98 : return sizeof(sal_Int32);
158 : }
159 :
160 0 : inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v)
161 : {
162 : v = (
163 0 : (buffer[0] << 24) |
164 0 : (buffer[1] << 16) |
165 0 : (buffer[2] << 8) |
166 0 : (buffer[3] << 0)
167 0 : );
168 :
169 0 : return sizeof(sal_Int32);
170 : }
171 :
172 5674 : inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v)
173 : {
174 5674 : buffer[0] = (sal_uInt8)((v >> 24) & 0xFF);
175 5674 : buffer[1] = (sal_uInt8)((v >> 16) & 0xFF);
176 5674 : buffer[2] = (sal_uInt8)((v >> 8) & 0xFF);
177 5674 : buffer[3] = (sal_uInt8)((v >> 0) & 0xFF);
178 :
179 5674 : return sizeof(sal_uInt32);
180 : }
181 :
182 18 : inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v)
183 : {
184 : //This is untainted data which comes from a controlled source
185 : //so, using a byte-swapping pattern which coverity doesn't
186 : //detect as such
187 : //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
188 18 : v = *buffer++; v <<= 8;
189 18 : v |= *buffer++; v <<= 8;
190 18 : v |= *buffer++; v <<= 8;
191 18 : v |= *buffer;
192 18 : return sizeof(sal_uInt32);
193 : }
194 :
195 : inline sal_uInt32 writeINT64(sal_uInt8* buffer, sal_Int64 v)
196 : {
197 : buffer[0] = (sal_uInt8)((v >> 56) & 0xFF);
198 : buffer[1] = (sal_uInt8)((v >> 48) & 0xFF);
199 : buffer[2] = (sal_uInt8)((v >> 40) & 0xFF);
200 : buffer[3] = (sal_uInt8)((v >> 32) & 0xFF);
201 : buffer[4] = (sal_uInt8)((v >> 24) & 0xFF);
202 : buffer[5] = (sal_uInt8)((v >> 16) & 0xFF);
203 : buffer[6] = (sal_uInt8)((v >> 8) & 0xFF);
204 : buffer[7] = (sal_uInt8)((v >> 0) & 0xFF);
205 :
206 : return sizeof(sal_Int64);
207 : }
208 :
209 : inline sal_uInt32 readINT64(const sal_uInt8* buffer, sal_Int64& v)
210 : {
211 : v = (
212 : ((sal_Int64)buffer[0] << 56) |
213 : ((sal_Int64)buffer[1] << 48) |
214 : ((sal_Int64)buffer[2] << 40) |
215 : ((sal_Int64)buffer[3] << 32) |
216 : ((sal_Int64)buffer[4] << 24) |
217 : ((sal_Int64)buffer[5] << 16) |
218 : ((sal_Int64)buffer[6] << 8) |
219 : ((sal_Int64)buffer[7] << 0)
220 : );
221 :
222 : return sizeof(sal_Int64);
223 : }
224 :
225 26 : inline sal_uInt32 writeUINT64(sal_uInt8* buffer, sal_uInt64 v)
226 : {
227 26 : buffer[0] = (sal_uInt8)((v >> 56) & 0xFF);
228 26 : buffer[1] = (sal_uInt8)((v >> 48) & 0xFF);
229 26 : buffer[2] = (sal_uInt8)((v >> 40) & 0xFF);
230 26 : buffer[3] = (sal_uInt8)((v >> 32) & 0xFF);
231 26 : buffer[4] = (sal_uInt8)((v >> 24) & 0xFF);
232 26 : buffer[5] = (sal_uInt8)((v >> 16) & 0xFF);
233 26 : buffer[6] = (sal_uInt8)((v >> 8) & 0xFF);
234 26 : buffer[7] = (sal_uInt8)((v >> 0) & 0xFF);
235 :
236 26 : return sizeof(sal_uInt64);
237 : }
238 :
239 : inline sal_uInt32 readUINT64(const sal_uInt8* buffer, sal_uInt64& v)
240 : {
241 : v = (
242 : ((sal_uInt64)buffer[0] << 56) |
243 : ((sal_uInt64)buffer[1] << 48) |
244 : ((sal_uInt64)buffer[2] << 40) |
245 : ((sal_uInt64)buffer[3] << 32) |
246 : ((sal_uInt64)buffer[4] << 24) |
247 : ((sal_uInt64)buffer[5] << 16) |
248 : ((sal_uInt64)buffer[6] << 8) |
249 : ((sal_uInt64)buffer[7] << 0)
250 : );
251 :
252 : return sizeof(sal_uInt64);
253 : }
254 :
255 2530 : inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const sal_Char* v)
256 : {
257 2530 : sal_uInt32 size = strlen(v) + 1;
258 :
259 2530 : memcpy(buffer, v, size);
260 :
261 2530 : return (size);
262 : }
263 :
264 6 : inline sal_uInt32 readUtf8(const sal_uInt8* buffer, sal_Char* v, sal_uInt32 maxSize)
265 : {
266 6 : sal_uInt32 size = strlen((const sal_Char*) buffer) + 1;
267 6 : if(size > maxSize)
268 : {
269 0 : size = maxSize;
270 : }
271 :
272 6 : memcpy(v, buffer, size);
273 :
274 6 : if (size == maxSize) v[size - 1] = '\0';
275 :
276 6 : return (size);
277 : }
278 :
279 :
280 : sal_uInt32 writeFloat(sal_uInt8* buffer, float v);
281 : sal_uInt32 writeDouble(sal_uInt8* buffer, double v);
282 : sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v);
283 : sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize);
284 :
285 : sal_uInt32 UINT16StringLen(const sal_uInt8* wstring);
286 :
287 : #endif
288 :
289 :
290 :
291 :
292 :
293 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|