diff --git a/src/fieldset.c b/src/fieldset.c index 34c9fdf..eb5d27e 100644 --- a/src/fieldset.c +++ b/src/fieldset.c @@ -50,6 +50,26 @@ static inline void fs_add_word(fieldset_t *fs, const char *name, int type, f->free_ = free_; } +static void fs_modify_word(fieldset_t *fs, const char *name, int type, + int free_, size_t len, void *value) +{ + int i; + for (i=0; ilen; i++) { + if (!strcmp(fs->fields[i].name, name)) { + if (fs->fields[i].free_) { + free((void*)fs->fields[i].value); + fs->fields[i].value = 0; + } + fs->fields[i].type = type; + fs->fields[i].free_ = free_; + fs->fields[i].len = len; + fs->fields[i].value = (uint64_t)value; + return; + } + } + fs_add_word(fs, name, type, free_, len, value); +} + void fs_add_null(fieldset_t *fs, const char *name) { fs_add_word(fs, name, FS_NULL, 0, 0, NULL); @@ -71,6 +91,28 @@ void fs_add_binary(fieldset_t *fs, const char *name, size_t len, fs_add_word(fs, name, FS_BINARY, free_, len, value); } +// Modify +void fs_modify_null(fieldset_t *fs, const char *name) +{ + fs_modify_word(fs, name, FS_NULL, 0, 0, NULL); +} + +void fs_modify_string(fieldset_t *fs, const char *name, char *value, int free_) +{ + fs_modify_word(fs, name, FS_STRING, free_, strlen(value), (void*) value); +} + +void fs_modify_uint64(fieldset_t *fs, const char *name, uint64_t value) +{ + fs_modify_word(fs, name, FS_UINT64, 0, sizeof(uint64_t), (void*) value); +} + +void fs_modify_binary(fieldset_t *fs, const char *name, size_t len, + void *value, int free_) +{ + fs_modify_word(fs, name, FS_BINARY, free_, len, value); +} + uint64_t fs_get_uint64_by_index(fieldset_t *fs, int index) { return (uint64_t) fs->fields[index].value; diff --git a/src/fieldset.h b/src/fieldset.h index 9d49ba3..66de892 100644 --- a/src/fieldset.h +++ b/src/fieldset.h @@ -74,6 +74,8 @@ int fds_get_index_by_name(fielddefset_t *fds, char *name); void gen_fielddef_set(fielddefset_t *fds, fielddef_t fs[], int len); +void fs_add_null(fieldset_t *fs, const char *name); + void fs_add_uint64(fieldset_t *fs, const char *name, uint64_t value); void fs_add_string(fieldset_t *fs, const char *name, char *value, int free_); @@ -81,9 +83,17 @@ void fs_add_string(fieldset_t *fs, const char *name, char *value, int free_); void fs_add_binary(fieldset_t *fs, const char *name, size_t len, void *value, int free_); -uint64_t fs_get_uint64_by_index(fieldset_t *fs, int index); +// Modify +void fs_modify_null(fieldset_t *fs, const char *name); -void fs_add_null(fieldset_t *fs, const char *name); +void fs_modify_uint64(fieldset_t *fs, const char *name, uint64_t value); + +void fs_modify_string(fieldset_t *fs, const char *name, char *value, int free_); + +void fs_modify_binary(fieldset_t *fs, const char *name, size_t len, + void *value, int free_); + +uint64_t fs_get_uint64_by_index(fieldset_t *fs, int index); void fs_free(fieldset_t *fs);