1 /* -*- Mode: c; c-basic-offset: 2 -*-
2  *
3  * raptor_internal.h - Redland Parser Toolkit for RDF (Raptor) internals
4  *
5  * Copyright (C) 2002-2009, David Beckett http://www.dajobe.org/
6  * Copyright (C) 2002-2004, 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_INTERNAL_H
28 #define RAPTOR_INTERNAL_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #define RAPTOR_EXTERN_C extern "C"
33 #else
34 #define RAPTOR_EXTERN_C
35 #endif
36 
37 #ifdef RAPTOR_INTERNAL
38 
39 /* for the memory allocation functions */
40 #ifdef HAVE_STDLIB_H
41 #include <stdlib.h>
42 #undef HAVE_STDLIB_H
43 #endif
44 
45 #if defined(HAVE_DMALLOC_H) && defined(RAPTOR_MEMORY_DEBUG_DMALLOC)
46 #include <dmalloc.h>
47 #endif
48 
49 
50 /* Can be over-ridden or undefined in a config.h file or -Ddefine */
51 #ifndef RAPTOR_INLINE
52 #define RAPTOR_INLINE inline
53 #endif
54 
55 #ifdef LIBRDF_DEBUG
56 #define RAPTOR_DEBUG 1
57 #endif
58 
59 #if defined(RAPTOR_MEMORY_SIGN)
60 #define RAPTOR_SIGN_KEY 0x08A61080
61 void* raptor_sign_malloc(size_t size);
62 void* raptor_sign_calloc(size_t nmemb, size_t size);
63 void* raptor_sign_realloc(void *ptr, size_t size);
64 void raptor_sign_free(void *ptr);
65 
66 #define RAPTOR_MALLOC(type, size)   raptor_sign_malloc(size)
67 #define RAPTOR_CALLOC(type, nmemb, size) raptor_sign_calloc(nmemb, size)
68 #define RAPTOR_REALLOC(type, ptr, size) raptor_sign_realloc(ptr, size)
69 #define RAPTOR_FREE(type, ptr)   raptor_sign_free(ptr)
70 
71 #else
72 #define RAPTOR_MALLOC(type, size) malloc(size)
73 #define RAPTOR_CALLOC(type, nmemb, size) calloc(nmemb, size)
74 #define RAPTOR_REALLOC(type, ptr, size) realloc(ptr, size)
75 #define RAPTOR_FREE(type, ptr)   free((void*)ptr)
76 
77 #endif
78 
79 #ifdef RAPTOR_DEBUG
80 /* Debugging messages */
81 #define RAPTOR_DEBUG1(msg) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__); } while(0)
82 #define RAPTOR_DEBUG2(msg, arg1) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1);} while(0)
83 #define RAPTOR_DEBUG3(msg, arg1, arg2) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2);} while(0)
84 #define RAPTOR_DEBUG4(msg, arg1, arg2, arg3) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2, arg3);} while(0)
85 #define RAPTOR_DEBUG5(msg, arg1, arg2, arg3, arg4) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2, arg3, arg4);} while(0)
86 #define RAPTOR_DEBUG6(msg, arg1, arg2, arg3, arg4, arg5) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2, arg3, arg4, arg5);} while(0)
87 
88 #if defined(HAVE_DMALLOC_H) && defined(RAPTOR_MEMORY_DEBUG_DMALLOC)
89 void* raptor_system_malloc(size_t size);
90 void raptor_system_free(void *ptr);
91 #define SYSTEM_MALLOC(size)   raptor_system_malloc(size)
92 #define SYSTEM_FREE(ptr)   raptor_system_free(ptr)
93 #else
94 #define SYSTEM_MALLOC(size)   malloc(size)
95 #define SYSTEM_FREE(ptr)   free(ptr)
96 #endif
97 
98 #ifndef RAPTOR_ASSERT_DIE
99 #define RAPTOR_ASSERT_DIE abort();
100 #endif
101 
102 #else
103 /* DEBUGGING TURNED OFF */
104 
105 /* No debugging messages */
106 #define RAPTOR_DEBUG1(msg)
107 #define RAPTOR_DEBUG2(msg, arg1)
108 #define RAPTOR_DEBUG3(msg, arg1, arg2)
109 #define RAPTOR_DEBUG4(msg, arg1, arg2, arg3)
110 #define RAPTOR_DEBUG5(msg, arg1, arg2, arg3, arg4)
111 #define RAPTOR_DEBUG6(msg, arg1, arg2, arg3, arg4, arg5)
112 
113 #define SYSTEM_MALLOC(size)   malloc(size)
114 #define SYSTEM_FREE(ptr)   free(ptr)
115 
116 #ifndef RAPTOR_ASSERT_DIE
117 #define RAPTOR_ASSERT_DIE
118 #endif
119 
120 #endif
121 
122 
123 #ifdef RAPTOR_DISABLE_ASSERT_MESSAGES
124 #define RAPTOR_ASSERT_REPORT(line)
125 #else
126 #define RAPTOR_ASSERT_REPORT(msg) fprintf(stderr, "%s:%d: (%s) assertion failed: " msg "\n", __FILE__, __LINE__, __func__);
127 #endif
128 
129 
130 #ifdef RAPTOR_DISABLE_ASSERT
131 
132 #define RAPTOR_ASSERT(condition, msg)
133 #define RAPTOR_ASSERT_RETURN(condition, msg, ret)
134 #define RAPTOR_ASSERT_OBJECT_POINTER_RETURN(pointer, type) do { \
135   if(!pointer) \
136     return; \
137 } while(0)
138 #define RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret)
139 
140 #else
141 
142 #define RAPTOR_ASSERT(condition, msg) do { \
143   if(condition) { \
144     RAPTOR_ASSERT_REPORT(msg) \
145     RAPTOR_ASSERT_DIE \
146   } \
147 } while(0)
148 
149 #define RAPTOR_ASSERT_RETURN(condition, msg, ret) do { \
150   if(condition) { \
151     RAPTOR_ASSERT_REPORT(msg) \
152     RAPTOR_ASSERT_DIE \
153     return ret; \
154   } \
155 } while(0)
156 
157 #define RAPTOR_ASSERT_OBJECT_POINTER_RETURN(pointer, type) do { \
158   if(!pointer) { \
159     RAPTOR_ASSERT_REPORT("object pointer of type " #type " is NULL.") \
160     RAPTOR_ASSERT_DIE \
161     return; \
162   } \
163 } while(0)
164 
165 #define RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret) do { \
166   if(!pointer) { \
167     RAPTOR_ASSERT_REPORT("object pointer of type " #type " is NULL.") \
168     RAPTOR_ASSERT_DIE \
169     return ret; \
170   } \
171 } while(0)
172 
173 #endif
174 
175 
176 /* Fatal errors - always happen */
177 #define RAPTOR_FATAL1(msg) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __func__); abort();} while(0)
178 #define RAPTOR_FATAL2(msg,arg) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __func__, arg); abort();} while(0)
179 #define RAPTOR_FATAL3(msg,arg1,arg2) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __func__, arg1, arg2); abort();} while(0)
180 
181 #define MAX_ASCII_INT_SIZE 13
182 
183 /* XML parser includes */
184 #ifdef RAPTOR_XML_EXPAT
185 #ifdef HAVE_EXPAT_H
186 #include <expat.h>
187 #endif
188 #ifdef HAVE_XMLPARSE_H
189 #include <xmlparse.h>
190 #endif
191 #endif
192 
193 
194 
195 
196 #ifdef RAPTOR_XML_LIBXML
197 
198 #include <libxml/parser.h>
199 
200 
201 /* libxml-only prototypes */
202 
203 
204 /* raptor_libxml.c exports */
205 extern void raptor_libxml_init(raptor_sax2* sax2, raptor_uri *base_uri);
206 extern void raptor_libxml_init_sax_error_handlers(xmlSAXHandler *sax);
207 extern void raptor_libxml_generic_error(void* user_data, const char *msg, ...) RAPTOR_PRINTF_FORMAT(2, 3);
208 
209 extern void raptor_libxml_validation_error(void *context, const char *msg, ...) RAPTOR_PRINTF_FORMAT(2, 3);
210 extern void raptor_libxml_validation_warning(void *context, const char *msg, ...) RAPTOR_PRINTF_FORMAT(2, 3);
211 void raptor_libxml_free(xmlParserCtxtPtr xc);
212 void raptor_libxml_xmlStructuredErrorFunc(void *user_data, xmlErrorPtr err);
213 
214 /* raptor_parse.c - exported to libxml part */
215 extern void raptor_libxml_update_document_locator(raptor_sax2* sax2, raptor_locator* locator);
216 
217 /* end of libxml-only */
218 #endif
219 
220 
221 /* expat-only prototypes */
222 
223 #ifdef RAPTOR_XML_EXPAT
224 /* raptor_expat.c exports */
225 extern void raptor_expat_init(raptor_sax2* sax2, raptor_uri *base_uri);
226 extern void raptor_expat_update_document_locator(raptor_sax2* sax2, raptor_locator *locator);
227 
228 /* raptor_parse.c */
229 void raptor_xml_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);
230 int raptor_xml_external_entity_ref_handler(void *user_data, const unsigned char* context, const unsigned char* base, const unsigned char* systemId, const unsigned char* publicId);
231 
232 /* end of expat-only */
233 #endif
234 
235 
236 typedef struct raptor_parser_factory_s raptor_parser_factory;
237 typedef struct raptor_serializer_factory_s raptor_serializer_factory;
238 typedef struct raptor_id_set_s raptor_id_set;
239 typedef struct raptor_uri_detail_s raptor_uri_detail;
240 
241 /* raptor_avltree.c */
242 /* AVL tree */
243 typedef struct raptor_avltree_s raptor_avltree;
244 typedef struct raptor_avltree_iterator_s raptor_avltree_iterator;
245 
246 typedef struct raptor_avltree_node_s raptor_avltree_node;
247 
248 /* user functions */
249 typedef int (*raptor_data_compare_function)(const void* data1, const void* data2);
250 typedef void (*raptor_data_free_function)(void* data);
251 typedef int (*raptor_avltree_visit_function)(int depth, void* data, void *user_data);
252 typedef void (*raptor_data_print_function)(FILE* handle, const void* data);
253 
254 /* AVL-tree */
255 struct raptor_avltree_s {
256   /* raptor_world object */
257   raptor_world* world;
258 
259   /* root node of tree */
260   raptor_avltree_node* root;
261 
262   /* node comparison function (optional) */
263   raptor_data_compare_function compare_fn;
264 
265   /* node deletion function (optional) */
266   raptor_data_free_function free_fn;
267 
268   /* node print function (optional) */
269   raptor_data_print_function print_fn;
270 
271   /* tree flags (none defined at present) */
272   unsigned int flags;
273 
274   /* number of nodes in tree */
275   unsigned int size;
276 
277   /* legacy iterator used for cursor methods */
278   raptor_avltree_iterator* cursor_iterator;
279 };
280 
281 
282 /* Raptor Namespace Stack node */
283 struct raptor_namespace_stack_s {
284   raptor_world* world;
285   int size;
286 
287   int table_size;
288   raptor_namespace** table;
289   raptor_namespace* def_namespace;
290   raptor_simple_message_handler error_handler;
291   void *error_data;
292 
293   raptor_uri *rdf_ms_uri;
294   raptor_uri *rdf_schema_uri;
295 };
296 
297 
298 /* Forms:
299  * 1) prefix=NULL uri=<URI>      - default namespace defined
300  * 2) prefix=NULL, uri=NULL      - no default namespace
301  * 3) prefix=<prefix>, uri=<URI> - regular pair defined <prefix>:<URI>
302  */
303 struct raptor_namespace_s {
304   /* next down the stack, NULL at bottom */
305   struct raptor_namespace_s* next;
306 
307   raptor_namespace_stack *nstack;
308 
309   /* NULL means is the default namespace */
310   const unsigned char *prefix;
311   /* needed to safely compare prefixed-names */
312   int prefix_length;
313   /* URI of namespace or NULL for default */
314   raptor_uri *uri;
315   /* parsing depth that this ns was added.  It will
316    * be deleted when the parser leaves this depth
317    */
318   int depth;
319   /* Non 0 if is xml: prefixed name */
320   int is_xml;
321   /* Non 0 if is RDF M&S Namespace */
322   int is_rdf_ms;
323   /* Non 0 if is RDF Schema Namespace */
324   int is_rdf_schema;
325 };
326 
327 raptor_namespace** raptor_namespace_stack_to_array(raptor_namespace_stack *nstack, size_t *size_p);
328 
329 #ifdef RAPTOR_XML_LIBXML
330 #define RAPTOR_LIBXML_MAGIC 0x8AF108
331 #endif
332 
333 
334 /*
335  * Raptor parser object
336  */
337 struct raptor_parser_s {
338   raptor_world* world;
339 
340 #ifdef RAPTOR_XML_LIBXML
341   int magic;
342 #endif
343 
344   /* can be filled with error location information */
345   raptor_locator locator;
346 
347   /* non 0 if parser had fatal error and cannot continue */
348   int failed;
349 
350   /* generated ID counter */
351   int genid;
352 
353   /* base URI of RDF/XML */
354   raptor_uri *base_uri;
355 
356   /* static statement for use in passing to user code */
357   raptor_statement statement;
358 
359   /* Features */
360   int features[RAPTOR_FEATURE_LAST+1];
361 
362   /* stuff for our user */
363   void *user_data;
364 
365   raptor_error_handlers error_handlers;
366 
367   void* unused1; /* UNUSED - re-use struct slot later needed */
368 
369   /* parser callbacks */
370   raptor_statement_handler statement_handler;
371 
372   raptor_graph_handler graph_handler;
373 
374   void *generate_id_handler_user_data;
375   raptor_generate_id_handler generate_id_handler;
376 
377   int default_generate_id_handler_base;
378   char *default_generate_id_handler_prefix;
379   size_t default_generate_id_handler_prefix_length;
380 
381   void* uri_filter_user_data;
382   raptor_uri_filter_func uri_filter;
383 
384   /* parser specific stuff */
385   void *context;
386 
387   struct raptor_parser_factory_s* factory;
388 
389   /* namespace callback */
390   raptor_namespace_handler namespace_handler;
391 
392   void* namespace_handler_user_data;
393 
394   raptor_stringbuffer* sb;
395 
396   /* raptor_www pointer stored here to allow cleanup on error */
397   raptor_www* www;
398 
399   /* internal data for lexers */
400   void* lexer_user_data;
401 
402   /* FEATURE:
403    * HTTP Cache-Control: header value to send (default NULL)
404    * RAPTOR_FEATURE_WWW_HTTP_CACHE_CONTROL
405    */
406   const char* cache_control;
407 
408   /* FEATURE:
409    * HTTP User-Agent: header value to send (default NULL)
410    * RAPTOR_FEATURE_WWW_HTTP_USER_AGENT
411    */
412   const char* user_agent;
413 
414   /* NOTE: if anything a user can set is added here check that
415    * raptor_parser_copy_user_state() is updated to copy it.
416    */
417 };
418 
419 
420 /** A list of (MIME Type, Q) values */
421 struct raptor_type_q_s {
422   const char* mime_type;
423   size_t mime_type_len;
424   int q; /* 0-10 standing for 0.0-1.0 */
425 };
426 typedef struct raptor_type_q_s raptor_type_q;
427 
428 
429 /** A Parser Factory for a syntax */
430 struct raptor_parser_factory_s {
431   raptor_world* world;
432 
433   struct raptor_parser_factory_s* next;
434 
435   /* syntax name */
436   const char* name;
437   /* alternate syntax name; not mentioned in enumerations */
438   const char* alias;
439 
440   /* syntax readable label */
441   const char* label;
442 
443   /* syntax MIME type (or NULL) */
444   raptor_sequence* mime_types;
445 
446   /* syntax URI (or NULL) */
447   const unsigned char* uri_string;
448 
449   /* the rest of this structure is populated by the
450      parser-specific register function */
451   size_t context_length;
452 
453   /* create a new parser */
454   int (*init)(raptor_parser* parser, const char *name);
455 
456   /* destroy a parser */
457   void (*terminate)(raptor_parser* parser);
458 
459   /* start a parse */
460   int (*start)(raptor_parser* parser);
461 
462   /* parse a chunk of memory */
463   int (*chunk)(raptor_parser* parser, const unsigned char *buffer, size_t len, int is_end);
464 
465   /* finish the parser factory */
466   void (*finish_factory)(raptor_parser_factory* factory);
467 
468   /* score recognition of the syntax by a block of characters, the
469    *  content identifier or it's suffix or a mime type
470    *  (different from the factory-registered one)
471    */
472   int (*recognise_syntax)(raptor_parser_factory* factory, const unsigned char *buffer, size_t len, const unsigned char *identifier, const unsigned char *suffix, const char *mime_type);
473 
474   /* get the Content-Type value of a URI request */
475   void (*content_type_handler)(raptor_parser* rdf_parser, const char* content_type);
476 
477   /* get the Accept header of a URI request (OPTIONAL) */
478   const char* (*accept_header)(raptor_parser* rdf_parser);
479 
480   /* non-0 if this parser needs a base URI */
481   int need_base_uri;
482 
483   /* get the current generated ID base (OPTIONAL) */
484   int (*get_current_base_id)(raptor_parser* rdf_parser);
485 
486   /* get the name (OPTIONAL) */
487   const char* (*get_name)(raptor_parser* rdf_parser);
488 };
489 
490 
491 /*
492  * Raptor serializer object
493  */
494 struct raptor_serializer_s {
495   raptor_world* world;
496 
497   /* can be filled with error location information */
498   raptor_locator locator;
499 
500   /* FEATURE:
501    * non 0 to write base URI to document header (@base)
502    */
503   int feature_write_base_uri;
504 
505   /* FEATURE:
506    * non 0 to write relative URIs wherever possible
507    */
508   int feature_relative_uris;
509 
510   /* FEATURE:
511    * non NULL to start serializing from this URI
512    */
513   raptor_uri* feature_start_uri;
514 
515   /* FEATURES:
516    * non NULL to override default border color
517    */
518   unsigned char *feature_resource_border;
519   unsigned char *feature_literal_border;
520   unsigned char *feature_bnode_border;
521 
522   /* FEATURES:
523    * non NULL to fill with value
524    */
525   unsigned char *feature_resource_fill;
526   unsigned char *feature_literal_fill;
527   unsigned char *feature_bnode_fill;
528 
529   void *error_user_data;
530   void *warning_user_data;
531 
532   raptor_message_handler error_handler;
533   raptor_message_handler warning_handler;
534 
535   /* non 0 if serializer had fatal error and cannot continue */
536   int failed;
537 
538   /* base URI of RDF/XML */
539   raptor_uri *base_uri;
540 
541   /* serializer specific stuff */
542   void *context;
543 
544   /* destination stream for the serialization */
545   raptor_iostream *iostream;
546 
547   /* if true, iostream was made here so free it */
548   int free_iostream_on_end;
549 
550   struct raptor_serializer_factory_s* factory;
551 
552   /* XML 1.0 (10) or XML 1.1 (11) */
553   int xml_version;
554 
555   /* FEATURE:
556    * non 0 to write XML 1.0 or 1.1 declaration (default 1)
557    */
558   int feature_write_xml_declaration;
559 
560   /* FEATURE:
561    * JSON serializer callback function name
562    */
563   unsigned char *feature_json_callback;
564 
565   /* FEATURE:
566    * JSON serializer extra data
567    */
568   unsigned char *feature_json_extra_data;
569 
570   /* FEATURE:
571    * RSS serializer triples
572    */
573   unsigned char *feature_rss_triples;
574 
575   /* FEATURE:
576    * Atom serializer entry URI string
577    */
578   unsigned char *feature_atom_entry_uri;
579 
580   /* FEATURE:
581    * Namespace-prefix elements OR prefer unprefixed elements.
582    */
583   int feature_prefix_elements;
584 };
585 
586 
587 /** A Serializer Factory for a syntax */
588 struct raptor_serializer_factory_s {
589   raptor_world* world;
590 
591   struct raptor_serializer_factory_s* next;
592 
593   /* syntax name */
594   const char* name;
595   /* alternate syntax name; not mentioned in enumerations */
596   const char* alias;
597 
598   /* syntax readable label */
599   const char* label;
600   /* syntax MIME type (or NULL) */
601   const char* mime_type;
602   /* syntax URI (or NULL) */
603   const unsigned char* uri_string;
604 
605   /* the rest of this structure is populated by the
606      serializer-specific register function */
607   size_t context_length;
608 
609   /* create a new serializer */
610   int (*init)(raptor_serializer* serializer, const char *name);
611 
612   /* destroy a serializer */
613   void (*terminate)(raptor_serializer* serializer);
614 
615   /* add a namespace */
616   int (*declare_namespace)(raptor_serializer* serializer, raptor_uri *uri, const unsigned char *prefix);
617 
618   /* start a serialization */
619   int (*serialize_start)(raptor_serializer* serializer);
620 
621   /* serialize a statement */
622   int (*serialize_statement)(raptor_serializer* serializer, const raptor_statement *statment);
623 
624   /* end a serialization */
625   int (*serialize_end)(raptor_serializer* serializer);
626 
627   /* finish the serializer factory */
628   void (*finish_factory)(raptor_serializer_factory* factory);
629 
630   /* add a namespace using an existing namespace */
631   int (*declare_namespace_from_namespace)(raptor_serializer* serializer, raptor_namespace *nspace);
632 };
633 
634 
635 /* for raptor_parse_uri_write_bytes() when used as a handler for
636  * raptor_www_set_write_bytes_handler()
637  */
638 typedef struct
639 {
640   raptor_parser* rdf_parser;
641   raptor_uri* base_uri;
642   raptor_uri* final_uri;
643   int started;
644 } raptor_parse_bytes_context;
645 
646 
647 /* raptor_serialize.c */
648 int raptor_serializer_register_factory(raptor_world* world, const char *name, const char *label, const char *mime_type, const char *alias, const unsigned char *uri_string, int (*factory) (raptor_serializer_factory*));
649 
650 
651 /* raptor_general.c */
652 
653 raptor_parser_factory* raptor_parser_register_factory(raptor_world* world, const char *name, const char *label, int (*factory) (raptor_parser_factory*));
654 int raptor_parser_factory_add_alias(raptor_parser_factory* factory, const char *alias);
655 int raptor_parser_factory_add_mime_type(raptor_parser_factory* factory, const char* mime_type, int q);
656 int raptor_parser_factory_add_uri(raptor_parser_factory* factory, const unsigned char *uri_string);
657 
658 unsigned char* raptor_parser_internal_generate_id(raptor_parser *rdf_parser, raptor_genid_type type, unsigned char *user_bnodeid);
659 
660 #ifdef RAPTOR_DEBUG
661 void raptor_stats_print(raptor_parser *rdf_parser, FILE *stream);
662 #endif
663 const char* raptor_basename(const char *name);
664 raptor_statement* raptor_statement_copy(raptor_world* world, const raptor_statement *statement);
665 raptor_statement_v2* raptor_statement_copy_v2(const raptor_statement_v2 *statement);
666 raptor_statement_v2* raptor_statement_copy_v2_from_v1(raptor_world* world, const raptor_statement *statement);
667 void raptor_free_statement(raptor_world* world, raptor_statement *statement);
668 void raptor_free_statement_v2(raptor_statement_v2 *statement);
669 void raptor_print_statement_v1(raptor_world* world, const raptor_statement * statement, FILE *stream);
670 
671 /* raptor_parse.c */
672 raptor_parser_factory* raptor_get_parser_factory(raptor_world* world, const char *name);
673 void raptor_delete_parser_factories(void);
674 const char* raptor_parser_get_accept_header_all(raptor_world* world);
675 int raptor_parse_uri_no_net_filter(void *user_data, raptor_uri* uri);
676 void raptor_parse_uri_write_bytes(raptor_www* www, void *userdata, const void *ptr, size_t size, size_t nmemb);
677 void raptor_parser_fatal_error(raptor_parser* parser, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
678 void raptor_parser_error(raptor_parser* parser, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
679 void raptor_parser_simple_error(void* parser, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
680 void raptor_parser_error_varargs(raptor_parser* parser, const char *message, va_list arguments) RAPTOR_PRINTF_FORMAT(2, 0);
681 void raptor_parser_warning(raptor_parser* parser, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
682 
683 /* logging */
684 #define RAPTOR_ERROR_HANDLER_MAGIC 0xD00DB1FF
685 
686 void raptor_log_error_to_handlers(raptor_world* world, raptor_error_handlers* error_handlers, raptor_log_level level, raptor_locator* locator, const char* message);
687 void raptor_log_error_varargs(raptor_world* world, raptor_log_level level, raptor_message_handler handler, void* handler_data, raptor_locator* locator, const char* message, va_list arguments) RAPTOR_PRINTF_FORMAT(6, 0);
688 void raptor_log_error(raptor_world* world, raptor_log_level level, raptor_message_handler handler, void* handler_data, raptor_locator* locator, const char* message);
689 
690 
691 /* raptor_parse.c */
692 
693 typedef struct raptor_rdfxml_parser_s raptor_rdfxml_parser;
694 
695 /* Prototypes for common expat/libxml parsing event-handling functions */
696 extern void raptor_xml_start_element_handler(void *user_data, const unsigned char *name, const unsigned char **atts);
697 extern void raptor_xml_end_element_handler(void *user_data, const unsigned char *name);
698 /* s is not 0 terminated. */
699 extern void raptor_xml_characters_handler(void *user_data, const unsigned char *s, int len);
700 extern void raptor_xml_cdata_handler(void *user_data, const unsigned char *s, int len);
701 void raptor_xml_comment_handler(void *user_data, const unsigned char *s);
702 
703 #if RAPTOR_DEBUG > 1
704 void raptor_rdfxml_parser_stats_print(raptor_rdfxml_parser* rdf_xml_parser, FILE *stream);
705 #endif
706 
707 int raptor_parser_copy_user_state(raptor_parser *to_parser, raptor_parser *from_parser);
708 
709 /* raptor_feature.c */
710 int raptor_features_enumerate_common(raptor_world* world, const raptor_feature feature, const char **name, raptor_uri **uri, const char **label, int flags);
711 
712 /* raptor_general.c */
713 extern int raptor_valid_xml_ID(raptor_parser *rdf_parser, const unsigned char *string);
714 int raptor_check_ordinal(const unsigned char *name);
715 
716 /* raptor_identifier.c */
717 void raptor_set_identifier_uri(raptor_identifier *identifier, raptor_uri *uri);
718 void raptor_set_identifier_id(raptor_identifier *identifier, const unsigned char *id);
719 #ifdef RAPTOR_DEBUG
720 void raptor_identifier_print(FILE *stream, raptor_identifier* identifier);
721 #endif
722 
723 /* raptor_locator.c */
724 
725 
726 #ifdef HAVE_STRCASECMP
727 #define raptor_strcasecmp strcasecmp
728 #define raptor_strncasecmp strncasecmp
729 #else
730 #ifdef HAVE_STRICMP
731 #define raptor_strcasecmp stricmp
732 #define raptor_strncasecmp strnicmp
733 #endif
734 #endif
735 
736 
737 /* raptor_nfc.c */
738 int raptor_nfc_check (const unsigned char* string, size_t len, int *error);
739 
740 
741 /* raptor_namespace.c */
742 
743 #ifdef RAPTOR_DEBUG
744 void raptor_namespace_print(FILE *stream, raptor_namespace* ns);
745 #endif
746 
747 void raptor_parser_start_namespace(raptor_parser* rdf_parser, raptor_namespace* nspace);
748 
749 
750 /*
751  * Raptor XML-namespace qualified name (qname), for elements or attributes
752  *
753  * namespace is only defined when the XML name has a namespace and
754  * only then is uri also given.
755  */
756 struct raptor_qname_s {
757   raptor_world* world;
758   /* Name - always present */
759   const unsigned char *local_name;
760   int local_name_length;
761   /* Namespace or NULL if not in a namespace */
762   const raptor_namespace *nspace;
763   /* URI of namespace+local_name or NULL if not defined */
764   raptor_uri *uri;
765   /* optional value - used when name is an attribute */
766   const unsigned char *value;
767   unsigned int value_length;
768 };
769 
770 
771 
772 /* raptor_qname.c */
773 #ifdef RAPTOR_DEBUG
774 void raptor_qname_print(FILE *stream, raptor_qname* name);
775 #endif
776 
777 
778 /* raptor_uri.c */
779 int raptor_uri_init(raptor_world* world);
780 raptor_uri* raptor_new_uri_from_rdf_ordinal(raptor_world* world, int ordinal);
781 
782 /* parsers */
783 int raptor_init_parser_rdfxml(raptor_world* world);
784 int raptor_init_parser_ntriples(raptor_world* world);
785 int raptor_init_parser_turtle(raptor_world* world);
786 int raptor_init_parser_trig(raptor_world* world);
787 int raptor_init_parser_n3(raptor_world* world);
788 int raptor_init_parser_grddl_common(raptor_world* world);
789 int raptor_init_parser_grddl(raptor_world* world);
790 int raptor_init_parser_guess(raptor_world* world);
791 int raptor_init_parser_rss(raptor_world* world);
792 int raptor_init_parser_rdfa(raptor_world* world);
793 
794 void raptor_terminate_parser_grddl_common(raptor_world *world);
795 
796 /* raptor_parse.c */
797 int raptor_parsers_init(raptor_world* world);
798 void raptor_parsers_finish(raptor_world *world);
799 
800 void raptor_parser_save_content(raptor_parser* rdf_parser, int save);
801 const unsigned char* raptor_parser_get_content(raptor_parser* rdf_parser, size_t* length_p);
802 void raptor_parser_set_graph_name(raptor_parser* parser, raptor_uri* uri);
803 int raptor_parser_get_current_base_id(raptor_parser* parser);
804 
805 /* raptor_rss.c */
806 int raptor_init_serializer_rss10(raptor_world* world);
807 int raptor_init_serializer_atom(raptor_world* world);
808 
809 extern const unsigned char * const raptor_atom_namespace_uri;
810 
811 /* raptor_rfc2396.c */
812 raptor_uri_detail* raptor_new_uri_detail(const unsigned char *uri_string);
813 void raptor_free_uri_detail(raptor_uri_detail* uri_detail);
814 unsigned char* raptor_uri_detail_to_string(raptor_uri_detail *ud, size_t* len_p);
815 
816 /* serializers */
817 int raptor_init_serializer_rdfxml(raptor_world* world);
818 int raptor_init_serializer_ntriples(raptor_world* world);
819 int raptor_init_serializer_dot(raptor_world* world);
820 int raptor_init_serializer_simple(raptor_world* world);
821 
822 /* raptor_serializer.c */
823 int raptor_serializers_init(raptor_world* world);
824 void raptor_serializers_finish(raptor_world* world);
825 
826 void raptor_serializer_error(raptor_serializer* serializer, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
827 void raptor_serializer_simple_error(void* serializer, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
828 void raptor_serializer_error_varargs(raptor_serializer* serializer, const char *message,  va_list arguments) RAPTOR_PRINTF_FORMAT(2, 0);
829 void raptor_serializer_warning(raptor_serializer* serializer, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
830 void raptor_serializer_warning_varargs(raptor_serializer* serializer, const char *message, va_list arguments) RAPTOR_PRINTF_FORMAT(2, 0);
831 
832 /* raptor_serialize_rdfxmla.c */
833 int raptor_init_serializer_rdfxmla(raptor_world* world);
834 
835 /* raptor_serialize_turtle.c */
836 int raptor_init_serializer_turtle(raptor_world* world);
837 
838 /* raptor_serialize_json.c */
839 int raptor_init_serializer_json(raptor_world* world);
840 
841 /* raptor_utf8.c */
842 int raptor_unicode_is_namestartchar(raptor_unichar c);
843 int raptor_unicode_is_namechar(raptor_unichar c);
844 int raptor_utf8_is_nfc(const unsigned char *input, size_t length);
845 
846 /* raptor_www*.c */
847 #ifdef RAPTOR_WWW_LIBXML
848 #include <libxml/parser.h>
849 #include <libxml/xmlerror.h>
850 #include <libxml/nanohttp.h>
851 #endif
852 
853 #ifdef RAPTOR_WWW_LIBCURL
854 #include <curl/curl.h>
855 #include <curl/easy.h>
856 #endif
857 
858 /* Size of buffer used in various raptor_www places for I/O  */
859 #ifndef RAPTOR_WWW_BUFFER_SIZE
860 #define RAPTOR_WWW_BUFFER_SIZE 4096
861 #endif
862 
863 /* WWW library state */
864 struct  raptor_www_s {
865   raptor_world* world;
866   char *type;
867   int free_type;
868   int total_bytes;
869   int failed;
870   int status_code;
871 
872   raptor_uri *uri;
873 
874 #ifdef RAPTOR_WWW_LIBCURL
875   CURL* curl_handle;
876   char error_buffer[CURL_ERROR_SIZE];
877   int curl_init_here;
878   int checked_status;
879 #endif
880 
881 #ifdef RAPTOR_WWW_LIBXML
882   void *ctxt;
883   char buffer[RAPTOR_WWW_BUFFER_SIZE];
884   int is_end;
885   void *old_xmlGenericErrorContext;
886 #endif
887 
888 #ifdef RAPTOR_WWW_LIBFETCH
889   char buffer[RAPTOR_WWW_BUFFER_SIZE];
890 #endif
891 
892   char *user_agent;
893 
894   /* proxy URL string or NULL for none */
895   char *proxy;
896 
897   void *write_bytes_userdata;
898   raptor_www_write_bytes_handler write_bytes;
899   void *content_type_userdata;
900   raptor_www_content_type_handler content_type;
901 
902   void* uri_filter_user_data;
903   raptor_uri_filter_func uri_filter;
904 
905   /* can be filled with error location information */
906   raptor_locator locator;
907 
908   char *http_accept;
909 
910   FILE* handle;
911 
912   raptor_error_handlers error_handlers;
913 
914   int connection_timeout;
915 
916   /* The URI returned after any redirections */
917   raptor_uri* final_uri;
918 
919   void *final_uri_userdata;
920   raptor_www_final_uri_handler final_uri_handler;
921 
922   char* cache_control;
923 };
924 
925 
926 
927 /* internal */
928 void raptor_www_libxml_init(raptor_www *www);
929 void raptor_www_libxml_free(raptor_www *www);
930 int raptor_www_libxml_fetch(raptor_www *www);
931 
932 void raptor_www_error(raptor_www *www, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
933 
934 void raptor_www_curl_init(raptor_www *www);
935 void raptor_www_curl_free(raptor_www *www);
936 int raptor_www_curl_fetch(raptor_www *www);
937 
938 void raptor_www_libfetch_init(raptor_www *www);
939 void raptor_www_libfetch_free(raptor_www *www);
940 int raptor_www_libfetch_fetch(raptor_www *www);
941 
942 /* raptor_set.c */
943 raptor_id_set* raptor_new_id_set(raptor_world* world);
944 void raptor_free_id_set(raptor_id_set* set);
945 int raptor_id_set_add(raptor_id_set* set, raptor_uri* base_uri, const unsigned char *item, size_t item_len);
946 #if RAPTOR_DEBUG > 1
947 void raptor_id_set_stats_print(raptor_id_set* set, FILE *stream);
948 #endif
949 
950 /* raptor_sax2.c */
951 /*
952  * SAX2 elements/attributes on stack
953  */
954 struct raptor_xml_element_s {
955   /* NULL at bottom of stack */
956   struct raptor_xml_element_s *parent;
957   raptor_qname *name;
958   raptor_qname **attributes;
959   unsigned int attribute_count;
960 
961   /* value of xml:lang attribute on this element or NULL */
962   const unsigned char *xml_language;
963 
964   /* URI of xml:base attribute value on this element or NULL */
965   raptor_uri *base_uri;
966 
967   /* CDATA content of element and checks for mixed content */
968   raptor_stringbuffer* content_cdata_sb;
969   unsigned int content_cdata_length;
970   /* how many cdata blocks seen */
971   unsigned int content_cdata_seen;
972   /* how many contained elements seen */
973   unsigned int content_element_seen;
974 
975   raptor_sequence *declared_nspaces;
976 
977   void* user_data;
978 };
979 
980 
981 struct raptor_sax2_s {
982 #ifdef RAPTOR_XML_LIBXML
983   int magic;
984 #endif
985   raptor_world* world;
986   void* user_data;
987 
988 #ifdef RAPTOR_XML_EXPAT
989   XML_Parser xp;
990 #ifdef EXPAT_UTF8_BOM_CRASH
991   int tokens_count; /* used to see if trying to get location info is safe */
992 #endif
993 #endif
994 #ifdef RAPTOR_XML_LIBXML
995   /* structure holding sax event handlers */
996   xmlSAXHandler sax;
997   /* parser context */
998   xmlParserCtxtPtr xc;
999   /* pointer to SAX document locator */
1000   xmlSAXLocatorPtr loc;
1001 
1002 #if LIBXML_VERSION < 20425
1003   /* flag for some libxml eversions*/
1004   int first_read;
1005 #endif
1006 
1007   void *saved_structured_error_context;
1008   xmlStructuredErrorFunc saved_structured_error_handler;
1009 
1010   void *saved_generic_error_context;
1011   xmlGenericErrorFunc saved_generic_error_handler;
1012 
1013 #endif
1014 
1015   /* element depth */
1016   int depth;
1017 
1018   /* stack of elements - elements add after current_element */
1019   raptor_xml_element *root_element;
1020   raptor_xml_element *current_element;
1021 
1022   /* start of an element */
1023   raptor_sax2_start_element_handler start_element_handler;
1024   /* end of an element */
1025   raptor_sax2_end_element_handler end_element_handler;
1026   /* characters */
1027   raptor_sax2_characters_handler characters_handler;
1028   /* like <![CDATA[...]> */
1029   raptor_sax2_cdata_handler cdata_handler;
1030   /* comment */
1031   raptor_sax2_comment_handler comment_handler;
1032   /* unparsed (NDATA) entity */
1033   raptor_sax2_unparsed_entity_decl_handler unparsed_entity_decl_handler;
1034   /* external entity reference */
1035   raptor_sax2_external_entity_ref_handler external_entity_ref_handler;
1036 
1037   raptor_locator *locator;
1038 
1039   raptor_error_handlers* error_handlers;
1040 
1041   /* New XML namespace callback */
1042   raptor_namespace_handler  namespace_handler;
1043 
1044   /* FEATURE:
1045    * non 0 if require normalizing xml:lang attribute values to lowercase.
1046    */
1047   int feature_normalize_language;
1048 
1049   /* FEATURE:
1050    * non 0 if network access is denied
1051    */
1052   int feature_no_net;
1053 
1054   /* stack of namespaces, most recently added at top */
1055   raptor_namespace_stack namespaces;
1056 
1057   /* base URI for resolving relative URIs or xml:base URIs */
1058   raptor_uri* base_uri;
1059 
1060   /* sax2 init failed - do not try to do anything with it */
1061   int failed;
1062 
1063    /* call SAX2 handlers if non-0 */
1064    int enabled;
1065 
1066   /* FEATURE:
1067    * non 0 if XML entities should be loaded
1068    */
1069   int feature_load_external_entities;
1070 };
1071 
1072 int raptor_sax2_init(raptor_world* world);
1073 void raptor_sax2_finish(raptor_world* world);
1074 
1075 
1076 raptor_xml_element* raptor_xml_element_pop(raptor_sax2* sax2);
1077 void raptor_xml_element_push(raptor_sax2* sax2, raptor_xml_element* element);
1078 int raptor_sax2_get_depth(raptor_sax2* sax2);
1079 void raptor_sax2_inc_depth(raptor_sax2* sax2);
1080 void raptor_sax2_dec_depth(raptor_sax2* sax2);
1081 void raptor_sax2_update_document_locator(raptor_sax2* sax2, raptor_locator* locator);
1082 int raptor_sax2_set_feature(raptor_sax2* sax2, raptor_feature feature, int value);
1083 
1084 #ifdef RAPTOR_DEBUG
1085 void raptor_print_xml_element(raptor_xml_element *element, FILE* stream);
1086 #endif
1087 
1088 void raptor_sax2_start_element(void* user_data, const unsigned char *name, const unsigned char **atts);
1089 void raptor_sax2_end_element(void* user_data, const unsigned char *name);
1090 void raptor_sax2_characters(void* user_data, const unsigned char *s, int len);
1091 void raptor_sax2_cdata(void* user_data, const unsigned char *s, int len);
1092 void raptor_sax2_comment(void* user_data, const unsigned char *s);
1093 void raptor_sax2_unparsed_entity_decl(void* user_data, const unsigned char* entityName, const unsigned char* base, const unsigned char* systemId, const unsigned char* publicId, const unsigned char* notationName);
1094 int raptor_sax2_external_entity_ref(void* user_data, const unsigned char* context, const unsigned char* base, const unsigned char* systemId, const unsigned char* publicId);
1095 
1096 
1097 /* turtle_parser.y and turtle_lexer.l */
1098 typedef struct raptor_turtle_parser_s raptor_turtle_parser;
1099 
1100 /* n3_parser.y and n3_lexer.l */
1101 typedef struct raptor_n3_parser_s raptor_n3_parser;
1102 
1103 typedef struct {
1104   raptor_identifier *subject;
1105   raptor_identifier *predicate;
1106   raptor_identifier *object;
1107 } raptor_triple;
1108 
1109 
1110 /* raptor_rfc2396.c */
1111 struct raptor_uri_detail_s
1112 {
1113   size_t uri_len;
1114   /* buffer is the same size as the original uri_len */
1115   unsigned char *buffer;
1116 
1117   /* URI Components.  These all point into buffer */
1118   unsigned char *scheme;
1119   unsigned char *authority;
1120   unsigned char *path;
1121   unsigned char *query;
1122   unsigned char *fragment;
1123 
1124   /* Lengths of the URI Components  */
1125   size_t scheme_len;
1126   size_t authority_len;
1127   size_t path_len;
1128   size_t query_len;
1129   size_t fragment_len;
1130 
1131   /* Flags */
1132   int is_hierarchical;
1133 };
1134 
1135 
1136 /* for time_t */
1137 #if TIME_WITH_SYS_TIME
1138 # include <sys/time.h>
1139 # include <time.h>
1140 #else
1141 # if HAVE_SYS_TIME_H
1142 #  include <sys/time.h>
1143 # else
1144 #  include <time.h>
1145 # endif
1146 #endif
1147 
1148 /* parsedate.c */
1149 #ifdef HAVE_INN_PARSEDATE
1150 #include <libinn.h>
1151 #define RAPTOR_PARSEDATE_FUNCTION parsedate
1152 #else
1153 #ifdef HAVE_RAPTOR_PARSE_DATE
1154 time_t raptor_parse_date(const char *p, time_t *now);
1155 #define RAPTOR_PARSEDATE_FUNCTION raptor_parse_date
1156 #else
1157 #ifdef HAVE_CURL_CURL_H
1158 #include <curl/curl.h>
1159 #define RAPTOR_PARSEDATE_FUNCTION curl_getdate
1160 #endif
1161 #endif
1162 #endif
1163 
1164 /* turtle_common.c */
1165 int raptor_stringbuffer_append_turtle_string(raptor_stringbuffer* stringbuffer, const unsigned char *text, size_t len, int delim, raptor_simple_message_handler error_handler, void *error_data);
1166 
1167 
1168 /* raptor_xsd.c */
1169 raptor_identifier* raptor_new_identifier_from_double(raptor_world* world, double d);
1170 
1171 
1172 /* raptor_abbrev.c */
1173 
1174 typedef struct {
1175   raptor_world* world;
1176   int ref_count;         /* count of references to this node */
1177   int count_as_subject;  /* count of this blank/resource node as subject */
1178   int count_as_object;   /* count of this blank/resource node as object */
1179 
1180   raptor_identifier_type type;  /* node type */
1181   union {
1182 
1183     struct {
1184       raptor_uri *uri;
1185     } resource;
1186 
1187     struct {
1188       unsigned char *string;
1189       raptor_uri *datatype;
1190       unsigned char *language;
1191     } literal;
1192 
1193     struct {
1194       int ordinal;
1195     } ordinal;
1196 
1197     struct {
1198       unsigned char *string;
1199     } blank;
1200 
1201   } value;
1202 } raptor_abbrev_node;
1203 
1204 
1205 typedef struct {
1206   raptor_abbrev_node* node;      /* node representing the subject of
1207                                   * this resource */
1208   raptor_abbrev_node* node_type; /* the rdf:type of this resource */
1209   raptor_avltree *properties;    /* list of properties
1210                                   * (predicate/object pair) of this
1211                                   * subject */
1212   raptor_sequence *list_items;   /* list of container elements if
1213                                   * is rdf container */
1214   int valid;                     /* set 0 for blank nodes that do not
1215                                   * need to be referred to again */
1216 } raptor_abbrev_subject;
1217 
1218 
1219 raptor_abbrev_node* raptor_new_abbrev_node(raptor_world* world, raptor_identifier_type node_type, const void *node_data, raptor_uri *datatype, const unsigned char *language);
1220 void raptor_free_abbrev_node(raptor_abbrev_node* node);
1221 int raptor_abbrev_node_cmp(raptor_abbrev_node* node1, raptor_abbrev_node* node2);
1222 int raptor_abbrev_node_equals(raptor_abbrev_node* node1, raptor_abbrev_node* node2);
1223 raptor_abbrev_node* raptor_abbrev_node_lookup(raptor_avltree* nodes, raptor_identifier_type node_type, const void *node_value, raptor_uri *datatype, const unsigned char *language, int* created_p);
1224 
1225 raptor_abbrev_subject* raptor_new_abbrev_subject(raptor_abbrev_node* node);
1226 void raptor_free_abbrev_subject(raptor_abbrev_subject* subject);
1227 int raptor_abbrev_subject_add_property(raptor_abbrev_subject* subject, raptor_abbrev_node* predicate, raptor_abbrev_node* object);
1228 int raptor_abbrev_subject_add_list_element(raptor_abbrev_subject* subject, int ordinal, raptor_abbrev_node* object);
1229 int raptor_abbrev_subject_cmp(raptor_abbrev_subject* subject1, raptor_abbrev_subject* subject2);
1230 raptor_abbrev_subject* raptor_abbrev_subject_find(raptor_avltree *subjects, raptor_identifier_type node_type, const void *node_data);
1231 raptor_abbrev_subject* raptor_abbrev_subject_lookup(raptor_avltree* nodes, raptor_avltree* subjects, raptor_avltree* blanks, raptor_identifier_type node_type, const void *node_data, int* created_p);
1232 int raptor_abbrev_subject_valid(raptor_abbrev_subject *subject);
1233 int raptor_abbrev_subject_invalidate(raptor_abbrev_subject *subject);
1234 
1235 unsigned char *raptor_unique_id(unsigned char *base);
1236 
1237 raptor_qname* raptor_new_qname_from_resource(raptor_sequence* namespaces, raptor_namespace_stack* nstack, int* namespace_count, raptor_abbrev_node* node);
1238 
1239 
1240 /**
1241  * raptor_turtle_writer:
1242  *
1243  * Raptor Turtle Writer class
1244  */
1245 typedef struct raptor_turtle_writer_s raptor_turtle_writer;
1246 
1247 /* Turtle Writer Class (raptor_turtle_writer) */
1248 raptor_turtle_writer* raptor_new_turtle_writer(raptor_world* world, raptor_uri* base_uri, int write_base_uri, raptor_namespace_stack *nstack, raptor_iostream* iostr, raptor_simple_message_handler error_handler, void *error_data);
1249 void raptor_free_turtle_writer(raptor_turtle_writer* turtle_writer);
1250 void raptor_turtle_writer_raw(raptor_turtle_writer* turtle_writer, const unsigned char *s);
1251 void raptor_turtle_writer_raw_counted(raptor_turtle_writer* turtle_writer, const unsigned char *s, unsigned int len);
1252 void raptor_turtle_writer_namespace_prefix(raptor_turtle_writer* turtle_writer, raptor_namespace* ns);
1253 void raptor_turtle_writer_base(raptor_turtle_writer* turtle_writer, raptor_uri* base_uri);
1254 void raptor_turtle_writer_increase_indent(raptor_turtle_writer *turtle_writer);
1255 void raptor_turtle_writer_decrease_indent(raptor_turtle_writer *turtle_writer);
1256 void raptor_turtle_writer_newline(raptor_turtle_writer *turtle_writer);
1257 void raptor_turtle_writer_reference(raptor_turtle_writer* turtle_writer, raptor_uri* uri);
1258 int raptor_turtle_writer_literal(raptor_turtle_writer* turtle_writer, raptor_namespace_stack *nstack, const unsigned char *s, const unsigned char* lang, raptor_uri* datatype);
1259 void raptor_turtle_writer_qname(raptor_turtle_writer* turtle_writer, raptor_qname* qname);
1260 int raptor_turtle_writer_quoted_counted_string(raptor_turtle_writer* turtle_writer, const unsigned char *s, size_t length);
1261 void raptor_turtle_writer_comment(raptor_turtle_writer* turtle_writer, const unsigned char *s);
1262 int raptor_turtle_writer_features_enumerate(raptor_world* world, const raptor_feature feature, const char **name,  raptor_uri **uri, const char **label);
1263 int raptor_turtle_writer_set_feature(raptor_turtle_writer *turtle_writer, raptor_feature feature, int value);
1264 int raptor_turtle_writer_set_feature_string(raptor_turtle_writer *turtle_writer, raptor_feature feature, const unsigned char *value);
1265 int raptor_turtle_writer_get_feature(raptor_turtle_writer *turtle_writer, raptor_feature feature);
1266 const unsigned char *raptor_turtle_writer_get_feature_string(raptor_turtle_writer *turtle_writer, raptor_feature feature);
1267 
1268 
1269 /**
1270  * raptor_json_writer:
1271  *
1272  * Raptor JSON Writer class
1273  */
1274 typedef struct raptor_json_writer_s raptor_json_writer;
1275 
1276 /* raptor_json_writer.c */
1277 raptor_json_writer* raptor_new_json_writer(raptor_world* world, raptor_uri* base_uri, raptor_iostream* iostr, raptor_simple_message_handler error_handler, void *error_data);
1278 void raptor_free_json_writer(raptor_json_writer* json_writer);
1279 
1280 int raptor_json_writer_newline(raptor_json_writer* json_writer);
1281 int raptor_json_writer_key_value(raptor_json_writer* json_writer, const char* key, size_t key_len, const char* value, size_t value_len);
1282 int raptor_json_writer_start_block(raptor_json_writer* json_writer, char c);
1283 int raptor_json_writer_end_block(raptor_json_writer* json_writer, char c);
1284 int raptor_json_writer_literal_object(raptor_json_writer* json_writer, unsigned char* s, unsigned char* lang, raptor_uri* datatype, const char* key, const char* type_key);
1285 int raptor_json_writer_blank_object(raptor_json_writer* json_writer, const char* blank);
1286 int raptor_json_writer_uri_object(raptor_json_writer* json_writer, raptor_uri* uri);
1287 int raptor_json_writer_key_uri_value(raptor_json_writer* json_writer, const char* key, size_t key_len, raptor_uri* uri);
1288 
1289 /* raptor_memstr.c */
1290 const char* raptor_memstr(const char *haystack, size_t haystack_len, const char *needle);
1291 
1292 /* raptor_serialize_rdfxmla.c special functions for embedding rdf/xml */
1293 int raptor_rdfxmla_serialize_set_write_rdf_RDF(raptor_serializer* serializer, int value);
1294 int raptor_rdfxmla_serialize_set_xml_writer(raptor_serializer* serializer, raptor_xml_writer* xml_writer, raptor_namespace_stack *nstack);
1295 int raptor_rdfxmla_serialize_set_single_node(raptor_serializer* serializer, raptor_uri* uri);
1296 int raptor_rdfxmla_serialize_set_write_typed_nodes(raptor_serializer* serializer, int value);
1297 
1298 /* snprintf.c */
1299 char* raptor_format_float(char *buffer, size_t *currlen, size_t maxlen, double fvalue, unsigned int min, unsigned int max, int flags);
1300 
1301 /* constructor / destructor */
1302 
1303 #define RAPTOR_AVLTREE_FLAG_REPLACE_DUPLICATES 1
1304 
1305 raptor_avltree* raptor_new_avltree(raptor_world* world, raptor_data_compare_function compare_fn, raptor_data_free_function free_fn, unsigned int flags);
1306 void raptor_free_avltree(raptor_avltree* tree);
1307 
1308 /* methods */
1309 int raptor_avltree_add(raptor_avltree* tree, void* p_user);
1310 void* raptor_avltree_remove(raptor_avltree* tree, void* p_data);
1311 int raptor_avltree_delete(raptor_avltree* tree, void* p_user);
1312 void* raptor_avltree_search(raptor_avltree* tree, const void* p_user);
1313 int raptor_avltree_visit(raptor_avltree* tree, raptor_avltree_visit_function visit_fn, void* user_data);
1314 int raptor_avltree_size(raptor_avltree* tree);
1315 void raptor_avltree_set_print_handler(raptor_avltree* tree, raptor_data_print_function print_fn);
1316 void raptor_avltree_print(raptor_avltree* tree, FILE* stream);
1317 
1318 #ifdef RAPTOR_DEBUG
1319 int raptor_avltree_dump(raptor_avltree* tree, FILE* stream);
1320 void raptor_avltree_check(raptor_avltree* tree);
1321 #endif
1322 
1323 int raptor_avltree_cursor_first(raptor_avltree* tree);
1324 int raptor_avltree_cursor_last(raptor_avltree* tree);
1325 int raptor_avltree_cursor_prev(raptor_avltree* tree);
1326 int raptor_avltree_cursor_next(raptor_avltree* tree);
1327 void* raptor_avltree_cursor_get(raptor_avltree* tree);
1328 
1329 raptor_avltree_iterator* raptor_new_avltree_iterator(raptor_avltree* tree, void* range,  raptor_data_free_function range_free_fn, int direction);
1330 void raptor_free_avltree_iterator(raptor_avltree_iterator* iterator);
1331 
1332 int raptor_avltree_iterator_end(raptor_avltree_iterator* iterator);
1333 int raptor_avltree_iterator_next(raptor_avltree_iterator* iterator);
1334 void* raptor_avltree_iterator_get(raptor_avltree_iterator* iterator);
1335 
1336 /* raptor_world structure */
1337 struct raptor_world_s {
1338   /* world has been initialized with raptor_world_open() */
1339   int opened;
1340 
1341   /* raptor_init(), raptor_finish() balance */
1342   int static_usage;
1343 
1344   /* sequence of parser factories */
1345   raptor_sequence *parsers;
1346 
1347   /* sequence of serializer factories */
1348   raptor_sequence *serializers;
1349 
1350   /* current uri handler and its data */
1351   const raptor_uri_handler *uri_handler;
1352   void *uri_handler_context;
1353 
1354   /* raptor_rss_common initialisation counter */
1355   int rss_common_initialised;
1356 
1357   /* raptor_rss_{namespaces,types,fields}_info const data initialized to raptor_uri,raptor_qname objects */
1358   raptor_uri **rss_namespaces_info_uris;
1359   raptor_uri **rss_types_info_uris;
1360   raptor_qname **rss_types_info_qnames;
1361   raptor_uri **rss_fields_info_uris;
1362   raptor_qname **rss_fields_info_qnames;
1363 
1364   /* raptor_www v2 flags */
1365   int www_skip_www_init_finish;
1366   int www_initialized;
1367 
1368   /* raptor_sax2 init counter to work around issues in xml parser init/cleanup */
1369   int sax2_initialized;
1370 
1371   /* This is used to store a #xsltSecurityPrefsPtr typed object
1372    * pointer when libxslt is compiled in.
1373    */
1374   void* xslt_security_preferences;
1375   /* If non-0 - raptors own the above object and should free it with
1376    * xsltFreeSecurityPrefs() on exit
1377    */
1378   int free_xslt_security_preferences;
1379 
1380   /* Flags for libxml set by raptor_world_set_libxml_flags() and
1381    * raptor_set_libxml_flags() - see #raptor_libxml_flags for
1382    * meanings
1383    */
1384   int libxml_flags;
1385 };
1386 
1387 /* raptor_world legacy accessor */
1388 #ifndef RAPTOR_DISABLE_V1
1389 raptor_world* raptor_world_instance(void);
1390 #endif
1391 
1392 /* end of RAPTOR_INTERNAL */
1393 #endif
1394 
1395 
1396 #ifdef __cplusplus
1397 }
1398 #endif
1399 
1400 #endif
1401