GS1 Barcode Syntax Tests reference
A reference to the AI component "linter" routines referred to by the GS1 Barcode Syntax Dictionary. Copyright (c) 2022-2024 GS1 AISBL.
Macros
lint_key.c File Reference

Macros

#define GCP_MIN_LENGTH   4
 Currently the shortest GS1 Company Prefix is four digits.
 

Purpose

The key linter checks whether an input starts with a GS1 Company Prefix ("GCP").

Remarks
The GCP is defined in the GS1 General Specifications section "GS1 Company Prefix".

Functional Description

◆ gs1_lint_key()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_key ( const char *const  data,
size_t *const  err_pos,
size_t *const  err_len 
)

Used to ensure that an AI component starts with a GCP.

Note
To enable this linter to hook into a GS1 Company Prefix lookup service containing a record of current GCP allocations (provided by the user) the GS1_LINTER_CUSTOM_GCP_LOOKUP_H macro may be set to the name of a header file to be included that defines a custom GS1_LINTER_CUSTOM_GCP_LOOKUP macro.
If provided, the GS1_LINTER_CUSTOM_GCP_LOOKUP macro shall invoke whatever API is defined by the user-provided GCP lookup service, then using the result must assign to locally-scoped variables as follows:
  • valid: Set to 1 if the GCP is valid (or should be treated as such). Otherwise 0.
  • offline: Set to 1 to indicate that the GCP data source is offline and the linter must fail. Otherwise 0.
Parameters
[in]dataPointer to the null-terminated data to be linted. Must not be NULL.
[out]err_posTo facilitate error highlighting, the start position of the bad data is written to this pointer, if not NULL.
[out]err_lenThe length of the bad data is written to this pointer, if not NULL.
Returns
GS1_LINTER_OK if okay.
GS1_LINTER_INVALID_GCP_PREFIX if the data does not start with a GCP.
GS1_LINTER_TOO_SHORT_FOR_KEY if the data is too short to start with a GCP.
GS1_LINTER_GCP_DATASOURCE_OFFLINE if the user-provided GCP lookup source is unavailable and this should result in the linting failing. [IMPLEMENTATION SPECIFIC]
Note
The choice of whether or not to assign offline = 1 in order to return GS1_LINTER_GCP_DATASOURCE_OFFLINE when a user-provided GCP lookup service is unavailable is implementation specific. It depends on whether the desired behaviour is to fail open (return GS1_LINTER_OK) or to fail closed (return GS1_LINTER_GCP_DATASOURCE_OFFLINE). In the case that it is desirable to fail open then in addition to assigning offline = 0 it is necessary to assign valid = 1 to avoid returning GS1_LINTER_INVALID_GCP_PREFIX, which would be misleading in the event of service outage.
97{
98
99 size_t i, len;
100
101 assert(data);
102
103 len = strlen(data);
104
105 /*
106 * The current minimum GCP length is defined by GCP_MIN_LENGTH.
107 *
108 */
109 if (len < GCP_MIN_LENGTH)
112 0,
113 len
114 );
115
116 /*
117 * Any character within the minimum-length GCP prefix that is outside
118 * the range '0' to '9' is illegal.
119 *
120 */
121 for (i = 0; i < GCP_MIN_LENGTH; i++) {
122 if (data[i] < '0' || data[i] > '9')
125 i,
126 1
127 );
128 }
129
130 /*
131 * Call the custom GCP lookup routine if one has been provided.
132 *
133 */
134#ifdef GS1_LINTER_CUSTOM_GCP_LOOKUP
135{
136 int valid = 0, offline = 0;
137 GS1_LINTER_CUSTOM_GCP_LOOKUP(data);
138 if (offline)
140 else if (!valid)
142}
143#endif
144
146
147}
#define GS1_LINTER_RETURN_ERROR(error, position, length)
Return from a linter indicating that a problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:77
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:62
@ GS1_LINTER_TOO_SHORT_FOR_KEY
The component is shorter than the minimum length GS1 Company Prefix.
Definition gs1syntaxdictionary.h:88
@ GS1_LINTER_GCP_DATASOURCE_OFFLINE
The data source for GCP lookups is offline.
Definition gs1syntaxdictionary.h:87
@ GS1_LINTER_INVALID_GCP_PREFIX
The GS1 Company Prefix is invalid.
Definition gs1syntaxdictionary.h:89
#define GCP_MIN_LENGTH
Currently the shortest GS1 Company Prefix is four digits.
Definition lint_key.c:50