1 /* -*- Mode: c; c-basic-offset: 2 -*-
2  *
3  * rasqal_internal.h - Rasqal RDF Query library internals
4  *
5  * Copyright (C) 2003-2010, David Beckett http://www.dajobe.org/
6  * Copyright (C) 2003-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 #ifndef RASQAL_INTERNAL_H
27 #define RASQAL_INTERNAL_H
28 
29 #if defined(_MSC_VER) && _MSC_VER < 1600
30 typedef unsigned __int32 uint32_t;
31 typedef __int16 int16_t;
32 #else
33 #include <stdint.h>
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #define RASQAL_EXTERN_C extern "C"
39 #else
40 #define RASQAL_EXTERN_C
41 #endif
42 
43 #ifdef RASQAL_INTERNAL
44 
45 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
46 #define RASQAL_PRINTF_FORMAT(string_index, first_to_check_index) \
47   __attribute__((__format__(__printf__, string_index, first_to_check_index)))
48 #else
49 #define RASQAL_PRINTF_FORMAT(string_index, first_to_check_index)
50 #endif
51 
52 #ifdef __GNUC__
53 #define RASQAL_NORETURN __attribute__((noreturn))
54 #else
55 #define RASQAL_NORETURN
56 #endif
57 
58 /* Can be over-ridden or undefined in a config.h file or -Ddefine */
59 #ifndef RASQAL_INLINE
60 #define RASQAL_INLINE inline
61 #endif
62 
63 #ifdef LIBRDF_DEBUG
64 #define RASQAL_DEBUG 1
65 #endif
66 
67 #if defined(RASQAL_MEMORY_SIGN)
68 #define RASQAL_SIGN_KEY 0x08A59A10
69 void* rasqal_sign_malloc(size_t size);
70 void* rasqal_sign_calloc(size_t nmemb, size_t size);
71 void* rasqal_sign_realloc(void *ptr, size_t size);
72 void rasqal_sign_free(void *ptr);
73 
74 #define RASQAL_MALLOC(type, size)   (type)rasqal_sign_malloc(size)
75 #define RASQAL_CALLOC(type, nmemb, size) (type)rasqal_sign_calloc(nmemb, size)
76 #define RASQAL_REALLOC(type, ptr, size) (type0rasqal_sign_realloc(ptr, size)
77 #define RASQAL_FREE(type, ptr)   rasqal_sign_free((void*)ptr)
78 
79 #else
80 #define RASQAL_MALLOC(type, size) (type)malloc(size)
81 #define RASQAL_CALLOC(type, size, count) (type)calloc(size, count)
82 #define RASQAL_FREE(type, ptr)   free((void*)ptr)
83 
84 #endif
85 
86 #ifdef HAVE___FUNCTION__
87 #else
88 #define __FUNCTION__ "???"
89 #endif
90 
91 #ifdef RASQAL_DEBUG
92 /* Debugging messages */
93 #define RASQAL_DEBUG1(msg) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__); } while(0)
94 #define RASQAL_DEBUG2(msg, arg1) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__, arg1);} while(0)
95 #define RASQAL_DEBUG3(msg, arg1, arg2) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__, arg1, arg2);} while(0)
96 #define RASQAL_DEBUG4(msg, arg1, arg2, arg3) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__, arg1, arg2, arg3);} while(0)
97 #define RASQAL_DEBUG5(msg, arg1, arg2, arg3, arg4) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__, arg1, arg2, arg3, arg4);} while(0)
98 #define RASQAL_DEBUG6(msg, arg1, arg2, arg3, arg4, arg5) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __FUNCTION__, arg1, arg2, arg3, arg4, arg5);} while(0)
99 
100 #if defined(HAVE_DMALLOC_H) && defined(RASQAL_MEMORY_DEBUG_DMALLOC)
101 void* rasqal_system_malloc(size_t size);
102 void rasqal_system_free(void *ptr);
103 #define SYSTEM_MALLOC(size)   rasqal_system_malloc(size)
104 #define SYSTEM_FREE(ptr)   rasqal_system_free(ptr)
105 #else
106 #define SYSTEM_MALLOC(size)   malloc(size)
107 #define SYSTEM_FREE(ptr)   free(ptr)
108 #endif
109 
110 #ifndef RASQAL_ASSERT_DIE
111 #define RASQAL_ASSERT_DIE abort();
112 #endif
113 
114 #else
115 /* DEBUGGING TURNED OFF */
116 
117 /* No debugging messages */
118 #define RASQAL_DEBUG1(msg)
119 #define RASQAL_DEBUG2(msg, arg1)
120 #define RASQAL_DEBUG3(msg, arg1, arg2)
121 #define RASQAL_DEBUG4(msg, arg1, arg2, arg3)
122 #define RASQAL_DEBUG5(msg, arg1, arg2, arg3, arg4)
123 #define RASQAL_DEBUG6(msg, arg1, arg2, arg3, arg4, arg5)
124 
125 #define SYSTEM_MALLOC(size)   malloc(size)
126 #define SYSTEM_FREE(ptr)   free(ptr)
127 
128 #ifndef RASQAL_ASSERT_DIE
129 #define RASQAL_ASSERT_DIE
130 #endif
131 
132 #endif
133 
134 
135 #ifdef RASQAL_DISABLE_ASSERT_MESSAGES
136 #define RASQAL_ASSERT_REPORT(line)
137 #else
138 #define RASQAL_ASSERT_REPORT(msg) fprintf(stderr, "%s:%d: (%s) assertion failed: " msg "\n", __FILE__, __LINE__, __FUNCTION__);
139 #endif
140 
141 
142 #ifdef RASQAL_DISABLE_ASSERT
143 
144 #define RASQAL_ASSERT(condition, msg)
145 #define RASQAL_ASSERT_RETURN(condition, msg, ret)
146 #define RASQAL_ASSERT_OBJECT_POINTER_RETURN(pointer, type) do { \
147   if(!pointer) \
148     return; \
149 } while(0)
150 #define RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret)
151 
152 #else
153 
154 #define RASQAL_ASSERT(condition, msg) do { \
155   if(condition) { \
156     RASQAL_ASSERT_REPORT(msg) \
157     RASQAL_ASSERT_DIE \
158   } \
159 } while(0)
160 
161 #define RASQAL_ASSERT_RETURN(condition, msg, ret) do { \
162   if(condition) { \
163     RASQAL_ASSERT_REPORT(msg) \
164     RASQAL_ASSERT_DIE \
165     return ret; \
166   } \
167 } while(0)
168 
169 #define RASQAL_ASSERT_OBJECT_POINTER_RETURN(pointer, type) do { \
170   if(!pointer) { \
171     RASQAL_ASSERT_REPORT("object pointer of type " #type " is NULL.") \
172     RASQAL_ASSERT_DIE \
173     return; \
174   } \
175 } while(0)
176 
177 #define RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret) do { \
178   if(!pointer) { \
179     RASQAL_ASSERT_REPORT("object pointer of type " #type " is NULL.") \
180     RASQAL_ASSERT_DIE \
181     return ret; \
182   } \
183 } while(0)
184 
185 #endif
186 
187 
188 /* Fatal errors - always happen */
189 #define RASQAL_FATAL1(msg) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __FUNCTION__); abort();} while(0)
190 #define RASQAL_FATAL2(msg,arg) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __FUNCTION__, arg); abort();} while(0)
191 #define RASQAL_FATAL3(msg,arg1,arg2) do {fprintf(stderr, "%s:%d:%s: fatal error: " msg, __FILE__, __LINE__ , __FUNCTION__, arg1, arg2); abort();} while(0)
192 
193 #ifndef NO_STATIC_DATA
194 #define RASQAL_DEPRECATED_MESSAGE(msg) do {static int warning_given=0; if(!warning_given++) fprintf(stderr, "Function %s is deprecated - " msg,  __FUNCTION__); } while(0)
195 #define RASQAL_DEPRECATED_WARNING(rq, msg) do {static int warning_given=0; if(!warning_given++) rasqal_query_warning(rq, msg); } while(0)
196 #else
197 #define RASQAL_DEPRECATED_MESSAGE(msg) do { fprintf(stderr, "Function %s is deprecated - " msg,  __FUNCTION__); } while(0)
198 #define RASQAL_DEPRECATED_WARNING(rq, msg) do { rasqal_query_warning(rq, msg); } while(0)
199 #endif
200 
201 
202 typedef struct rasqal_query_execution_factory_s rasqal_query_execution_factory;
203 typedef struct rasqal_query_language_factory_s rasqal_query_language_factory;
204 
205 
206 /**
207  * rasqal_projection:
208  * @query: rasqal query
209  * @wildcard: non-0 if @variables was '*'
210  * @distinct: 1 if distinct, 2 if reduced, otherwise neither
211  *
212  * Query projection (SELECT vars, SELECT *, SELECT DISTINCT/REDUCED ...)
213  *
214  */
215 typedef struct {
216   rasqal_query* query;
217 
218   raptor_sequence* variables;
219 
220   unsigned int wildcard:1;
221 
222   int distinct;
223 } rasqal_projection;
224 
225 
226 /**
227  * rasqal_solution_modifier:
228  * @query: rasqal query
229  * @order_conditions: sequence of order condition expressions (or NULL)
230  * @group_conditions: sequence of group by condition expressions (or NULL)
231  * @having_conditions: sequence of (group by ...) having condition expressions (or NULL)
232  * @limit: result limit LIMIT (>=0) or <0 if not given
233  * @offset: result offset OFFSET (>=0) or <0 if not given
234  *
235  * Query solution modifiers
236  *
237  */
238 typedef struct {
239   rasqal_query* query;
240 
241   raptor_sequence* order_conditions;
242 
243   raptor_sequence* group_conditions;
244 
245   raptor_sequence* having_conditions;
246 
247   int limit;
248 
249   int offset;
250 } rasqal_solution_modifier;
251 
252 
253 /**
254  * rasqal_bindings:
255  * @query: rasqal query
256  * @variables: sequence of variables
257  * @rows: sequence of #rasqal_row (or NULL)
258  *
259  * Result bindings from SPARQL 1.1 BINDINGS block
260  *
261  */
262 typedef struct {
263   /* usage/reference count */
264   int usage;
265 
266   rasqal_query* query;
267 
268   raptor_sequence* variables;
269 
270   raptor_sequence* rows;
271 } rasqal_bindings;
272 
273 
274 /*
275  * Graph Pattern
276  */
277 struct rasqal_graph_pattern_s {
278   rasqal_query* query;
279 
280   /* operator for this graph pattern's contents */
281   rasqal_graph_pattern_operator op;
282 
283   raptor_sequence* triples;          /* ... rasqal_triple*         */
284   raptor_sequence* graph_patterns;   /* ... rasqal_graph_pattern*  */
285 
286   int start_column;
287   int end_column;
288 
289   /* the FILTER / LET expression */
290   rasqal_expression* filter_expression;
291 
292   /* index of the graph pattern in the query (0.. query->graph_pattern_count-1) */
293   int gp_index;
294 
295   /* Graph literal / SERVICE literal */
296   rasqal_literal *origin;
297 
298   /* Variable for LET graph pattern */
299   rasqal_variable *var;
300 
301   /* SELECT projection */
302   rasqal_projection* projection;
303 
304   /* SELECT modifiers */
305   rasqal_solution_modifier* modifier;
306 
307   /* SILENT flag for SERVICE graph pattern */
308   unsigned int silent : 1;
309 
310   /* SELECT graph pattern: sequence of #rasqal_data_graph */
311   raptor_sequence* data_graphs;
312 
313   /* VALUES bindings for VALUES and sub-SELECT graph patterns */
314   rasqal_bindings* bindings;
315 };
316 
317 rasqal_graph_pattern* rasqal_new_basic_graph_pattern(rasqal_query* query, raptor_sequence* triples, int start_column, int end_column);
318 rasqal_graph_pattern* rasqal_new_graph_pattern_from_sequence(rasqal_query* query, raptor_sequence* graph_patterns, rasqal_graph_pattern_operator op);
319 rasqal_graph_pattern* rasqal_new_filter_graph_pattern(rasqal_query* query, rasqal_expression* expr);
320 rasqal_graph_pattern* rasqal_new_let_graph_pattern(rasqal_query *query, rasqal_variable *var, rasqal_expression *expr);
321 rasqal_graph_pattern* rasqal_new_select_graph_pattern(rasqal_query *query, rasqal_projection* projection, raptor_sequence* data_graphs, rasqal_graph_pattern* where, rasqal_solution_modifier* modifier, rasqal_bindings* bindings);
322 rasqal_graph_pattern* rasqal_new_single_graph_pattern(rasqal_query* query, rasqal_graph_pattern_operator op, rasqal_graph_pattern* single);
323 rasqal_graph_pattern* rasqal_new_values_graph_pattern(rasqal_query* query, rasqal_bindings* bindings);
324 void rasqal_free_graph_pattern(rasqal_graph_pattern* gp);
325 void rasqal_graph_pattern_adjust(rasqal_graph_pattern* gp, int offset);
326 void rasqal_graph_pattern_set_origin(rasqal_graph_pattern* graph_pattern, rasqal_literal* origin);
327 
328 
329 /**
330  * rasqal_var_use_map_flags:
331  * @RASQAL_VAR_USE_IN_SCOPE: variable is in-scope in this GP
332  * @RASQAL_VAR_USE_MENTIONED_HERE: variable is mentioned/used in this GP
333  * @RASQAL_VAR_USE_BOUND_HERE: variable is bound in this GP
334  */
335 typedef enum {
336   RASQAL_VAR_USE_IN_SCOPE       = 1 << 0,
337   RASQAL_VAR_USE_MENTIONED_HERE = 1 << 1,
338   RASQAL_VAR_USE_BOUND_HERE     = 1 << 2
339 } rasqal_var_use_map_flags;
340 
341 
342 /**
343  * rasqal_var_use_map_offset:
344  * @RASQAL_VAR_USE_MAP_OFFSET_VERBS: Variables in query verbs: ASK: never, SELECT: project-expressions (SPARQL 1.1), CONSTRUCT: in constructed triple patterns, DESCRIBE: in argument (SPARQL 1.0)
345  * @RASQAL_VAR_USE_MAP_OFFSET_GROUP_BY: Variables in GROUP BY expr/var (SPARQL 1.1)
346  * @RASQAL_VAR_USE_MAP_OFFSET_HAVING: Variables in HAVING expr (SPARQL 1.1)
347  * @RASQAL_VAR_USE_MAP_OFFSET_ORDER_BY: Variables in ORDER BY list-of-expr (SPARQL 1.0)
348  * @RASQAL_VAR_USE_MAP_OFFSET_VALUES: Variables bound in VALUES (SPARQL 1.1)
349  * @RASQAL_VAR_USE_MAP_OFFSET_LAST: internal
350  *
351  * Offsets into variables use-map for non-graph pattern parts of #rasqal_query structure
352  */
353 typedef enum {
354   RASQAL_VAR_USE_MAP_OFFSET_VERBS    = 0,
355   RASQAL_VAR_USE_MAP_OFFSET_GROUP_BY = 1,
356   RASQAL_VAR_USE_MAP_OFFSET_HAVING   = 2,
357   RASQAL_VAR_USE_MAP_OFFSET_ORDER_BY = 3,
358   RASQAL_VAR_USE_MAP_OFFSET_VALUES   = 4,
359   RASQAL_VAR_USE_MAP_OFFSET_LAST     = RASQAL_VAR_USE_MAP_OFFSET_VALUES
360 } rasqal_var_use_map_offset;
361 
362 
363 /**
364  * rasqal_triples_use_map_flags:
365  * @RASQAL_TRIPLES_USE_SUBJECT: variable used in subject of this triple
366  * @RASQAL_TRIPLES_USE_PREDICATE: ditto predicate
367  * @RASQAL_TRIPLES_USE_OBJECT: ditto object
368  * @RASQAL_TRIPLES_USE_GRAPH: ditto graph
369  * @RASQAL_TRIPLES_BOUND_SUBJECT: variable bound in subject of this triple
370  * @RASQAL_TRIPLES_BOUND_PREDICATE: ditto predicate
371  * @RASQAL_TRIPLES_BOUND_OBJECT: ditto object
372  * @RASQAL_TRIPLES_BOUND_GRAPH: ditto graph
373  * @RASQAL_TRIPLES_USE_MASK: mask to check if variable is used in any part of TP
374  * @RASQAL_TRIPLES_BOUND_MASK: mask to check if variable is bound in any part of TP (a single variable can be bound at most once in a triple pattern)
375  */
376 typedef enum {
377   RASQAL_TRIPLES_USE_SUBJECT     = RASQAL_TRIPLE_SUBJECT,
378   RASQAL_TRIPLES_USE_PREDICATE   = RASQAL_TRIPLE_PREDICATE,
379   RASQAL_TRIPLES_USE_OBJECT      = RASQAL_TRIPLE_OBJECT,
380   RASQAL_TRIPLES_USE_GRAPH       = RASQAL_TRIPLE_GRAPH,
381   RASQAL_TRIPLES_BOUND_SUBJECT   = RASQAL_TRIPLE_SUBJECT   << 4,
382   RASQAL_TRIPLES_BOUND_PREDICATE = RASQAL_TRIPLE_PREDICATE << 4,
383   RASQAL_TRIPLES_BOUND_OBJECT    = RASQAL_TRIPLE_OBJECT    << 4,
384   RASQAL_TRIPLES_BOUND_GRAPH     = RASQAL_TRIPLE_GRAPH     << 4,
385   RASQAL_TRIPLES_USE_MASK        = (RASQAL_TRIPLES_USE_SUBJECT | RASQAL_TRIPLES_USE_PREDICATE | RASQAL_TRIPLES_USE_OBJECT | RASQAL_TRIPLES_USE_GRAPH),
386   RASQAL_TRIPLES_BOUND_MASK      = (RASQAL_TRIPLES_BOUND_SUBJECT | RASQAL_TRIPLES_BOUND_PREDICATE | RASQAL_TRIPLES_BOUND_OBJECT | RASQAL_TRIPLES_BOUND_GRAPH)
387 } rasqal_triples_use_map_flags;
388 
389 
390 /*
391  * A query in some query language
392  */
393 struct rasqal_query_s {
394   rasqal_world* world; /* world object */
395 
396   int usage; /* reference count - 1 for itself, plus for query_results */
397 
398   unsigned char* query_string;
399   size_t query_string_length; /* length including NULs */
400 
401   raptor_namespace_stack* namespaces;
402 
403   /* query graph pattern, containing the sequence of graph_patterns below */
404   rasqal_graph_pattern* query_graph_pattern;
405 
406   /* the query verb - in SPARQL terms: SELECT, CONSTRUCT, DESCRIBE or ASK */
407   rasqal_query_verb verb;
408 
409   /* WAS: selects - sequence of rasqal_variable# */
410   raptor_sequence* unused10;     /* ... rasqal_variable* names only */
411 
412   /* sequences of ... */
413   raptor_sequence* data_graphs; /* ... rasqal_data_graph*          */
414   /* NOTE: Cannot assume that triples are in any of
415    * graph pattern use / query execution / document order
416    */
417   raptor_sequence* triples;     /* ... rasqal_triple*              */
418   raptor_sequence* prefixes;    /* ... rasqal_prefix*              */
419   raptor_sequence* constructs;  /* ... rasqal_triple*       SPARQL */
420   raptor_sequence* optional_triples; /* ... rasqal_triple*  SPARQL */
421   raptor_sequence* describes;   /* ... rasqal_literal* (var or URIs) SPARQL */
422 
423   /* WAS: distinct 0..2; now projection->distinct */
424   unsigned int unused9;
425 
426   /* WAS: result limit LIMIT (>=0) or <0 if not given */
427   int unused4;
428 
429   /* WAS: result offset OFFSET (>=0) or <0 if not given */
430   int unused5;
431 
432   /* WAS: wildcard flag; now projection->wildcard  */
433   int unused12;
434 
435   /* flag: non-0 if query has been prepared */
436   int prepared;
437 
438   rasqal_variables_table* vars_table;
439 
440   /* WAS: The number of selected variables: these are always the first
441    * in the variables table and are the ones returend to the user.
442    */
443   int unused11;
444 
445   /* INTERNAL 2D array of:
446    *   width (number of total variables)
447    *   height (number of triples)
448    * marking how a variable is mentioned/used in a TRIPLE PATTERN
449    * Each triple pattern has a row and the short values are per-variable
450    * with flags from #rasqal_triples_use_map_flags
451    */
452   unsigned short* triples_use_map;
453 
454   /* can be filled with error location information */
455   raptor_locator locator;
456 
457   /* base URI of this query for resolving relative URIs in queries */
458   raptor_uri* base_uri;
459 
460   /* non 0 if query had fatal error in parsing and cannot be executed */
461   int failed;
462 
463   /* stuff for our user */
464   void* user_data;
465 
466   /* former state for generating blank node IDs; now in world object */
467   int unused1;
468   char *unused2;
469   size_t unused3;
470 
471   /* query engine specific stuff */
472   void* context;
473 
474   struct rasqal_query_language_factory_s* factory;
475 
476   rasqal_triples_source_factory* triples_source_factory;
477 
478   /* sequence of query results made from this query */
479   raptor_sequence* results;
480 
481   /* incrementing counter for declaring prefixes in order of appearance */
482   int prefix_depth;
483 
484   /* WAS: sequence of order condition expressions */
485   void* unused6;
486 
487   /* WAS: sequence of group by condition expressions */
488   void* unused7;
489 
490   /* INTERNAL rasqal_literal_compare / rasqal_expression_evaluate flags */
491   int compare_flags;
492 
493   /* Number of graph patterns in this query */
494   int graph_pattern_count;
495 
496   /* Graph pattern shared pointers by gp index (after prepare) */
497   raptor_sequence* graph_patterns_sequence;
498 
499   /* Features */
500   int features[RASQAL_FEATURE_LAST+1];
501 
502   /* Name of requested query results syntax.  If present, this
503    * is the name used for constructing a rasqal_query_formatter
504    * from the results.
505    */
506   char* query_results_formatter_name;
507 
508   /* flag: non-0 if EXPLAIN was given */
509   int explain;
510 
511   /* INTERNAL lexer internal data */
512   void* lexer_user_data;
513 
514   /* INTERNAL flag for now: non-0 to store results otherwise lazy eval results */
515   int store_results;
516 
517   /* INTERNAL 2D array of:
518    *   width (number of total variables)
519    *   height (number of graph patterns)
520    * marking how a variable is mentioned/used in a GP
521    * Each graph pattern has a row and the short values are per-variable
522    * with flags:
523    *   1  RASQAL_USE_IN_SCOPE
524    *   2  RASQAL_USE_MENTIONED_HERE
525    *   4  RASQAL_USE_BOUND_HERE
526    */
527   unsigned short* variables_use_map;
528 
529   /* sequence of #rasqal_update_operation when @verb is
530    * INSERT (deprecated), DELETE (deprecated) or UPDATE
531    */
532   raptor_sequence* updates;
533 
534   /* WAS: sequence of (group by ...) having condition expressions */
535   raptor_sequence* unused8;
536 
537   /* INTERNAL solution modifier */
538   rasqal_solution_modifier* modifier;
539 
540   /* INTERNAL SELECT bindings */
541   rasqal_bindings* bindings;
542 
543   /* INTERNAL static structure for expresion evaluation*/
544   rasqal_evaluation_context *eval_context;
545 
546   /* INTERNAL flag: non-0 if user set a random seed via RASQAL_FEATURE_RAND_SEED */
547   unsigned int user_set_rand : 1;
548 
549   /* Variable projection (or NULL when invalid such as for ASK) */
550   rasqal_projection* projection;
551 };
552 
553 
554 /*
555  * A query language factory for a query language.
556  *
557  * This structure is about turning a query syntax string into a
558  * #rasqal_query structure.  It does not deal with execution of the
559  * query in any manner.
560  */
561 struct rasqal_query_language_factory_s {
562   rasqal_world* world;
563 
564   struct rasqal_query_language_factory_s* next;
565 
566   /* static description that the query language registration initialises */
567   raptor_syntax_description desc;
568 
569   /* the rest of this structure is populated by the
570      query-language-specific register function */
571   size_t context_length;
572 
573   /* create a new query */
574   int (*init)(rasqal_query* rq, const char *name);
575 
576   /* destroy a query */
577   void (*terminate)(rasqal_query* rq);
578 
579   /* prepare a query */
580   int (*prepare)(rasqal_query* rq);
581 
582   /* finish the query language factory */
583   void (*finish_factory)(rasqal_query_language_factory* factory);
584 
585   /* Write a string to an iostream in escaped form suitable for the query */
586   int (*iostream_write_escaped_counted_string)(rasqal_query* rq, raptor_iostream* iostr, const unsigned char* string, size_t len);
587 };
588 
589 
590 typedef struct rasqal_rowsource_s rasqal_rowsource;
591 
592 #define RASQAL_ROW_FLAG_WEAK_ROWSOURCE 0x01
593 
594 /*
595  * A row of values from a query result, usually generated by a rowsource
596  */
597 struct rasqal_row_s {
598   /* reference count */
599   int usage;
600 
601   /* Rowsource this row is associated with (or NULL if none) */
602   rasqal_rowsource* rowsource;
603 
604   /* current row number in the sequence of rows*/
605   int offset;
606 
607   /* values for each variable in the query sequence of values */
608   int size;
609   rasqal_literal** values;
610 
611   /* literal values for ORDER BY expressions evaluated for this row */
612   /* number of expressions (can be 0) */
613   int order_size;
614   rasqal_literal** order_values;
615 
616   /* Group ID */
617   int group_id;
618 
619   /* Bit mask of flags: bit 0 = WEAK ROWSOURCE */
620   unsigned int flags;
621 };
622 
623 
624 typedef struct rasqal_map_s rasqal_map;
625 
626 /**
627  * rasqal_join_type:
628  * @RASQAL_JOIN_TYPE_UNKNOWN: unknown join type
629  * @RASQAL_JOIN_TYPE_NATURAL: natural join.  returns compatible rows and no NULLs
630  * @RASQAL_JOIN_TYPE_LEFT: left join.  returns compatible rows plus rows from left rowsource that are not compatible or fail filter condition
631  *
632  * Rowsource join type.
633  */
634 typedef enum {
635   RASQAL_JOIN_TYPE_UNKNOWN,
636   RASQAL_JOIN_TYPE_NATURAL,
637   RASQAL_JOIN_TYPE_LEFT
638 } rasqal_join_type;
639 
640 
641 
642 /* rasqal_rowsource_aggregation.c */
643 rasqal_rowsource* rasqal_new_aggregation_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* rowsource, raptor_sequence* exprs_seq, raptor_sequence* vars_seq);
644 
645 /* rasqal_rowsource_empty.c */
646 rasqal_rowsource* rasqal_new_empty_rowsource(rasqal_world *world, rasqal_query* query);
647 
648 /* rasqal_rowsource_engine.c */
649 rasqal_rowsource* rasqal_new_execution_rowsource(rasqal_query_results* query_results);
650 
651 /* rasqal_rowsource_assignment.c */
652 rasqal_rowsource* rasqal_new_assignment_rowsource(rasqal_world *world, rasqal_query *query, rasqal_variable* var, rasqal_expression* expr);
653 
654 /* rasqal_rowsource_bindings.c */
655 rasqal_rowsource* rasqal_new_bindings_rowsource(rasqal_world *world, rasqal_query *query, rasqal_bindings* bindings);
656 
657 /* rasqal_rowsource_distinct.c */
658 rasqal_rowsource* rasqal_new_distinct_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rs);
659 
660 /* rasqal_rowsource_filter.c */
661 rasqal_rowsource* rasqal_new_filter_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rs, rasqal_expression* expr);
662 
663 /* rasqal_rowsource_graph.c */
664 rasqal_rowsource* rasqal_new_graph_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource, rasqal_variable *var);
665 
666 /* rasqal_rowsource_groupby.c */
667 rasqal_rowsource* rasqal_new_groupby_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* rowsource, raptor_sequence* exprs_seq);
668 
669 /* rasqal_rowsource_having.c */
670 rasqal_rowsource* rasqal_new_having_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource, raptor_sequence* exprs_seq);
671 
672 /* rasqal_rowsource_join.c */
673 rasqal_rowsource* rasqal_new_join_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* left, rasqal_rowsource* right, rasqal_join_type join_type, rasqal_expression *expr);
674 
675 /* rasqal_rowsource_project.c */
676 rasqal_rowsource* rasqal_new_project_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource, raptor_sequence* projection_variables);
677 
678 /* rasqal_rowsource_rowsequence.c */
679 rasqal_rowsource* rasqal_new_rowsequence_rowsource(rasqal_world *world, rasqal_query* query, rasqal_variables_table* vt, raptor_sequence* rows_seq, raptor_sequence* vars_seq);
680 
681 /* rasqal_rowsource_slice.c */
682 rasqal_rowsource* rasqal_new_slice_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource, int limit, int offset);
683 
684 /* rasqal_rowsource_service.c */
685 rasqal_rowsource* rasqal_new_service_rowsource(rasqal_world *world, rasqal_query* query, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, unsigned int rs_flags);
686 
687 /* rasqal_rowsource_sort.c */
688 rasqal_rowsource* rasqal_new_sort_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource *rowsource, raptor_sequence* order_seq, int distinct);
689 
690 /* rasqal_rowsource_triples.c */
691 rasqal_rowsource* rasqal_new_triples_rowsource(rasqal_world *world, rasqal_query* query, rasqal_triples_source* triples_source, raptor_sequence* triples, int start_column, int end_column);
692 
693 /* rasqal_rowsource_union.c */
694 rasqal_rowsource* rasqal_new_union_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* left, rasqal_rowsource* right);
695 
696 
697 /**
698  * rasqal_rowsource_init_func:
699  * @context: stream context data
700  *
701  * Handler function for #rasqal_rowsource initialising.
702  *
703  * Return value: non-0 on failure.
704  */
705 typedef int (*rasqal_rowsource_init_func) (rasqal_rowsource* rowsource, void *user_data);
706 
707 /**
708  * rasqal_rowsource_finish_func:
709  * @user_data: user data
710  *
711  * Handler function for #rasqal_rowsource terminating.
712  *
713  * Return value: non-0 on failure
714  */
715 typedef int (*rasqal_rowsource_finish_func) (rasqal_rowsource* rowsource, void *user_data);
716 
717 /**
718  * rasqal_rowsource_ensure_variables_func
719  * @rowsource: #rasqal_rowsource
720  * @user_data: user data
721  *
722  * Handler function for ensuring rowsource variables fields are initialised
723  *
724  * Return value: non-0 on failure
725  */
726 typedef int (*rasqal_rowsource_ensure_variables_func) (rasqal_rowsource* rowsource, void *user_data);
727 
728 /**
729  * rasqal_rowsource_read_row_func
730  * @user_data: user data
731  *
732  * Handler function for returning the next result row
733  *
734  * Return value: a query result row or NULL if exhausted
735  */
736 typedef rasqal_row* (*rasqal_rowsource_read_row_func) (rasqal_rowsource* rowsource, void *user_data);
737 
738 
739 /**
740  * rasqal_rowsource_read_all_rows_func
741  * @user_data: user data
742  *
743  * Handler function for returning all rows as a sequence
744  *
745  * Return value: a sequence of result rows (which may be size 0) or NULL if exhausted
746  */
747 typedef raptor_sequence* (*rasqal_rowsource_read_all_rows_func) (rasqal_rowsource* rowsource, void *user_data);
748 
749 
750 /**
751  * rasqal_rowsource_reset_func
752  * @user_data: user data
753  *
754  * Handler function for resetting a rowsource to generate the same set of rows
755  *
756  * Return value: non-0 on failure
757  */
758 typedef int (*rasqal_rowsource_reset_func) (rasqal_rowsource* rowsource, void *user_data);
759 
760 
761 /* bit flags */
762 #define RASQAL_ROWSOURCE_REQUIRE_RESET (1 << 0)
763 
764 /**
765  * rasqal_rowsource_set_requirements_func
766  * @user_data: user data
767  * @flags: bit flags
768  *
769  * Handler function for one rowsource setting requirements on inner rowsources
770  *
771  * Return value: non-0 on failure
772  */
773 typedef int (*rasqal_rowsource_set_requirements_func) (rasqal_rowsource* rowsource, void *user_data, unsigned int flags);
774 
775 
776 /**
777  * rasqal_rowsource_get_inner_rowsource_func
778  * @user_data: user data
779  * @offset: offset
780  *
781  * Handler function for getting an inner rowsource at an offset
782  *
783  * Return value: rowsource object or NULL if offset out of range
784  */
785 typedef rasqal_rowsource* (*rasqal_rowsource_get_inner_rowsource_func) (rasqal_rowsource* rowsource, void *user_data, int offset);
786 
787 
788 /**
789  * rasqal_rowsource_set_origin_func
790  * @user_data: user data
791  * @origin: Graph URI literal
792  *
793  * Handler function for setting the rowsource origin (GRAPH)
794  *
795  * Return value: non-0 on failure
796  */
797 typedef int (*rasqal_rowsource_set_origin_func) (rasqal_rowsource* rowsource, void *user_data, rasqal_literal *origin);
798 
799 
800 /**
801  * rasqal_rowsource_handler:
802  * @version: API version - 1
803  * @name: rowsource name for debugging
804  * @init:  initialisation handler - optional, called at most once (V1)
805  * @finish: finishing handler - optional, called at most once (V1)
806  * @ensure_variables: update variables handler- optional, called at most once (V1)
807  * @read_row: read row handler - this or @read_all_rows required (V1)
808  * @read_all_rows: read all rows handler - this or @read_row required (V1)
809  * @reset: reset rowsource to starting state handler - optional (V1)
810  * @set_requirements: set requirements flag handler - optional (V1)
811  * @get_inner_rowsource: get inner rowsource handler - optional if has no inner rowsources (V1)
812  * @set_origin: set origin (GRAPH) handler - optional (V1)
813  *
814  * Row Source implementation factory handler structure.
815  *
816  */
817 typedef struct {
818   int version;
819   const char* name;
820   /* API V1 methods */
821   rasqal_rowsource_init_func                 init;
822   rasqal_rowsource_finish_func               finish;
823   rasqal_rowsource_ensure_variables_func     ensure_variables;
824   rasqal_rowsource_read_row_func             read_row;
825   rasqal_rowsource_read_all_rows_func        read_all_rows;
826   rasqal_rowsource_reset_func                reset;
827   rasqal_rowsource_set_requirements_func     set_requirements;
828   rasqal_rowsource_get_inner_rowsource_func  get_inner_rowsource;
829   rasqal_rowsource_set_origin_func           set_origin;
830 } rasqal_rowsource_handler;
831 
832 
833 /**
834  * rasqal_row_compatible:
835  * @variables_table: variables table
836  * @rowsource1: first rowsource
837  * @rowsource2: second rowsource
838  * @variables_count: number of variables in the map
839  * @variables_in_both_rows_count: number of shared variables
840  * @defined_in_map: of size @variables_count
841  *
842  * Lookup data constructed for two rowsources to enable quick
843  * checking if rows from the two rowsource are compatible with
844  * rasqal_row_compatible_check()
845  *
846  */
847 typedef struct {
848   rasqal_variables_table* variables_table;
849   rasqal_rowsource *first_rowsource;
850   rasqal_rowsource *second_rowsource;
851   int variables_count;
852   int variables_in_both_rows_count;
853   int* defined_in_map;
854 } rasqal_row_compatible;
855 
856 
857 typedef struct rasqal_results_compare_s rasqal_results_compare;
858 
859 
860 /*
861  * Rowsource Internal flags
862  *
863  * RASQAL_ROWSOURCE_FLAGS_SAVE_ROWS: need to save all rows in
864  * @rows_sequence for reset operation
865  *
866  * RASQAL_ROWSOURCE_FLAGS_SAVED_ROWS: have saved rows ready for reply
867  */
868 #define RASQAL_ROWSOURCE_FLAGS_SAVE_ROWS  0x01
869 #define RASQAL_ROWSOURCE_FLAGS_SAVED_ROWS 0x02
870 
871 /**
872  * rasqal_rowsource:
873  * @world: rasqal world
874  * @query: query that this may be associated with (or NULL)
875  * @flags: flags - none currently defined.
876  * @user_data: rowsource handler data
877  * @handler: rowsource handler pointer
878  * @finished: non-0 if rowsource has been exhausted
879  * @count:  number of rows returned
880  * @updated_variables: non-0 if ensure_variables factory method has been called to get the variables_sequence updated
881  * @vars_table: variables table where variables used in this row are declared/owned
882  * @variables_sequence: variables declared in this row from @vars_table
883  * @size: number of variables in @variables_sequence
884  * @rows_sequence: stored sequence of rows for use by rasqal_rowsource_read_row() (or NULL)
885  * @offset: size of @rows_sequence
886  * @generate_group: non-0 to generate a group (ID 0) around all the returned rows, if there is no grouping returned.
887  * @usage: reference count
888  *
889  * Rasqal Row Source class providing a sequence of rows of values similar to a SQL table.
890  *
891  * The table has @size columns which are #rasqal_variable names that
892  * are declared in the associated variables table.
893  * @variables_sequence contains the ordered projection of the
894  * variables for the columns for this row sequence, from the full set
895  * of variables in @vars_table.
896  *
897  * Each row has @size #rasqal_literal values for the variables or
898  * NULL if unset.
899  *
900  * Row sources are constructed indirectly via an @handler passed
901  * to the rasqal_new_rowsource_from_handler() constructor.
902  *
903  * The main methods are rasqal_rowsource_read_row() to read one row
904  * and rasqal_rowsource_read_all_rows() to get all rows as a
905  * sequence, draining the row source.
906  * rasqal_rowsource_get_rows_count() returns the current number of
907  * rows that have been read which is only useful in the read one row
908  * case.
909  *
910  * The variables associated with a rowsource can be read by
911  * rasqal_rowsource_get_variable_by_offset() and
912  * rasqal_rowsource_get_variable_offset_by_name() which all are
913  * offsets into @variables_sequence but refer to variables owned by
914  * the full internal variables table @vars_table
915  *
916  * The @rows_sequence and @offset variables are used by the
917  * rasqal_rowsource_read_row() function when operating over a handler
918  * that will only return a full sequence: handler->read_all_rows is NULL.
919  */
920 struct rasqal_rowsource_s
921 {
922   rasqal_world* world;
923 
924   rasqal_query* query;
925 
926   int flags;
927 
928   void *user_data;
929 
930   const rasqal_rowsource_handler* handler;
931 
932   unsigned int finished : 1;
933 
934   int count;
935 
936   int updated_variables;
937 
938   rasqal_variables_table* vars_table;
939 
940   raptor_sequence* variables_sequence;
941 
942   int size;
943 
944   raptor_sequence* rows_sequence;
945 
946   int offset;
947 
948   unsigned int generate_group : 1;
949 
950   int usage;
951 };
952 
953 
954 /* rasqal_rowsource.c */
955 rasqal_rowsource* rasqal_new_rowsource_from_handler(rasqal_world *world, rasqal_query* query, void* user_data, const rasqal_rowsource_handler *handler, rasqal_variables_table* vars_table, int flags);
956 rasqal_rowsource* rasqal_new_rowsource_from_rowsource(rasqal_rowsource* rowsource);
957 void rasqal_free_rowsource(rasqal_rowsource *rowsource);
958 
959 rasqal_row* rasqal_rowsource_read_row(rasqal_rowsource *rowsource);
960 int rasqal_rowsource_get_rows_count(rasqal_rowsource *rowsource);
961 raptor_sequence* rasqal_rowsource_read_all_rows(rasqal_rowsource *rowsource);
962 int rasqal_rowsource_get_size(rasqal_rowsource *rowsource);
963 int rasqal_rowsource_add_variable(rasqal_rowsource *rowsource, rasqal_variable* v);
964 rasqal_variable* rasqal_rowsource_get_variable_by_offset(rasqal_rowsource *rowsource, int offset);
965 int rasqal_rowsource_get_variable_offset_by_name(rasqal_rowsource *rowsource, const unsigned char* name);
966 int rasqal_rowsource_copy_variables(rasqal_rowsource *dest_rowsource, rasqal_rowsource *src_rowsource);
967 void rasqal_rowsource_print_row_sequence(rasqal_rowsource* rowsource,raptor_sequence* seq, FILE* fh);
968 int rasqal_rowsource_reset(rasqal_rowsource* rowsource);
969 int rasqal_rowsource_set_requirements(rasqal_rowsource* rowsource, unsigned int requirement);
970 rasqal_rowsource* rasqal_rowsource_get_inner_rowsource(rasqal_rowsource* rowsource, int offset);
971 int rasqal_rowsource_write(rasqal_rowsource *rowsource,  raptor_iostream *iostr);
972 void rasqal_rowsource_print(rasqal_rowsource* rs, FILE* fh);
973 int rasqal_rowsource_ensure_variables(rasqal_rowsource *rowsource);
974 int rasqal_rowsource_set_origin(rasqal_rowsource* rowsource, rasqal_literal *literal);
975 int rasqal_rowsource_request_grouping(rasqal_rowsource* rowsource);
976 void rasqal_rowsource_remove_all_variables(rasqal_rowsource *rowsource);
977 
978 typedef struct rasqal_query_results_format_factory_s rasqal_query_results_format_factory;
979 
980 typedef int (*rasqal_query_results_init_func)(rasqal_query_results_formatter* formatter, const char* name);
981 
982 typedef void (*rasqal_query_results_finish_func)(rasqal_query_results_formatter* formatter);
983 
984 typedef int (*rasqal_query_results_write_func)(rasqal_query_results_formatter* formatter, raptor_iostream *iostr, rasqal_query_results* results, raptor_uri *base_uri);
985 
986 typedef rasqal_rowsource* (*rasqal_query_results_get_rowsource_func)(rasqal_query_results_formatter* formatter, rasqal_world* world, rasqal_variables_table* vars_table, raptor_iostream *iostr, raptor_uri *base_uri, unsigned int flags);
987 
988 typedef int (*rasqal_query_results_recognise_syntax_func)(struct rasqal_query_results_format_factory_s* factory, const unsigned char *buffer, size_t len, const unsigned char *identifier, const unsigned char *suffix, const char *mime_type);
989 
990 typedef int (*rasqal_query_results_get_boolean_func)(rasqal_query_results_formatter *formatter, rasqal_world* world, raptor_iostream *iostr, raptor_uri *base_uri, unsigned int flags);
991 
992 
993 typedef int (*rasqal_rowsource_visit_fn)(rasqal_rowsource* rowsource, void *user_data);
994 
995 int rasqal_rowsource_visit(rasqal_rowsource* rowsource, rasqal_rowsource_visit_fn fn, void *user_data);
996 
997 
998 struct rasqal_query_results_format_factory_s {
999   rasqal_world* world;
1000 
1001   struct rasqal_query_results_format_factory_s* next;
1002 
1003   /* static desc that the parser registration initialises */
1004   raptor_syntax_description desc;
1005 
1006   /* Memory to allocate for per-formatter data */
1007   int context_length;
1008 
1009   /* format initialisation (OPTIONAL) */
1010   rasqal_query_results_init_func init;
1011 
1012   /* format initialisation (OPTIONAL) */
1013   rasqal_query_results_finish_func finish;
1014 
1015   /* format writer: READ from results, WRITE syntax (using base URI) to iostr */
1016   rasqal_query_results_write_func write;
1017 
1018   /* format get rowsource: get a rowsource that will return a sequence of rows from an iostream */
1019   rasqal_query_results_get_rowsource_func get_rowsource;
1020 
1021   /* recognize a format (OPTIONAL) */
1022   rasqal_query_results_recognise_syntax_func recognise_syntax;
1023 
1024   /* get a boolean result (OPTIONAL) */
1025   rasqal_query_results_get_boolean_func get_boolean;
1026 };
1027 
1028 
1029 /*
1030  * A query results formatter for some query_results
1031  */
1032 struct rasqal_query_results_formatter_s {
1033   rasqal_query_results_format_factory* factory;
1034 
1035   /* Per-formatter data */
1036   void* context;
1037 };
1038 
1039 /* rasqal_results_formats.c */
1040 rasqal_rowsource* rasqal_query_results_formatter_get_read_rowsource(rasqal_world *world, raptor_iostream *iostr, rasqal_query_results_formatter* formatter, rasqal_variables_table* vars_table, raptor_uri *base_uri, unsigned int flags);
1041 
1042 
1043 typedef struct {
1044   rasqal_world *world;
1045   raptor_sequence *triples;
1046   rasqal_literal *value;
1047 } rasqal_formula;
1048 
1049 
1050 /* rasqal_datetime.c */
1051 int rasqal_xsd_datetime_check(const char* string);
1052 int rasqal_xsd_date_check(const char* string);
1053 
1054 
1055 /* rasqal_dataset.c */
1056 typedef struct rasqal_dataset_s rasqal_dataset;
1057 typedef struct rasqal_dataset_term_iterator_s rasqal_dataset_term_iterator;
1058 typedef struct rasqal_dataset_triples_iterator_s rasqal_dataset_triples_iterator;
1059 
1060 rasqal_dataset* rasqal_new_dataset(rasqal_world* world);
1061 void rasqal_free_dataset(rasqal_dataset* ds);
1062 int rasqal_dataset_load_graph_iostream(rasqal_dataset* ds, const char* name, raptor_iostream* iostr, raptor_uri* base_uri);
1063 int rasqal_dataset_load_graph_uri(rasqal_dataset* ds, const char* name, raptor_uri* uri, raptor_uri* base_uri);
1064 void rasqal_free_dataset_term_iterator(rasqal_dataset_term_iterator* iter);
1065 rasqal_literal* rasqal_dataset_term_iterator_get(rasqal_dataset_term_iterator* iter);
1066 int rasqal_dataset_term_iterator_next(rasqal_dataset_term_iterator* iter);
1067 rasqal_dataset_term_iterator* rasqal_dataset_get_sources_iterator(rasqal_dataset* ds, rasqal_literal* predicate, rasqal_literal* object);
1068 rasqal_dataset_term_iterator* rasqal_dataset_get_targets_iterator(rasqal_dataset* ds, rasqal_literal* subject, rasqal_literal* predicate);
1069 rasqal_literal* rasqal_dataset_get_source(rasqal_dataset* ds, rasqal_literal* predicate, rasqal_literal* object);
1070 rasqal_literal* rasqal_dataset_get_target(rasqal_dataset* ds, rasqal_literal* subject, rasqal_literal* predicate);
1071 rasqal_dataset_triples_iterator* rasqal_dataset_get_triples_iterator(rasqal_dataset* ds);
1072 void rasqal_free_dataset_triples_iterator(rasqal_dataset_triples_iterator* ti);
1073 rasqal_triple* rasqal_dataset_triples_iterator_get(rasqal_dataset_triples_iterator* ti);
1074 int rasqal_dataset_triples_iterator_next(rasqal_dataset_triples_iterator* ti);
1075 int rasqal_dataset_print(rasqal_dataset* ds, FILE *fh);
1076 
1077 
1078 /* rasqal_general.c */
1079 char* rasqal_vsnprintf(const char* message, va_list arguments);
1080 unsigned char* rasqal_world_generate_bnodeid(rasqal_world* world, unsigned char *user_bnodeid);
1081 int rasqal_world_reset_now(rasqal_world* world);
1082 struct timeval* rasqal_world_get_now_timeval(rasqal_world* world);
1083 
1084 
1085 typedef enum {
1086   /* Warnings in 0..100 range.  Warn if LEVEL < world->warning_level */
1087   RASQAL_WARNING_LEVEL_MAYBE_ERROR  = 10,
1088   RASQAL_WARNING_LEVEL_STYLE        = 30,
1089   RASQAL_WARNING_LEVEL_STRICT_STYLE = 90,
1090 
1091   /* Default warning level */
1092   RASQAL_WARNING_LEVEL_DEFAULT      = 50,
1093   RASQAL_WARNING_LEVEL_MAX          = 100,
1094 
1095   /* Warnings level in code base */
1096   RASQAL_WARNING_LEVEL_DUPLICATE_VARIABLE = RASQAL_WARNING_LEVEL_STYLE,
1097   RASQAL_WARNING_LEVEL_VARIABLE_UNUSED    = RASQAL_WARNING_LEVEL_STYLE,
1098   RASQAL_WARNING_LEVEL_MULTIPLE_BG_GRAPHS = RASQAL_WARNING_LEVEL_STYLE,
1099   RASQAL_WARNING_LEVEL_QUERY_SYNTAX       = RASQAL_WARNING_LEVEL_STYLE,
1100 
1101   RASQAL_WARNING_LEVEL_NOT_IMPLEMENTED      = RASQAL_WARNING_LEVEL_MAYBE_ERROR,
1102   RASQAL_WARNING_LEVEL_MISSING_SUPPORT      = RASQAL_WARNING_LEVEL_MAYBE_ERROR,
1103   RASQAL_WARNING_LEVEL_BAD_TRIPLE           = RASQAL_WARNING_LEVEL_MAYBE_ERROR,
1104   RASQAL_WARNING_LEVEL_SELECTED_NEVER_BOUND = RASQAL_WARNING_LEVEL_MAYBE_ERROR,
1105 
1106   RASQAL_WARNING_LEVEL_UNUSED_SELECTED_VARIABLE = RASQAL_WARNING_LEVEL_STRICT_STYLE
1107 } rasqal_warning_level;
1108 
1109 
1110 rasqal_query_language_factory* rasqal_query_language_register_factory(rasqal_world *world, int (*factory) (rasqal_query_language_factory*));
1111 rasqal_query_language_factory* rasqal_get_query_language_factory (rasqal_world*, const char* name, const unsigned char* uri);
1112 void rasqal_log_error_simple(rasqal_world* world, raptor_log_level level, raptor_locator* locator, const char* message, ...) RASQAL_PRINTF_FORMAT(4, 5);
1113 void rasqal_log_error_varargs(rasqal_world* world, raptor_log_level level, raptor_locator* locator, const char* message, va_list arguments) RASQAL_PRINTF_FORMAT(4, 0);
1114 void rasqal_query_simple_error(void* user_data /* query */, const char *message, ...) RASQAL_PRINTF_FORMAT(2, 3);
1115 void rasqal_world_simple_error(void* user_data /* world */, const char *message, ...) RASQAL_PRINTF_FORMAT(2, 3);
1116 void rasqal_log_warning_simple(rasqal_world* world, rasqal_warning_level warn_level, raptor_locator* locator, const char* message, ...) RASQAL_PRINTF_FORMAT(4, 5);
1117 
1118 const char* rasqal_basename(const char* name);
1119 unsigned char* rasqal_world_default_generate_bnodeid_handler(void *user_data, unsigned char *user_bnodeid);
1120 
1121 extern const raptor_unichar rasqal_unicode_max_codepoint;
1122 
1123 unsigned char* rasqal_escaped_name_to_utf8_string(const unsigned char* src, size_t len, size_t* dest_lenp, int (*error_handler)(rasqal_query *error_data, const char *message, ...) RASQAL_PRINTF_FORMAT(2, 3), rasqal_query* error_data);
1124 
1125 /* rasqal_graph_pattern.c */
1126 unsigned char* rasqal_query_generate_bnodeid(rasqal_query* rdf_query, unsigned char *user_bnodeid);
1127 
1128 rasqal_graph_pattern* rasqal_new_basic_graph_pattern_from_formula(rasqal_query* query, rasqal_formula* formula);
1129 rasqal_graph_pattern* rasqal_new_basic_graph_pattern_from_triples(rasqal_query* query, raptor_sequence* triples);
1130 
1131 rasqal_graph_pattern* rasqal_new_2_group_graph_pattern(rasqal_query* query, rasqal_graph_pattern* first_gp, rasqal_graph_pattern* second_gp);
1132 
1133 rasqal_graph_pattern* rasqal_graph_pattern_get_parent(rasqal_query *query, rasqal_graph_pattern* gp, rasqal_graph_pattern* tree_gp);
1134 
1135 
1136 /* sparql_parser.y */
1137 typedef struct
1138 {
1139   raptor_uri* uri;
1140   rasqal_update_graph_applies applies;
1141 } sparql_uri_applies;
1142 
1143 typedef struct
1144 {
1145   rasqal_op op;
1146   rasqal_expression *expr;
1147 } sparql_op_expr;
1148 
1149 int rasqal_init_query_language_sparql(rasqal_world*);
1150 int rasqal_init_query_language_sparql11(rasqal_world*);
1151 int rasqal_init_query_language_laqrs(rasqal_world*);
1152 
1153 
1154 /* rasqal_query_transform.c */
1155 int rasqal_query_expand_triple_qnames(rasqal_query* rq);
1156 int rasqal_sequence_has_qname(raptor_sequence* seq);
1157 int rasqal_query_constraints_has_qname(rasqal_query* gp);
1158 int rasqal_query_expand_graph_pattern_constraints_qnames(rasqal_query* rq, rasqal_graph_pattern* gp);
1159 int rasqal_query_expand_query_constraints_qnames(rasqal_query* rq);
1160 int rasqal_query_build_anonymous_variables(rasqal_query* rq);
1161 int rasqal_query_expand_wildcards(rasqal_query* rq, rasqal_projection* projection);
1162 int rasqal_query_remove_duplicate_select_vars(rasqal_query* rq, rasqal_projection* projection);
1163 int rasqal_query_build_variables_use(rasqal_query* query, rasqal_projection* projection);
1164 int rasqal_query_prepare_common(rasqal_query *query);
1165 int rasqal_query_merge_graph_patterns(rasqal_query* query, rasqal_graph_pattern* gp, void* data);
1166 int rasqal_graph_patterns_join(rasqal_graph_pattern *dest_gp, rasqal_graph_pattern *src_gp);
1167 int rasqal_graph_pattern_move_constraints(rasqal_graph_pattern* dest_gp, rasqal_graph_pattern* src_gp);
1168 int rasqal_graph_pattern_variable_bound_below(rasqal_graph_pattern *gp, rasqal_variable *v);
1169 
1170 /* rasqal_double.c */
1171 int rasqal_double_approximately_compare(double a, double b);
1172 int rasqal_double_approximately_equal(double a, double b);
1173 
1174 /* rasqal_expr.c */
1175 rasqal_literal* rasqal_new_string_literal_node(rasqal_world*, const unsigned char *string, const char *language, raptor_uri *datatype);
1176 int rasqal_literal_as_boolean(rasqal_literal* literal, int* error_p);
1177 int rasqal_literal_as_integer(rasqal_literal* l, int* error_p);
1178 double rasqal_literal_as_double(rasqal_literal* l, int* error_p);
1179 raptor_uri* rasqal_literal_as_uri(rasqal_literal* l);
1180 int rasqal_literal_string_to_native(rasqal_literal *l, int flags);
1181 int rasqal_literal_has_qname(rasqal_literal* l);
1182 int rasqal_literal_expand_qname(void* user_data, rasqal_literal* l);
1183 int rasqal_literal_is_constant(rasqal_literal* l);
1184 int rasqal_expression_has_qname(void* user_data, rasqal_expression* e);
1185 int rasqal_expression_expand_qname(void* user_data, rasqal_expression* e);
1186 int rasqal_literal_ebv(rasqal_literal* l);
1187 int rasqal_expression_is_constant(rasqal_expression* e);
1188 void rasqal_expression_clear(rasqal_expression* e);
1189 void rasqal_expression_convert_to_literal(rasqal_expression* e, rasqal_literal* l);
1190 int rasqal_expression_mentions_variable(rasqal_expression* e, rasqal_variable* v);
1191 void rasqal_triple_write(rasqal_triple* t, raptor_iostream* iostr);
1192 void rasqal_variable_write(rasqal_variable* v, raptor_iostream* iostr);
1193 int rasqal_expression_is_aggregate(rasqal_expression* e);
1194 int rasqal_expression_convert_aggregate_to_variable(rasqal_expression* e_in, rasqal_variable* v, rasqal_expression** e_out);
1195 int rasqal_expression_mentions_aggregate(rasqal_expression* e);
1196 
1197 raptor_sequence* rasqal_expression_copy_expression_sequence(raptor_sequence* exprs_seq);
1198 int rasqal_literal_sequence_compare(int compare_flags, raptor_sequence* values_a, raptor_sequence* values_b);
1199 raptor_sequence* rasqal_expression_sequence_evaluate(rasqal_query* query, raptor_sequence* exprs_seq, int ignore_errors, int* error_p);
1200 int rasqal_literal_sequence_equals(raptor_sequence* values_a, raptor_sequence* values_b);
1201 
1202 
1203 /* rasqal_expr_evaluate.c */
1204 int rasqal_language_matches(const unsigned char* lang_tag, const unsigned char* lang_range);
1205 
1206 /* rasqal_expr_datetimes.c */
1207 rasqal_literal* rasqal_expression_evaluate_now(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1208 rasqal_literal* rasqal_expression_evaluate_to_unixtime(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1209 rasqal_literal* rasqal_expression_evaluate_from_unixtime(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1210 rasqal_literal* rasqal_expression_evaluate_datetime_part(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1211 rasqal_literal* rasqal_expression_evaluate_datetime_timezone(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1212 rasqal_literal* rasqal_expression_evaluate_datetime_tz(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1213 
1214 /* rasqal_expr_numerics.c */
1215 rasqal_literal* rasqal_expression_evaluate_abs(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1216 rasqal_literal* rasqal_expression_evaluate_round(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1217 rasqal_literal* rasqal_expression_evaluate_ceil(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1218 rasqal_literal* rasqal_expression_evaluate_floor(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1219 rasqal_literal* rasqal_expression_evaluate_rand(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1220 rasqal_literal* rasqal_expression_evaluate_digest(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1221 rasqal_literal* rasqal_expression_evaluate_uriuuid(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1222 rasqal_literal* rasqal_expression_evaluate_struuid(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1223 
1224 /* rasqal_expr_strings.c */
1225 rasqal_literal* rasqal_expression_evaluate_substr(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1226 rasqal_literal* rasqal_expression_evaluate_set_case(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1227 rasqal_literal* rasqal_expression_evaluate_str_prefix_suffix(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1228 rasqal_literal* rasqal_expression_evaluate_strlen(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1229 rasqal_literal* rasqal_expression_evaluate_encode_for_uri(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1230 rasqal_literal* rasqal_expression_evaluate_concat(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1231 rasqal_literal* rasqal_expression_evaluate_langmatches(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1232 rasqal_literal* rasqal_expression_evaluate_strmatch(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1233 rasqal_literal* rasqal_expression_evaluate_strbefore(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1234 rasqal_literal* rasqal_expression_evaluate_strafter(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1235 rasqal_literal* rasqal_expression_evaluate_replace(rasqal_expression *e, rasqal_evaluation_context *eval_context, int *error_p);
1236 
1237 
1238 /* strcasecmp.c */
1239 #ifdef HAVE_STRCASECMP
1240 #  define rasqal_strcasecmp strcasecmp
1241 #  define rasqal_strncasecmp strncasecmp
1242 #else
1243 #  ifdef HAVE_STRICMP
1244 #    define rasqal_strcasecmp stricmp
1245 #    define rasqal_strncasecmp strnicmp
1246 #   else
1247 int rasqal_strcasecmp(const char* s1, const char* s2);
1248 int rasqal_strncasecmp(const char* s1, const char* s2, size_t n);
1249 #  endif
1250 #endif
1251 
1252 /* timegm.c */
1253 #ifdef HAVE_TIMEGM
1254 #define rasqal_timegm timegm
1255 #else
1256 time_t rasqal_timegm(struct tm *tm);
1257 #endif
1258 
1259 /* rasqal_raptor.c */
1260 int rasqal_raptor_init(rasqal_world*);
1261 
1262 #ifdef RAPTOR_TRIPLES_SOURCE_REDLAND
1263 /* rasqal_redland.c */
1264 int rasqal_redland_init(rasqal_world*);
1265 void rasqal_redland_finish(void);
1266 #endif
1267 
1268 rasqal_triple* raptor_statement_as_rasqal_triple(rasqal_world* world, const raptor_statement *statement);
1269 int rasqal_raptor_triple_match(rasqal_world* world, rasqal_triple *triple, rasqal_triple *match, unsigned int parts);
1270 
1271 
1272 /* rasqal_general.c */
1273 int rasqal_uri_init(rasqal_world*);
1274 void rasqal_uri_finish(rasqal_world*);
1275 
1276 /* rasqal_literal.c */
1277 rasqal_formula* rasqal_new_formula(rasqal_world* world);
1278 void rasqal_free_formula(rasqal_formula* formula);
1279 int rasqal_formula_print(rasqal_formula* formula, FILE *stream);
1280 rasqal_formula* rasqal_formula_join(rasqal_formula* first_formula, rasqal_formula* second_formula);
1281 
1282 /* The following should be public eventually in rasqal.h or raptor.h or ...? */
1283 
1284 typedef int (rasqal_compare_fn)(void* user_data, const void *a, const void *b);
1285 typedef void (rasqal_kv_free_fn)(const void *key, const void *value);
1286 
1287 #define RASQAL_XSD_BOOLEAN_TRUE_LEN 4
1288 extern const unsigned char* rasqal_xsd_boolean_true;
1289 
1290 #define RASQAL_XSD_BOOLEAN_FALSE_LEN 5
1291 extern const unsigned char* rasqal_xsd_boolean_false;
1292 
1293 rasqal_literal* rasqal_literal_cast(rasqal_literal* l, raptor_uri* datatype, int flags,  int* error_p);
1294 rasqal_literal* rasqal_new_numeric_literal(rasqal_world*, rasqal_literal_type type, double d);
1295 int rasqal_literal_is_numeric(rasqal_literal* literal);
1296 rasqal_literal* rasqal_literal_add(rasqal_literal* l1, rasqal_literal* l2, int *error);
1297 rasqal_literal* rasqal_literal_subtract(rasqal_literal* l1, rasqal_literal* l2, int *error);
1298 rasqal_literal* rasqal_literal_multiply(rasqal_literal* l1, rasqal_literal* l2, int *error);
1299 rasqal_literal* rasqal_literal_divide(rasqal_literal* l1, rasqal_literal* l2, int *error);
1300 rasqal_literal* rasqal_literal_negate(rasqal_literal* l, int *error_p);
1301 rasqal_literal* rasqal_literal_abs(rasqal_literal* l1,  int *error_p);
1302 rasqal_literal* rasqal_literal_round(rasqal_literal* l1, int *error_p);
1303 rasqal_literal* rasqal_literal_ceil(rasqal_literal* l1,  int *error_p);
1304 rasqal_literal* rasqal_literal_floor(rasqal_literal* l1, int *error_p);
1305 int rasqal_literal_equals_flags(rasqal_literal* l1, rasqal_literal* l2, int flags, int* error);
1306 int rasqal_literal_not_equals_flags(rasqal_literal* l1, rasqal_literal* l2, int flags, int* error);
1307 void rasqal_literal_write_type(rasqal_literal* l, raptor_iostream* iostr);
1308 void rasqal_literal_write(rasqal_literal* l, raptor_iostream* iostr);
1309 void rasqal_expression_write_op(rasqal_expression* e, raptor_iostream* iostr);
1310 void rasqal_expression_write(rasqal_expression* e, raptor_iostream* iostr);
1311 int rasqal_literal_write_turtle(rasqal_literal* l, raptor_iostream* iostr);
1312 int rasqal_literal_array_equals(rasqal_literal** values_a, rasqal_literal** values_b, int size);
1313 int rasqal_literal_array_compare(rasqal_literal** values_a, rasqal_literal** values_b, raptor_sequence* exprs_seq, int size, int compare_flags);
1314 int rasqal_literal_array_compare_by_order(rasqal_literal** values_a, rasqal_literal** values_b, int* order, int size, int compare_flags);
1315 rasqal_map* rasqal_new_literal_sequence_sort_map(int is_distinct, int compare_flags);
1316 int rasqal_literal_sequence_sort_map_add_literal_sequence(rasqal_map* map, raptor_sequence* literals_sequence);
1317 raptor_sequence* rasqal_new_literal_sequence_of_sequence_from_data(rasqal_world* world, const char* const row_data[], int width);
1318 rasqal_literal* rasqal_new_literal_from_term(rasqal_world* world, raptor_term* term);
1319 int rasqal_literal_string_datatypes_compare(rasqal_literal* l1, rasqal_literal* l2);
1320 int rasqal_literal_string_languages_compare(rasqal_literal* l1, rasqal_literal* l2);
1321 int rasqal_literal_is_string(rasqal_literal* l1);
1322 
1323 /* rasqal_map.c */
1324 typedef void (*rasqal_map_visit_fn)(void *key, void *value, void *user_data);
1325 
1326 rasqal_map* rasqal_new_map(rasqal_compare_fn* compare_fn, void* compare_user_data, raptor_data_free_handler free_compare_user_data, raptor_data_free_handler free_key_fn, raptor_data_free_handler free_value_fn, raptor_data_print_handler print_key_fn, raptor_data_print_handler print_value_fn, int flags);
1327 
1328 void rasqal_free_map(rasqal_map *map);
1329 int rasqal_map_add_kv(rasqal_map* map, void* key, void *value);
1330 void rasqal_map_visit(rasqal_map* map, rasqal_map_visit_fn fn, void *user_data);
1331 int rasqal_map_print(rasqal_map* map, FILE* fh);
1332 void* rasqal_map_search(rasqal_map* map, const void* key);
1333 
1334 
1335 /* rasqal_query.c */
1336 rasqal_query_results* rasqal_query_execute_with_engine(rasqal_query* query, const rasqal_query_execution_factory* engine);
1337 int rasqal_query_remove_query_result(rasqal_query* query, rasqal_query_results* query_results);
1338 int rasqal_query_declare_prefix(rasqal_query* rq, rasqal_prefix* prefix);
1339 int rasqal_query_declare_prefixes(rasqal_query* rq);
1340 void rasqal_query_set_base_uri(rasqal_query* rq, raptor_uri* base_uri);
1341 rasqal_variable* rasqal_query_get_variable_by_offset(rasqal_query* query, int idx);
1342 const rasqal_query_execution_factory* rasqal_query_get_engine_by_name(const char* name);
1343 int rasqal_query_variable_is_bound(rasqal_query* query, rasqal_variable* v);
1344 rasqal_triple_parts rasqal_query_variable_bound_in_triple(rasqal_query* query, rasqal_variable* v, int column);
1345 int rasqal_query_store_select_query(rasqal_query* query, rasqal_projection* projection, raptor_sequence* data_graphs, rasqal_graph_pattern* where_gp, rasqal_solution_modifier* modifier);
1346 int rasqal_query_reset_select_query(rasqal_query* query);
1347 rasqal_projection* rasqal_query_get_projection(rasqal_query* query);
1348 int rasqal_query_set_projection(rasqal_query* query, rasqal_projection* projection);
1349 int rasqal_query_set_modifier(rasqal_query* query, rasqal_solution_modifier* modifier);
1350 
1351 /* rasqal_query_results.c */
1352 int rasqal_init_query_results(void);
1353 void rasqal_finish_query_results(void);
1354 int rasqal_query_results_execute_with_engine(rasqal_query_results* query_results, const rasqal_query_execution_factory* factory, int store_results);
1355 int rasqal_query_check_limit_offset_core(int result_offset, int limit, int offset);
1356 int rasqal_query_check_limit_offset(rasqal_query* query, int result_offset);
1357 void rasqal_query_results_remove_query_reference(rasqal_query_results* query_results);
1358 rasqal_variables_table* rasqal_query_results_get_variables_table(rasqal_query_results* query_results);
1359 rasqal_row* rasqal_query_results_get_current_row(rasqal_query_results* query_results);
1360 rasqal_world* rasqal_query_results_get_world(rasqal_query_results* query_results);
1361 #if RAPTOR_VERSION < 20015
1362 typedef int (*raptor_data_compare_arg_handler)(const void *data1, const void *data2, void *user_data);
1363 #endif
1364 int rasqal_query_results_sort(rasqal_query_results* query_result);
1365 int rasqal_query_results_set_boolean(rasqal_query_results* query_results, int value);
1366 
1367 /* rasqal_query_write.c */
1368 int rasqal_query_write_sparql_20060406_graph_pattern(rasqal_graph_pattern* gp, raptor_iostream *iostr,raptor_uri* base_uri);
1369 int rasqal_query_write_sparql_20060406(raptor_iostream *iostr, rasqal_query* query, raptor_uri *base_uri);
1370 
1371 /* rasqal_result_formats.c */
1372 rasqal_query_results_format_factory* rasqal_world_register_query_results_format_factory(rasqal_world* world, int (*register_factory) (rasqal_query_results_format_factory*));
1373 void rasqal_free_query_results_format_factory(rasqal_query_results_format_factory* factory);
1374 int rasqal_init_result_formats(rasqal_world*);
1375 void rasqal_finish_result_formats(rasqal_world*);
1376 
1377 /* rasqal_format_sv.c */
1378 int rasqal_init_result_format_sv(rasqal_world* world);
1379 
1380 /* rasqal_format_json.c */
1381 int rasqal_init_result_format_json(rasqal_world*);
1382 
1383 /* rasqal_format_sparql_xml.c */
1384 int rasqal_init_result_format_sparql_xml(rasqal_world*);
1385 
1386 /* rasqal_format_table.c */
1387 int rasqal_init_result_format_table(rasqal_world*);
1388 
1389 /* rasqal_format_html.c */
1390 int rasqal_init_result_format_html(rasqal_world*);
1391 
1392 /* rasqal_format_turtle.c */
1393 int rasqal_init_result_format_turtle(rasqal_world*);
1394 
1395 /* rasqal_format_rdf.c */
1396 int rasqal_init_result_format_rdf(rasqal_world*);
1397 
1398 /* rasqal_row.c */
1399 rasqal_row* rasqal_new_row(rasqal_rowsource* rowsource);
1400 rasqal_row* rasqal_new_row_from_row(rasqal_row* row);
1401 int rasqal_row_print(rasqal_row* row, FILE* fh);
1402 int rasqal_row_write(rasqal_row* row, raptor_iostream* iostr);
1403 raptor_sequence* rasqal_new_row_sequence(rasqal_world* world, rasqal_variables_table* vt, const char* const row_data[], int vars_count, raptor_sequence** vars_seq_p);
1404 int rasqal_row_to_nodes(rasqal_row* row);
1405 void rasqal_row_set_values_from_variables_table(rasqal_row* row, rasqal_variables_table* vars_table);
1406 int rasqal_row_set_order_size(rasqal_row *row, int order_size);
1407 int rasqal_row_expand_size(rasqal_row *row, int size);
1408 int rasqal_row_bind_variables(rasqal_row* row, rasqal_variables_table* vars_table);
1409 raptor_sequence* rasqal_row_sequence_copy(raptor_sequence *seq);
1410 void rasqal_row_set_rowsource(rasqal_row* row, rasqal_rowsource* rowsource);
1411 void rasqal_row_set_weak_rowsource(rasqal_row* row, rasqal_rowsource* rowsource);
1412 rasqal_variable* rasqal_row_get_variable_by_offset(rasqal_row* row, int offset);
1413 
1414 /* rasqal_row_compatible.c */
1415 rasqal_row_compatible* rasqal_new_row_compatible(rasqal_variables_table* vt, rasqal_rowsource *first_rowsource, rasqal_rowsource *second_rowsource);
1416 void rasqal_free_row_compatible(rasqal_row_compatible* map);
1417 int rasqal_row_compatible_check(rasqal_row_compatible* map, rasqal_row *first_row, rasqal_row *second_row);
1418 void rasqal_print_row_compatible(FILE *handle, rasqal_row_compatible* map);
1419 
1420 /* rasqal_triples_source.c */
1421 rasqal_triples_source* rasqal_new_triples_source(rasqal_query* query);
1422 int rasqal_reset_triple_meta(rasqal_triple_meta* m);
1423 void rasqal_free_triples_source(rasqal_triples_source *rts);
1424 int rasqal_triples_source_triple_present(rasqal_triples_source *rts, rasqal_triple *t);
1425 int rasqal_triples_source_support_feature(rasqal_triples_source *rts, rasqal_triples_source_feature feature);
1426 
1427 rasqal_triples_match* rasqal_new_triples_match(rasqal_query* query, rasqal_triples_source* triples_source, rasqal_triple_meta *m, rasqal_triple *t);
1428 rasqal_triple_parts rasqal_triples_match_bind_match(struct rasqal_triples_match_s* rtm, rasqal_variable *bindings[4],rasqal_triple_parts parts);
1429 void rasqal_triples_match_next_match(struct rasqal_triples_match_s* rtm);
1430 int rasqal_triples_match_is_end(struct rasqal_triples_match_s* rtm);
1431 
1432 
1433 /* rasqal_xsd_datatypes.c */
1434 int rasqal_xsd_init(rasqal_world*);
1435 void rasqal_xsd_finish(rasqal_world*);
1436 rasqal_literal_type rasqal_xsd_datatype_uri_to_type(rasqal_world*, raptor_uri* uri);
1437 raptor_uri* rasqal_xsd_datatype_type_to_uri(rasqal_world*, rasqal_literal_type type);
1438 int rasqal_xsd_datatype_check(rasqal_literal_type native_type, const unsigned char* string, int flags);
1439 const char* rasqal_xsd_datatype_label(rasqal_literal_type native_type);
1440 int rasqal_xsd_is_datatype_uri(rasqal_world*, raptor_uri* uri);
1441 
1442 int rasqal_xsd_datatype_is_numeric(rasqal_literal_type type);
1443 unsigned char* rasqal_xsd_format_integer(int i, size_t *len_p);
1444 unsigned char* rasqal_xsd_format_float(float f, size_t *len_p);
1445 unsigned char* rasqal_xsd_format_double(double d, size_t *len_p);
1446 rasqal_literal_type rasqal_xsd_datatype_parent_type(rasqal_literal_type type);
1447 
1448 int rasqal_xsd_boolean_value_from_string(const unsigned char* string);
1449 
1450 
1451 typedef struct rasqal_graph_factory_s rasqal_graph_factory;
1452 
1453 /* rasqal_world structure */
1454 struct rasqal_world_s {
1455   /* opened flag */
1456   int opened;
1457 
1458   /* raptor_world object */
1459   raptor_world *raptor_world_ptr;
1460 
1461   /* should rasqal free the raptor_world */
1462   int raptor_world_allocated_here;
1463 
1464   /* log handler */
1465   raptor_log_handler log_handler;
1466   void *log_handler_user_data;
1467 
1468   /* sequence of query language factories */
1469   raptor_sequence *query_languages;
1470 
1471   /* registered query results formats */
1472   raptor_sequence *query_results_formats;
1473 
1474   /* rasqal_uri rdf uris */
1475   raptor_uri *rdf_namespace_uri;
1476   raptor_uri *rdf_first_uri;
1477   raptor_uri *rdf_rest_uri;
1478   raptor_uri *rdf_nil_uri;
1479 
1480   /* triples source factory */
1481   rasqal_triples_source_factory triples_source_factory;
1482 
1483   /* rasqal_xsd_datatypes */
1484   raptor_uri *xsd_namespace_uri;
1485   raptor_uri **xsd_datatype_uris;
1486 
1487   /* graph factory */
1488   rasqal_graph_factory *graph_factory;
1489   void *graph_factory_user_data;
1490 
1491   int default_generate_bnodeid_handler_base;
1492   char *default_generate_bnodeid_handler_prefix;
1493   size_t default_generate_bnodeid_handler_prefix_length;
1494 
1495   void *generate_bnodeid_handler_user_data;
1496   rasqal_generate_bnodeid_handler generate_bnodeid_handler;
1497 
1498   /* used for NOW() value */
1499   struct timeval now;
1500   /* set when now is a cached value */
1501   unsigned int now_set : 1;
1502 
1503   rasqal_warning_level warning_level;
1504 
1505   /* generated counter - increments at every generation */
1506   int genid_counter;
1507 };
1508 
1509 
1510 /*
1511  * Rasqal Algebra
1512  *
1513  * Based on http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
1514  */
1515 
1516 typedef enum {
1517   RASQAL_ALGEBRA_OPERATOR_UNKNOWN  = 0,
1518   RASQAL_ALGEBRA_OPERATOR_BGP      = 1,
1519   RASQAL_ALGEBRA_OPERATOR_FILTER   = 2,
1520   RASQAL_ALGEBRA_OPERATOR_JOIN     = 3,
1521   RASQAL_ALGEBRA_OPERATOR_DIFF     = 4,
1522   RASQAL_ALGEBRA_OPERATOR_LEFTJOIN = 5,
1523   RASQAL_ALGEBRA_OPERATOR_UNION    = 6,
1524   RASQAL_ALGEBRA_OPERATOR_TOLIST   = 7,
1525   RASQAL_ALGEBRA_OPERATOR_ORDERBY  = 8,
1526   RASQAL_ALGEBRA_OPERATOR_PROJECT  = 9,
1527   RASQAL_ALGEBRA_OPERATOR_DISTINCT = 10,
1528   RASQAL_ALGEBRA_OPERATOR_REDUCED  = 11,
1529   RASQAL_ALGEBRA_OPERATOR_SLICE    = 12,
1530   RASQAL_ALGEBRA_OPERATOR_GRAPH    = 13,
1531   RASQAL_ALGEBRA_OPERATOR_ASSIGN   = 14,
1532   RASQAL_ALGEBRA_OPERATOR_GROUP    = 15,
1533   RASQAL_ALGEBRA_OPERATOR_AGGREGATION = 16,
1534   RASQAL_ALGEBRA_OPERATOR_HAVING   = 17,
1535   RASQAL_ALGEBRA_OPERATOR_VALUES   = 18,
1536   RASQAL_ALGEBRA_OPERATOR_SERVICE  = 19,
1537 
1538   RASQAL_ALGEBRA_OPERATOR_LAST = RASQAL_ALGEBRA_OPERATOR_SERVICE
1539 } rasqal_algebra_node_operator;
1540 
1541 
1542 /* bitflags used by rasqal_algebra_node and rasqal_rowsource */
1543 typedef enum {
1544   /* used by */
1545   RASQAL_ENGINE_BITFLAG_SILENT = 1
1546 } rasqal_engine_bitflags;
1547 
1548 
1549 /*
1550  * Algebra Node
1551  *
1552  * Rasqal graph pattern class.
1553  */
1554 struct rasqal_algebra_node_s {
1555   rasqal_query* query;
1556 
1557   /* operator for this algebra_node's contents */
1558   rasqal_algebra_node_operator op;
1559 
1560   /* type BGP (otherwise NULL and start_column and end_column are -1) */
1561   raptor_sequence* triples;
1562   int start_column;
1563   int end_column;
1564 
1565   /* types JOIN, DIFF, LEFTJOIN, UNION, ORDERBY: node1 and node2 ALWAYS present
1566    * types FILTER, TOLIST: node1 ALWAYS present, node2 ALWAYS NULL
1567    * type PROJECT, GRAPH, GROUPBY, AGGREGATION, HAVING: node1 always present
1568    * (otherwise NULL)
1569    */
1570   struct rasqal_algebra_node_s *node1;
1571   struct rasqal_algebra_node_s *node2;
1572 
1573   /* types FILTER, LEFTJOIN
1574    * (otherwise NULL)
1575    */
1576   rasqal_expression* expr;
1577 
1578   /* types ORDERBY, GROUPBY, AGGREGATION, HAVING always present: sequence of
1579    * #rasqal_expression
1580    * (otherwise NULL)
1581    */
1582   raptor_sequence* seq;
1583 
1584   /* types PROJECT, DISTINCT, REDUCED
1585    * FIXME: sequence of solution mappings */
1586 
1587   /* types PROJECT, AGGREGATION: sequence of #rasqal_variable */
1588   raptor_sequence* vars_seq;
1589 
1590   /* type SLICE: limit and offset rows */
1591   int limit;
1592   int offset;
1593 
1594   /* type GRAPH */
1595   rasqal_literal *graph;
1596 
1597   /* type LET */
1598   rasqal_variable *var;
1599 
1600   /* type ORDERBY */
1601   int distinct;
1602 
1603   /* type VALUES */
1604   rasqal_bindings *bindings;
1605 
1606   /* type SERVICE */
1607   raptor_uri* service_uri;
1608   const unsigned char* query_string;
1609   raptor_sequence* data_graphs;
1610 
1611   /* flags */
1612   unsigned int flags;
1613 };
1614 typedef struct rasqal_algebra_node_s rasqal_algebra_node;
1615 
1616 
1617 /**
1618  * rasqal_algebra_node_visit_fn:
1619  * @query: #rasqal_query containing the graph pattern
1620  * @gp: current algebra_node
1621  * @user_data: user data passed in
1622  *
1623  * User function to visit an algebra_node and operate on it with
1624  * rasqal_algebra_node_visit() or rasqal_query_algebra_node_visit()
1625  *
1626  * Return value: 0 to truncate the visit
1627  */
1628 typedef int (*rasqal_algebra_node_visit_fn)(rasqal_query* query, rasqal_algebra_node* node, void *user_data);
1629 
1630 typedef struct
1631 {
1632   rasqal_query* query;
1633 
1634   /* aggregate expression variables map
1635    * key: rasqal_expression* tree with an aggregate function at top
1636    * value: rasqal_variable*
1637    */
1638   rasqal_map* agg_vars;
1639 
1640   /* sequence of aggregate #rasqal_expression in same order as @agg_vars_seq */
1641   raptor_sequence* agg_exprs;
1642 
1643   /* sequence of aggregate #rasqal_expression in same order as @agg_exprs */
1644   raptor_sequence* agg_vars_seq;
1645 
1646   /* number of aggregate expressions seen
1647    * ( = number of internal variables created )
1648    */
1649   int counter;
1650 
1651   /* compare flags */
1652   int flags;
1653 
1654   /* error indicator */
1655   int error;
1656 
1657   /* if set, finding a new expression is an error */
1658   unsigned int adding_new_vars_is_error : 1;
1659 
1660   /* query part for error messages */
1661   const char* error_part;
1662 } rasqal_algebra_aggregate;
1663 
1664 
1665 /* rasqal_algebra.c */
1666 
1667 rasqal_algebra_node* rasqal_new_assignment_algebra_node(rasqal_query* query, rasqal_variable *var, rasqal_expression *expr);
1668 rasqal_algebra_node* rasqal_new_distinct_algebra_node(rasqal_query* query, rasqal_algebra_node* node1);
1669 rasqal_algebra_node* rasqal_new_filter_algebra_node(rasqal_query* query, rasqal_expression* expr, rasqal_algebra_node* node);
1670 rasqal_algebra_node* rasqal_new_empty_algebra_node(rasqal_query* query);
1671 rasqal_algebra_node* rasqal_new_triples_algebra_node(rasqal_query* query, raptor_sequence* triples, int start_column, int end_column);
1672 rasqal_algebra_node* rasqal_new_2op_algebra_node(rasqal_query* query, rasqal_algebra_node_operator op, rasqal_algebra_node* node1, rasqal_algebra_node* node2);
1673 rasqal_algebra_node* rasqal_new_leftjoin_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, rasqal_algebra_node* node2, rasqal_expression* expr);
1674 rasqal_algebra_node* rasqal_new_join_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, rasqal_algebra_node* node2, rasqal_expression* expr);
1675 rasqal_algebra_node* rasqal_new_orderby_algebra_node(rasqal_query* query, rasqal_algebra_node* node, raptor_sequence* seq, int distinct);
1676 rasqal_algebra_node* rasqal_new_slice_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, int limit, int offset);
1677 rasqal_algebra_node* rasqal_new_project_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, raptor_sequence* vars_seq);
1678 rasqal_algebra_node* rasqal_new_graph_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, rasqal_literal *graph);
1679 rasqal_algebra_node* rasqal_new_let_algebra_node(rasqal_query* query, rasqal_variable *var, rasqal_expression *expr);
1680 rasqal_algebra_node* rasqal_new_groupby_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, raptor_sequence* seq);
1681 rasqal_algebra_node* rasqal_new_aggregation_algebra_node(rasqal_query* query, rasqal_algebra_node* node1, raptor_sequence* exprs_seq, raptor_sequence* vars_seq);
1682 rasqal_algebra_node* rasqal_new_having_algebra_node(rasqal_query* query,rasqal_algebra_node* node1, raptor_sequence* exprs_seq);
1683 rasqal_algebra_node* rasqal_new_values_algebra_node(rasqal_query* query, rasqal_bindings* bindings);
1684 rasqal_algebra_node* rasqal_new_service_algebra_node(rasqal_query* query, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, int silent);
1685 
1686 void rasqal_free_algebra_node(rasqal_algebra_node* node);
1687 rasqal_algebra_node_operator rasqal_algebra_node_get_operator(rasqal_algebra_node* node);
1688 const char* rasqal_algebra_node_operator_as_counted_string(rasqal_algebra_node_operator op, size_t* length_p);
1689 int rasqal_algebra_algebra_node_write(rasqal_algebra_node *node, raptor_iostream* iostr);
1690 int rasqal_algebra_node_print(rasqal_algebra_node* node, FILE* fh);
1691 int rasqal_algebra_node_visit(rasqal_query *query, rasqal_algebra_node* node, rasqal_algebra_node_visit_fn fn, void *user_data);
1692 rasqal_algebra_node* rasqal_algebra_query_to_algebra(rasqal_query* query);
1693 rasqal_algebra_node* rasqal_algebra_query_add_group_by(rasqal_query* query, rasqal_algebra_node* node, rasqal_solution_modifier* modifier);
1694 rasqal_algebra_node* rasqal_algebra_query_add_orderby(rasqal_query* query, rasqal_algebra_node* node, rasqal_projection* projection, rasqal_solution_modifier* modifier);
1695 rasqal_algebra_node* rasqal_algebra_query_add_slice(rasqal_query* query, rasqal_algebra_node* node, rasqal_solution_modifier* modifier);
1696 rasqal_algebra_node* rasqal_algebra_query_add_aggregation(rasqal_query* query, rasqal_algebra_aggregate* ae, rasqal_algebra_node* node);
1697 rasqal_algebra_node* rasqal_algebra_query_add_projection(rasqal_query* query, rasqal_algebra_node* node, rasqal_projection* projection);
1698 rasqal_algebra_node* rasqal_algebra_query_add_construct_projection(rasqal_query* query, rasqal_algebra_node* node);
1699 rasqal_algebra_node* rasqal_algebra_query_add_distinct(rasqal_query* query, rasqal_algebra_node* node, rasqal_projection* projection);
1700 rasqal_algebra_node* rasqal_algebra_query_add_having(rasqal_query* query, rasqal_algebra_node* node, rasqal_solution_modifier* modifier);
1701 int rasqal_algebra_node_is_empty(rasqal_algebra_node* node);
1702 
1703 rasqal_algebra_aggregate* rasqal_algebra_query_prepare_aggregates(rasqal_query* query, rasqal_algebra_node* node, rasqal_projection* projection, rasqal_solution_modifier* modifier);
1704 void rasqal_free_algebra_aggregate(rasqal_algebra_aggregate* ae);
1705 
1706 /* rasqal_variable.c */
1707 rasqal_variables_table* rasqal_new_variables_table_from_variables_table(rasqal_variables_table* vt);
1708 rasqal_variable* rasqal_variables_table_get(rasqal_variables_table* vt, int idx);
1709 rasqal_literal* rasqal_variables_table_get_value(rasqal_variables_table* vt, int idx);
1710 int rasqal_variables_table_set(rasqal_variables_table* vt, rasqal_variable_type type, const unsigned char *name, rasqal_literal* value);
1711 int rasqal_variables_table_get_named_variables_count(rasqal_variables_table* vt);
1712 int rasqal_variables_table_get_anonymous_variables_count(rasqal_variables_table* vt);
1713 int rasqal_variables_table_get_total_variables_count(rasqal_variables_table* vt);
1714 raptor_sequence* rasqal_variables_table_get_named_variables_sequence(rasqal_variables_table* vt);
1715 raptor_sequence* rasqal_variables_table_get_anonymous_variables_sequence(rasqal_variables_table* vt);
1716 const unsigned char** rasqal_variables_table_get_names(rasqal_variables_table* vt);
1717 raptor_sequence* rasqal_variable_copy_variable_sequence(raptor_sequence* vars_seq);
1718 int rasqal_variables_write(raptor_sequence* seq, raptor_iostream* iostr);
1719 
1720 /**
1721  * rasqal_engine_error:
1722  * @RASQAL_ENGINE_OK:
1723  * @RASQAL_ENGINE_FAILED:
1724  * @RASQAL_ENGINE_FINISHED:
1725  *
1726  * Execution engine errors.
1727  *
1728  */
1729 typedef enum {
1730   RASQAL_ENGINE_OK,
1731   RASQAL_ENGINE_FAILED,
1732   RASQAL_ENGINE_FINISHED,
1733   RASQAL_ENGINE_ERROR_LAST = RASQAL_ENGINE_FINISHED
1734 } rasqal_engine_error;
1735 
1736 
1737 /*
1738  * A query execution engine factory
1739  *
1740  * This structure is about executing the query recorded in
1741  * #rasqal_query structure into results accessed via #rasqal_query_results
1742  */
1743 struct rasqal_query_execution_factory_s {
1744   /* execution engine name */
1745   const char* name;
1746 
1747   /* size of execution engine private data */
1748   size_t execution_data_size;
1749 
1750   /*
1751    * @ex_data: execution data
1752    * @query: query to execute
1753    * @query_results: query results
1754    * @flags: execution flags.  1: execute and store results
1755    * @error_p: execution error (OUT variable)
1756    *
1757    * Initialise a new execution
1758    *
1759    * Return value: non-0 on failure
1760    */
1761   int (*execute_init)(void* ex_data, rasqal_query* query, rasqal_query_results* query_results, int flags, rasqal_engine_error *error_p);
1762 
1763   /**
1764    * @ex_data: execution data
1765    * @error_p: execution error (OUT variable)
1766    *
1767    * Get all bindings result rows (returning a new raptor_sequence object holding new objects.
1768    *
1769    * Will not be called if query results is NULL, finished or failed.
1770    */
1771   raptor_sequence* (*get_all_rows)(void* ex_data, rasqal_engine_error *error_p);
1772 
1773   /*
1774    * @ex_data: execution object
1775    * @error_p: execution error (OUT variable)
1776    *
1777    * Get current bindings result row (returning a new object)
1778    *
1779    * Will not be called if query results is NULL, finished or failed.
1780    */
1781   rasqal_row* (*get_row)(void* ex_data, rasqal_engine_error *error_p);
1782 
1783   /* finish (free) execution */
1784   int (*execute_finish)(void* ex_data, rasqal_engine_error *error_p);
1785 
1786   /* finish the query execution factory */
1787   void (*finish_factory)(rasqal_query_execution_factory* factory);
1788 
1789 };
1790 
1791 
1792 /* rasqal_engine.c */
1793 #ifdef RASQAL_DEBUG
1794 const char* rasqal_engine_get_parts_string(rasqal_triple_parts parts);
1795 const char* rasqal_engine_error_as_string(rasqal_engine_error error);
1796 #endif
1797 
1798 
1799 /* rasqal_engine_sort.c */
1800 rasqal_map* rasqal_engine_new_rowsort_map(int is_distinct, int compare_flags, raptor_sequence* order_conditions_sequence);
1801 int rasqal_engine_rowsort_map_add_row(rasqal_map* map, rasqal_row* row);
1802 raptor_sequence* rasqal_engine_rowsort_map_to_sequence(rasqal_map* map, raptor_sequence* seq);
1803 int rasqal_engine_rowsort_calculate_order_values(rasqal_query* query, raptor_sequence* order_seq, rasqal_row* row);
1804 
1805 
1806 /* rasqal_engine_algebra.c */
1807 
1808 /* New query engine based on executing over query algebra */
1809 extern const rasqal_query_execution_factory rasqal_query_engine_algebra;
1810 
1811 /* rasqal_iostream.c */
1812 raptor_iostream* rasqal_new_iostream_from_stringbuffer(raptor_world *raptor_world_ptr, raptor_stringbuffer* sb);
1813 
1814 /* rasqal_service.c */
1815 rasqal_rowsource* rasqal_service_execute_as_rowsource(rasqal_service* svc, rasqal_variables_table* vars_table);
1816 
1817 /* rasqal_triples_source.c */
1818 void rasqal_triples_source_error_handler(rasqal_query* rdf_query, raptor_locator* locator, const char* message);
1819 void rasqal_triples_source_error_handler2(rasqal_world* world, raptor_locator* locator,  const char* message);
1820 
1821 /* rasqal_update.c */
1822 const char* rasqal_update_type_label(rasqal_update_type type);
1823 rasqal_update_operation* rasqal_new_update_operation(rasqal_update_type type, raptor_uri* graph_uri, raptor_uri* document_uri, raptor_sequence* insert_templates, raptor_sequence* delete_templates, rasqal_graph_pattern* graph_pattern, int flags, rasqal_update_graph_applies applies);
1824 void rasqal_free_update_operation(rasqal_update_operation *update);
1825 int rasqal_update_operation_print(rasqal_update_operation *update, FILE* stream);
1826 int rasqal_query_add_update_operation(rasqal_query* query, rasqal_update_operation *update);
1827 
1828 
1829 /* rasqal_bindings.c */
1830 rasqal_bindings* rasqal_new_bindings(rasqal_query* query, raptor_sequence* variables, raptor_sequence* rows);
1831 rasqal_bindings* rasqal_new_bindings_from_var_values(rasqal_query* query, rasqal_variable* var, raptor_sequence* values);
1832 rasqal_bindings* rasqal_new_bindings_from_bindings(rasqal_bindings* bindings);
1833 void rasqal_free_bindings(rasqal_bindings* bindings);
1834 int rasqal_bindings_print(rasqal_bindings* bindings, FILE* fh);
1835 rasqal_row* rasqal_bindings_get_row(rasqal_bindings* bindings, int offset);
1836 
1837 /* rasqal_ntriples.c */
1838 rasqal_literal* rasqal_new_literal_from_ntriples_counted_string(rasqal_world* world, unsigned char* string, size_t length);
1839 
1840 /* rasqal_projection.c */
1841 rasqal_projection* rasqal_new_projection(rasqal_query* query, raptor_sequence* variables, int wildcard, int distinct);
1842 void rasqal_free_projection(rasqal_projection* projection);
1843 raptor_sequence* rasqal_projection_get_variables_sequence(rasqal_projection* projection);
1844 int rasqal_projection_add_variable(rasqal_projection* projection, rasqal_variable* var);
1845 
1846 /* rasqal_regex.c */
1847 int rasqal_regex_match(rasqal_world* world, raptor_locator* locator, const char* pattern, const char* regex_flags, const char* subject, size_t subject_len);
1848 
1849 /* rasqal_results_compare.c */
1850 rasqal_results_compare* rasqal_new_results_compare(rasqal_world* world, rasqal_query_results *first_qr, const char* first_qr_label, rasqal_query_results *second_qr, const char* second_qr_label);
1851 void rasqal_free_results_compare(rasqal_results_compare* rrc);
1852 void rasqal_results_compare_set_log_handler(rasqal_results_compare* rrc, void* log_user_data, raptor_log_handler log_handler);
1853 int rasqal_results_compare_compare(rasqal_results_compare* rrc);
1854 rasqal_variable* rasqal_results_compare_get_variable_by_offset(rasqal_results_compare* rrc, int idx);
1855 int rasqal_results_compare_get_variable_offset_for_result(rasqal_results_compare* rrc, int var_idx, int qr_index);
1856 int rasqal_results_compare_variables_equal(rasqal_results_compare* rrc);
1857 void rasqal_print_results_compare(FILE *handle, rasqal_results_compare* rrc);
1858 
1859 /* rasqal_service.c */
1860 rasqal_service* rasqal_new_service_from_service(rasqal_service* svc);
1861 
1862 /* rasqal_solution_modifier.c */
1863 rasqal_solution_modifier* rasqal_new_solution_modifier(rasqal_query* query, raptor_sequence* order_conditions, raptor_sequence* group_conditions, raptor_sequence* having_conditions, int limit, int offset);
1864 void rasqal_free_solution_modifier(rasqal_solution_modifier* sm);
1865 
1866 /* rasqal_triples.c */
1867 int rasqal_triples_sequence_set_origin(raptor_sequence* dest_seq, raptor_sequence* src_seq, rasqal_literal* origin);
1868 
1869 /* rasqal_random.c */
1870 /**
1871  * RASQAL_RANDOM_STATE_SIZE:
1872  *
1873  * Size of BSD random state
1874  *
1875  * "With 256 bytes of state information, the period of the random
1876  * number generator is greater than 2**69 , which should be
1877  * sufficient for most purposes." - BSD random(3) man page
1878  */
1879 #define RASQAL_RANDOM_STATE_SIZE 256
1880 
1881 
1882 /**
1883  * rasqal_random:
1884  * @world: world object
1885  * @seed: used for rand_r() (if available) or srand()
1886  * @state: used for BSD initstate(), setstate() and random() (if available)
1887  * @data: internal to random algorithm
1888  *
1889  * A class providing a random number generator
1890  *
1891  */
1892 struct rasqal_random_s {
1893   rasqal_world* world;
1894   unsigned int seed;
1895   char state[RASQAL_RANDOM_STATE_SIZE];
1896   void* data;
1897 };
1898 
1899 unsigned int rasqal_random_get_system_seed(rasqal_world *world);
1900 rasqal_random* rasqal_new_random(rasqal_world *world);
1901 void rasqal_free_random(rasqal_random *random_object);
1902 int rasqal_random_seed(rasqal_random *random_object, unsigned int seed);
1903 int rasqal_random_irand(rasqal_random *random_object);
1904 double rasqal_random_drand(rasqal_random *random_object);
1905 
1906 /* rasqal_sort.c */
1907 #if RAPTOR_VERSION < 20015
1908 void** rasqal_sequence_as_sorted(raptor_sequence* seq,  raptor_data_compare_arg_handler compare, void* user_data);
1909 #endif
1910 int* rasqal_variables_table_get_order(rasqal_variables_table* vt);
1911 
1912 /*
1913  * rasqal_digest_type:
1914  * RASQAL_DIGEST_NONE: No digest
1915  * RASQAL_DIGEST_MD5: MD5
1916  * RASQAL_DIGEST_SHA1: SHA1
1917  * RASQAL_DIGEST_SHA224: SHA224
1918  * RASQAL_DIGEST_SHA256: SHA256
1919  * RASQAL_DIGEST_SHA384: SHA384
1920  * RASQAL_DIGEST_SHA512: SHA512
1921  * RASQAL_DIGEST_LAST: Internal
1922  *
1923  * INTERNAL - Message digest algorithm for rasqal_digest_buffer()
1924 */
1925 typedef enum {
1926   RASQAL_DIGEST_NONE,
1927   RASQAL_DIGEST_MD5,
1928   RASQAL_DIGEST_SHA1,
1929   RASQAL_DIGEST_SHA224,
1930   RASQAL_DIGEST_SHA256,
1931   RASQAL_DIGEST_SHA384,
1932   RASQAL_DIGEST_SHA512,
1933   RASQAL_DIGEST_LAST = RASQAL_DIGEST_SHA512
1934 } rasqal_digest_type;
1935 
1936 int rasqal_digest_buffer(rasqal_digest_type type, unsigned char *output, const unsigned char * const input, size_t len);
1937 #ifdef RASQAL_DIGEST_INTERNAL
1938 
1939 int rasqal_digest_sha1_buffer(const unsigned char *output,
1940                               const unsigned char *input, size_t len);
1941 int rasqal_digest_md5_buffer(const unsigned char *output,
1942                              const unsigned char *input, size_t len);
1943 #endif
1944 
1945 /* snprint.c */
1946 size_t rasqal_format_integer(char* buffer, size_t bufsize, int integer, int width, char padding);
1947 
1948 /* Safe casts: widening a value */
1949 #define RASQAL_GOOD_CAST(t, v) (t)(v)
1950 
1951 /* Unsafe casts: narrowing a value */
1952 #define RASQAL_BAD_CAST(t, v) (t)(v)
1953 
1954 /* Converting a double / float to int - OK but not great */
1955 #define RASQAL_FLOATING_AS_INT(v) ((int)(v))
1956 
1957 /* IEEE 32 bit double ~ 1E-07 and 64 bit double  ~ 2E-16 */
1958 #define RASQAL_DOUBLE_EPSILON (DBL_EPSILON)
1959 
1960 /* end of RASQAL_INTERNAL */
1961 #endif
1962 
1963 
1964 #ifdef __cplusplus
1965 }
1966 #endif
1967 
1968 #endif
1969