|
@@ -142,15 +142,20 @@ LSUP_rc
|
|
LSUP_nsmap_normalize_uri (
|
|
LSUP_nsmap_normalize_uri (
|
|
const LSUP_NSMap *map, const char *pfx_uri, char **fq_uri_p)
|
|
const LSUP_NSMap *map, const char *pfx_uri, char **fq_uri_p)
|
|
{
|
|
{
|
|
- LSUP_rc rc;
|
|
|
|
|
|
+ LSUP_rc rc = LSUP_NORESULT;
|
|
char *fq_uri = NULL;
|
|
char *fq_uri = NULL;
|
|
|
|
|
|
|
|
+ if (UNLIKELY (!map)) {
|
|
|
|
+ log_warn ("No namespace map was passed for normalization.");
|
|
|
|
+ goto finally;
|
|
|
|
+ }
|
|
|
|
+
|
|
size_t pfx_len = strcspn (pfx_uri, ":");
|
|
size_t pfx_len = strcspn (pfx_uri, ":");
|
|
if (pfx_len >= PFX_LEN || pfx_len == strlen (pfx_uri)) {
|
|
if (pfx_len >= PFX_LEN || pfx_len == strlen (pfx_uri)) {
|
|
log_warn (
|
|
log_warn (
|
|
"No prefix separator detected in URI `%s` within maximum "
|
|
"No prefix separator detected in URI `%s` within maximum "
|
|
"prefix length (%d characters).", pfx_uri, PFX_LEN - 1);
|
|
"prefix length (%d characters).", pfx_uri, PFX_LEN - 1);
|
|
- goto no_prefix;
|
|
|
|
|
|
+ goto finally;
|
|
}
|
|
}
|
|
|
|
|
|
LSUP_ns_pfx pfx;
|
|
LSUP_ns_pfx pfx;
|
|
@@ -169,16 +174,9 @@ LSUP_nsmap_normalize_uri (
|
|
strcat (fq_uri, pfx_uri + pfx_len + 1);
|
|
strcat (fq_uri, pfx_uri + pfx_len + 1);
|
|
|
|
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
- } else {
|
|
|
|
- log_warn ("No NS prefix found in map to normalize %s", pfx_uri);
|
|
|
|
-
|
|
|
|
-no_prefix:
|
|
|
|
- fq_uri = malloc (strlen(pfx_uri) + 1);
|
|
|
|
- if (UNLIKELY (! (fq_uri))) return LSUP_MEM_ERR;
|
|
|
|
- strcpy (fq_uri, pfx_uri);
|
|
|
|
- rc = LSUP_NORESULT;
|
|
|
|
- }
|
|
|
|
|
|
+ } else log_warn ("No NS prefix found in map to normalize %s", pfx_uri);
|
|
|
|
|
|
|
|
+finally:
|
|
*fq_uri_p = fq_uri;
|
|
*fq_uri_p = fq_uri;
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
@@ -195,11 +193,17 @@ LSUP_nsmap_denormalize_uri (
|
|
* This function has to count the characters left over from the match in
|
|
* This function has to count the characters left over from the match in
|
|
* order to add the URI suffix.
|
|
* order to add the URI suffix.
|
|
*/
|
|
*/
|
|
- LSUP_rc rc;
|
|
|
|
|
|
+ LSUP_rc rc = LSUP_NORESULT;
|
|
const NSEntry *entry;
|
|
const NSEntry *entry;
|
|
const char *pfx = NULL;
|
|
const char *pfx = NULL;
|
|
- size_t i = 0, offset;
|
|
|
|
|
|
+ char *pfx_uri = NULL;
|
|
|
|
|
|
|
|
+ if (UNLIKELY (!map)) {
|
|
|
|
+ log_warn ("No namespace map was passed for denormalization.");
|
|
|
|
+ goto finally;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ size_t i = 0, offset;
|
|
while (hashmap_iter ((LSUP_NSMap *)map, &i, (void **) &entry)) {
|
|
while (hashmap_iter ((LSUP_NSMap *)map, &i, (void **) &entry)) {
|
|
offset = strlen (entry->ns);
|
|
offset = strlen (entry->ns);
|
|
if (strncmp (entry->ns, fq_uri, offset) == 0) {
|
|
if (strncmp (entry->ns, fq_uri, offset) == 0) {
|
|
@@ -207,8 +211,6 @@ LSUP_nsmap_denormalize_uri (
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- char *pfx_uri = NULL;
|
|
|
|
-
|
|
|
|
if (pfx) {
|
|
if (pfx) {
|
|
// +2: one for terminating \x00, one for the colon.
|
|
// +2: one for terminating \x00, one for the colon.
|
|
pfx_uri = malloc (strlen (pfx) + strlen (fq_uri) - offset + 2);
|
|
pfx_uri = malloc (strlen (pfx) + strlen (fq_uri) - offset + 2);
|
|
@@ -217,12 +219,9 @@ LSUP_nsmap_denormalize_uri (
|
|
sprintf (pfx_uri, "%s:%s", pfx, fq_uri + offset);
|
|
sprintf (pfx_uri, "%s:%s", pfx, fq_uri + offset);
|
|
|
|
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
|
|
+ } else log_warn ("No NS prefix found in map to denormalize %s", fq_uri);
|
|
|
|
|
|
- } else {
|
|
|
|
- pfx_uri = strdup (fq_uri);
|
|
|
|
- rc = LSUP_NORESULT;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+finally:
|
|
*pfx_uri_p = pfx_uri;
|
|
*pfx_uri_p = pfx_uri;
|
|
|
|
|
|
return rc;
|
|
return rc;
|