GS1 Syntax Dictionary: Linter reference
A reference to the AI component linter routines referred to by the GS1 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
The default lookup function provided by this linter is a binary search over a static list this is maintained in this file.
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.
78{
79
80 /*
81 * Allow for a custom replacement of the lookup code to be provided.
82 *
83 */
84#ifdef GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP
85#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP(cc)
86#else
87
88 /*
89 * Set of valid AIDC media type values
90 *
91 * MAINTENANCE NOTE:
92 *
93 * Updates to the AIDC media type list shall be announced by GSCN
94 *
95 */
96 static const char mediatypes[][3] = {
97 /* 00 Not used */
98 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", /* ICCBBA assignments */
99 /* 11-29 Reserved for future assignment by ICCBBA */
100 /* 30-59 Reserved for future assignment by GS1 */
101 /* 60-79 Reserved for future assignment by ICCBBA or GS1 */
102 "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", /* ICCBBA local / national use */
103 "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", /* ICCBBA local / national use */
104 };
105
106 /*
107 * Binary search over the above list.
108 *
109 */
110/// \cond
111#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) do { \
112 size_t s = 0; \
113 size_t e = sizeof(mediatypes) / sizeof(mediatypes[0]); \
114 while (s < e) { \
115 const size_t m = s + (e - s) / 2; \
116 const int cmp = strcmp(mediatypes[m], cc); \
117 if (cmp < 0) \
118 s = m + 1; \
119 else if (cmp > 0) \
120 e = m; \
121 else { \
122 valid = 1; \
123 break; \
124 } \
125 } \
126} while (0)
127/// \endcond
128
129#endif
130
131 int valid = 0;
132
133 assert(data);
134
135 /*
136 * Ensure that the data is in the list.
137 *
138 */
139 GS1_LINTER_MEDIA_TYPE_LOOKUP(data);
140 if (valid)
141 return GS1_LINTER_OK;
142
143 /*
144 * If not valid then indicate an error.
145 *
146 */
147 if (err_pos) *err_pos = 0;
148 if (err_len) *err_len = strlen(data);
150
151}
@ GS1_LINTER_INVALID_MEDIA_TYPE
A valid AIDC media type is required.
Definition gs1syntaxdictionary.h:170
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition gs1syntaxdictionary.h:66