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.
lint_mediatype.c File Reference

Purpose

The mediatype linter ensures that the data represents a valid AIDC media type.

Remarks
The two-digit AIDC media type codes are defined in the GS1 General Specifications table "AIDC media type values".

Functional Description

◆ gs1_lint_mediatype()

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

Used to validate that an AI component is a valid AIDC media type.

Note
To enable this linter to hook into an alternative AIDC media type lookup function (provided by the user) the GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP_H macro may be set to the name of a header file to be included that defines a custom GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP macro.
If provided, the GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP macro shall invoke whatever functionality is available in the user-provided lookup function, then using the result must assign to a locally-scoped variable as follows:
  • valid: Set to 1 if the lookup was successful. 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_MEDIA_TYPE if the data is not a num-3 country code.
79{
80
81 /*
82 * Allow for a custom replacement of the lookup code to be provided.
83 *
84 */
85#ifdef GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP
86#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP(cc)
87#else
88
89 /*
90 * Set of valid AIDC media type values
91 *
92 * MAINTENANCE NOTE:
93 *
94 * Updates to the AIDC media type list shall be announced by GSCN
95 *
96 */
97 static const uint8_t mediatypes[] = {
98#if __STDC_VERSION__ >= 202311L
99 0b01111111, 0b11100000, // 00: Not used
100 // 01-10: ICCBBA assignments
101 // 11-15: Reserved for future assignment by ICCBBA
102 0b00000000, 0b00000000, // 16-29: Reserved for future assignment by ICCBBA
103 // 30-31: Reserved for future assignment by GS1
104 0b00000000, 0b00000000, // 32-47: Reserved for future assignment by GS1
105 0b00000000, 0b00000000, // 48-59: Reserved for future assignment by GS1
106 // 60-63: Reserved for future assignment by ICCBBA or GS1
107 0b00000000, 0b00000000, // 64-79: Reserved for future assignment by ICCBBA or GS1
108 0b11111111, 0b11111111, // 80-95: ICCBBA local / national use
109 0b11110000, // 96-99: ICCBBA local / national use
110#else
111 /*
112 * Fallback for compilers lacking binary literal support.
113 *
114 * Generated from the above data with:
115 *
116 * for (size_t i = 0; i < sizeof(mediatypes) / sizeof(mediatypes[0]); i++) { printf("0x%02x, ", mediatypes[i]); };
117 *
118 */
119 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0,
120#endif
121 };
122
123/// \cond
124#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) do { \
125 if (strlen(cc) == 2 && isdigit(cc[0]) && isdigit(cc[1])) { \
126 int v = (cc[0] - '0') * 10 + (cc[1] - '0'); \
127 GS1_LINTER_BITFIELD_LOOKUP(v, mediatypes); \
128 } \
129} while (0)
130/// \endcond
131
132#endif
133
134 int valid = 0;
135
136 assert(data);
137
138 /*
139 * Ensure that the data is in the list.
140 *
141 */
142 GS1_LINTER_MEDIA_TYPE_LOOKUP(data);
143 if (valid)
145
146 /*
147 * If not valid then indicate an error.
148 *
149 */
152 0,
153 strlen(data)
154 );
155
156}
#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_INVALID_MEDIA_TYPE
A valid AIDC media type is required.
Definition gs1syntaxdictionary.h:182