123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #ifndef _LSUP_NAMESPACE_H
- #define _LSUP_NAMESPACE_H
- #include "hashmap.h"
- #include "lsup/core.h"
- /** @defgroup namespace Namespace module
- * @ingroup public
- * @{
- */
- /** @brief Namespace prefix length, including terminator.
- */
- #define PFX_LEN 8
- /** @brief Namespace prefix type.
- */
- typedef char LSUP_ns_pfx[PFX_LEN];
- /** @brief Prefix / Namespace pair.
- */
- typedef struct ns_entry_t {
- LSUP_ns_pfx pfx; // Namespace prefix.
- char * ns; // Fully qualified NS.
- } NSEntry;
- /** @brief Default namespace prefix map.
- *
- * This is a singleton. It gets created with #LSUP_init() and freed with
- * #LSUP_done().
- */
- extern struct hashmap *LSUP_default_nsm;
- /** @brief Add a prefix -> namespace pair to the map or update it.
- *
- * If the prefix already exists, it is quietly updated with the new value.
- *
- * @param[in] map The map to add to.
- *
- * @param[in] pfx The namespace prefix.
- *
- * @param[in] nsstr Fully qualified namespace.
- *
- * @return LSUP_OK if the record was added or replaced; LSUP_MEM_ERR if an
- * allocation error occurred.
- */
- LSUP_rc
- LSUP_nsmap_add (const char *pfx, const char *nsstr);
- /** @brief Remove a prefix -> namespace pair from a map.
- *
- * @param[in] map The map to remove from.
- *
- * @param[in] pfx The namespace prefix to remove.
- *
- * @return LSUP_OK on successful delete; LSUP_NOACTION if no record was found.
- */
- LSUP_rc
- LSUP_nsmap_remove (const char *pfx);
- /** @brief Get the namespace for a prefix.
- *
- * @param[in] map The map to look up the namespace in.
- *
- * @param[in] pfx The prefix to look up.
- *
- * @return A pointer to the namespace string. Note that this is not a copy and
- * should not be modified directly.
- */
- const char *
- LSUP_nsmap_get_ns (const char *pfx);
- /** @brief Get the prefix for a namespace.
- *
- * @param[in] map The map to look up the prefix in.
- *
- * @param[in] ns The namespace to look up.
- *
- * @return Found prefix, or NULL if the namespace is not mapped.
- */
- const char *
- LSUP_nsmap_get_pfx (const char *ns);
- /** @brief Convert a namespace-prefixed string to a FQ URI sring if mapped.
- *
- * @param[in] pfx_uri URI string to denormalize.
- *
- * @param[out] fq_uri String pointer to be filled with the FQ URI. The caller
- * is in charge of freeing the memory. If the namespace is not in the map or
- * an error occurred, this will be NULL. This is to inform the caller that the
- * result is not normalized and a TERM_NS_IRIREF should not be construed with
- * it.
- *
- * @return LSUP_OK on success, LSUP_NORESULT if no entry was found in the map,
- * LSUP_MEM_ERR if a memory allocation error ocurred.
- */
- LSUP_rc
- LSUP_nsmap_normalize_uri (const char *pfx_uri, char **fq_uri);
- /** @brief Convert a FQ URI string to a prefixed string if the prefix is found.
- *
- * @todo Note that this function does not attempt to find the longest or
- * shortest namespace prefix in case of conflicts (e.g. when both
- * `http://example.edu/` and `http://example.edu/data/` are mapped and
- * `http://example.edu/data/51937642` is being denormalized). In such
- * case, the first prefix that is found is assigned.
- *
- * @param[in] fq_uri URI string to normalize.
- *
- * @param[out] pfx_uri String pointer to be filled with the prefixed URI. The
- * caller is in charge of freeing the memory. If the namespace is not in the
- * map or an error occurred, this will be NULL. This is to inform the caller
- * that the result is not denormalized and a TERM_IRIREF should not be
- * construed with it.
- *
- * @return LSUP_OK on success, LSUP_NORESULT if no entry was found in the map,
- * LSUP_MEM_ERR if a memory allocation error ocurred.
- */
- LSUP_rc
- LSUP_nsmap_denormalize_uri (const char *fq_uri, char **pfx_uri);
- /** @brief Dump all entries of the namespace map.
- *
- * @param[in] map Map to dump.
- *
- * @return 2-dimensional array of strings, with as many rows as namespace
- * entries, and two columns: the first for the namespace prefix, the second
- * for the namespace. The last entry is NULL. Prefix and namespace strings
- * pointed to by the array are owned by the namespace map, but the individual
- * pointers must be freed along with the parent array. E.g.:
- *
- * const char ***nsm_data = LSUP_nsmap_dump (nsm);
- * // [...]
- * for (size_t i = 0; nsm_data[i] != NULL; i++)
- * free (nsm_data[i]);
- * free (nsm_data);
- */
- const char ***
- LSUP_nsmap_dump (void);
- /// @} END defgroup namespace
- #endif
|