1/* -*- Mode: c; c-basic-offset: 2 -*-
2 *
3 * raptor.h - Redland Parser Toolkit for RDF (Raptor) - public API
4 *
5 * Copyright (C) 2000-2013, David Beckett http://www.dajobe.org/
6 * Copyright (C) 2000-2005, University of Bristol, UK http://www.bristol.ac.uk/
7 *
8 * This package is Free Software and part of Redland http://librdf.org/
9 *
10 * It is licensed under the following three licenses as alternatives:
11 * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 * 2. GNU General Public License (GPL) V2 or any newer version
13 * 3. Apache License, V2.0 or any newer version
14 *
15 * You may not use this file except in compliance with at least one of
16 * the above three licenses.
17 *
18 * See LICENSE.html or LICENSE.txt at the top of this package for the
19 * complete terms and further detail along with the license texts for
20 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
21 *
22 *
23 */
24
25
26
27#ifndef RAPTOR_H
28#define RAPTOR_H
29
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include <stdio.h>
36
37/* Required for va_list in raptor_vsnprintf */
38#include <stdarg.h>
39
40
41/**
42 * RAPTOR_V2_AVAILABLE
43 *
44 * Flag for marking raptor2 API availability.
45 */
46#define RAPTOR_V2_AVAILABLE 1
47
48
49/**
50 * RAPTOR_VERSION:
51 *
52 * Raptor library version number
53 *
54 * Format: major * 10000 + minor * 100 + release
55 */
56#define RAPTOR_VERSION 20013
57
58/**
59 * RAPTOR_VERSION_STRING:
60 *
61 * Raptor library version string
62 */
63#define RAPTOR_VERSION_STRING "2.0.13"
64
65/**
66 * RAPTOR_VERSION_MAJOR:
67 *
68 * Raptor library major version
69 */
70#define RAPTOR_VERSION_MAJOR 2
71
72/**
73 * RAPTOR_VERSION_MINOR:
74 *
75 * Raptor library minor version
76 */
77#define RAPTOR_VERSION_MINOR 0
78
79/**
80 * RAPTOR_VERSION_RELEASE:
81 *
82 * Raptor library release
83 */
84#define RAPTOR_VERSION_RELEASE 13
85
86/**
87 * RAPTOR_API:
88 *
89 * Macro for wrapping API function call declarations.
90 *
91 */
92#ifndef RAPTOR_API
93# ifdef WIN32
94# ifdef __GNUC__
95# undef _declspec
96# define _declspec(x) __declspec(x)
97# endif
98# ifdef RAPTOR_STATIC
99# define RAPTOR_API
100# else
101# ifdef RAPTOR_INTERNAL
102# define RAPTOR_API _declspec(dllexport)
103# else
104# define RAPTOR_API _declspec(dllimport)
105# endif
106# endif
107# else
108# define RAPTOR_API
109# endif
110#endif
111
112/* Use gcc 3.1+ feature to allow marking of deprecated API calls.
113 * This gives a warning during compiling.
114 */
115#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
116#define RAPTOR_DEPRECATED __attribute__((deprecated))
117#define RAPTOR_NORETURN __attribute__((__noreturn__))
118#else
119#define RAPTOR_DEPRECATED
120#define RAPTOR_NORETURN
121#endif
122
123/**
124 * RAPTOR_PRINTF_FORMAT:
125 * @string_index: ignore me
126 * @first_to_check_index: ignore me
127 *
128 * Internal macro
129 */
130#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
131#define RAPTOR_PRINTF_FORMAT(string_index, first_to_check_index) \
132 __attribute__((__format__(__printf__, string_index, first_to_check_index)))
133#else
134#define RAPTOR_PRINTF_FORMAT(string_index, first_to_check_index)
135#endif
136
137/**
138 * raptor_uri:
139 *
140 * Raptor URI Class.
141 */
142typedef struct raptor_uri_s raptor_uri;
143
144
145/* Public statics */
146
147/**
148 * raptor_short_copyright_string:
149 *
150 * Short copyright string (one line).
151 */
152RAPTOR_API
153extern const char * const raptor_short_copyright_string;
154
155/**
156 * raptor_copyright_string:
157 *
158 * Copyright string (multiple lines).
159 */
160RAPTOR_API
161extern const char * const raptor_copyright_string;
162
163/**
164 * raptor_version_string:
165 *
166 * Raptor version as a string.
167 */
168RAPTOR_API
169extern const char * const raptor_version_string;
170
171/**
172 * raptor_version_major:
173 *
174 * Raptor major version number.
175 */
176RAPTOR_API
177extern const unsigned int raptor_version_major;
178
179/**
180 * raptor_version_minor:
181 *
182 * Raptor minor version number.
183 */
184RAPTOR_API
185extern const unsigned int raptor_version_minor;
186
187/**
188 * raptor_version_release:
189 *
190 * Raptor release version number.
191 */
192RAPTOR_API
193extern const unsigned int raptor_version_release;
194
195/**
196 * raptor_version_decimal:
197 *
198 * Raptor version as a decimal number.
199 *
200 * Format: major * 10000 + minor * 100 + release
201 */
202RAPTOR_API
203extern const unsigned int raptor_version_decimal;
204
205/**
206 * raptor_license_string:
207 *
208 * Raptor license string.
209 */
210RAPTOR_API
211extern const char * const raptor_license_string;
212
213/**
214 * raptor_home_url_string:
215 *
216 * Raptor home page URL.
217 */
218RAPTOR_API
219extern const char * const raptor_home_url_string;
220
221/**
222 * raptor_xml_namespace_uri:
223 *
224 * XML Namespace (xml:) URI string.
225 */
226RAPTOR_API
227extern const unsigned char * const raptor_xml_namespace_uri;
228
229
230/**
231 * raptor_rdf_namespace_uri:
232 *
233 * RDF Namespace (rdf:) URI string.
234 */
235RAPTOR_API
236extern const unsigned char * const raptor_rdf_namespace_uri;
237
238/**
239 * raptor_rdf_namespace_uri_len:
240 *
241 * Length of #raptor_rdf_namespace_uri string
242 */
243RAPTOR_API
244extern const unsigned int raptor_rdf_namespace_uri_len;
245
246/**
247 * raptor_rdf_schema_namespace_uri:
248 *
249 * RDF Schema (rdfs:) Namespace URI string.
250 */
251RAPTOR_API
252extern const unsigned char * const raptor_rdf_schema_namespace_uri;
253
254/**
255 * raptor_xmlschema_datatypes_namespace_uri:
256 *
257 * XML Schema datatypes (xsd:) namespace URI string.
258 */
259RAPTOR_API
260extern const unsigned char * const raptor_xmlschema_datatypes_namespace_uri;
261
262/**
263 * raptor_owl_namespace_uri:
264 *
265 * OWL (owl:) Namespace URI string.
266 */
267RAPTOR_API
268extern const unsigned char * const raptor_owl_namespace_uri;
269
270/**
271 * raptor_xml_literal_datatype_uri_string:
272 *
273 * XML Literal datatype (rdf:XMLLiteral) URI string.
274 */
275RAPTOR_API
276extern const unsigned char * const raptor_xml_literal_datatype_uri_string;
277
278/**
279 * raptor_xml_literal_datatype_uri_string_len:
280 *
281 * Length of #raptor_xml_literal_datatype_uri_string
282 */
283RAPTOR_API
284extern const unsigned int raptor_xml_literal_datatype_uri_string_len;
285
286
287/* Public structure */
288/**
289 * raptor_world:
290 *
291 * Raptor world class.
292 */
293typedef struct raptor_world_s raptor_world;
294/**
295 * raptor_parser:
296 *
297 * Raptor Parser class
298 */
299typedef struct raptor_parser_s raptor_parser;
300/**
301 * raptor_serializer:
302 *
303 * Raptor Serializer class
304 */
305typedef struct raptor_serializer_s raptor_serializer;
306
307/**
308 * raptor_www:
309 *
310 * Raptor WWW class
311 */
312typedef struct raptor_www_s raptor_www;
313/**
314 * raptor_iostream:
315 *
316 * Raptor I/O Stream class
317 */
318typedef struct raptor_iostream_s raptor_iostream;
319/**
320 * raptor_xml_element:
321 *
322 * Raptor XML Element class
323 */
324typedef struct raptor_xml_element_s raptor_xml_element;
325/**
326 * raptor_xml_writer:
327 *
328 * Raptor XML Writer class
329 */
330typedef struct raptor_xml_writer_s raptor_xml_writer;
331/**
332 * raptor_qname:
333 *
334 * Raptor XML qname class
335 */
336typedef struct raptor_qname_s raptor_qname;
337/**
338 * raptor_namespace:
339 *
340 * Raptor XML Namespace class
341 */
342typedef struct raptor_namespace_s raptor_namespace;
343/**
344 * raptor_namespace_stack:
345 *
346 * Raptor XML Namespace Stack class
347 */
348typedef struct raptor_namespace_stack_s raptor_namespace_stack;
349
350/**
351 * raptor_sax2:
352 *
353 * Raptor SAX2 class
354 */
355typedef struct raptor_sax2_s raptor_sax2;
356
357
358/**
359 * raptor_type_q:
360 * @mime_type: MIME type string
361 * @mime_type_len: length of @mime_type
362 * @q: Q value 0-10 standing for decimal 0.0-1.0
363 *
364 * (MIME Type, Q) pair
365 */
366typedef struct {
367 const char* mime_type;
368 size_t mime_type_len;
369 unsigned char q;
370} raptor_type_q;
371
372
373/**
374 * raptor_syntax_bitflags:
375 * @RAPTOR_SYNTAX_NEED_BASE_URI: the syntax requires a base URI
376 *
377 * Bit flags for #raptor_syntax_description flags field
378 */
379typedef enum {
380 RAPTOR_SYNTAX_NEED_BASE_URI = 1
381} raptor_syntax_bitflags;
382
383
384/**
385 * raptor_syntax_description:
386 * @names: array of syntax names - the first one (required) is the public name, the rest are aliases. The array is NULL terminated.
387 * @names_count: size of @names array
388 * @label: long descriptive label for syntax
389 * @mime_types: Array of (MIME type, Q) values associated with the syntax (or NULL). If present the array is NULL terminated.
390 * @mime_types_count: size of @mime_types array
391 * @uri_strings: array of URIs identifying the syntax (or NULL). The first one if present is the main URI, the rest are aliases. The array is NULL terminated.
392 * @uri_strings_count: size of @uri_strings array
393 * @flags: See #raptor_syntax_bitflags for the bits
394 *
395 * Description of a syntax or file format.
396 *
397 */
398typedef struct {
399 const char* const* names;
400 unsigned int names_count;
401
402 const char* label;
403
404 const raptor_type_q* mime_types;
405 unsigned int mime_types_count;
406
407 const char* const* uri_strings;
408 unsigned int uri_strings_count;
409
410 unsigned int flags;
411} raptor_syntax_description;
412
413
414/**
415 * raptor_term_type:
416 * @RAPTOR_TERM_TYPE_URI: RDF URI
417 * @RAPTOR_TERM_TYPE_LITERAL: RDF literal
418 * @RAPTOR_TERM_TYPE_BLANK: RDF blank node
419 * @RAPTOR_TERM_TYPE_UNKNOWN: Internal
420 *
421 * Type of term in a #raptor_statement
422 *
423 * Node type 3 is unused but exists to preserve numeric compatibility
424 * with librdf_node_type values.
425 */
426typedef enum {
427 RAPTOR_TERM_TYPE_UNKNOWN = 0,
428 RAPTOR_TERM_TYPE_URI = 1,
429 RAPTOR_TERM_TYPE_LITERAL = 2,
430 /* unused type 3 */
431 RAPTOR_TERM_TYPE_BLANK = 4
432} raptor_term_type;
433
434
435/**
436 * raptor_locator:
437 * @uri: URI of location (or NULL)
438 * @file: Filename of location (or NULL)
439 * @line: Line number of location (or <0 for no line)
440 * @column: Column number of location (or <0 for no column)
441 * @byte: Byte number of location (or <0 for no byte)
442 *
443 * Location information for an error, warning or information message.
444 */
445typedef struct {
446 raptor_uri *uri;
447 const char *file;
448 int line;
449 int column;
450 int byte;
451} raptor_locator;
452
453/**
454 * raptor_option:
455 * @RAPTOR_OPTION_SCANNING: If true (default false), the RDF/XML
456 * parser will look for embedded rdf:RDF elements inside the XML
457 * content, and not require that the XML start with an rdf:RDF root
458 * element.
459 * @RAPTOR_OPTION_ALLOW_NON_NS_ATTRIBUTES: If true (default true)
460 * then the RDF/XML parser will allow non-XML namespaced attributes
461 * to be accepted as well as rdf: namespaced ones. For example,
462 * 'about' and 'ID' will be interpreted as if they were rdf:about
463 * and rdf:ID respectively.
464 * @RAPTOR_OPTION_ALLOW_OTHER_PARSETYPES: If true (default true)
465 * then the RDF/XML parser will allow unknown parsetypes to be
466 * present and will pass them on to the user. Unimplemented at
467 * present.
468 * @RAPTOR_OPTION_ALLOW_BAGID: If true (default true) then the
469 * RDF/XML parser will support the rdf:bagID attribute that was
470 * removed from the RDF/XML language when it was revised. This
471 * support may be removed in future.
472 * @RAPTOR_OPTION_ALLOW_RDF_TYPE_RDF_LIST: If true (default false)
473 * then the RDF/XML parser will generate the idList rdf:type
474 * rdf:List triple in the handling of rdf:parseType="Collection".
475 * This triple was removed during the revising of RDF/XML after
476 * collections were initially added.
477 * @RAPTOR_OPTION_NORMALIZE_LANGUAGE: If true (default true) then
478 * XML language values such as from xml:lang will be normalized to
479 * lowercase.
480 * @RAPTOR_OPTION_NON_NFC_FATAL: If true (default false) then
481 * illegal Unicode Normal Form C in literals will give a fatal
482 * error, otherwise just a warning.
483 * @RAPTOR_OPTION_WARN_OTHER_PARSETYPES: If true (default true) then
484 * the RDF/XML parser will warn about unknown rdf:parseType values.
485 * @RAPTOR_OPTION_CHECK_RDF_ID: If true (default true) then the
486 * RDF/XML will check rdf:ID attribute values for duplicates and
487 * cause an error if any are found.
488 * @RAPTOR_OPTION_RELATIVE_URIS: If true (default true) then
489 * relative URIs will be used wherever possible when serializing.
490 * @RAPTOR_OPTION_WRITER_AUTO_INDENT: Automatically indent elements when
491 * seriailizing.
492 * @RAPTOR_OPTION_WRITER_AUTO_EMPTY: Automatically detect and
493 * abbreviate empty elements when serializing.
494 * @RAPTOR_OPTION_WRITER_INDENT_WIDTH: Integer number of spaces to use
495 * for each indent level when serializing with auto indent.
496 * @RAPTOR_OPTION_WRITER_XML_VERSION: Integer XML version XML 1.0 (10) or XML 1.1 (11)
497 * @RAPTOR_OPTION_WRITER_XML_DECLARATION: Write XML 1.0 or 1.1 declaration.
498 * @RAPTOR_OPTION_NO_NET: Deny network requests inside other requests.
499 * @RAPTOR_OPTION_RESOURCE_BORDER: Border color of resource
500 * nodes for GraphViz DOT serializer.
501 * @RAPTOR_OPTION_LITERAL_BORDER: Border color of literal nodes
502 * for GraphViz DOT serializer.
503 * @RAPTOR_OPTION_BNODE_BORDER: Border color of blank nodes for
504 * GraphViz DOT serializer.
505 * @RAPTOR_OPTION_RESOURCE_FILL: Fill color of resource nodes
506 * for GraphViz DOT serializer.
507 * @RAPTOR_OPTION_LITERAL_FILL: Fill color of literal nodes for
508 * GraphViz DOT serializer.
509 * @RAPTOR_OPTION_BNODE_FILL: Fill color of blank nodes for
510 * GraphViz DOT serializer.
511 * @RAPTOR_OPTION_HTML_TAG_SOUP: Use a lax HTML parser if an XML parser
512 * fails when read HTML for GRDDL parser.
513 * @RAPTOR_OPTION_MICROFORMATS: Look for microformats for GRDDL parser.
514 * @RAPTOR_OPTION_HTML_LINK: Look for head &lt;link&gt; to type rdf/xml
515 * for GRDDL parser.
516 * @RAPTOR_OPTION_WWW_TIMEOUT: Set timeout for internal WWW URI requests
517 * for GRDDL parser.
518 * @RAPTOR_OPTION_WRITE_BASE_URI: Write @base directive for Turtle/N3.
519 * @RAPTOR_OPTION_WWW_HTTP_CACHE_CONTROL: HTTP Cache-Control: header
520 * @RAPTOR_OPTION_WWW_HTTP_USER_AGENT: HTTP User-Agent: header
521 * @RAPTOR_OPTION_JSON_CALLBACK: JSON serializer callback function.
522 * @RAPTOR_OPTION_JSON_EXTRA_DATA: JSON serializer extra top-level data
523 * @RAPTOR_OPTION_RSS_TRIPLES: Atom/RSS serializer writes extra RDF triples it finds (none, rdf-xml, atom-triples)
524 * @RAPTOR_OPTION_ATOM_ENTRY_URI: Atom entry URI. If given, generate an Atom Entry Document with the item having the given URI, otherwise generate an Atom Feed Document with any items found.
525 * @RAPTOR_OPTION_PREFIX_ELEMENTS: Integer. If set, generate Atom/RSS1.0 documents with prefixed elements, otherwise unprefixed.
526 * @RAPTOR_OPTION_STRICT: Boolean. If set, operate in strict conformance mode.
527 * @RAPTOR_OPTION_WWW_CERT_FILENAME: String. SSL client certificate filename
528 * @RAPTOR_OPTION_WWW_CERT_TYPE: String. SSL client certificate type
529 * @RAPTOR_OPTION_WWW_CERT_PASSPHRASE: String. SSL client certificate passphrase
530 * @RAPTOR_OPTION_WWW_SSL_VERIFY_PEER: Integer. SSL verify peer - non-0 to verify peer SSL certificate (default)
531 * @RAPTOR_OPTION_WWW_SSL_VERIFY_HOST: Integer. SSL verify host - 0 none, 1 CN match, 2 host match (default). Other values are ignored.
532 * @RAPTOR_OPTION_NO_FILE: Deny file reading requests inside other requests.
533 * @RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES: When reading XML, load external entities.
534 * @RAPTOR_OPTION_LAST: Internal
535 *
536 * Raptor parser, serializer or XML writer options.
537 */
538typedef enum {
539 RAPTOR_OPTION_SCANNING,
540 RAPTOR_OPTION_ALLOW_NON_NS_ATTRIBUTES,
541 RAPTOR_OPTION_ALLOW_OTHER_PARSETYPES,
542 RAPTOR_OPTION_ALLOW_BAGID,
543 RAPTOR_OPTION_ALLOW_RDF_TYPE_RDF_LIST,
544 RAPTOR_OPTION_NORMALIZE_LANGUAGE,
545 RAPTOR_OPTION_NON_NFC_FATAL,
546 RAPTOR_OPTION_WARN_OTHER_PARSETYPES,
547 RAPTOR_OPTION_CHECK_RDF_ID,
548 RAPTOR_OPTION_RELATIVE_URIS,
549 RAPTOR_OPTION_WRITER_AUTO_INDENT,
550 RAPTOR_OPTION_WRITER_AUTO_EMPTY,
551 RAPTOR_OPTION_WRITER_INDENT_WIDTH,
552 RAPTOR_OPTION_WRITER_XML_VERSION,
553 RAPTOR_OPTION_WRITER_XML_DECLARATION,
554 RAPTOR_OPTION_NO_NET,
555 RAPTOR_OPTION_RESOURCE_BORDER,
556 RAPTOR_OPTION_LITERAL_BORDER,
557 RAPTOR_OPTION_BNODE_BORDER,
558 RAPTOR_OPTION_RESOURCE_FILL,
559 RAPTOR_OPTION_LITERAL_FILL,
560 RAPTOR_OPTION_BNODE_FILL,
561 RAPTOR_OPTION_HTML_TAG_SOUP,
562 RAPTOR_OPTION_MICROFORMATS,
563 RAPTOR_OPTION_HTML_LINK,
564 RAPTOR_OPTION_WWW_TIMEOUT,
565 RAPTOR_OPTION_WRITE_BASE_URI,
566 RAPTOR_OPTION_WWW_HTTP_CACHE_CONTROL,
567 RAPTOR_OPTION_WWW_HTTP_USER_AGENT,
568 RAPTOR_OPTION_JSON_CALLBACK,
569 RAPTOR_OPTION_JSON_EXTRA_DATA,
570 RAPTOR_OPTION_RSS_TRIPLES,
571 RAPTOR_OPTION_ATOM_ENTRY_URI,
572 RAPTOR_OPTION_PREFIX_ELEMENTS,
573 RAPTOR_OPTION_STRICT,
574 RAPTOR_OPTION_WWW_CERT_FILENAME,
575 RAPTOR_OPTION_WWW_CERT_TYPE,
576 RAPTOR_OPTION_WWW_CERT_PASSPHRASE,
577 RAPTOR_OPTION_NO_FILE,
578 RAPTOR_OPTION_WWW_SSL_VERIFY_PEER,
579 RAPTOR_OPTION_WWW_SSL_VERIFY_HOST,
580 RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
581 RAPTOR_OPTION_LAST = RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES
582} raptor_option;
583
584
585/**
586 * raptor_term_literal_value:
587 * @string: literal string
588 * @string_len: length of string
589 * @datatype: datatype URI (or NULL)
590 * @language: literal language (or NULL)
591 * @language_len: length of language
592 *
593 * Literal term value - this typedef exists solely for use in #raptor_term
594 *
595 * Either @datatype or @language may be non-NULL but not both.
596 */
597typedef struct {
598 unsigned char *string;
599 unsigned int string_len;
600
601 raptor_uri *datatype;
602
603 unsigned char *language;
604 unsigned char language_len;
605} raptor_term_literal_value;
606
607
608/**
609 * raptor_term_blank_value:
610 * @string: literal string
611 * @string_len: length of string
612 *
613 * Blank term value - this typedef exists solely for use in #raptor_term
614 *
615 */
616typedef struct {
617 unsigned char *string;
618 unsigned int string_len;
619} raptor_term_blank_value;
620
621
622/**
623 * raptor_term_value:
624 * @uri: uri value when term type is #RAPTOR_TERM_TYPE_URI
625 * @literal: literal value when term type is #RAPTOR_TERM_TYPE_LITERAL
626 * @blank: blank value when term type is #RAPTOR_TERM_TYPE_BLANK
627 *
628 * Term value - this typedef exists solely for use in #raptor_term
629 *
630 **/
631typedef union {
632 raptor_uri *uri;
633
634 raptor_term_literal_value literal;
635
636 raptor_term_blank_value blank;
637} raptor_term_value;
638
639
640/**
641 * raptor_term:
642 * @world: world
643 * @usage: usage reference count (if >0)
644 * @type: term type
645 * @value: term values per type
646 *
647 * An RDF statement term
648 *
649 */
650typedef struct {
651 raptor_world* world;
652
653 int usage;
654
655 raptor_term_type type;
656
657 raptor_term_value value;
658
659} raptor_term;
660
661
662/**
663 * raptor_statement:
664 * @world: world pointer
665 * @usage: usage count
666 * @subject: statement subject
667 * @predicate: statement predicate
668 * @object: statement object
669 * @graph: statement graph name (or NULL if not present)
670 *
671 * An RDF triple with optional graph name (quad)
672 *
673 * See #raptor_term for a description of how the fields may be used.
674 * As returned by a parser statement_handler.
675 */
676typedef struct {
677 raptor_world* world;
678 int usage;
679 raptor_term* subject;
680 raptor_term* predicate;
681 raptor_term* object;
682 raptor_term* graph;
683} raptor_statement;
684
685
686/**
687 * raptor_log_level:
688 * @RAPTOR_LOG_LEVEL_NONE: Internal
689 * @RAPTOR_LOG_LEVEL_TRACE: very fine-grained tracing messages information
690 * @RAPTOR_LOG_LEVEL_DEBUG: fine-grained tracing messages suitable for debugging
691 * @RAPTOR_LOG_LEVEL_INFO: coarse-grained information messages
692 * @RAPTOR_LOG_LEVEL_WARN: warning messages of potentially harmful problems
693 * @RAPTOR_LOG_LEVEL_ERROR: error messages where the application can continue
694 * @RAPTOR_LOG_LEVEL_FATAL: fatal error message where the application will likely abort
695 * @RAPTOR_LOG_LEVEL_LAST: Internal
696 *
697 * Log levels
698 */
699typedef enum {
700 RAPTOR_LOG_LEVEL_NONE,
701 RAPTOR_LOG_LEVEL_TRACE,
702 RAPTOR_LOG_LEVEL_DEBUG,
703 RAPTOR_LOG_LEVEL_INFO,
704 RAPTOR_LOG_LEVEL_WARN,
705 RAPTOR_LOG_LEVEL_ERROR,
706 RAPTOR_LOG_LEVEL_FATAL,
707 RAPTOR_LOG_LEVEL_LAST = RAPTOR_LOG_LEVEL_FATAL
708} raptor_log_level;
709
710
711/**
712 * raptor_domain:
713 * @RAPTOR_DOMAIN_IOSTREAM: I/O stream
714 * @RAPTOR_DOMAIN_NAMESPACE: XML Namespace / namespace stack
715 * @RAPTOR_DOMAIN_PARSER: RDF Parser
716 * @RAPTOR_DOMAIN_QNAME: XML QName
717 * @RAPTOR_DOMAIN_SAX2: XML SAX2
718 * @RAPTOR_DOMAIN_SERIALIZER: RDF Serializer
719 * @RAPTOR_DOMAIN_TERM: RDF Term
720 * @RAPTOR_DOMAIN_TURTLE_WRITER: Turtle Writer
721 * @RAPTOR_DOMAIN_URI: RDF Uri
722 * @RAPTOR_DOMAIN_WORLD: RDF world
723 * @RAPTOR_DOMAIN_WWW: WWW
724 * @RAPTOR_DOMAIN_XML_WRITER: XML Writer
725 * @RAPTOR_DOMAIN_NONE: Internal
726 * @RAPTOR_DOMAIN_LAST: Internal
727 *
728 * Log domain
729 */
730typedef enum {
731 RAPTOR_DOMAIN_NONE,
732 RAPTOR_DOMAIN_IOSTREAM,
733 RAPTOR_DOMAIN_NAMESPACE,
734 RAPTOR_DOMAIN_PARSER,
735 RAPTOR_DOMAIN_QNAME,
736 RAPTOR_DOMAIN_SAX2,
737 RAPTOR_DOMAIN_SERIALIZER,
738 RAPTOR_DOMAIN_TERM,
739 RAPTOR_DOMAIN_TURTLE_WRITER,
740 RAPTOR_DOMAIN_URI,
741 RAPTOR_DOMAIN_WORLD,
742 RAPTOR_DOMAIN_WWW,
743 RAPTOR_DOMAIN_XML_WRITER,
744 RAPTOR_DOMAIN_LAST = RAPTOR_DOMAIN_XML_WRITER
745} raptor_domain;
746
747
748/**
749 * raptor_log_message:
750 * @code: error code or < 0 if not used or known
751 * @domain: message domain or #RAPTOR_DOMAIN_NONE if not used or known
752 * @level: log message level
753 * @locator: location associated with message or NULL if not known
754 * @text: message string
755 *
756 * Log message.
757 */
758typedef struct {
759 int code;
760 raptor_domain domain;
761 raptor_log_level level;
762 raptor_locator *locator;
763 const char *text;
764} raptor_log_message;
765
766
767/**
768 * raptor_log_handler:
769 * @user_data: user data
770 * @message: log message
771 *
772 * Handler function for log messages with location
773 *
774 * Used during parsing and serializing for errors and warnings that
775 * may include location information. Handlers may be set
776 * by raptor_world_set_log_handler().
777 *
778 */
779typedef void (*raptor_log_handler)(void *user_data, raptor_log_message *message);
780
781
782/**
783 * raptor_statement_handler:
784 * @user_data: user data
785 * @statement: statement to report
786 *
787 * Statement (triple) reporting handler function.
788 *
789 * This handler function set with
790 * raptor_parser_set_statement_handler() on a parser receives
791 * statements as the parsing proceeds. The @statement argument to the
792 * handler is shared and must be copied by the caller with
793 * raptor_statement_copy().
794 */
795typedef void (*raptor_statement_handler)(void *user_data, raptor_statement *statement);
796
797/**
798 * raptor_graph_mark_flags:
799 * @RAPTOR_GRAPH_MARK_START: mark is start of graph (otherwise is end)
800 * @RAPTOR_GRAPH_MARK_DECLARED: mark was declared in syntax rather than implict
801 *
802 * Graph mark handler bitmask flags
803 */
804typedef enum {
805 RAPTOR_GRAPH_MARK_START = 1,
806 RAPTOR_GRAPH_MARK_DECLARED = 2
807} raptor_graph_mark_flags;
808
809
810/**
811 * raptor_graph_mark_handler:
812 * @user_data: user data
813 * @graph: graph to report, NULL for the default graph
814 * @flags: bitmask of #raptor_graph_mark_flags flags
815 *
816 * Graph start/end mark handler function.
817 *
818 * Records start and end of graphs happening in a stream of generated
819 * #raptor_statement via the statement handler. The callback starts a
820 * graph when @flags has #RAPTOR_GRAPH_MARK_START bit set.
821 *
822 * The start and ends may be either declared in the syntax via some
823 * keyword or mechanism such as TRiG {} syntax when @flags has bit
824 * #RAPTOR_GRAPH_MARK_DECLARED set, or be implied by the start/end of
825 * the data in other syntaxes, and the bit will be unset.
826 */
827typedef void (*raptor_graph_mark_handler)(void *user_data, raptor_uri *graph, int flags);
828
829/**
830 * raptor_generate_bnodeid_handler:
831 * @user_data: user data
832 * @user_bnodeid: a user-specified ID or NULL if none available.
833 *
834 * Generate a blank node identifier handler function.
835 *
836 * Return value: new blank node ID to use
837 */
838typedef unsigned char* (*raptor_generate_bnodeid_handler)(void *user_data, unsigned char* user_bnodeid);
839
840/**
841 * raptor_namespace_handler:
842 * @user_data: user data
843 * @nspace: #raptor_namespace declared
844 *
845 * XML Namespace declaration reporting handler set by
846 * raptor_parser_set_namespace_handler().
847 */
848typedef void (*raptor_namespace_handler)(void* user_data, raptor_namespace *nspace);
849
850
851/**
852 * raptor_www_write_bytes_handler:
853 * @www: WWW object
854 * @userdata: user data
855 * @ptr: data pointer
856 * @size: size of individual item
857 * @nmemb: number of items
858 *
859 * Receiving bytes of data from WWW retrieval handler.
860 *
861 * Set by raptor_www_set_write_bytes_handler().
862 */
863typedef void (*raptor_www_write_bytes_handler)(raptor_www* www, void *userdata, const void *ptr, size_t size, size_t nmemb);
864
865/**
866 * raptor_www_content_type_handler:
867 * @www: WWW object
868 * @userdata: user data
869 * @content_type: content type seen
870 *
871 * Receiving Content-Type: header from WWW retrieval handler.
872 *
873 * Set by raptor_www_set_content_type_handler().
874 */
875typedef void (*raptor_www_content_type_handler)(raptor_www* www, void *userdata, const char *content_type);
876
877/**
878 * raptor_www_final_uri_handler:
879 * @www: WWW object
880 * @userdata: user data
881 * @final_uri: final URI seen
882 *
883 * Receiving the final resolved URI from a WWW retrieval
884 *
885 * Set by raptor_www_set_final_uri_handler().
886 */
887typedef void (*raptor_www_final_uri_handler)(raptor_www* www, void *userdata, raptor_uri *final_uri);
888
889/**
890 * raptor_uri_filter_func:
891 * @user_data: user data
892 * @uri: #raptor_uri URI to check
893 *
894 * Callback function for #raptor_www_set_uri_filter
895 *
896 * Return value: non-0 to filter the URI
897 */
898typedef int (*raptor_uri_filter_func)(void *user_data, raptor_uri* uri);
899
900
901/**
902 * raptor_world_flag:
903 * @RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE: if set (non-0 value) - save/restore the libxml generic error handler when raptor library initializes (default set)
904 * @RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE: if set (non-0 value) - save/restore the libxml structured error handler when raptor library terminates (default set)
905 * @RAPTOR_WORLD_FLAG_URI_INTERNING: if set (non-0 value) - each URI is saved interned in-memory and reused (default set)
906 * @RAPTOR_WORLD_FLAG_WWW_SKIP_INIT_FINISH: if set (non-0 value) the raptor will neither initialise or terminate the lower level WWW library. Usually in raptor initialising either curl_global_init (for libcurl) are called and in raptor cleanup, curl_global_cleanup is called. This flag allows the application finer control over these libraries such as setting other global options or potentially calling and terminating raptor several times. It does mean that applications which use this call must do their own extra work in order to allocate and free all resources to the system.
907 *
908 * Raptor world flags
909 *
910 * These are used by raptor_world_set_flags() to control raptor-wide
911 * options across classes. These must be set before
912 * raptor_world_open() is called explicitly or implicitly (by
913 * creating a raptor object). There is no enumeration function for
914 * these flags because they are not user options and must be set
915 * before the library is initialised. For similar reasons, there is
916 * no get function.
917 *
918 * If any libxml handler saving/restoring is enabled, any existing
919 * handler and context is saved before parsing and restored
920 * afterwards. Otherwise, no saving/restoring is performed.
921 *
922 */
923typedef enum {
924 RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE = 1,
925 RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE = 2,
926 RAPTOR_WORLD_FLAG_URI_INTERNING = 3,
927 RAPTOR_WORLD_FLAG_WWW_SKIP_INIT_FINISH = 4
928} raptor_world_flag;
929
930
931/**
932 * raptor_data_compare_handler:
933 * @data1: first data object
934 * @data2: second data object
935 *
936 * Function to compare two data objects - signature like strcmp() and function pssed to qsort()
937 *
938 * Designed to be passed into generic data structure constructors
939 * like raptor_new_avltree().
940 *
941 * Return value: compare value <0 if @data1 is before @data2, =0 if equal, >0 if @data1 is after @data2
942 */
943typedef int (*raptor_data_compare_handler)(const void* data1, const void* data2);
944
945
946/**
947 * raptor_data_malloc_handler:
948 * @size: data size
949 *
950 * Typedef for a function to allocate memory - signature like malloc()
951 *
952 * Designed to be passed into constructors
953 * like raptor_www_fetch_to_string
954 *
955 * Return value: pointer to newly allocated memory or NULL on failure
956 */
957typedef void* (*raptor_data_malloc_handler)(size_t size);
958
959
960/**
961 * raptor_data_free_handler:
962 * @data: data object or NULL
963 *
964 * Typedef for function to free a data object - signature like free()
965 *
966 * Designed to be passed into generic data structure constructors
967 * like raptor_new_avltree(). If @data is NULL, nothing should be done.
968 */
969typedef void (*raptor_data_free_handler)(void* data);
970
971
972/**
973 * raptor_data_context_free_handler:
974 * @context: context data for the free function
975 * @object: object to free
976 *
977 * Handler function for freeing a sequence item with a contextual pointer.
978 *
979 * Set by raptor_new_sequence_with_context().
980*/
981typedef void (*raptor_data_context_free_handler)(void* context, void* object);
982
983/**
984 * raptor_data_print_handler:
985 * @object: object to print
986 * @fh: FILE* to print to
987 *
988 * Handler function for printing an object to a stream.
989 *
990 * Set by raptor_new_sequence()
991 *
992 * Return value: non-0 on failure
993 */
994typedef int (*raptor_data_print_handler)(void *object, FILE *fh);
995
996/**
997 * raptor_data_context_print_handler:
998 * @context: context data for the print function
999 * @object: object to print
1000 * @fh: FILE* to print to
1001 *
1002 * Function function for printing an object with data context to a stream.
1003 *
1004 * Set by raptor_new_sequence_with_context()
1005 *
1006 * Return value: non-0 on failure
1007 */
1008typedef int (*raptor_data_context_print_handler)(void *context, void *object, FILE *fh);
1009
1010/**
1011 * raptor_stringbuffer:
1012 *
1013 * Raptor string buffer class
1014 */
1015typedef struct raptor_stringbuffer_s raptor_stringbuffer;
1016
1017
1018/* Public functions */
1019
1020#define raptor_new_world() raptor_new_world_internal(RAPTOR_VERSION)
1021/* The real target of the raptor_new_world() macro */
1022RAPTOR_API
1023raptor_world *raptor_new_world_internal(unsigned int version_decimal);
1024RAPTOR_API
1025int raptor_world_open(raptor_world* world);
1026RAPTOR_API
1027void raptor_free_world(raptor_world* world);
1028RAPTOR_API
1029int raptor_world_set_libxslt_security_preferences(raptor_world *world, void *security_preferences);
1030RAPTOR_API
1031int raptor_world_set_flag(raptor_world *world, raptor_world_flag flag, int value);
1032RAPTOR_API
1033int raptor_world_set_log_handler(raptor_world *world, void *user_data, raptor_log_handler handler);
1034RAPTOR_API
1035void raptor_world_set_generate_bnodeid_handler(raptor_world* world, void *user_data, raptor_generate_bnodeid_handler handler);
1036RAPTOR_API
1037unsigned char* raptor_world_generate_bnodeid(raptor_world *world);
1038RAPTOR_API
1039void raptor_world_set_generate_bnodeid_parameters(raptor_world* world, char *prefix, int base);
1040RAPTOR_API
1041const char* raptor_log_level_get_label(raptor_log_level level);
1042RAPTOR_API
1043const char* raptor_domain_get_label(raptor_domain domain);
1044
1045/* Names */
1046RAPTOR_API
1047int raptor_world_is_parser_name(raptor_world* world, const char *name);
1048RAPTOR_API
1049const char* raptor_world_guess_parser_name(raptor_world* world, raptor_uri *uri, const char *mime_type, const unsigned char *buffer, size_t len, const unsigned char *identifier);
1050RAPTOR_API
1051int raptor_world_is_serializer_name(raptor_world* world, const char *name);
1052
1053/* Syntax descriptions */
1054RAPTOR_API
1055const raptor_syntax_description* raptor_world_get_parser_description(raptor_world* world, unsigned int counter);
1056RAPTOR_API
1057const raptor_syntax_description* raptor_world_get_serializer_description(raptor_world* world, unsigned int counter);
1058RAPTOR_API
1059int raptor_syntax_description_validate(raptor_syntax_description* desc);
1060
1061RAPTOR_API
1062raptor_option raptor_world_get_option_from_uri(raptor_world* world, raptor_uri *uri);
1063
1064
1065/* Term Class */
1066RAPTOR_API
1067raptor_term* raptor_new_term_from_uri(raptor_world* world, raptor_uri* uri);
1068RAPTOR_API
1069raptor_term* raptor_new_term_from_counted_uri_string(raptor_world* world, const unsigned char *uri_string, size_t length);
1070RAPTOR_API
1071raptor_term* raptor_new_term_from_uri_string(raptor_world* world, const unsigned char *uri_string);
1072RAPTOR_API
1073raptor_term* raptor_new_term_from_literal(raptor_world* world, const unsigned char* literal, raptor_uri* datatype, const unsigned char* language);
1074RAPTOR_API
1075raptor_term* raptor_new_term_from_counted_literal(raptor_world* world, const unsigned char* literal, size_t literal_len, raptor_uri* datatype, const unsigned char* language, unsigned char language_len);
1076RAPTOR_API
1077raptor_term* raptor_new_term_from_blank(raptor_world* world, const unsigned char* blank);
1078RAPTOR_API
1079raptor_term* raptor_new_term_from_counted_blank(raptor_world* world, const unsigned char* blank, size_t length);
1080RAPTOR_API
1081raptor_term* raptor_new_term_from_counted_string(raptor_world* world, unsigned char* string, size_t length);
1082RAPTOR_API
1083raptor_term* raptor_term_copy(raptor_term* term);
1084RAPTOR_API
1085int raptor_term_compare(const raptor_term *t1, const raptor_term *t2);
1086RAPTOR_API
1087int raptor_term_equals(raptor_term* t1, raptor_term* t2);
1088RAPTOR_API
1089void raptor_free_term(raptor_term *term);
1090
1091RAPTOR_API
1092unsigned char* raptor_term_to_counted_string(raptor_term *term, size_t* len_p);
1093RAPTOR_API
1094unsigned char* raptor_term_to_string(raptor_term *term);
1095RAPTOR_API
1096int raptor_term_escaped_write(const raptor_term *term, unsigned int flags, raptor_iostream* iostr);
1097RAPTOR_API RAPTOR_DEPRECATED
1098int raptor_term_ntriples_write(const raptor_term *term, raptor_iostream* iostr);
1099RAPTOR_API
1100int raptor_uri_turtle_write(raptor_world *world, raptor_iostream* iostr, raptor_uri* uri, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1101RAPTOR_API
1102int raptor_term_turtle_write(raptor_iostream* iostr, raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1103RAPTOR_API
1104unsigned char* raptor_uri_to_turtle_counted_string(raptor_world *world, raptor_uri* uri, raptor_namespace_stack *nstack, raptor_uri *base_uri, size_t *len_p);
1105RAPTOR_API
1106unsigned char* raptor_uri_to_turtle_string(raptor_world *world, raptor_uri* uri, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1107RAPTOR_API
1108unsigned char* raptor_term_to_turtle_counted_string(raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri, size_t *len_p);
1109RAPTOR_API
1110unsigned char* raptor_term_to_turtle_string(raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1111
1112
1113/* Statement Class */
1114RAPTOR_API
1115void raptor_statement_init(raptor_statement *statement, raptor_world *world);
1116RAPTOR_API
1117void raptor_statement_clear(raptor_statement *statement);
1118RAPTOR_API
1119raptor_statement* raptor_new_statement(raptor_world *world);
1120RAPTOR_API
1121raptor_statement* raptor_new_statement_from_nodes(raptor_world* world, raptor_term *subject, raptor_term *predicate, raptor_term *object, raptor_term *graph);
1122RAPTOR_API
1123raptor_statement* raptor_statement_copy(raptor_statement *statement);
1124RAPTOR_API
1125void raptor_free_statement(raptor_statement *statement);
1126
1127RAPTOR_API
1128int raptor_statement_print(const raptor_statement * statement, FILE *stream);
1129RAPTOR_API
1130int raptor_statement_print_as_ntriples(const raptor_statement * statement, FILE *stream);
1131RAPTOR_API
1132int raptor_statement_compare(const raptor_statement *s1, const raptor_statement *s2);
1133RAPTOR_API
1134int raptor_statement_equals(const raptor_statement* s1, const raptor_statement* s2);
1135
1136
1137/* Parser Class */
1138RAPTOR_API
1139raptor_parser* raptor_new_parser(raptor_world* world, const char *name);
1140RAPTOR_API
1141raptor_parser* raptor_new_parser_for_content(raptor_world* world, raptor_uri *uri, const char *mime_type, const unsigned char *buffer, size_t len, const unsigned char *identifier);
1142RAPTOR_API
1143void raptor_free_parser(raptor_parser* parser);
1144
1145/* methods */
1146
1147/* Handlers */
1148RAPTOR_API
1149void raptor_parser_set_statement_handler(raptor_parser* parser, void *user_data, raptor_statement_handler handler);
1150RAPTOR_API
1151void raptor_parser_set_graph_mark_handler(raptor_parser* parser, void *user_data, raptor_graph_mark_handler handler);
1152RAPTOR_API
1153void raptor_parser_set_namespace_handler(raptor_parser* parser, void *user_data, raptor_namespace_handler handler);
1154RAPTOR_API
1155void raptor_parser_set_uri_filter(raptor_parser* parser, raptor_uri_filter_func filter, void* user_data);
1156RAPTOR_API
1157raptor_locator* raptor_parser_get_locator(raptor_parser* rdf_parser);
1158
1159
1160/* Parsing functions */
1161RAPTOR_API
1162int raptor_parser_parse_start(raptor_parser *rdf_parser, raptor_uri *uri);
1163RAPTOR_API
1164int raptor_parser_parse_chunk(raptor_parser* rdf_parser, const unsigned char *buffer, size_t len, int is_end);
1165RAPTOR_API
1166int raptor_parser_parse_file_stream(raptor_parser* rdf_parser, FILE *stream, const char *filename, raptor_uri *base_uri);
1167RAPTOR_API
1168int raptor_parser_parse_file(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri);
1169RAPTOR_API
1170int raptor_parser_parse_uri(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri);
1171RAPTOR_API
1172int raptor_parser_parse_uri_with_connection(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri, void *connection);
1173RAPTOR_API
1174int raptor_parser_parse_iostream(raptor_parser* rdf_parser, raptor_iostream *iostr, raptor_uri *base_uri);
1175RAPTOR_API
1176void raptor_parser_parse_abort(raptor_parser* rdf_parser);
1177RAPTOR_API
1178const char* raptor_parser_get_name(raptor_parser *rdf_parser);
1179RAPTOR_API
1180const raptor_syntax_description* raptor_parser_get_description(raptor_parser *rdf_parser);
1181
1182/* parser option methods */
1183RAPTOR_API
1184int raptor_parser_set_option(raptor_parser *parser, raptor_option option, const char* string, int integer);
1185RAPTOR_API
1186int raptor_parser_get_option(raptor_parser *parser, raptor_option option, char** string_p, int* integer_p);
1187
1188/* parser utility methods */
1189RAPTOR_API
1190const char* raptor_parser_get_accept_header(raptor_parser* rdf_parser);
1191RAPTOR_API
1192raptor_world* raptor_parser_get_world(raptor_parser* rdf_parser);
1193RAPTOR_API
1194raptor_uri* raptor_parser_get_graph(raptor_parser* rdf_parser);
1195
1196
1197/* Locator Class */
1198/* methods */
1199RAPTOR_API
1200int raptor_locator_print(raptor_locator* locator, FILE *stream);
1201RAPTOR_API
1202int raptor_locator_format(char *buffer, size_t length, raptor_locator* locator);
1203RAPTOR_API
1204int raptor_locator_line(raptor_locator *locator);
1205RAPTOR_API
1206int raptor_locator_column(raptor_locator *locator);
1207RAPTOR_API
1208int raptor_locator_byte(raptor_locator *locator);
1209RAPTOR_API
1210const char* raptor_locator_file(raptor_locator *locator);
1211RAPTOR_API
1212const char* raptor_locator_uri(raptor_locator *locator);
1213
1214
1215/* Serializer Class */
1216RAPTOR_API
1217raptor_serializer* raptor_new_serializer(raptor_world* world, const char *name);
1218RAPTOR_API
1219void raptor_free_serializer(raptor_serializer* rdf_serializer);
1220
1221/* methods */
1222RAPTOR_API
1223int raptor_serializer_start_to_iostream(raptor_serializer *rdf_serializer, raptor_uri *uri, raptor_iostream *iostream);
1224RAPTOR_API
1225int raptor_serializer_start_to_filename(raptor_serializer *rdf_serializer, const char *filename);
1226RAPTOR_API
1227int raptor_serializer_start_to_string(raptor_serializer *rdf_serializer, raptor_uri *uri, void **string_p, size_t *length_p);
1228RAPTOR_API
1229int raptor_serializer_start_to_file_handle(raptor_serializer *rdf_serializer, raptor_uri *uri, FILE *fh);
1230RAPTOR_API
1231int raptor_serializer_set_namespace(raptor_serializer* rdf_serializer, raptor_uri *uri, const unsigned char *prefix);
1232RAPTOR_API
1233int raptor_serializer_set_namespace_from_namespace(raptor_serializer* rdf_serializer, raptor_namespace *nspace);
1234RAPTOR_API
1235int raptor_serializer_serialize_statement(raptor_serializer* rdf_serializer, raptor_statement *statement);
1236RAPTOR_API
1237int raptor_serializer_serialize_end(raptor_serializer *rdf_serializer);
1238RAPTOR_API
1239raptor_iostream* raptor_serializer_get_iostream(raptor_serializer *serializer);
1240RAPTOR_API
1241raptor_locator* raptor_serializer_get_locator(raptor_serializer *rdf_serializer);
1242RAPTOR_API
1243int raptor_serializer_flush(raptor_serializer *rdf_serializer);
1244RAPTOR_API
1245const raptor_syntax_description* raptor_serializer_get_description(raptor_serializer *rdf_serializer);
1246
1247/* serializer option methods */
1248RAPTOR_API
1249int raptor_serializer_set_option(raptor_serializer *serializer, raptor_option option, const char* string, int integer);
1250RAPTOR_API
1251int raptor_serializer_get_option(raptor_serializer *serializer, raptor_option option, char** string_p, int* integer_p);
1252
1253/* utility methods */
1254RAPTOR_API
1255raptor_world* raptor_serializer_get_world(raptor_serializer* rdf_serializer);
1256
1257
1258/* memory functions */
1259RAPTOR_API
1260void raptor_free_memory(void *ptr);
1261RAPTOR_API
1262void* raptor_alloc_memory(size_t size);
1263RAPTOR_API
1264void* raptor_calloc_memory(size_t nmemb, size_t size);
1265
1266
1267/* URI Class */
1268RAPTOR_API
1269raptor_uri* raptor_new_uri_from_counted_string(raptor_world* world, const unsigned char *uri_string, size_t length);
1270RAPTOR_API
1271raptor_uri* raptor_new_uri(raptor_world* world, const unsigned char *uri_string);
1272RAPTOR_API
1273raptor_uri* raptor_new_uri_from_uri_local_name(raptor_world* world, raptor_uri *uri, const unsigned char *local_name);
1274RAPTOR_API
1275raptor_uri* raptor_new_uri_relative_to_base(raptor_world* world, raptor_uri *base_uri, const unsigned char *uri_string);
1276RAPTOR_API
1277raptor_uri* raptor_new_uri_relative_to_base_counted(raptor_world* world, raptor_uri *base_uri, const unsigned char *uri_string, size_t uri_len);
1278RAPTOR_API
1279raptor_uri* raptor_new_uri_from_id(raptor_world* world, raptor_uri *base_uri, const unsigned char *id);
1280RAPTOR_API
1281raptor_uri* raptor_new_uri_from_uri_or_file_string(raptor_world* world, raptor_uri* base_uri, const unsigned char* uri_or_file_string);
1282RAPTOR_API
1283raptor_uri* raptor_new_uri_for_rdf_concept(raptor_world* world, const unsigned char *name);
1284RAPTOR_API
1285raptor_uri* raptor_new_uri_for_xmlbase(raptor_uri* old_uri);
1286RAPTOR_API
1287raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri);
1288RAPTOR_API
1289void raptor_free_uri(raptor_uri *uri);
1290
1291/* methods */
1292RAPTOR_API
1293int raptor_uri_equals(raptor_uri* uri1, raptor_uri* uri2);
1294RAPTOR_API
1295int raptor_uri_compare(raptor_uri* uri1, raptor_uri* uri2);
1296RAPTOR_API
1297raptor_uri* raptor_uri_copy(raptor_uri *uri);
1298RAPTOR_API
1299unsigned char* raptor_uri_as_string(raptor_uri *uri);
1300RAPTOR_API
1301unsigned char* raptor_uri_as_counted_string(raptor_uri *uri, size_t* len_p);
1302RAPTOR_API
1303unsigned char* raptor_uri_to_relative_counted_uri_string(raptor_uri *base_uri, raptor_uri *reference_uri, size_t *length_p);
1304RAPTOR_API
1305unsigned char* raptor_uri_to_relative_uri_string(raptor_uri *base_uri, raptor_uri *reference_uri);
1306RAPTOR_API
1307int raptor_uri_print(const raptor_uri* uri, FILE *stream);
1308RAPTOR_API
1309unsigned char* raptor_uri_to_counted_string(raptor_uri *uri, size_t *len_p);
1310RAPTOR_API
1311unsigned char* raptor_uri_to_string(raptor_uri *uri);
1312RAPTOR_API
1313raptor_world* raptor_uri_get_world(raptor_uri *uri);
1314RAPTOR_API
1315int raptor_uri_file_exists(raptor_uri* uri);
1316RAPTOR_API
1317int raptor_uri_escaped_write(raptor_uri* uri, raptor_uri* base_uri, unsigned int flags, raptor_iostream *iostr);
1318
1319/* XML utility functions */
1320RAPTOR_API
1321int raptor_xml_escape_string_any(raptor_world* world, const unsigned char *string, size_t len, unsigned char *buffer, size_t length, char quote, int xml_version);
1322RAPTOR_API
1323int raptor_xml_escape_string_any_write(const unsigned char *string, size_t len, char quote, int xml_version, raptor_iostream* iostr);
1324RAPTOR_API
1325int raptor_xml_escape_string(raptor_world *world, const unsigned char *string, size_t len, unsigned char *buffer, size_t length, char quote);
1326RAPTOR_API
1327int raptor_xml_escape_string_write(const unsigned char *string, size_t len, char quote, raptor_iostream* iostr);
1328RAPTOR_API
1329int raptor_xml_name_check(const unsigned char *string, size_t length, int xml_version);
1330
1331
1332/* portable vsnprintf utility function */
1333RAPTOR_API RAPTOR_DEPRECATED
1334char* raptor_vsnprintf(const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(1, 0);
1335RAPTOR_API
1336int raptor_vsnprintf2(char *buffer, size_t size, const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(3, 0);
1337RAPTOR_API
1338int raptor_snprintf(char *buffer, size_t size, const char *format, ...) RAPTOR_PRINTF_FORMAT(3, 4);
1339RAPTOR_API
1340int raptor_vasprintf(char **ret, const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(2, 0);
1341
1342/* RFC2396 URI resolving functions */
1343RAPTOR_API
1344size_t raptor_uri_resolve_uri_reference(const unsigned char *base_uri, const unsigned char *reference_uri, unsigned char* buffer, size_t length);
1345
1346/* URI String utility functions */
1347RAPTOR_API
1348unsigned char* raptor_uri_filename_to_uri_string(const char *filename);
1349RAPTOR_API
1350int raptor_uri_filename_exists(const unsigned char* path);
1351RAPTOR_API
1352char* raptor_uri_uri_string_to_filename(const unsigned char *uri_string);
1353RAPTOR_API
1354char* raptor_uri_uri_string_to_filename_fragment(const unsigned char *uri_string, unsigned char **fragment_p);
1355RAPTOR_API
1356int raptor_uri_uri_string_is_file_uri(const unsigned char* uri_string);
1357RAPTOR_API
1358int raptor_stringbuffer_append_uri_escaped_counted_string(raptor_stringbuffer* sb, const char* string, size_t length, int space_is_plus);
1359RAPTOR_API
1360char* raptor_uri_uri_string_to_counted_filename_fragment(const unsigned char *uri_string, size_t* len_p, unsigned char **fragment_p, size_t* fragment_len_p);
1361RAPTOR_API
1362int raptor_uri_uri_string_is_absolute(const unsigned char* uri_string);
1363
1364
1365/**
1366 * RAPTOR_RDF_MS_URI:
1367 *
1368 * RDF Namespace URI (rdf:).
1369 *
1370 * Copy with raptor_uri_copy() to use.
1371 */
1372#define RAPTOR_RDF_MS_URI raptor_rdf_namespace_uri
1373
1374/**
1375 * RAPTOR_RDF_SCHEMA_URI:
1376 *
1377 * RDF Schema Namespace URI (rdfs:).
1378 *
1379 * Copy with raptor_uri_copy() to use.
1380 */
1381#define RAPTOR_RDF_SCHEMA_URI raptor_rdf_schema_namespace_uri
1382
1383/**
1384 * RAPTOR_XMLSCHEMA_DATATYPES_URI:
1385 *
1386 * XML Schema Datatypes URI (xsd:).
1387 *
1388 * Copy with raptor_uri_copy() to use.
1389 */
1390#define RAPTOR_XMLSCHEMA_DATATYPES_URI raptor_xmlschema_datatypes_namespace_uri
1391
1392/**
1393 * RAPTOR_OWL_URI:
1394 *
1395 * OWL Namespace URI (owl:).
1396 *
1397 * Copy with raptor_uri_copy() to use.
1398 */
1399#define RAPTOR_OWL_URI raptor_owl_namespace_uri
1400
1401
1402/* raptor_www */
1403RAPTOR_API
1404raptor_www* raptor_new_www(raptor_world* world);
1405RAPTOR_API
1406raptor_www* raptor_new_www_with_connection(raptor_world* world, void* connection);
1407RAPTOR_API
1408void raptor_free_www(raptor_www *www);
1409RAPTOR_API
1410int raptor_www_set_ssl_cert_options(raptor_www* www, const char* cert_filename, const char* cert_type, const char* cert_passphrase);
1411RAPTOR_API
1412int raptor_www_set_ssl_verify_options(raptor_www* www, int verify_peer, int verify_host);
1413RAPTOR_API
1414void raptor_www_set_user_agent(raptor_www *www, const char *user_agent);
1415RAPTOR_API
1416void raptor_www_set_proxy(raptor_www *www, const char *proxy);
1417RAPTOR_API
1418void raptor_www_set_http_accept(raptor_www *www, const char *value);
1419RAPTOR_API
1420void raptor_www_set_write_bytes_handler(raptor_www *www, raptor_www_write_bytes_handler handler, void *user_data);
1421RAPTOR_API
1422void raptor_www_set_content_type_handler(raptor_www *www, raptor_www_content_type_handler handler, void *user_data);
1423RAPTOR_API
1424void raptor_www_set_final_uri_handler(raptor_www* www, raptor_www_final_uri_handler handler, void *user_data);
1425RAPTOR_API
1426void raptor_www_set_uri_filter(raptor_www* www, raptor_uri_filter_func filter, void* user_data);
1427RAPTOR_API
1428void raptor_www_set_connection_timeout(raptor_www* www, int timeout);
1429RAPTOR_API
1430int raptor_www_set_http_cache_control(raptor_www* www, const char* cache_control);
1431RAPTOR_API
1432int raptor_www_fetch(raptor_www *www, raptor_uri *uri);
1433RAPTOR_API
1434int raptor_www_fetch_to_string(raptor_www *www, raptor_uri *uri, void **string_p, size_t *length_p, raptor_data_malloc_handler const malloc_handler);
1435RAPTOR_API
1436void* raptor_www_get_connection(raptor_www *www);
1437RAPTOR_API
1438void raptor_www_abort(raptor_www *www, const char *reason);
1439RAPTOR_API
1440raptor_uri* raptor_www_get_final_uri(raptor_www* www);
1441
1442
1443/* XML QNames Class */
1444RAPTOR_API
1445raptor_qname* raptor_new_qname(raptor_namespace_stack *nstack, const unsigned char *name, const unsigned char *value);
1446RAPTOR_API
1447raptor_qname* raptor_new_qname_from_namespace_local_name(raptor_world* world, raptor_namespace *ns, const unsigned char *local_name, const unsigned char *value);
1448
1449/* methods */
1450RAPTOR_API
1451raptor_qname* raptor_qname_copy(raptor_qname *qname);
1452RAPTOR_API
1453void raptor_free_qname(raptor_qname* name);
1454RAPTOR_API
1455int raptor_qname_equal(raptor_qname *name1, raptor_qname *name2);
1456RAPTOR_API
1457unsigned char* raptor_qname_to_counted_name(raptor_qname *qname, size_t* length_p);
1458RAPTOR_API
1459const raptor_namespace* raptor_qname_get_namespace(raptor_qname* name);
1460RAPTOR_API
1461const unsigned char* raptor_qname_get_local_name(raptor_qname* name);
1462RAPTOR_API
1463const unsigned char* raptor_qname_get_value(raptor_qname* name);
1464RAPTOR_API
1465const unsigned char* raptor_qname_get_counted_value(raptor_qname* name, size_t* length_p);
1466RAPTOR_API
1467int raptor_qname_write(raptor_qname *qname, raptor_iostream* iostr);
1468
1469/* QName String utility functions */
1470RAPTOR_API
1471raptor_uri* raptor_qname_string_to_uri(raptor_namespace_stack *nstack, const unsigned char *name, size_t name_len);
1472RAPTOR_API
1473unsigned char* raptor_qname_format_as_xml(const raptor_qname *qname, size_t *length_p);
1474
1475/* XML Namespaces Stack class */
1476RAPTOR_API
1477raptor_namespace* raptor_new_namespace_from_uri(raptor_namespace_stack *nstack, const unsigned char *prefix, raptor_uri* ns_uri, int depth);
1478RAPTOR_API
1479raptor_namespace_stack* raptor_new_namespaces(raptor_world* world, int defaults);
1480RAPTOR_API
1481int raptor_namespaces_init(raptor_world* world, raptor_namespace_stack *nstack, int defaults);
1482RAPTOR_API
1483void raptor_namespaces_clear(raptor_namespace_stack *nstack);
1484RAPTOR_API
1485void raptor_free_namespaces(raptor_namespace_stack *nstack);
1486
1487/* methods */
1488RAPTOR_API
1489void raptor_namespaces_start_namespace(raptor_namespace_stack *nstack, raptor_namespace *nspace);
1490RAPTOR_API
1491int raptor_namespaces_start_namespace_full(raptor_namespace_stack *nstack, const unsigned char *prefix, const unsigned char *ns_uri_string, int depth);
1492RAPTOR_API
1493void raptor_namespaces_end_for_depth(raptor_namespace_stack *nstack, int depth);
1494RAPTOR_API
1495raptor_namespace* raptor_namespaces_get_default_namespace(raptor_namespace_stack *nstack);
1496RAPTOR_API
1497raptor_namespace* raptor_namespaces_find_namespace(raptor_namespace_stack *nstack, const unsigned char *prefix, int prefix_length);
1498RAPTOR_API
1499raptor_namespace* raptor_namespaces_find_namespace_by_uri(raptor_namespace_stack *nstack, raptor_uri *ns_uri);
1500RAPTOR_API
1501int raptor_namespaces_namespace_in_scope(raptor_namespace_stack *nstack, const raptor_namespace *nspace);
1502RAPTOR_API
1503raptor_qname* raptor_new_qname_from_namespace_uri(raptor_namespace_stack *nstack, raptor_uri *uri, int xml_version);
1504
1505
1506/* XML Namespace Class */
1507RAPTOR_API
1508raptor_namespace* raptor_new_namespace(raptor_namespace_stack *nstack, const unsigned char *prefix, const unsigned char *ns_uri_string, int depth);
1509RAPTOR_API
1510void raptor_free_namespace(raptor_namespace *ns);
1511RAPTOR_API
1512int raptor_namespace_stack_start_namespace(raptor_namespace_stack *nstack, raptor_namespace *ns, int new_depth);
1513RAPTOR_API
1514raptor_uri* raptor_namespace_get_uri(const raptor_namespace *ns);
1515RAPTOR_API
1516const unsigned char* raptor_namespace_get_prefix(const raptor_namespace *ns);
1517RAPTOR_API
1518const unsigned char* raptor_namespace_get_counted_prefix(const raptor_namespace *ns, size_t *length_p);
1519RAPTOR_API
1520unsigned char* raptor_namespace_format_as_xml(const raptor_namespace *ns, size_t *length_p);
1521RAPTOR_API
1522int raptor_namespace_write(raptor_namespace *ns, raptor_iostream* iostr);
1523
1524/* namespace string utility function */
1525RAPTOR_API
1526int raptor_xml_namespace_string_parse(const unsigned char *string, unsigned char **prefix, unsigned char **uri_string);
1527
1528/* Sequence class */
1529/**
1530 * raptor_sequence:
1531 *
1532 * Raptor sequence class
1533 */
1534typedef struct raptor_sequence_s raptor_sequence;
1535
1536/* Sequence Class */
1537RAPTOR_API
1538raptor_sequence* raptor_new_sequence(raptor_data_free_handler free_handler, raptor_data_print_handler print_handler);
1539RAPTOR_API
1540raptor_sequence* raptor_new_sequence_with_context(raptor_data_context_free_handler free_handler, raptor_data_context_print_handler print_handler, void* handler_context);
1541RAPTOR_API
1542void raptor_free_sequence(raptor_sequence* seq);
1543
1544/* methods */
1545RAPTOR_API
1546int raptor_sequence_size(raptor_sequence* seq);
1547RAPTOR_API
1548int raptor_sequence_set_at(raptor_sequence* seq, int idx, void *data);
1549RAPTOR_API
1550int raptor_sequence_push(raptor_sequence* seq, void *data);
1551RAPTOR_API
1552int raptor_sequence_shift(raptor_sequence* seq, void *data);
1553RAPTOR_API
1554void* raptor_sequence_get_at(raptor_sequence* seq, int idx);
1555RAPTOR_API
1556void* raptor_sequence_pop(raptor_sequence* seq);
1557RAPTOR_API
1558void* raptor_sequence_unshift(raptor_sequence* seq);
1559RAPTOR_API
1560void* raptor_sequence_delete_at(raptor_sequence* seq, int idx);
1561
1562RAPTOR_API
1563void raptor_sequence_sort(raptor_sequence* seq, raptor_data_compare_handler compare);
1564RAPTOR_API
1565int raptor_sequence_swap(raptor_sequence* seq, int i, int j);
1566RAPTOR_API
1567int raptor_sequence_reverse(raptor_sequence* seq, int start_index, int length);
1568RAPTOR_API
1569int raptor_sequence_next_permutation(raptor_sequence *seq, raptor_data_compare_handler compare);
1570
1571/* helper for printing sequences of strings */
1572RAPTOR_API
1573int raptor_sequence_print(raptor_sequence* seq, FILE* fh);
1574RAPTOR_API
1575int raptor_sequence_join(raptor_sequence* dest, raptor_sequence *src);
1576
1577
1578/* Unicode and UTF8 */
1579
1580/**
1581 * raptor_unichar:
1582 *
1583 * raptor Unicode codepoint
1584 */
1585typedef unsigned long raptor_unichar;
1586RAPTOR_API
1587int raptor_unicode_utf8_string_put_char(raptor_unichar c, unsigned char *output, size_t length);
1588RAPTOR_API
1589int raptor_unicode_utf8_string_get_char(const unsigned char *input, size_t length, raptor_unichar *output);
1590RAPTOR_API
1591int raptor_unicode_is_xml11_namestartchar(raptor_unichar c);
1592RAPTOR_API
1593int raptor_unicode_is_xml10_namestartchar(raptor_unichar c);
1594RAPTOR_API
1595int raptor_unicode_is_xml11_namechar(raptor_unichar c);
1596RAPTOR_API
1597int raptor_unicode_is_xml10_namechar(raptor_unichar c);
1598RAPTOR_API
1599int raptor_unicode_check_utf8_string(const unsigned char *string, size_t length);
1600RAPTOR_API
1601int raptor_unicode_utf8_strlen(const unsigned char *string, size_t length);
1602RAPTOR_API
1603size_t raptor_unicode_utf8_substr(unsigned char* dest, size_t* dest_length_p, const unsigned char* src, size_t src_length, int startingLoc, int length);
1604
1605/* Stringbuffer Class */
1606RAPTOR_API
1607raptor_stringbuffer* raptor_new_stringbuffer(void);
1608RAPTOR_API
1609void raptor_free_stringbuffer(raptor_stringbuffer *stringbuffer);
1610
1611/* methods */
1612RAPTOR_API
1613int raptor_stringbuffer_append_counted_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, size_t length, int do_copy);
1614RAPTOR_API
1615int raptor_stringbuffer_append_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, int do_copy);
1616RAPTOR_API
1617int raptor_stringbuffer_append_decimal(raptor_stringbuffer* stringbuffer, int integer);
1618RAPTOR_API
1619int raptor_stringbuffer_append_hexadecimal(raptor_stringbuffer* stringbuffer, int hex);
1620RAPTOR_API
1621int raptor_stringbuffer_append_stringbuffer(raptor_stringbuffer* stringbuffer, raptor_stringbuffer* append);
1622RAPTOR_API
1623int raptor_stringbuffer_prepend_counted_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, size_t length, int do_copy);
1624RAPTOR_API
1625int raptor_stringbuffer_prepend_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, int do_copy);
1626RAPTOR_API
1627unsigned char* raptor_stringbuffer_as_string(raptor_stringbuffer* stringbuffer);
1628RAPTOR_API
1629size_t raptor_stringbuffer_length(raptor_stringbuffer* stringbuffer);
1630RAPTOR_API
1631int raptor_stringbuffer_copy_to_string(raptor_stringbuffer* stringbuffer, unsigned char *string, size_t length);
1632
1633/**
1634 * raptor_iostream_init_func:
1635 * @context: stream context data
1636 *
1637 * Handler function for #raptor_iostream initialising.
1638 *
1639 * Return value: non-0 on failure.
1640 */
1641typedef int (*raptor_iostream_init_func) (void *context);
1642
1643/**
1644 * raptor_iostream_finish_func:
1645 * @context: stream context data
1646 *
1647 * Handler function for #raptor_iostream terminating.
1648 *
1649 */
1650typedef void (*raptor_iostream_finish_func) (void *context);
1651
1652/**
1653 * raptor_iostream_write_byte_func
1654 * @context: stream context data
1655 * @byte: byte to write
1656 *
1657 * Handler function for implementing raptor_iostream_write_byte().
1658 *
1659 * Return value: non-0 on failure.
1660 */
1661typedef int (*raptor_iostream_write_byte_func) (void *context, const int byte);
1662
1663/**
1664 * raptor_iostream_write_bytes_func:
1665 * @context: stream context data
1666 * @ptr: pointer to bytes to write
1667 * @size: size of item
1668 * @nmemb: number of items
1669 *
1670 * Handler function for implementing raptor_iostream_write_bytes().
1671 *
1672 * Return value: non-0 on failure.
1673 */
1674typedef int (*raptor_iostream_write_bytes_func) (void *context, const void *ptr, size_t size, size_t nmemb);
1675
1676/**
1677 * raptor_iostream_write_end_func:
1678 * @context: stream context data
1679 *
1680 * Handler function for implementing raptor_iostream_write_end().
1681 *
1682 * Return value: non-0 on failure.
1683 */
1684typedef int (*raptor_iostream_write_end_func) (void *context);
1685
1686/**
1687 * raptor_iostream_read_bytes_func:
1688 * @context: stream context data
1689 * @ptr: pointer to buffer to read into
1690 * @size: size of buffer
1691 * @nmemb: number of items
1692 *
1693 * Handler function for implementing raptor_iostream_read_bytes().
1694 *
1695 * Return value: number of items read, 0 or < @size on EOF, <0 on failure
1696 */
1697typedef int (*raptor_iostream_read_bytes_func) (void *context, void *ptr, size_t size, size_t nmemb);
1698
1699/**
1700 * raptor_iostream_read_eof_func:
1701 * @context: stream context data
1702 *
1703 * Handler function for implementing raptor_iostream_read_eof().
1704 *
1705 * Return value: non-0 if EOF
1706 */
1707typedef int (*raptor_iostream_read_eof_func) (void *context);
1708
1709/**
1710 * raptor_iostream_handler:
1711 * @version: interface version. Presently 1 or 2.
1712 * @init: initialisation handler - optional, called at most once (V1)
1713 * @finish: finishing handler - optional, called at most once (V1)
1714 * @write_byte: write byte handler - required (for writing) (V1)
1715 * @write_bytes: write bytes handler - required (for writing) (V1)
1716 * @write_end: write end handler - optional (for writing), called at most once (V1)
1717 * @read_bytes: read bytes handler - required (for reading) (V2)
1718 * @read_eof: read EOF handler - required (for reading) (V2)
1719 *
1720 * I/O stream implementation handler structure.
1721 *
1722 */
1723typedef struct {
1724 int version;
1725
1726 /* V1 functions */
1727 raptor_iostream_init_func init;
1728 raptor_iostream_finish_func finish;
1729 raptor_iostream_write_byte_func write_byte;
1730 raptor_iostream_write_bytes_func write_bytes;
1731 raptor_iostream_write_end_func write_end;
1732
1733 /* V2 functions */
1734 raptor_iostream_read_bytes_func read_bytes;
1735 raptor_iostream_read_eof_func read_eof;
1736} raptor_iostream_handler;
1737
1738
1739/* I/O Stream Class */
1740RAPTOR_API
1741raptor_iostream* raptor_new_iostream_from_handler(raptor_world* world, void *user_data, const raptor_iostream_handler* const handler);
1742RAPTOR_API
1743raptor_iostream* raptor_new_iostream_to_sink(raptor_world* world);
1744RAPTOR_API
1745raptor_iostream* raptor_new_iostream_to_filename(raptor_world* world, const char *filename);
1746RAPTOR_API
1747raptor_iostream* raptor_new_iostream_to_file_handle(raptor_world* world, FILE *handle);
1748RAPTOR_API
1749raptor_iostream* raptor_new_iostream_to_string(raptor_world* world, void **string_p, size_t *length_p, raptor_data_malloc_handler const malloc_handler);
1750RAPTOR_API
1751raptor_iostream* raptor_new_iostream_from_sink(raptor_world* world);
1752RAPTOR_API
1753raptor_iostream* raptor_new_iostream_from_filename(raptor_world* world, const char *filename);
1754RAPTOR_API
1755raptor_iostream* raptor_new_iostream_from_file_handle(raptor_world* world, FILE *handle);
1756RAPTOR_API
1757raptor_iostream* raptor_new_iostream_from_string(raptor_world* world, void *string, size_t length);
1758RAPTOR_API
1759void raptor_free_iostream(raptor_iostream *iostr);
1760
1761RAPTOR_API
1762int raptor_iostream_write_bytes(const void *ptr, size_t size, size_t nmemb, raptor_iostream *iostr);
1763RAPTOR_API
1764int raptor_iostream_write_byte(const int byte, raptor_iostream *iostr);
1765RAPTOR_API
1766int raptor_iostream_write_end(raptor_iostream *iostr);
1767RAPTOR_API
1768int raptor_iostream_string_write(const void *string, raptor_iostream *iostr);
1769RAPTOR_API
1770int raptor_iostream_counted_string_write(const void *string, size_t len, raptor_iostream *iostr);
1771RAPTOR_API
1772unsigned long raptor_iostream_tell(raptor_iostream *iostr);
1773RAPTOR_API
1774int raptor_iostream_decimal_write(int integer, raptor_iostream* iostr);
1775RAPTOR_API
1776int raptor_iostream_hexadecimal_write(unsigned int integer, int width, raptor_iostream* iostr);
1777RAPTOR_API
1778int raptor_stringbuffer_write(raptor_stringbuffer *sb, raptor_iostream* iostr);
1779RAPTOR_API
1780int raptor_uri_write(raptor_uri *uri, raptor_iostream *iostr);
1781RAPTOR_API
1782int raptor_iostream_read_bytes(void *ptr, size_t size, size_t nmemb, raptor_iostream* iostr);
1783RAPTOR_API
1784int raptor_iostream_read_eof(raptor_iostream *iostr);
1785
1786/* I/O Stream utility functions */
1787
1788/**
1789 * raptor_escaped_write_bitflags:
1790 * @RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF : Allow \b \f,
1791 * @RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU : ALlow \t \n \r \u
1792 * @RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8 : Allow UTF-8 for printable U *
1793 * @RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES: Must escape #x00-#x20<>\"{}|^` in URIs
1794 * @RAPTOR_ESCAPED_WRITE_NTRIPLES_LITERAL: N-Triples literal
1795 * @RAPTOR_ESCAPED_WRITE_NTRIPLES_URI: N-Triples URI
1796 * @RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL: SPARQL literal: allows raw UTF8 for printable literals
1797 * @RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL: SPARQL long literal: no BS-escapes allowed
1798 * @RAPTOR_ESCAPED_WRITE_SPARQL_URI: SPARQL uri: have to escape certain characters
1799 * @RAPTOR_ESCAPED_WRITE_TURTLE_URI: Turtle 2013 URIs (like SPARQL)
1800 * @RAPTOR_ESCAPED_WRITE_TURTLE_LITERAL: Turtle 2013 literals (like SPARQL)
1801 * @RAPTOR_ESCAPED_WRITE_TURTLE_LONG_LITERAL: Turtle 2013 long literals (like SPARQL)
1802 * @RAPTOR_ESCAPED_WRITE_JSON_LITERAL: JSON literals: \b \f \t \r \n and \u \U
1803 *
1804 * Bit flags for raptor_string_escaped_write() and friends.
1805 */
1806typedef enum {
1807 RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF = 1,
1808 RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU = 2,
1809 RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8 = 4,
1810 RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES = 8,
1811
1812 /* N-Triples - favour writing \u, \U over UTF8 */
1813 RAPTOR_ESCAPED_WRITE_NTRIPLES_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU | RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF,
1814 RAPTOR_ESCAPED_WRITE_NTRIPLES_URI = RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES,
1815
1816 /* SPARQL literal: allows raw UTF8 for printable literals */
1817 RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8,
1818
1819 /* SPARQL long literal: no BS-escapes allowed */
1820 RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8,
1821
1822 /* SPARQL uri: have to escape certain characters */
1823 RAPTOR_ESCAPED_WRITE_SPARQL_URI = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8 | RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES,
1824
1825 /* Turtle (2013) escapes are like SPARQL */
1826 RAPTOR_ESCAPED_WRITE_TURTLE_URI = RAPTOR_ESCAPED_WRITE_SPARQL_URI,
1827 RAPTOR_ESCAPED_WRITE_TURTLE_LITERAL = RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL,
1828 RAPTOR_ESCAPED_WRITE_TURTLE_LONG_LITERAL = RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL,
1829
1830 /* JSON literals: \b \f \t \r \n and \u \U */
1831 RAPTOR_ESCAPED_WRITE_JSON_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU | RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF
1832} raptor_escaped_write_bitflags;
1833
1834
1835RAPTOR_API
1836int raptor_string_ntriples_write(const unsigned char *string, size_t len, const char delim, raptor_iostream *iostr);
1837RAPTOR_API
1838int raptor_bnodeid_ntriples_write(const unsigned char *bnodeid, size_t len, raptor_iostream *iostr);
1839RAPTOR_API RAPTOR_DEPRECATED
1840int raptor_string_python_write(const unsigned char *string, size_t len, const char delim, unsigned int mode, raptor_iostream *iostr);
1841RAPTOR_API
1842int raptor_statement_ntriples_write(const raptor_statement *statement, raptor_iostream* iostr, int write_graph_term);
1843RAPTOR_API
1844int raptor_string_escaped_write(const unsigned char *string, size_t len, const char delim, unsigned int flags, raptor_iostream *iostr);
1845
1846
1847/* Parser and Serializer options */
1848
1849/**
1850 * raptor_option_value_type:
1851 * @RAPTOR_OPTION_VALUE_TYPE_BOOL: Boolean integer value. Non-0 is true
1852 * @RAPTOR_OPTION_VALUE_TYPE_INT: Decimal integer value
1853 * @RAPTOR_OPTION_VALUE_TYPE_STRING: String value
1854 * @RAPTOR_OPTION_VALUE_TYPE_URI: URI String value.
1855 * @RAPTOR_OPTION_VALUE_TYPE_LAST: internal
1856 *
1857 * Option value types.
1858 */
1859typedef enum {
1860 RAPTOR_OPTION_VALUE_TYPE_BOOL,
1861 RAPTOR_OPTION_VALUE_TYPE_INT,
1862 RAPTOR_OPTION_VALUE_TYPE_STRING,
1863 RAPTOR_OPTION_VALUE_TYPE_URI,
1864 RAPTOR_OPTION_VALUE_TYPE_LAST = RAPTOR_OPTION_VALUE_TYPE_URI
1865} raptor_option_value_type;
1866
1867
1868/**
1869 * raptor_option_description:
1870 * @domain: domain ID
1871 * @option: option ID
1872 * @value_type: data type of option value
1873 * @name: short name for option
1874 * @name_len: length of @name
1875 * @label: description of option
1876 * @uri: URI identifying option
1877 *
1878 * Description of an option for a domain.
1879 */
1880typedef struct {
1881 raptor_domain domain;
1882 raptor_option option;
1883 raptor_option_value_type value_type;
1884 const char* name;
1885 size_t name_len;
1886 const char* label;
1887 raptor_uri* uri;
1888} raptor_option_description;
1889
1890
1891RAPTOR_API
1892unsigned int raptor_option_get_count(void);
1893RAPTOR_API
1894const char* raptor_option_get_value_type_label(const raptor_option_value_type type);
1895RAPTOR_API
1896void raptor_free_option_description(raptor_option_description* option_description);
1897RAPTOR_API
1898raptor_option_description* raptor_world_get_option_description(raptor_world* world, const raptor_domain domain, const raptor_option option);
1899
1900
1901/* SAX2 element Class (raptor_xml_element) */
1902RAPTOR_API
1903raptor_xml_element* raptor_new_xml_element(raptor_qname* name, const unsigned char* xml_language, raptor_uri* xml_base);
1904RAPTOR_API
1905raptor_xml_element* raptor_new_xml_element_from_namespace_local_name(raptor_namespace *ns, const unsigned char *name, const unsigned char *xml_language, raptor_uri *xml_base);
1906RAPTOR_API
1907void raptor_free_xml_element(raptor_xml_element *element);
1908
1909/* methods */
1910RAPTOR_API
1911raptor_qname* raptor_xml_element_get_name(raptor_xml_element *xml_element);
1912RAPTOR_API
1913void raptor_xml_element_set_attributes(raptor_xml_element* xml_element, raptor_qname **attributes, int count);
1914RAPTOR_API
1915raptor_qname** raptor_xml_element_get_attributes(raptor_xml_element* xml_element);
1916RAPTOR_API
1917int raptor_xml_element_get_attributes_count(raptor_xml_element* xml_element);
1918RAPTOR_API
1919int raptor_xml_element_declare_namespace(raptor_xml_element* xml_element, raptor_namespace *nspace);
1920RAPTOR_API
1921int raptor_xml_element_write(raptor_xml_element *element, raptor_namespace_stack *nstack, int is_empty, int is_end, int depth, raptor_iostream *iostr);
1922RAPTOR_API
1923int raptor_xml_element_is_empty(raptor_xml_element* xml_element);
1924RAPTOR_API
1925const unsigned char* raptor_xml_element_get_language(raptor_xml_element* xml_element);
1926
1927
1928/* XML Writer Class (raptor_xml_writer) */
1929RAPTOR_API
1930raptor_xml_writer* raptor_new_xml_writer(raptor_world* world, raptor_namespace_stack *nstack, raptor_iostream* iostr);
1931RAPTOR_API
1932void raptor_free_xml_writer(raptor_xml_writer* xml_writer);
1933
1934/* methods */
1935RAPTOR_API
1936void raptor_xml_writer_empty_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1937RAPTOR_API
1938void raptor_xml_writer_start_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1939RAPTOR_API
1940void raptor_xml_writer_end_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1941RAPTOR_API
1942void raptor_xml_writer_newline(raptor_xml_writer* xml_writer);
1943RAPTOR_API
1944void raptor_xml_writer_cdata(raptor_xml_writer* xml_writer, const unsigned char *s);
1945RAPTOR_API
1946void raptor_xml_writer_cdata_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1947RAPTOR_API
1948void raptor_xml_writer_raw(raptor_xml_writer* xml_writer, const unsigned char *s);
1949RAPTOR_API
1950void raptor_xml_writer_raw_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1951RAPTOR_API
1952void raptor_xml_writer_comment(raptor_xml_writer* xml_writer, const unsigned char *s);
1953RAPTOR_API
1954void raptor_xml_writer_comment_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1955RAPTOR_API
1956void raptor_xml_writer_flush(raptor_xml_writer* xml_writer);
1957RAPTOR_API
1958int raptor_xml_writer_set_option(raptor_xml_writer *xml_writer, raptor_option option, char* string, int integer);
1959RAPTOR_API
1960int raptor_xml_writer_get_option(raptor_xml_writer *xml_writer, raptor_option option, char** string_p, int* integer_p);
1961RAPTOR_API
1962int raptor_xml_writer_get_depth(raptor_xml_writer *xml_writer);
1963
1964/**
1965 * raptor_sax2_start_element_handler:
1966 * @user_data: user data
1967 * @xml_element: XML element
1968 *
1969 * SAX2 start element handler
1970 */
1971typedef void (*raptor_sax2_start_element_handler)(void *user_data, raptor_xml_element *xml_element);
1972
1973/**
1974 * raptor_sax2_end_element_handler:
1975 * @user_data: user data
1976 * @xml_element: XML element
1977 *
1978 * SAX2 end element handler
1979 */
1980typedef void (*raptor_sax2_end_element_handler)(void *user_data, raptor_xml_element* xml_element);
1981
1982/**
1983 * raptor_sax2_characters_handler:
1984 * @user_data: user data
1985 * @xml_element: XML element
1986 * @s: string
1987 * @len: string len
1988 *
1989 * SAX2 characters handler
1990 */
1991typedef void (*raptor_sax2_characters_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s, int len);
1992
1993/**
1994 * raptor_sax2_cdata_handler:
1995 * @user_data: user data
1996 * @xml_element: XML element
1997 * @s: string
1998 * @len: string len
1999
2000 * SAX2 CDATA section handler
2001 */
2002typedef void (*raptor_sax2_cdata_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s, int len);
2003
2004/**
2005 * raptor_sax2_comment_handler:
2006 * @user_data: user data
2007 * @xml_element: XML element
2008 * @s: string
2009 *
2010 * SAX2 XML comment handler
2011 */
2012typedef void (*raptor_sax2_comment_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s);
2013
2014/**
2015 * raptor_sax2_unparsed_entity_decl_handler:
2016 * @user_data: user data
2017 * @entityName: entity name
2018 * @base: base URI
2019 * @systemId: system ID
2020 * @publicId: public ID
2021 * @notationName: notation name
2022 *
2023 * SAX2 unparsed entity (NDATA) handler
2024 */
2025typedef void (*raptor_sax2_unparsed_entity_decl_handler)(void *user_data, const unsigned char* entityName, const unsigned char* base, const unsigned char* systemId, const unsigned char* publicId, const unsigned char* notationName);
2026
2027/**
2028 * raptor_sax2_external_entity_ref_handler:
2029 * @user_data: user data
2030 * @context: context
2031 * @base: base URI
2032 * @systemId: system ID
2033 * @publicId: public ID
2034 *
2035 * SAX2 external entity reference handler
2036 *
2037 * Return value: 0 if processing should not continue because of a
2038 * fatal error in the handling of the external entity.
2039 */
2040typedef int (*raptor_sax2_external_entity_ref_handler)(void *user_data, const unsigned char* context, const unsigned char* base, const unsigned char* systemId, const unsigned char* publicId);
2041
2042
2043/* SAX2 API */
2044RAPTOR_API
2045raptor_sax2* raptor_new_sax2(raptor_world *world, raptor_locator *locator, void* user_data);
2046RAPTOR_API
2047void raptor_free_sax2(raptor_sax2 *sax2);
2048
2049/* methods */
2050RAPTOR_API
2051void raptor_sax2_set_start_element_handler(raptor_sax2* sax2, raptor_sax2_start_element_handler handler);
2052RAPTOR_API
2053void raptor_sax2_set_end_element_handler(raptor_sax2* sax2, raptor_sax2_end_element_handler handler);
2054RAPTOR_API
2055void raptor_sax2_set_characters_handler(raptor_sax2* sax2, raptor_sax2_characters_handler handler);
2056RAPTOR_API
2057void raptor_sax2_set_cdata_handler(raptor_sax2* sax2, raptor_sax2_cdata_handler handler);
2058RAPTOR_API
2059void raptor_sax2_set_comment_handler(raptor_sax2* sax2, raptor_sax2_comment_handler handler);
2060RAPTOR_API
2061void raptor_sax2_set_unparsed_entity_decl_handler(raptor_sax2* sax2, raptor_sax2_unparsed_entity_decl_handler handler);
2062RAPTOR_API
2063void raptor_sax2_set_external_entity_ref_handler(raptor_sax2* sax2, raptor_sax2_external_entity_ref_handler handler);
2064RAPTOR_API
2065void raptor_sax2_set_namespace_handler(raptor_sax2* sax2, raptor_namespace_handler handler);
2066RAPTOR_API
2067void raptor_sax2_set_uri_filter(raptor_sax2* sax2, raptor_uri_filter_func filter, void *user_data);
2068RAPTOR_API
2069void raptor_sax2_parse_start(raptor_sax2 *sax2, raptor_uri *base_uri);
2070RAPTOR_API
2071int raptor_sax2_parse_chunk(raptor_sax2* sax2, const unsigned char *buffer, size_t len, int is_end);
2072RAPTOR_API
2073const unsigned char* raptor_sax2_inscope_xml_language(raptor_sax2* sax2);
2074RAPTOR_API
2075raptor_uri* raptor_sax2_inscope_base_uri(raptor_sax2* sax2);
2076
2077
2078
2079/* AVL Trees */
2080
2081/**
2082 * raptor_avltree:
2083 *
2084 * AVL Tree
2085 */
2086typedef struct raptor_avltree_s raptor_avltree;
2087
2088/**
2089 * raptor_avltree_iterator:
2090 *
2091 * AVL Tree Iterator as created by raptor_new_avltree_iterator()
2092 */
2093typedef struct raptor_avltree_iterator_s raptor_avltree_iterator;
2094
2095/**
2096 * raptor_avltree_visit_handler:
2097 * @depth: depth of object in tree
2098 * @data: data object being visited
2099 * @user_data: user data arg to raptor_avltree_visit()
2100 *
2101 * AVL Tree visitor function as given to raptor_avltree_visit()
2102 *
2103 * Return value: non-0 to terminate visit early.
2104 */
2105typedef int (*raptor_avltree_visit_handler)(int depth, void* data, void *user_data);
2106
2107
2108/**
2109 * raptor_avltree_bitflags:
2110 * @RAPTOR_AVLTREE_FLAG_REPLACE_DUPLICATES: If set raptor_avltree_add() will replace any duplicate items. If not set, raptor_avltree_add() will not replace them and will return status >0 when adding a duplicate. (Default is not set)
2111 *
2112 * Bit flags for AVL Tree class constructor raptor_new_avltree()
2113 **/
2114typedef enum {
2115 RAPTOR_AVLTREE_FLAG_REPLACE_DUPLICATES = 1
2116} raptor_avltree_bitflags;
2117
2118
2119RAPTOR_API
2120raptor_avltree* raptor_new_avltree(raptor_data_compare_handler compare_handler, raptor_data_free_handler free_handler, unsigned int flags);
2121RAPTOR_API
2122void raptor_free_avltree(raptor_avltree* tree);
2123
2124/* methods */
2125RAPTOR_API
2126int raptor_avltree_add(raptor_avltree* tree, void* p_data);
2127RAPTOR_API
2128void* raptor_avltree_remove(raptor_avltree* tree, void* p_data);
2129RAPTOR_API
2130int raptor_avltree_delete(raptor_avltree* tree, void* p_data);
2131RAPTOR_API
2132void* raptor_avltree_search(raptor_avltree* tree, const void* p_data);
2133RAPTOR_API
2134int raptor_avltree_visit(raptor_avltree* tree, raptor_avltree_visit_handler visit_handler, void* user_data);
2135RAPTOR_API
2136int raptor_avltree_size(raptor_avltree* tree);
2137RAPTOR_API
2138void raptor_avltree_set_print_handler(raptor_avltree* tree, raptor_data_print_handler print_handler);
2139RAPTOR_API
2140int raptor_avltree_print(raptor_avltree* tree, FILE* stream);
2141
2142RAPTOR_API
2143raptor_avltree_iterator* raptor_new_avltree_iterator(raptor_avltree* tree, void* range, raptor_data_free_handler range_free_handler, int direction);
2144RAPTOR_API
2145void raptor_free_avltree_iterator(raptor_avltree_iterator* iterator);
2146
2147RAPTOR_API
2148int raptor_avltree_iterator_is_end(raptor_avltree_iterator* iterator);
2149RAPTOR_API
2150int raptor_avltree_iterator_next(raptor_avltree_iterator* iterator);
2151RAPTOR_API
2152void* raptor_avltree_iterator_get(raptor_avltree_iterator* iterator);
2153
2154
2155#ifdef __cplusplus
2156}
2157#endif
2158
2159#endif
2160