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 @RAPTOR_VERSION_DECIMAL@
57
58/**
59 * RAPTOR_VERSION_STRING:
60 *
61 * Raptor library version string
62 */
63#define RAPTOR_VERSION_STRING "@VERSION@"
64
65/**
66 * RAPTOR_VERSION_MAJOR:
67 *
68 * Raptor library major version
69 */
70#define RAPTOR_VERSION_MAJOR @RAPTOR_VERSION_MAJOR@
71
72/**
73 * RAPTOR_VERSION_MINOR:
74 *
75 * Raptor library minor version
76 */
77#define RAPTOR_VERSION_MINOR @RAPTOR_VERSION_MINOR@
78
79/**
80 * RAPTOR_VERSION_RELEASE:
81 *
82 * Raptor library release
83 */
84#define RAPTOR_VERSION_RELEASE @RAPTOR_VERSION_RELEASE@
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_arg_handler:
933 * @data1: first object
934 * @data2: second object
935 * @user_data: user data argument
936 *
937 * Function to compare two data objects with a user data argument
938 *
939 * Designed to be used with raptor_sort_r() and compatible functions
940 * such as raptor_sequence_sort_r() which uses it.
941 *
942 * Return value: compare value <0 if @data1 is before @data2, =0 if equal, >0 if @data1 is after @data2
943 */
944typedef int (*raptor_data_compare_arg_handler)(const void *data1, const void *data2, void *user_data);
945
946
947/**
948 * raptor_data_compare_handler:
949 * @data1: first data object
950 * @data2: second data object
951 *
952 * Function to compare two data objects - signature like strcmp() and function pssed to qsort()
953 *
954 * Designed to be passed into generic data structure constructors
955 * like raptor_new_avltree().
956 *
957 * Return value: compare value <0 if @data1 is before @data2, =0 if equal, >0 if @data1 is after @data2
958 */
959typedef int (*raptor_data_compare_handler)(const void* data1, const void* data2);
960
961
962/**
963 * raptor_data_malloc_handler:
964 * @size: data size
965 *
966 * Typedef for a function to allocate memory - signature like malloc()
967 *
968 * Designed to be passed into constructors
969 * like raptor_www_fetch_to_string
970 *
971 * Return value: pointer to newly allocated memory or NULL on failure
972 */
973typedef void* (*raptor_data_malloc_handler)(size_t size);
974
975
976/**
977 * raptor_data_free_handler:
978 * @data: data object or NULL
979 *
980 * Typedef for function to free a data object - signature like free()
981 *
982 * Designed to be passed into generic data structure constructors
983 * like raptor_new_avltree().  If @data is NULL, nothing should be done.
984 */
985typedef void (*raptor_data_free_handler)(void* data);
986
987
988/**
989 * raptor_data_context_free_handler:
990 * @context: context data for the free function
991 * @object: object to free
992 *
993 * Handler function for freeing a sequence item with a contextual pointer.
994 *
995 * Set by raptor_new_sequence_with_context().
996*/
997typedef void (*raptor_data_context_free_handler)(void* context, void* object);
998
999/**
1000 * raptor_data_print_handler:
1001 * @object: object to print
1002 * @fh: FILE* to print to
1003 *
1004 * Handler function for printing an object to a stream.
1005 *
1006 * Set by raptor_new_sequence()
1007 *
1008 * Return value: non-0 on failure
1009 */
1010typedef int (*raptor_data_print_handler)(void *object, FILE *fh);
1011
1012/**
1013 * raptor_data_context_print_handler:
1014 * @context: context data for the print function
1015 * @object: object to print
1016 * @fh: FILE* to print to
1017 *
1018 * Function function for printing an object with data context to a stream.
1019 *
1020 * Set by raptor_new_sequence_with_context()
1021 *
1022 * Return value: non-0 on failure
1023 */
1024typedef int (*raptor_data_context_print_handler)(void *context, void *object, FILE *fh);
1025
1026/**
1027 * raptor_stringbuffer:
1028 *
1029 * Raptor string buffer class
1030 */
1031typedef struct raptor_stringbuffer_s raptor_stringbuffer;
1032
1033
1034/* Public functions */
1035
1036#define raptor_new_world() raptor_new_world_internal(RAPTOR_VERSION)
1037/* The real target of the raptor_new_world() macro */
1038RAPTOR_API
1039raptor_world *raptor_new_world_internal(unsigned int version_decimal);
1040RAPTOR_API
1041int raptor_world_open(raptor_world* world);
1042RAPTOR_API
1043void raptor_free_world(raptor_world* world);
1044RAPTOR_API
1045int raptor_world_set_libxslt_security_preferences(raptor_world *world, void *security_preferences);
1046RAPTOR_API
1047int raptor_world_set_flag(raptor_world *world, raptor_world_flag flag, int value);
1048RAPTOR_API
1049int raptor_world_set_log_handler(raptor_world *world, void *user_data, raptor_log_handler handler);
1050RAPTOR_API
1051void raptor_world_set_generate_bnodeid_handler(raptor_world* world, void *user_data, raptor_generate_bnodeid_handler handler);
1052RAPTOR_API
1053unsigned char* raptor_world_generate_bnodeid(raptor_world *world);
1054RAPTOR_API
1055void raptor_world_set_generate_bnodeid_parameters(raptor_world* world, char *prefix, int base);
1056RAPTOR_API
1057const char* raptor_log_level_get_label(raptor_log_level level);
1058RAPTOR_API
1059const char* raptor_domain_get_label(raptor_domain domain);
1060
1061/* Names */
1062RAPTOR_API
1063int raptor_world_is_parser_name(raptor_world* world, const char *name);
1064RAPTOR_API
1065const 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);
1066RAPTOR_API
1067int raptor_world_is_serializer_name(raptor_world* world, const char *name);
1068
1069/* Syntax descriptions */
1070RAPTOR_API
1071int raptor_world_get_parsers_count(raptor_world* world);
1072RAPTOR_API
1073int raptor_world_get_serializers_count(raptor_world* world);
1074RAPTOR_API
1075const raptor_syntax_description* raptor_world_get_parser_description(raptor_world* world, unsigned int counter);
1076RAPTOR_API
1077const raptor_syntax_description* raptor_world_get_serializer_description(raptor_world* world, unsigned int counter);
1078RAPTOR_API
1079int raptor_syntax_description_validate(raptor_syntax_description* desc);
1080
1081RAPTOR_API
1082raptor_option raptor_world_get_option_from_uri(raptor_world* world, raptor_uri *uri);
1083
1084
1085/* Term Class */
1086RAPTOR_API
1087raptor_term* raptor_new_term_from_uri(raptor_world* world, raptor_uri* uri);
1088RAPTOR_API
1089raptor_term* raptor_new_term_from_counted_uri_string(raptor_world* world,  const unsigned char *uri_string, size_t length);
1090RAPTOR_API
1091raptor_term* raptor_new_term_from_uri_string(raptor_world* world, const unsigned char *uri_string);
1092RAPTOR_API
1093raptor_term* raptor_new_term_from_literal(raptor_world* world, const unsigned char* literal, raptor_uri* datatype, const unsigned char* language);
1094RAPTOR_API
1095raptor_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);
1096RAPTOR_API
1097raptor_term* raptor_new_term_from_blank(raptor_world* world, const unsigned char* blank);
1098RAPTOR_API
1099raptor_term* raptor_new_term_from_counted_blank(raptor_world* world, const unsigned char* blank, size_t length);
1100RAPTOR_API
1101raptor_term* raptor_new_term_from_counted_string(raptor_world* world, unsigned char* string, size_t length);
1102RAPTOR_API
1103raptor_term* raptor_term_copy(raptor_term* term);
1104RAPTOR_API
1105int raptor_term_compare(const raptor_term *t1, const raptor_term *t2);
1106RAPTOR_API
1107int raptor_term_equals(raptor_term* t1, raptor_term* t2);
1108RAPTOR_API
1109void raptor_free_term(raptor_term *term);
1110
1111RAPTOR_API
1112unsigned char* raptor_term_to_counted_string(raptor_term *term, size_t* len_p);
1113RAPTOR_API
1114unsigned char* raptor_term_to_string(raptor_term *term);
1115RAPTOR_API
1116int raptor_term_escaped_write(const raptor_term *term, unsigned int flags, raptor_iostream* iostr);
1117RAPTOR_API RAPTOR_DEPRECATED
1118int raptor_term_ntriples_write(const raptor_term *term, raptor_iostream* iostr);
1119RAPTOR_API
1120int raptor_uri_turtle_write(raptor_world *world, raptor_iostream* iostr, raptor_uri* uri, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1121RAPTOR_API
1122int raptor_term_turtle_write(raptor_iostream* iostr, raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1123RAPTOR_API
1124unsigned 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);
1125RAPTOR_API
1126unsigned char* raptor_uri_to_turtle_string(raptor_world *world, raptor_uri* uri, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1127RAPTOR_API
1128unsigned char* raptor_term_to_turtle_counted_string(raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri, size_t *len_p);
1129RAPTOR_API
1130unsigned char* raptor_term_to_turtle_string(raptor_term* term, raptor_namespace_stack *nstack, raptor_uri *base_uri);
1131
1132
1133/* Statement Class */
1134RAPTOR_API
1135void raptor_statement_init(raptor_statement *statement, raptor_world *world);
1136RAPTOR_API
1137void raptor_statement_clear(raptor_statement *statement);
1138RAPTOR_API
1139raptor_statement* raptor_new_statement(raptor_world *world);
1140RAPTOR_API
1141raptor_statement* raptor_new_statement_from_nodes(raptor_world* world, raptor_term *subject, raptor_term *predicate, raptor_term *object, raptor_term *graph);
1142RAPTOR_API
1143raptor_statement* raptor_statement_copy(raptor_statement *statement);
1144RAPTOR_API
1145void raptor_free_statement(raptor_statement *statement);
1146
1147RAPTOR_API
1148int raptor_statement_print(const raptor_statement * statement, FILE *stream);
1149RAPTOR_API
1150int raptor_statement_print_as_ntriples(const raptor_statement * statement, FILE *stream);
1151RAPTOR_API
1152int raptor_statement_compare(const raptor_statement *s1, const raptor_statement *s2);
1153RAPTOR_API
1154int raptor_statement_equals(const raptor_statement* s1, const raptor_statement* s2);
1155
1156
1157/* Parser Class */
1158RAPTOR_API
1159raptor_parser* raptor_new_parser(raptor_world* world, const char *name);
1160RAPTOR_API
1161raptor_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);
1162RAPTOR_API
1163void raptor_free_parser(raptor_parser* parser);
1164
1165/* methods */
1166
1167/* Handlers */
1168RAPTOR_API
1169void raptor_parser_set_statement_handler(raptor_parser* parser, void *user_data, raptor_statement_handler handler);
1170RAPTOR_API
1171void raptor_parser_set_graph_mark_handler(raptor_parser* parser, void *user_data, raptor_graph_mark_handler handler);
1172RAPTOR_API
1173void raptor_parser_set_namespace_handler(raptor_parser* parser, void *user_data, raptor_namespace_handler handler);
1174RAPTOR_API
1175void raptor_parser_set_uri_filter(raptor_parser* parser, raptor_uri_filter_func filter, void* user_data);
1176RAPTOR_API
1177raptor_locator* raptor_parser_get_locator(raptor_parser* rdf_parser);
1178
1179
1180/* Parsing functions */
1181RAPTOR_API
1182int raptor_parser_parse_start(raptor_parser *rdf_parser, raptor_uri *uri);
1183RAPTOR_API
1184int raptor_parser_parse_chunk(raptor_parser* rdf_parser, const unsigned char *buffer, size_t len, int is_end);
1185RAPTOR_API
1186int raptor_parser_parse_file_stream(raptor_parser* rdf_parser, FILE *stream, const char *filename, raptor_uri *base_uri);
1187RAPTOR_API
1188int raptor_parser_parse_file(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri);
1189RAPTOR_API
1190int raptor_parser_parse_uri(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri);
1191RAPTOR_API
1192int raptor_parser_parse_uri_with_connection(raptor_parser* rdf_parser, raptor_uri *uri, raptor_uri *base_uri, void *connection);
1193RAPTOR_API
1194int raptor_parser_parse_iostream(raptor_parser* rdf_parser, raptor_iostream *iostr, raptor_uri *base_uri);
1195RAPTOR_API
1196void raptor_parser_parse_abort(raptor_parser* rdf_parser);
1197RAPTOR_API
1198const char* raptor_parser_get_name(raptor_parser *rdf_parser);
1199RAPTOR_API
1200const raptor_syntax_description* raptor_parser_get_description(raptor_parser *rdf_parser);
1201
1202/* parser option methods */
1203RAPTOR_API
1204int raptor_parser_set_option(raptor_parser *parser, raptor_option option, const char* string, int integer);
1205RAPTOR_API
1206int raptor_parser_get_option(raptor_parser *parser, raptor_option option, char** string_p, int* integer_p);
1207
1208/* parser utility methods */
1209RAPTOR_API
1210const char* raptor_parser_get_accept_header(raptor_parser* rdf_parser);
1211RAPTOR_API
1212raptor_world* raptor_parser_get_world(raptor_parser* rdf_parser);
1213RAPTOR_API
1214raptor_uri* raptor_parser_get_graph(raptor_parser* rdf_parser);
1215
1216
1217/* Locator Class */
1218/* methods */
1219RAPTOR_API
1220int raptor_locator_print(raptor_locator* locator, FILE *stream);
1221RAPTOR_API
1222int raptor_locator_format(char *buffer, size_t length, raptor_locator* locator);
1223RAPTOR_API
1224int raptor_locator_line(raptor_locator *locator);
1225RAPTOR_API
1226int raptor_locator_column(raptor_locator *locator);
1227RAPTOR_API
1228int raptor_locator_byte(raptor_locator *locator);
1229RAPTOR_API
1230const char* raptor_locator_file(raptor_locator *locator);
1231RAPTOR_API
1232const char* raptor_locator_uri(raptor_locator *locator);
1233
1234
1235/* Serializer Class */
1236RAPTOR_API
1237raptor_serializer* raptor_new_serializer(raptor_world* world, const char *name);
1238RAPTOR_API
1239void raptor_free_serializer(raptor_serializer* rdf_serializer);
1240
1241/* methods */
1242RAPTOR_API
1243int raptor_serializer_start_to_iostream(raptor_serializer *rdf_serializer, raptor_uri *uri, raptor_iostream *iostream);
1244RAPTOR_API
1245int raptor_serializer_start_to_filename(raptor_serializer *rdf_serializer, const char *filename);
1246RAPTOR_API
1247int raptor_serializer_start_to_string(raptor_serializer *rdf_serializer, raptor_uri *uri, void **string_p, size_t *length_p);
1248RAPTOR_API
1249int raptor_serializer_start_to_file_handle(raptor_serializer *rdf_serializer, raptor_uri *uri, FILE *fh);
1250RAPTOR_API
1251int raptor_serializer_set_namespace(raptor_serializer* rdf_serializer, raptor_uri *uri, const unsigned char *prefix);
1252RAPTOR_API
1253int raptor_serializer_set_namespace_from_namespace(raptor_serializer* rdf_serializer, raptor_namespace *nspace);
1254RAPTOR_API
1255int raptor_serializer_serialize_statement(raptor_serializer* rdf_serializer, raptor_statement *statement);
1256RAPTOR_API
1257int raptor_serializer_serialize_end(raptor_serializer *rdf_serializer);
1258RAPTOR_API
1259raptor_iostream* raptor_serializer_get_iostream(raptor_serializer *serializer);
1260RAPTOR_API
1261raptor_locator* raptor_serializer_get_locator(raptor_serializer *rdf_serializer);
1262RAPTOR_API
1263int raptor_serializer_flush(raptor_serializer *rdf_serializer);
1264RAPTOR_API
1265const raptor_syntax_description* raptor_serializer_get_description(raptor_serializer *rdf_serializer);
1266
1267/* serializer option methods */
1268RAPTOR_API
1269int raptor_serializer_set_option(raptor_serializer *serializer, raptor_option option, const char* string, int integer);
1270RAPTOR_API
1271int raptor_serializer_get_option(raptor_serializer *serializer, raptor_option option, char** string_p, int* integer_p);
1272
1273/* utility methods */
1274RAPTOR_API
1275raptor_world* raptor_serializer_get_world(raptor_serializer* rdf_serializer);
1276
1277
1278/* memory functions */
1279RAPTOR_API
1280void raptor_free_memory(void *ptr);
1281RAPTOR_API
1282void* raptor_alloc_memory(size_t size);
1283RAPTOR_API
1284void* raptor_calloc_memory(size_t nmemb, size_t size);
1285
1286
1287/* URI Class */
1288RAPTOR_API
1289raptor_uri* raptor_new_uri_from_counted_string(raptor_world* world, const unsigned char *uri_string, size_t length);
1290RAPTOR_API
1291raptor_uri* raptor_new_uri(raptor_world* world, const unsigned char *uri_string);
1292RAPTOR_API
1293raptor_uri* raptor_new_uri_from_uri_local_name(raptor_world* world, raptor_uri *uri, const unsigned char *local_name);
1294RAPTOR_API
1295raptor_uri* raptor_new_uri_relative_to_base(raptor_world* world, raptor_uri *base_uri, const unsigned char *uri_string);
1296RAPTOR_API
1297raptor_uri* raptor_new_uri_relative_to_base_counted(raptor_world* world, raptor_uri *base_uri, const unsigned char *uri_string, size_t uri_len);
1298RAPTOR_API
1299raptor_uri* raptor_new_uri_from_id(raptor_world* world, raptor_uri *base_uri, const unsigned char *id);
1300RAPTOR_API
1301raptor_uri* raptor_new_uri_from_uri_or_file_string(raptor_world* world, raptor_uri* base_uri, const unsigned char* uri_or_file_string);
1302RAPTOR_API
1303raptor_uri* raptor_new_uri_for_rdf_concept(raptor_world* world, const unsigned char *name);
1304RAPTOR_API
1305raptor_uri* raptor_new_uri_for_xmlbase(raptor_uri* old_uri);
1306RAPTOR_API
1307raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri);
1308RAPTOR_API
1309void raptor_free_uri(raptor_uri *uri);
1310
1311/* methods */
1312RAPTOR_API
1313int raptor_uri_equals(raptor_uri* uri1, raptor_uri* uri2);
1314RAPTOR_API
1315int raptor_uri_compare(raptor_uri* uri1, raptor_uri* uri2);
1316RAPTOR_API
1317raptor_uri* raptor_uri_copy(raptor_uri *uri);
1318RAPTOR_API
1319unsigned char* raptor_uri_as_string(raptor_uri *uri);
1320RAPTOR_API
1321unsigned char* raptor_uri_as_counted_string(raptor_uri *uri, size_t* len_p);
1322RAPTOR_API
1323unsigned char* raptor_uri_to_relative_counted_uri_string(raptor_uri *base_uri, raptor_uri *reference_uri, size_t *length_p);
1324RAPTOR_API
1325unsigned char* raptor_uri_to_relative_uri_string(raptor_uri *base_uri,  raptor_uri *reference_uri);
1326RAPTOR_API
1327int raptor_uri_print(const raptor_uri* uri, FILE *stream);
1328RAPTOR_API
1329unsigned char* raptor_uri_to_counted_string(raptor_uri *uri, size_t *len_p);
1330RAPTOR_API
1331unsigned char* raptor_uri_to_string(raptor_uri *uri);
1332RAPTOR_API
1333raptor_world* raptor_uri_get_world(raptor_uri *uri);
1334RAPTOR_API
1335int raptor_uri_file_exists(raptor_uri* uri);
1336RAPTOR_API
1337int raptor_uri_escaped_write(raptor_uri* uri, raptor_uri* base_uri, unsigned int flags, raptor_iostream *iostr);
1338
1339/* XML utility functions */
1340RAPTOR_API
1341int 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);
1342RAPTOR_API
1343int raptor_xml_escape_string_any_write(const unsigned char *string, size_t len, char quote, int xml_version, raptor_iostream* iostr);
1344RAPTOR_API
1345int raptor_xml_escape_string(raptor_world *world, const unsigned char *string, size_t len, unsigned char *buffer, size_t length, char quote);
1346RAPTOR_API
1347int raptor_xml_escape_string_write(const unsigned char *string, size_t len, char quote, raptor_iostream* iostr);
1348RAPTOR_API
1349int raptor_xml_name_check(const unsigned char *string, size_t length, int xml_version);
1350
1351
1352/* portable vsnprintf utility function */
1353RAPTOR_API RAPTOR_DEPRECATED
1354char* raptor_vsnprintf(const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(1, 0);
1355RAPTOR_API
1356int raptor_vsnprintf2(char *buffer, size_t size, const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(3, 0);
1357RAPTOR_API
1358int raptor_snprintf(char *buffer, size_t size, const char *format, ...) RAPTOR_PRINTF_FORMAT(3, 4);
1359RAPTOR_API
1360int raptor_vasprintf(char **ret, const char *format, va_list arguments) RAPTOR_PRINTF_FORMAT(2, 0);
1361
1362/* RFC2396 URI resolving functions */
1363RAPTOR_API
1364size_t raptor_uri_resolve_uri_reference(const unsigned char *base_uri, const unsigned char *reference_uri, unsigned char* buffer, size_t length);
1365
1366/* URI String utility functions */
1367RAPTOR_API
1368unsigned char* raptor_uri_counted_filename_to_uri_string(const char *filename, size_t filename_len);
1369RAPTOR_API
1370unsigned char* raptor_uri_filename_to_uri_string(const char *filename);
1371RAPTOR_API
1372int raptor_uri_filename_exists(const unsigned char* path);
1373RAPTOR_API
1374char* raptor_uri_uri_string_to_filename(const unsigned char *uri_string);
1375RAPTOR_API
1376char* raptor_uri_uri_string_to_filename_fragment(const unsigned char *uri_string, unsigned char **fragment_p);
1377RAPTOR_API
1378int raptor_uri_uri_string_is_file_uri(const unsigned char* uri_string);
1379RAPTOR_API
1380int raptor_stringbuffer_append_uri_escaped_counted_string(raptor_stringbuffer* sb, const char* string, size_t length, int space_is_plus);
1381RAPTOR_API
1382char* 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);
1383RAPTOR_API
1384int raptor_uri_uri_string_is_absolute(const unsigned char* uri_string);
1385
1386
1387/**
1388 * RAPTOR_RDF_MS_URI:
1389 *
1390 * RDF Namespace URI (rdf:).
1391 *
1392 * Copy with raptor_uri_copy() to use.
1393 */
1394#define RAPTOR_RDF_MS_URI raptor_rdf_namespace_uri
1395
1396/**
1397 * RAPTOR_RDF_SCHEMA_URI:
1398 *
1399 * RDF Schema Namespace URI (rdfs:).
1400 *
1401 * Copy with raptor_uri_copy() to use.
1402 */
1403#define RAPTOR_RDF_SCHEMA_URI raptor_rdf_schema_namespace_uri
1404
1405/**
1406 * RAPTOR_XMLSCHEMA_DATATYPES_URI:
1407 *
1408 * XML Schema Datatypes URI (xsd:).
1409 *
1410 * Copy with raptor_uri_copy() to use.
1411 */
1412#define RAPTOR_XMLSCHEMA_DATATYPES_URI raptor_xmlschema_datatypes_namespace_uri
1413
1414/**
1415 * RAPTOR_OWL_URI:
1416 *
1417 * OWL Namespace URI (owl:).
1418 *
1419 * Copy with raptor_uri_copy() to use.
1420 */
1421#define RAPTOR_OWL_URI raptor_owl_namespace_uri
1422
1423
1424/* raptor_www */
1425RAPTOR_API
1426raptor_www* raptor_new_www(raptor_world* world);
1427RAPTOR_API
1428raptor_www* raptor_new_www_with_connection(raptor_world* world, void* connection);
1429RAPTOR_API
1430void raptor_free_www(raptor_www *www);
1431RAPTOR_API
1432int raptor_www_set_ssl_cert_options(raptor_www* www, const char* cert_filename, const char* cert_type, const char* cert_passphrase);
1433RAPTOR_API
1434int raptor_www_set_ssl_verify_options(raptor_www* www, int verify_peer, int verify_host);
1435RAPTOR_API
1436void raptor_www_set_user_agent(raptor_www *www, const char *user_agent);
1437RAPTOR_API
1438void raptor_www_set_proxy(raptor_www *www, const char *proxy);
1439RAPTOR_API
1440void raptor_www_set_http_accept(raptor_www *www, const char *value);
1441RAPTOR_API
1442void raptor_www_set_write_bytes_handler(raptor_www *www, raptor_www_write_bytes_handler handler, void *user_data);
1443RAPTOR_API
1444void raptor_www_set_content_type_handler(raptor_www *www, raptor_www_content_type_handler handler, void *user_data);
1445RAPTOR_API
1446void raptor_www_set_final_uri_handler(raptor_www* www, raptor_www_final_uri_handler handler, void *user_data);
1447RAPTOR_API
1448void raptor_www_set_uri_filter(raptor_www* www, raptor_uri_filter_func filter, void* user_data);
1449RAPTOR_API
1450void raptor_www_set_connection_timeout(raptor_www* www, int timeout);
1451RAPTOR_API
1452int raptor_www_set_http_cache_control(raptor_www* www, const char* cache_control);
1453RAPTOR_API
1454int raptor_www_fetch(raptor_www *www, raptor_uri *uri);
1455RAPTOR_API
1456int 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);
1457RAPTOR_API
1458void* raptor_www_get_connection(raptor_www *www);
1459RAPTOR_API
1460void raptor_www_abort(raptor_www *www, const char *reason);
1461RAPTOR_API
1462raptor_uri* raptor_www_get_final_uri(raptor_www* www);
1463
1464
1465/* XML QNames Class */
1466RAPTOR_API
1467raptor_qname* raptor_new_qname(raptor_namespace_stack *nstack, const unsigned char *name, const unsigned char *value);
1468RAPTOR_API
1469raptor_qname* raptor_new_qname_from_namespace_local_name(raptor_world* world, raptor_namespace *ns, const unsigned char *local_name, const unsigned char *value);
1470
1471/* methods */
1472RAPTOR_API
1473raptor_qname* raptor_qname_copy(raptor_qname *qname);
1474RAPTOR_API
1475void raptor_free_qname(raptor_qname* name);
1476RAPTOR_API
1477int raptor_qname_equal(raptor_qname *name1, raptor_qname *name2);
1478RAPTOR_API
1479unsigned char* raptor_qname_to_counted_name(raptor_qname *qname, size_t* length_p);
1480RAPTOR_API
1481const raptor_namespace* raptor_qname_get_namespace(raptor_qname* name);
1482RAPTOR_API
1483const unsigned char* raptor_qname_get_local_name(raptor_qname* name);
1484RAPTOR_API
1485const unsigned char* raptor_qname_get_value(raptor_qname* name);
1486RAPTOR_API
1487const unsigned char* raptor_qname_get_counted_value(raptor_qname* name, size_t* length_p);
1488RAPTOR_API
1489int raptor_qname_write(raptor_qname *qname, raptor_iostream* iostr);
1490
1491/* QName String utility functions */
1492RAPTOR_API
1493raptor_uri* raptor_qname_string_to_uri(raptor_namespace_stack *nstack,  const unsigned char *name, size_t name_len);
1494RAPTOR_API
1495unsigned char* raptor_qname_format_as_xml(const raptor_qname *qname, size_t *length_p);
1496
1497/* XML Namespaces Stack class */
1498RAPTOR_API
1499raptor_namespace* raptor_new_namespace_from_uri(raptor_namespace_stack *nstack, const unsigned char *prefix,  raptor_uri* ns_uri, int depth);
1500RAPTOR_API
1501raptor_namespace_stack* raptor_new_namespaces(raptor_world* world, int defaults);
1502RAPTOR_API
1503int raptor_namespaces_init(raptor_world* world, raptor_namespace_stack *nstack, int defaults);
1504RAPTOR_API
1505void raptor_namespaces_clear(raptor_namespace_stack *nstack);
1506RAPTOR_API
1507void raptor_free_namespaces(raptor_namespace_stack *nstack);
1508
1509/* methods */
1510RAPTOR_API
1511void raptor_namespaces_start_namespace(raptor_namespace_stack *nstack, raptor_namespace *nspace);
1512RAPTOR_API
1513int raptor_namespaces_start_namespace_full(raptor_namespace_stack *nstack, const unsigned char *prefix, const unsigned char *ns_uri_string, int depth);
1514RAPTOR_API
1515void raptor_namespaces_end_for_depth(raptor_namespace_stack *nstack, int depth);
1516RAPTOR_API
1517raptor_namespace* raptor_namespaces_get_default_namespace(raptor_namespace_stack *nstack);
1518RAPTOR_API
1519raptor_namespace* raptor_namespaces_find_namespace(raptor_namespace_stack *nstack, const unsigned char *prefix, int prefix_length);
1520RAPTOR_API
1521raptor_namespace* raptor_namespaces_find_namespace_by_uri(raptor_namespace_stack *nstack, raptor_uri *ns_uri);
1522RAPTOR_API
1523int raptor_namespaces_namespace_in_scope(raptor_namespace_stack *nstack, const raptor_namespace *nspace);
1524RAPTOR_API
1525raptor_qname* raptor_new_qname_from_namespace_uri(raptor_namespace_stack *nstack,  raptor_uri *uri, int xml_version);
1526
1527
1528/* XML Namespace Class */
1529RAPTOR_API
1530raptor_namespace* raptor_new_namespace(raptor_namespace_stack *nstack, const unsigned char *prefix, const unsigned char *ns_uri_string, int depth);
1531RAPTOR_API
1532void raptor_free_namespace(raptor_namespace *ns);
1533RAPTOR_API
1534int raptor_namespace_stack_start_namespace(raptor_namespace_stack *nstack, raptor_namespace *ns, int new_depth);
1535RAPTOR_API
1536raptor_uri* raptor_namespace_get_uri(const raptor_namespace *ns);
1537RAPTOR_API
1538const unsigned char* raptor_namespace_get_prefix(const raptor_namespace *ns);
1539RAPTOR_API
1540const unsigned char* raptor_namespace_get_counted_prefix(const raptor_namespace *ns, size_t *length_p);
1541RAPTOR_API
1542unsigned char* raptor_namespace_format_as_xml(const raptor_namespace *ns, size_t *length_p);
1543RAPTOR_API
1544int raptor_namespace_write(raptor_namespace *ns, raptor_iostream* iostr);
1545
1546/* namespace string utility function */
1547RAPTOR_API
1548int raptor_xml_namespace_string_parse(const unsigned char *string, unsigned char **prefix, unsigned char **uri_string);
1549
1550/* Sequence class */
1551/**
1552 * raptor_sequence:
1553 *
1554 * Raptor sequence class
1555 */
1556typedef struct raptor_sequence_s raptor_sequence;
1557
1558/* Sequence Class */
1559RAPTOR_API
1560raptor_sequence* raptor_new_sequence(raptor_data_free_handler free_handler, raptor_data_print_handler print_handler);
1561RAPTOR_API
1562raptor_sequence* raptor_new_sequence_with_context(raptor_data_context_free_handler free_handler, raptor_data_context_print_handler print_handler, void* handler_context);
1563RAPTOR_API
1564void raptor_free_sequence(raptor_sequence* seq);
1565
1566/* methods */
1567RAPTOR_API
1568int raptor_sequence_size(raptor_sequence* seq);
1569RAPTOR_API
1570int raptor_sequence_set_at(raptor_sequence* seq, int idx, void *data);
1571RAPTOR_API
1572int raptor_sequence_push(raptor_sequence* seq, void *data);
1573RAPTOR_API
1574int raptor_sequence_shift(raptor_sequence* seq, void *data);
1575RAPTOR_API
1576void* raptor_sequence_get_at(raptor_sequence* seq, int idx);
1577RAPTOR_API
1578void* raptor_sequence_pop(raptor_sequence* seq);
1579RAPTOR_API
1580void* raptor_sequence_unshift(raptor_sequence* seq);
1581RAPTOR_API
1582void* raptor_sequence_delete_at(raptor_sequence* seq, int idx);
1583
1584RAPTOR_API
1585void raptor_sequence_sort(raptor_sequence* seq, raptor_data_compare_handler compare);
1586RAPTOR_API
1587void raptor_sequence_sort_r(raptor_sequence* seq, raptor_data_compare_arg_handler compare, void* user_data);
1588RAPTOR_API
1589int raptor_sequence_swap(raptor_sequence* seq, int i, int j);
1590RAPTOR_API
1591int raptor_sequence_reverse(raptor_sequence* seq, int start_index, int length);
1592RAPTOR_API
1593int raptor_sequence_next_permutation(raptor_sequence *seq, raptor_data_compare_handler compare);
1594
1595/* helper for printing sequences of strings */
1596RAPTOR_API
1597int raptor_sequence_print(raptor_sequence* seq, FILE* fh);
1598RAPTOR_API
1599int raptor_sequence_join(raptor_sequence* dest, raptor_sequence *src);
1600
1601
1602/* Unicode and UTF8 */
1603
1604/**
1605 * raptor_unichar:
1606 *
1607 * raptor Unicode codepoint
1608 */
1609typedef unsigned long raptor_unichar;
1610RAPTOR_API
1611int raptor_unicode_utf8_string_put_char(raptor_unichar c, unsigned char *output, size_t length);
1612RAPTOR_API
1613int raptor_unicode_utf8_string_get_char(const unsigned char *input, size_t length, raptor_unichar *output);
1614RAPTOR_API
1615int raptor_unicode_is_xml11_namestartchar(raptor_unichar c);
1616RAPTOR_API
1617int raptor_unicode_is_xml10_namestartchar(raptor_unichar c);
1618RAPTOR_API
1619int raptor_unicode_is_xml11_namechar(raptor_unichar c);
1620RAPTOR_API
1621int raptor_unicode_is_xml10_namechar(raptor_unichar c);
1622RAPTOR_API
1623int raptor_unicode_check_utf8_string(const unsigned char *string, size_t length);
1624RAPTOR_API
1625int raptor_unicode_utf8_strlen(const unsigned char *string, size_t length);
1626RAPTOR_API
1627size_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);
1628
1629/* Stringbuffer Class */
1630RAPTOR_API
1631raptor_stringbuffer* raptor_new_stringbuffer(void);
1632RAPTOR_API
1633void raptor_free_stringbuffer(raptor_stringbuffer *stringbuffer);
1634
1635/* methods */
1636RAPTOR_API
1637int raptor_stringbuffer_append_counted_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, size_t length, int do_copy);
1638RAPTOR_API
1639int raptor_stringbuffer_append_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, int do_copy);
1640RAPTOR_API
1641int raptor_stringbuffer_append_decimal(raptor_stringbuffer* stringbuffer, int integer);
1642RAPTOR_API
1643int raptor_stringbuffer_append_hexadecimal(raptor_stringbuffer* stringbuffer, int hex);
1644RAPTOR_API
1645int raptor_stringbuffer_append_stringbuffer(raptor_stringbuffer* stringbuffer, raptor_stringbuffer* append);
1646RAPTOR_API
1647int raptor_stringbuffer_prepend_counted_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, size_t length, int do_copy);
1648RAPTOR_API
1649int raptor_stringbuffer_prepend_string(raptor_stringbuffer* stringbuffer, const unsigned char *string, int do_copy);
1650RAPTOR_API
1651unsigned char* raptor_stringbuffer_as_string(raptor_stringbuffer* stringbuffer);
1652RAPTOR_API
1653size_t raptor_stringbuffer_length(raptor_stringbuffer* stringbuffer);
1654RAPTOR_API
1655int raptor_stringbuffer_copy_to_string(raptor_stringbuffer* stringbuffer, unsigned char *string, size_t length);
1656
1657/**
1658 * raptor_iostream_init_func:
1659 * @context: stream context data
1660 *
1661 * Handler function for #raptor_iostream initialising.
1662 *
1663 * Return value: non-0 on failure.
1664 */
1665typedef int (*raptor_iostream_init_func) (void *context);
1666
1667/**
1668 * raptor_iostream_finish_func:
1669 * @context: stream context data
1670 *
1671 * Handler function for #raptor_iostream terminating.
1672 *
1673 */
1674typedef void (*raptor_iostream_finish_func) (void *context);
1675
1676/**
1677 * raptor_iostream_write_byte_func
1678 * @context: stream context data
1679 * @byte: byte to write
1680 *
1681 * Handler function for implementing raptor_iostream_write_byte().
1682 *
1683 * Return value: non-0 on failure.
1684 */
1685typedef int (*raptor_iostream_write_byte_func) (void *context, const int byte);
1686
1687/**
1688 * raptor_iostream_write_bytes_func:
1689 * @context: stream context data
1690 * @ptr: pointer to bytes to write
1691 * @size: size of item
1692 * @nmemb: number of items
1693 *
1694 * Handler function for implementing raptor_iostream_write_bytes().
1695 *
1696 * Return value: non-0 on failure.
1697 */
1698typedef int (*raptor_iostream_write_bytes_func) (void *context, const void *ptr, size_t size, size_t nmemb);
1699
1700/**
1701 * raptor_iostream_write_end_func:
1702 * @context: stream context data
1703 *
1704 * Handler function for implementing raptor_iostream_write_end().
1705 *
1706 * Return value: non-0 on failure.
1707 */
1708typedef int (*raptor_iostream_write_end_func) (void *context);
1709
1710/**
1711 * raptor_iostream_read_bytes_func:
1712 * @context: stream context data
1713 * @ptr: pointer to buffer to read into
1714 * @size: size of buffer
1715 * @nmemb: number of items
1716 *
1717 * Handler function for implementing raptor_iostream_read_bytes().
1718 *
1719 * Return value: number of items read, 0 or < @size on EOF, <0 on failure
1720 */
1721typedef int (*raptor_iostream_read_bytes_func) (void *context, void *ptr, size_t size, size_t nmemb);
1722
1723/**
1724 * raptor_iostream_read_eof_func:
1725 * @context: stream context data
1726 *
1727 * Handler function for implementing raptor_iostream_read_eof().
1728 *
1729 * Return value: non-0 if EOF
1730 */
1731typedef int (*raptor_iostream_read_eof_func) (void *context);
1732
1733/**
1734 * raptor_iostream_handler:
1735 * @version: interface version.  Presently 1 or 2.
1736 * @init:  initialisation handler - optional, called at most once (V1)
1737 * @finish: finishing handler -  optional, called at most once (V1)
1738 * @write_byte: write byte handler - required (for writing) (V1)
1739 * @write_bytes: write bytes handler - required (for writing) (V1)
1740 * @write_end: write end handler - optional (for writing), called at most once (V1)
1741 * @read_bytes: read bytes handler - required (for reading) (V2)
1742 * @read_eof: read EOF handler - required (for reading) (V2)
1743 *
1744 * I/O stream implementation handler structure.
1745 *
1746 */
1747typedef struct {
1748  int version;
1749
1750  /* V1 functions */
1751  raptor_iostream_init_func         init;
1752  raptor_iostream_finish_func       finish;
1753  raptor_iostream_write_byte_func   write_byte;
1754  raptor_iostream_write_bytes_func  write_bytes;
1755  raptor_iostream_write_end_func    write_end;
1756
1757  /* V2 functions */
1758  raptor_iostream_read_bytes_func   read_bytes;
1759  raptor_iostream_read_eof_func     read_eof;
1760} raptor_iostream_handler;
1761
1762
1763/* I/O Stream Class */
1764RAPTOR_API
1765raptor_iostream* raptor_new_iostream_from_handler(raptor_world* world, void *user_data, const raptor_iostream_handler* const handler);
1766RAPTOR_API
1767raptor_iostream* raptor_new_iostream_to_sink(raptor_world* world);
1768RAPTOR_API
1769raptor_iostream* raptor_new_iostream_to_filename(raptor_world* world, const char *filename);
1770RAPTOR_API
1771raptor_iostream* raptor_new_iostream_to_file_handle(raptor_world* world, FILE *handle);
1772RAPTOR_API
1773raptor_iostream* raptor_new_iostream_to_string(raptor_world* world, void **string_p, size_t *length_p, raptor_data_malloc_handler const malloc_handler);
1774RAPTOR_API
1775raptor_iostream* raptor_new_iostream_from_sink(raptor_world* world);
1776RAPTOR_API
1777raptor_iostream* raptor_new_iostream_from_filename(raptor_world* world, const char *filename);
1778RAPTOR_API
1779raptor_iostream* raptor_new_iostream_from_file_handle(raptor_world* world, FILE *handle);
1780RAPTOR_API
1781raptor_iostream* raptor_new_iostream_from_string(raptor_world* world, void *string, size_t length);
1782RAPTOR_API
1783void raptor_free_iostream(raptor_iostream *iostr);
1784
1785RAPTOR_API
1786int raptor_iostream_write_bytes(const void *ptr, size_t size, size_t nmemb, raptor_iostream *iostr);
1787RAPTOR_API
1788int raptor_iostream_write_byte(const int byte, raptor_iostream *iostr);
1789RAPTOR_API
1790int raptor_iostream_write_end(raptor_iostream *iostr);
1791RAPTOR_API
1792int raptor_iostream_string_write(const void *string, raptor_iostream *iostr);
1793RAPTOR_API
1794int raptor_iostream_counted_string_write(const void *string, size_t len, raptor_iostream *iostr);
1795RAPTOR_API
1796unsigned long raptor_iostream_tell(raptor_iostream *iostr);
1797RAPTOR_API
1798int raptor_iostream_decimal_write(int integer, raptor_iostream* iostr);
1799RAPTOR_API
1800int raptor_iostream_hexadecimal_write(unsigned int integer, int width, raptor_iostream* iostr);
1801RAPTOR_API
1802int raptor_stringbuffer_write(raptor_stringbuffer *sb, raptor_iostream* iostr);
1803RAPTOR_API
1804int raptor_uri_write(raptor_uri *uri, raptor_iostream *iostr);
1805RAPTOR_API
1806int raptor_iostream_read_bytes(void *ptr, size_t size, size_t nmemb, raptor_iostream* iostr);
1807RAPTOR_API
1808int raptor_iostream_read_eof(raptor_iostream *iostr);
1809
1810/* I/O Stream utility functions */
1811
1812/**
1813 * raptor_escaped_write_bitflags:
1814 * @RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF   : Allow \b \f,
1815 * @RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU : ALlow \t \n \r \u
1816 * @RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8            : Allow UTF-8 for printable U *
1817 * @RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES: Must escape #x00-#x20<>\"{}|^` in URIs
1818 * @RAPTOR_ESCAPED_WRITE_NTRIPLES_LITERAL: N-Triples literal
1819 * @RAPTOR_ESCAPED_WRITE_NTRIPLES_URI: N-Triples URI
1820 * @RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL: SPARQL literal: allows raw UTF8 for printable literals
1821 * @RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL: SPARQL long literal: no BS-escapes allowed
1822 * @RAPTOR_ESCAPED_WRITE_SPARQL_URI: SPARQL uri: have to escape certain characters
1823 * @RAPTOR_ESCAPED_WRITE_TURTLE_URI: Turtle 2013 URIs (like SPARQL)
1824 * @RAPTOR_ESCAPED_WRITE_TURTLE_LITERAL: Turtle 2013 literals (like SPARQL)
1825 * @RAPTOR_ESCAPED_WRITE_TURTLE_LONG_LITERAL: Turtle 2013 long literals (like SPARQL)
1826 * @RAPTOR_ESCAPED_WRITE_JSON_LITERAL: JSON literals: \b \f \t \r \n and \u \U
1827 *
1828 * Bit flags for raptor_string_escaped_write() and friends.
1829 */
1830typedef enum {
1831  RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF      = 1,
1832  RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU    = 2,
1833  RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8               = 4,
1834  RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES = 8,
1835
1836  /* N-Triples - favour writing \u, \U over UTF8 */
1837  RAPTOR_ESCAPED_WRITE_NTRIPLES_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU | RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF,
1838  RAPTOR_ESCAPED_WRITE_NTRIPLES_URI     = RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES,
1839
1840  /* SPARQL literal: allows raw UTF8 for printable literals */
1841  RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8,
1842
1843  /* SPARQL long literal: no BS-escapes allowed */
1844  RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8,
1845
1846  /* SPARQL uri: have to escape certain characters */
1847  RAPTOR_ESCAPED_WRITE_SPARQL_URI     = RAPTOR_ESCAPED_WRITE_BITFLAG_UTF8 | RAPTOR_ESCAPED_WRITE_BITFLAG_SPARQL_URI_ESCAPES,
1848
1849  /* Turtle (2013) escapes are like SPARQL */
1850  RAPTOR_ESCAPED_WRITE_TURTLE_URI     = RAPTOR_ESCAPED_WRITE_SPARQL_URI,
1851  RAPTOR_ESCAPED_WRITE_TURTLE_LITERAL = RAPTOR_ESCAPED_WRITE_SPARQL_LITERAL,
1852  RAPTOR_ESCAPED_WRITE_TURTLE_LONG_LITERAL = RAPTOR_ESCAPED_WRITE_SPARQL_LONG_LITERAL,
1853
1854  /* JSON literals: \b \f \t \r \n and \u \U */
1855  RAPTOR_ESCAPED_WRITE_JSON_LITERAL = RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_TNRU | RAPTOR_ESCAPED_WRITE_BITFLAG_BS_ESCAPES_BF
1856} raptor_escaped_write_bitflags;
1857
1858
1859RAPTOR_API
1860int raptor_string_ntriples_write(const unsigned char *string, size_t len, const char delim, raptor_iostream *iostr);
1861RAPTOR_API
1862int raptor_bnodeid_ntriples_write(const unsigned char *bnodeid, size_t len, raptor_iostream *iostr);
1863RAPTOR_API RAPTOR_DEPRECATED
1864int raptor_string_python_write(const unsigned char *string, size_t len, const char delim, unsigned int mode, raptor_iostream *iostr);
1865RAPTOR_API
1866int raptor_statement_ntriples_write(const raptor_statement *statement, raptor_iostream* iostr, int write_graph_term);
1867RAPTOR_API
1868int raptor_string_escaped_write(const unsigned char *string, size_t len, const char delim, unsigned int flags, raptor_iostream *iostr);
1869
1870
1871/* Parser and Serializer options */
1872
1873/**
1874 * raptor_option_value_type:
1875 * @RAPTOR_OPTION_VALUE_TYPE_BOOL: Boolean integer value. Non-0 is true
1876 * @RAPTOR_OPTION_VALUE_TYPE_INT: Decimal integer value
1877 * @RAPTOR_OPTION_VALUE_TYPE_STRING: String value
1878 * @RAPTOR_OPTION_VALUE_TYPE_URI: URI String value.
1879 * @RAPTOR_OPTION_VALUE_TYPE_LAST: internal
1880 *
1881 * Option value types.
1882 */
1883typedef enum {
1884  RAPTOR_OPTION_VALUE_TYPE_BOOL,
1885  RAPTOR_OPTION_VALUE_TYPE_INT,
1886  RAPTOR_OPTION_VALUE_TYPE_STRING,
1887  RAPTOR_OPTION_VALUE_TYPE_URI,
1888  RAPTOR_OPTION_VALUE_TYPE_LAST = RAPTOR_OPTION_VALUE_TYPE_URI
1889} raptor_option_value_type;
1890
1891
1892/**
1893 * raptor_option_description:
1894 * @domain: domain ID
1895 * @option: option ID
1896 * @value_type: data type of option value
1897 * @name: short name for option
1898 * @name_len: length of @name
1899 * @label: description of option
1900 * @uri: URI identifying option
1901 *
1902 * Description of an option for a domain.
1903 */
1904typedef struct {
1905  raptor_domain domain;
1906  raptor_option option;
1907  raptor_option_value_type value_type;
1908  const char* name;
1909  size_t name_len;
1910  const char* label;
1911  raptor_uri* uri;
1912} raptor_option_description;
1913
1914
1915RAPTOR_API
1916unsigned int raptor_option_get_count(void);
1917RAPTOR_API
1918const char* raptor_option_get_value_type_label(const raptor_option_value_type type);
1919RAPTOR_API
1920void raptor_free_option_description(raptor_option_description* option_description);
1921RAPTOR_API
1922raptor_option_description* raptor_world_get_option_description(raptor_world* world, const raptor_domain domain, const raptor_option option);
1923
1924
1925/* SAX2 element Class (raptor_xml_element) */
1926RAPTOR_API
1927raptor_xml_element* raptor_new_xml_element(raptor_qname* name, const unsigned char* xml_language, raptor_uri* xml_base);
1928RAPTOR_API
1929raptor_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);
1930RAPTOR_API
1931void raptor_free_xml_element(raptor_xml_element *element);
1932
1933/* methods */
1934RAPTOR_API
1935raptor_qname* raptor_xml_element_get_name(raptor_xml_element *xml_element);
1936RAPTOR_API
1937void raptor_xml_element_set_attributes(raptor_xml_element* xml_element, raptor_qname **attributes, int count);
1938RAPTOR_API
1939raptor_qname** raptor_xml_element_get_attributes(raptor_xml_element* xml_element);
1940RAPTOR_API
1941int raptor_xml_element_get_attributes_count(raptor_xml_element* xml_element);
1942RAPTOR_API
1943int raptor_xml_element_declare_namespace(raptor_xml_element* xml_element, raptor_namespace *nspace);
1944RAPTOR_API
1945int raptor_xml_element_write(raptor_xml_element *element, raptor_namespace_stack *nstack, int is_empty, int is_end, int depth, raptor_iostream *iostr);
1946RAPTOR_API
1947int raptor_xml_element_is_empty(raptor_xml_element* xml_element);
1948RAPTOR_API
1949const unsigned char* raptor_xml_element_get_language(raptor_xml_element* xml_element);
1950
1951
1952/* XML Writer Class (raptor_xml_writer) */
1953RAPTOR_API
1954raptor_xml_writer* raptor_new_xml_writer(raptor_world* world, raptor_namespace_stack *nstack, raptor_iostream* iostr);
1955RAPTOR_API
1956void raptor_free_xml_writer(raptor_xml_writer* xml_writer);
1957
1958/* methods */
1959RAPTOR_API
1960void raptor_xml_writer_empty_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1961RAPTOR_API
1962void raptor_xml_writer_start_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1963RAPTOR_API
1964void raptor_xml_writer_end_element(raptor_xml_writer* xml_writer, raptor_xml_element *element);
1965RAPTOR_API
1966void raptor_xml_writer_newline(raptor_xml_writer* xml_writer);
1967RAPTOR_API
1968void raptor_xml_writer_cdata(raptor_xml_writer* xml_writer, const unsigned char *s);
1969RAPTOR_API
1970void raptor_xml_writer_cdata_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1971RAPTOR_API
1972void raptor_xml_writer_raw(raptor_xml_writer* xml_writer, const unsigned char *s);
1973RAPTOR_API
1974void raptor_xml_writer_raw_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1975RAPTOR_API
1976void raptor_xml_writer_comment(raptor_xml_writer* xml_writer, const unsigned char *s);
1977RAPTOR_API
1978void raptor_xml_writer_comment_counted(raptor_xml_writer* xml_writer, const unsigned char *s, unsigned int len);
1979RAPTOR_API
1980void raptor_xml_writer_flush(raptor_xml_writer* xml_writer);
1981RAPTOR_API
1982int raptor_xml_writer_set_option(raptor_xml_writer *xml_writer, raptor_option option, char* string, int integer);
1983RAPTOR_API
1984int raptor_xml_writer_get_option(raptor_xml_writer *xml_writer, raptor_option option, char** string_p, int* integer_p);
1985RAPTOR_API
1986int raptor_xml_writer_get_depth(raptor_xml_writer *xml_writer);
1987
1988/**
1989 * raptor_sax2_start_element_handler:
1990 * @user_data: user data
1991 * @xml_element: XML element
1992 *
1993 * SAX2 start element handler
1994 */
1995typedef void (*raptor_sax2_start_element_handler)(void *user_data, raptor_xml_element *xml_element);
1996
1997/**
1998 * raptor_sax2_end_element_handler:
1999 * @user_data: user data
2000 * @xml_element: XML element
2001 *
2002 * SAX2 end element handler
2003 */
2004typedef void (*raptor_sax2_end_element_handler)(void *user_data, raptor_xml_element* xml_element);
2005
2006/**
2007 * raptor_sax2_characters_handler:
2008 * @user_data: user data
2009 * @xml_element: XML element
2010 * @s: string
2011 * @len: string len
2012 *
2013 * SAX2 characters handler
2014 */
2015typedef void (*raptor_sax2_characters_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s, int len);
2016
2017/**
2018 * raptor_sax2_cdata_handler:
2019 * @user_data: user data
2020 * @xml_element: XML element
2021 * @s: string
2022 * @len: string len
2023
2024 * SAX2 CDATA section handler
2025 */
2026typedef void (*raptor_sax2_cdata_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s, int len);
2027
2028/**
2029 * raptor_sax2_comment_handler:
2030 * @user_data: user data
2031 * @xml_element: XML element
2032 * @s: string
2033 *
2034 * SAX2 XML comment handler
2035 */
2036typedef void (*raptor_sax2_comment_handler)(void *user_data, raptor_xml_element* xml_element, const unsigned char *s);
2037
2038/**
2039 * raptor_sax2_unparsed_entity_decl_handler:
2040 * @user_data: user data
2041 * @entityName: entity name
2042 * @base: base URI
2043 * @systemId: system ID
2044 * @publicId: public ID
2045 * @notationName: notation name
2046 *
2047 * SAX2 unparsed entity (NDATA) handler
2048 */
2049typedef 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);
2050
2051/**
2052 * raptor_sax2_external_entity_ref_handler:
2053 * @user_data: user data
2054 * @context: context
2055 * @base: base URI
2056 * @systemId: system ID
2057 * @publicId: public ID
2058 *
2059 * SAX2 external entity reference handler
2060 *
2061 * Return value: 0 if processing should not continue because of a
2062 * fatal error in the handling of the external entity.
2063 */
2064typedef 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);
2065
2066
2067/* SAX2 API */
2068RAPTOR_API
2069raptor_sax2* raptor_new_sax2(raptor_world *world, raptor_locator *locator, void* user_data);
2070RAPTOR_API
2071void raptor_free_sax2(raptor_sax2 *sax2);
2072
2073/* methods */
2074RAPTOR_API
2075void raptor_sax2_set_start_element_handler(raptor_sax2* sax2, raptor_sax2_start_element_handler handler);
2076RAPTOR_API
2077void raptor_sax2_set_end_element_handler(raptor_sax2* sax2, raptor_sax2_end_element_handler handler);
2078RAPTOR_API
2079void raptor_sax2_set_characters_handler(raptor_sax2* sax2, raptor_sax2_characters_handler handler);
2080RAPTOR_API
2081void raptor_sax2_set_cdata_handler(raptor_sax2* sax2, raptor_sax2_cdata_handler handler);
2082RAPTOR_API
2083void raptor_sax2_set_comment_handler(raptor_sax2* sax2, raptor_sax2_comment_handler handler);
2084RAPTOR_API
2085void raptor_sax2_set_unparsed_entity_decl_handler(raptor_sax2* sax2, raptor_sax2_unparsed_entity_decl_handler handler);
2086RAPTOR_API
2087void raptor_sax2_set_external_entity_ref_handler(raptor_sax2* sax2, raptor_sax2_external_entity_ref_handler handler);
2088RAPTOR_API
2089void raptor_sax2_set_namespace_handler(raptor_sax2* sax2, raptor_namespace_handler handler);
2090RAPTOR_API
2091void raptor_sax2_set_uri_filter(raptor_sax2* sax2, raptor_uri_filter_func filter, void *user_data);
2092RAPTOR_API
2093void raptor_sax2_parse_start(raptor_sax2 *sax2, raptor_uri *base_uri);
2094RAPTOR_API
2095int raptor_sax2_parse_chunk(raptor_sax2* sax2, const unsigned char *buffer, size_t len, int is_end);
2096RAPTOR_API
2097const unsigned char* raptor_sax2_inscope_xml_language(raptor_sax2* sax2);
2098RAPTOR_API
2099raptor_uri* raptor_sax2_inscope_base_uri(raptor_sax2* sax2);
2100
2101
2102
2103/* AVL Trees */
2104
2105/**
2106 * raptor_avltree:
2107 *
2108 * AVL Tree
2109 */
2110typedef struct raptor_avltree_s raptor_avltree;
2111
2112/**
2113 * raptor_avltree_iterator:
2114 *
2115 * AVL Tree Iterator as created by raptor_new_avltree_iterator()
2116 */
2117typedef struct raptor_avltree_iterator_s raptor_avltree_iterator;
2118
2119/**
2120 * raptor_avltree_visit_handler:
2121 * @depth: depth of object in tree
2122 * @data: data object being visited
2123 * @user_data: user data arg to raptor_avltree_visit()
2124 *
2125 * AVL Tree visitor function as given to raptor_avltree_visit()
2126 *
2127 * Return value: non-0 to terminate visit early.
2128 */
2129typedef int (*raptor_avltree_visit_handler)(int depth, void* data, void *user_data);
2130
2131
2132/**
2133 * raptor_avltree_bitflags:
2134 * @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)
2135 *
2136 * Bit flags for AVL Tree class constructor raptor_new_avltree()
2137 **/
2138typedef enum {
2139 RAPTOR_AVLTREE_FLAG_REPLACE_DUPLICATES = 1
2140} raptor_avltree_bitflags;
2141
2142
2143RAPTOR_API
2144raptor_avltree* raptor_new_avltree(raptor_data_compare_handler compare_handler, raptor_data_free_handler free_handler, unsigned int flags);
2145RAPTOR_API
2146void raptor_free_avltree(raptor_avltree* tree);
2147
2148/* methods */
2149RAPTOR_API
2150int raptor_avltree_add(raptor_avltree* tree, void* p_data);
2151RAPTOR_API
2152void* raptor_avltree_remove(raptor_avltree* tree, void* p_data);
2153RAPTOR_API
2154int raptor_avltree_delete(raptor_avltree* tree, void* p_data);
2155RAPTOR_API
2156void* raptor_avltree_search(raptor_avltree* tree, const void* p_data);
2157RAPTOR_API
2158int raptor_avltree_visit(raptor_avltree* tree, raptor_avltree_visit_handler visit_handler, void* user_data);
2159RAPTOR_API
2160int raptor_avltree_size(raptor_avltree* tree);
2161RAPTOR_API
2162void raptor_avltree_set_print_handler(raptor_avltree* tree, raptor_data_print_handler print_handler);
2163RAPTOR_API
2164int raptor_avltree_print(raptor_avltree* tree, FILE* stream);
2165
2166RAPTOR_API
2167raptor_avltree_iterator* raptor_new_avltree_iterator(raptor_avltree* tree, void* range,  raptor_data_free_handler range_free_handler, int direction);
2168RAPTOR_API
2169void raptor_free_avltree_iterator(raptor_avltree_iterator* iterator);
2170
2171RAPTOR_API
2172int raptor_avltree_iterator_is_end(raptor_avltree_iterator* iterator);
2173RAPTOR_API
2174int raptor_avltree_iterator_next(raptor_avltree_iterator* iterator);
2175RAPTOR_API
2176void* raptor_avltree_iterator_get(raptor_avltree_iterator* iterator);
2177
2178/* utility methods */
2179void raptor_sort_r(void *base, size_t nel, size_t width, raptor_data_compare_arg_handler compar, void *user_data);
2180
2181
2182#ifdef __cplusplus
2183}
2184#endif
2185
2186#endif
2187