Lines Matching refs:fields

9 #include "auth-fields.h"
13 ARRAY_TYPE(auth_field) fields, snapshot_fields;
20 struct auth_fields *fields;
22 fields = p_new(pool, struct auth_fields, 1);
23 fields->pool = pool;
24 return fields;
27 static void auth_fields_snapshot_preserve(struct auth_fields *fields)
29 if (!fields->snapshotted || array_is_created(&fields->snapshot_fields))
32 p_array_init(&fields->snapshot_fields, fields->pool,
33 array_count(&fields->fields));
34 array_append_array(&fields->snapshot_fields, &fields->fields);
38 auth_fields_find_idx(struct auth_fields *fields, const char *key,
44 if (!array_is_created(&fields->fields))
47 f = array_get(&fields->fields, &count);
57 void auth_fields_add(struct auth_fields *fields,
68 if (!auth_fields_find_idx(fields, key, &idx)) {
69 if (!array_is_created(&fields->fields))
70 p_array_init(&fields->fields, fields->pool, 16);
72 field = array_append_space(&fields->fields);
73 field->key = p_strdup(fields->pool, key);
75 auth_fields_snapshot_preserve(fields);
76 field = array_idx_modifiable(&fields->fields, idx);
78 field->value = p_strdup_empty(fields->pool, value);
82 void auth_fields_remove(struct auth_fields *fields, const char *key)
86 if (auth_fields_find_idx(fields, key, &idx)) {
87 auth_fields_snapshot_preserve(fields);
88 array_delete(&fields->fields, idx, 1);
92 const char *auth_fields_find(struct auth_fields *fields, const char *key)
97 if (!auth_fields_find_idx(fields, key, &idx))
100 field = array_idx(&fields->fields, idx);
104 bool auth_fields_exists(struct auth_fields *fields, const char *key)
106 return auth_fields_find(fields, key) != NULL;
109 void auth_fields_reset(struct auth_fields *fields)
111 if (array_is_created(&fields->fields)) {
112 auth_fields_snapshot_preserve(fields);
113 array_clear(&fields->fields);
117 void auth_fields_import_prefixed(struct auth_fields *fields, const char *prefix,
134 auth_fields_add(fields, key, value, flags);
139 void auth_fields_import(struct auth_fields *fields, const char *str,
142 auth_fields_import_prefixed(fields, "", str, flags);
145 const ARRAY_TYPE(auth_field) *auth_fields_export(struct auth_fields *fields)
147 if (!array_is_created(&fields->fields))
148 p_array_init(&fields->fields, fields->pool, 1);
149 return &fields->fields;
152 void auth_fields_append(struct auth_fields *fields, string_t *dest,
160 if (!array_is_created(&fields->fields))
163 f = array_get(&fields->fields, &count);
180 bool auth_fields_is_empty(struct auth_fields *fields)
182 return fields == NULL || !array_is_created(&fields->fields) ||
183 array_count(&fields->fields) == 0;
186 void auth_fields_booleanize(struct auth_fields *fields, const char *key)
191 if (auth_fields_find_idx(fields, key, &idx)) {
192 field = array_idx_modifiable(&fields->fields, idx);
197 void auth_fields_snapshot(struct auth_fields *fields)
201 fields->snapshotted = TRUE;
202 if (!array_is_created(&fields->fields))
205 if (!array_is_created(&fields->snapshot_fields)) {
207 fields->snapshot_idx = array_count(&fields->fields);
209 array_clear(&fields->snapshot_fields);
210 array_append_array(&fields->snapshot_fields, &fields->fields);
212 array_foreach_modifiable(&fields->fields, field)
216 void auth_fields_rollback(struct auth_fields *fields)
218 if (array_is_created(&fields->snapshot_fields)) {
219 array_clear(&fields->fields);
220 array_append_array(&fields->fields, &fields->snapshot_fields);
221 } else if (array_is_created(&fields->fields)) {
222 array_delete(&fields->fields, fields->snapshot_idx,
223 array_count(&fields->fields) -
224 fields->snapshot_idx);