core.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "core.h"
  2. bool LSR_is_init = false;
  3. /*
  4. * Initial namespace map.
  5. */
  6. static char *nsm_str[][2] = {
  7. {"ebucore", "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#"},
  8. {"rsrc", LSR_RSRC_PFX},
  9. {"lsup", "http://data.knowledgetx.com/onto/lsup#"},
  10. {"premis", "http://www.loc.gov/premis/rdf/v1#"},
  11. {NULL, NULL}
  12. };
  13. /*
  14. * Repo-managed predicates.
  15. */
  16. static char *mgd_pred_str[] = {
  17. "ebucore:hasMimeType",
  18. "lsup:created",
  19. "lsup:createdBy",
  20. "lsup:lastModified",
  21. "lsup:lastModifiedBy",
  22. "premis:hasSize",
  23. "premis:hasMessageDigest",
  24. NULL
  25. };
  26. /*
  27. * Repo-managed RDF types.
  28. */
  29. static char *mgd_type_str[] = {
  30. "lsup:AdminMetadata",
  31. "lsup:DataResource",
  32. "lsup:DescriptionResource",
  33. "lsup:List",
  34. "lsup:ListItem",
  35. "lsup:Metadata",
  36. "lsup:Proxy",
  37. "lsup:Resource",
  38. "lsup:Set",
  39. "lsup:UserMetadata",
  40. NULL
  41. };
  42. LSR_TermMap *LSR_managed_preds, *LSR_managed_types;
  43. LSUP_rc LSR_init (void)
  44. {
  45. if (LSR_is_init) return LSUP_NOACTION;
  46. LSUP_rc rc = LSUP_init();
  47. if (rc < 0) return rc;
  48. // Load additional LSUP_repo namespaces into store and memory.
  49. LSUP_NSMap *nsm = LSUP_default_env->nsm;
  50. for (int i = 0; nsm_str[i][0] != NULL; i++)
  51. LSUP_nsmap_add (nsm, nsm_str[i][0], nsm_str[i][1]);
  52. // Store the additional NS if this is the first time.
  53. LSUP_mdbstore_nsm_store (LSUP_default_env->mdb_store, nsm);
  54. // Cache managed predicates.
  55. for (int i = 0; mgd_pred_str[i] != NULL; i++) {
  56. LSUP_Term *uri = LSUP_iriref_new (
  57. mgd_pred_str[i], LSUP_default_env->nsm);
  58. LSR_TermMap *titem;
  59. MALLOC_GUARD (titem, LSUP_MEM_ERR);
  60. titem->term = uri;
  61. titem->key = LSUP_term_hash (uri);
  62. HASH_ADD (hh, LSR_managed_preds, key, sizeof (titem->key), titem);
  63. }
  64. // Cache managed types.
  65. for (int i = 0; mgd_type_str[i] != NULL; i++) {
  66. LSUP_Term *uri = LSUP_iriref_new (
  67. mgd_type_str[i], LSUP_default_env->nsm);
  68. LSR_TermMap *titem;
  69. MALLOC_GUARD (titem, LSUP_MEM_ERR);
  70. titem->term = uri;
  71. titem->key = LSUP_term_hash (uri);
  72. HASH_ADD (hh, LSR_managed_types, key, sizeof (titem->key), titem);
  73. }
  74. LSR_is_init = true;
  75. atexit (LSR_done);
  76. return LSUP_OK;
  77. }
  78. void LSR_done (void)
  79. {
  80. if (!LSR_is_init) return;
  81. log_info ("Tearing down LSUP repo environment.");
  82. LSR_TermMap *entry, *tmp;
  83. HASH_ITER (hh, LSR_managed_preds, entry, tmp) {
  84. HASH_DEL (LSR_managed_preds, entry);
  85. LSUP_term_free (entry->term);
  86. free (entry);
  87. }
  88. HASH_ITER (hh, LSR_managed_types, entry, tmp) {
  89. HASH_DEL (LSR_managed_types, entry);
  90. LSUP_term_free (entry->term);
  91. free (entry);
  92. }
  93. LSUP_done();
  94. LSR_is_init = false;
  95. }
  96. LSUP_Term *LSR_id_to_urn (const uuid_t id, const char *frag);