2009-07-28 16:01:52 +08:00
|
|
|
/*
|
2011-01-21 03:28:54 +08:00
|
|
|
* Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
|
2009-07-28 16:01:52 +08:00
|
|
|
*
|
|
|
|
* Jansson is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
|
|
*/
|
|
|
|
|
2009-07-14 02:03:09 +08:00
|
|
|
#ifndef JANSSON_PRIVATE_H
|
|
|
|
#define JANSSON_PRIVATE_H
|
|
|
|
|
2010-08-13 02:34:02 +08:00
|
|
|
#include <stddef.h>
|
2011-01-24 03:14:19 +08:00
|
|
|
#include <stdarg.h>
|
2009-10-16 02:02:27 +08:00
|
|
|
#include "jansson.h"
|
|
|
|
#include "hashtable.h"
|
|
|
|
|
|
|
|
#define container_of(ptr_, type_, member_) \
|
2010-08-13 02:34:02 +08:00
|
|
|
((type_ *)((char *)ptr_ - offsetof(type_, member_)))
|
2009-10-16 02:02:27 +08:00
|
|
|
|
2010-09-06 01:54:37 +08:00
|
|
|
/* On some platforms, max() may already be defined */
|
|
|
|
#ifndef max
|
|
|
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 02:02:27 +08:00
|
|
|
typedef struct {
|
|
|
|
json_t json;
|
|
|
|
hashtable_t hashtable;
|
2010-06-15 20:27:35 +08:00
|
|
|
size_t serial;
|
2009-10-16 02:02:27 +08:00
|
|
|
int visited;
|
|
|
|
} json_object_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
json_t json;
|
2010-06-15 20:27:35 +08:00
|
|
|
size_t size;
|
|
|
|
size_t entries;
|
2009-10-16 02:02:27 +08:00
|
|
|
json_t **table;
|
|
|
|
int visited;
|
|
|
|
} json_array_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
json_t json;
|
|
|
|
char *value;
|
|
|
|
} json_string_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
json_t json;
|
|
|
|
double value;
|
|
|
|
} json_real_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
json_t json;
|
2010-08-14 03:06:01 +08:00
|
|
|
json_int_t value;
|
2009-10-16 02:02:27 +08:00
|
|
|
} json_integer_t;
|
|
|
|
|
|
|
|
#define json_to_object(json_) container_of(json_, json_object_t, json)
|
|
|
|
#define json_to_array(json_) container_of(json_, json_array_t, json)
|
|
|
|
#define json_to_string(json_) container_of(json_, json_string_t, json)
|
|
|
|
#define json_to_real(json_) container_of(json_, json_real_t, json)
|
|
|
|
#define json_to_integer(json_) container_of(json_, json_integer_t, json)
|
|
|
|
|
2011-01-25 03:45:54 +08:00
|
|
|
size_t jsonp_hash_key(const void *ptr);
|
|
|
|
int jsonp_key_equal(const void *ptr1, const void *ptr2);
|
|
|
|
|
2010-02-10 03:29:33 +08:00
|
|
|
typedef struct {
|
2010-06-15 20:27:35 +08:00
|
|
|
size_t serial;
|
2010-08-13 02:35:19 +08:00
|
|
|
char key[1];
|
2010-02-10 03:29:33 +08:00
|
|
|
} object_key_t;
|
|
|
|
|
|
|
|
const object_key_t *jsonp_object_iter_fullkey(void *iter);
|
|
|
|
|
2010-10-27 04:36:24 +08:00
|
|
|
void jsonp_error_init(json_error_t *error, const char *source);
|
|
|
|
void jsonp_error_set(json_error_t *error, int line, int column,
|
|
|
|
const char *msg, ...);
|
2011-01-24 03:14:19 +08:00
|
|
|
void jsonp_error_vset(json_error_t *error, int line, int column,
|
|
|
|
const char *msg, va_list ap);
|
2010-10-27 04:36:24 +08:00
|
|
|
|
2011-02-17 16:10:53 +08:00
|
|
|
/* Wrappers for custom memory functions */
|
|
|
|
void* jsonp_malloc(size_t size);
|
|
|
|
void jsonp_free(void *ptr);
|
|
|
|
char *jsonp_strdup(const char *str);
|
|
|
|
|
2009-07-14 02:03:09 +08:00
|
|
|
#endif
|