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
130
131#ifndef FIFTYONE_DEGREES_PROPERTIES_H_INCLUDED
132#define FIFTYONE_DEGREES_PROPERTIES_H_INCLUDED
133
134#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
135#include "ipiSymbols.h"
136#endif
137
138#include <stdint.h>
139#ifdef _MSC_FULL_VER
140#include <string.h>
141#else
142#include <strings.h>
143#define _stricmp strcasecmp
144#define _strnicmp strncasecmp
145#endif
146#include "string.h"
147#include "list.h"
148#include "data.h"
149#include "collection.h"
150#include "array.h"
151#include "common.h"
152
154#define FIFTYONE_DEGREES_PROPERTIES_SEPARATORS "|, "
155
161
163
164
169
171typedef struct fiftyone_degrees_property_available_t {
172 uint32_t propertyIndex;
193
197typedef struct fiftyone_degrees_property_named_t {
203
206 bool allComponentsRequired;
211 uint32_t namedCount;
219)
220
224
229EXTERNAL typedef struct fiftyone_degrees_properties_required_t {
230 const char **array;
233 int count;
234 const char *string;
240
249typedef const fiftyoneDegreesString*(*fiftyoneDegreesPropertiesGetMethod)(
250 void *state,
251 uint32_t index,
253
268 void* state,
270 fiftyoneDegreesEvidenceProperties* evidenceProperties);
271
277EXTERNAL_VAR fiftyoneDegreesPropertiesRequired fiftyoneDegreesPropertiesDefault;
278
301 void *state,
302 fiftyoneDegreesPropertiesGetMethod getPropertyMethod,
303 fiftyoneDegreesEvidencePropertiesGetMethod getEvidencePropertiesMethod);
304
313 const char *propertyName);
314
327 const char *propertyName);
328
339 int requiredPropertyIndex);
340
350EXTERNAL fiftyoneDegreesString*
353 int requiredPropertyIndex);
354
358#if defined(_MSC_VER)
359#define FIFTYONE_DEGREES_PROPERTIES_INLINE static __inline
360#elif defined(__GNUC__) || defined(__clang__)
361#define FIFTYONE_DEGREES_PROPERTIES_INLINE static __inline__
362#else
363#define FIFTYONE_DEGREES_PROPERTIES_INLINE static inline
364#endif
365
377 const fiftyoneDegreesPropertiesAvailable *available) {
378 if (available == NULL) {
379 return 0;
380 }
381 return available->named != NULL ? available->namedCount : available->count;
382}
383
393 const fiftyoneDegreesPropertiesAvailable *available,
394 int requiredPropertyIndex) {
395 if (available == NULL || requiredPropertyIndex < 0) {
396 return -1;
397 }
398 if (available->named != NULL) {
399 return (uint32_t)requiredPropertyIndex < available->namedCount ?
400 (int)available->named[requiredPropertyIndex].availableIndex :
401 -1;
402 }
403 return (uint32_t)requiredPropertyIndex < available->count ?
404 requiredPropertyIndex :
405 -1;
406}
407
418 const char *propertyName) {
420 available,
422 available,
423 propertyName));
424}
425
435 const fiftyoneDegreesPropertiesAvailable *available,
436 int availableIndex) {
437 if (available == NULL ||
438 availableIndex < 0 ||
439 (uint32_t)availableIndex >= available->count) {
440 return -1;
441 }
442 return (int)available->items[availableIndex].propertyIndex;
443}
444
453
461
465
466#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:363
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:376
fiftyoneDegreesEvidencePropertyIndexArray fiftyoneDegreesEvidenceProperties
Array of properties which are required to fetch additional evidence for a specific property.
Definition properties.h:168
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:249
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:267
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:392
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:434
uint32_t fiftyoneDegreesEvidencePropertyIndex
Index in the properties collection to a property which is required to get evidence for another proper...
Definition properties.h:160
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:223
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:416
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:315
Array of items of type fiftyoneDegreesEvidencePropertyIndex used to easily access and track the size ...
Definition properties.h:162
Defines a set of properties which are required by a caller.
Definition properties.h:229
int count
Number of properties in array.
Definition properties.h:233
const char * string
Separated list of required properties or NULL if all properties are required.
Definition properties.h:234
fiftyoneDegreesPropertiesAvailable * existing
A pointer to an existing set of property names from another instance.
Definition properties.h:236
const char ** array
Array of required properties or NULL if all properties are required.
Definition properties.h:230
Array of items of type fiftyoneDegreesPropertyAvailable used to easily access and track the size of t...
Definition properties.h:209
fiftyoneDegreesPropertyNamed * named
The names the caller gave, in the caller's order, or NULL when the caller named no property.
Definition properties.h:215
uint32_t count
Number of used items.
Definition properties.h:209
uint32_t namedCount
Number of names the caller gave, which is the number of required property indexes when the caller nam...
Definition properties.h:213
fiftyoneDegreesPropertyAvailable * items
Pointer to the first item.
Definition properties.h:209
Used to access the property item quickly without the need to search.
Definition properties.h:171
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:188
fiftyoneDegreesCollectionItem name
Name of the property from strings.
Definition properties.h:174
uint32_t propertyIndex
Index of the property in the collection of all properties.
Definition properties.h:172
bool delayExecution
True if the execution any JavaScript returned as a value of this property should be delayed.
Definition properties.h:179
byte componentIndex
Index in the data set's component list of the component the property belongs to.
Definition properties.h:184
fiftyoneDegreesEvidenceProperties * evidenceProperties
Evidence properties which are required by this property.
Definition properties.h:175
A property name the caller gave, in the place the caller gave it.
Definition properties.h:197
int32_t availableIndex
Index of the property in the available properties, or -1 when the data does not have the property.
Definition properties.h:198
const fiftyoneDegreesString * name
The name as the caller gave it.
Definition properties.h:201
Definition string.h:97