LibreOffice Module registry (master)  1
reflcnst.hxx
Go to the documentation of this file.
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/types.hxx>
24 
25 #include <string.h>
26 
27 #define REGTYPE_IEEE_NATIVE 1
28 
29 extern const sal_uInt32 magic;
30 extern const sal_uInt16 minorVersion;
31 extern const sal_uInt16 majorVersion;
32 
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))
44 
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))
47 
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))
50 
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 
55 #define FIELD_OFFSET_ACCESS 0
56 #define FIELD_OFFSET_NAME static_cast<sal_uInt32>(FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
57 #define FIELD_OFFSET_TYPE static_cast<sal_uInt32>(FIELD_OFFSET_NAME + sizeof(sal_uInt16))
58 #define FIELD_OFFSET_VALUE static_cast<sal_uInt32>(FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
59 #define FIELD_OFFSET_DOKU static_cast<sal_uInt32>(FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
60 #define FIELD_OFFSET_FILENAME static_cast<sal_uInt32>(FIELD_OFFSET_DOKU + sizeof(sal_uInt16))
61 
62 #define PARAM_OFFSET_TYPE 0
63 #define PARAM_OFFSET_MODE static_cast<sal_uInt32>(PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
64 #define PARAM_OFFSET_NAME static_cast<sal_uInt32>(PARAM_OFFSET_MODE + sizeof(sal_uInt16))
65 
66 #define METHOD_OFFSET_SIZE 0
67 #define METHOD_OFFSET_MODE static_cast<sal_uInt32>(METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
68 #define METHOD_OFFSET_NAME static_cast<sal_uInt32>(METHOD_OFFSET_MODE + sizeof(sal_uInt16))
69 #define METHOD_OFFSET_RETURN static_cast<sal_uInt32>(METHOD_OFFSET_NAME + sizeof(sal_uInt16))
70 #define METHOD_OFFSET_DOKU static_cast<sal_uInt32>(METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
71 #define METHOD_OFFSET_PARAM_COUNT static_cast<sal_uInt32>(METHOD_OFFSET_DOKU + sizeof(sal_uInt16))
72 
73 #define REFERENCE_OFFSET_TYPE 0
74 #define REFERENCE_OFFSET_NAME static_cast<sal_uInt32>(REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
75 #define REFERENCE_OFFSET_DOKU static_cast<sal_uInt32>(REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
76 #define REFERENCE_OFFSET_ACCESS static_cast<sal_uInt32>(REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16))
77 
79 {
93 };
94 
95 inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v)
96 {
97  buffer[0] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
98  buffer[1] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
99 
100  return sizeof(sal_uInt16);
101 }
102 
103 inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v)
104 {
105  //This is untainted data which comes from a controlled source
106  //so, using a byte-swapping pattern which coverity doesn't
107  //detect as such
108  //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
109  v = *buffer++; v <<= 8;
110  v |= *buffer;
111  return sizeof(sal_uInt16);
112 }
113 
114 inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v)
115 {
116  buffer[0] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
117  buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
118  buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
119  buffer[3] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
120 
121  return sizeof(sal_Int32);
122 }
123 
124 inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v)
125 {
126  v = (
127  (buffer[0] << 24) |
128  (buffer[1] << 16) |
129  (buffer[2] << 8) |
130  (buffer[3] << 0)
131  );
132 
133  return sizeof(sal_Int32);
134 }
135 
136 inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v)
137 {
138  buffer[0] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
139  buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
140  buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
141  buffer[3] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
142 
143  return sizeof(sal_uInt32);
144 }
145 
146 inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v)
147 {
148  //This is untainted data which comes from a controlled source
149  //so, using a byte-swapping pattern which coverity doesn't
150  //detect as such
151  //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
152  v = *buffer++; v <<= 8;
153  v |= *buffer++; v <<= 8;
154  v |= *buffer++; v <<= 8;
155  v |= *buffer;
156  return sizeof(sal_uInt32);
157 }
158 
159 inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const char* v)
160 {
161  sal_uInt32 size = strlen(v) + 1;
162 
163  memcpy(buffer, v, size);
164 
165  return size;
166 }
167 
168 inline sal_uInt32 readUtf8(const sal_uInt8* buffer, char* v, sal_uInt32 maxSize)
169 {
170  sal_uInt32 size = strlen(reinterpret_cast<const char*>(buffer)) + 1;
171  if(size > maxSize)
172  {
173  size = maxSize;
174  }
175 
176  memcpy(v, buffer, size);
177 
178  if (size == maxSize) v[size - 1] = '\0';
179 
180  return size;
181 }
182 
183 
184 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v);
185 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize);
186 
187 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring);
188 
189 #endif
190 
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 writeUINT16(sal_uInt8 *buffer, sal_uInt16 v)
Definition: reflcnst.hxx:95
const sal_uInt32 magic
Definition: reflread.cxx:43
const sal_uInt16 minorVersion
Definition: reflread.cxx:44
sal_uInt32 readUINT32(const sal_uInt8 *buffer, sal_uInt32 &v)
Definition: reflcnst.hxx:146
const sal_uInt16 majorVersion
Definition: reflread.cxx:45
sal_uInt16 sal_Unicode
CPInfoTag
Definition: reflcnst.hxx:78
sal_uInt32 readUtf8(const sal_uInt8 *buffer, char *v, sal_uInt32 maxSize)
Definition: reflcnst.hxx:168
sal_uInt32 UINT16StringLen(const sal_uInt8 *wstring)
Definition: reflwrit.cxx:29
sal_uInt32 writeString(sal_uInt8 *buffer, const sal_Unicode *v)
Definition: reflwrit.cxx:40
sal_uInt32 readUINT16(const sal_uInt8 *buffer, sal_uInt16 &v)
Definition: reflcnst.hxx:103
size
sal_uInt32 readINT32(const sal_uInt8 *buffer, sal_Int32 &v)
Definition: reflcnst.hxx:124
sal_uInt32 writeINT32(sal_uInt8 *buffer, sal_Int32 v)
Definition: reflcnst.hxx:114
sal_uInt32 readString(const sal_uInt8 *buffer, sal_Unicode *v, sal_uInt32 maxSize)
Definition: reflwrit.cxx:54
unsigned char sal_uInt8
sal_uInt32 writeUtf8(sal_uInt8 *buffer, const char *v)
Definition: reflcnst.hxx:159
sal_uInt32 writeUINT32(sal_uInt8 *buffer, sal_uInt32 v)
Definition: reflcnst.hxx:136