SourceForge.net Logo

xqc.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Matthias Brantner, John Snelson
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright notice,
00009  *       this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the developers nor the names of contributors may be
00014  *       used to endorse or promote products derived from this software without
00015  *       specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _XQUERY_C_API_H
00031 #define _XQUERY_C_API_H
00032 
00033 /* Include stdio for FILE */
00034 #include <stdio.h>
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00041 #define XQC_VERSION_NUMBER 1
00042 
00043 typedef struct XQC_Implementation_s XQC_Implementation;
00044 typedef struct XQC_StaticContext_s XQC_StaticContext;
00045 typedef struct XQC_Expression_s XQC_Expression;
00046 typedef struct XQC_DynamicContext_s XQC_DynamicContext;
00047 typedef struct XQC_Sequence_s XQC_Sequence;
00048 typedef struct XQC_InputStream_s XQC_InputStream;
00049 typedef struct XQC_ErrorHandler_s XQC_ErrorHandler;
00050 
00055 typedef enum {
00056         XQC_NO_ERROR = 0,          
00057         XQC_END_OF_SEQUENCE,       
00058         XQC_NO_CURRENT_ITEM,
00059         XQC_PARSE_ERROR,
00060         XQC_INVALID_ARGUMENT,
00061         XQC_NOT_NODE,
00062 
00063         XQC_INTERNAL_ERROR,        
00064         XQC_NOT_IMPLEMENTED,       
00065 
00069         XQC_UNRECOGNIZED_ENCODING,
00070 
00071         XQC_STATIC_ERROR,          
00072         XQC_TYPE_ERROR,            
00073         XQC_DYNAMIC_ERROR,         
00074         XQC_SERIALIZATION_ERROR    
00075 } XQC_Error;
00076 
00081 struct XQC_InputStream_s {
00088         const char *encoding;
00089 
00093         void *user_data;
00094 
00108         unsigned int (*read)(XQC_InputStream *stream, void *buffer, unsigned int length);
00109 
00116         void (*free)(XQC_InputStream *stream);
00117 };
00118 
00131 struct XQC_ErrorHandler_s {
00132 
00136         void *user_data;
00137 
00156         void (*error)(XQC_ErrorHandler *handler, XQC_Error error, const char *error_uri,
00157                 const char *error_localname, const char *description, XQC_Sequence *error_object);
00158 };
00159 
00160 typedef enum {
00161         XQC_EMPTY_TYPE = 0,
00162 
00163         XQC_DOCUMENT_TYPE,
00164         XQC_ELEMENT_TYPE,
00165         XQC_ATTRIBUTE_TYPE,
00166         XQC_TEXT_TYPE,
00167         XQC_PROCESSING_INSTRUCTION_TYPE,
00168         XQC_COMMENT_TYPE,
00169         XQC_NAMESPACE_TYPE,
00170 
00171         XQC_ANY_SIMPLE_TYPE,
00172         XQC_ANY_URI_TYPE,
00173         XQC_BASE_64_BINARY_TYPE,
00174         XQC_BOOLEAN_TYPE,
00175         XQC_DATE_TYPE,
00176         XQC_DATE_TIME_TYPE,
00177         XQC_DAY_TIME_DURATION_TYPE,
00178         XQC_DECIMAL_TYPE,
00179         XQC_DOUBLE_TYPE,
00180         XQC_DURATION_TYPE,
00181         XQC_FLOAT_TYPE,
00182         XQC_G_DAY_TYPE,
00183         XQC_G_MONTH_TYPE,
00184         XQC_G_MONTH_DAY_TYPE,
00185         XQC_G_YEAR_TYPE,
00186         XQC_G_YEAR_MONTH_TYPE,
00187         XQC_HEX_BINARY_TYPE,
00188         XQC_NOTATION_TYPE,
00189         XQC_QNAME_TYPE,
00190         XQC_STRING_TYPE,
00191         XQC_TIME_TYPE,
00192         XQC_UNTYPED_ATOMIC_TYPE,
00193         XQC_YEAR_MONTH_DURATION_TYPE
00194         
00195 } XQC_ItemType;
00196 
00207 struct XQC_Implementation_s {
00208 
00225         XQC_Error (*create_context)(XQC_Implementation *implementation, XQC_StaticContext **context);
00226 
00244         XQC_Error (*prepare)(XQC_Implementation *implementation, const char *string,
00245                 const XQC_StaticContext *context, XQC_Expression **expression);
00246 
00266         XQC_Error (*prepare_file)(XQC_Implementation *implementation, FILE *file,
00267                 const XQC_StaticContext *context, XQC_Expression **expression);
00268 
00290         XQC_Error (*prepare_stream)(XQC_Implementation *implementation, XQC_InputStream *stream,
00291                 const XQC_StaticContext *context, XQC_Expression **expression);
00292 
00294 
00300 
00301         XQC_Error (*parse_document)(XQC_Implementation *implementation,
00302                 const char *string, XQC_Sequence **sequence);
00304         XQC_Error (*parse_document_file)(XQC_Implementation *implementation,
00305                 FILE *file, XQC_Sequence **sequence);
00307         XQC_Error (*parse_document_stream)(XQC_Implementation *implementation,
00308                 XQC_InputStream *stream, XQC_Sequence **sequence);
00309 
00311 
00317         XQC_Error (*create_empty_sequence)(XQC_Implementation *implementation,
00318                 XQC_Sequence **sequence);
00319         XQC_Error (*create_singleton_sequence)(XQC_Implementation *implementation,
00320                 XQC_ItemType type, const char *value,
00321                 XQC_Sequence **sequence);
00322         XQC_Error (*create_string_sequence)(XQC_Implementation *implementation,
00323                 const char *values[], unsigned int count,
00324                 XQC_Sequence **sequence);
00325         XQC_Error (*create_integer_sequence)(XQC_Implementation *implementation,
00326                 int values[], unsigned int count,
00327                 XQC_Sequence **sequence);
00328         XQC_Error (*create_double_sequence)(XQC_Implementation *implementation,
00329                 double values[], unsigned int count,
00330                 XQC_Sequence **sequence);
00331 
00333 
00343         void *(*get_interface)(const XQC_Implementation *implementation, const char *name);
00344 
00351         void (*free)(XQC_Implementation *implementation);
00352 };
00353 
00359 typedef enum { XQC_XPATH2_0, XQC_XPATH1_0 } XQC_XPath1Mode;
00360 
00364 typedef enum { XQC_ORDERED, XQC_UNORDERED } XQC_OrderingMode;
00365 
00370 typedef enum { XQC_EMPTY_GREATEST, XQC_EMPTY_LEAST } XQC_OrderEmptyMode;
00371 
00376 typedef enum { XQC_INHERIT_NS, XQC_NO_INHERIT_NS } XQC_InheritMode;
00377 
00382 typedef enum { XQC_PRESERVE_NS, XQC_NO_PRESERVE_NS } XQC_PreserveMode;
00383 
00387 typedef enum { XQC_PRESERVE_SPACE, XQC_STRIP_SPACE } XQC_BoundarySpaceMode;
00388 
00392 typedef enum { XQC_PRESERVE_CONS, XQC_STRIP_CONS } XQC_ConstructionMode;
00393 
00404 struct XQC_StaticContext_s {
00405 
00420         XQC_Error
00421         (*create_child_context)(XQC_StaticContext *context, XQC_StaticContext **child_context);
00422 
00434         XQC_Error
00435         (*declare_ns)(XQC_StaticContext *context, const char *prefix, const char *uri);
00436 
00448         XQC_Error
00449         (*get_ns_by_prefix)(XQC_StaticContext *context, const char *prefix, const char **result_ns);
00450 
00460         XQC_Error
00461         (*set_default_element_and_type_ns)(XQC_StaticContext *context, const char *uri);
00462 
00471         XQC_Error
00472         (*get_default_element_and_type_ns)(XQC_StaticContext *context, const char **uri);
00473 
00483         XQC_Error
00484         (*set_default_function_ns)(XQC_StaticContext *context, const char *uri);
00485 
00495         XQC_Error
00496         (*get_default_function_ns)(XQC_StaticContext *context, const char **uri);
00497 
00507         XQC_Error
00508         (*set_xpath_compatib_mode)(XQC_StaticContext *context, XQC_XPath1Mode mode);
00509 
00519         XQC_Error 
00520         (*get_xpath_compatib_mode)(XQC_StaticContext *context, XQC_XPath1Mode* mode);
00521 
00531         XQC_Error
00532         (*set_construction_mode)(XQC_StaticContext *context, XQC_ConstructionMode mode);
00533 
00543         XQC_Error
00544         (*get_construction_mode)(XQC_StaticContext *context, XQC_ConstructionMode* mode);
00545 
00555         XQC_Error
00556         (*set_ordering_mode)(XQC_StaticContext *context, XQC_OrderingMode mode);
00557 
00567         XQC_Error
00568         (*get_ordering_mode)(XQC_StaticContext *context, XQC_OrderingMode* mode);
00569 
00580         XQC_Error
00581         (*set_default_order_empty_sequences)(XQC_StaticContext *context, XQC_OrderEmptyMode mode);
00582 
00593         XQC_Error
00594         (*get_default_order_empty_sequences)(XQC_StaticContext *context, XQC_OrderEmptyMode* mode);
00595 
00605         XQC_Error  
00606         (*set_boundary_space_policy)(XQC_StaticContext *context, XQC_BoundarySpaceMode mode);
00607 
00617         XQC_Error
00618         (*get_boundary_space_policy)(XQC_StaticContext *context, XQC_BoundarySpaceMode* mode);
00619 
00630         XQC_Error 
00631         (*set_copy_ns_mode)(XQC_StaticContext *context, XQC_PreserveMode preserve, XQC_InheritMode inherit);
00632 
00644         XQC_Error
00645         (*get_copy_ns_mode)(XQC_StaticContext *context, XQC_PreserveMode* preserve, XQC_InheritMode* inherit);
00646 
00656         XQC_Error
00657         (*set_base_uri)(XQC_StaticContext *context, const char *base_uri);
00658 
00668         XQC_Error
00669         (*get_base_uri)(XQC_StaticContext *context, const char **base_uri);
00670 
00671         XQC_Error (*set_error_handler)(XQC_StaticContext *context, XQC_ErrorHandler *handler);
00672         XQC_Error (*get_error_handler)(const XQC_StaticContext *context, XQC_ErrorHandler **handler);
00673 
00683         void *(*get_interface)(const XQC_StaticContext *context, const char *name);
00684 
00691         void (*free)(XQC_StaticContext *context);
00692 };
00693 
00707 struct XQC_Expression_s {
00708 
00720         XQC_Error (*create_context)(const XQC_Expression *expression, XQC_DynamicContext **context);
00721 
00738         XQC_Error (*execute)(const XQC_Expression *expression, const XQC_DynamicContext *context, XQC_Sequence **sequence);
00739 
00749         void *(*get_interface)(const XQC_Expression *expression, const char *name);
00750 
00757         void (*free)(XQC_Expression *expression);
00758 };
00759 
00760 struct XQC_DynamicContext_s {
00779         XQC_Error (*set_variable)(XQC_DynamicContext *context, const char *uri, const char *name,
00780                 XQC_Sequence *value);
00781 
00782         XQC_Error (*get_variable)(const XQC_DynamicContext *context, const char *uri, const char *name,
00783                 XQC_Sequence **value);
00784 
00802         XQC_Error (*set_context_item)(XQC_DynamicContext *context, XQC_Sequence *value);
00803 
00804         XQC_Error (*get_context_item)(const XQC_DynamicContext *context, XQC_Sequence **value);
00805 
00811         XQC_Error (*set_implicit_timezone)(XQC_DynamicContext *context, int timezone);
00812         XQC_Error (*get_implicit_timezone)(const XQC_DynamicContext *context, int *timezone);
00813 
00814         XQC_Error (*set_error_handler)(XQC_DynamicContext *context, XQC_ErrorHandler *handler);
00815         XQC_Error (*get_error_handler)(const XQC_DynamicContext *context, XQC_ErrorHandler **handler);
00816 
00826         void *(*get_interface)(const XQC_DynamicContext *context, const char *name);
00827 
00834         void (*free)(XQC_DynamicContext *context);
00835 };
00836 
00843 struct XQC_Sequence_s {
00854         XQC_Error (*next)(XQC_Sequence *sequence);
00855 
00871         XQC_Error (*item_type)(const XQC_Sequence *sequence, XQC_ItemType *type);
00872 
00886         XQC_Error (*type_name)(const XQC_Sequence *sequence, const char **uri, const char **name);
00887 
00901         XQC_Error (*string_value)(const XQC_Sequence *sequence, const char **value);
00902 
00915         XQC_Error (*integer_value)(const XQC_Sequence *sequence, int *value);
00916 
00929         XQC_Error (*double_value)(const XQC_Sequence *sequence, double *value);
00930 
00945         XQC_Error (*node_name)(const XQC_Sequence *sequence, const char **uri, const char **name);
00946 
00958         void *(*get_interface)(const XQC_Sequence *sequence, const char *name);
00959 
00966         void (*free)(XQC_Sequence *sequence);
00967 };
00968 
00969 #ifdef  __cplusplus
00970 }
00971 #endif
00972 
00973 #endif