13static bool nsmap_dump_ns_iter_fn (
const void *item,
void *udata)
19 cur->
data[cur->
i][0] = (
const char *)entry->
pfx;
20 cur->
data[cur->
i++][1] = (
const char *)entry->
ns;
48 "Prefix `%s` is longer than the maximum allowed size "
49 "(%d characters). Truncating.", pfx,
PFX_LEN - 1);
54 if (!ret)
LOG_DEBUG(
"Adding prefix '%s' to NS map.", entry_s.
pfx);
57 "Replacing NS '%s' with '%s' for prefix '%s'.",
58 ret->
ns, entry_s.
ns, entry_s.
pfx);
91 return (entry) ? entry->
ns : NULL;
101 if (strncmp (entry->
ns, ns, strlen (ns)) == 0)
113 log_error (
"Prefixed URI cannot be NULL.");
119 size_t pfx_len = strcspn (pfx_uri,
":");
120 if (pfx_len >=
PFX_LEN || pfx_len == strlen (pfx_uri)) {
122 "No prefix separator detected in URI `%s` within maximum "
123 "prefix length (%d characters).", pfx_uri,
PFX_LEN - 1);
128 strncpy (pfx, pfx_uri, pfx_len);
135 size_t fq_size = strlen (ns) + strlen (pfx_uri) - pfx_len;
136 fq_uri = malloc (fq_size);
140 strcat (fq_uri, pfx_uri + pfx_len + 1);
143 }
else log_warn (
"No NS prefix found in map to normalize %s", pfx_uri);
163 const char *pfx = NULL;
164 char *pfx_uri = NULL;
166 size_t i = 0, offset;
168 offset = strlen (entry->
ns);
169 if (strncmp (entry->
ns, fq_uri, offset) == 0) {
176 pfx_uri = malloc (strlen (pfx) + strlen (fq_uri) - offset + 2);
179 sprintf (pfx_uri,
"%s:%s", pfx, fq_uri + offset);
182 }
else log_warn (
"No NS prefix found in map to denormalize %s", fq_uri);
184 *pfx_uri_p = pfx_uri;
195 const char ***data = malloc (2 * (i + 1) *
sizeof (
char *));
198 for (
size_t j = 0; j < i; j++) {
199 data[j] = malloc (2 *
sizeof (
char *));
200 if (
UNLIKELY (!data[j]))
return NULL;
VOLK_rc VOLK_nsmap_remove(const char *pfx)
Remove a prefix -> namespace pair from a map.
const char * VOLK_nsmap_get_pfx(const char *ns)
Get the prefix for a namespace.
struct hashmap * VOLK_default_nsm
Default namespace prefix map.
VOLK_rc VOLK_nsmap_normalize_uri(const char *pfx_uri, char **fq_uri_p)
Convert a namespace-prefixed string to a FQ URI sring if mapped.
const char * VOLK_nsmap_get_ns(const char *pfx)
Get the namespace for a prefix.
const char *** VOLK_nsmap_dump(void)
Dump all entries of the namespace map.
VOLK_rc VOLK_nsmap_denormalize_uri(const char *fq_uri, char **pfx_uri_p)
Convert a FQ URI string to a prefixed string if the prefix is found.
VOLK_rc VOLK_nsmap_add(const char *pfx, const char *nsstr)
Add a prefix -> namespace pair to the map or update it.
char VOLK_ns_pfx[PFX_LEN]
Namespace prefix type.
#define PFX_LEN
Namespace prefix length, including terminator.
char * strdup(const char *src)
Replacement for GNU strdup.
#define VOLK_VALUE_ERR
An invalid input value was provided.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_NORESULT
No result yielded.
#define VOLK_OK
Generic success return code.
#define VOLK_NOACTION
No action taken.
Iterator for dumping NS map.