libclamav/json_api.h
9fdbf2c7
 /*
  * JSON Object API
557c712c
  *
e1cbc270
  * Copyright (C) 2014-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
557c712c
  *
9fdbf2c7
  * Authors: Kevin Lin
557c712c
  *
9fdbf2c7
  * This program is free software; you can redistribute it and/or modify it under
  * the terms of the GNU General Public License version 2 as published by the
  * Free Software Foundation.
557c712c
  *
9fdbf2c7
  * This program is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
557c712c
  *
9fdbf2c7
  * You should have received a copy of the GNU General Public License along with
  * this program; if not, write to the Free Software Foundation, Inc., 51
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifndef __JSON_C_H__
 #define __JSON_C_H__
 
 #if HAVE_CONFIG_H
 #include "clamav-config.h"
 #endif
 
2a3d247b
 #if HAVE_JSON
e182c02c
 #include "json.h"
2a3d247b
 #endif
 
e030ba4f
 #include "clamav-types.h"
9fdbf2c7
 #include "others.h"
 
2a3d247b
 #if HAVE_JSON
8c338ea9
 #define JSON_TIMEOUT_SKIP_CYCLES 3
20b45621
 
557c712c
 cl_error_t cli_json_timeout_cycle_check(cli_ctx *ctx, int *toval);
 cl_error_t cli_json_parse_error(json_object *root, const char *errstr);
20b45621
 
557c712c
 cl_error_t cli_jsonnull(json_object *obj, const char *key);
 cl_error_t cli_jsonstr(json_object *obj, const char *key, const char *s);
 cl_error_t cli_jsonstrlen(json_object *obj, const char *key, const char *s, int len);
 cl_error_t cli_jsonint(json_object *obj, const char *key, int32_t i);
 cl_error_t cli_jsonint64(json_object *obj, const char *key, int64_t i);
 cl_error_t cli_jsonbool(json_object *obj, const char *key, int i);
 cl_error_t cli_jsondouble(json_object *obj, const char *key, double d);
8e586053
 
d7ee9b81
 json_object *cli_jsonarray(json_object *obj, const char *key);
557c712c
 cl_error_t cli_jsonint_array(json_object *obj, int32_t val);
d7ee9b81
 json_object *cli_jsonobj(json_object *obj, const char *key);
557c712c
 cl_error_t cli_json_addowner(json_object *owner, json_object *child, const char *key, int idx);
 cl_error_t cli_json_delowner(json_object *owner, const char *key, int idx);
288057e9
 #define cli_json_delobj(obj) json_object_put(obj)
6a16a828
 
060a57d2
 #if HAVE_DEPRECATED_JSON
 int json_object_object_get_ex(struct json_object *obj, const char *key, struct json_object **value);
 #endif
 
288057e9
 #define JSON_KEY_FILETYPE "FileType"
 #define JSON_KEY_FILESIZE "FileSize"
6a16a828
 
288057e9
 #define JSON_VALUE_FILETYPE_PDF "CL_TYPE_PDF"
 #define JSON_VALUE_FILETYPE_PPT "CL_TYPE_MSPPT"
 #define JSON_VALUE_FILETYPE_WORD "CL_TYPE_WORD"
 #define JSON_VALUE_FILETYPE_EXCEL "CL_TYPE_MSXLS"
6a16a828
 
9fdbf2c7
 #else
a69adec1
 #define nojson_func cli_dbgmsg
 
 /* internal functions */
557c712c
 cl_error_t cli_json_nojson(void);
 
 cl_error_t cli_jsonnull_nojson(const char* key);
 cl_error_t cli_jsonstr_nojson(const char* key, const char* s);
 cl_error_t cli_jsonstrlen_nojson(const char* key, const char* s, int len);
 cl_error_t cli_jsonint_nojson(const char* key, int32_t i);
 cl_error_t cli_jsonint64_nojson(const char* key, int64_t i);
 cl_error_t cli_jsonbool_nojson(const char* key, int i);
 cl_error_t cli_jsondouble_nojson(const char* key, double d);
288057e9
 void* cli_jsonarray_nojson(const char* key);
557c712c
 cl_error_t cli_jsonint_array_nojson(int32_t val);
a69adec1
 
288057e9
 #define cli_jsonnull(o, n) cli_jsonnull_nojson(n)
 #define cli_jsonstr(o, n, s) cli_jsonstr_nojson(n, s)
 #define cli_jsonstrlen(o, n, s, len) cli_jsonstrlen_nojson(n, s, len)
 #define cli_jsonint(o, n, i) cli_jsonint_nojson(n, i)
 #define cli_jsonint64(o, n, i) cli_jsonint64_nojson(n, i)
 #define cli_jsonbool(o, n, b) cli_jsonbool_nojson(n, b)
 #define cli_jsondouble(o, n, d) cli_jsondouble_nojson(n, d)
 #define cli_jsonarray(o, k) cli_jsonarray_nojson(k)
 #define cli_jsonint_array(o, v) cli_jsonint_array_nojson(v)
 #define cli_json_addowner(o, c, k, i) cli_json_nojson()
 #define cli_json_delowner(o, k, i) cli_json_nojson()
 #define cli_json_delobj(o) cli_json_nojson()
8e586053
 
9fdbf2c7
 #endif
 
 #endif /*__JSON_C_H__*/