コード例 #1
0
ファイル: find.c プロジェクト: kimiby/camelion
CML_Error CML_NodeFind(CML_Node * node, char * path, CML_Node ** result, CML_Type type)
{
    CHECKPTR(node  );
    CHECKTYP(type  );
    CHECKPTR(result);

    char next[1024];
    char curr[1024];
    path_curr(path, curr);
    path_next(path, next);
    uint32_t index;

    CHECKERR(CML_NodeFindIndex(node, curr, &index));

    if (next[0]) /* go deeper */
        CHECKERR(CML_NodeFind(node->nodes[index], next, result, type))
    else /* stay here */
    {
        if (node->nodes[index]->type == type)
            *result = node->nodes[index];
        else
            return CML_ERROR_USER_BADTYPE;
    }


    return CML_ERROR_SUCCESS;
}
コード例 #2
0
ファイル: vfs.c プロジェクト: AleksandraButrova/embox
static int __vfs_subtree_lookup_existing(struct node *parent,
		const char *str_path, const char **p_end_existent,
		struct node **child_ptr) {
	size_t len = 0;
	int res = 0;
	struct node *child = *child_ptr;

	assert(parent && str_path);

	while ((str_path = path_next(str_path, &len))) {
		child = vfs_subtree_lookup_childn(parent, str_path, len);
		if (!child) {
			res = -ERR_CHILD_NOT_FOUND;
			goto out;
		}

		str_path += len;
		parent = child;

		if (child->mounted) {
			res = -ERR_CHILD_MOUNTED;
			goto out;
		}
	}

	out: if (p_end_existent) {
		*p_end_existent = str_path;
	}

	*child_ptr = parent;
	return res;
}
コード例 #3
0
ファイル: find.c プロジェクト: kimiby/camelion
CML_Error CML_NodeFindContainer(CML_Node * node, char * path, CML_Node ** result)
{
    CHECKPTR(node  );
    CHECKPTR(result);

    char next[256];
    char curr[256];
    path_curr(path, curr);
    path_next(path, next);
    uint32_t index;

    CHECKERR(CML_NodeFindIndex(node, curr, &index));

    if (next[0]) /* go deeper */
        CHECKERR(CML_NodeFindContainer(node->nodes[index], next, result))
    else /* stay here */
    {
        if ((node->nodes[index]->type == CML_TYPE_ARRAY) ||
            (node->nodes[index]->type == CML_TYPE_HASH))
            *result = node->nodes[index];
        else
            return CML_ERROR_USER_BADTYPE;
    }


    return CML_ERROR_SUCCESS;
}
コード例 #4
0
ファイル: vfs.c プロジェクト: AleksandraButrova/embox
static struct node *__vfs_subtree_create(struct node *parent, const char *path,
		mode_t mode, int intermediate) {
	struct node *child = NULL;
	size_t len;
	struct node **tmp_parent;

	assert(parent);

	tmp_parent = &parent;

	__vfs_subtree_lookup_existing(*tmp_parent, path, &path, tmp_parent);

	path = path_next(path, &len);

	/* Here path points to the first non-existent fragment, if any. */

	if (intermediate) {
		const char *next_path;
		size_t next_len;

		if (!path) {
			/* Node already exist, set mode. */
			//XXX wtf?? parent->mode = mode;
			return *tmp_parent;
		}

		while ((next_path = path_next(path + len, &next_len))) {
			child = __vfs_subtree_create_child(*tmp_parent, path, len, S_IFDIR);

			if (!child) {
				return NULL;
			}

			tmp_parent = &child;
			path = next_path;
			len = next_len;
		}
	} else if (!path || path_next(path + len, NULL)) {
		/* Node already exists or missing intermediate node. */
		return NULL;
	}

	return vfs_subtree_create_child(*tmp_parent, path, mode);
}
コード例 #5
0
ファイル: item.c プロジェクト: Ecdosis/calliope
int item_num_paths( item *it )
{
    int num = 0;
    path *p = it->paths;
    while ( p != NULL )
    {
        num++;
        p = path_next(p);
    }
    return num;
}
コード例 #6
0
ファイル: vfs.c プロジェクト: AleksandraButrova/embox
struct node *vfs_subtree_lookup(struct node *parent, const char *str_path) {
	struct node *node;

	assert(parent);

	__vfs_subtree_lookup_existing(parent, str_path, &str_path, &node);

	if (path_next(str_path, NULL)) {
		/* Have unresolved fragments in path. */
		return NULL;
	}

	return node;
}
コード例 #7
0
ファイル: item.c プロジェクト: Ecdosis/calliope
int item_path_starts( item *it, char *p, char *fname )
{
    path *temp = it->paths;
    int plen = strlen(p);
    while ( temp != NULL )
    {
        char *pt = path_get(temp);
        if ( strlen(pt)>=plen && strncmp(p,pt,plen)==0 )
            return 1;
        else
            temp = path_next(temp);
    }
    return 0;
}
コード例 #8
0
ファイル: item.c プロジェクト: Ecdosis/calliope
/**
 * Does the config path uniquely apply to a file in the current directory?
 * @param it the item
 * @param p the directory path
 * @param fname the full config file path
 * @return 
 */
int item_path_unique( item *it, char *p, char *fname )
{
    path *temp = it->paths;
    int plen = strlen(p);
    while ( temp != NULL )
    {
        char *pt = path_get(temp);
        if ( in_dir(pt,p,plen) && fnames_equal(fname,pt) )
            return 1;
        else
            temp = path_next(temp);
    }
    return 0;
}
コード例 #9
0
ファイル: vfs.c プロジェクト: AleksandraButrova/embox
int vfs_lookup(const char *str_path, struct path *path) {
	struct path parent;

	vfs_get_root_path(&parent);

	if_mounted_follow_down(&parent);

	__vfs_lookup_existing(&parent, str_path, &str_path, path);

	if (path_next(str_path, NULL)) {
		/* Have unresolved fragments in path. */
		return -1;
	}

	return 0;
}
コード例 #10
0
ファイル: item.c プロジェクト: Ecdosis/calliope
void item_dispose( item *it )
{
    path *p = it->paths;
    while ( p != NULL )
    {
        path *next = path_next( p );
        path_dispose( p );
        p = next;
    }
    if ( it->cf != NULL )
        config_dispose( it->cf );
    if ( it->docid != NULL )
        free( it->docid );
    if ( it->db != NULL )
        free( it->db );
    if ( it->versionID != NULL )
        free( it->versionID );
    free( it );
}
コード例 #11
0
ファイル: vfs.c プロジェクト: AleksandraButrova/embox
static void __vfs_lookup_existing(const struct path *parent,
		const char *str_path, const char **p_end_existent, struct path *path) {
	struct node *node;
	size_t len = 0;

	assert(parent && str_path);
	*path = *parent;

	while ((str_path = path_next(str_path, &len))) {
		if_mounted_follow_down(path);
		if (-ERR_CHILD_MOUNTED
				!= __vfs_subtree_lookup_existing(path->node, str_path,
						p_end_existent, &node)) {
			path->node = node;
			break;
		}

		str_path = *p_end_existent;
		path->node = node;
	}

	return;
}