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

properties.h

1/* *********************************************************************
2 * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
4 * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 *
6 * This Original Work is licensed under the European Union Public Licence
7 * (EUPL) 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
133
134#ifndef FIFTYONE_DEGREES_PROPERTIES_H_INCLUDED
135#define FIFTYONE_DEGREES_PROPERTIES_H_INCLUDED
136
137#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
138#include "ipiSymbols.h"
139#endif
140
141#include <stdint.h>
142#ifdef _MSC_FULL_VER
143#include <string.h>
144#else
145#include <strings.h>
146#define _stricmp strcasecmp
147#define _strnicmp strncasecmp
148#endif
149#include "string.h"
150#include "list.h"
151#include "data.h"
152#include "collection.h"
153#include "array.h"
154#include "common.h"
155
157#define FIFTYONE_DEGREES_PROPERTIES_SEPARATORS "|, "
158
164
166
167
172
174typedef struct fiftyone_degrees_property_available_t {
175 uint32_t propertyIndex;
198
202typedef struct fiftyone_degrees_property_named_t {
208
211 bool allComponentsRequired;
216 bool namesFromDataSet;
221 uint32_t namedCount;
230)
231
235
240EXTERNAL typedef struct fiftyone_degrees_properties_required_t {
241 const char **array;
244 int count;
245 const char *string;
251
260typedef const fiftyoneDegreesString*(*fiftyoneDegreesPropertiesGetMethod)(
261 void *state,
262 uint32_t index,
264
279 void* state,
281 fiftyoneDegreesEvidenceProperties* evidenceProperties);
282
288EXTERNAL_VAR fiftyoneDegreesPropertiesRequired fiftyoneDegreesPropertiesDefault;
289
312 void *state,
313 fiftyoneDegreesPropertiesGetMethod getPropertyMethod,
314 fiftyoneDegreesEvidencePropertiesGetMethod getEvidencePropertiesMethod);
315
324 const char *propertyName);
325
338 const char *propertyName);
339
350 int requiredPropertyIndex);
351
361EXTERNAL fiftyoneDegreesString*
364 int requiredPropertyIndex);
365
369#if defined(_MSC_VER)
370#define FIFTYONE_DEGREES_PROPERTIES_INLINE static __inline
371#elif defined(__GNUC__) || defined(__clang__)
372#define FIFTYONE_DEGREES_PROPERTIES_INLINE static __inline__
373#else
374#define FIFTYONE_DEGREES_PROPERTIES_INLINE static inline
375#endif
376
388 const fiftyoneDegreesPropertiesAvailable *available) {
389 if (available == NULL) {
390 return 0;
391 }
392 return available->named != NULL ? available->namedCount : available->count;
393}
394
404 const fiftyoneDegreesPropertiesAvailable *available,
405 int requiredPropertyIndex) {
406 if (available == NULL || requiredPropertyIndex < 0) {
407 return -1;
408 }
409 if (available->named != NULL) {
410 return (uint32_t)requiredPropertyIndex < available->namedCount ?
411 (int)available->named[requiredPropertyIndex].availableIndex :
412 -1;
413 }
414 return (uint32_t)requiredPropertyIndex < available->count ?
415 requiredPropertyIndex :
416 -1;
417}
418
429 const char *propertyName) {
431 available,
433 available,
434 propertyName));
435}
436
446 const fiftyoneDegreesPropertiesAvailable *available,
447 int availableIndex) {
448 if (available == NULL ||
449 availableIndex < 0 ||
450 (uint32_t)availableIndex >= available->count) {
451 return -1;
452 }
453 return (int)available->items[availableIndex].propertyIndex;
454}
455
464
473 const fiftyoneDegreesPropertiesRequired *properties,
474 uint32_t total);
475
483
487
488#endif
#define FIFTYONE_DEGREES_ARRAY_TYPE(t, m)
Simple array structure definition macro used for generic types.
Definition array.h:55
#define FIFTYONE_DEGREES_PROPERTIES_INLINE
The functions below are inline, so they add no name to the library.
Definition properties.h:374
bool fiftyoneDegreesPropertiesRequiredNamesFewerThan(const fiftyoneDegreesPropertiesRequired *properties, uint32_t total)
Checks whether the properties required name some properties, and fewer than the data file has.
FIFTYONE_DEGREES_PROPERTIES_INLINE uint32_t fiftyoneDegreesPropertiesGetRequiredPropertyCount(const fiftyoneDegreesPropertiesAvailable *available)
Gets the number of required property indexes, which is the number of names the caller gave,...
Definition properties.h:387
fiftyoneDegreesEvidencePropertyIndexArray fiftyoneDegreesEvidenceProperties
Array of properties which are required to fetch additional evidence for a specific property.
Definition properties.h:171
fiftyoneDegreesString * fiftyoneDegreesPropertiesGetNameFromRequiredIndex(fiftyoneDegreesPropertiesAvailable *available, int requiredPropertyIndex)
Gets the name as a string from the required property index.
const 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:260
int fiftyoneDegreesPropertiesGetRequiredPropertyIndexFromName(fiftyoneDegreesPropertiesAvailable *available, const char *propertyName)
Gets the required property index of the property named, which is its place in the names the caller ga...
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:278
FIFTYONE_DEGREES_PROPERTIES_INLINE int fiftyoneDegreesPropertiesGetAvailableIndex(const fiftyoneDegreesPropertiesAvailable *available, int requiredPropertyIndex)
Gets the available index of the property at the required property index.
Definition properties.h:403
FIFTYONE_DEGREES_PROPERTIES_INLINE int fiftyoneDegreesPropertiesGetPropertyIndexFromAvailableIndex(const fiftyoneDegreesPropertiesAvailable *available, int availableIndex)
Maps the available index to the index in the source data structure.
Definition properties.h:445
uint32_t fiftyoneDegreesEvidencePropertyIndex
Index in the properties collection to a property which is required to get evidence for another proper...
Definition properties.h:163
int fiftyoneDegreesPropertiesGetPropertyIndexFromRequiredIndex(fiftyoneDegreesPropertiesAvailable *available, int requiredPropertyIndex)
Maps the required property index to the index in the source data structure.
fiftyoneDegreesPropertyAvailableArray fiftyoneDegreesPropertiesAvailable
Array of properties which are available in a data set.
Definition properties.h:234
int fiftyoneDegreesPropertiesGetPropertyIndexFromName(fiftyoneDegreesPropertiesAvailable *available, const char *propertyName)
Gets the index of the property in the source data structure from the name.
FIFTYONE_DEGREES_PROPERTIES_INLINE int fiftyoneDegreesPropertiesGetAvailableIndexFromName(fiftyoneDegreesPropertiesAvailable *available, const char *propertyName)
Gets the available index of the property named.
Definition properties.h:427
bool fiftyoneDegreesPropertiesIsSetHeaderAvailable(fiftyoneDegreesPropertiesAvailable *available)
Check if the 'SetHeader' properties are included in the available required properties.
fiftyoneDegreesPropertiesAvailable * fiftyoneDegreesPropertiesCreate(fiftyoneDegreesPropertiesRequired *properties, void *state, fiftyoneDegreesPropertiesGetMethod getPropertyMethod, fiftyoneDegreesEvidencePropertiesGetMethod getEvidencePropertiesMethod)
Creates a properties result instance for use with future property operations.
void fiftyoneDegreesPropertiesFree(fiftyoneDegreesPropertiesAvailable *available)
Frees the memory and resources used by the properties results previously created using the fiftyoneDe...
Used to store a handle to the underlying item that could be used to release the item when it's finish...
Definition collection.h:317
Array of items of type fiftyoneDegreesEvidencePropertyIndex used to easily access and track the size ...
Definition properties.h:165
Defines a set of properties which are required by a caller.
Definition properties.h:240
int count
Number of properties in array.
Definition properties.h:244
const char * string
Separated list of required properties or NULL if all properties are required.
Definition properties.h:245
fiftyoneDegreesPropertiesAvailable * existing
A pointer to an existing set of property names from another instance.
Definition properties.h:247
const char ** array
Array of required properties or NULL if all properties are required.
Definition properties.h:241
Array of items of type fiftyoneDegreesPropertyAvailable used to easily access and track the size of t...
Definition properties.h:215
fiftyoneDegreesPropertyNamed * named
The names the caller gave, in the caller's order, or NULL when the caller named no property and this ...
Definition properties.h:225
bool namesFromDataSet
True when the caller named no property, so the names are those of the first data set loaded.
Definition properties.h:219
uint32_t count
Number of used items.
Definition properties.h:215
uint32_t namedCount
Number of names the caller gave, which is the number of required property indexes when the caller nam...
Definition properties.h:223
fiftyoneDegreesPropertyAvailable * items
Pointer to the first item.
Definition properties.h:215
Used to access the property item quickly without the need to search.
Definition properties.h:174
int32_t requiredPropertyIndex
Index of the property in the names the caller gave, the first if the name was given more than once,...
Definition properties.h:191
fiftyoneDegreesCollectionItem name
Name of the property from strings.
Definition properties.h:177
uint32_t propertyIndex
Index of the property in the collection of all properties.
Definition properties.h:175
bool delayExecution
True if the execution any JavaScript returned as a value of this property should be delayed.
Definition properties.h:182
byte componentIndex
Index in the data set's component list of the component the property belongs to.
Definition properties.h:187
fiftyoneDegreesEvidenceProperties * evidenceProperties
Evidence properties which are required by this property.
Definition properties.h:178
A property name the caller gave, in the place the caller gave it.
Definition properties.h:202
int32_t availableIndex
Index of the property in the available properties, or -1 when the data does not have the property.
Definition properties.h:203
const fiftyoneDegreesString * name
The name as the caller gave it.
Definition properties.h:206
Definition string.h:97