desc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "desc.h"
  2. LSUP_rc
  3. LSR_desc_new (LSUP_Graph *data, LSR_Desc **rsrc_p)
  4. {
  5. LSUP_rc rc = LSUP_NOACTION;
  6. LSR_Desc *rsrc;
  7. MALLOC_GUARD (rsrc, LSUP_MEM_ERR);
  8. LSUP_GraphIterator
  9. *lu_it = LSUP_graph_lookup (data, NULL, NULL, NULL, NULL),
  10. *uattr_it = LSUP_graph_add_init (rsrc->user_attr),
  11. *aattr_it = LSUP_graph_add_init (rsrc->admin_attr),
  12. *urel_it = LSUP_graph_add_init (rsrc->user_rel),
  13. *arel_it = LSUP_graph_add_init (rsrc->admin_rel);
  14. LSUP_Triple src_spo;
  15. while (LSUP_graph_iter_next (lu_it, &src_spo) == LSUP_OK) {
  16. LSUP_Triple dest_spo = {
  17. LSUP_term_copy (src_spo.s),
  18. LSUP_term_copy (src_spo.p),
  19. LSUP_term_copy (src_spo.o),
  20. };
  21. // TODO if the pred is managed, ignore the triple and send a warning.
  22. // TODO Else if the resource is a structure type, handle special workflow.
  23. // TODO Else if the subject or object is a resource, check if it exists; if
  24. // it does, add triple to urel; if not, return an error.
  25. // TODO Else add triple to user_attr.
  26. }
  27. finally:
  28. LSUP_graph_iter_free (lu_it);
  29. LSUP_graph_add_done (uattr_it);
  30. LSUP_graph_add_done (aattr_it);
  31. LSUP_graph_add_done (urel_it);
  32. LSUP_graph_add_done (arel_it);
  33. if (rc == LSUP_OK) *rsrc_p = rsrc;
  34. else {
  35. LSR_desc_free (rsrc);
  36. *rsrc_p = NULL;
  37. }
  38. return rc;
  39. }
  40. void LSR_desc_free (LSR_Desc *rsrc)
  41. {
  42. LSUP_graph_free (rsrc->user_attr);
  43. LSUP_graph_free (rsrc->admin_attr);
  44. LSUP_graph_free (rsrc->user_rel);
  45. LSUP_graph_free (rsrc->admin_rel);
  46. free (rsrc);
  47. }