Blame json_pointer.h

Packit Service def718
/*
Packit Service def718
 * Copyright (c) 2016 Alexadru Ardelean.
Packit Service def718
 *
Packit Service def718
 * This 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 JSON Pointer (RFC 6901) implementation for retrieving
Packit Service def718
 *        objects from a json-c object tree.
Packit Service def718
 */
Packit Service def718
#ifndef _json_pointer_h_
Packit Service def718
#define _json_pointer_h_
Packit Service def718
Packit Service def718
#include "json_object.h"
Packit Service def718
Packit Service def718
#ifdef __cplusplus
Packit Service def718
extern "C" {
Packit Service def718
#endif
Packit Service def718
Packit Service def718
/**
Packit Service def718
 * Retrieves a JSON sub-object from inside another JSON object
Packit Service def718
 * using the JSON pointer notation as defined in RFC 6901
Packit Service def718
 *   https://tools.ietf.org/html/rfc6901
Packit Service def718
 *
Packit Service def718
 * The returned JSON sub-object is equivalent to parsing manually the
Packit Service def718
 * 'obj' JSON tree ; i.e. it's not a new object that is created, but rather
Packit Service def718
 * a pointer inside the JSON tree.
Packit Service def718
 *
Packit Service def718
 * Internally, this is equivalent to doing a series of 'json_object_object_get()'
Packit Service def718
 * and 'json_object_array_get_idx()' along the given 'path'.
Packit Service def718
 *
Packit Service def718
 * Note that the 'path' string supports 'printf()' type arguments, so, whatever
Packit Service def718
 * is added after the 'res' param will be treated as an argument for 'path'
Packit Service def718
 * Example: json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar)
Packit Service def718
 * This means, that you need to escape '%' with '%%' (just like in printf())
Packit Service def718
 *
Packit Service def718
 * @param obj the json_object instance/tree from where to retrieve sub-objects
Packit Service def718
 * @param path a (RFC6901) string notation for the sub-object to retrieve
Packit Service def718
 * @param res a pointer where to store a reference to the json_object
Packit Service def718
 *              associated with the given path
Packit Service def718
 *
Packit Service def718
 * @return negative if an error (or not found), or 0 if succeeded
Packit Service def718
 */
Packit Service def718
int json_pointer_get(struct json_object *obj, const char *path, struct json_object **res);
Packit Service def718
Packit Service def718
/**
Packit Service def718
 * This is a variant of 'json_pointer_get()' that supports printf() style arguments.
Packit Service def718
 *
Packit Service def718
 * Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, bak)
Packit Service def718
 * This also means that you need to escape '%' with '%%' (just like in printf())
Packit Service def718
 *
Packit Service def718
 * Please take into consideration all recommended 'printf()' format security
Packit Service def718
 * aspects when using this function.
Packit Service def718
 *
Packit Service def718
 * @param obj the json_object instance/tree to which to add a sub-object
Packit Service def718
 * @param res a pointer where to store a reference to the json_object
Packit Service def718
 *              associated with the given path
Packit Service def718
 * @param path_fmt a printf() style format for the path
Packit Service def718
 *
Packit Service def718
 * @return negative if an error (or not found), or 0 if succeeded
Packit Service def718
 */
Packit Service def718
int json_pointer_getf(struct json_object *obj, struct json_object **res, const char *path_fmt, ...);
Packit Service def718
Packit Service def718
/**
Packit Service def718
 * Sets JSON object 'value' in the 'obj' tree at the location specified
Packit Service def718
 * by the 'path'. 'path' is JSON pointer notation as defined in RFC 6901
Packit Service def718
 *   https://tools.ietf.org/html/rfc6901
Packit Service def718
 *
Packit Service def718
 * Note that 'obj' is a double pointer, mostly for the "" (empty string)
Packit Service def718
 * case, where the entire JSON object would be replaced by 'value'.
Packit Service def718
 * In the case of the "" path, the object at '*obj' will have it's refcount
Packit Service def718
 * decremented with 'json_object_put()' and the 'value' object will be assigned to it.
Packit Service def718
 *
Packit Service def718
 * For other cases (JSON sub-objects) ownership of 'value' will be transferred into
Packit Service def718
 * '*obj' via 'json_object_object_add()' & 'json_object_array_put_idx()', so the
Packit Service def718
 * only time the refcount should be decremented for 'value' is when the return value of
Packit Service def718
 * 'json_pointer_set()' is negative (meaning the 'value' object did not get set into '*obj').
Packit Service def718
 *
Packit Service def718
 * That also implies that 'json_pointer_set()' does not do any refcount incrementing.
Packit Service def718
 * (Just that single decrement that was mentioned above).
Packit Service def718
 *
Packit Service def718
 * Note that the 'path' string supports 'printf()' type arguments, so, whatever
Packit Service def718
 * is added after the 'value' param will be treated as an argument for 'path'
Packit Service def718
 * Example: json_pointer_set(obj, "/foo/%d/%s", value, 0, bak)
Packit Service def718
 * This means, that you need to escape '%' with '%%' (just like in printf())
Packit Service def718
 *
Packit Service def718
 * @param obj the json_object instance/tree to which to add a sub-object
Packit Service def718
 * @param path a (RFC6901) string notation for the sub-object to set in the tree
Packit Service def718
 * @param value object to set at path
Packit Service def718
 *
Packit Service def718
 * @return negative if an error (or not found), or 0 if succeeded
Packit Service def718
 */
Packit Service def718
int json_pointer_set(struct json_object **obj, const char *path, struct json_object *value);
Packit Service def718
Packit Service def718
/**
Packit Service def718
 * This is a variant of 'json_pointer_set()' that supports printf() style arguments.
Packit Service def718
 *
Packit Service def718
 * Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, bak)
Packit Service def718
 * This also means that you need to escape '%' with '%%' (just like in printf())
Packit Service def718
 *
Packit Service def718
 * Please take into consideration all recommended 'printf()' format security
Packit Service def718
 * aspects when using this function.
Packit Service def718
 *
Packit Service def718
 * @param obj the json_object instance/tree to which to add a sub-object
Packit Service def718
 * @param value object to set at path
Packit Service def718
 * @param path_fmt a printf() style format for the path
Packit Service def718
 *
Packit Service def718
 * @return negative if an error (or not found), or 0 if succeeded
Packit Service def718
 */
Packit Service def718
int json_pointer_setf(struct json_object **obj, struct json_object *value, const char *path_fmt, ...);
Packit Service def718
Packit Service def718
Packit Service def718
#ifdef __cplusplus
Packit Service def718
}
Packit Service def718
#endif
Packit Service def718
Packit Service def718
#endif