## infd-storage

infd-storage

## Functions

InfdStorageNode * | infd_storage_node_new_subdirectory ()
InfdStorageNode * | infd_storage_node_new_note ()
InfdStorageNode * | infd_storage_node_copy ()
void | infd_storage_node_free ()
void | infd_storage_node_list_free ()
InfdStorageAcl * | infd_storage_acl_copy ()
void | infd_storage_acl_free ()
void | infd_storage_acl_list_free ()
GSList * | infd_storage_read_subdirectory ()
gboolean | infd_storage_create_subdirectory ()
gboolean | infd_storage_remove_node ()
GSList * | infd_storage_read_acl ()
gboolean | infd_storage_write_acl ()

## Types and Values

| InfdStorage
struct | InfdStorageInterface
enum | InfdStorageNodeType
struct | InfdStorageNode
struct | InfdStorageAcl

## Object Hierarchy

        GBoxed
        ├── InfdStorageAcl
        ╰── InfdStorageNode
        GEnum
        ╰── InfdStorageNodeType
        GInterface
        ╰── InfdStorage

## Prerequisites

InfdStorage requires GObject.

## Known Implementations

InfdStorage is implemented by InfdFilesystemStorage.

## Description

## Functions

### infd_storage_node_new_subdirectory ()

    InfdStorageNode *
    infd_storage_node_new_subdirectory (const gchar *path);

Creates a new InfdStorageNode with type `INFD_STORAGE_NODE_SUBDIRECTORY` and the given path. This is most likely only going to be used by InfdStorage implementations.

[constructor]

#### Parameters

path | Path to the node. |

#### Returns

A new InfdStorageNode.

[transfer full]

### infd_storage_node_new_note ()

    InfdStorageNode *
    infd_storage_node_new_note (const gchar *path,
                                const gchar *identifier);

Creates a new InfdStorageNode with type `INFD_STORAGE_NODE_NOTE` and the given path and identifier. This is most likely only going to be used by InfdStorage implementations.

[constructor]

#### Parameters

path | Path to the node. |
identifier | Identifier of the note type, for example 'InfText' for text notes. |

#### Returns

A new InfdStorageNode.

[transfer full]

### infd_storage_node_copy ()

    InfdStorageNode *
    infd_storage_node_copy (const InfdStorageNode *node);

Creates a copy of a InfdStorageNode object.

#### Parameters

node | Node from which to make a copy. |

#### Returns

A copy of `node` .

[transfer full]

### infd_storage_node_free ()

    void
    infd_storage_node_free (InfdStorageNode *node);

Frees a InfdStorageNode allocated with `infd_storage_node_new_subdirectory()`, `infd_storage_node_new_note()` or `infd_storage_node_copy()`.

#### Parameters

node | A InfdStorageNode. |

### infd_storage_node_list_free ()

    void
    infd_storage_node_list_free (GSList *node_list);

Frees a singly-linked list of InfdStorageNode as returned by `infd_storage_read_subdirectory()`.

#### Parameters

node_list | A list of InfdStorageNode objects. | [element-type InfdStorageNode]

### infd_storage_acl_copy ()

    InfdStorageAcl *
    infd_storage_acl_copy (const InfdStorageAcl *acl);

Creates a copy of a InfdStorageAcl object.

#### Parameters

acl | ACL settings from which to make a copy. |

#### Returns

A copy of `acl` .

### infd_storage_acl_free ()

    void
    infd_storage_acl_free (InfdStorageAcl *acl);

Frees a InfdStorageAcl allocated with `infd_storage_acl_copy()`.

#### Parameters

acl | A InfdStorageAcl. |

### infd_storage_acl_list_free ()

    void
    infd_storage_acl_list_free (GSList *acl_list);

Frees a singly-linked list of InfdStorageAcl as returned by `infd_storage_read_acls()`.

#### Parameters

acl_list | A list of InfdStorageAcl objects. | [element-type InfdStorageAcl]

### infd_storage_read_subdirectory ()

    GSList *
    infd_storage_read_subdirectory (InfdStorage *storage,
                                    const gchar *path,
                                    GError **error);

Reads a subdirectory from the storage. Returns a list of InfdStorageNode objects. Both the list and the objects need to be freed by the caller via `infd_storage_node_list_free()`.

#### Parameters

storage | A InfdStorage |
path | A path pointing to a subdirectory node. |
error | Location to store error information. |

#### Returns

A GSList that contains InfdStorageNode objects, or `NULL` if either the subdirectory is empty or an error occurred.

[transfer full][element-type InfdStorageNode][allow-none]

### infd_storage_create_subdirectory ()

    gboolean
    infd_storage_create_subdirectory (InfdStorage *storage,
                                      const gchar *path,
                                      GError **error);

Creates a new subdirectory at the given path that is initially empty.

#### Parameters

storage | A InfdStorage. |
path | A path pointing to non-existing node. |
error | Location to store error information. |

#### Returns

`TRUE` on success.

### infd_storage_remove_node ()

    gboolean
    infd_storage_remove_node (InfdStorage *storage,
                              const gchar *identifier,
                              const gchar *path,
                              GError **error);

Removes the node at path from storage. If it is a subdirectory node, all containing nodes and subdirectory nodes are removed recursively.

#### Parameters

storage | A InfdStorage |
identifier | The type of the node to remove, or `NULL` to remove a subdirectory (TODO: This shouldn't be necessary). |
path | A path pointing to an existing node. |
error | Location to store error information. |

#### Returns

`TRUE` on success.

### infd_storage_read_acl ()

    GSList *
    infd_storage_read_acl (InfdStorage *storage,
                           const gchar *path,
                           GError **error);

Reads the ACL for the node at the path `path` from the storage. It returns a list of InfdStorageAcl objects.

#### Parameters

storage | A InfdStorage. |
path | A path pointing to an existing node. |
error | Location to store error information, if any. |

#### Returns

A possibly empty list of InfdStorageAcl objects. Free with `infd_storage_acl_list_free()` when no longer needed.

[transfer full][element-type InfdStorageAcl][allow-none]

### infd_storage_write_acl ()

    gboolean
    infd_storage_write_acl (InfdStorage *storage,
                            const gchar *path,
                            const InfAclSheetSet *sheet_set,
                            GError **error);

Writes the ACL defined by `sheet_set` into storage. If `sheet_set` is `NULL` this is equivalent to an empty set. Returns `TRUE` on success or `FALSE` on error. If the function fails, `error` is set.

#### Parameters

storage | A InfdStorage. |
path | A path to an existing node. |
sheet_set | Sheets to set for the node at `path` , or `NULL`. |
error | Location to store error information, if any. |

#### Returns

`TRUE` on success or `FALSE` on error.

## Types and Values

### InfdStorage

    typedef struct _InfdStorage InfdStorage;

### struct InfdStorageInterface

    struct InfdStorageInterface {
      GTypeInterface parent;

      /* All these calls are supposed to be synchronous, e.g. completly perform
       * the required task. Some day, we could implement asynchronous
       * behaviour in InfdDirectory (e.g. it caches operations and executes
       * them via the storage in the background). */

      /* Virtual Table */
      GSList* (*read_subdirectory)(InfdStorage* storage,
                                   const gchar* path,
                                   GError** error);

      gboolean (*create_subdirectory)(InfdStorage* storage,
                                      const gchar* path,
                                      GError** error);

      /* TODO: Remove the identifier here */
      gboolean (*remove_node)(InfdStorage* storage,
                              const gchar* identifier,
                              const gchar* path,
                              GError** error);

      /* TODO: Add further methods to copy, move and expunge nodes */

      GSList* (*read_acl)(InfdStorage* storage,
                          const gchar* path,
                          GError** error);

      gboolean (*write_acl)(InfdStorage* storage,
                            const gchar* path,
                            const InfAclSheetSet* sheet_set,
                            GError** error);
    };

### enum InfdStorageNodeType

#### Members

INFD_STORAGE_NODE_SUBDIRECTORY |  |
INFD_STORAGE_NODE_NOTE |  |

### struct InfdStorageNode

    struct InfdStorageNode {
      InfdStorageNodeType type;
      gchar* name;

      gchar* identifier; /* Only set when type == INFD_STORAGE_NODE_NOTE */
    };

### struct InfdStorageAcl

    struct InfdStorageAcl {
      gchar* account_id;
      InfAclMask mask;
      InfAclMask perms;

    };