51Degrees Device Detection C/C++  4.1Newer Version 4.2

A device detection library that is used natively or by 51Degrees products

hash.h

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is the subject of the following patents and patent
7  * applications, owned by 51 Degrees Mobile Experts Limited of 5 Charlotte
8  * Close, Caversham, Reading, Berkshire, United Kingdom RG4 7BY:
9  * European Patent No. 3438848; and
10  * United States Patent No. 10,482,175.
11  *
12  * This Original Work is licensed under the European Union Public Licence (EUPL)
13  * v.1.2 and is subject to its terms as set out below.
14  *
15  * If a copy of the EUPL was not distributed with this file, You can obtain
16  * one at https://opensource.org/licenses/EUPL-1.2.
17  *
18  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
19  * amended by the European Commission) shall be deemed incompatible for
20  * the purposes of the Work and the provisions of the compatibility
21  * clause in Article 5 of the EUPL shall not apply.
22  *
23  * If using the Work as, or as part of, a network application, by
24  * including the attribution notice(s) required under Article 5 of the EUPL
25  * in the end user terms of the application under an appropriate heading,
26  * such notice(s) shall fulfill the requirements of that article.
27  * ********************************************************************* */
28 
29 #ifndef FIFTYONE_DEGREES_HASH_INCLUDED
30 #define FIFTYONE_DEGREES_HASH_INCLUDED
31 
40 #if !defined(DEBUG) && !defined(_DEBUG) && !defined(NDEBUG)
41 #define NDEBUG
42 #endif
43 
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <limits.h>
48 #include <math.h>
49 #include <time.h>
50 #include <ctype.h>
51 #include <assert.h>
52 #ifdef _MSC_VER
53 #include <windows.h>
54 #endif
55 #include "../common-cxx/data.h"
56 #include "../common-cxx/exceptions.h"
57 #include "../common-cxx/threading.h"
58 #include "../common-cxx/file.h"
59 #include "../common-cxx/collection.h"
60 #include "../common-cxx/evidence.h"
61 #include "../common-cxx/list.h"
62 #include "../common-cxx/resource.h"
63 #include "../common-cxx/properties.h"
64 #include "../common-cxx/status.h"
65 #include "../common-cxx/date.h"
66 #include "../common-cxx/pool.h"
67 #include "../common-cxx/component.h"
68 #include "../common-cxx/property.h"
69 #include "../common-cxx/value.h"
70 #include "../common-cxx/profile.h"
71 #include "../common-cxx/overrides.h"
72 #include "../config-dd.h"
73 #include "../dataset-dd.h"
74 #include "../results-dd.h"
75 #include "graph.h"
76 
78 #ifndef FIFTYONE_DEGREES_CACHE_CONCURRENCY
79 #ifndef FIFTYONE_DEGREES_NO_THREADING
80 #define FIFTYONE_DEGREES_CACHE_CONCURRENCY 10
81 #else
82 #define FIFTYONE_DEGREES_CACHE_CONCURRENCY 1
83 #endif
84 #endif
85 
89 #ifndef FIFTYONE_DEGREES_HASH_DIFFERENCE
90 #define FIFTYONE_DEGREES_HASH_DIFFERENCE 0
91 #endif
92 
96 #ifndef FIFTYONE_DEGREES_HASH_DRIFT
97 #define FIFTYONE_DEGREES_HASH_DRIFT 0
98 #endif
99 
104 #ifndef FIFTYONE_DEGREES_STRING_CACHE_SIZE
105 #define FIFTYONE_DEGREES_STRING_CACHE_SIZE 10000
106 #endif
107 
111 #ifndef FIFTYONE_DEGREES_STRING_LOADED
112 #define FIFTYONE_DEGREES_STRING_LOADED 100
113 #endif
114 
118 #ifndef FIFTYONE_DEGREES_NODE_CACHE_SIZE
119 #define FIFTYONE_DEGREES_NODE_CACHE_SIZE 50000
120 #endif
121 
125 #ifndef FIFTYONE_DEGREES_NODE_LOADED
126 #define FIFTYONE_DEGREES_NODE_LOADED 100
127 #endif
128 
132 #ifndef FIFTYONE_DEGREES_PROFILE_CACHE_SIZE
133 #define FIFTYONE_DEGREES_PROFILE_CACHE_SIZE 10000
134 #endif
135 
139 #ifndef FIFTYONE_DEGREES_PROFILE_LOADED
140 #define FIFTYONE_DEGREES_PROFILE_LOADED 100
141 #endif
142 
146 #ifndef FIFTYONE_DEGREES_VALUE_CACHE_SIZE
147 #define FIFTYONE_DEGREES_VALUE_CACHE_SIZE 500
148 #endif
149 
153 #ifndef FIFTYONE_DEGREES_VALUE_LOADED
154 #define FIFTYONE_DEGREES_VALUE_LOADED 0
155 #endif
156 
160 #ifndef FIFTYONE_DEGREES_PROPERTY_CACHE_SIZE
161 #define FIFTYONE_DEGREES_PROPERTY_CACHE_SIZE 0
162 #endif
163 
167 #ifndef FIFTYONE_DEGREES_PROPERTY_LOADED
168 #define FIFTYONE_DEGREES_PROPERTY_LOADED INT_MAX
169 #endif
170 
179 typedef enum e_fiftyone_degrees_hash_match_method {
180  FIFTYONE_DEGREES_HASH_MATCH_METHOD_NONE,
181  FIFTYONE_DEGREES_HASH_MATCH_METHOD_PERFORMANCE,
182  FIFTYONE_DEGREES_HASH_MATCH_METHOD_COMBINED,
183  FIFTYONE_DEGREES_HASH_MATCH_METHOD_PREDICTIVE,
186 
188 #pragma pack(push, 1)
189 typedef struct fiftyoneDegrees_hash_dataset_header_t {
190  const int32_t versionMajor;
191  const int32_t versionMinor;
192  const int32_t versionBuild;
193  const int32_t versionRevision;
195  const byte tag[16];
196  const byte exportTag[16];
197  const int32_t copyrightOffset;
199  const int16_t age;
200  const int32_t minUserAgentCount;
202  const int32_t nameOffset;
204  const int32_t formatOffset;
232 #pragma pack(pop)
233 
239 typedef struct fiftyone_degrees_config_hash_t {
254  int32_t difference;
258  int32_t drift;
265  bool traceRoute;
270 
275 typedef struct fiftyone_degrees_hash_rootnodes_t {
281 
291 typedef struct fiftyone_degrees_dataset_hash_t {
312 
314 typedef struct fiftyone_degrees_result_hash_t fiftyoneDegreesResultHash;
322 typedef struct fiftyone_degrees_result_hash_t {
324  uint32_t *profileOffsets;
331  int32_t iterations;
333  int32_t difference;
335  int32_t drift;
337  int32_t matchedNodes;
345 
349 #define FIFTYONE_DEGREES_RESULTS_HASH_MEMBERS \
350  fiftyoneDegreesResultsDeviceDetection b; \
351  fiftyoneDegreesCollectionItem propertyItem; \
353  fiftyoneDegreesList values;
356 FIFTYONE_DEGREES_ARRAY_TYPE(
469  const char *fileName,
470  fiftyoneDegreesException *exception);
471 
496  const char *fileName,
497  fiftyoneDegreesException *exception);
498 
519  void *memory,
520  long size,
521  fiftyoneDegreesException *exception);
522 
471 
496  const char *fileName,
497  fiftyoneDegreesException *exception);
498 
519  void *memory,
520  long size,
521  fiftyoneDegreesException *exception);
522 
546  void *memory,
547  long size,
548  fiftyoneDegreesException *exception);
549 
566  fiftyoneDegreesException *exception);
567 
579  const char* userAgent,
580  size_t userAgentLength,
581  fiftyoneDegreesException *exception);
582 
594  const char* deviceId,
595  size_t deviceIdLength,
596  fiftyoneDegreesException *exception);
597 
611  uint32_t userAgentCapacity,
612  uint32_t overridesCapacity);
613 
620 EXTERNAL void fiftyoneDegreesResultsHashFree(
621  fiftyoneDegreesResultsHash* results);
622 
636  int requiredPropertyIndex,
637  fiftyoneDegreesException *exception);
638 
652  int requiredPropertyIndex,
653  fiftyoneDegreesException *exception);
654 
662 
678  int requiredPropertyIndex,
679  fiftyoneDegreesException *exception);
680 
695  const char *propertyName,
696  char *buffer,
697  size_t bufferLength,
698  const char *separator,
699  fiftyoneDegreesException *exception);
700 
713 EXTERNAL size_t
716  const int requiredPropertyIndex,
717  char *buffer,
718  size_t bufferLength,
719  const char *separator,
720  fiftyoneDegreesException *exception);