Example #1
0
static void getchecksum(struct context *ctx)
{
    size_t len;
    struct md_method *m = ctx->md_hash ? ctx->md_method_hash : ctx->md_method_checksum;

    DebugIn(DEBUG_BUFFER);

    sigbus_cur = ctx->cfn;

    if (chunk_get(ctx, &ctx->io_offset)) {
	reply(ctx, MSG_451_Internal_error);
	goto bye;
    }

    if (chunk_remaining(ctx)) {
	len = MIN((size_t) bufsize, ctx->chunk_length);
	m->update(ctx, (u_char *) ctx->chunk_start, len);
	chunk_release(ctx, len);
    }

    if (chunk_remaining(ctx))
	io_sched_renew_proc(ctx->io, ctx, (void *) getchecksum);
    else {
	if (!strcmp(m->ftp_name, "CRC32")) {
	    if (ctx->md_hash) {
		replyf(ctx, "213 %s %llu-%llu %s %s\r\n", m->ftp_name,
		       (unsigned long long) ctx->io_offset_start, (unsigned long long) ctx->offset, m->final(ctx), ctx->filename + ctx->rootlen);
	    } else
		replyf(ctx, "200 %s %llu %s\r\n", m->final(ctx), (unsigned long long) ctx->offset, ctx->filename + ctx->rootlen);
	} else if (ctx->md_hash) {
Example #2
0
static void skipbytes(struct context *ctx, int cur __attribute__ ((unused)))
{
    off_t ro = ctx->io_offset, off = 0;

    DebugIn(DEBUG_BUFFER);

    sigbus_cur = ctx->cfn;

    if (chunk_get(ctx, NULL)) {
	io_sched_pop(ctx->io, ctx);
	ctx->dbufi = buffer_free_all(ctx->dbufi);
	ctx->remaining = 0, ctx->offset = 0;
	cleanup_file(ctx, ctx->ffn);
	cleanup_data(ctx, ctx->ffn);
	reply(ctx, MSG_451_Internal_error);
    } else {
	if (chunk_remaining(ctx)) {
	    char *u = ctx->chunk_start;
	    char lastchar = ctx->lastchar;
	    size_t len = MIN(ctx->chunk_length, (size_t) bufsize);
	    char *ul = u + len;

	    for (off = 0; ro && u < ul; ro--, off++, lastchar = *u++)
		if (*u == '\n' && lastchar != '\r')
		    ro--;

	    ctx->lastchar = lastchar;
	    chunk_release(ctx, len);
	}

	if (!chunk_remaining(ctx))
	    ro = 0;

	if (!ro) {
	    ctx->dbufi = buffer_free_all(ctx->dbufi);
	    lseek(ctx->ffn, ctx->offset + off, SEEK_SET);
	    ctx->remaining = 0, ctx->offset = 0;

	    if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer) {
		/* already connected */
		io_clr_o(ctx->io, ctx->dfn);
		io_set_i(ctx->io, ctx->dfn);
	    }
	    io_sched_pop(ctx->io, ctx);
	} else
	    io_sched_renew_proc(ctx->io, ctx, (void *) skipbytes);

	ctx->io_offset = ro;
    }

    DebugOut(DEBUG_BUFFER);
}
Example #3
0
int main(int argc, char* argv[]) {
    int err, i;
    char key[10], value[10];    
    CHUNK* chunk;
    
    /* create database file */
    err = chunk_create(FILENAME, HTABLE_SIZE);
    if (err) {
        printf("Error: cant create chunk file\n");
        return -1;
    }

    /* open database file */
    chunk = malloc(sizeof(CHUNK));    
    err = chunk_open(chunk, FILENAME, CACHE_SIZE);
    if (err) {
        free(chunk);
        printf("Error: problem with open chunk file\n");
        return -2;
    }

    /* insert  */
    for(i=0; i<SIZE; i++) {
        sprintf(key, "%s%d", "key", i);
        sprintf(value, "%s%d", "value", i);
        chunk_set(chunk, key, value);
    }

    /* remove */
    printf("chunk_remove key5 %d\n", chunk_remove(chunk, "key5"));
    printf("chunk_remove key7 %d\n", chunk_remove(chunk, "key7"));
    
    /* get */
    for(i=0; i<SIZE; i++) {
        sprintf(key, "%s%d", "key", i);
        printf("chunk_get %s = %s\n",key, chunk_get(chunk, key));
    }    
    
    /* forEach */
    chunk_for_each(chunk, display);

    /* close */
    chunk_close(chunk);    
    free(chunk);
    
    return  0;
}