|
Packit Service |
def718 |
/*
|
|
Packit Service |
def718 |
* $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
|
|
Packit Service |
def718 |
* Michael Clark <michael@metaparadigm.com>
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* This library is free software; you can redistribute it and/or modify
|
|
Packit Service |
def718 |
* it under the terms of the MIT license. See COPYING for details.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* @file
|
|
Packit Service |
def718 |
* @brief Miscllaneous utility functions and macros.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
#ifndef _json_util_h_
|
|
Packit Service |
def718 |
#define _json_util_h_
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#include "json_object.h"
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifndef json_min
|
|
Packit Service |
def718 |
#define json_min(a,b) ((a) < (b) ? (a) : (b))
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifndef json_max
|
|
Packit Service |
def718 |
#define json_max(a,b) ((a) > (b) ? (a) : (b))
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifdef __cplusplus
|
|
Packit Service |
def718 |
extern "C" {
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#define JSON_FILE_BUF_SIZE 4096
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/* utility functions */
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Read the full contents of the given file, then convert it to a
|
|
Packit Service |
def718 |
* json_object using json_tokener_parse().
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern struct json_object* json_object_from_file(const char *filename);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Create a JSON object from already opened file descriptor.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* This function can be helpful, when you opened the file already,
|
|
Packit Service |
def718 |
* e.g. when you have a temp file.
|
|
Packit Service |
def718 |
* Note, that the fd must be readable at the actual position, i.e.
|
|
Packit Service |
def718 |
* use lseek(fd, 0, SEEK_SET) before.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern struct json_object* json_object_from_fd(int fd);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Equivalent to:
|
|
Packit Service |
def718 |
* json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN);
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern int json_object_to_file(const char *filename, struct json_object *obj);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Open and truncate the given file, creating it if necessary, then
|
|
Packit Service |
def718 |
* convert the json_object to a string and write it to the file.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Convert the json_object to a string and write it to the file descriptor.
|
|
Packit Service |
def718 |
* Handles partial writes and will keep writing until done, or an error
|
|
Packit Service |
def718 |
* occurs.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param fd an open, writable file descriptor to write to
|
|
Packit Service |
def718 |
* @param obj the object to serializer and write
|
|
Packit Service |
def718 |
* @param flags flags to pass to json_object_to_json_string_ext()
|
|
Packit Service |
def718 |
* @return -1 if something fails. See json_util_get_last_err() for details.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern int json_object_to_fd(int fd, struct json_object *obj, int flags);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Return the last error from various json-c functions, including:
|
|
Packit Service |
def718 |
* json_object_to_file{,_ext}, json_object_to_fd() or
|
|
Packit Service |
def718 |
* json_object_from_{file,fd}, or NULL if there is none.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
const char *json_util_get_last_err(void);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
extern int json_parse_int64(const char *buf, int64_t *retval);
|
|
Packit Service |
def718 |
extern int json_parse_double(const char *buf, double *retval);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Return a string describing the type of the object.
|
|
Packit Service |
def718 |
* e.g. "int", or "object", etc...
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
extern const char *json_type_to_name(enum json_type o_type);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifdef __cplusplus
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#endif
|