desc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /** @file desc.h
  2. *
  3. * @brief Description (RDF) resource.
  4. *
  5. * The Description Resource (DESC-R), together with the Data Resource (DATA-R),
  6. * is the building block of lsup_repo information. Its contents are fully
  7. * understood by the library.
  8. */
  9. #ifndef _LSR_DESC_H
  10. #define _LSR_DESC_H
  11. #include "core.h"
  12. /*
  13. * Typedefs.
  14. */
  15. typedef char LSR_id[UUIDSTR_SIZE];
  16. typedef enum res_flags_t {
  17. LSR_RS_MANAGED = 1 << 0, // Managed by the repo.
  18. } LSR_ResFlags;
  19. /** @brief DESC-R structure.
  20. *
  21. * A Descriptive Resource (DESC-R) is made up of several RDF named graphs.
  22. * Each graph has a function defined by the framework and can be managed by
  23. * the framework or by the user.
  24. *
  25. * the URI of each graph is derived from the ID of the resource. This is just
  26. * for readability. Actually, when stored, the resource generates triples that
  27. * explicitly link these graphs together. These URIs have an URN prefix so that
  28. * they are portable and, in a Linked Data server, can be easily replaced with
  29. * absolute URLs based on the server root.
  30. *
  31. * The `user_attr` and `admin_attr` graphs contain triples whose objects are
  32. * not managed resources—i.e. URIs on the WWW, blank nodes or literal terms.
  33. * These triples are generally referred to as "attributes" in this
  34. * documentation.
  35. *
  36. * The `user_rel` and `admin_rel` graphs contain exclusively triples whose
  37. * objects are URIs managed by the current repository. They may have special
  38. * functionality attached and may be created as a direct consequence of a user
  39. * action (e.g. adding a member to a Set or List). These triples are
  40. * generally referred to as "relationships" in this documentation.
  41. *
  42. * Relationships between these graphs are expressed by triples stored in the
  43. * default graph.
  44. */
  45. typedef struct desc_t {
  46. LSUP_Graph * user_attr; // User-defined attributes.
  47. LSUP_Graph * admin_attr; // Managed attributes.
  48. LSUP_Graph * user_rel; // User-defined relationships.
  49. LSUP_Graph * admin_rel; // Managed relationships.
  50. uuid_t id; // Resource identifier (UUID4).
  51. LSR_ResFlags flags; // Flags.
  52. } LSR_Desc;
  53. /*
  54. * API functions.
  55. */
  56. /** @brief Create an in-memory DESC-R from graph data.
  57. *
  58. * The resource is volatile until it is stored in a persistent back end. It
  59. * must be stored in a context-capable back end (e.g. `LSUP_STORE_MDB`).
  60. *
  61. * The resource is assigned a UUID4. The resource URI, used in
  62. * relationships, is the ID prefixed with the `LSR_NS_DESC` namespace.
  63. *
  64. * @param[in] data Graph with triples to populate the new resource. The graph
  65. * URI is not used. All URIs in the graph may be relative to the resource.
  66. * Hence, to reference the resource itself, an IRIRef with an empty string as
  67. * data is used.
  68. *
  69. * @param[out] rsrc Resource handle. It must be freed with #LSR_desc_free().
  70. */
  71. LSUP_rc
  72. LSR_desc_new (LSUP_Graph *data, LSR_Desc **rsrc);
  73. /** @brief Create an in-memory DESC-R from a stored resource.
  74. *
  75. * Once created, the resource may be modified independently from its stored
  76. * counterpart. In order to make changes permanent, it must be stored again
  77. * using #LSR_desc_store().
  78. *
  79. * @param[in] id ID of the resource to be retrieved, without the namespace.
  80. *
  81. * @param[out] rsrc Resource handle. It must be freed with #LSR_desc_free().
  82. */
  83. LSUP_rc
  84. LSR_desc_get (LSR_id id, LSR_Desc **rsrc);
  85. /** @brief Free a DESC-R.
  86. */
  87. void
  88. LSR_desc_free (LSR_Desc *rsrc);
  89. /** @brief Store a DESC-R, overwriting any data if it already exists.
  90. *
  91. * This is a "create or overwrite" function that deletes any existing resource
  92. * under the given ID before storing the content of the in-memory resource
  93. * at hand.
  94. *
  95. * All data are copied and the resource may be freed after this operation.
  96. *
  97. * @param[in] rsrc Resource to be created or overwritten.
  98. */
  99. LSUP_rc
  100. LSR_desc_store (LSR_Desc *rsrc);
  101. /** Perform a delta update on a stored resource.
  102. *
  103. * This function operates directly on a stored resource without the need to
  104. * provide an in-memory DESC-R. It first deletes triples by given patterns,
  105. * then adds triples. Both steps are optional.
  106. *
  107. * @param[in] id ID of the resource to be modified, without the namespace.
  108. *
  109. * @param[in] remove Array of 3-member array of terms. Each set of
  110. * terms represents the s, p, o bound terms. Any and all can be NULL, as in
  111. * #LSUP_graph_remove(). The array is terminated by a `{NULL}` array.
  112. *
  113. * @param[in] add Array of triples to be added, terminated by a NULL.
  114. */
  115. LSUP_rc
  116. LSUP_desc_update (LSR_id id, LSUP_Term **remove, LSUP_Triple *add);
  117. #endif /* _LSR_DESC_H */