return 0;
}
-size_t
-deltas_head_get_size(struct deltas_head *deltas)
-{
- return deltas->capacity;
-}
-
/*
- * A new delta_head will be allocated at the @position inside @deltas (also its
- * URI and HASH will be allocated).
+ * A new delta_head will be allocated at its corresponding position inside
+ * @deltas (also its URI and HASH will be allocated). The position is calculated
+ * using the difference between @max_serial and @serial.
*
* The following errors can be returned due to a wrong @position:
* -EEXIST: There's already an element at @position.
* Don't forget to call deltas_head_set_size() before this!!
*/
int
-deltas_head_add(struct deltas_head *deltas, size_t position,
+deltas_head_add(struct deltas_head *deltas, unsigned long max_serial,
unsigned long serial, char *uri, unsigned char *hash, size_t hash_len)
{
struct delta_head *elem;
+ size_t position;
int error;
+ position = deltas->capacity - 1 - (max_serial - serial);
if (position < 0 || position > deltas->capacity - 1)
return -EINVAL;
return deltas->len == deltas->capacity;
}
+/* Do the @cb to the delta head elements from @from_serial to @max_serial */
int
-deltas_head_for_each(struct deltas_head *deltas, size_t from, delta_head_cb cb,
- void *arg)
+deltas_head_for_each(struct deltas_head *deltas, unsigned long max_serial,
+ unsigned long from_serial, delta_head_cb cb, void *arg)
{
size_t index;
+ size_t from;
int error;
/* No elements, send error so that the snapshot is processed */
return -ENOENT;
}
+ from = deltas->capacity - (max_serial - from_serial);
for (index = from; index < deltas->capacity; index++) {
error = cb(deltas->array[index], arg);
if (error)
void update_notification_destroy(struct update_notification *);
typedef int (*delta_head_cb)(struct delta_head *, void *);
-int deltas_head_for_each(struct deltas_head *, size_t, delta_head_cb, void *);
-int deltas_head_add(struct deltas_head *, size_t, unsigned long, char *,
+int deltas_head_for_each(struct deltas_head *, unsigned long, unsigned long,
+ delta_head_cb, void *);
+int deltas_head_add(struct deltas_head *, unsigned long, unsigned long, char *,
unsigned char *, size_t);
int deltas_head_set_size(struct deltas_head *, size_t);
-size_t deltas_head_get_size(struct deltas_head *);
bool deltas_head_values_set(struct deltas_head *);
int snapshot_create(struct snapshot **);
static int
parse_notification_deltas(xmlNode *root, unsigned long max_serial,
- unsigned long deltas_len, struct deltas_head *deltas)
+ struct deltas_head *deltas)
{
struct doc_data doc_data;
unsigned long serial;
- size_t position;
int error;
error = parse_long(root, RRDP_ATTR_SERIAL, &serial);
* The delta will be added to the position it belongs, assuring that
* the deltas list will be ordered.
*/
- position = deltas_len - 1 - (max_serial - serial);
- error = deltas_head_add(deltas, position, serial, doc_data.uri,
+ error = deltas_head_add(deltas, max_serial, serial, doc_data.uri,
doc_data.hash, doc_data.hash_len);
/* Always release data */
xmlNode *cur_node;
rrdp_uri_cmp_result_t res;
unsigned long from_serial, max_serial;
- unsigned long deltas_len;
bool create_snapshot;
int error;
max_serial = file->global_data.serial;
/* By schema, at least one snapshot element will be present */
- deltas_len = xmlChildElementCount(root) - 1;
-
- error = deltas_head_set_size(file->deltas_list, deltas_len);
+ error = deltas_head_set_size(file->deltas_list,
+ xmlChildElementCount(root) - 1);
if (error)
return error;
for (cur_node = root->children; cur_node; cur_node = cur_node->next) {
if (xmlStrEqual(cur_node->name, BAD_CAST RRDP_ELEM_DELTA)) {
error = parse_notification_deltas(cur_node, max_serial,
- deltas_len, file->deltas_list);
+ file->deltas_list);
} else if (xmlStrEqual(cur_node->name,
BAD_CAST RRDP_ELEM_SNAPSHOT)) {
error = parse_doc_data(cur_node, true, true,
rrdp_process_deltas(struct update_notification *parent,
unsigned long cur_serial)
{
- size_t deltas_len;
- size_t from;
-
- deltas_len = deltas_head_get_size(parent->deltas_list);
- from = deltas_len - (parent->global_data.serial - cur_serial);
-
- return deltas_head_for_each(parent->deltas_list, from, process_delta,
- parent);
+ return deltas_head_for_each(parent->deltas_list,
+ parent->global_data.serial, cur_serial, process_delta, parent);
}