// Return 0 for OK, -1 for error, 1 for finished reading the file. static int get_next_dindex(uint64_t **dnew, struct sbuf *sb, struct fzp *fzp) { static struct blk blk; static struct iobuf rbuf; memset(&rbuf, 0, sizeof(rbuf)); switch(iobuf_fill_from_fzp(&rbuf, fzp)) { case -1: goto error; case 1: return 1; // Reached the end. } if(rbuf.cmd==CMD_SAVE_PATH) { if(blk_set_from_iobuf_savepath(&blk, &rbuf)) goto error; *dnew=(uint64_t *)malloc_w(sizeof(uint64_t), __func__); **dnew=blk.savepath; iobuf_free_content(&rbuf); return 0; } else iobuf_log_unexpected(&sb->path, __func__); error: iobuf_free_content(&rbuf); return -1; }
static void check_dindex(int i) { int ret; struct fzp *fzp; const char *p; struct iobuf rbuf; int lines=0; struct blk blk; uint64_t last_savepath=0; p=get_extra_path(i, "dindex"); memset(&rbuf, 0, sizeof(rbuf)); fail_unless((fzp=fzp_gzopen(p, "rb"))!=NULL); while(!(ret=iobuf_fill_from_fzp(&rbuf, fzp))) { lines++; switch(rbuf.cmd) { case CMD_SAVE_PATH: blk_set_from_iobuf_savepath(&blk, &rbuf); fail_unless(blk.savepath>last_savepath); last_savepath=blk.savepath; break; default: fail_unless(0==1); break; } iobuf_free_content(&rbuf); } fail_unless(ret==1); fail_unless(lines>500); fail_unless(!fzp_close(&fzp)); }
static int parse_cmd(struct iobuf *rbuf, struct blk *blk) { int ret=-1; printf("%c%04X", rbuf->cmd, (unsigned int)rbuf->len); switch(rbuf->cmd) { case CMD_SIG: if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf)) goto end; printf("%016" PRIX64 "%s%s\n", blk->fingerprint, bytes_to_md5str(blk->md5sum), uint64_to_savepathstr_with_sig(blk->savepath)); break; case CMD_FINGERPRINT: if(blk_set_from_iobuf_fingerprint(blk, rbuf)) goto end; printf("%016" PRIX64 "\n", blk->fingerprint); break; case CMD_SAVE_PATH: if(blk_set_from_iobuf_savepath(blk, rbuf)) goto end; printf("%s\n", uint64_to_savepathstr(blk->savepath)); break; case CMD_DATA: logp("\n%s looks like a data file\n", path); goto end; /* FIX THIS - give a flag to tell it to decode attributes. case CMD_ATTRIBS: memcpy(&sb->attr, rbuf, sizeof(struct iobuf)); attribs_decode(sb); printf("compression: %d\n", sb->compression); break; */ default: printf("%s\n", rbuf->buf); break; } ret=0; end: return ret; }
static int parse_cmd(struct iobuf *rbuf, struct blk *blk) { int ret=-1; printf("%c%04lX", rbuf->cmd, rbuf->len); switch(rbuf->cmd) { case CMD_SIG: if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf)) goto end; printf("%016"PRIX64"%s%s\n", blk->fingerprint, bytes_to_md5str(blk->md5sum), uint64_to_savepathstr_with_sig(blk->savepath)); break; case CMD_FINGERPRINT: if(blk_set_from_iobuf_fingerprint(blk, rbuf)) goto end; printf("%016"PRIX64"\n", blk->fingerprint); break; case CMD_SAVE_PATH: if(blk_set_from_iobuf_savepath(blk, rbuf)) goto end; printf("%s\n", uint64_to_savepathstr(blk->savepath)); break; case CMD_DATA: logp("\n%s looks like a data file\n", path); goto end; default: printf("%s\n", rbuf->buf); break; } ret=0; end: return ret;; }