]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
start of skeleton for parsing value boxes for fields
authorAlan T. DeKok <aland@freeradius.org>
Tue, 2 Jun 2020 15:26:27 +0000 (11:26 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 2 Jun 2020 15:26:27 +0000 (11:26 -0400)
src/modules/rlm_csv/rlm_csv.c

index d8faa96a3488f5f599a02a2d39a9649f892356bb..2bece823858bf31d124c4e70df8b8dddcd30f81d 100644 (file)
@@ -58,6 +58,7 @@ typedef struct {
 
        char const      **field_names;
        int             *field_offsets; /* field X from the file maps to array entry Y here */
+       fr_type_t       *field_types;
        rbtree_t        *tree;
        fr_trie_t       *trie;
 
@@ -212,6 +213,23 @@ static rlm_csv_entry_t *file2csv(CONF_SECTION *conf, rlm_csv_t *inst, int lineno
                 */
                if (inst->field_offsets[i] < 0) continue;
 
+               /*
+                *      Try to parse fields as data types if the data type is defined.
+                */
+               if (inst->field_types[i] != FR_TYPE_INVALID) {
+                       fr_value_box_t box;
+                       fr_type_t type = inst->field_types[i];
+
+                       if (fr_value_box_from_str(e, &box, &type, NULL, p, -1, 0, false) < 0) {
+                               cf_log_err(conf, "Failed parsing field '%s' in file %s line %d - %s", inst->field_names[i],
+                                          inst->filename, lineno, fr_strerror());
+                               talloc_free(e);
+                               return NULL;
+                       }
+
+                       fr_value_box_clear(&box);
+               }
+
                MEM(e->data[inst->field_offsets[i]] = talloc_typed_strdup(e, p));
        }
 
@@ -469,9 +487,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
 
        MEM(inst->field_names = talloc_zero_array(inst, const char *, inst->num_fields));
        MEM(inst->field_offsets = talloc_array(inst, int, inst->num_fields));
+       MEM(inst->field_types = talloc_array(inst, fr_type_t, inst->num_fields));
 
        for (i = 0; i < inst->num_fields; i++) {
                inst->field_offsets[i] = -1; /* unused */
+               inst->field_types[i] = FR_TYPE_INVALID;
        }
 
        /*
@@ -562,6 +582,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
                return -1;
        }
 
+       /*
+        *      Set the data type of the index field.
+        */
+       inst->field_types[inst->index_field] = inst->data_type;
+
        /*
         *      Read the rest of the file.
         */