diff --git a/src/node.c b/src/node.c index 1d19585..cea34eb 100644 --- a/src/node.c +++ b/src/node.c @@ -59,6 +59,14 @@ void iso_node_unref(IsoNode *node) /* TODO #00002 handle deletion of each kind of node */ break; } + +#ifdef LIBISO_EXTENDED_INFORMATION + if (node->xinfo) { + /* free extended info */ + node->xinfo->process(node->xinfo->data, 1); + free(node->xinfo); + } +#endif free(node->name); free(node); } diff --git a/src/node.h b/src/node.h index 5b819f5..dfc49ed 100644 --- a/src/node.h +++ b/src/node.h @@ -20,6 +20,51 @@ #include #include +/* #define LIBISO_EXTENDED_INFORMATION */ +#ifdef LIBISO_EXTENDED_INFORMATION + +/** + * The extended information is a way to attach additional information to each + * IsoNode. External applications may want to use this extension system to + * store application speficic information related to each node. On the other + * side, libisofs may make use of this struct to attach information to nodes in + * some particular, uncommon, cases, without incrementing the size of the + * IsoNode struct. + * + * It is implemented like a chained list. + */ +typedef struct iso_extended_info IsoExtendedInfo; + +struct iso_extended_info { + /** + * Next struct in the chain. NULL if it is the last item + */ + IsoExtendedInfo *next; + + /** + * Function to handle this particular extended information. The function + * pointer acts as an identifier for the type of the information. Structs + * with same information type must use the same function. + * + * @param data + * Attached data + * @param flag + * What to do with the data. At this time the following values are + * defined: + * -> 1 the data must be freed + * @return + * 1 + */ + int (*process)(void *data, int flag); + + /** + * Pointer to information specific data. + */ + void *data; +}; + +#endif + /** * */ @@ -56,6 +101,13 @@ struct Iso_Node * Pointer to the linked list of children in a dir. */ IsoNode *next; + +#ifdef LIBISO_EXTENDED_INFORMATION + /** + * Extended information for the node. + */ + IsoExtendedInfo *xinfo; +#endif }; struct Iso_Dir