Commit 402375ec authored by vvaltman's avatar vvaltman

added json support

parent 76aec0bf
......@@ -19,7 +19,7 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto
EXE_LIST=${EXE}/telegram-cli
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o ${OBJ}/json-tg.o
INCLUDE=-I. -I${srcdir} -I${srcdir}/tgl
CC=@CC@
......
......@@ -36,6 +36,9 @@
/* Define to 1 if you have the `event' library (-levent). */
#undef HAVE_LIBEVENT
/* Define to 1 if you have the `jansson' library (-ljansson). */
#undef HAVE_LIBJANSSON
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
......@@ -155,6 +158,9 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* use json */
#undef USE_JSON
/* use lua */
#undef USE_LUA
......
......@@ -694,6 +694,7 @@ with_zlib
enable_libconfig
enable_extf
enable_liblua
enable_json
with_progname
enable_valgrind
'
......@@ -1321,6 +1322,7 @@ Optional Features:
--enable-libconfig/--disable-libconfig
--enable-extf/--disable-extf
--enable-liblua/--disable-liblua
--enable-json/--disable-json
--enable-valgrind/--disable-valgrind
Optional Packages:
......@@ -5865,7 +5867,130 @@ fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libjansson" >&5
$as_echo_n "checking for libjansson... " >&6; }
# Check whether --enable-json was given.
if test "${enable_json+set}" = set; then :
enableval=$enable_json;
if test "x$enableval" = "xno" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
$as_echo "disabled" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled" >&5
$as_echo "enabled" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for json_array_set_new in -ljansson" >&5
$as_echo_n "checking for json_array_set_new in -ljansson... " >&6; }
if ${ac_cv_lib_jansson_json_array_set_new+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-ljansson $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char json_array_set_new ();
int
main ()
{
return json_array_set_new ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_jansson_json_array_set_new=yes
else
ac_cv_lib_jansson_json_array_set_new=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jansson_json_array_set_new" >&5
$as_echo "$ac_cv_lib_jansson_json_array_set_new" >&6; }
if test "x$ac_cv_lib_jansson_json_array_set_new" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBJANSSON 1
_ACEOF
LIBS="-ljansson $LIBS"
else
as_fn_error $? "No libjansson found. Try --disable-json" "$LINENO" 5
fi
$as_echo "#define USE_JSON 1" >>confdefs.h
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled" >&5
$as_echo "enabled" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for json_array_set_new in -ljansson" >&5
$as_echo_n "checking for json_array_set_new in -ljansson... " >&6; }
if ${ac_cv_lib_jansson_json_array_set_new+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-ljansson $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char json_array_set_new ();
int
main ()
{
return json_array_set_new ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_jansson_json_array_set_new=yes
else
ac_cv_lib_jansson_json_array_set_new=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jansson_json_array_set_new" >&5
$as_echo "$ac_cv_lib_jansson_json_array_set_new" >&6; }
if test "x$ac_cv_lib_jansson_json_array_set_new" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBJANSSON 1
_ACEOF
LIBS="-ljansson $LIBS"
else
as_fn_error $? "No libjansson found. Try --disable-json" "$LINENO" 5
fi
$as_echo "#define USE_JSON 1" >>confdefs.h
fi
#check for custom prog name
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking progname" >&5
$as_echo_n "checking progname... " >&6; }
# Check whether --with-progname was given.
if test "${with_progname+set}" = set; then :
......
......@@ -94,7 +94,24 @@ AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
])
])
AC_MSG_CHECKING([for libjansson])
AC_ARG_ENABLE(json,[--enable-json/--disable-json],
[
if test "x$enableval" = "xno" ; then
AC_MSG_RESULT([disabled])
else
AC_MSG_RESULT([enabled])
AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json]))
AC_DEFINE(USE_JSON,1,[use json])
fi
],[
AC_MSG_RESULT([enabled])
AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json]))
AC_DEFINE(USE_JSON,1,[use json])
])
#check for custom prog name
AC_MSG_CHECKING([progname])
AC_ARG_WITH(progname,[--with-progname=<name>],
[
if test "x$with_progname" = "xno" ; then
......
This diff is collapsed.
This diff is collapsed.
#ifndef __JSON_TG_H__
#define __JSON_TG_H__
#include "config.h"
#ifdef USE_JSON
#include <jansson.h>
#include <tgl.h>
#include <tgl-layout.h>
json_t *json_pack_message (struct tgl_message *M);
json_t *json_pack_updates (unsigned flags);
json_t *json_pack_peer (tgl_peer_id_t id, tgl_peer_t *P);
#endif
#endif
......@@ -120,6 +120,7 @@ int use_ids;
int ipv6_enabled;
char *start_command;
int disable_link_preview;
int enable_json;
struct tgl_state *TLS;
......@@ -480,7 +481,9 @@ void usage (void) {
printf (" --help/-h prints this help\n");
printf (" --accept-any-tcp accepts tcp connections from any src (only loopback by default)\n");
printf (" --disable-link-preview disables server-side previews to links\n");
#ifdef USE_JSON
printf (" --json prints answers and values in json format\n");
#endif
exit (1);
}
......@@ -625,6 +628,7 @@ void args_parse (int argc, char **argv) {
{"help", no_argument, 0, 'h'},
{"accept-any-tcp", no_argument, 0, 1001},
{"disable-link-preview", no_argument, 0, 1002},
{"json", no_argument, 0, 1003},
{0, 0, 0, 0 }
};
......@@ -738,6 +742,9 @@ void args_parse (int argc, char **argv) {
case 1002:
disable_link_preview = 2;
break;
case 1003:
enable_json = 1;
break;
case 'h':
default:
usage ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment