2 Copyright (C) 2006 Georgia Public Library Service
3 Bill Erickson <billserickson@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 #ifndef OSRF_JSON_UTILS_H
17 #define OSRF_JSON_UTILS_H
19 /* ----------------------------------------------------------------------- */
20 /* Clients need not include this file. These are internal utilities only */
21 /* ----------------------------------------------------------------------- */
23 #define JSON_EAT_WS(ctx) \
24 while( ctx->index < ctx->chunksize ) { \
25 if(!isspace(ctx->chunk[ctx->index])) break; \
28 if( ctx->index >= ctx->chunksize ) return 0; \
29 c = ctx->chunk[ctx->index];
31 #define JSON_CACHE_DATA(ctx, buf, size) \
32 while( (buf->n_used < size) && (ctx->index < ctx->chunksize) ) \
33 buffer_add_char(buf, ctx->chunk[ctx->index++]);
35 #define JSON_LOG_MARK __FILE__,__LINE__
37 #define JSON_NUMBER_CHARS "0123456789.+-eE"
40 * These are the callbacks through which the top level parser
41 * builds objects via the push parser
43 void _jsonHandleStartObject(void*);
44 void _jsonHandleObjectKey(void*, char* key);
45 void _jsonHandleEndObject(void*);
46 void _jsonHandleStartArray(void*);
47 void _jsonHandleEndArray(void*);
48 void _jsonHandleNull(void*);
49 void _jsonHandleString(void*, char* string);
50 void _jsonHandleBool(void*, int boolval);
51 void _jsonHandleNumber(void*, const char* numstr);
52 void _jsonHandleError(void*, char* str, ...);
54 struct jsonInternalParserStruct {
55 jsonParserContext* ctx;
59 void (*handleError) (const char*);
61 typedef struct jsonInternalParserStruct jsonInternalParser;
63 jsonInternalParser* _jsonNewInternalParser();
64 void _jsonInternalParserFree(jsonInternalParser* p);
67 * Calls the defined error handler with the given error message.
70 int _jsonParserError( jsonParserContext* ctx, char* err, ... );
75 * @return 0 on continue, 1 if it goes past the end of the string, -1 on error
77 int _jsonParserHandleUnicode( jsonParserContext* ctx );
81 * @param type 0 for null, 1 for true, 2 for false
82 * @return 0 on continue, 1 if it goes past the end of the string, -1 on error
84 int _jsonParserHandleMatch( jsonParserContext* ctx, int type );
87 * @return 0 on continue, 1 on end of chunk, -1 on error
89 int _jsonParserHandleString( jsonParserContext* ctx );
92 * @return 0 on continue, 1 on end of chunk, -1 on error
94 int _jsonParserHandleNumber( jsonParserContext* ctx );
97 void _jsonInsertParserItem( jsonInternalParser* p, jsonObject* newo );