Skip to content

Commit

Permalink
improved JSON support
Browse files Browse the repository at this point in the history
In order to better interact with other programs,
the Bareos Director console now supports
the ".api json" command, to switch to JSON output.
Currently only a subset of the commands are supported
(the ones required by bareos-webui).

To archieve this, Bareos can be linked against the jansson library.
Other parts of Bareos (output of the configuration options)
now also use the jansson library.
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed May 22, 2015
1 parent 7804e55 commit 4b0a7cf
Show file tree
Hide file tree
Showing 48 changed files with 1,326 additions and 573 deletions.
41 changes: 41 additions & 0 deletions autoconf/configure.in
Expand Up @@ -3077,6 +3077,46 @@ AC_SUBST(FASTLZ_INC)
AC_SUBST(FASTLZ_LIBS)
AC_SUBST(FASTLZ_LIBS_NONSHARED)


dnl
dnl Check for jansson (json library)
dnl
JANSSON_LIBS="-ljansson"
JANSSON_INC=""
have_jansson=no
AC_ARG_WITH(jansson,
AC_HELP_STRING([--with-jansson@<:@=DIR@:>@], [Directory holding jansson includes/libs]),
with_jansson_directory=${withval}
)

if test "x${with_jansson_directory}" != "xyes" && test x"${with_jansson_directory}" != "x"; then
#
# Make sure the $with_jansson_directory also makes sense
#
if test -d "${with_jansson_directory}/lib" -a -d "${with_jansson_directory}/include"; then
have_jansson=yes
JANSSON_INC="-I${with_jansson_directory}/include ${JANSSON_INC}"
JANSSON_LIBS="-L${with_jansson_directory}/lib ${JANSSON_LIBS}"
fi
else
if test x$with_jansson_directory = xyes || test x"${with_jansson_directory}" = "x" && $PKGCONFIG jansson; then
have_jansson=yes
JANSSON_INC=`$PKGCONFIG --cflags janson`
JANSSON_LIBS=`$PKGCONFIG --libs jansson`
fi
fi

if test "x${have_jansson}" = "xyes"; then
AC_DEFINE(HAVE_JANSSON, 1, [Define to 1 if you have jansson lib])
else
JANSSON_LIBS=""
JANSSON_INC=""
fi

AC_SUBST(JANSSON_INC)
AC_SUBST(JANSSON_LIBS)


dnl
dnl Check if we have AFS on this system
dnl
Expand Down Expand Up @@ -4705,6 +4745,7 @@ Configuration on `date`:
ZLIB support: ${have_zlib}
LZO support: ${have_lzo}
FASTLZ support: ${have_fastlz}
JANSSON support: ${have_jansson}
LMDB support: ${support_lmdb}
NDMP support: ${support_ndmp}
enable-smartalloc: ${support_smartalloc}
Expand Down
2 changes: 1 addition & 1 deletion platforms/packaging/bareos-Univention_4.0.dsc
Expand Up @@ -6,7 +6,7 @@ Version: 15.2.0
Maintainer: Joerg Steffens <joerg.steffens@bareos.com>
Homepage: http://www.bareos.org/
Standards-Version: 3.9.4
Build-Depends: acl-dev, autotools-dev, bc, chrpath, debhelper (>= 7.0.50~), dpkg-dev (>= 1.13.19), git-core, libacl1-dev, libcap-dev, libfastlz-dev, liblzo2-dev, libqt4-dev, libreadline-dev, libssl-dev, libwrap0-dev, libx11-dev, libsqlite3-dev, libmysqlclient-dev, libpq-dev (>= 8.4), lsb-release, mtx, ncurses-dev, openssl, pkg-config, po-debconf (>= 0.8.2), python-dev, ucslint, univention-config-dev, zlib1g-dev
Build-Depends: acl-dev, autotools-dev, bc, chrpath, debhelper (>= 7.0.50~), dpkg-dev (>= 1.13.19), git-core, libacl1-dev, libcap-dev, libfastlz-dev, libjansson-dev, liblzo2-dev, libqt4-dev, libreadline-dev, libssl-dev, libwrap0-dev, libx11-dev, libsqlite3-dev, libmysqlclient-dev, libpq-dev (>= 8.4), lsb-release, mtx, ncurses-dev, openssl, pkg-config, po-debconf (>= 0.8.2), python-dev, ucslint, univention-config-dev, zlib1g-dev
Build-Conflicts: python2.2-dev, python2.3, python2.4, qt3-dev-tools
DEBTRANSFORM-RELEASE: 1
Files:
2 changes: 1 addition & 1 deletion platforms/packaging/bareos.dsc
Expand Up @@ -6,7 +6,7 @@ Version: 15.2.0
Maintainer: Joerg Steffens <joerg.steffens@bareos.com>
Homepage: http://www.bareos.org/
Standards-Version: 3.9.4
Build-Depends: acl-dev, autotools-dev, bc, chrpath, debhelper (>= 7.0.50~), dpkg-dev (>= 1.13.19), git-core, libacl1-dev, libcap-dev, libfastlz-dev, liblzo2-dev, libqt4-dev, libreadline-dev, libssl-dev, libwrap0-dev, libx11-dev, libsqlite3-dev, libmysqlclient-dev, libpq-dev, lsb-release, mtx, ncurses-dev, openssl, pkg-config, po-debconf (>= 0.8.2), python-dev, zlib1g-dev, libcmocka-dev
Build-Depends: acl-dev, autotools-dev, bc, chrpath, debhelper (>= 7.0.50~), dpkg-dev (>= 1.13.19), git-core, libacl1-dev, libcap-dev, libcmocka-dev, libfastlz-dev, libjansson-dev, liblzo2-dev, libqt4-dev, libreadline-dev, libssl-dev, libwrap0-dev, libx11-dev, libsqlite3-dev, libmysqlclient-dev, libpq-dev, lsb-release, mtx, ncurses-dev, openssl, pkg-config, po-debconf (>= 0.8.2), python-dev, zlib1g-dev, libcmocka-dev
Build-Conflicts: python2.2-dev, python2.3, python2.4, qt3-dev-tools
DEBTRANSFORM-RELEASE: 1
Files:
2 changes: 2 additions & 0 deletions platforms/packaging/bareos.spec
Expand Up @@ -196,6 +196,7 @@ BuildRequires: update-desktop-files
%if 0%{?suse_version} > 1010
# link identical files
BuildRequires: fdupes
BuildRequires: libjansson-devel
BuildRequires: lsb-release
%endif

Expand Down Expand Up @@ -225,6 +226,7 @@ BuildRequires: fedora-release
%endif

%if 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600 || 0%{?fedora_version} >= 14
BuildRequires: jansson-devel
BuildRequires: tcp_wrappers-devel
%endif

Expand Down
11 changes: 4 additions & 7 deletions src/cats/cats.h
Expand Up @@ -637,9 +637,8 @@ class LIST_CTX {
int32_t num_rows;

e_list_type type; /* Vertical/Horizontal */
DB_LIST_HANDLER *send; /* send data back */
OUTPUT_FORMATTER *send; /* send data back */
bool once; /* Used to print header one time */
void *ctx; /* send() user argument */
B_DB *mdb;
JCR *jcr;

Expand All @@ -650,17 +649,16 @@ class LIST_CTX {

void send_dashes() {
if (*line) {
send(ctx, line);
send->decoration(line);
}
}

LIST_CTX(JCR *j, B_DB *m, DB_LIST_HANDLER *h, void *c, e_list_type t) {
LIST_CTX(JCR *j, B_DB *m, OUTPUT_FORMATTER *h, e_list_type t) {
line[0] = '\0';
once = false;
num_rows = 0;
type = t;
send = h;
ctx = c;
jcr = j;
mdb = m;
}
Expand All @@ -670,8 +668,7 @@ class LIST_CTX {
* Some functions exported by sql.c for use within the cats directory.
*/
int list_result(void *vctx, int cols, char **row);
int list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type);
void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx);
int list_result(JCR *jcr, B_DB *mdb, OUTPUT_FORMATTER *send, e_list_type type);
int get_sql_record_max(JCR *jcr, B_DB *mdb);
bool check_tables_version(JCR *jcr, B_DB *mdb);
bool db_check_max_connections(JCR *jcr, B_DB *mdb, uint32_t nb);
Expand Down
22 changes: 11 additions & 11 deletions src/cats/protos.h
Expand Up @@ -118,17 +118,17 @@ int db_get_ndmp_level_mapping(JCR *jcr, B_DB *mdb, JOB_DBR *jr, char *filesystem
bool db_get_ndmp_environment_string(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_RESULT_HANDLER *result_handler, void *ctx);

/* sql_list.c */
void db_list_pool_records(JCR *jcr, B_DB *db, POOL_DBR *pr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
void db_list_job_records(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx);
void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx);
void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, bool verbose, e_list_type type);
void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx);
void db_list_pool_records(JCR *jcr, B_DB *db, POOL_DBR *pr, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_job_records(JCR *jcr, B_DB *db, JOB_DBR *jr, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr, OUTPUT_FORMATTER *sendit);
void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, OUTPUT_FORMATTER *sendit);
void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type);
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, OUTPUT_FORMATTER *sendit, bool verbose, e_list_type type);
void db_list_client_records(JCR *jcr, B_DB *mdb, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, OUTPUT_FORMATTER *sendit);

/* sql_pooling.c */
bool db_sql_pool_initialize(const char *db_drivername,
Expand Down

0 comments on commit 4b0a7cf

Please sign in to comment.