Serd  0.14.0
serd.h
1 /*
2  Copyright 2011-2012 David Robillard <http://drobilla.net>
3 
4  Permission to use, copy, modify, and/or distribute this software for any
5  purpose with or without fee is hereby granted, provided that the above
6  copyright notice and this permission notice appear in all copies.
7 
8  THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 
21 #ifndef SERD_SERD_H
22 #define SERD_SERD_H
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 
28 #ifdef SERD_SHARED
29 # ifdef _WIN32
30 # define SERD_LIB_IMPORT __declspec(dllimport)
31 # define SERD_LIB_EXPORT __declspec(dllexport)
32 # else
33 # define SERD_LIB_IMPORT __attribute__((visibility("default")))
34 # define SERD_LIB_EXPORT __attribute__((visibility("default")))
35 # endif
36 # ifdef SERD_INTERNAL
37 # define SERD_API SERD_LIB_EXPORT
38 # else
39 # define SERD_API SERD_LIB_IMPORT
40 # endif
41 #else
42 # define SERD_API
43 #endif
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #else
48 # include <stdbool.h>
49 #endif
50 
63 typedef struct SerdEnvImpl SerdEnv;
64 
71 typedef struct SerdReaderImpl SerdReader;
72 
81 typedef struct SerdWriterImpl SerdWriter;
82 
86 typedef enum {
93 } SerdStatus;
94 
98 typedef enum {
104 
110 } SerdSyntax;
111 
115 typedef enum {
116  SERD_EMPTY_S = 1 << 1,
117  SERD_EMPTY_O = 1 << 2,
118  SERD_ANON_S_BEGIN = 1 << 3,
119  SERD_ANON_O_BEGIN = 1 << 4,
120  SERD_ANON_CONT = 1 << 5,
121  SERD_LIST_S_BEGIN = 1 << 6,
122  SERD_LIST_O_BEGIN = 1 << 7,
123  SERD_LIST_CONT = 1 << 8
125 
129 typedef uint32_t SerdStatementFlags;
130 
140 typedef enum {
147 
154 
163  SERD_URI = 2,
164 
173 
183 
184 } SerdType;
185 
189 typedef enum {
191  SERD_HAS_QUOTE = 1 << 1
192 } SerdNodeFlag;
193 
197 typedef uint32_t SerdNodeFlags;
198 
202 typedef struct {
203  const uint8_t* buf;
204  size_t n_bytes;
205  size_t n_chars;
206  SerdNodeFlags flags;
208 } SerdNode;
209 
213 typedef struct {
214  const uint8_t* buf;
215  size_t len;
216 } SerdChunk;
217 
225 typedef struct {
232 } SerdURI;
233 
242 typedef enum {
244  SERD_STYLE_ASCII = 1 << 1,
246  SERD_STYLE_CURIED = 1 << 3,
247  SERD_STYLE_BULK = 1 << 4
248 } SerdStyle;
249 
258 SERD_API
259 const uint8_t*
260 serd_strerror(SerdStatus status);
261 
269 SERD_API
270 size_t
271 serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags);
272 
280 SERD_API
281 double
282 serd_strtod(const char* str, char** endptr);
283 
294 SERD_API
295 void*
296 serd_base64_decode(const uint8_t* str, size_t len, size_t* size);
297 
304 static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
305 
313 SERD_API
314 const uint8_t*
315 serd_uri_to_path(const uint8_t* uri);
316 
326 SERD_API
327 uint8_t*
328 serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname);
329 
333 SERD_API
334 bool
335 serd_uri_string_has_scheme(const uint8_t* utf8);
336 
340 SERD_API
342 serd_uri_parse(const uint8_t* utf8, SerdURI* out);
343 
347 SERD_API
348 void
349 serd_uri_resolve(const SerdURI* uri, const SerdURI* base, SerdURI* out);
350 
354 typedef size_t (*SerdSink)(const void* buf, size_t len, void* stream);
355 
359 SERD_API
360 size_t
361 serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream);
362 
370 SERD_API
371 size_t
373  const SerdURI* base,
374  const SerdURI* root,
375  SerdSink sink,
376  void* stream);
377 
384 static const SerdNode SERD_NODE_NULL = { 0, 0, 0, 0, SERD_NOTHING };
385 
391 SERD_API
392 SerdNode
393 serd_node_from_string(SerdType type, const uint8_t* str);
394 
400 SERD_API
401 SerdNode
402 serd_node_copy(const SerdNode* node);
403 
407 SERD_API
408 bool
409 serd_node_equals(const SerdNode* a, const SerdNode* b);
410 
414 SERD_API
415 SerdNode
416 serd_node_new_uri_from_node(const SerdNode* uri_node,
417  const SerdURI* base,
418  SerdURI* out);
419 
423 SERD_API
424 SerdNode
425 serd_node_new_uri_from_string(const uint8_t* str,
426  const SerdURI* base,
427  SerdURI* out);
428 
439 SERD_API
440 SerdNode
441 serd_node_new_file_uri(const uint8_t* path,
442  const uint8_t* hostname,
443  SerdURI* out,
444  bool escape);
445 
456 SERD_API
457 SerdNode
458 serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out);
459 
475 SERD_API
476 SerdNode
477 serd_node_new_decimal(double d, unsigned frac_digits);
478 
482 SERD_API
483 SerdNode
484 serd_node_new_integer(int64_t i);
485 
495 SERD_API
496 SerdNode
497 serd_node_new_blob(const void* buf, size_t size, bool wrap_lines);
498 
505 SERD_API
506 void
507 serd_node_free(SerdNode* node);
508 
520 typedef SerdStatus (*SerdBaseSink)(void* handle,
521  const SerdNode* uri);
522 
528 typedef SerdStatus (*SerdPrefixSink)(void* handle,
529  const SerdNode* name,
530  const SerdNode* uri);
531 
537 typedef SerdStatus (*SerdStatementSink)(void* handle,
538  SerdStatementFlags flags,
539  const SerdNode* graph,
540  const SerdNode* subject,
541  const SerdNode* predicate,
542  const SerdNode* object,
543  const SerdNode* object_datatype,
544  const SerdNode* object_lang);
545 
553 typedef SerdStatus (*SerdEndSink)(void* handle,
554  const SerdNode* node);
555 
565 SERD_API
566 SerdEnv*
567 serd_env_new(const SerdNode* base_uri);
568 
572 SERD_API
573 void
574 serd_env_free(SerdEnv* env);
575 
579 SERD_API
580 const SerdNode*
581 serd_env_get_base_uri(const SerdEnv* env,
582  SerdURI* out);
583 
587 SERD_API
590  const SerdNode* uri);
591 
595 SERD_API
598  const SerdNode* name,
599  const SerdNode* uri);
600 
604 SERD_API
607  const uint8_t* name,
608  const uint8_t* uri);
609 
613 SERD_API
614 bool
615 serd_env_qualify(const SerdEnv* env,
616  const SerdNode* uri,
617  SerdNode* prefix,
618  SerdChunk* suffix);
619 
623 SERD_API
625 serd_env_expand(const SerdEnv* env,
626  const SerdNode* curie,
627  SerdChunk* uri_prefix,
628  SerdChunk* uri_suffix);
629 
633 SERD_API
634 SerdNode
635 serd_env_expand_node(const SerdEnv* env,
636  const SerdNode* node);
637 
641 SERD_API
642 void
643 serd_env_foreach(const SerdEnv* env,
644  SerdPrefixSink func,
645  void* handle);
646 
656 SERD_API
657 SerdReader*
659  void* handle,
660  void (*free_handle)(void*),
661  SerdBaseSink base_sink,
662  SerdPrefixSink prefix_sink,
663  SerdStatementSink statement_sink,
664  SerdEndSink end_sink);
665 
669 SERD_API
670 void*
671 serd_reader_get_handle(const SerdReader* reader);
672 
682 SERD_API
683 void
685  const uint8_t* prefix);
686 
694 SERD_API
695 void
697  const SerdNode* graph);
698 
702 SERD_API
705  const uint8_t* uri);
706 
710 SERD_API
713  FILE* file,
714  const uint8_t* name);
715 
719 SERD_API
721 serd_reader_read_string(SerdReader* me, const uint8_t* utf8);
722 
726 SERD_API
727 void
729 
739 SERD_API
740 SerdWriter*
742  SerdStyle style,
743  SerdEnv* env,
744  const SerdURI* base_uri,
745  SerdSink sink,
746  void* stream);
747 
751 SERD_API
752 void
754 
758 SERD_API
759 SerdEnv*
761 
768 SERD_API
769 size_t
770 serd_file_sink(const void* buf, size_t len, void* stream);
771 
780 SERD_API
781 size_t
782 serd_chunk_sink(const void* buf, size_t len, void* stream);
783 
790 SERD_API
791 uint8_t*
793 
797 SERD_API
798 void
800  const uint8_t* prefix);
801 
807 SERD_API
810  const SerdNode* uri);
811 
822 SERD_API
825  const SerdNode* uri);
826 
832 SERD_API
835  const SerdNode* name,
836  const SerdNode* uri);
837 
843 SERD_API
846  SerdStatementFlags flags,
847  const SerdNode* graph,
848  const SerdNode* subject,
849  const SerdNode* predicate,
850  const SerdNode* object,
851  const SerdNode* object_datatype,
852  const SerdNode* object_lang);
853 
859 SERD_API
862  const SerdNode* node);
863 
867 SERD_API
870 
876 #ifdef __cplusplus
877 } /* extern "C" */
878 #endif
879 
880 #endif /* SERD_SERD_H */