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 ...@@ -19,7 +19,7 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto
EXE_LIST=${EXE}/telegram-cli 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 INCLUDE=-I. -I${srcdir} -I${srcdir}/tgl
CC=@CC@ CC=@CC@
......
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
/* Define to 1 if you have the `event' library (-levent). */ /* Define to 1 if you have the `event' library (-levent). */
#undef HAVE_LIBEVENT #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). */ /* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM #undef HAVE_LIBM
...@@ -155,6 +158,9 @@ ...@@ -155,6 +158,9 @@
/* Define to 1 if you have the ANSI C header files. */ /* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS #undef STDC_HEADERS
/* use json */
#undef USE_JSON
/* use lua */ /* use lua */
#undef USE_LUA #undef USE_LUA
......
...@@ -694,6 +694,7 @@ with_zlib ...@@ -694,6 +694,7 @@ with_zlib
enable_libconfig enable_libconfig
enable_extf enable_extf
enable_liblua enable_liblua
enable_json
with_progname with_progname
enable_valgrind enable_valgrind
' '
...@@ -1321,6 +1322,7 @@ Optional Features: ...@@ -1321,6 +1322,7 @@ Optional Features:
--enable-libconfig/--disable-libconfig --enable-libconfig/--disable-libconfig
--enable-extf/--disable-extf --enable-extf/--disable-extf
--enable-liblua/--disable-liblua --enable-liblua/--disable-liblua
--enable-json/--disable-json
--enable-valgrind/--disable-valgrind --enable-valgrind/--disable-valgrind
Optional Packages: Optional Packages:
...@@ -5865,7 +5867,130 @@ fi ...@@ -5865,7 +5867,130 @@ fi
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 #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. # Check whether --with-progname was given.
if test "${with_progname+set}" = set; then : if test "${with_progname+set}" = set; then :
......
...@@ -94,7 +94,24 @@ AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua], ...@@ -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 #check for custom prog name
AC_MSG_CHECKING([progname])
AC_ARG_WITH(progname,[--with-progname=<name>], AC_ARG_WITH(progname,[--with-progname=<name>],
[ [
if test "x$with_progname" = "xno" ; then 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; ...@@ -120,6 +120,7 @@ int use_ids;
int ipv6_enabled; int ipv6_enabled;
char *start_command; char *start_command;
int disable_link_preview; int disable_link_preview;
int enable_json;
struct tgl_state *TLS; struct tgl_state *TLS;
...@@ -480,7 +481,9 @@ void usage (void) { ...@@ -480,7 +481,9 @@ void usage (void) {
printf (" --help/-h prints this help\n"); printf (" --help/-h prints this help\n");
printf (" --accept-any-tcp accepts tcp connections from any src (only loopback by default)\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"); 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); exit (1);
} }
...@@ -625,6 +628,7 @@ void args_parse (int argc, char **argv) { ...@@ -625,6 +628,7 @@ void args_parse (int argc, char **argv) {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"accept-any-tcp", no_argument, 0, 1001}, {"accept-any-tcp", no_argument, 0, 1001},
{"disable-link-preview", no_argument, 0, 1002}, {"disable-link-preview", no_argument, 0, 1002},
{"json", no_argument, 0, 1003},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
...@@ -738,6 +742,9 @@ void args_parse (int argc, char **argv) { ...@@ -738,6 +742,9 @@ void args_parse (int argc, char **argv) {
case 1002: case 1002:
disable_link_preview = 2; disable_link_preview = 2;
break; break;
case 1003:
enable_json = 1;
break;
case 'h': case 'h':
default: default:
usage (); 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