51Degrees Device Detection C/C++  4.1

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

dataset.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 licensed under the European Union Public Licence (EUPL)
7  * v.1.2 and is subject to its terms as set out below.
8  *
9  * If a copy of the EUPL was not distributed with this file, You can obtain
10  * one at https://opensource.org/licenses/EUPL-1.2.
11  *
12  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13  * amended by the European Commission) shall be deemed incompatible for
14  * the purposes of the Work and the provisions of the compatibility
15  * clause in Article 5 of the EUPL shall not apply.
16  *
17  * If using the Work as, or as part of, a network application, by
18  * including the attribution notice(s) required under Article 5 of the EUPL
19  * in the end user terms of the application under an appropriate heading,
20  * such notice(s) shall fulfill the requirements of that article.
21  * ********************************************************************* */
22 
23 #ifndef FIFTYONE_DEGREES_DATASET_H_INCLUDED
24 #define FIFTYONE_DEGREES_DATASET_H_INCLUDED
25 
89 #include "exceptions.h"
90 #include "file.h"
91 #include "memory.h"
92 #include "resource.h"
93 #include "properties.h"
94 #include "headers.h"
95 #include "config.h"
96 #include "overrides.h"
97 
101 typedef struct fiftyone_degrees_dataset_base_t {
102  const char fileName[FIFTYONE_DEGREES_FILE_MAX_PATH];
109  const char masterFileName[FIFTYONE_DEGREES_FILE_MAX_PATH];
113  void *memoryToFree;
118  bool isInMemory;
128  const void *config;
130 
148  void *dataSet,
149  const void *config,
151  void *memory,
152  long size,
153  fiftyoneDegreesException *exception);
154 
172  void *dataSet,
173  const void *config,
175  const char *fileName,
176  fiftyoneDegreesException *exception);
177 
195  void *state,
196  fiftyoneDegreesPropertiesGetMethod getPropertyMethod,
197  fiftyoneDegreesEvidencePropertiesGetMethod getEvidencePropertiesMethod);
198 
213  void *state,
214  fiftyoneDegreesHeadersGetMethod getHeaderMethod);
215 
231  const char *fileName,
232  long bytesToCompare);
233 
245 
251 
261 
268 
275 
300  void *source,
301  long length,
302  size_t dataSetSize,
304  fiftyoneDegreesException *exception);
305 
328  const char *fileName,
329  size_t dataSetSize,
331  fiftyoneDegreesException *exception);
332 
340 #define FIFTYONE_DEGREES_DATASET_RELOAD(t) \
341  \
359 fiftyoneDegreesStatusCode fiftyoneDegrees##t##ReloadManagerFromMemory( \
360 fiftyoneDegreesResourceManager *manager, \
361 void *source, \
362 long length, \
363 fiftyoneDegreesException *exception) { \
364  return fiftyoneDegreesDataSetReloadManagerFromMemory( \
365  manager, \
366  source, \
367  length, \
368  sizeof(DataSet##t), \
369  initDataSetFromMemory, \
370  exception); \
371 } \
372  \
388 fiftyoneDegreesStatusCode fiftyoneDegrees##t##ReloadManagerFromFile( \
389 fiftyoneDegreesResourceManager* manager, \
390 const char *fileName, \
391 fiftyoneDegreesException *exception) { \
392  return fiftyoneDegreesDataSetReloadManagerFromFile( \
393  manager, \
394  fileName, \
395  sizeof(DataSet##t), \
396  initDataSetFromFile, \
397  exception); \
398 } \
399  \
414 fiftyoneDegreesStatusCode fiftyoneDegrees##t##ReloadManagerFromOriginalFile( \
415 fiftyoneDegreesResourceManager* manager, \
416 fiftyoneDegreesException *exception) { \
417  fiftyoneDegreesStatusCode status = FIFTYONE_DEGREES_STATUS_NOT_SET; \
418  DataSet##t* dataSet = fiftyoneDegreesDataSet##t##Get(manager); \
419  status = fiftyoneDegrees##t##ReloadManagerFromFile( \
420  manager, \
421  dataSet->b.b.masterFileName, \
422  exception); \
423  fiftyoneDegreesDataSet##t##Release(dataSet); \
424  return status; \
425 }
426 
431 #endif
bool isInMemory
True if the data file has been read into continuous memory.
Definition: dataset.h:118
fiftyoneDegreesFilePool filePool
Linked list of file readers.
Definition: dataset.h:120
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetInitProperties(fiftyoneDegreesDataSetBase *dataSet, fiftyoneDegreesPropertiesRequired *properties, void *state, fiftyoneDegreesPropertiesGetMethod getPropertyMethod, fiftyoneDegreesEvidencePropertiesGetMethod getEvidencePropertiesMethod)
Initialises the properties in the data set.
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:82
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetInitHeaders(fiftyoneDegreesDataSetBase *dataSet, void *state, fiftyoneDegreesHeadersGetMethod getHeaderMethod)
Initialises the HTTP headers in the data set.
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetReloadManagerFromMemory(fiftyoneDegreesResourceManager *manager, void *source, long length, size_t dataSetSize, fiftyoneDegreesDataSetInitFromMemoryMethod initDataSet, fiftyoneDegreesException *exception)
Reload the data set being used by the resource manager using a data file loaded into contiguous memor...
fiftyoneDegreesResourceHandle * handle
Pointer to the handle that tracks this data set instance.
Definition: dataset.h:121
fiftyoneDegreesStatusCode(* fiftyoneDegreesDataSetInitFromMemoryMethod)(void *dataSet, const void *config, fiftyoneDegreesPropertiesRequired *properties, void *memory, long size, fiftyoneDegreesException *exception)
Initialses the data set from data stored in continuous memory.
Definition: dataset.h:147
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetInitInMemory(fiftyoneDegreesDataSetBase *dataSet, fiftyoneDegreesMemoryReader *reader)
Initialses the data set from data stored in continuous memory.
void * memoryToFree
A pointer to the memory where the data within the data set is held.
Definition: dataset.h:113
void fiftyoneDegreesDataSetFree(fiftyoneDegreesDataSetBase *dataSet)
Closes the data set by freeing anything which has been initialised at creation.
Used to read data from memory in a similar manner to a file handle.
Definition: memory.h:58
uint32_t(* fiftyoneDegreesEvidencePropertiesGetMethod)(void *state, fiftyoneDegreesPropertyAvailable *property, fiftyoneDegreesEvidenceProperties *evidenceProperties)
Populates the evidence properties structure with the indexes of the properties required by the proper...
Definition: properties.h:218
fiftyoneDegreesPropertiesAvailable * available
Available properties.
Definition: dataset.h:123
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetReloadManagerFromFile(fiftyoneDegreesResourceManager *manager, const char *fileName, size_t dataSetSize, fiftyoneDegreesDataSetInitFromFileMethod initDataSet, fiftyoneDegreesException *exception)
Reload the data set being used by the resource manager using the data file location specified.
Array of items of type fiftyoneDegreesHeader used to easily access and track the size of the array.
Definition: headers.h:131
fiftyoneDegreesStatusCode fiftyoneDegreesDataSetInitFromFile(fiftyoneDegreesDataSetBase *dataSet, const char *fileName, long bytesToCompare)
Initialses the data set from data stored on file.
fiftyoneDegreesString *(* fiftyoneDegreesPropertiesGetMethod)(void *state, uint32_t index, fiftyoneDegreesCollectionItem *item)
Returns a string for the property at the index provided or NULL if there is no property available at ...
Definition: properties.h:200
Array of items of type fiftyoneDegreesPropertyAvailable used to easily access and track the size of t...
Definition: properties.h:170
Tracks the number of active uses of the resource within the manager.
Definition: resource.h:174
const void * config
Pointer to the config used to create the dataset.
Definition: dataset.h:128
fiftyoneDegreesOverridePropertyArray * overridable
Array of properties that can be overridden.
Definition: dataset.h:125
fiftyoneDegreesStatusCode(* fiftyoneDegreesDataSetInitFromFileMethod)(void *dataSet, const void *config, fiftyoneDegreesPropertiesRequired *properties, const char *fileName, fiftyoneDegreesException *exception)
Initialses the data set from data stored on file.
Definition: dataset.h:171
Defines a set of properties which are required by a caller.
Definition: properties.h:180
Manager structure used to provide access to a shared and changing resource.
Definition: resource.h:188
Base data set structure which contains the 'must have's for all data sets.
Definition: dataset.h:101
void fiftyoneDegreesDataSetReset(fiftyoneDegreesDataSetBase *dataSet)
Resets a newly allocated data set structure ready for initialisation.
fiftyoneDegreesDataSetBase * fiftyoneDegreesDataSetGet(fiftyoneDegreesResourceManager *manager)
Gets a pointer to the active data set from a resource manager.
fiftyoneDegreesHeaders * uniqueHeaders
Related HTTP headers.
Definition: dataset.h:124
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:116
Stack of handles used to read data from a single source file.
Definition: file.h:222
void fiftyoneDegreesDataSetRelease(fiftyoneDegreesDataSetBase *dataSet)
Releases a reference to a data set which has been fetched via the DataSetGet method.
#define FIFTYONE_DEGREES_FILE_MAX_PATH
Define the max path length on the target system.
Definition: file.h:202
long(* fiftyoneDegreesHeadersGetMethod)(void *state, uint32_t index, fiftyoneDegreesCollectionItem *nameItem)
Gets the unique id and name of the header at the requested index.
Definition: headers.h:146
Array of items of type fiftyoneDegreesOverrideProperty used to easily access and track the size of th...
Definition: overrides.h:102