"zstd"
};
-int zck_comp_init(zckCtx *zck) {
+int comp_init(zckCtx *zck) {
VALIDATE(zck);
zckComp *comp = &(zck->comp);
free(dst);
return False;
}
- if(!zck_index_add_to_chunk(zck, dst, dst_size,
+ if(!index_add_to_chunk(zck, dst, dst_size,
zck->comp.dict_size)) {
free(dst);
return False;
free(dst);
return False;
}
- if(!zck_index_add_to_chunk(zck, dst, dst_size, 0) ||
- !zck_index_finish_chunk(zck)) {
+ if(!index_add_to_chunk(zck, dst, dst_size, 0) ||
+ !index_finish_chunk(zck)) {
free(dst);
return False;
}
free(dst);
} else {
- if(!zck_index_finish_chunk(zck))
+ if(!index_finish_chunk(zck))
return False;
}
}
return True;
}
-int zck_comp_reset(zckCtx *zck) {
+int comp_reset(zckCtx *zck) {
VALIDATE(zck);
zck->comp.started = 0;
return zck->comp.close(&(zck->comp));
}
-int zck_comp_close(zckCtx *zck) {
+int comp_close(zckCtx *zck) {
VALIDATE(zck);
zck_log(ZCK_LOG_DEBUG, "Closing compression\n");
if(zck->comp.data) {
zck->comp.data_loc = 0;
zck->comp.data_idx = NULL;
}
- return zck_comp_reset(zck);
+ return comp_reset(zck);
}
static int set_comp_type(zckCtx *zck, ssize_t type) {
zck_log(ZCK_LOG_DEBUG, "Setting compression to %s\n",
zck_comp_name_from_type(type));
if(type == ZCK_COMP_NONE) {
- return zck_nocomp_setup(comp);
+ return nocomp_setup(comp);
#ifdef ZCHUNK_ZSTD
} else if(type == ZCK_COMP_ZSTD) {
- return zck_zstd_setup(comp);
+ return zstd_setup(comp);
#endif
} else {
zck_log(ZCK_LOG_ERROR, "Unsupported compression type: %s\n",
return COMP_NAME[comp_type];
}
-size_t zck_comp_read_from_dc(zckComp *comp, char *dst, size_t dst_size) {
+size_t comp_read_from_dc(zckComp *comp, char *dst, size_t dst_size) {
VALIDATE_SIZE(comp);
VALIDATE_SIZE(dst);
return dl_size;
}
-int zck_comp_add_to_dc(zckComp *comp, const char *src, size_t src_size) {
+int comp_add_to_dc(zckComp *comp, const char *src, size_t src_size) {
VALIDATE(comp);
VALIDATE(src);
return True;
}
-int zck_comp_add_to_data(zckComp *comp, const char *src, size_t src_size) {
+int comp_add_to_data(zckComp *comp, const char *src, size_t src_size) {
VALIDATE(comp);
VALIDATE(src);
comp->data = realloc(comp->data, comp->data_size + src_size);
ssize_t PUBLIC zck_write(zckCtx *zck, const char *src, const size_t src_size) {
VALIDATE_WRITE_SIZE(zck);
- if(!zck->comp.started && !zck_comp_init(zck))
+ if(!zck->comp.started && !comp_init(zck))
return -1;
if(src_size == 0)
free(dst);
return -1;
}
- if(!zck_index_add_to_chunk(zck, dst, dst_size, src_size)) {
+ if(!index_add_to_chunk(zck, dst, dst_size, src_size)) {
free(dst);
return -1;
}
ssize_t PUBLIC zck_end_chunk(zckCtx *zck) {
VALIDATE_WRITE_SIZE(zck);
- if(!zck->comp.started && !zck_comp_init(zck))
+ if(!zck->comp.started && !comp_init(zck))
return -1;
/* No point in compressing empty data */
free(dst);
return -1;
}
- if(!zck_index_add_to_chunk(zck, dst, dst_size, 0)) {
+ if(!index_add_to_chunk(zck, dst, dst_size, 0)) {
free(dst);
return -1;
}
- if(!zck_index_finish_chunk(zck)) {
+ if(!index_finish_chunk(zck)) {
free(dst);
return -1;
}
ssize_t comp_end_dchunk(zckCtx *zck, int use_dict, size_t fd_size) {
ssize_t rb = zck->comp.end_dchunk(&(zck->comp), use_dict, fd_size);
- if(zck_validate_current_chunk(zck) < 1)
+ if(validate_current_chunk(zck) < 1)
return -1;
zck->comp.data_loc = 0;
zck->comp.data_idx = zck->comp.data_idx->next;
- if(!zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
+ if(!hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
return -1;
return rb;
}
/* Read dictionary if it exists and hasn't been read yet */
if(use_dict && !zck->comp.data_eof && zck->comp.data_idx == NULL &&
- zck->index.first->length > 0 && !zck_import_dict(zck))
+ zck->index.first->length > 0 && !import_dict(zck))
return -1;
size_t dc = 0;
zck_log(ZCK_LOG_DEBUG, "Trying to read %lu bytes\n", dst_size);
while(dc < dst_size) {
/* Get bytes from decompressed buffer */
- ssize_t rb = zck_comp_read_from_dc(&(zck->comp), dst+dc, dst_size-dc);
+ ssize_t rb = comp_read_from_dc(&(zck->comp), dst+dc, dst_size-dc);
if(rb < 0)
- goto zck_read_error;
+ goto read_error;
dc += rb;
if(dc == dst_size)
break;
size_t dc_data_size = zck->comp.dc_data_size;
size_t dc_data_loc = zck->comp.dc_data_loc;
if(!zck->comp.decompress(&(zck->comp), use_dict))
- goto zck_read_error;
+ goto read_error;
/* Check whether we decompressed more data */
if(zck->comp.dc_data_size != dc_data_size ||
/* Skip first chunk if it's an empty dict */
if(zck->comp.data_idx->comp_length == 0)
zck->comp.data_idx = zck->comp.data_idx->next;
- if(!zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
- goto zck_hash_error;
+ if(!hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
+ goto hash_error;
if(zck->comp.data_loc > 0) {
- if(!zck_hash_update(&(zck->check_full_hash), zck->comp.data,
+ if(!hash_update(&(zck->check_full_hash), zck->comp.data,
zck->comp.data_loc))
- goto zck_hash_error;
- if(!zck_hash_update(&(zck->check_chunk_hash), zck->comp.data,
+ goto hash_error;
+ if(!hash_update(&(zck->check_chunk_hash), zck->comp.data,
zck->comp.data_loc))
- goto zck_hash_error;
+ goto hash_error;
}
if(zck->comp.data_idx == NULL) {
free(src);
* compressed buffer */
rb = read_data(zck->fd, src, rs);
if(rb < 0)
- goto zck_read_error;
+ goto read_error;
if(rb < rs) {
zck_log(ZCK_LOG_DEBUG, "EOF\n");
finished_rd = True;
}
- if(!zck_hash_update(&(zck->check_full_hash), src, rb) ||
- !zck_hash_update(&(zck->check_chunk_hash), src, rb) ||
- !zck_comp_add_to_data(&(zck->comp), src, rb))
- goto zck_read_error;
+ if(!hash_update(&(zck->check_full_hash), src, rb) ||
+ !hash_update(&(zck->check_chunk_hash), src, rb) ||
+ !comp_add_to_data(&(zck->comp), src, rb))
+ goto read_error;
}
free(src);
return dc;
-zck_read_error:
+read_error:
free(src);
return -1;
-zck_hash_error:
+hash_error:
free(src);
return -2;
}
char src_size = comp->data_size;
comp->data = NULL;
comp->data_size = 0;
- if(!zck_comp_add_to_dc(comp, src, src_size)) {
+ if(!comp_add_to_dc(comp, src, src_size)) {
free(src);
return False;
}
return True;
}
-int zck_nocomp_setup(zckComp *comp) {
+int nocomp_setup(zckComp *comp) {
comp->init = init;
comp->set_parameter = set_parameter;
comp->compress = compress;
#ifndef ZCHUNK_COMPRESSION_NOCOMP_H
#define ZCHUNK_COMPRESSION_NOCOMP_H
-int zck_nocomp_setup(zckComp *comp);
+int nocomp_setup(zckComp *comp);
#endif
ZSTD_getErrorName(retval));
goto decomp_error_2;
}
- if(!zck_comp_add_to_dc(comp, dst, fd_size))
+ if(!comp_add_to_dc(comp, dst, fd_size))
goto decomp_error_2;
free(dst);
free(src);
return set_parameter(comp, ZCK_ZSTD_COMP_LEVEL, &level);
}
-int zck_zstd_setup(zckComp *comp) {
+int zstd_setup(zckComp *comp) {
comp->init = init;
comp->set_parameter = set_parameter;
comp->compress = compress;
#ifndef ZCHUNK_COMPRESSION_ZSTD_H
#define ZCHUNK_COMPRESSION_ZSTD_H
-int zck_zstd_setup(zckComp *comp);
+int zstd_setup(zckComp *comp);
#endif
return False; \
}
-/* Free zckDL regex's used for downloading ranges */
-static void free_dl_regex(zckDL *dl) {
+/* Free zckDL header regex used for downloading ranges */
+void clear_dl_regex(zckDL *dl) {
if(dl == NULL || dl->priv == NULL)
return;
return True;
}
-static int dl_write(zckDL *dl, const char *at, size_t length) {
- VALIDATE(dl);
- VALIDATE(dl->priv);
- int wb = 0;
- if(dl->priv->write_in_chunk > 0) {
- if(dl->priv->write_in_chunk < length)
- wb = dl->priv->write_in_chunk;
- else
- wb = length;
- if(!write_data(dl->zck->fd, at, wb))
- return -1;
- dl->priv->write_in_chunk -= wb;
- if(!zck_hash_update(dl->priv->chunk_hash, at, wb))
- return -1;
- zck_log(ZCK_LOG_DEBUG, "Writing %lu bytes\n", wb);
- dl->priv->dl_chunk_data += wb;
- }
- return wb;
-}
-
+/* Check whether last downloaded chunk is valid and zero it out if it isn't */
static int validate_chunk(zckDL *dl) {
VALIDATE(dl);
VALIDATE(dl->priv);
zck_log(ZCK_LOG_ERROR, "Chunk hash not initialized\n");
return False;
}
- char *digest = zck_hash_finalize(dl->priv->chunk_hash);
+ char *digest = hash_finalize(dl->priv->chunk_hash);
free(dl->priv->chunk_hash);
if(memcmp(digest, dl->priv->tgt_check->digest,
dl->priv->tgt_check->digest_size) != 0) {
return True;
}
-int zck_dl_write_range(zckDL *dl, const char *at, size_t length) {
+/* Write length or to end of current chunk, whichever comes first */
+static int dl_write(zckDL *dl, const char *at, size_t length) {
+ VALIDATE(dl);
+ VALIDATE(dl->priv);
+ int wb = 0;
+ if(dl->priv->write_in_chunk > 0) {
+ if(dl->priv->write_in_chunk < length)
+ wb = dl->priv->write_in_chunk;
+ else
+ wb = length;
+ if(!write_data(dl->zck->fd, at, wb))
+ return -1;
+ dl->priv->write_in_chunk -= wb;
+ if(!hash_update(dl->priv->chunk_hash, at, wb))
+ return -1;
+ zck_log(ZCK_LOG_DEBUG, "Writing %lu bytes\n", wb);
+ dl->priv->dl_chunk_data += wb;
+ }
+ return wb;
+}
+
+/* Split current read into the appropriate chunks and write appropriately */
+int dl_write_range(zckDL *dl, const char *at, size_t length) {
VALIDATE(dl);
VALIDATE(dl->priv);
if(dl->range == NULL) {
idx->digest_size) == 0) {
dl->priv->tgt_check = tgt_idx;
dl->priv->chunk_hash = zmalloc(sizeof(zckHash));
- if(!zck_hash_init(dl->priv->chunk_hash,
+ if(!hash_init(dl->priv->chunk_hash,
&(dl->zck->chunk_hash_type)))
return 0;
dl->priv->write_in_chunk = idx->comp_length;
}
}
int wb2 = 0;
+ /* We've still got data, call recursively */
if(dl->priv->write_in_chunk > 0 && wb < length) {
- wb2 = zck_dl_write_range(dl, at+wb, length-wb);
+ wb2 = dl_write_range(dl, at+wb, length-wb);
if(wb2 == 0)
return 0;
}
return wb + wb2;
}
-size_t PUBLIC zck_write_zck_header_cb(void *ptr, size_t l, size_t c, void *dl_v) {
- if(dl_v == NULL)
- return 0;
- zckDL *dl = (zckDL*)dl_v;
- size_t wb = 0;
- dl->dl += l*c;
- size_t loc = tell_data(dl->zck->fd);
- zck_log(ZCK_LOG_DEBUG, "Downloading %lu bytes to position %lu\n", l*c, loc);
- wb = write(dl->zck->fd, ptr, l*c);
- if(dl->write_cb)
- return dl->write_cb(ptr, l, c, dl->wdata);
- return wb;
-}
-
-size_t PUBLIC zck_write_chunk_cb(void *ptr, size_t l, size_t c, void *dl_v) {
- if(dl_v == NULL)
- return 0;
- zckDL *dl = (zckDL*)dl_v;
- size_t wb = 0;
- dl->dl += l*c;
- if(dl->priv->boundary != NULL) {
- int retval = zck_multipart_extract(dl, ptr, l*c);
- if(retval == 0)
- wb = 0;
- else
- wb = l*c;
- } else {
- int retval = zck_dl_write_range(dl, ptr, l*c);
- if(retval == 0)
- wb = 0;
- else
- wb = l*c;
- }
- if(dl->write_cb)
- return dl->write_cb(ptr, l, c, dl->wdata);
- return wb;
-}
-
+/* Copy chunk identified by src_idx into location specified by tgt_idx */
int write_and_verify_chunk(zckCtx *src, zckCtx *tgt, zckIndexItem *src_idx,
zckIndexItem *tgt_idx) {
static char buf[BUF_SIZE] = {0};
if(!seek_data(tgt->fd, tgt->data_offset + tgt_idx->start, SEEK_SET))
return False;
zckHash check_hash = {0};
- if(!zck_hash_init(&check_hash, &(src->chunk_hash_type)))
+ if(!hash_init(&check_hash, &(src->chunk_hash_type)))
return False;
while(to_read > 0) {
int rb = BUF_SIZE;
rb = to_read;
if(!read_data(src->fd, buf, rb))
return False;
- if(!zck_hash_update(&check_hash, buf, rb))
+ if(!hash_update(&check_hash, buf, rb))
return False;
if(!write_data(tgt->fd, buf, rb))
return False;
to_read -= rb;
}
- char *digest = zck_hash_finalize(&check_hash);
+ char *digest = hash_finalize(&check_hash);
/* If chunk is invalid, overwrite with zeros and add to download range */
if(memcmp(digest, src_idx->digest, src_idx->digest_size) != 0) {
char *pdigest = zck_get_chunk_digest(src_idx);
return True;
}
-size_t PUBLIC zck_header_cb(char *b, size_t l, size_t c, void *dl_v) {
- if(dl_v == NULL)
- return 0;
- zckDL *dl = (zckDL*)dl_v;
-
- if(zck_multipart_get_boundary(dl, b, c*l) == 0)
- zck_log(ZCK_LOG_DEBUG, "No boundary detected");
-
- if(dl->header_cb)
- return dl->header_cb(b, l, c, dl->hdrdata);
- return c*l;
-}
-
-
-int zck_zero_bytes(zckDL *dl, size_t bytes, size_t start, size_t *buffer_len) {
- char buf[BUF_SIZE] = {0};
- if(start + bytes > *buffer_len) {
- zck_log(ZCK_LOG_DEBUG, "Seeking to end of temporary file\n");
- if(lseek(dl->zck->fd, 0, SEEK_END) == -1) {
- zck_log(ZCK_LOG_ERROR, "Seek to end of temporary file failed: %s\n",
- strerror(errno));
- return False;
- }
- size_t write = *buffer_len;
- while(write < start + bytes) {
- size_t wb = BUF_SIZE;
- if(write + wb > start + bytes)
- wb = (start + bytes) - write;
- if(!write_data(dl->zck->fd, buf, wb))
- return False;
- write += wb;
- }
- zck_log(ZCK_LOG_DEBUG, "Wrote %lu zeros at position %lu\n", start+bytes-*buffer_len, *buffer_len);
- *buffer_len = start+bytes;
- zck_log(ZCK_LOG_DEBUG, "Seeking to position %lu\n", start);
- if(lseek(dl->zck->fd, start, SEEK_SET) == -1) {
- zck_log(ZCK_LOG_ERROR,
- "Seek to byte %lu of temporary file failed: %s\n", start,
- strerror(errno));
- return False;
- }
- }
- return True;
-}
-
-
size_t PUBLIC zck_dl_get_bytes_downloaded(zckDL *dl) {
VALIDATE(dl);
return dl->dl;
return dl->ul;
}
-/* Free zckDL header regex used for downloading ranges */
-void zck_dl_clear_regex(zckDL *dl) {
- if(dl == NULL || dl->priv == NULL)
- return;
-
- free_dl_regex(dl);
- if(dl->priv->hdr_regex) {
- regfree(dl->priv->hdr_regex);
- free(dl->priv->hdr_regex);
- dl->priv->hdr_regex = NULL;
- }
-}
-
/* Initialize zckDL. When finished, zckDL *must* be freed by zck_dl_free() */
zckDL PUBLIC *zck_dl_init(zckCtx *zck) {
zckDL *dl = zmalloc(sizeof(zckDL));
return dl;
}
-/* Free zckDL and set pointer to NULL */
+/* Reset dl while maintaining download statistics and private information */
void PUBLIC zck_dl_reset(zckDL *dl) {
if(!dl)
return;
memset(dl->priv->mp, 0, sizeof(zckMP));
}
dl->priv->dl_chunk_data = 0;
- zck_dl_clear_regex(dl);
+ clear_dl_regex(dl);
if(dl->priv->boundary)
free(dl->priv->boundary);
dl->priv->boundary = NULL;
free(*dl);
*dl = NULL;
}
+
+/*******************************************************************
+ * Callbacks
+ *******************************************************************/
+
+size_t PUBLIC zck_header_cb(char *b, size_t l, size_t c, void *dl_v) {
+ if(dl_v == NULL)
+ return 0;
+ zckDL *dl = (zckDL*)dl_v;
+
+ if(multipart_get_boundary(dl, b, c*l) == 0)
+ zck_log(ZCK_LOG_DEBUG, "No boundary detected");
+
+ if(dl->header_cb)
+ return dl->header_cb(b, l, c, dl->hdrdata);
+ return c*l;
+}
+
+size_t PUBLIC zck_write_zck_header_cb(void *ptr, size_t l, size_t c, void *dl_v) {
+ if(dl_v == NULL)
+ return 0;
+ zckDL *dl = (zckDL*)dl_v;
+ size_t wb = 0;
+ dl->dl += l*c;
+ size_t loc = tell_data(dl->zck->fd);
+ zck_log(ZCK_LOG_DEBUG, "Downloading %lu bytes to position %lu\n", l*c, loc);
+ wb = write(dl->zck->fd, ptr, l*c);
+ if(dl->write_cb)
+ return dl->write_cb(ptr, l, c, dl->wdata);
+ return wb;
+}
+
+size_t PUBLIC zck_write_chunk_cb(void *ptr, size_t l, size_t c, void *dl_v) {
+ if(dl_v == NULL)
+ return 0;
+ zckDL *dl = (zckDL*)dl_v;
+ size_t wb = 0;
+ dl->dl += l*c;
+ if(dl->priv->boundary != NULL) {
+ int retval = multipart_extract(dl, ptr, l*c);
+ if(retval == 0)
+ wb = 0;
+ else
+ wb = l*c;
+ } else {
+ int retval = dl_write_range(dl, ptr, l*c);
+ if(retval == 0)
+ wb = 0;
+ else
+ wb = l*c;
+ }
+ if(dl->write_cb)
+ return dl->write_cb(ptr, l, c, dl->wdata);
+ return wb;
+}
return True;
}
-size_t zck_multipart_extract(zckDL *dl, char *b, size_t l) {
+size_t multipart_extract(zckDL *dl, char *b, size_t l) {
VALIDATE(dl);
if(dl->priv == NULL || dl->priv->mp == NULL)
return 0;
} else {
mp->length -= size;
}
- if(zck_dl_write_range(dl, i, size) != size)
+ if(dl_write_range(dl, i, size) != size)
return 0;
i += size;
continue;
memset(mp, 0, sizeof(zckMP));
}
-size_t zck_multipart_get_boundary(zckDL *dl, char *b, size_t size) {
+size_t multipart_get_boundary(zckDL *dl, char *b, size_t size) {
VALIDATE(dl);
if(dl->priv == NULL)
return 0;
#include "zck_private.h"
-void zck_range_remove(zckRangeItem *range) {
- if(range->prev)
- range->prev->next = range->next;
- if(range->next)
- range->next->prev = range->prev;
- free(range);
-}
-
void PUBLIC zck_range_free(zckRange **info) {
zckRangeItem *next = (*info)->first;
while(next) {
next = next->next;
free(tmp);
}
- zck_index_clean(&((*info)->index));
+ index_clean(&((*info)->index));
free(*info);
*info = NULL;
}
-zckRangeItem *zck_range_insert_new(zckRangeItem *prev, zckRangeItem *next, uint64_t start,
+zckRangeItem *range_insert_new(zckRangeItem *prev, zckRangeItem *next, uint64_t start,
uint64_t end, zckRange *info,
zckIndexItem *idx, int add_index) {
zckRangeItem *new = zmalloc(sizeof(zckRangeItem));
next->prev = new;
}
if(add_index)
- if(!zck_index_new_chunk(&(info->index), idx->digest, idx->digest_size,
+ if(!index_new_chunk(&(info->index), idx->digest, idx->digest_size,
end-start+1, end-start+1, False)) {
free(new);
return NULL;
return new;
}
-void zck_range_merge_combined(zckRange *info) {
+void range_remove(zckRangeItem *range) {
+ if(range->prev)
+ range->prev->next = range->next;
+ if(range->next)
+ range->next->prev = range->prev;
+ free(range);
+}
+
+void range_merge_combined(zckRange *info) {
if(!info) {
zck_log(ZCK_LOG_ERROR, "zckRange not allocated\n");
return;
if(ptr->next && ptr->end >= ptr->next->start-1) {
if(ptr->end < ptr->next->end)
ptr->end = ptr->next->end;
- zck_range_remove(ptr->next);
+ range_remove(ptr->next);
info->count -= 1;
} else {
ptr = ptr->next;
}
}
-int zck_range_add(zckRange *info, zckIndexItem *idx, zckCtx *zck) {
+int range_add(zckRange *info, zckIndexItem *idx, zckCtx *zck) {
if(info == NULL || idx == NULL) {
zck_log(ZCK_LOG_ERROR, "zckRange or zckIndexItem not allocated\n");
return False;
continue;
} else if(start < ptr->start) {
- if(zck_range_insert_new(ptr->prev, ptr, start, end, info, idx, add_index) == NULL)
+ if(range_insert_new(ptr->prev, ptr, start, end, info, idx,
+ add_index) == NULL)
return False;
if(info->first == ptr) {
info->first = ptr->prev;
}
info->count += 1;
- zck_range_merge_combined(info);
+ range_merge_combined(info);
return True;
} else { // start == ptr->start
if(end > ptr->end)
ptr->end = end;
info->count += 1;
- zck_range_merge_combined(info);
+ range_merge_combined(info);
return True;
}
}
/* We've only reached here if we should be last item */
- zckRangeItem *new = zck_range_insert_new(prev, NULL, start, end, info, idx, add_index);
+ zckRangeItem *new = range_insert_new(prev, NULL, start, end, info, idx,
+ add_index);
if(new == NULL)
return False;
if(info->first == NULL)
info->first = new;
info->count += 1;
- zck_range_merge_combined(info);
+ range_merge_combined(info);
return True;
}
char PUBLIC *zck_get_range_char(zckRange *range) {
- int buf_size=32768;
+ int buf_size=BUF_SIZE;
char *output=malloc(buf_size);
if(!output) {
zck_log(ZCK_LOG_ERROR, "Unable to allocate %lu bytes\n", buf_size);
idx = idx->next;
continue;
}
- if(!zck_range_add(range, idx, zck)) {
+ if(!range_add(range, idx, zck)) {
zck_range_free(&range);
return NULL;
}
return range;
}
-int zck_range_get_need_dl(zckRange *info, zckCtx *zck_src, zckCtx *zck_tgt) {
- zckIndex *tgt_info = zck_get_index(zck_tgt);
- zckIndex *src_info = zck_get_index(zck_src);
- zckIndexItem *tgt_idx = tgt_info->first;
- zckIndexItem *src_idx = src_info->first;
- while(tgt_idx) {
- int found = False;
- src_idx = src_info->first;
-
- while(src_idx) {
- if(memcmp(tgt_idx->digest, src_idx->digest, tgt_idx->digest_size) == 0) {
- found = True;
- break;
- }
- src_idx = src_idx->next;
- }
- if(!found)
- if(!zck_range_add(info, tgt_idx, zck_tgt))
- return False;
-
- tgt_idx = tgt_idx->next;
- }
- return True;
-}
-
char PUBLIC *zck_get_range(size_t start, size_t end) {
zckRange range = {0};
zckRangeItem ri = {0};
return SHA256_DIGEST_SIZE;
}
-int zck_hash_setup(zckHashType *ht, int h) {
+int hash_setup(zckHashType *ht, int h) {
if(ht) {
if(h == ZCK_HASH_SHA1) {
memset(ht, 0, sizeof(zckHashType));
return False;
}
-int zck_hash_init(zckHash *hash, zckHashType *hash_type) {
+void hash_close(zckHash *hash) {
+ if(!hash)
+ return;
+
+ if(hash->ctx) {
+ free(hash->ctx);
+ hash->ctx = NULL;
+ }
+ hash->type = NULL;
+ return;
+}
+
+int hash_init(zckHash *hash, zckHashType *hash_type) {
if(hash && hash_type) {
if(hash_type->type == ZCK_HASH_SHA1) {
zck_log(ZCK_LOG_DEBUG, "Initializing SHA-1 hash\n");
return False;
}
-int zck_hash_update(zckHash *hash, const char *message, const size_t size) {
+int hash_update(zckHash *hash, const char *message, const size_t size) {
if(message == NULL && size == 0)
return True;
if(message == NULL) {
return False;
}
-void zck_hash_close(zckHash *hash) {
- if(!hash)
- return;
-
- if(hash->ctx) {
- free(hash->ctx);
- hash->ctx = NULL;
- }
- hash->type = NULL;
- return;
-}
-
-/* Returns 1 if data hash matches, 0 if it doesn't and -1 if failure */
-int PUBLIC zck_validate_data_checksum(zckCtx *zck) {
- zck_hash_close(&(zck->check_full_hash));
- if(!seek_data(zck->fd, zck->data_offset, SEEK_SET))
- return -1;
- if(!zck_hash_init(&(zck->check_full_hash), &(zck->hash_type)))
- return -1;
- char buf[BUF_SIZE] = {0};
- zckIndexItem *idx = zck->index.first;
- zck_log(ZCK_LOG_INFO, "Checking full hash\n");
- while(idx) {
- size_t to_read = idx->comp_length;
- while(to_read > 0) {
- size_t rb = BUF_SIZE;
- if(rb > to_read)
- rb = to_read;
- if(!read_data(zck->fd, buf, rb))
- return -1;
- if(!zck_hash_update(&(zck->check_full_hash), buf, rb))
- return -1;
- to_read -= rb;
- }
- idx = idx->next;
- }
- return zck_validate_file(zck);
-}
-
-char *zck_hash_finalize(zckHash *hash) {
+char *hash_finalize(zckHash *hash) {
if(hash && hash->ctx && hash->type) {
if(hash->type->type == ZCK_HASH_SHA1) {
unsigned char *digest = zmalloc(hash->type->digest_size);
SHA1_Final((sha1_byte*)digest, (SHA_CTX *)hash->ctx);
- zck_hash_close(hash);
+ hash_close(hash);
return (char *)digest;
} else if(hash->type->type == ZCK_HASH_SHA256) {
unsigned char *digest = zmalloc(hash->type->digest_size);
sha256_final((sha256_ctx *)hash->ctx, digest);
- zck_hash_close(hash);
+ hash_close(hash);
return (char *)digest;
}
zck_log(ZCK_LOG_ERROR, "Unsupported hash type: %i\n", hash->type);
return NULL;
}
-const char PUBLIC *zck_hash_name_from_type(int hash_type) {
- if(hash_type > 1) {
- snprintf(unknown+8, 21, "%i)", hash_type);
- return unknown;
- }
- return HASH_NAME[hash_type];
-}
-
int set_full_hash_type(zckCtx *zck, int hash_type) {
VALIDATE(zck);
zck_log(ZCK_LOG_INFO, "Setting full hash to %s\n",
zck_hash_name_from_type(hash_type));
- if(!zck_hash_setup(&(zck->hash_type), hash_type)) {
+ if(!hash_setup(&(zck->hash_type), hash_type)) {
zck_log(ZCK_LOG_ERROR, "Unable to set full hash to %s\n",
zck_hash_name_from_type(hash_type));
return False;
}
- zck_hash_close(&(zck->full_hash));
- if(!zck_hash_init(&(zck->full_hash), &(zck->hash_type))) {
+ hash_close(&(zck->full_hash));
+ if(!hash_init(&(zck->full_hash), &(zck->hash_type))) {
zck_log(ZCK_LOG_ERROR, "Unable initialize full hash\n");
return False;
}
memset(&(zck->chunk_hash_type), 0, sizeof(zckHashType));
zck_log(ZCK_LOG_INFO, "Setting chunk hash to %s\n",
zck_hash_name_from_type(hash_type));
- if(!zck_hash_setup(&(zck->chunk_hash_type), hash_type)) {
+ if(!hash_setup(&(zck->chunk_hash_type), hash_type)) {
zck_log(ZCK_LOG_ERROR, "Unable to set chunk hash to %s\n",
zck_hash_name_from_type(hash_type));
return False;
zck->index.digest_size = zck->chunk_hash_type.digest_size;
return True;
}
+
+/* Returns 1 if data hash matches, 0 if it doesn't and -1 if failure */
+int PUBLIC zck_validate_data_checksum(zckCtx *zck) {
+ hash_close(&(zck->check_full_hash));
+ if(!seek_data(zck->fd, zck->data_offset, SEEK_SET))
+ return -1;
+ if(!hash_init(&(zck->check_full_hash), &(zck->hash_type)))
+ return -1;
+ char buf[BUF_SIZE] = {0};
+ zckIndexItem *idx = zck->index.first;
+ zck_log(ZCK_LOG_INFO, "Checking full hash\n");
+ while(idx) {
+ size_t to_read = idx->comp_length;
+ while(to_read > 0) {
+ size_t rb = BUF_SIZE;
+ if(rb > to_read)
+ rb = to_read;
+ if(!read_data(zck->fd, buf, rb))
+ return -1;
+ if(!hash_update(&(zck->check_full_hash), buf, rb))
+ return -1;
+ to_read -= rb;
+ }
+ idx = idx->next;
+ }
+ return validate_file(zck);
+}
+
+const char PUBLIC *zck_hash_name_from_type(int hash_type) {
+ if(hash_type > 1) {
+ snprintf(unknown+8, 21, "%i)", hash_type);
+ return unknown;
+ }
+ return HASH_NAME[hash_type];
+}
"(%i)\n", hash_type, zck->prep_hash_type);
return False;
}
- if(!zck_hash_setup(&(zck->hash_type), hash_type))
+ if(!hash_setup(&(zck->hash_type), hash_type))
return False;
zck_log(ZCK_LOG_DEBUG, "Setting header and full digest hash type to %s\n",
zck_hash_name_from_type(hash_type));
zck->header_size = zck->lead_size + zck->header_length;
}
- if(!zck_hash_init(&(zck->check_full_hash), &(zck->hash_type)))
+ if(!hash_init(&(zck->check_full_hash), &(zck->hash_type)))
return False;
- if(!zck_hash_update(&(zck->check_full_hash), zck->header,
+ if(!hash_update(&(zck->check_full_hash), zck->header,
zck->hdr_digest_loc))
return False;
- if(!zck_hash_update(&(zck->check_full_hash), header, zck->header_length))
+ if(!hash_update(&(zck->check_full_hash), header, zck->header_length))
return False;
- if(!zck_validate_header(zck))
+ if(!validate_header(zck))
return False;
return True;
}
return False;
if(!comp_ioption(zck, ZCK_COMP_TYPE, tmp))
return False;
- if(!zck_comp_init(zck))
+ if(!comp_init(zck))
return False;
/* Read and initialize index size */
}
header = zck->header + zck->lead_size + zck->preface_size;
int max_length = zck->header_size - (zck->lead_size + zck->preface_size);
- if(!zck_index_read(zck, header, zck->index_size, max_length))
+ if(!index_read(zck, header, zck->index_size, max_length))
return False;
zck->index_string = header;
return True;
}
-int zck_header_create(zckCtx *zck) {
+int header_create(zckCtx *zck) {
/* Rebuild header without header hash */
if(zck->header_digest) {
free(zck->header_digest);
zckHash header_hash = {0};
/* Calculate hash of header */
- if(!zck_hash_init(&header_hash, &(zck->hash_type)))
+ if(!hash_init(&header_hash, &(zck->hash_type)))
return False;
zck_log(ZCK_LOG_DEBUG, "Hashing lead\n");
/* Hash lead up to header digest */
- if(!zck_hash_update(&header_hash, zck->lead_string,
+ if(!hash_update(&header_hash, zck->lead_string,
zck->hdr_digest_loc))
return False;
zck_log(ZCK_LOG_DEBUG, "Hashing the rest\n");
/* Hash rest of header */
- if(!zck_hash_update(&header_hash, zck->preface_string, zck->header_length))
+ if(!hash_update(&header_hash, zck->preface_string, zck->header_length))
return False;
- zck->header_digest = zck_hash_finalize(&header_hash);
+ zck->header_digest = hash_finalize(&header_hash);
if(zck->header_digest == NULL) {
zck_log(ZCK_LOG_ERROR,
"Unable to calculate %s checksum for index\n",
return True;
}
-int zck_write_header(zckCtx *zck) {
+int write_header(zckCtx *zck) {
VALIDATE_WRITE(zck);
zck_log(ZCK_LOG_DEBUG, "Writing header: %lu bytes\n",
#include "zck_private.h"
-zckIndexItem *zck_get_index_of_loc(zckIndex *index, size_t loc) {
+zckIndexItem *get_index_of_loc(zckIndex *index, size_t loc) {
zckIndexItem *idx = index->first;
while(idx != NULL) {
if(loc >= idx->start && loc < idx->start + idx->comp_length)
return NULL;
}
-void zck_index_free_item(zckIndexItem **item) {
+void index_free_item(zckIndexItem **item) {
if(*item == NULL)
return;
return;
}
-void zck_index_clean(zckIndex *index) {
+void index_clean(zckIndex *index) {
if(index == NULL)
return;
zckIndexItem *tmp=index->first;
while(tmp != NULL) {
next = tmp->next;
- zck_index_free_item(&tmp);
+ index_free_item(&tmp);
tmp = next;
}
}
memset(index, 0, sizeof(zckIndex));
}
-void zck_index_free(zckCtx *zck) {
- zck_index_clean(&(zck->index));
+void index_free(zckCtx *zck) {
+ index_clean(&(zck->index));
if(zck->full_hash_digest) {
free(zck->full_hash_digest);
zck->full_hash_digest = NULL;
zck->header_digest = NULL;
}
}
+
+void clear_work_index(zckCtx *zck) {
+ if(zck == NULL)
+ return;
+
+ hash_close(&(zck->work_index_hash));
+ if(zck->work_index_item)
+ index_free_item(&(zck->work_index_item));
+}
size_t index_size = 0;
- zck->full_hash_digest = zck_hash_finalize(&(zck->full_hash));
+ zck->full_hash_digest = hash_finalize(&(zck->full_hash));
if(zck->full_hash_digest == NULL)
return False;
return True;
}
-int zck_index_new_chunk(zckIndex *index, char *digest, int digest_size,
+int index_new_chunk(zckIndex *index, char *digest, int digest_size,
size_t comp_size, size_t orig_size, int finished) {
if(index == NULL) {
zck_log(ZCK_LOG_ERROR, "Invalid index\n");
return finish_chunk(index, idx, digest, finished);
}
-int zck_index_create_chunk(zckCtx *zck) {
+int index_create_chunk(zckCtx *zck) {
VALIDATE(zck);
- zck_clear_work_index(zck);
+ clear_work_index(zck);
zck->work_index_item = zmalloc(sizeof(zckIndexItem));
if(zck->work_index_item == NULL) {
zck_log(ZCK_LOG_ERROR, "Unable to allocate %lu bytes\n",
sizeof(zckIndexItem));
return False;
}
- if(!zck_hash_init(&(zck->work_index_hash), &(zck->chunk_hash_type)))
+ if(!hash_init(&(zck->work_index_hash), &(zck->chunk_hash_type)))
return False;
return True;
}
-int zck_index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
+int index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
size_t orig_size) {
VALIDATE(zck);
- if(zck->work_index_item == NULL && !zck_index_create_chunk(zck))
+ if(zck->work_index_item == NULL && !index_create_chunk(zck))
return False;
zck->work_index_item->length += orig_size;
if(comp_size == 0)
return True;
- if(!zck_hash_update(&(zck->full_hash), data, comp_size))
+ if(!hash_update(&(zck->full_hash), data, comp_size))
return False;
- if(!zck_hash_update(&(zck->work_index_hash), data, comp_size))
+ if(!hash_update(&(zck->work_index_hash), data, comp_size))
return False;
zck->work_index_item->comp_length += comp_size;
return True;
}
-int zck_index_finish_chunk(zckCtx *zck) {
+int index_finish_chunk(zckCtx *zck) {
VALIDATE(zck);
- if(zck->work_index_item == NULL && !zck_index_create_chunk(zck))
+ if(zck->work_index_item == NULL && !index_create_chunk(zck))
return False;
char *digest = NULL;
if(zck->work_index_item->length > 0) {
/* Finalize chunk checksum */
- digest = zck_hash_finalize(&(zck->work_index_hash));
+ digest = hash_finalize(&(zck->work_index_hash));
if(digest == NULL) {
zck_log(ZCK_LOG_ERROR,
"Unable to calculate %s checksum for new chunk\n",
free(digest);
zck->work_index_item = NULL;
- zck_hash_close(&(zck->work_index_hash));
+ hash_close(&(zck->work_index_hash));
return True;
}
return False; \
}
-int zck_index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
+int index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
VALIDATE(zck);
size_t length = 0;
log_level = ll;
}
-void PUBLIC zck_log(zck_log_type lt, const char *format, ...) {
+void zck_log(zck_log_type lt, const char *format, ...) {
if(lt >= log_level) {
va_list args;
va_start(args, format);
"*before* the header digest itself\n");
return False;
}
- if(!zck_hash_setup(&chk_type, zck->prep_hash_type)) {
+ if(!hash_setup(&chk_type, zck->prep_hash_type)) {
free(data);
return False;
}
if(zck->mode == ZCK_MODE_WRITE) {
if(zck_end_chunk(zck) < 0)
return False;
- if(!zck_header_create(zck))
+ if(!header_create(zck))
return False;
- if(!zck_write_header(zck))
+ if(!write_header(zck))
return False;
zck_log(ZCK_LOG_DEBUG, "Writing chunks\n");
if(!chunks_from_temp(zck))
return False;
zck_log(ZCK_LOG_DEBUG, "Finished writing file, cleaning up\n");
- if(!zck_comp_close(zck))
+ if(!comp_close(zck))
return False;
if(zck->temp_fd) {
close(zck->temp_fd);
zck->temp_fd = 0;
}
} else {
- if(!zck_validate_file(zck))
+ if(!validate_file(zck))
return False;
}
return True;
}
-void zck_clear_work_index(zckCtx *zck) {
- if(zck == NULL)
- return;
-
- zck_hash_close(&(zck->work_index_hash));
- if(zck->work_index_item)
- zck_index_free_item(&(zck->work_index_item));
-}
-
void zck_clear(zckCtx *zck) {
if(zck == NULL)
return;
- zck_index_free(zck);
+ index_free(zck);
if(zck->header)
free(zck->header);
zck->header = NULL;
zck->header_size = 0;
- if(!zck_comp_close(zck))
+ if(!comp_close(zck))
zck_log(ZCK_LOG_WARNING, "Unable to close compression\n");
- zck_hash_close(&(zck->full_hash));
- zck_hash_close(&(zck->check_full_hash));
- zck_hash_close(&(zck->check_chunk_hash));
- zck_clear_work_index(zck);
+ hash_close(&(zck->full_hash));
+ hash_close(&(zck->check_full_hash));
+ hash_close(&(zck->check_chunk_hash));
+ clear_work_index(zck);
if(zck->full_hash_digest) {
free(zck->full_hash_digest);
zck->full_hash_digest = NULL;
return NULL;
zck->mode = ZCK_MODE_WRITE;
- zck->temp_fd = zck_get_tmp_fd();
+ zck->temp_fd = get_tmp_fd();
if(zck->temp_fd < 0)
goto iw_error;
return zck_get_header_length(zck) + zck_get_data_length(zck);
}
-int zck_get_tmp_fd() {
+int get_tmp_fd() {
int temp_fd;
char *fname = NULL;
char template[] = "zcktempXXXXXX";
return temp_fd;
}
-int zck_import_dict(zckCtx *zck) {
+int import_dict(zckCtx *zck) {
VALIDATE(zck);
size_t size = zck->index.first->length;
return False;
}
zck_log(ZCK_LOG_DEBUG, "Resetting compression\n");
- if(!zck_comp_reset(zck))
+ if(!comp_reset(zck))
return False;
zck_log(ZCK_LOG_DEBUG, "Setting dict\n");
if(!comp_soption(zck, ZCK_COMP_DICT, data, size))
return False;
- if(!zck_comp_init(zck))
+ if(!comp_init(zck))
return False;
free(data);
return True;
}
-int zck_validate_chunk(zckCtx *zck, zckIndexItem *idx,
+int validate_chunk(zckCtx *zck, zckIndexItem *idx,
zck_log_type bad_checksum) {
VALIDATE(zck);
if(idx == NULL) {
return -1;
}
- char *digest = zck_hash_finalize(&(zck->check_chunk_hash));
+ char *digest = hash_finalize(&(zck->check_chunk_hash));
if(digest == NULL) {
zck_log(ZCK_LOG_ERROR,
"Unable to calculate %s checksum for chunk\n");
return 1;
}
-int zck_validate_current_chunk(zckCtx *zck) {
+int validate_current_chunk(zckCtx *zck) {
VALIDATE(zck);
- return zck_validate_chunk(zck, zck->comp.data_idx, ZCK_LOG_ERROR);
+ return validate_chunk(zck, zck->comp.data_idx, ZCK_LOG_ERROR);
}
-int zck_validate_file(zckCtx *zck) {
+int validate_file(zckCtx *zck) {
VALIDATE(zck);
- char *digest = zck_hash_finalize(&(zck->check_full_hash));
+ char *digest = hash_finalize(&(zck->check_full_hash));
if(digest == NULL) {
zck_log(ZCK_LOG_ERROR,
"Unable to calculate %s checksum for full file\n");
return 1;
}
-int zck_validate_header(zckCtx *zck) {
+int validate_header(zckCtx *zck) {
VALIDATE(zck);
- char *digest = zck_hash_finalize(&(zck->check_full_hash));
+ char *digest = hash_finalize(&(zck->check_full_hash));
if(digest == NULL) {
zck_log(ZCK_LOG_ERROR,
"Unable to calculate %s checksum for header\n");
zck_log(ZCK_LOG_DEBUG, "Header checksum valid\n");
free(digest);
- if(!zck_hash_init(&(zck->check_full_hash), &(zck->hash_type)))
+ if(!hash_init(&(zck->check_full_hash), &(zck->hash_type)))
return -1;
return 1;
return -1;
}
- zck_hash_close(&(zck->check_full_hash));
- if(!zck_hash_init(&(zck->check_full_hash), &(zck->hash_type)))
+ hash_close(&(zck->check_full_hash));
+ if(!hash_init(&(zck->check_full_hash), &(zck->hash_type)))
return -1;
if(!seek_data(zck->fd, zck->data_offset, SEEK_SET))
continue;
}
- if(!zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
+ if(!hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
return -1;
size_t rlen = 0;
rsize = idx->comp_length - rlen;
if(read_data(zck->fd, buf, rsize) != rsize)
return 0;
- if(!zck_hash_update(&(zck->check_chunk_hash), buf, rsize))
+ if(!hash_update(&(zck->check_chunk_hash), buf, rsize))
return -1;
- if(!zck_hash_update(&(zck->check_full_hash), buf, rsize))
+ if(!hash_update(&(zck->check_full_hash), buf, rsize))
return -1;
rlen += rsize;
}
- int valid_chunk = zck_validate_chunk(zck, idx, ZCK_LOG_ERROR);
+ int valid_chunk = validate_chunk(zck, idx, ZCK_LOG_ERROR);
if(valid_chunk < 0)
return -1;
idx->valid = valid_chunk;
return 0;
/* Check data checksum */
- int valid_file = zck_validate_file(zck);
+ int valid_file = validate_file(zck);
if(valid_file < 0)
return -1;
return -1;
/* Reinitialize data checksum */
- if(!zck_hash_init(&(zck->check_full_hash), &(zck->hash_type)))
+ if(!hash_init(&(zck->check_full_hash), &(zck->hash_type)))
return -1;
return valid_file;
size_t data_size;
} zckCtx;
-const char *zck_hash_name_from_type(int hash_type)
+int get_tmp_fd()
__attribute__ ((warn_unused_result));
-int zck_get_tmp_fd()
+int import_dict(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_import_dict(zckCtx *zck)
+int validate_file(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_validate_file(zckCtx *zck)
+int validate_current_chunk(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_validate_current_chunk(zckCtx *zck)
+int validate_header(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_validate_header(zckCtx *zck)
+const char *hash_name_from_type(int hash_type)
__attribute__ ((warn_unused_result));
-void zck_clear_work_index(zckCtx *zck);
char *get_digest_string(const char *digest, int size)
__attribute__ ((warn_unused_result));
/* hash/hash.h */
-int zck_hash_setup(zckHashType *ht, int h)
+int hash_setup(zckHashType *ht, int h)
__attribute__ ((warn_unused_result));
-int zck_hash_init(zckHash *hash, zckHashType *hash_type)
+int hash_init(zckHash *hash, zckHashType *hash_type)
__attribute__ ((warn_unused_result));
-int zck_hash_update(zckHash *hash, const char *message, const size_t size)
+int hash_update(zckHash *hash, const char *message, const size_t size)
__attribute__ ((warn_unused_result));
-char *zck_hash_finalize(zckHash *hash)
+char *hash_finalize(zckHash *hash)
__attribute__ ((warn_unused_result));
-void zck_hash_close(zckHash *hash);
+void hash_close(zckHash *hash);
const char *zck_hash_get_printable(const char *digest, zckHashType *type)
__attribute__ ((warn_unused_result));
int set_full_hash_type(zckCtx *zck, int hash_type)
/* index/index.c */
-int zck_index_read(zckCtx *zck, char *data, size_t size, size_t max_length)
+int index_read(zckCtx *zck, char *data, size_t size, size_t max_length)
__attribute__ ((warn_unused_result));
int index_create(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_index_new_chunk(zckIndex *index, char *digest, int digest_size,
+int index_new_chunk(zckIndex *index, char *digest, int digest_size,
size_t comp_size, size_t orig_size, int valid)
__attribute__ ((warn_unused_result));
-int zck_index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
+int index_add_to_chunk(zckCtx *zck, char *data, size_t comp_size,
size_t orig_size)
__attribute__ ((warn_unused_result));
-int zck_index_finish_chunk(zckCtx *zck)
+int index_finish_chunk(zckCtx *zck)
__attribute__ ((warn_unused_result));
-void zck_index_clean(zckIndex *index);
-void zck_index_free(zckCtx *zck);
-void zck_index_free_item(zckIndexItem **item);
-int zck_write_index(zckCtx *zck)
+void index_clean(zckIndex *index);
+void index_free(zckCtx *zck);
+void index_free_item(zckIndexItem **item);
+void clear_work_index(zckCtx *zck);
+int write_index(zckCtx *zck)
__attribute__ ((warn_unused_result));
-zckIndexItem *zck_get_index_of_loc(zckIndex *index, size_t loc)
+zckIndexItem *get_index_of_loc(zckIndex *index, size_t loc)
__attribute__ ((warn_unused_result));
+
/* io.c */
int seek_data(int fd, off_t offset, int whence)
__attribute__ ((warn_unused_result));
__attribute__ ((warn_unused_result));
int read_sig(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_read_header(zckCtx *zck)
+int header_create(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_header_create(zckCtx *zck)
+int sig_create(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_sig_create(zckCtx *zck)
+int write_header(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_write_header(zckCtx *zck)
- __attribute__ ((warn_unused_result));
-int zck_write_sigs(zckCtx *zck)
+int write_sigs(zckCtx *zck)
__attribute__ ((warn_unused_result));
/* comp/comp.c */
-int zck_comp_add_to_dc(zckComp *comp, const char *src, size_t src_size)
+int comp_init(zckCtx *zck)
+ __attribute__ ((warn_unused_result));
+int comp_close(zckCtx *zck)
__attribute__ ((warn_unused_result));
-int zck_comp_add_to_data(zckComp *comp, const char *src, size_t src_size)
+int comp_reset(zckCtx *zck)
__attribute__ ((warn_unused_result));
-size_t zck_comp_read_from_dc(zckComp *comp, char *dst, size_t dst_size)
+int comp_add_to_dc(zckComp *comp, const char *src, size_t src_size)
+ __attribute__ ((warn_unused_result));
+int comp_add_to_data(zckComp *comp, const char *src, size_t src_size)
+ __attribute__ ((warn_unused_result));
+size_t comp_read_from_dc(zckComp *comp, char *dst, size_t dst_size)
__attribute__ ((warn_unused_result));
ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, int use_dict)
__attribute__ ((warn_unused_result));
__attribute__ ((warn_unused_result));
/* dl/range.c */
-char *zck_range_get_char(zckRangeItem **range, int max_ranges)
+char *range_get_char(zckRangeItem **range, int max_ranges)
__attribute__ ((warn_unused_result));
-int zck_range_add(zckRange *info, zckIndexItem *idx, zckCtx *zck)
+int range_add(zckRange *info, zckIndexItem *idx, zckCtx *zck)
__attribute__ ((warn_unused_result));
/* dl/multipart.c */
-size_t zck_multipart_extract(zckDL *dl, char *b, size_t l)
+size_t multipart_extract(zckDL *dl, char *b, size_t l)
__attribute__ ((warn_unused_result));
-size_t zck_multipart_get_boundary(zckDL *dl, char *b, size_t size)
+size_t multipart_get_boundary(zckDL *dl, char *b, size_t size)
__attribute__ ((warn_unused_result));
/* dl/dl.c */
-int zck_dl_write_range(zckDL *dl, const char *at, size_t length)
- __attribute__ ((warn_unused_result));
-int zck_dl_range_chk_chunk(zckDL *dl, char *url, int is_chunk)
+int dl_write_range(zckDL *dl, const char *at, size_t length)
__attribute__ ((warn_unused_result));
/* compint.c */
int max_ranges;
} dlCtx;
+/* Fail if dl_ctx->fail_no_ranges is set and we get a 200 response */
size_t dl_header_cb(char *b, size_t l, size_t c, void *dl_v) {
dlCtx *dl_ctx = (dlCtx*)dl_v;
if(dl_ctx->fail_no_ranges) {
return zck_header_cb(b, l, c, dl_ctx->dl);
}
-/* Return -1 on error, 0 on 200 response (if is_chunk), and 1 on complete
- * success */
+/* Return 0 on error, -1 on 200 response (if dl_ctx->fail_no_ranges),
+ * and 1 on complete success */
int dl_range(dlCtx *dl_ctx, char *url, char *range, int is_chunk) {
if(dl_ctx == NULL || dl_ctx->dl == NULL || dl_ctx->dl->priv == NULL) {
free(range);
char *get_hash(char *data, size_t length, int type) {
zckHashType hash_type = {0};
zckHash hash = {0};
- if(!zck_hash_setup(&hash_type, type))
+ if(!hash_setup(&hash_type, type))
return NULL;
- if(!zck_hash_init(&hash, &hash_type))
+ if(!hash_init(&hash, &hash_type))
return NULL;
- if(!zck_hash_update(&hash, data, length))
+ if(!hash_update(&hash, data, length))
return NULL;
- char *digest = zck_hash_finalize(&hash);
+ char *digest = hash_finalize(&hash);
if(digest == NULL)
return NULL;
return get_digest_string(digest, hash_type.digest_size);