5252#define DEF_SIZE 32
5353/** Size of error buffer */
5454#define ERR_SIZE 256
55+ /** Special type of UniRec string field that is trimmed before conversion from IPFIX */
56+ #define TYPE_STRING_TRIM "string_trimmed"
5557
5658/** Internal structure of the mapping database */
5759struct map_s {
@@ -234,13 +236,14 @@ map_elem_get_internal(const char *elem)
234236 * \param[in] ur_name UniRec name
235237 * \param[in] ur_type UniRec type
236238 * \param[in] ur_type_str UniRec type string
239+ * \param[in] cflags Additional conversion flags
237240 * \param[in] ie_defs Definition of IPFIX IEs (comma separated list of definitions)
238241 * \param[in] line_id Line ID (just for error messages)
239242 * \return #IPX_OK on success
240243 * \return #IPX_ERR_NOMEM or #IPX_ERR_FORMAT on failure
241244 */
242245static int
243- map_load_line_ie_defs (map_t * map , char * ur_name , int ur_type , char * ur_type_str ,
246+ map_load_line_ie_defs (map_t * map , char * ur_name , int ur_type , char * ur_type_str , uint32_t cflags ,
244247 const char * ie_defs , size_t line_id )
245248{
246249 char * defs_cpy = strdup (ie_defs );
@@ -264,6 +267,7 @@ map_load_line_ie_defs(map_t *map, char *ur_name, int ur_type, char *ur_type_str,
264267 rec .unirec .name = ur_name ;
265268 rec .unirec .type = ur_type ;
266269 rec .unirec .type_str = ur_type_str ;
270+ rec .unirec .flags = cflags ;
267271
268272 // Process IPFIX fields
269273 char * subsave_ptr = NULL ;
@@ -323,6 +327,7 @@ map_load_line(map_t *map, const char *line, size_t line_id)
323327 int rc = IPX_OK ;
324328 char * ur_name = NULL ;
325329 char * ur_type_str = NULL ;
330+ uint32_t conv_flags = 0 ;
326331 ur_field_type_t ur_type ;
327332
328333 char * line_cpy = strdup (line );
@@ -356,7 +361,15 @@ map_load_line(map_t *map, const char *line, size_t line_id)
356361 goto end ;
357362 }
358363
359- int type = ur_get_field_type_from_str (token );
364+ int type ;
365+ if (strcmp (token , TYPE_STRING_TRIM ) == 0 ) {
366+ // Special version of string
367+ type = UR_TYPE_STRING ;
368+ conv_flags |= MAP_FLAGS_STR_TRIM ;
369+ } else {
370+ type = ur_get_field_type_from_str (token );
371+ }
372+
360373 if (type == UR_E_INVALID_TYPE ) {
361374 snprintf (map -> err_buffer , ERR_SIZE , "Line %zu: Invalid type '%s' of UniRec field '%s'" ,
362375 line_id , token , ur_name );
@@ -382,7 +395,7 @@ map_load_line(map_t *map, const char *line, size_t line_id)
382395
383396 ptrdiff_t offset = token - line_cpy ;
384397 const char * ie_defs = line + offset ;
385- rc = map_load_line_ie_defs (map , ur_name , ur_type , ur_type_str , ie_defs , line_id );
398+ rc = map_load_line_ie_defs (map , ur_name , ur_type , ur_type_str , conv_flags , ie_defs , line_id );
386399
387400end :
388401 free (ur_type_str );
0 commit comments