snowflake-connector-python 3.16.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/connector/__init__.py +96 -0
- snowflake/connector/_query_context_cache.py +276 -0
- snowflake/connector/_sql_util.py +48 -0
- snowflake/connector/_utils.py +70 -0
- snowflake/connector/arrow_context.py +203 -0
- snowflake/connector/auth/__init__.py +53 -0
- snowflake/connector/auth/_auth.py +586 -0
- snowflake/connector/auth/_http_server.py +220 -0
- snowflake/connector/auth/_oauth_base.py +400 -0
- snowflake/connector/auth/by_plugin.py +219 -0
- snowflake/connector/auth/default.py +36 -0
- snowflake/connector/auth/idtoken.py +72 -0
- snowflake/connector/auth/keypair.py +222 -0
- snowflake/connector/auth/no_auth.py +39 -0
- snowflake/connector/auth/oauth.py +49 -0
- snowflake/connector/auth/oauth_code.py +479 -0
- snowflake/connector/auth/oauth_credentials.py +66 -0
- snowflake/connector/auth/okta.py +335 -0
- snowflake/connector/auth/pat.py +39 -0
- snowflake/connector/auth/usrpwdmfa.py +69 -0
- snowflake/connector/auth/webbrowser.py +502 -0
- snowflake/connector/auth/workload_identity.py +94 -0
- snowflake/connector/azure_storage_client.py +276 -0
- snowflake/connector/backoff_policies.py +141 -0
- snowflake/connector/bind_upload_agent.py +89 -0
- snowflake/connector/cache.py +696 -0
- snowflake/connector/compat.py +127 -0
- snowflake/connector/config_manager.py +496 -0
- snowflake/connector/connection.py +2273 -0
- snowflake/connector/connection_diagnostic.py +776 -0
- snowflake/connector/constants.py +442 -0
- snowflake/connector/converter.py +785 -0
- snowflake/connector/converter_issue23517.py +87 -0
- snowflake/connector/converter_null.py +14 -0
- snowflake/connector/converter_snowsql.py +205 -0
- snowflake/connector/cursor.py +1951 -0
- snowflake/connector/dbapi.py +53 -0
- snowflake/connector/description.py +19 -0
- snowflake/connector/direct_file_operation_utils.py +88 -0
- snowflake/connector/encryption_util.py +220 -0
- snowflake/connector/errorcode.py +91 -0
- snowflake/connector/errors.py +615 -0
- snowflake/connector/externals_utils/__init__.py +0 -0
- snowflake/connector/externals_utils/externals_setup.py +27 -0
- snowflake/connector/feature.py +4 -0
- snowflake/connector/file_compression_type.py +118 -0
- snowflake/connector/file_lock.py +72 -0
- snowflake/connector/file_transfer_agent.py +1215 -0
- snowflake/connector/file_util.py +153 -0
- snowflake/connector/gcs_storage_client.py +474 -0
- snowflake/connector/gzip_decoder.py +85 -0
- snowflake/connector/local_storage_client.py +90 -0
- snowflake/connector/log_configuration.py +60 -0
- snowflake/connector/logging_utils/__init__.py +0 -0
- snowflake/connector/logging_utils/filters.py +72 -0
- snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
- snowflake/connector/network.py +1297 -0
- snowflake/connector/ocsp_asn1crypto.py +447 -0
- snowflake/connector/ocsp_snowflake.py +1883 -0
- snowflake/connector/options.py +131 -0
- snowflake/connector/pandas_tools.py +732 -0
- snowflake/connector/proxy.py +43 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +786 -0
- snowflake/connector/result_set.py +319 -0
- snowflake/connector/s3_storage_client.py +605 -0
- snowflake/connector/secret_detector.py +181 -0
- snowflake/connector/sf_dirs.py +64 -0
- snowflake/connector/sfbinaryformat.py +35 -0
- snowflake/connector/sfdatetime.py +345 -0
- snowflake/connector/snow_logging.py +144 -0
- snowflake/connector/sqlstate.py +9 -0
- snowflake/connector/ssd_internal_keys.py +30 -0
- snowflake/connector/ssl_wrap_socket.py +134 -0
- snowflake/connector/storage_client.py +478 -0
- snowflake/connector/telemetry.py +249 -0
- snowflake/connector/telemetry_oob.py +543 -0
- snowflake/connector/test_util.py +30 -0
- snowflake/connector/time_util.py +159 -0
- snowflake/connector/token_cache.py +402 -0
- snowflake/connector/tool/__init__.py +0 -0
- snowflake/connector/tool/dump_certs.py +57 -0
- snowflake/connector/tool/dump_ocsp_response.py +139 -0
- snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
- snowflake/connector/tool/probe_connection.py +69 -0
- snowflake/connector/url_util.py +49 -0
- snowflake/connector/util_text.py +301 -0
- snowflake/connector/vendored/__init__.py +3 -0
- snowflake/connector/vendored/requests/LICENSE +175 -0
- snowflake/connector/vendored/requests/__init__.py +169 -0
- snowflake/connector/vendored/requests/__version__.py +14 -0
- snowflake/connector/vendored/requests/_internal_utils.py +50 -0
- snowflake/connector/vendored/requests/adapters.py +537 -0
- snowflake/connector/vendored/requests/api.py +157 -0
- snowflake/connector/vendored/requests/auth.py +315 -0
- snowflake/connector/vendored/requests/certs.py +17 -0
- snowflake/connector/vendored/requests/compat.py +79 -0
- snowflake/connector/vendored/requests/cookies.py +561 -0
- snowflake/connector/vendored/requests/exceptions.py +140 -0
- snowflake/connector/vendored/requests/help.py +134 -0
- snowflake/connector/vendored/requests/hooks.py +33 -0
- snowflake/connector/vendored/requests/models.py +1033 -0
- snowflake/connector/vendored/requests/sessions.py +833 -0
- snowflake/connector/vendored/requests/status_codes.py +128 -0
- snowflake/connector/vendored/requests/structures.py +99 -0
- snowflake/connector/vendored/requests/utils.py +1093 -0
- snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
- snowflake/connector/vendored/urllib3/__init__.py +85 -0
- snowflake/connector/vendored/urllib3/_collections.py +355 -0
- snowflake/connector/vendored/urllib3/_version.py +2 -0
- snowflake/connector/vendored/urllib3/connection.py +572 -0
- snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
- snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
- snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
- snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
- snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
- snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
- snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
- snowflake/connector/vendored/urllib3/exceptions.py +323 -0
- snowflake/connector/vendored/urllib3/fields.py +274 -0
- snowflake/connector/vendored/urllib3/filepost.py +98 -0
- snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
- snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
- snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
- snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
- snowflake/connector/vendored/urllib3/request.py +191 -0
- snowflake/connector/vendored/urllib3/response.py +885 -0
- snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
- snowflake/connector/vendored/urllib3/util/connection.py +156 -0
- snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
- snowflake/connector/vendored/urllib3/util/queue.py +22 -0
- snowflake/connector/vendored/urllib3/util/request.py +146 -0
- snowflake/connector/vendored/urllib3/util/response.py +107 -0
- snowflake/connector/vendored/urllib3/util/retry.py +620 -0
- snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
- snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
- snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
- snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
- snowflake/connector/vendored/urllib3/util/url.py +435 -0
- snowflake/connector/vendored/urllib3/util/wait.py +152 -0
- snowflake/connector/version.py +3 -0
- snowflake/connector/wif_util.py +407 -0
- snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
- snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
- snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
- snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
- snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The flatcc builder supports storing a pointer to a refmap
|
|
3
|
+
* and wraps some operations to make them work as a dummy
|
|
4
|
+
* even if no refmap has been set. This enables optional
|
|
5
|
+
* DAG preservation possible during clone operations.
|
|
6
|
+
*
|
|
7
|
+
* A refmap maps a source address to a builder reference.
|
|
8
|
+
*
|
|
9
|
+
* This is just a map, but the semantics are important:
|
|
10
|
+
*
|
|
11
|
+
* The map thus preserves identity of the source. It is not a
|
|
12
|
+
* cache because cache eviction would fail to properly track
|
|
13
|
+
* identity.
|
|
14
|
+
*
|
|
15
|
+
* The map is used for memoization during object cloning are and
|
|
16
|
+
* may also be used by user logic doing similar operations.
|
|
17
|
+
* This ensures that identity is preserved so a source object is
|
|
18
|
+
* not duplicated which could lead to either loss of semantic
|
|
19
|
+
* information, or an explosion in size, or both. In some, or
|
|
20
|
+
* even most, cases this concern may not be important, but when
|
|
21
|
+
* it is important, it is important.
|
|
22
|
+
*
|
|
23
|
+
* The source address must not be reused for different content
|
|
24
|
+
* for the lifetime of the map, although the content doest not
|
|
25
|
+
* have to be valid or event exist at that location since source
|
|
26
|
+
* address is just used as a key.
|
|
27
|
+
*
|
|
28
|
+
* The lifetime may be a single clone operation which then
|
|
29
|
+
* tracks child object references as well, or it may be the
|
|
30
|
+
* lifetime of the buffer builder.
|
|
31
|
+
*
|
|
32
|
+
* The map may be flushed explicitly when the source addresses
|
|
33
|
+
* are no longer unique, such as when reusing a memory buffer,
|
|
34
|
+
* and when identity preservation is no longer important.
|
|
35
|
+
* Flushing a map is esentially the same as ending a lifetime.
|
|
36
|
+
*
|
|
37
|
+
* Multiple maps may exist concurrently for example if cloning
|
|
38
|
+
* an object twice into two new objects that should have
|
|
39
|
+
* separate identities. This is especially true and necessary
|
|
40
|
+
* when creating a new nested buffer because the nested buffer
|
|
41
|
+
* cannot share references with the parent. Cloning and object
|
|
42
|
+
* that contains a nested buffer does not require multiple maps
|
|
43
|
+
* because the nested buffer is then opaque.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
#ifndef FLATCC_REFMAP_H
|
|
47
|
+
#define FLATCC_REFMAP_H
|
|
48
|
+
|
|
49
|
+
#ifdef __cplusplus
|
|
50
|
+
extern "C" {
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
#include "flatcc/flatcc_types.h"
|
|
54
|
+
|
|
55
|
+
#ifndef FLATCC_REFMAP_MIN_BUCKETS
|
|
56
|
+
/* 8 buckets gives us 5 useful initial entries with a load factor of 0.7 */
|
|
57
|
+
#define FLATCC_REFMAP_MIN_BUCKETS 8
|
|
58
|
+
#endif
|
|
59
|
+
|
|
60
|
+
#define FLATCC_REFMAP_LOAD_FACTOR 0.7f
|
|
61
|
+
|
|
62
|
+
typedef struct flatcc_refmap flatcc_refmap_t;
|
|
63
|
+
typedef flatbuffers_soffset_t flatcc_refmap_ref_t;
|
|
64
|
+
|
|
65
|
+
static const flatcc_refmap_ref_t flatcc_refmap_not_found = 0;
|
|
66
|
+
|
|
67
|
+
struct flatcc_refmap_item {
|
|
68
|
+
const void *src;
|
|
69
|
+
flatcc_refmap_ref_t ref;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
struct flatcc_refmap {
|
|
73
|
+
size_t count;
|
|
74
|
+
size_t buckets;
|
|
75
|
+
struct flatcc_refmap_item *table;
|
|
76
|
+
/* Use stack allocation for small maps. */
|
|
77
|
+
struct flatcc_refmap_item min_table[FLATCC_REFMAP_MIN_BUCKETS];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Fast zero initialization - does not allocate any memory.
|
|
82
|
+
* May be replaced by memset 0, but `init` avoids clearing the
|
|
83
|
+
* stack allocated initial hash table until it is needed.
|
|
84
|
+
*/
|
|
85
|
+
static inline int flatcc_refmap_init(flatcc_refmap_t *refmap)
|
|
86
|
+
{
|
|
87
|
+
refmap->count = 0;
|
|
88
|
+
refmap->buckets = 0;
|
|
89
|
+
refmap->table = 0;
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* Removes all items and deallocates memory.
|
|
95
|
+
* Not required unless `insert` or `resize` took place. The map can be
|
|
96
|
+
* reused subsequently without calling `init`.
|
|
97
|
+
*/
|
|
98
|
+
void flatcc_refmap_clear(flatcc_refmap_t *refmap);
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Keeps allocated memory as is, but removes all items. The map
|
|
102
|
+
* must intialized first.
|
|
103
|
+
*/
|
|
104
|
+
void flatcc_refmap_reset(flatcc_refmap_t *refmap);
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Returns the inserted reference if the `src` pointer was found,
|
|
108
|
+
* without inspecting the content of the `src` pointer.
|
|
109
|
+
*
|
|
110
|
+
* Returns flatcc_refmap_not_found (default 0) if the `src` pointer was
|
|
111
|
+
* not found.
|
|
112
|
+
*/
|
|
113
|
+
flatcc_refmap_ref_t flatcc_refmap_find(flatcc_refmap_t *refmap, const void *src);
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Inserts a `src` source pointer and its associated `ref` reference
|
|
117
|
+
* into the refmap without inspecting the `src` pointer content. The
|
|
118
|
+
* `ref` value will be replaced if the the `src` pointer already exists.
|
|
119
|
+
*
|
|
120
|
+
* Inserting null will just return the ref without updating the map.
|
|
121
|
+
*
|
|
122
|
+
* There is no delete operation which simplifies an open
|
|
123
|
+
* addressing hash table, and it isn't needed for this use case.
|
|
124
|
+
*
|
|
125
|
+
* Returns the input ref or not_found on allocation error.
|
|
126
|
+
*/
|
|
127
|
+
flatcc_refmap_ref_t flatcc_refmap_insert(flatcc_refmap_t *refmap, const void *src, flatcc_refmap_ref_t ref);
|
|
128
|
+
|
|
129
|
+
/*
|
|
130
|
+
* Set the hash table to accommodate at least `count` items while staying
|
|
131
|
+
* within the predefined load factor.
|
|
132
|
+
*
|
|
133
|
+
* Resize is primarily an internal operation, but the user may resize
|
|
134
|
+
* ahead of a large anticipated load, or after a large load to shrink
|
|
135
|
+
* the table using 0 as the `count` argument. The table never shrinks
|
|
136
|
+
* on its own account.
|
|
137
|
+
*/
|
|
138
|
+
int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count);
|
|
139
|
+
|
|
140
|
+
#ifdef __cplusplus
|
|
141
|
+
}
|
|
142
|
+
#endif
|
|
143
|
+
|
|
144
|
+
#endif /* FLATCC_REFMAP_H */
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#ifndef FLATCC_RTCONFIG_H
|
|
2
|
+
#define FLATCC_RTCONFIG_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/* Include portability layer here since all other files depend on it. */
|
|
10
|
+
#ifdef FLATCC_PORTABLE
|
|
11
|
+
#include "flatcc/portable/portable.h"
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Fast printing and parsing of double.
|
|
16
|
+
*
|
|
17
|
+
* This requires the grisu3/grisu3_* files to be in the include path,
|
|
18
|
+
* otherwise strod and sprintf will be used (these needed anyway
|
|
19
|
+
* as fallback for cases not supported by grisu3).
|
|
20
|
+
*/
|
|
21
|
+
#ifndef FLATCC_USE_GRISU3
|
|
22
|
+
#define FLATCC_USE_GRISU3 1
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* This requires compiler that has enabled marc=native or similar so
|
|
27
|
+
* __SSE4_2__ flag is defined. Otherwise it will have no effect.
|
|
28
|
+
*
|
|
29
|
+
* While SSE may be used for different purposes, it has (as of this
|
|
30
|
+
* writing) only be used to test the effect on JSON whitespace handling
|
|
31
|
+
* which improved, but not by a lot, assuming 64-bit unligned access is
|
|
32
|
+
* otherwise available:
|
|
33
|
+
*
|
|
34
|
+
* With 8 space indentation, the JSON benchmark handles 308K parse ops/sec
|
|
35
|
+
* while SSE ups that to 333 parse ops/sec or 336 if \r\n is also
|
|
36
|
+
* consumed by SSE. Disabling indentation leaves SSE spacing handling
|
|
37
|
+
* ineffective, and performance reaches 450K parse ops/sec and can
|
|
38
|
+
* improve further to 500+K parse ops/sec if inexact GRISU3 numbers are
|
|
39
|
+
* allowed (they are pretty accurate anyway, just not exact). This
|
|
40
|
+
* feature requires hacking a flag direct in the grisu3 double parsing
|
|
41
|
+
* lib directly and only mentioned for comparison.
|
|
42
|
+
*
|
|
43
|
+
* In conclusion SSE doesn't add a lot to JSON space handling at least.
|
|
44
|
+
*
|
|
45
|
+
* Disabled by default, but can be overriden by build system.
|
|
46
|
+
*/
|
|
47
|
+
#ifndef FLATCC_USE_SSE4_2
|
|
48
|
+
#define FLATCC_USE_SSE4_2 0
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* The verifier only reports yes and no. The following setting
|
|
53
|
+
* enables assertions in debug builds. It must be compiled into
|
|
54
|
+
* the runtime library and is not normally the desired behavior.
|
|
55
|
+
*
|
|
56
|
+
* NOTE: enabling this can break test cases so use with build, not test.
|
|
57
|
+
*/
|
|
58
|
+
#if !defined(FLATCC_DEBUG_VERIFY) && !defined(NDEBUG)
|
|
59
|
+
#define FLATCC_DEBUG_VERIFY 0
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
#if !defined(FLATCC_TRACE_VERIFY)
|
|
63
|
+
#define FLATCC_TRACE_VERIFY 0
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Limit recursion level for tables. Actual level may be deeper
|
|
69
|
+
* when structs are deeply nested - but these are limited by the
|
|
70
|
+
* schema compiler.
|
|
71
|
+
*/
|
|
72
|
+
#ifndef FLATCC_JSON_PRINT_MAX_LEVELS
|
|
73
|
+
#define FLATCC_JSON_PRINT_MAX_LEVELS 100
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
/* Maximum length of names printed exluding _type suffix. */
|
|
77
|
+
#ifndef FLATCC_JSON_PRINT_NAME_LEN_MAX
|
|
78
|
+
#define FLATCC_JSON_PRINT_NAME_LEN_MAX 100
|
|
79
|
+
#endif
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Print float and double values with C99 hexadecimal floating point
|
|
83
|
+
* notation. This option is not valid JSON but it avoids precision
|
|
84
|
+
* loss, correctly handles NaN, +/-Infinity and is significantly faster
|
|
85
|
+
* to parse and print. Some JSON parsers rely on strtod which does
|
|
86
|
+
* support hexadecimal floating points when C99 compliant.
|
|
87
|
+
*/
|
|
88
|
+
#ifndef FLATCC_JSON_PRINT_HEX_FLOAT
|
|
89
|
+
#define FLATCC_JSON_PRINT_HEX_FLOAT 0
|
|
90
|
+
#endif
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Always print multipe enum flags like `color: "Red Green"`
|
|
94
|
+
* even when unquote is selected as an option for single
|
|
95
|
+
* value like `color: Green`. Otherwise multiple values
|
|
96
|
+
* are printed as `color: Red Green`, but this could break
|
|
97
|
+
* some flatbuffer json parser.
|
|
98
|
+
*/
|
|
99
|
+
#ifndef FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS
|
|
100
|
+
#define FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS 1
|
|
101
|
+
#endif
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* The general nesting limit may be lower, but for skipping
|
|
105
|
+
* JSON we do not need to - we can set this high as it only
|
|
106
|
+
* costs a single char per level in a stack array.
|
|
107
|
+
*/
|
|
108
|
+
#ifndef FLATCC_JSON_PARSE_GENERIC_MAX_NEST
|
|
109
|
+
#define FLATCC_JSON_PARSE_GENERIC_MAX_NEST 512
|
|
110
|
+
#endif
|
|
111
|
+
|
|
112
|
+
/* Store value even if it is default. */
|
|
113
|
+
#ifndef FLATCC_JSON_PARSE_FORCE_DEFAULTS
|
|
114
|
+
#define FLATCC_JSON_PARSE_FORCE_DEFAULTS 0
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
#ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED
|
|
118
|
+
#define FLATCC_JSON_PARSE_ALLOW_UNQUOTED 1
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
* Multiple enum values are by default not permitted unless
|
|
123
|
+
* quoted like `color: "Red Green" as per Googles flatc JSON
|
|
124
|
+
* parser while a single value like `color: Red` can be
|
|
125
|
+
* unquoted. Enabling this setting will allow `color: Red
|
|
126
|
+
* Green`, but only if FLATCC_JSON_PARSE_ALLOW_UNQUOTED is
|
|
127
|
+
* also enabled.
|
|
128
|
+
*/
|
|
129
|
+
#ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST
|
|
130
|
+
#define FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST 0
|
|
131
|
+
#endif
|
|
132
|
+
|
|
133
|
+
#ifndef FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD
|
|
134
|
+
#define FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD 1
|
|
135
|
+
#endif
|
|
136
|
+
|
|
137
|
+
#ifndef FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA
|
|
138
|
+
#define FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA 1
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* Just parse to the closing bracket '}' if set.
|
|
143
|
+
* Otherwise parse to end by consuming space and
|
|
144
|
+
* fail if anything but space follows.
|
|
145
|
+
*/
|
|
146
|
+
#ifndef FLATCC_PARSE_IGNORE_TRAILING_DATA
|
|
147
|
+
#define FLATCC_PARSE_IGNORE_TRAILING_DATA 0
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Optimize to parse a lot of white space, but
|
|
152
|
+
* in most cases it probably slows parsing down.
|
|
153
|
+
*/
|
|
154
|
+
#ifndef FLATCC_JSON_PARSE_WIDE_SPACE
|
|
155
|
+
#define FLATCC_JSON_PARSE_WIDE_SPACE 0
|
|
156
|
+
#endif
|
|
157
|
+
|
|
158
|
+
#ifdef __cplusplus
|
|
159
|
+
}
|
|
160
|
+
#endif
|
|
161
|
+
|
|
162
|
+
#endif /* FLATCC_RTCONFIG_H */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#ifndef FLATCC_TYPES_H
|
|
2
|
+
#define FLATCC_TYPES_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
|
|
10
|
+
#ifndef UINT8_MAX
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* This should match generated type declaratios in
|
|
16
|
+
* `flatbuffers_common_reader.h` (might have different name prefix).
|
|
17
|
+
* Read only generated code does not depend on library code,
|
|
18
|
+
* hence the duplication.
|
|
19
|
+
*/
|
|
20
|
+
#ifndef flatbuffers_types_defined
|
|
21
|
+
#define flatbuffers_types_defined
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* uoffset_t and soffset_t must be same integer type, except for sign.
|
|
25
|
+
* They can be (u)int16_t, (u)int32_t, or (u)int64_t.
|
|
26
|
+
* The default is (u)int32_t.
|
|
27
|
+
*
|
|
28
|
+
* voffset_t is expected to be uint16_t, but can experimentally be
|
|
29
|
+
* compiled from uint8_t up to uint32_t.
|
|
30
|
+
*
|
|
31
|
+
* ID_MAX is the largest value that can index a vtable. The table size
|
|
32
|
+
* is given as voffset value. Each id represents a voffset value index
|
|
33
|
+
* from 0 to max inclusive. Space is required for two header voffset
|
|
34
|
+
* fields and the unaddressible highest index (due to the table size
|
|
35
|
+
* representation). For 16-bit voffsets this yields a max of 2^15 - 4,
|
|
36
|
+
* or (2^16 - 1) / 2 - 3.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#define flatbuffers_uoffset_t_defined
|
|
40
|
+
#define flatbuffers_soffset_t_defined
|
|
41
|
+
#define flatbuffers_voffset_t_defined
|
|
42
|
+
#define flatbuffers_utype_t_defined
|
|
43
|
+
#define flatbuffers_bool_t_defined
|
|
44
|
+
#define flatbuffers_thash_t_defined
|
|
45
|
+
#define flatbuffers_fid_t_defined
|
|
46
|
+
|
|
47
|
+
/* uoffset_t is also used for vector and string headers. */
|
|
48
|
+
#define FLATBUFFERS_UOFFSET_MAX UINT32_MAX
|
|
49
|
+
#define FLATBUFFERS_SOFFSET_MAX INT32_MAX
|
|
50
|
+
#define FLATBUFFERS_SOFFSET_MIN INT32_MIN
|
|
51
|
+
#define FLATBUFFERS_VOFFSET_MAX UINT16_MAX
|
|
52
|
+
#define FLATBUFFERS_UTYPE_MAX UINT8_MAX
|
|
53
|
+
/* Well - the max of the underlying type. */
|
|
54
|
+
#define FLATBUFFERS_BOOL_MAX UINT8_MAX
|
|
55
|
+
#define FLATBUFFERS_THASH_MAX UINT32_MAX
|
|
56
|
+
|
|
57
|
+
#define FLATBUFFERS_ID_MAX (FLATBUFFERS_VOFFSET_MAX / sizeof(flatbuffers_voffset_t) - 3)
|
|
58
|
+
/* Vectors of empty structs can yield div by zero, so we must guard against this. */
|
|
59
|
+
#define FLATBUFFERS_COUNT_MAX(elem_size) (FLATBUFFERS_UOFFSET_MAX/((elem_size) == 0 ? 1 : (elem_size)))
|
|
60
|
+
|
|
61
|
+
#define FLATBUFFERS_UOFFSET_WIDTH 32
|
|
62
|
+
#define FLATBUFFERS_COUNT_WIDTH 32
|
|
63
|
+
#define FLATBUFFERS_SOFFSET_WIDTH 32
|
|
64
|
+
#define FLATBUFFERS_VOFFSET_WIDTH 16
|
|
65
|
+
#define FLATBUFFERS_UTYPE_WIDTH 8
|
|
66
|
+
#define FLATBUFFERS_BOOL_WIDTH 8
|
|
67
|
+
#define FLATBUFFERS_THASH_WIDTH 32
|
|
68
|
+
|
|
69
|
+
#define FLATBUFFERS_TRUE 1
|
|
70
|
+
#define FLATBUFFERS_FALSE 0
|
|
71
|
+
|
|
72
|
+
#define FLATBUFFERS_PROTOCOL_IS_LE 1
|
|
73
|
+
#define FLATBUFFERS_PROTOCOL_IS_BE 0
|
|
74
|
+
|
|
75
|
+
typedef uint32_t flatbuffers_uoffset_t;
|
|
76
|
+
typedef int32_t flatbuffers_soffset_t;
|
|
77
|
+
typedef uint16_t flatbuffers_voffset_t;
|
|
78
|
+
typedef uint8_t flatbuffers_utype_t;
|
|
79
|
+
typedef uint8_t flatbuffers_bool_t;
|
|
80
|
+
typedef uint32_t flatbuffers_thash_t;
|
|
81
|
+
/* Public facing type operations. */
|
|
82
|
+
typedef flatbuffers_utype_t flatbuffers_union_type_t;
|
|
83
|
+
|
|
84
|
+
static const flatbuffers_bool_t flatbuffers_true = FLATBUFFERS_TRUE;
|
|
85
|
+
static const flatbuffers_bool_t flatbuffers_false = FLATBUFFERS_FALSE;
|
|
86
|
+
|
|
87
|
+
#define FLATBUFFERS_IDENTIFIER_SIZE (FLATBUFFERS_THASH_WIDTH / 8)
|
|
88
|
+
|
|
89
|
+
typedef char flatbuffers_fid_t[FLATBUFFERS_IDENTIFIER_SIZE];
|
|
90
|
+
|
|
91
|
+
#endif /* flatbuffers_types_defined */
|
|
92
|
+
|
|
93
|
+
#ifdef __cplusplus
|
|
94
|
+
}
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
#endif /* FLATCC_TYPES_H */
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#ifndef FLATCC_VERIFIER_H
|
|
2
|
+
#define FLATCC_VERIFIER_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Runtime support for verifying flatbuffers.
|
|
10
|
+
*
|
|
11
|
+
* Link with the verifier implementation file.
|
|
12
|
+
*
|
|
13
|
+
* Note:
|
|
14
|
+
*
|
|
15
|
+
* 1) nested buffers will NOT have their identifier verified.
|
|
16
|
+
* The user may do so subsequently. The reason is in part because
|
|
17
|
+
* the information is not readily avaible without generated reader code,
|
|
18
|
+
* in part because the buffer might use a different, but valid,
|
|
19
|
+
* identifier and the user has no chance of specifiying this in the
|
|
20
|
+
* verifier code. The root verifier also doesn't assume a specific id
|
|
21
|
+
* but accepts a user supplied input which may be null.
|
|
22
|
+
*
|
|
23
|
+
* 2) All offsets in a buffer are verified for alignment relative to the
|
|
24
|
+
* buffer start, but the buffer itself is only assumed to aligned to
|
|
25
|
+
* uoffset_t. A reader should therefore ensure buffer alignment separately
|
|
26
|
+
* before reading the buffer. Nested buffers are in fact checked for
|
|
27
|
+
* alignment, but still only relative to the root buffer.
|
|
28
|
+
*
|
|
29
|
+
* 3) The max nesting level includes nested buffer nestings, so the
|
|
30
|
+
* verifier might fail even if the individual buffers are otherwise ok.
|
|
31
|
+
* This is to prevent abuse with lots of nested buffers.
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
* IMPORTANT:
|
|
35
|
+
*
|
|
36
|
+
* Even if verifier passes, the buffer may be invalid to access due to
|
|
37
|
+
* lack of alignemnt in memory, but the verifier is safe to call.
|
|
38
|
+
*
|
|
39
|
+
* NOTE: The buffer is not safe to modify after verification because an
|
|
40
|
+
* attacker may craft overlapping data structures such that modification
|
|
41
|
+
* of one field updates another in a way that violates the buffer
|
|
42
|
+
* constraints. This may also be caused by a clever compression scheme.
|
|
43
|
+
*
|
|
44
|
+
* It is likely faster to rewrite the table although this is also
|
|
45
|
+
* dangerous because an attacker (or even normal user) can draft a DAG
|
|
46
|
+
* that explodes when expanded carelesslessly. A safer approach is to
|
|
47
|
+
* hash all object references written and reuse those that match. This
|
|
48
|
+
* will expand references into other objects while bounding expansion
|
|
49
|
+
* and it will be safe to update assuming shared objects are ok to
|
|
50
|
+
* update.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
#include "flatcc/flatcc_types.h"
|
|
55
|
+
|
|
56
|
+
#define FLATCC_VERIFY_ERROR_MAP(XX)\
|
|
57
|
+
XX(ok, "ok")\
|
|
58
|
+
XX(buffer_header_too_small, "buffer header too small")\
|
|
59
|
+
XX(identifier_mismatch, "identifier mismatch")\
|
|
60
|
+
XX(max_nesting_level_reached, "max nesting level reached")\
|
|
61
|
+
XX(required_field_missing, "required field missing")\
|
|
62
|
+
XX(runtime_buffer_header_not_aligned, "runtime: buffer header not aligned")\
|
|
63
|
+
XX(runtime_buffer_size_too_large, "runtime: buffer size too large")\
|
|
64
|
+
XX(string_not_zero_terminated, "string not zero terminated")\
|
|
65
|
+
XX(string_out_of_range, "string out of range")\
|
|
66
|
+
XX(struct_out_of_range, "struct out of range")\
|
|
67
|
+
XX(struct_size_overflow, "struct size overflow")\
|
|
68
|
+
XX(struct_unaligned, "struct unaligned")\
|
|
69
|
+
XX(table_field_not_aligned, "table field not aligned")\
|
|
70
|
+
XX(table_field_out_of_range, "table field out of range")\
|
|
71
|
+
XX(table_field_size_overflow, "table field size overflow")\
|
|
72
|
+
XX(table_header_out_of_range_or_unaligned, "table header out of range or unaligned")\
|
|
73
|
+
XX(vector_header_out_of_range_or_unaligned, "vector header out of range or unaligned")\
|
|
74
|
+
XX(string_header_out_of_range_or_unaligned, "string header out of range or unaligned")\
|
|
75
|
+
XX(offset_out_of_range, "offset out of range")\
|
|
76
|
+
XX(table_offset_out_of_range_or_unaligned, "table offset out of range or unaligned")\
|
|
77
|
+
XX(table_size_out_of_range, "table size out of range")\
|
|
78
|
+
XX(type_field_absent_from_required_union_field, "type field absent from required union field")\
|
|
79
|
+
XX(type_field_absent_from_required_union_vector_field, "type field absent from required union vector field")\
|
|
80
|
+
XX(union_cannot_have_a_table_without_a_type, "union cannot have a table without a type")\
|
|
81
|
+
XX(union_type_NONE_cannot_have_a_value, "union value field present with type NONE")\
|
|
82
|
+
XX(vector_count_exceeds_representable_vector_size, "vector count exceeds representable vector size")\
|
|
83
|
+
XX(vector_out_of_range, "vector out of range")\
|
|
84
|
+
XX(vtable_header_out_of_range, "vtable header out of range")\
|
|
85
|
+
XX(vtable_header_too_small, "vtable header too small")\
|
|
86
|
+
XX(vtable_offset_out_of_range_or_unaligned, "vtable offset out of range or unaligned")\
|
|
87
|
+
XX(vtable_size_out_of_range_or_unaligned, "vtable size out of range or unaligned")\
|
|
88
|
+
XX(vtable_size_overflow, "vtable size overflow")\
|
|
89
|
+
XX(union_element_absent_without_type_NONE, "union element absent without type NONE")\
|
|
90
|
+
XX(union_element_present_with_type_NONE, "union element present with type NONE")\
|
|
91
|
+
XX(union_vector_length_mismatch, "union type and table vectors have different lengths")\
|
|
92
|
+
XX(union_vector_verification_not_supported, "union vector verification not supported")\
|
|
93
|
+
XX(not_supported, "not supported")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
enum flatcc_verify_error_no {
|
|
97
|
+
#define XX(no, str) flatcc_verify_error_##no,
|
|
98
|
+
FLATCC_VERIFY_ERROR_MAP(XX)
|
|
99
|
+
#undef XX
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
#define flatcc_verify_ok flatcc_verify_error_ok
|
|
103
|
+
|
|
104
|
+
const char *flatcc_verify_error_string(int err);
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Type specific table verifier function that checks each known field
|
|
108
|
+
* for existence in the vtable and then calls the appropriate verifier
|
|
109
|
+
* function in this library.
|
|
110
|
+
*
|
|
111
|
+
* The table descriptor values have been verified for bounds, overflow,
|
|
112
|
+
* and alignment, but vtable entries after header must be verified
|
|
113
|
+
* for all fields the table verifier function understands.
|
|
114
|
+
*
|
|
115
|
+
* Calls other typespecific verifier functions recursively whenever a
|
|
116
|
+
* table field, union or table vector is encountered.
|
|
117
|
+
*/
|
|
118
|
+
typedef struct flatcc_table_verifier_descriptor flatcc_table_verifier_descriptor_t;
|
|
119
|
+
struct flatcc_table_verifier_descriptor {
|
|
120
|
+
/* Pointer to buffer. Not assumed to be aligned beyond uoffset_t. */
|
|
121
|
+
const void *buf;
|
|
122
|
+
/* Buffer size. */
|
|
123
|
+
flatbuffers_uoffset_t end;
|
|
124
|
+
/* Time to live: number nesting levels left before failure. */
|
|
125
|
+
int ttl;
|
|
126
|
+
/* Vtable of current table. */
|
|
127
|
+
const void *vtable;
|
|
128
|
+
/* Table offset relative to buffer start */
|
|
129
|
+
flatbuffers_uoffset_t table;
|
|
130
|
+
/* Table end relative to buffer start as per vtable[1] field. */
|
|
131
|
+
flatbuffers_voffset_t tsize;
|
|
132
|
+
/* Size of vtable in bytes. */
|
|
133
|
+
flatbuffers_voffset_t vsize;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
typedef int flatcc_table_verifier_f(flatcc_table_verifier_descriptor_t *td);
|
|
137
|
+
|
|
138
|
+
typedef struct flatcc_union_verifier_descriptor flatcc_union_verifier_descriptor_t;
|
|
139
|
+
|
|
140
|
+
struct flatcc_union_verifier_descriptor {
|
|
141
|
+
/* Pointer to buffer. Not assumed to be aligned beyond uoffset_t. */
|
|
142
|
+
const void *buf;
|
|
143
|
+
/* Buffer size. */
|
|
144
|
+
flatbuffers_uoffset_t end;
|
|
145
|
+
/* Time to live: number nesting levels left before failure. */
|
|
146
|
+
int ttl;
|
|
147
|
+
/* Type of union value to be verified */
|
|
148
|
+
flatbuffers_utype_t type;
|
|
149
|
+
/* Offset relative to buffer start to where union value offset is stored. */
|
|
150
|
+
flatbuffers_uoffset_t base;
|
|
151
|
+
/* Offset of union value relative to base. */
|
|
152
|
+
flatbuffers_uoffset_t offset;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
typedef int flatcc_union_verifier_f(flatcc_union_verifier_descriptor_t *ud);
|
|
156
|
+
|
|
157
|
+
/*
|
|
158
|
+
* The `as_root` functions are normally the only functions called
|
|
159
|
+
* explicitly in this interface.
|
|
160
|
+
*
|
|
161
|
+
* If `fid` is null, the identifier is not checked and is allowed to be entirely absent.
|
|
162
|
+
*
|
|
163
|
+
* The buffer must at least be aligned to uoffset_t on systems that
|
|
164
|
+
* require aligned memory addresses. The buffer pointers alignment is
|
|
165
|
+
* not significant to internal verification of the buffer.
|
|
166
|
+
*/
|
|
167
|
+
int flatcc_verify_struct_as_root(const void *buf, size_t bufsiz, const char *fid,
|
|
168
|
+
size_t size, uint16_t align);
|
|
169
|
+
|
|
170
|
+
int flatcc_verify_struct_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash,
|
|
171
|
+
size_t size, uint16_t align);
|
|
172
|
+
|
|
173
|
+
int flatcc_verify_table_as_root(const void *buf, size_t bufsiz, const char *fid,
|
|
174
|
+
flatcc_table_verifier_f *root_tvf);
|
|
175
|
+
|
|
176
|
+
int flatcc_verify_table_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash,
|
|
177
|
+
flatcc_table_verifier_f *root_tvf);
|
|
178
|
+
/*
|
|
179
|
+
* The buffer header is verified by any of the `_as_root` verifiers, but
|
|
180
|
+
* this function may be used as a quick sanity check.
|
|
181
|
+
*/
|
|
182
|
+
int flatcc_verify_buffer_header(const void *buf, size_t bufsiz, const char *fid);
|
|
183
|
+
|
|
184
|
+
int flatcc_verify_typed_buffer_header(const void *buf, size_t bufsiz, flatbuffers_thash_t type_hash);
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
* The following functions are typically called by a generated table
|
|
188
|
+
* verifier function.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/* Scalar, enum or struct field. */
|
|
192
|
+
int flatcc_verify_field(flatcc_table_verifier_descriptor_t *td,
|
|
193
|
+
flatbuffers_voffset_t id, size_t size, uint16_t align);
|
|
194
|
+
/* Vector of scalars, enums or structs. */
|
|
195
|
+
int flatcc_verify_vector_field(flatcc_table_verifier_descriptor_t *td,
|
|
196
|
+
flatbuffers_voffset_t id, int required, size_t elem_size, uint16_t align, size_t max_count);
|
|
197
|
+
int flatcc_verify_string_field(flatcc_table_verifier_descriptor_t *td,
|
|
198
|
+
flatbuffers_voffset_t id, int required);
|
|
199
|
+
int flatcc_verify_string_vector_field(flatcc_table_verifier_descriptor_t *td,
|
|
200
|
+
flatbuffers_voffset_t id, int required);
|
|
201
|
+
int flatcc_verify_table_field(flatcc_table_verifier_descriptor_t *td,
|
|
202
|
+
flatbuffers_voffset_t id, int required, flatcc_table_verifier_f tvf);
|
|
203
|
+
int flatcc_verify_table_vector_field(flatcc_table_verifier_descriptor_t *td,
|
|
204
|
+
flatbuffers_voffset_t id, int required, flatcc_table_verifier_f tvf);
|
|
205
|
+
/* Table verifiers pass 0 as fid. */
|
|
206
|
+
int flatcc_verify_struct_as_nested_root(flatcc_table_verifier_descriptor_t *td,
|
|
207
|
+
flatbuffers_voffset_t id, int required, const char *fid,
|
|
208
|
+
size_t size, uint16_t align);
|
|
209
|
+
int flatcc_verify_table_as_nested_root(flatcc_table_verifier_descriptor_t *td,
|
|
210
|
+
flatbuffers_voffset_t id, int required, const char *fid,
|
|
211
|
+
uint16_t align, flatcc_table_verifier_f tvf);
|
|
212
|
+
|
|
213
|
+
/*
|
|
214
|
+
* A NONE type will not accept a table being present, and a required
|
|
215
|
+
* union will not accept a type field being absent, and an absent type
|
|
216
|
+
* field will not accept a table field being present.
|
|
217
|
+
*
|
|
218
|
+
* If the above checks out and the type is not NONE, the uvf callback
|
|
219
|
+
* is executed. It must test each known table type and silently accept
|
|
220
|
+
* any unknown table type for forward compatibility. A union table
|
|
221
|
+
* value is verified without the required flag because an absent table
|
|
222
|
+
* encodes a typed NULL value while an absent type field encodes a
|
|
223
|
+
* missing union which fails if required.
|
|
224
|
+
*/
|
|
225
|
+
int flatcc_verify_union_field(flatcc_table_verifier_descriptor_t *td,
|
|
226
|
+
flatbuffers_voffset_t id, int required, flatcc_union_verifier_f uvf);
|
|
227
|
+
|
|
228
|
+
int flatcc_verify_union_vector_field(flatcc_table_verifier_descriptor_t *td,
|
|
229
|
+
flatbuffers_voffset_t id, int required, flatcc_union_verifier_f uvf);
|
|
230
|
+
|
|
231
|
+
int flatcc_verify_union_table(flatcc_union_verifier_descriptor_t *ud, flatcc_table_verifier_f *tvf);
|
|
232
|
+
int flatcc_verify_union_struct(flatcc_union_verifier_descriptor_t *ud, size_t size, uint16_t align);
|
|
233
|
+
int flatcc_verify_union_string(flatcc_union_verifier_descriptor_t *ud);
|
|
234
|
+
|
|
235
|
+
#ifdef __cplusplus
|
|
236
|
+
}
|
|
237
|
+
#endif
|
|
238
|
+
|
|
239
|
+
#endif /* FLATCC_VERIFIER_H */
|