Пример #1
0
static Store *fs_store_new(const char *pathname)
{
    struct stat stt;
    Store *new_store = store_new();

    new_store->file_mode = S_IRUSR | S_IWUSR;
#ifndef POSH_OS_WIN32
    if (!stat(pathname, &stt) && stt.st_gid == getgid()) {
        if (stt.st_mode & S_IWGRP) {
            umask(S_IWOTH);
        }
        new_store->file_mode |= stt.st_mode & (S_IRGRP | S_IWGRP);
    }
#endif

    new_store->dir.path      = estrdup(pathname);
    new_store->touch         = &fs_touch;
    new_store->exists        = &fs_exists;
    new_store->remove        = &fs_remove;
    new_store->rename        = &fs_rename;
    new_store->count         = &fs_count;
    new_store->close_i       = &fs_close_i;
    new_store->clear         = &fs_clear;
    new_store->clear_all     = &fs_clear_all;
    new_store->clear_locks   = &fs_clear_locks;
    new_store->length        = &fs_length;
    new_store->each          = &fs_each;
    new_store->new_output    = &fs_new_output;
    new_store->open_input    = &fs_open_input;
    new_store->open_lock_i   = &fs_open_lock_i;
    new_store->close_lock_i  = &fs_close_lock_i;
    return new_store;
}
Пример #2
0
/*
 * Btw don't touch beacuse here is hack that change bs->cmp func on the fly 
 * so if you don't know what are you doing, don't do it :-)
 * Hack is needed cause parser sys is bs (array) of bs (arrays) and we want
 * to optimize cascade searching.
 */
int
parser_add(struct ctx_t *dst, struct parser_t *parser)
{
	int i = -1;
	struct store_t *sys;
	struct store_t *pbs;

	log(dst,2,"parser add [%s]\n", parser->name);

	sys = parser_sys_init(dst);

	if(NULL == sys)
		return -1;
	
	/* cmp between parser_t and store_t of parsers */
	sys->cmp = parserbscmp;

	i = store_search(sys, parser);

	if(i >= 0)
	{
		pbs = store_idx_get(sys, i);

		if(store_insert(pbs, parser)<0)
			log(dst,4,"Unable to insert!\n");

		print_parsers(dst); 
	}
	else
	{
		pbs = store_new(2, sizeof(struct parser_t), priocmp);

		if(NULL == pbs)
			return -1;
			
		if(store_idx_set(pbs, parser, 0) < 0)
			log(dst,4,"Unable to store parser!\n");

		/* Cmp between parser arrays (store_t) */
		sys->cmp = pbscmp;

		if(store_idx_set(sys, pbs, sys->last) < 0)
			log(dst,4,"Unable to insert!\n");

		store_sort(sys);
		i = store_search(sys, pbs); 
	}

	sys->cmp = pbscmp;
	return i;
}
Пример #3
0
static enum parser_error parse_store(struct parser *p) {
	struct store *h = parser_priv(p);
	struct store *s;
	unsigned int idx = parser_getuint(p, "index") - 1;

	if (idx >= MAX_STORES)
		return PARSE_ERROR_OUT_OF_BOUNDS;

	s = store_new(parser_getuint(p, "index") - 1);
	s->name = string_make(parser_getstr(p, "name"));
	s->next = h;
	parser_setpriv(p, s);
	return PARSE_ERROR_NONE;
}
Пример #4
0
static Store *fs_store_new(const char *pathname)
{
    struct stat stt;
    Store *new_store = store_new();

    new_store->file_mode = S_IRUSR | S_IWUSR;
#ifndef POSH_OS_WIN32
    if (!stat(pathname, &stt)) {
        gid_t st_gid = stt.st_gid;
        bool is_grp = (st_gid == getgid());

        if (!is_grp) {
            int size = getgroups(0, NULL);
            gid_t list[size];

            if (getgroups(size, list) != -1) {
                int i = 0;
                while (i < size && !(is_grp = (st_gid == list[i]))) i++;
            }
        }

        if (is_grp) {
            if (stt.st_mode & S_IWGRP) {
                umask(S_IWOTH);
            }
            new_store->file_mode |= stt.st_mode & (S_IRGRP | S_IWGRP);
        }
    }
#endif

    new_store->dir.path      = estrdup(pathname);
    new_store->touch         = &fs_touch;
    new_store->exists        = &fs_exists;
    new_store->remove        = &fs_remove;
    new_store->rename        = &fs_rename;
    new_store->count         = &fs_count;
    new_store->close_i       = &fs_close_i;
    new_store->clear         = &fs_clear;
    new_store->clear_all     = &fs_clear_all;
    new_store->clear_locks   = &fs_clear_locks;
    new_store->length        = &fs_length;
    new_store->each          = &fs_each;
    new_store->new_output    = &fs_new_output;
    new_store->open_input    = &fs_open_input;
    new_store->open_lock_i   = &fs_open_lock_i;
    new_store->close_lock_i  = &fs_close_lock_i;
    return new_store;
}
Пример #5
0
Store *open_ram_store()
{
    Store *new_store = store_new();

    new_store->dir.ht       = h_new_str(NULL, rf_close);
    new_store->touch        = &ram_touch;
    new_store->exists       = &ram_exists;
    new_store->remove       = &ram_remove;
    new_store->rename       = &ram_rename;
    new_store->count        = &ram_count;
    new_store->clear        = &ram_clear;
    new_store->clear_all    = &ram_clear_all;
    new_store->clear_locks  = &ram_clear_locks;
    new_store->length       = &ram_length;
    new_store->each         = &ram_each;
    new_store->new_output   = &ram_new_output;
    new_store->open_input   = &ram_open_input;
    new_store->open_lock_i  = &ram_open_lock_i;
    new_store->close_lock_i = &ram_close_lock_i;
    new_store->close_i      = &ram_close_i;
    return new_store;
}
Пример #6
0
Store *open_cmpd_store(Store *store, const char *name)
{
    int count, i;
    off_t offset;
    char *fname;
    FileEntry *entry = NULL;
    Store *new_store = NULL;
    CompoundStore *volatile cmpd = NULL;
    InStream *volatile is = NULL;

    TRY
        cmpd = ALLOC_AND_ZERO(CompoundStore);

        cmpd->store       = store;
        cmpd->name        = name;
        cmpd->entries     = h_new_str(&free, &free);
        is = cmpd->stream = store->open_input(store, cmpd->name);

        /* read the directory and init files */
        count = is_read_vint(is);
        entry = NULL;
        for (i = 0; i < count; i++) {
            offset = (off_t)is_read_i64(is);
            fname = is_read_string(is);

            if (entry != NULL) {
                /* set length of the previous entry */
                entry->length = offset - entry->offset;
            }

            entry = ALLOC(FileEntry);
            entry->offset = offset;
            h_set(cmpd->entries, fname, entry);
        }
    XCATCHALL
        if (is) is_close(is);
        if (cmpd->entries) h_destroy(cmpd->entries);
        free(cmpd);
    XENDTRY

    /* set the length of the final entry */
    if (entry != NULL) {
        entry->length = is_length(is) - entry->offset;
    }

    new_store               = store_new();
    new_store->dir.cmpd     = cmpd;
    new_store->touch        = &cmpd_touch;
    new_store->exists       = &cmpd_exists;
    new_store->remove       = &cmpd_remove;
    new_store->rename       = &cmpd_rename;
    new_store->count        = &cmpd_count;
    new_store->clear        = &cmpd_clear;
    new_store->length       = &cmpd_length;
    new_store->each         = &cmpd_each;
    new_store->close_i      = &cmpd_close_i;
    new_store->new_output   = &cmpd_new_output;
    new_store->open_input   = &cmpd_open_input;
    new_store->open_lock_i  = &cmpd_open_lock_i;
    new_store->close_lock_i = &cmpd_close_lock_i;

    return new_store;
}