예제 #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) {
예제 #2
0
int mf_unmap(mf_handle_t mf, mf_mapmem_handle_t mapmem_handle) {

    int res_code = 0;

    if((mf == MF_OPEN_FAILED) || (mapmem_handle == MF_OPEN_FAILED)) {
        errno = EINVAL;
        write_log_to_file(Error,"mf_unmap: invalid input!\n");
        return -1;
    }
    ch_pool_t* ch_pool = (ch_pool_t*)mf;
    sem_wait(&(ch_pool -> lock));
    if(((chunk_t*)mapmem_handle) -> length == 0) {
        sem_post(&(ch_pool -> lock));
        return 0;
    }

    res_code = chunk_release((chunk_t*)mapmem_handle);
    if(res_code) {
        write_log_to_file(Error,"mf_unmap: chunk deinitialization failed!\n");
        sem_post(&(ch_pool -> lock));
        return res_code;
    }
    sem_post(&(ch_pool -> lock));
    return 0;
}
예제 #3
0
파일: fcgi_fd.c 프로젝트: Noeyfan/monkey
/*
 * Copy inherit bytes from old chunk to new chunk and set as current
 * chunk.
 */
int fcgi_fd_set_chunk(struct fcgi_fd *fd, struct chunk *a, size_t inherit)
{
	struct chunk *b = fd->chunk;
	size_t b_pos, a_pos;
	struct chunk_ptr tmp;

	chunk_retain(a);

	if (b && inherit > 0) {
		check(b->write >= inherit,
			"Not enough used on old chunk to inherit.");
		check(a->size - a->write > inherit,
			"Not enough free space on new chunk to inherit.");

		a_pos = a->write;
		b_pos = b->write - inherit;

		memcpy(a->data + a_pos, b->data + b_pos, inherit);

		a_pos     += inherit;
		tmp.parent = a;
		tmp.len    = a->size - a_pos;
		tmp.data   = a->data + a_pos;

		check(!chunk_set_write_ptr(a, tmp),
			"Failed to set new write pointer.");
		chunk_release(b);
	} else if (b) {
		chunk_release(b);
	} else {
		check(inherit == 0, "There are no chunks to inherit from.");
	}

	fd->chunk = a;
	return 0;
error:
	if (mk_list_is_empty(&a->_head)) {
		mk_list_del(&a->_head);
	}
	return -1;
}
예제 #4
0
파일: h_stor.c 프로젝트: hydrix1/tacacs
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);
}