|
@@ -141,35 +141,43 @@ LSUP_nsmap_get (const NSMap *map, const ns_pfx pfx)
|
|
|
|
|
|
LSUP_rc
|
|
|
LSUP_nsmap_normalize_uri (
|
|
|
- const NSMap *map, const char *uri, char **pfx_uri)
|
|
|
+ const NSMap *map, const char *fq_uri, char **pfx_uri_p)
|
|
|
{
|
|
|
- *pfx_uri = NULL;
|
|
|
+ char *pfx_uri = NULL;
|
|
|
|
|
|
NSIndex *entry;
|
|
|
- HASH_FIND_STR (map->np, uri, entry);
|
|
|
+ HASH_FIND_STR (map->np, fq_uri, entry);
|
|
|
+ for (entry = map->np; entry != NULL; entry = entry->hh.next) {
|
|
|
+ if (memcmp (entry->ns->ns, fq_uri, strlen (entry->ns->ns)) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
if (entry) {
|
|
|
- *pfx_uri = malloc (
|
|
|
+ pfx_uri = malloc (
|
|
|
strlen (entry->ns->pfx)
|
|
|
- + strlen (uri) - strlen (entry->ns->ns)
|
|
|
+ + strlen (fq_uri) - strlen (entry->ns->ns)
|
|
|
+ 2);
|
|
|
- if (UNLIKELY (! (*pfx_uri))) return LSUP_MEM_ERR;
|
|
|
+ if (UNLIKELY (! (pfx_uri))) return LSUP_MEM_ERR;
|
|
|
|
|
|
sprintf (
|
|
|
- *pfx_uri, "%s:%s",
|
|
|
- entry->ns->pfx, uri + strlen (entry->ns->ns));
|
|
|
+ pfx_uri, "%s:%s",
|
|
|
+ entry->ns->pfx, fq_uri + strlen (entry->ns->ns));
|
|
|
|
|
|
- return LSUP_OK;
|
|
|
+ }
|
|
|
|
|
|
- } else return LSUP_NORESULT;
|
|
|
+ else pfx_uri = strdup (fq_uri);
|
|
|
+
|
|
|
+ *pfx_uri_p = pfx_uri;
|
|
|
+
|
|
|
+ return LSUP_OK;
|
|
|
}
|
|
|
|
|
|
|
|
|
LSUP_rc
|
|
|
LSUP_nsmap_denormalize_uri (
|
|
|
- const NSMap *map, const char *pfx_uri, char **uri)
|
|
|
+ const NSMap *map, const char *pfx_uri, char **fq_uri_p)
|
|
|
{
|
|
|
- *uri = NULL;
|
|
|
+ char *fq_uri = NULL;
|
|
|
|
|
|
size_t pfx_len = strcspn (pfx_uri, ":");
|
|
|
if (pfx_len >= PFX_LEN) pfx_len = PFX_LEN - 1;
|
|
@@ -179,12 +187,23 @@ LSUP_nsmap_denormalize_uri (
|
|
|
pfx[pfx_len] = 0;
|
|
|
|
|
|
Namespace *entry;
|
|
|
- HASH_FIND_STR (map->pn, pfx, entry);
|
|
|
+ for (entry = map->pn; entry != NULL; entry = entry->hh.next) {
|
|
|
+ if (strncmp (entry->pfx, pfx_uri, strlen (entry->pfx)) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (entry) {
|
|
|
+ size_t fq_size = strlen (entry->ns) + strlen (pfx_uri) - pfx_len - 1;
|
|
|
+ fq_uri = malloc (fq_size);
|
|
|
+ if (UNLIKELY (! (fq_uri))) return LSUP_MEM_ERR;
|
|
|
+
|
|
|
+ strcpy (fq_uri, entry->ns);
|
|
|
+ strcat (fq_uri, pfx_uri + pfx_len + 1);
|
|
|
+ }
|
|
|
|
|
|
- if (entry)
|
|
|
- *uri = malloc (strlen (entry->ns) + strlen (pfx_uri) - pfx_len - 1);
|
|
|
+ else fq_uri = strdup (pfx_uri);
|
|
|
|
|
|
- else *uri = strdup (pfx_uri);
|
|
|
+ *fq_uri_p = fq_uri;
|
|
|
|
|
|
return LSUP_OK;
|
|
|
}
|