mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-21 06:35:04 +08:00
use system jansson if available
This commit is contained in:
parent
0653feaec8
commit
9d97962759
10 changed files with 158 additions and 16 deletions
|
@ -11,6 +11,8 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
|
|||
- Add `make check` mechanics (@doegox)
|
||||
- Change, log files moved to subfolders (@doegox)
|
||||
- Change, use system Lua library if available (@doegox)
|
||||
- Change, use system Jansson library if available (@doegox)
|
||||
- Change, use system Whereami library if available (@doegox)
|
||||
- Fix release version information (@doegox)
|
||||
|
||||
## [ice coffee.4.9237][2020-05-21]
|
||||
|
|
|
@ -165,6 +165,7 @@ set (TARGET_SOURCES
|
|||
src/fileutils.c
|
||||
src/flash.c
|
||||
src/graph.c
|
||||
src/jansson_path.c
|
||||
src/preferences.c
|
||||
src/pm3_binlib.c
|
||||
src/pm3_bitlib.c
|
||||
|
|
|
@ -82,17 +82,27 @@ ZLIB = $(OBJDIR)/libz.a
|
|||
ifneq ($(SKIPLUASYSTEM),1)
|
||||
LUAINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags lua5.2 2>/dev/null)
|
||||
LUALDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs lua5.2 2>/dev/null)
|
||||
ifneq ($(LUAINCLUDES),)
|
||||
ifneq ($(LUALDLIBS),)
|
||||
LUALIB = $(LUALDLIBS)
|
||||
LUALIBINC = $(LUAINCLUDES)
|
||||
LUASYSTEM = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(SKIPJANSSONSYSTEM),1)
|
||||
JANSSONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags jansson 2>/dev/null)
|
||||
JANSSONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs jansson 2>/dev/null)
|
||||
ifneq ($(JANSSONLDLIBS),)
|
||||
JANSSONLIB = $(JANSSONLDLIBS)
|
||||
JANSSONLIBINC = $(JANSSONINCLUDES)
|
||||
JANSSONSYSTEM = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(SKIPWHEREAMISYSTEM),1)
|
||||
ifneq (,$(wildcard /usr/include/whereami.h))
|
||||
WAILIBINC =
|
||||
WAILIB = -lwhereami
|
||||
WAILIBINC =
|
||||
WAISYSTEM = 1
|
||||
endif
|
||||
endif
|
||||
|
@ -195,6 +205,9 @@ $(info native BT support: Bluez found, enabled)
|
|||
else
|
||||
$(info native BT support: Bluez not found, disabled)
|
||||
endif
|
||||
ifeq ($(JANSSONSYSTEM),1)
|
||||
$(info Jansson library: system library found)
|
||||
endif
|
||||
ifeq ($(LUASYSTEM),1)
|
||||
$(info Lua library: system library found)
|
||||
endif
|
||||
|
@ -339,9 +352,8 @@ CMDSRCS = crapto1/crapto1.c \
|
|||
wiegand_formats.c \
|
||||
wiegand_formatutils.c \
|
||||
cardhelper.c \
|
||||
preferences.c
|
||||
|
||||
|
||||
preferences.c \
|
||||
jansson_path.c
|
||||
|
||||
COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
|
||||
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
|
||||
|
@ -430,8 +442,10 @@ ifneq ($(LUASYSTEM),1)
|
|||
endif
|
||||
|
||||
jansson:
|
||||
ifneq ($(JANSSONSYSTEM),1)
|
||||
$(info [*] MAKE $@)
|
||||
$(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) all
|
||||
endif
|
||||
|
||||
tinycbor:
|
||||
$(info [*] MAKE $@)
|
||||
|
|
|
@ -145,6 +145,7 @@ add_library(pm3rrg_rdv4 SHARED
|
|||
${PM3_ROOT}/client/src/cmdlfpcf7931.c
|
||||
${PM3_ROOT}/client/src/cmdhfmfhard.c
|
||||
${PM3_ROOT}/client/src/cmdusart.c
|
||||
${PM3_ROOT}/client/src/jansson_path.c
|
||||
# android resources
|
||||
jni_tools.c
|
||||
pm3_main.c
|
||||
|
|
|
@ -9,7 +9,6 @@ add_library(pm3rrg_rdv4_jansson STATIC
|
|||
jansson/strbuffer.c
|
||||
jansson/strconv.c
|
||||
jansson/utf.c
|
||||
jansson/path.c
|
||||
jansson/value.c
|
||||
)
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ MYSRCS = \
|
|||
strbuffer.c \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
path.c \
|
||||
value.c
|
||||
|
||||
LIB_A = libjansson.a
|
||||
|
|
|
@ -302,14 +302,6 @@ int json_equal(const json_t *json1, const json_t *json2);
|
|||
json_t *json_copy(json_t *json) JANSSON_ATTRS(warn_unused_result);
|
||||
json_t *json_deep_copy(const json_t *json) JANSSON_ATTRS(warn_unused_result);
|
||||
|
||||
json_t *json_path_get(const json_t *json, const char *path);
|
||||
int json_path_set_new(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_path_set(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error) {
|
||||
return json_path_set_new(json, path, json_incref(value), flags, error);
|
||||
}
|
||||
|
||||
/* decoding */
|
||||
|
||||
#define JSON_REJECT_DUPLICATES 0x1
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "common.h"
|
||||
|
||||
#include "jansson.h"
|
||||
#include "jansson_path.h"
|
||||
#include "tlv.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -11,7 +11,110 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "jansson.h"
|
||||
#include "jansson_private.h"
|
||||
#include "jansson_path.h"
|
||||
|
||||
////// memory.c private functions
|
||||
|
||||
/* C89 allows these to be macros */
|
||||
#undef malloc
|
||||
#undef free
|
||||
|
||||
/* memory function pointers */
|
||||
static json_malloc_t do_malloc = malloc;
|
||||
static json_free_t do_free = free;
|
||||
|
||||
static void *jsonp_malloc(size_t size) {
|
||||
if (!size)
|
||||
return NULL;
|
||||
|
||||
return (*do_malloc)(size);
|
||||
}
|
||||
|
||||
static void jsonp_free(void *ptr) {
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
(*do_free)(ptr);
|
||||
}
|
||||
|
||||
static char *jsonp_strndup(const char *str, size_t len) {
|
||||
char *new_str;
|
||||
|
||||
new_str = jsonp_malloc(len + 1);
|
||||
if (!new_str)
|
||||
return NULL;
|
||||
|
||||
memcpy(new_str, str, len);
|
||||
new_str[len] = '\0';
|
||||
return new_str;
|
||||
}
|
||||
|
||||
static char *jsonp_strdup(const char *str) {
|
||||
return jsonp_strndup(str, strlen(str));
|
||||
}
|
||||
|
||||
////// error.c private functions
|
||||
|
||||
static void jsonp_error_set_source(json_error_t *error, const char *source) {
|
||||
size_t length;
|
||||
|
||||
if (!error || !source)
|
||||
return;
|
||||
|
||||
length = strlen(source);
|
||||
if (length < JSON_ERROR_SOURCE_LENGTH) {
|
||||
strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH - 1);
|
||||
} else {
|
||||
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
|
||||
memcpy(error->source, "...", 3);
|
||||
strncpy(error->source + 3, source + extra, length - extra + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void jsonp_error_init(json_error_t *error, const char *source) {
|
||||
if (error) {
|
||||
error->text[0] = '\0';
|
||||
error->line = -1;
|
||||
error->column = -1;
|
||||
error->position = 0;
|
||||
if (source)
|
||||
jsonp_error_set_source(error, source);
|
||||
else
|
||||
error->source[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void jsonp_error_vset(json_error_t *error, int line, int column,
|
||||
size_t position, enum json_error_code code,
|
||||
const char *msg, va_list ap) {
|
||||
if (!error)
|
||||
return;
|
||||
|
||||
if (error->text[0] != '\0') {
|
||||
/* error already set */
|
||||
return;
|
||||
}
|
||||
|
||||
error->line = line;
|
||||
error->column = column;
|
||||
error->position = (int)position;
|
||||
|
||||
vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH - 1, msg, ap);
|
||||
error->text[JSON_ERROR_TEXT_LENGTH - 2] = '\0';
|
||||
error->text[JSON_ERROR_TEXT_LENGTH - 1] = code;
|
||||
}
|
||||
|
||||
static void jsonp_error_set(json_error_t *error, int line, int column,
|
||||
size_t position, enum json_error_code code,
|
||||
const char *msg, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
jsonp_error_vset(error, line, column, position, code, msg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
// original path.c from jansson fork
|
||||
|
||||
json_t *json_path_get(const json_t *json, const char *path) {
|
||||
static const char root_chr = '$', array_open = '[';
|
30
client/src/jansson_path.h
Normal file
30
client/src/jansson_path.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef JANSSON_PATH_H
|
||||
#define JANSSON_PATH_H
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <stdlib.h> /* for size_t */
|
||||
//#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
json_t *json_path_get(const json_t *json, const char *path);
|
||||
int json_path_set_new(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_path_set(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error) {
|
||||
return json_path_set_new(json, path, json_incref(value), flags, error);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in a new issue