YAJL 1.0.12
yajl_parse.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010, Lloyd Hilaiel.
00003  * 
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  * 
00008  *  1. Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer.
00010  * 
00011  *  2. Redistributions in binary form must reproduce the above copyright
00012  *     notice, this list of conditions and the following disclaimer in
00013  *     the documentation and/or other materials provided with the
00014  *     distribution.
00015  * 
00016  *  3. Neither the name of Lloyd Hilaiel nor the names of its
00017  *     contributors may be used to endorse or promote products derived
00018  *     from this software without specific prior written permission.
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00021  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
00024  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00026  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00028  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */ 
00032 
00038 #include <yajl/yajl_common.h>
00039 
00040 #ifndef __YAJL_PARSE_H__
00041 #define __YAJL_PARSE_H__
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif    
00046 
00047     typedef enum {
00049         yajl_status_ok,
00051         yajl_status_client_canceled,
00055         yajl_status_insufficient_data,
00058         yajl_status_error
00059     } yajl_status;
00060 
00062     YAJL_API const char * yajl_status_to_string(yajl_status code);
00063 
00065     typedef struct yajl_handle_t * yajl_handle;
00066 
00088     typedef struct {
00089         int (* yajl_null)(void * ctx);
00090         int (* yajl_boolean)(void * ctx, int boolVal);
00091         int (* yajl_integer)(void * ctx, long integerVal);
00092         int (* yajl_double)(void * ctx, double doubleVal);
00095         int (* yajl_number)(void * ctx, const char * numberVal,
00096                             unsigned int numberLen);
00097 
00100         int (* yajl_string)(void * ctx, const unsigned char * stringVal,
00101                             unsigned int stringLen);
00102 
00103         int (* yajl_start_map)(void * ctx);
00104         int (* yajl_map_key)(void * ctx, const unsigned char * key,
00105                              unsigned int stringLen);
00106         int (* yajl_end_map)(void * ctx);        
00107 
00108         int (* yajl_start_array)(void * ctx);
00109         int (* yajl_end_array)(void * ctx);        
00110     } yajl_callbacks;
00111     
00113     typedef struct {
00116         unsigned int allowComments;
00119         unsigned int checkUTF8;
00120     } yajl_parser_config;
00121 
00130     YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
00131                                     const yajl_parser_config * config,
00132                                     const yajl_alloc_funcs * allocFuncs,
00133                                     void * ctx);
00134 
00136     YAJL_API void yajl_free(yajl_handle handle);
00137 
00143     YAJL_API yajl_status yajl_parse(yajl_handle hand,
00144                                     const unsigned char * jsonText,
00145                                     unsigned int jsonTextLength);
00146 
00156     YAJL_API yajl_status yajl_parse_complete(yajl_handle hand);
00157     
00168     YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
00169                                             const unsigned char * jsonText,
00170                                             unsigned int jsonTextLength);
00171 
00184     YAJL_API unsigned int yajl_get_bytes_consumed(yajl_handle hand);
00185 
00187     YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);
00188 
00189 #ifdef __cplusplus
00190 }
00191 #endif    
00192 
00193 #endif