annotate osx/include/serd/serd.h @ 116:e448888319fc

PortAudio on OS/X
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 09 Jan 2014 21:33:28 +0000
parents 1609fb751561
children
rev   line source
cannam@115 1 /*
cannam@115 2 Copyright 2011-2012 David Robillard <http://drobilla.net>
cannam@115 3
cannam@115 4 Permission to use, copy, modify, and/or distribute this software for any
cannam@115 5 purpose with or without fee is hereby granted, provided that the above
cannam@115 6 copyright notice and this permission notice appear in all copies.
cannam@115 7
cannam@115 8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
cannam@115 9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
cannam@115 10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
cannam@115 11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
cannam@115 12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
cannam@115 13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
cannam@115 14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cannam@115 15 */
cannam@115 16
cannam@115 17 /**
cannam@115 18 @file serd.h API for Serd, a lightweight RDF syntax library.
cannam@115 19 */
cannam@115 20
cannam@115 21 #ifndef SERD_SERD_H
cannam@115 22 #define SERD_SERD_H
cannam@115 23
cannam@115 24 #include <stdarg.h>
cannam@115 25 #include <stddef.h>
cannam@115 26 #include <stdint.h>
cannam@115 27 #include <stdio.h>
cannam@115 28
cannam@115 29 #ifdef SERD_SHARED
cannam@115 30 # ifdef _WIN32
cannam@115 31 # define SERD_LIB_IMPORT __declspec(dllimport)
cannam@115 32 # define SERD_LIB_EXPORT __declspec(dllexport)
cannam@115 33 # else
cannam@115 34 # define SERD_LIB_IMPORT __attribute__((visibility("default")))
cannam@115 35 # define SERD_LIB_EXPORT __attribute__((visibility("default")))
cannam@115 36 # endif
cannam@115 37 # ifdef SERD_INTERNAL
cannam@115 38 # define SERD_API SERD_LIB_EXPORT
cannam@115 39 # else
cannam@115 40 # define SERD_API SERD_LIB_IMPORT
cannam@115 41 # endif
cannam@115 42 #else
cannam@115 43 # define SERD_API
cannam@115 44 #endif
cannam@115 45
cannam@115 46 #ifdef __cplusplus
cannam@115 47 extern "C" {
cannam@115 48 #else
cannam@115 49 # include <stdbool.h>
cannam@115 50 #endif
cannam@115 51
cannam@115 52 /**
cannam@115 53 @defgroup serd Serd
cannam@115 54 A lightweight RDF syntax library.
cannam@115 55 @{
cannam@115 56 */
cannam@115 57
cannam@115 58 /**
cannam@115 59 Environment.
cannam@115 60
cannam@115 61 Represents the state required to resolve a CURIE or relative URI, e.g. the
cannam@115 62 base URI and set of namespace prefixes at a particular point.
cannam@115 63 */
cannam@115 64 typedef struct SerdEnvImpl SerdEnv;
cannam@115 65
cannam@115 66 /**
cannam@115 67 RDF reader.
cannam@115 68
cannam@115 69 Parses RDF by calling user-provided sink functions as input is consumed
cannam@115 70 (much like an XML SAX parser).
cannam@115 71 */
cannam@115 72 typedef struct SerdReaderImpl SerdReader;
cannam@115 73
cannam@115 74 /**
cannam@115 75 RDF writer.
cannam@115 76
cannam@115 77 Provides a number of functions to allow writing RDF syntax out to some
cannam@115 78 stream. These functions are deliberately compatible with the sink functions
cannam@115 79 used by SerdReader, so a reader can be directly connected to a writer to
cannam@115 80 re-serialise a document with minimal overhead.
cannam@115 81 */
cannam@115 82 typedef struct SerdWriterImpl SerdWriter;
cannam@115 83
cannam@115 84 /**
cannam@115 85 Return status code.
cannam@115 86 */
cannam@115 87 typedef enum {
cannam@115 88 SERD_SUCCESS, /**< No error */
cannam@115 89 SERD_FAILURE, /**< Non-fatal failure */
cannam@115 90 SERD_ERR_UNKNOWN, /**< Unknown error */
cannam@115 91 SERD_ERR_BAD_SYNTAX, /**< Invalid syntax */
cannam@115 92 SERD_ERR_BAD_ARG, /**< Invalid argument */
cannam@115 93 SERD_ERR_NOT_FOUND, /**< Not found */
cannam@115 94 SERD_ERR_ID_CLASH, /**< Encountered clashing blank node IDs */
cannam@115 95 SERD_ERR_BAD_CURIE, /**< Invalid CURIE (e.g. prefix does not exist) */
cannam@115 96 SERD_ERR_INTERNAL /**< Unexpected internal error (should not happen) */
cannam@115 97 } SerdStatus;
cannam@115 98
cannam@115 99 /**
cannam@115 100 RDF syntax type.
cannam@115 101 */
cannam@115 102 typedef enum {
cannam@115 103 /**
cannam@115 104 Turtle - Terse RDF Triple Language (UTF-8).
cannam@115 105 @see <a href="http://www.w3.org/TeamSubmission/turtle/">Turtle</a>
cannam@115 106 */
cannam@115 107 SERD_TURTLE = 1,
cannam@115 108
cannam@115 109 /**
cannam@115 110 NTriples - Line-based RDF triples (ASCII).
cannam@115 111 @see <a href="http://www.w3.org/TR/rdf-testcases#ntriples">NTriples</a>
cannam@115 112 */
cannam@115 113 SERD_NTRIPLES = 2
cannam@115 114 } SerdSyntax;
cannam@115 115
cannam@115 116 /**
cannam@115 117 Flags indication inline abbreviation information for a statement.
cannam@115 118 */
cannam@115 119 typedef enum {
cannam@115 120 SERD_EMPTY_S = 1 << 1, /**< Empty blank node subject */
cannam@115 121 SERD_EMPTY_O = 1 << 2, /**< Empty blank node object */
cannam@115 122 SERD_ANON_S_BEGIN = 1 << 3, /**< Start of anonymous subject */
cannam@115 123 SERD_ANON_O_BEGIN = 1 << 4, /**< Start of anonymous object */
cannam@115 124 SERD_ANON_CONT = 1 << 5, /**< Continuation of anonymous node */
cannam@115 125 SERD_LIST_S_BEGIN = 1 << 6, /**< Start of list subject */
cannam@115 126 SERD_LIST_O_BEGIN = 1 << 7, /**< Start of list object */
cannam@115 127 SERD_LIST_CONT = 1 << 8 /**< Continuation of list */
cannam@115 128 } SerdStatementFlag;
cannam@115 129
cannam@115 130 /**
cannam@115 131 Bitwise OR of SerdNodeFlag values.
cannam@115 132 */
cannam@115 133 typedef uint32_t SerdStatementFlags;
cannam@115 134
cannam@115 135 /**
cannam@115 136 Type of a syntactic RDF node.
cannam@115 137
cannam@115 138 This is more precise than the type of an abstract RDF node. An abstract
cannam@115 139 node is either a resource, literal, or blank. In syntax there are two ways
cannam@115 140 to refer to a resource (by URI or CURIE) and two ways to refer to a blank
cannam@115 141 (by ID or anonymously). Anonymous (inline) blank nodes are expressed using
cannam@115 142 SerdStatementFlags rather than this type.
cannam@115 143 */
cannam@115 144 typedef enum {
cannam@115 145 /**
cannam@115 146 The type of a nonexistent node.
cannam@115 147
cannam@115 148 This type is useful as a sentinel, but is never emitted by the reader.
cannam@115 149 */
cannam@115 150 SERD_NOTHING = 0,
cannam@115 151
cannam@115 152 /**
cannam@115 153 Literal value.
cannam@115 154
cannam@115 155 A literal optionally has either a language, or a datatype (not both).
cannam@115 156 */
cannam@115 157 SERD_LITERAL = 1,
cannam@115 158
cannam@115 159 /**
cannam@115 160 URI (absolute or relative).
cannam@115 161
cannam@115 162 Value is an unquoted URI string, which is either a relative reference
cannam@115 163 with respect to the current base URI (e.g. "foo/bar"), or an absolute
cannam@115 164 URI (e.g. "http://example.org/foo").
cannam@115 165 @see <a href="http://tools.ietf.org/html/rfc3986">RFC3986</a>.
cannam@115 166 */
cannam@115 167 SERD_URI = 2,
cannam@115 168
cannam@115 169 /**
cannam@115 170 CURIE, a shortened URI.
cannam@115 171
cannam@115 172 Value is an unquoted CURIE string relative to the current environment,
cannam@115 173 e.g. "rdf:type".
cannam@115 174 @see <a href="http://www.w3.org/TR/curie">CURIE Syntax 1.0</a>
cannam@115 175 */
cannam@115 176 SERD_CURIE = 3,
cannam@115 177
cannam@115 178 /**
cannam@115 179 A blank node.
cannam@115 180
cannam@115 181 Value is a blank node ID, e.g. "id3", which is meaningful only within
cannam@115 182 this serialisation.
cannam@115 183 @see <a href="http://www.w3.org/TeamSubmission/turtle#nodeID">Turtle
cannam@115 184 <tt>nodeID</tt></a>
cannam@115 185 */
cannam@115 186 SERD_BLANK = 4,
cannam@115 187
cannam@115 188 } SerdType;
cannam@115 189
cannam@115 190 /**
cannam@115 191 Flags indicating certain string properties relevant to serialisation.
cannam@115 192 */
cannam@115 193 typedef enum {
cannam@115 194 SERD_HAS_NEWLINE = 1, /**< Contains line breaks ('\\n' or '\\r') */
cannam@115 195 SERD_HAS_QUOTE = 1 << 1 /**< Contains quotes ('"') */
cannam@115 196 } SerdNodeFlag;
cannam@115 197
cannam@115 198 /**
cannam@115 199 Bitwise OR of SerdNodeFlag values.
cannam@115 200 */
cannam@115 201 typedef uint32_t SerdNodeFlags;
cannam@115 202
cannam@115 203 /**
cannam@115 204 A syntactic RDF node.
cannam@115 205 */
cannam@115 206 typedef struct {
cannam@115 207 const uint8_t* buf; /**< Value string */
cannam@115 208 size_t n_bytes; /**< Size in bytes (not including null) */
cannam@115 209 size_t n_chars; /**< Length in characters (not including null)*/
cannam@115 210 SerdNodeFlags flags; /**< Node flags (e.g. string properties) */
cannam@115 211 SerdType type; /**< Node type */
cannam@115 212 } SerdNode;
cannam@115 213
cannam@115 214 /**
cannam@115 215 An unterminated string fragment.
cannam@115 216 */
cannam@115 217 typedef struct {
cannam@115 218 const uint8_t* buf; /**< Start of chunk */
cannam@115 219 size_t len; /**< Length of chunk in bytes */
cannam@115 220 } SerdChunk;
cannam@115 221
cannam@115 222 /**
cannam@115 223 An error description.
cannam@115 224 */
cannam@115 225 typedef struct {
cannam@115 226 SerdStatus status; /**< Error code */
cannam@115 227 const uint8_t* filename; /**< File where error was encountered, or NULL */
cannam@115 228 unsigned line; /**< Line where error was encountered, or 0 */
cannam@115 229 unsigned col; /**< Column where error was encountered */
cannam@115 230 const char* fmt; /**< Message format string (printf style) */
cannam@115 231 va_list* args; /**< Arguments for fmt */
cannam@115 232 } SerdError;
cannam@115 233
cannam@115 234 /**
cannam@115 235 A parsed URI.
cannam@115 236
cannam@115 237 This struct directly refers to chunks in other strings, it does not own any
cannam@115 238 memory itself. Thus, URIs can be parsed and/or resolved against a base URI
cannam@115 239 in-place without allocating memory.
cannam@115 240 */
cannam@115 241 typedef struct {
cannam@115 242 SerdChunk scheme; /**< Scheme */
cannam@115 243 SerdChunk authority; /**< Authority */
cannam@115 244 SerdChunk path_base; /**< Path prefix if relative */
cannam@115 245 SerdChunk path; /**< Path suffix */
cannam@115 246 SerdChunk query; /**< Query */
cannam@115 247 SerdChunk fragment; /**< Fragment */
cannam@115 248 } SerdURI;
cannam@115 249
cannam@115 250 /**
cannam@115 251 Syntax style options.
cannam@115 252
cannam@115 253 The style of the writer output can be controlled by ORing together
cannam@115 254 values from this enumeration. Note that some options are only supported
cannam@115 255 for some syntaxes (e.g. NTriples does not support abbreviation and is
cannam@115 256 always ASCII).
cannam@115 257 */
cannam@115 258 typedef enum {
cannam@115 259 SERD_STYLE_ABBREVIATED = 1, /**< Abbreviate triples when possible. */
cannam@115 260 SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */
cannam@115 261 SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */
cannam@115 262 SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */
cannam@115 263 SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */
cannam@115 264 } SerdStyle;
cannam@115 265
cannam@115 266 /**
cannam@115 267 @name String Utilities
cannam@115 268 @{
cannam@115 269 */
cannam@115 270
cannam@115 271 /**
cannam@115 272 Return a string describing a status code.
cannam@115 273 */
cannam@115 274 SERD_API
cannam@115 275 const uint8_t*
cannam@115 276 serd_strerror(SerdStatus status);
cannam@115 277
cannam@115 278 /**
cannam@115 279 Measure a UTF-8 string.
cannam@115 280 @return Length of @c str in characters (except NULL).
cannam@115 281 @param str A null-terminated UTF-8 string.
cannam@115 282 @param n_bytes (Output) Set to the size of @c str in bytes (except NULL).
cannam@115 283 @param flags (Output) Set to the applicable flags.
cannam@115 284 */
cannam@115 285 SERD_API
cannam@115 286 size_t
cannam@115 287 serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags);
cannam@115 288
cannam@115 289 /**
cannam@115 290 Parse a string to a double.
cannam@115 291
cannam@115 292 The API of this function is identical to the standard C strtod function,
cannam@115 293 except this function is locale-independent and always matches the lexical
cannam@115 294 format used in the Turtle grammar (the decimal point is always ".").
cannam@115 295 */
cannam@115 296 SERD_API
cannam@115 297 double
cannam@115 298 serd_strtod(const char* str, char** endptr);
cannam@115 299
cannam@115 300 /**
cannam@115 301 Decode a base64 string.
cannam@115 302 This function can be used to deserialise a blob node created with
cannam@115 303 serd_node_new_blob().
cannam@115 304
cannam@115 305 @param str Base64 string to decode.
cannam@115 306 @param len The length of @c str.
cannam@115 307 @param size Set to the size of the returned blob in bytes.
cannam@115 308 @return A newly allocated blob which must be freed with free().
cannam@115 309 */
cannam@115 310 SERD_API
cannam@115 311 void*
cannam@115 312 serd_base64_decode(const uint8_t* str, size_t len, size_t* size);
cannam@115 313
cannam@115 314 /**
cannam@115 315 @}
cannam@115 316 @name URI
cannam@115 317 @{
cannam@115 318 */
cannam@115 319
cannam@115 320 static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
cannam@115 321
cannam@115 322 /**
cannam@115 323 Return the local path for @c uri, or NULL if @c uri is not a file URI.
cannam@115 324 Note this (inappropriately named) function only removes the file scheme if
cannam@115 325 necessary, and returns @c uri unmodified if it is an absolute path. Percent
cannam@115 326 encoding and other issues are not handled, to properly convert a file URI to
cannam@115 327 a path, use serd_file_uri_parse().
cannam@115 328 */
cannam@115 329 SERD_API
cannam@115 330 const uint8_t*
cannam@115 331 serd_uri_to_path(const uint8_t* uri);
cannam@115 332
cannam@115 333 /**
cannam@115 334 Get the unescaped path and hostname from a file URI.
cannam@115 335 @param uri A file URI.
cannam@115 336 @param hostname If non-NULL, set to the hostname, if present.
cannam@115 337 @return The path component of the URI.
cannam@115 338
cannam@115 339 Both the returned path and @c hostname (if applicable) are owned by the
cannam@115 340 caller and must be freed with free().
cannam@115 341 */
cannam@115 342 SERD_API
cannam@115 343 uint8_t*
cannam@115 344 serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname);
cannam@115 345
cannam@115 346 /**
cannam@115 347 Return true iff @c utf8 starts with a valid URI scheme.
cannam@115 348 */
cannam@115 349 SERD_API
cannam@115 350 bool
cannam@115 351 serd_uri_string_has_scheme(const uint8_t* utf8);
cannam@115 352
cannam@115 353 /**
cannam@115 354 Parse @c utf8, writing result to @c out.
cannam@115 355 */
cannam@115 356 SERD_API
cannam@115 357 SerdStatus
cannam@115 358 serd_uri_parse(const uint8_t* utf8, SerdURI* out);
cannam@115 359
cannam@115 360 /**
cannam@115 361 Set @c out to @c uri resolved against @c base.
cannam@115 362 */
cannam@115 363 SERD_API
cannam@115 364 void
cannam@115 365 serd_uri_resolve(const SerdURI* uri, const SerdURI* base, SerdURI* out);
cannam@115 366
cannam@115 367 /**
cannam@115 368 Sink function for raw string output.
cannam@115 369 */
cannam@115 370 typedef size_t (*SerdSink)(const void* buf, size_t len, void* stream);
cannam@115 371
cannam@115 372 /**
cannam@115 373 Serialise @c uri with a series of calls to @c sink.
cannam@115 374 */
cannam@115 375 SERD_API
cannam@115 376 size_t
cannam@115 377 serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream);
cannam@115 378
cannam@115 379 /**
cannam@115 380 Serialise @c uri relative to @c base with a series of calls to @c sink.
cannam@115 381
cannam@115 382 The @c uri is written as a relative URI iff if it a child of @c base and @c
cannam@115 383 root. The optional @c root parameter must be a prefix of @c base and can be
cannam@115 384 used keep up-references ("../") within a certain namespace.
cannam@115 385 */
cannam@115 386 SERD_API
cannam@115 387 size_t
cannam@115 388 serd_uri_serialise_relative(const SerdURI* uri,
cannam@115 389 const SerdURI* base,
cannam@115 390 const SerdURI* root,
cannam@115 391 SerdSink sink,
cannam@115 392 void* stream);
cannam@115 393
cannam@115 394 /**
cannam@115 395 @}
cannam@115 396 @name Node
cannam@115 397 @{
cannam@115 398 */
cannam@115 399
cannam@115 400 static const SerdNode SERD_NODE_NULL = { 0, 0, 0, 0, SERD_NOTHING };
cannam@115 401
cannam@115 402 /**
cannam@115 403 Make a (shallow) node from @c str.
cannam@115 404
cannam@115 405 This measures, but does not copy, @c str. No memory is allocated.
cannam@115 406 */
cannam@115 407 SERD_API
cannam@115 408 SerdNode
cannam@115 409 serd_node_from_string(SerdType type, const uint8_t* str);
cannam@115 410
cannam@115 411 /**
cannam@115 412 Make a deep copy of @c node.
cannam@115 413
cannam@115 414 @return a node that the caller must free with @ref serd_node_free.
cannam@115 415 */
cannam@115 416 SERD_API
cannam@115 417 SerdNode
cannam@115 418 serd_node_copy(const SerdNode* node);
cannam@115 419
cannam@115 420 /**
cannam@115 421 Return true iff @c a is equal to @c b.
cannam@115 422 */
cannam@115 423 SERD_API
cannam@115 424 bool
cannam@115 425 serd_node_equals(const SerdNode* a, const SerdNode* b);
cannam@115 426
cannam@115 427 /**
cannam@115 428 Simple wrapper for serd_node_new_uri to resolve a URI node.
cannam@115 429 */
cannam@115 430 SERD_API
cannam@115 431 SerdNode
cannam@115 432 serd_node_new_uri_from_node(const SerdNode* uri_node,
cannam@115 433 const SerdURI* base,
cannam@115 434 SerdURI* out);
cannam@115 435
cannam@115 436 /**
cannam@115 437 Simple wrapper for serd_node_new_uri to resolve a URI string.
cannam@115 438 */
cannam@115 439 SERD_API
cannam@115 440 SerdNode
cannam@115 441 serd_node_new_uri_from_string(const uint8_t* str,
cannam@115 442 const SerdURI* base,
cannam@115 443 SerdURI* out);
cannam@115 444
cannam@115 445 /**
cannam@115 446 Create a new file URI node from a file system path and optional hostname.
cannam@115 447
cannam@115 448 Backslashes in Windows paths will be converted and '%' will always be
cannam@115 449 percent encoded. If @c escape is true, all other invalid characters will be
cannam@115 450 percent encoded as well.
cannam@115 451
cannam@115 452 If @c path is relative, @c hostname is ignored.
cannam@115 453 If @c out is not NULL, it will be set to the parsed URI.
cannam@115 454 */
cannam@115 455 SERD_API
cannam@115 456 SerdNode
cannam@115 457 serd_node_new_file_uri(const uint8_t* path,
cannam@115 458 const uint8_t* hostname,
cannam@115 459 SerdURI* out,
cannam@115 460 bool escape);
cannam@115 461
cannam@115 462 /**
cannam@115 463 Create a new node by serialising @c uri into a new string.
cannam@115 464
cannam@115 465 @param uri The URI to parse and serialise.
cannam@115 466
cannam@115 467 @param base Base URI to resolve @c uri against (or NULL for no resolution).
cannam@115 468
cannam@115 469 @param out Set to the parsing of the new URI (i.e. points only to
cannam@115 470 memory owned by the new returned node).
cannam@115 471 */
cannam@115 472 SERD_API
cannam@115 473 SerdNode
cannam@115 474 serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out);
cannam@115 475
cannam@115 476 /**
cannam@115 477 Create a new node by serialising @c d into an xsd:decimal string.
cannam@115 478
cannam@115 479 The resulting node will always contain a `.', start with a digit, and end
cannam@115 480 with a digit (i.e. will have a leading and/or trailing `0' if necessary).
cannam@115 481 It will never be in scientific notation. A maximum of @c frac_digits digits
cannam@115 482 will be written after the decimal point, but trailing zeros will
cannam@115 483 automatically be omitted (except one if @c d is a round integer).
cannam@115 484
cannam@115 485 Note that about 16 and 8 fractional digits are required to precisely
cannam@115 486 represent a double and float, respectively.
cannam@115 487
cannam@115 488 @param d The value for the new node.
cannam@115 489 @param frac_digits The maximum number of digits after the decimal place.
cannam@115 490 */
cannam@115 491 SERD_API
cannam@115 492 SerdNode
cannam@115 493 serd_node_new_decimal(double d, unsigned frac_digits);
cannam@115 494
cannam@115 495 /**
cannam@115 496 Create a new node by serialising @c i into an xsd:integer string.
cannam@115 497 */
cannam@115 498 SERD_API
cannam@115 499 SerdNode
cannam@115 500 serd_node_new_integer(int64_t i);
cannam@115 501
cannam@115 502 /**
cannam@115 503 Create a node by serialising @c buf into an xsd:base64Binary string.
cannam@115 504 This function can be used to make a serialisable node out of arbitrary
cannam@115 505 binary data, which can be decoded using serd_base64_decode().
cannam@115 506
cannam@115 507 @param buf Raw binary input data.
cannam@115 508 @param size Size of @c buf.
cannam@115 509 @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045.
cannam@115 510 */
cannam@115 511 SERD_API
cannam@115 512 SerdNode
cannam@115 513 serd_node_new_blob(const void* buf, size_t size, bool wrap_lines);
cannam@115 514
cannam@115 515 /**
cannam@115 516 Free any data owned by @c node.
cannam@115 517
cannam@115 518 Note that if @c node is itself dynamically allocated (which is not the case
cannam@115 519 for nodes created internally by serd), it will not be freed.
cannam@115 520 */
cannam@115 521 SERD_API
cannam@115 522 void
cannam@115 523 serd_node_free(SerdNode* node);
cannam@115 524
cannam@115 525 /**
cannam@115 526 @}
cannam@115 527 @name Event Handlers
cannam@115 528 @{
cannam@115 529 */
cannam@115 530
cannam@115 531 /**
cannam@115 532 Sink (callback) for errors.
cannam@115 533
cannam@115 534 @param handle Handle for user data.
cannam@115 535 @param error Error description.
cannam@115 536 */
cannam@115 537 typedef SerdStatus (*SerdErrorSink)(void* handle,
cannam@115 538 const SerdError* error);
cannam@115 539
cannam@115 540 /**
cannam@115 541 Sink (callback) for base URI changes.
cannam@115 542
cannam@115 543 Called whenever the base URI of the serialisation changes.
cannam@115 544 */
cannam@115 545 typedef SerdStatus (*SerdBaseSink)(void* handle,
cannam@115 546 const SerdNode* uri);
cannam@115 547
cannam@115 548 /**
cannam@115 549 Sink (callback) for namespace definitions.
cannam@115 550
cannam@115 551 Called whenever a prefix is defined in the serialisation.
cannam@115 552 */
cannam@115 553 typedef SerdStatus (*SerdPrefixSink)(void* handle,
cannam@115 554 const SerdNode* name,
cannam@115 555 const SerdNode* uri);
cannam@115 556
cannam@115 557 /**
cannam@115 558 Sink (callback) for statements.
cannam@115 559
cannam@115 560 Called for every RDF statement in the serialisation.
cannam@115 561 */
cannam@115 562 typedef SerdStatus (*SerdStatementSink)(void* handle,
cannam@115 563 SerdStatementFlags flags,
cannam@115 564 const SerdNode* graph,
cannam@115 565 const SerdNode* subject,
cannam@115 566 const SerdNode* predicate,
cannam@115 567 const SerdNode* object,
cannam@115 568 const SerdNode* object_datatype,
cannam@115 569 const SerdNode* object_lang);
cannam@115 570
cannam@115 571 /**
cannam@115 572 Sink (callback) for anonymous node end markers.
cannam@115 573
cannam@115 574 This is called to indicate that the anonymous node with the given
cannam@115 575 @c value will no longer be referred to by any future statements
cannam@115 576 (i.e. the anonymous serialisation of the node is finished).
cannam@115 577 */
cannam@115 578 typedef SerdStatus (*SerdEndSink)(void* handle,
cannam@115 579 const SerdNode* node);
cannam@115 580
cannam@115 581 /**
cannam@115 582 @}
cannam@115 583 @name Environment
cannam@115 584 @{
cannam@115 585 */
cannam@115 586
cannam@115 587 /**
cannam@115 588 Create a new environment.
cannam@115 589 */
cannam@115 590 SERD_API
cannam@115 591 SerdEnv*
cannam@115 592 serd_env_new(const SerdNode* base_uri);
cannam@115 593
cannam@115 594 /**
cannam@115 595 Free @c ns.
cannam@115 596 */
cannam@115 597 SERD_API
cannam@115 598 void
cannam@115 599 serd_env_free(SerdEnv* env);
cannam@115 600
cannam@115 601 /**
cannam@115 602 Get the current base URI.
cannam@115 603 */
cannam@115 604 SERD_API
cannam@115 605 const SerdNode*
cannam@115 606 serd_env_get_base_uri(const SerdEnv* env,
cannam@115 607 SerdURI* out);
cannam@115 608
cannam@115 609 /**
cannam@115 610 Set the current base URI.
cannam@115 611 */
cannam@115 612 SERD_API
cannam@115 613 SerdStatus
cannam@115 614 serd_env_set_base_uri(SerdEnv* env,
cannam@115 615 const SerdNode* uri);
cannam@115 616
cannam@115 617 /**
cannam@115 618 Set a namespace prefix.
cannam@115 619 */
cannam@115 620 SERD_API
cannam@115 621 SerdStatus
cannam@115 622 serd_env_set_prefix(SerdEnv* env,
cannam@115 623 const SerdNode* name,
cannam@115 624 const SerdNode* uri);
cannam@115 625
cannam@115 626 /**
cannam@115 627 Set a namespace prefix.
cannam@115 628 */
cannam@115 629 SERD_API
cannam@115 630 SerdStatus
cannam@115 631 serd_env_set_prefix_from_strings(SerdEnv* env,
cannam@115 632 const uint8_t* name,
cannam@115 633 const uint8_t* uri);
cannam@115 634
cannam@115 635 /**
cannam@115 636 Qualify @c uri into a CURIE if possible.
cannam@115 637 */
cannam@115 638 SERD_API
cannam@115 639 bool
cannam@115 640 serd_env_qualify(const SerdEnv* env,
cannam@115 641 const SerdNode* uri,
cannam@115 642 SerdNode* prefix,
cannam@115 643 SerdChunk* suffix);
cannam@115 644
cannam@115 645 /**
cannam@115 646 Expand @c curie.
cannam@115 647 */
cannam@115 648 SERD_API
cannam@115 649 SerdStatus
cannam@115 650 serd_env_expand(const SerdEnv* env,
cannam@115 651 const SerdNode* curie,
cannam@115 652 SerdChunk* uri_prefix,
cannam@115 653 SerdChunk* uri_suffix);
cannam@115 654
cannam@115 655 /**
cannam@115 656 Expand @c node, which must be a CURIE or URI, to a full URI.
cannam@115 657 */
cannam@115 658 SERD_API
cannam@115 659 SerdNode
cannam@115 660 serd_env_expand_node(const SerdEnv* env,
cannam@115 661 const SerdNode* node);
cannam@115 662
cannam@115 663 /**
cannam@115 664 Call @c func for each prefix defined in @c env.
cannam@115 665 */
cannam@115 666 SERD_API
cannam@115 667 void
cannam@115 668 serd_env_foreach(const SerdEnv* env,
cannam@115 669 SerdPrefixSink func,
cannam@115 670 void* handle);
cannam@115 671
cannam@115 672 /**
cannam@115 673 @}
cannam@115 674 @name Reader
cannam@115 675 @{
cannam@115 676 */
cannam@115 677
cannam@115 678 /**
cannam@115 679 Create a new RDF reader.
cannam@115 680 */
cannam@115 681 SERD_API
cannam@115 682 SerdReader*
cannam@115 683 serd_reader_new(SerdSyntax syntax,
cannam@115 684 void* handle,
cannam@115 685 void (*free_handle)(void*),
cannam@115 686 SerdBaseSink base_sink,
cannam@115 687 SerdPrefixSink prefix_sink,
cannam@115 688 SerdStatementSink statement_sink,
cannam@115 689 SerdEndSink end_sink);
cannam@115 690
cannam@115 691 /**
cannam@115 692 Set a function to be called when errors occur during reading.
cannam@115 693
cannam@115 694 The @p error_sink will be called with @p handle as its first argument. If
cannam@115 695 no error function is set, errors are printed to stderr in GCC style.
cannam@115 696 */
cannam@115 697 SERD_API
cannam@115 698 void
cannam@115 699 serd_reader_set_error_sink(SerdReader* reader,
cannam@115 700 SerdErrorSink error_sink,
cannam@115 701 void* handle);
cannam@115 702
cannam@115 703 /**
cannam@115 704 Return the @c handle passed to @ref serd_reader_new.
cannam@115 705 */
cannam@115 706 SERD_API
cannam@115 707 void*
cannam@115 708 serd_reader_get_handle(const SerdReader* reader);
cannam@115 709
cannam@115 710 /**
cannam@115 711 Set a prefix to be added to all blank node identifiers.
cannam@115 712
cannam@115 713 This is useful when multiple files are to be parsed into the same output
cannam@115 714 (e.g. a store, or other files). Since Serd preserves blank node IDs, this
cannam@115 715 could cause conflicts where two non-equivalent blank nodes are merged,
cannam@115 716 resulting in corrupt data. By setting a unique blank node prefix for each
cannam@115 717 parsed file, this can be avoided, while preserving blank node names.
cannam@115 718 */
cannam@115 719 SERD_API
cannam@115 720 void
cannam@115 721 serd_reader_add_blank_prefix(SerdReader* reader,
cannam@115 722 const uint8_t* prefix);
cannam@115 723
cannam@115 724 /**
cannam@115 725 Set the URI of the default graph.
cannam@115 726
cannam@115 727 If this is set, the reader will emit quads with the graph set to the given
cannam@115 728 node for any statements that are not in a named graph (which is currently
cannam@115 729 all of them since Serd currently does not support any graph syntaxes).
cannam@115 730 */
cannam@115 731 SERD_API
cannam@115 732 void
cannam@115 733 serd_reader_set_default_graph(SerdReader* reader,
cannam@115 734 const SerdNode* graph);
cannam@115 735
cannam@115 736 /**
cannam@115 737 Read a file at a given @c uri.
cannam@115 738 */
cannam@115 739 SERD_API
cannam@115 740 SerdStatus
cannam@115 741 serd_reader_read_file(SerdReader* reader,
cannam@115 742 const uint8_t* uri);
cannam@115 743
cannam@115 744 /**
cannam@115 745 Start an incremental read from a file handle.
cannam@115 746
cannam@115 747 Iff @p bulk is true, @p file will be read a page at a time. This is more
cannam@115 748 efficient, but uses a page of memory and means that an entire page of input
cannam@115 749 must be ready before any callbacks will fire. To react as soon as input
cannam@115 750 arrives, set @p bulk to false.
cannam@115 751 */
cannam@115 752 SERD_API
cannam@115 753 SerdStatus
cannam@115 754 serd_reader_start_stream(SerdReader* me,
cannam@115 755 FILE* file,
cannam@115 756 const uint8_t* name,
cannam@115 757 bool bulk);
cannam@115 758
cannam@115 759 /**
cannam@115 760 Read a single "chunk" of data during an incremental read.
cannam@115 761
cannam@115 762 This function will read a single top level description, and return. This
cannam@115 763 may be a directive, statement, or several statements; essentially it reads
cannam@115 764 until a '.' is encountered. This is particularly useful for reading
cannam@115 765 directly from a pipe or socket.
cannam@115 766 */
cannam@115 767 SERD_API
cannam@115 768 SerdStatus
cannam@115 769 serd_reader_read_chunk(SerdReader* me);
cannam@115 770
cannam@115 771 /**
cannam@115 772 Finish an incremental read from a file handle.
cannam@115 773 */
cannam@115 774 SERD_API
cannam@115 775 SerdStatus
cannam@115 776 serd_reader_end_stream(SerdReader* me);
cannam@115 777
cannam@115 778 /**
cannam@115 779 Read @c file.
cannam@115 780 */
cannam@115 781 SERD_API
cannam@115 782 SerdStatus
cannam@115 783 serd_reader_read_file_handle(SerdReader* reader,
cannam@115 784 FILE* file,
cannam@115 785 const uint8_t* name);
cannam@115 786
cannam@115 787 /**
cannam@115 788 Read @c utf8.
cannam@115 789 */
cannam@115 790 SERD_API
cannam@115 791 SerdStatus
cannam@115 792 serd_reader_read_string(SerdReader* me, const uint8_t* utf8);
cannam@115 793
cannam@115 794 /**
cannam@115 795 Free @c reader.
cannam@115 796 */
cannam@115 797 SERD_API
cannam@115 798 void
cannam@115 799 serd_reader_free(SerdReader* reader);
cannam@115 800
cannam@115 801 /**
cannam@115 802 @}
cannam@115 803 @name Writer
cannam@115 804 @{
cannam@115 805 */
cannam@115 806
cannam@115 807 /**
cannam@115 808 Create a new RDF writer.
cannam@115 809 */
cannam@115 810 SERD_API
cannam@115 811 SerdWriter*
cannam@115 812 serd_writer_new(SerdSyntax syntax,
cannam@115 813 SerdStyle style,
cannam@115 814 SerdEnv* env,
cannam@115 815 const SerdURI* base_uri,
cannam@115 816 SerdSink sink,
cannam@115 817 void* stream);
cannam@115 818
cannam@115 819 /**
cannam@115 820 Free @c writer.
cannam@115 821 */
cannam@115 822 SERD_API
cannam@115 823 void
cannam@115 824 serd_writer_free(SerdWriter* writer);
cannam@115 825
cannam@115 826 /**
cannam@115 827 Return the env used by @c writer.
cannam@115 828 */
cannam@115 829 SERD_API
cannam@115 830 SerdEnv*
cannam@115 831 serd_writer_get_env(SerdWriter* writer);
cannam@115 832
cannam@115 833 /**
cannam@115 834 A convenience sink function for writing to a FILE*.
cannam@115 835
cannam@115 836 This function can be used as a SerdSink when writing to a FILE*. The
cannam@115 837 @c stream parameter must be a FILE* opened for writing.
cannam@115 838 */
cannam@115 839 SERD_API
cannam@115 840 size_t
cannam@115 841 serd_file_sink(const void* buf, size_t len, void* stream);
cannam@115 842
cannam@115 843 /**
cannam@115 844 A convenience sink function for writing to a string.
cannam@115 845
cannam@115 846 This function can be used as a SerdSink to write to a SerdChunk which is
cannam@115 847 resized as necessary with realloc(). The @c stream parameter must point to
cannam@115 848 an initialized SerdChunk. When the write is finished, the string should be
cannam@115 849 retrieved with serd_chunk_sink_finish().
cannam@115 850 */
cannam@115 851 SERD_API
cannam@115 852 size_t
cannam@115 853 serd_chunk_sink(const void* buf, size_t len, void* stream);
cannam@115 854
cannam@115 855 /**
cannam@115 856 Finish a serialisation to a chunk with serd_chunk_sink().
cannam@115 857
cannam@115 858 The returned string is the result of the serialisation, which is NULL
cannam@115 859 terminated (by this function) and owned by the caller.
cannam@115 860 */
cannam@115 861 SERD_API
cannam@115 862 uint8_t*
cannam@115 863 serd_chunk_sink_finish(SerdChunk* stream);
cannam@115 864
cannam@115 865 /**
cannam@115 866 Set a function to be called when errors occur during writing.
cannam@115 867
cannam@115 868 The @p error_sink will be called with @p handle as its first argument. If
cannam@115 869 no error function is set, errors are printed to stderr.
cannam@115 870 */
cannam@115 871 SERD_API
cannam@115 872 void
cannam@115 873 serd_writer_set_error_sink(SerdWriter* writer,
cannam@115 874 SerdErrorSink error_sink,
cannam@115 875 void* handle);
cannam@115 876
cannam@115 877 /**
cannam@115 878 Set a prefix to be removed from matching blank node identifiers.
cannam@115 879 */
cannam@115 880 SERD_API
cannam@115 881 void
cannam@115 882 serd_writer_chop_blank_prefix(SerdWriter* writer,
cannam@115 883 const uint8_t* prefix);
cannam@115 884
cannam@115 885 /**
cannam@115 886 Set the current output base URI (and emit directive if applicable).
cannam@115 887
cannam@115 888 Note this function can be safely casted to SerdBaseSink.
cannam@115 889 */
cannam@115 890 SERD_API
cannam@115 891 SerdStatus
cannam@115 892 serd_writer_set_base_uri(SerdWriter* writer,
cannam@115 893 const SerdNode* uri);
cannam@115 894
cannam@115 895 /**
cannam@115 896 Set the current root URI.
cannam@115 897
cannam@115 898 The root URI should be a prefix of the base URI. The path of the root URI
cannam@115 899 is the highest path any relative up-reference can refer to. For example,
cannam@115 900 with root <file:///foo/root> and base <file:///foo/root/base>,
cannam@115 901 <file:///foo/root> will be written as <../>, but <file:///foo> will be
cannam@115 902 written non-relatively as <file:///foo>. If the root is not explicitly set,
cannam@115 903 it defaults to the base URI, so no up-references will be created at all.
cannam@115 904 */
cannam@115 905 SERD_API
cannam@115 906 SerdStatus
cannam@115 907 serd_writer_set_root_uri(SerdWriter* writer,
cannam@115 908 const SerdNode* uri);
cannam@115 909
cannam@115 910 /**
cannam@115 911 Set a namespace prefix (and emit directive if applicable).
cannam@115 912
cannam@115 913 Note this function can be safely casted to SerdPrefixSink.
cannam@115 914 */
cannam@115 915 SERD_API
cannam@115 916 SerdStatus
cannam@115 917 serd_writer_set_prefix(SerdWriter* writer,
cannam@115 918 const SerdNode* name,
cannam@115 919 const SerdNode* uri);
cannam@115 920
cannam@115 921 /**
cannam@115 922 Write a statement.
cannam@115 923
cannam@115 924 Note this function can be safely casted to SerdStatementSink.
cannam@115 925 */
cannam@115 926 SERD_API
cannam@115 927 SerdStatus
cannam@115 928 serd_writer_write_statement(SerdWriter* writer,
cannam@115 929 SerdStatementFlags flags,
cannam@115 930 const SerdNode* graph,
cannam@115 931 const SerdNode* subject,
cannam@115 932 const SerdNode* predicate,
cannam@115 933 const SerdNode* object,
cannam@115 934 const SerdNode* object_datatype,
cannam@115 935 const SerdNode* object_lang);
cannam@115 936
cannam@115 937 /**
cannam@115 938 Mark the end of an anonymous node's description.
cannam@115 939
cannam@115 940 Note this function can be safely casted to SerdEndSink.
cannam@115 941 */
cannam@115 942 SERD_API
cannam@115 943 SerdStatus
cannam@115 944 serd_writer_end_anon(SerdWriter* writer,
cannam@115 945 const SerdNode* node);
cannam@115 946
cannam@115 947 /**
cannam@115 948 Finish a write.
cannam@115 949 */
cannam@115 950 SERD_API
cannam@115 951 SerdStatus
cannam@115 952 serd_writer_finish(SerdWriter* writer);
cannam@115 953
cannam@115 954 /**
cannam@115 955 @}
cannam@115 956 @}
cannam@115 957 */
cannam@115 958
cannam@115 959 #ifdef __cplusplus
cannam@115 960 } /* extern "C" */
cannam@115 961 #endif
cannam@115 962
cannam@115 963 #endif /* SERD_SERD_H */