aboutsummaryrefslogtreecommitdiffstats
path: root/serd/serd.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-03-08 15:57:20 +0000
committerDavid Robillard <d@drobilla.net>2012-03-08 15:57:20 +0000
commitf4365012b555699b916dbeec4d81425bf663579c (patch)
tree27807b4430269cdb279d32e9f734f119b8bb7191 /serd/serd.h
parent7b022006c47586dc00ed8bca85fcb0bdf5f9465d (diff)
downloadserd-f4365012b555699b916dbeec4d81425bf663579c.tar.gz
serd-f4365012b555699b916dbeec4d81425bf663579c.tar.bz2
serd-f4365012b555699b916dbeec4d81425bf663579c.zip
Add serd_writer_get_env().
Add serd_node_new_uri_from_path() and serd_file_uri_parse() and implement proper URI to/from path hex escaping, etc. Add serd_uri_serialise_relative() for making URIs relative to a base where possible (by chopping a common prefix and adding dot segments). Make URIs serialised by the writer properly escape characters. git-svn-id: http://svn.drobilla.net/serd/trunk@330 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'serd/serd.h')
-rw-r--r--serd/serd.h48
1 files changed, 46 insertions, 2 deletions
diff --git a/serd/serd.h b/serd/serd.h
index ba4e6fb5..3a2f9e3b 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -244,7 +244,7 @@ typedef enum {
SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */
SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */
SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */
- SERD_STYLE_BULK = 1 << 4, /**< Write output in pages. */
+ SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */
} SerdStyle;
/**
@@ -305,12 +305,29 @@ static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
/**
Return the local path for @c uri, or NULL if @c uri is not a file URI.
+ Note this (inappropriately named) function only removes the file scheme if
+ necessary, and returns @c uri unmodified if it is an absolute path. Percent
+ encoding and other issues are not handled, to properly convert a file URI to
+ a path, use serd_file_uri_parse().
*/
SERD_API
const uint8_t*
serd_uri_to_path(const uint8_t* uri);
/**
+ Get the unescaped path and hostname from a file URI.
+ @param uri A file URI.
+ @param hostname If non-NULL, set to the hostname, if present.
+ @return The path component of the URI.
+
+ Both the returned path and @c hostname (if applicable) are owned by the
+ caller and must be freed with free().
+*/
+SERD_API
+uint8_t*
+serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname);
+
+/**
Return true iff @c utf8 starts with a valid URI scheme.
*/
SERD_API
@@ -344,6 +361,16 @@ size_t
serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream);
/**
+ Serialise @c uri relative to @c base with a series of calls to @c sink.
+*/
+SERD_API
+size_t
+serd_uri_serialise_relative(const SerdURI* uri,
+ const SerdURI* base,
+ SerdSink sink,
+ void* stream);
+
+/**
@}
@name Node
@{
@@ -395,6 +422,17 @@ serd_node_new_uri_from_string(const uint8_t* str,
SerdURI* out);
/**
+ Create a new file URI node from a file system path.
+ If @c path is relative, @c hostname is ignored.
+ If @c out is not NULL, it will be set to the parsed URI.
+*/
+SERD_API
+SerdNode
+serd_node_new_uri_from_path(const uint8_t* path,
+ const uint8_t* hostname,
+ SerdURI* out);
+
+/**
Create a new node by serialising @c uri into a new string.
@param uri The URI to parse and serialise.
@@ -439,7 +477,6 @@ serd_node_new_integer(int64_t i);
This function can be used to make a serialisable node out of arbitrary
binary data, which can be decoded using serd_base64_decode().
-
@param buf Raw binary input data.
@param size Size of @c buf.
@param wrap_lines Wrap lines at 76 characters to conform to RFC 2045.
@@ -693,6 +730,13 @@ void
serd_writer_free(SerdWriter* writer);
/**
+ Return the env used by @c writer.
+*/
+SERD_API
+SerdEnv*
+serd_writer_get_env(SerdWriter* writer);
+
+/**
A convenience sink function for writing to a FILE*.
This function can be used as a SerdSink when writing to a FILE*. The