Skip to content

Commit

Permalink
Remove libjson-c dead code
Browse files Browse the repository at this point in the history
As of ClamAV 0.105, libjson-c is required.
There is also no option to disable libjson-c support.

This commit removes the dead code associated with the old build
option.
  • Loading branch information
val-ms committed Apr 13, 2024
1 parent b436105 commit 47dfe9b
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 731 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ include(CPack)

# libclamav efficacy dependencies
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
set(HAVE_LIBSSL 1)
endif()

find_package(ZLIB REQUIRED)

Expand Down Expand Up @@ -489,8 +486,6 @@ else()
set(JSONC_USE_STATIC ON)
endif()
find_package(JSONC REQUIRED)
# Set variable required by libclamav to use libjson-c
set(HAVE_JSON 1)

set(LLVM_MAX_VER "13")
set(LLVM_MIN_VER "8")
Expand Down
10 changes: 0 additions & 10 deletions clamav-config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@
you don't. */
#cmakedefine HAVE_DECL_CYGWIN_CONV_PATH 1

/* Define to 1 if you have a deprecated version of the 'libjson' library
(-ljson). */
#cmakedefine HAVE_DEPRECATED_JSON 1

/* Define to 1 if you have the <dirent.h> header file. */
#cmakedefine HAVE_DIRENT_H 1

Expand Down Expand Up @@ -178,9 +174,6 @@
/* Define to 1 if you have the <inttypes.h> header file (for libjson-c). */
#cmakedefine JSON_C_HAVE_INTTYPES_H 1

/* Define to 1 if you have the 'libjson' library (-ljson). */
#cmakedefine HAVE_JSON 1

/* Define to '1' if you have the check.h library */
#cmakedefine HAVE_LIBCHECK 1

Expand All @@ -190,9 +183,6 @@
/* Define to '1' if you have the curses.h library */
#cmakedefine HAVE_LIBPDCURSES 1

/* Define to 1 if you have the `ssl' library (-lssl). */
#cmakedefine HAVE_LIBSSL 1

/* Define to 1 if you have the <limits.h> header file. */
#cmakedefine HAVE_LIMITS_H 1

Expand Down
3 changes: 0 additions & 3 deletions clamconf/clamconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ int main(int argc, char **argv)

#ifdef HAVE_ICONV
printf("ICONV ");
#endif
#ifdef HAVE_JSON
printf("JSON ");
#endif
if (have_rar)
printf("RAR ");
Expand Down
8 changes: 0 additions & 8 deletions clamd/server-th.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,17 +1377,9 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
options.dev |= CL_SCAN_DEV_COLLECT_SHA;
#endif

#if HAVE_JSON
/* JSON check to prevent engine loading if specified without libjson-c */
if (optget(opts, "GenerateMetadataJson")->enabled)
options.general |= CL_SCAN_GENERAL_COLLECT_METADATA;
#else
if (optget(opts, "GenerateMetadataJson")->enabled) {
logg(LOGG_ERROR, "Can't generate json (gen-json). libjson-c dev library was missing or misconfigured when ClamAV was built.\n");
cl_engine_free(engine);
return 1;
}
#endif

selfchk = optget(opts, "SelfCheck")->numarg;
if (!selfchk) {
Expand Down
10 changes: 0 additions & 10 deletions clamscan/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,18 +1236,8 @@ int scanmanager(const struct optstruct *opts)
}
}

/* JSON check to prevent engine loading if specified without libjson-c */
#if HAVE_JSON
if (optget(opts, "gen-json")->enabled)
options.general |= CL_SCAN_GENERAL_COLLECT_METADATA;
#else
if (optget(opts, "gen-json")->enabled) {
logg(LOGG_ERROR, "Can't generate json (gen-json). libjson-c dev library was missing or misconfigured when ClamAV was built.\n");

ret = 2;
goto done;
}
#endif

if ((opt = optget(opts, "tempdir"))->enabled) {
if ((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) {
Expand Down
5 changes: 0 additions & 5 deletions libclamav/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
#include <assert.h>
#include <fcntl.h>

#if HAVE_JSON
#include "json.h"
#endif

#include "dconf.h"
#include "clamav.h"
#include "others.h"
Expand Down Expand Up @@ -229,11 +226,9 @@ static void bytecode_context_reset(struct cli_bc_ctx *ctx)
/* Use input_switch() to free the extracted file fmap, if one exists */
cli_bcapi_input_switch(ctx, 0);

#if HAVE_JSON
free((json_object **)(ctx->jsonobjs));
ctx->jsonobjs = NULL;
ctx->njsonobjs = 0;
#endif

ctx->containertype = CL_TYPE_ANY;
}
Expand Down
75 changes: 0 additions & 75 deletions libclamav/bytecode_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
#include <math.h>
#include <ctype.h>

#if HAVE_JSON
#include <json.h>
#endif
#include <bzlib.h>

#include "clamav.h"
Expand Down Expand Up @@ -2007,21 +2005,15 @@ int32_t cli_bcapi_get_file_reliability(struct cli_bc_ctx *ctx)

int32_t cli_bcapi_json_is_active(struct cli_bc_ctx *ctx)
{
#if HAVE_JSON
cli_ctx *cctx = (cli_ctx *)ctx->ctx;
if (cctx->properties != NULL) {
return 1;
}
#else
UNUSEDPARAM(ctx);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
#endif
return 0;
}

static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx)
{
#if HAVE_JSON
unsigned n = ctx->njsonobjs + 1;
json_object **j, **jobjs = (json_object **)(ctx->jsonobjs);
cli_ctx *cctx = (cli_ctx *)ctx->ctx;
Expand All @@ -2036,10 +2028,6 @@ static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx)
j[n - 1] = cctx->properties;

return 0;
#else
UNUSEDPARAM(ctx);
return -1;
#endif
}

#define INIT_JSON_OBJS(ctx) \
Expand All @@ -2053,7 +2041,6 @@ static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx)

int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t *name, int32_t name_len, int32_t objid)
{
#if HAVE_JSON
unsigned n;
json_object **j, *jobj, **jobjs;
char *namep;
Expand Down Expand Up @@ -2098,19 +2085,10 @@ int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t *name, in
cli_dbgmsg("bytecode api[json_get_object]: assigned %s => ID %d\n", namep, n - 1);
free(namep);
return n - 1;
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(name);
UNUSEDPARAM(name_len);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return -1;
#endif
}

int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid)
{
#if HAVE_JSON
enum json_type type;
json_object **jobjs;

Expand Down Expand Up @@ -2141,17 +2119,11 @@ int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid)
cli_dbgmsg("bytecode api[json_get_type]: unrecognized json type %d\n", type);
}

#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
#endif
return -1;
}

int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid)
{
#if HAVE_JSON
enum json_type type;
json_object **jobjs;

Expand All @@ -2168,17 +2140,10 @@ int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid)
}

return json_object_array_length(jobjs[objid]);
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return -1;
#endif
}

int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_t objid)
{
#if HAVE_JSON
enum json_type type;
unsigned n;
int length;
Expand Down Expand Up @@ -2223,18 +2188,10 @@ int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_
}

return 0;
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(idx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return -1;
#endif
}

int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid)
{
#if HAVE_JSON
enum json_type type;
json_object *jobj, **jobjs;
int32_t len;
Expand All @@ -2261,17 +2218,10 @@ int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid)
len = strlen(jstr);

return len;
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return -1;
#endif
}

int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t *str, int32_t str_len, int32_t objid)
{
#if HAVE_JSON
enum json_type type;
json_object *jobj, **jobjs;
int32_t len;
Expand Down Expand Up @@ -2308,19 +2258,10 @@ int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t *str, int32_t s
str[len] = '\0';
return len + 1;
}
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(str);
UNUSEDPARAM(str_len);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return -1;
#endif
}

int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid)
{
#if HAVE_JSON
json_object *jobj, **jobjs;

INIT_JSON_OBJS(ctx);
Expand All @@ -2332,17 +2273,10 @@ int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid)

jobj = jobjs[objid];
return json_object_get_boolean(jobj);
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return 0;
#endif
}

int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid)
{
#if HAVE_JSON
json_object *jobj, **jobjs;

INIT_JSON_OBJS(ctx);
Expand All @@ -2354,13 +2288,4 @@ int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid)

jobj = jobjs[objid];
return json_object_get_int(jobj);
#else
UNUSEDPARAM(ctx);
UNUSEDPARAM(objid);
cli_dbgmsg("bytecode api: libjson is not enabled!\n");
return 0;
#endif
}

// int64_t cli_bcapi_json_get_int64(struct cli_bc_ctx *ctx, int32_t objid);
// double cli_bcapi_json_get_double(struct cli_bc_ctx *ctx, int32_t objid);
2 changes: 0 additions & 2 deletions libclamav/bytecode_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ struct cli_bc_ctx {
cli_events_t *bc_events;
int on_jit;
int no_diff;
#if HAVE_JSON
void **jsonobjs;
unsigned njsonobjs;
#endif
};
struct cli_all_bc;
cl_error_t cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst);
Expand Down
Loading

0 comments on commit 47dfe9b

Please sign in to comment.