aboutsummaryrefslogtreecommitdiffstats
path: root/src/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/env.c b/src/env.c
index 7ea66623..02cd7d1e 100644
--- a/src/env.c
+++ b/src/env.c
@@ -14,6 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "env.h"
+
#include "node.h"
#include "serd/serd.h"
@@ -57,13 +59,15 @@ serd_env_free(SerdEnv* env)
free(env);
}
+const SerdURI*
+serd_env_get_parsed_base_uri(const SerdEnv* env)
+{
+ return &env->base_uri;
+}
+
const SerdNode*
-serd_env_get_base_uri(const SerdEnv* env,
- SerdURI* out)
+serd_env_get_base_uri(const SerdEnv* env)
{
- if (out) {
- *out = env->base_uri;
- }
return env->base_uri_node;
}
@@ -71,14 +75,16 @@ SerdStatus
serd_env_set_base_uri(SerdEnv* env,
const SerdNode* uri)
{
- if (!env || !uri) {
+ if (!env || !uri || uri->type != SERD_URI) {
return SERD_ERR_BAD_ARG;
}
// Resolve base URI and create a new node and URI for it
+ SerdNode* base_uri_node = serd_node_new_resolved_uri_i(
+ serd_node_get_string(uri), &env->base_uri);
+
SerdURI base_uri;
- SerdNode* base_uri_node = serd_node_new_uri_from_node(
- uri, &env->base_uri, &base_uri);
+ serd_uri_parse(serd_node_get_string(base_uri_node), &base_uri);
if (base_uri_node) {
// Replace the current base URI
@@ -137,13 +143,12 @@ serd_env_set_prefix(SerdEnv* env,
serd_env_add(env, name, uri);
} else {
// Resolve relative URI and create a new node and URI for it
- SerdURI abs_uri;
- SerdNode* abs_uri_node = serd_node_new_uri_from_node(
- uri, &env->base_uri, &abs_uri);
+ SerdNode* abs_uri = serd_node_new_resolved_uri_i(
+ serd_node_get_string(uri), &env->base_uri);
// Set prefix to resolved (absolute) URI
- serd_env_add(env, name, abs_uri_node);
- serd_node_free(abs_uri_node);
+ serd_env_add(env, name, abs_uri);
+ serd_node_free(abs_uri);
}
return SERD_SUCCESS;
}
@@ -153,8 +158,8 @@ serd_env_set_prefix_from_strings(SerdEnv* env,
const char* name,
const char* uri)
{
- SerdNode* name_node = serd_node_new_string(SERD_LITERAL, name);
- SerdNode* uri_node = serd_node_new_string(SERD_URI, uri);
+ SerdNode* name_node = serd_node_new_string(name);
+ SerdNode* uri_node = serd_node_new_uri(uri);
const SerdStatus st = serd_env_set_prefix(env, name_node, uri_node);
@@ -228,10 +233,9 @@ serd_env_expand_node(const SerdEnv* env,
ret->n_bytes = len;
return ret;
}
- case SERD_URI: {
- SerdURI ignored;
- return serd_node_new_uri_from_node(node, &env->base_uri, &ignored);
- }
+ case SERD_URI:
+ return serd_node_new_resolved_uri_i(
+ serd_node_get_string(node), &env->base_uri);
default:
return NULL;
}