diff --git a/config.h.in b/config.h.in index a753380..9c1f275 100644 --- a/config.h.in +++ b/config.h.in @@ -1,5 +1,11 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* Use libevent v1 */ +#undef EVENT_V1 + +/* Use libevent v2 */ +#undef EVENT_V2 + /* Define to 1 if you have the `alarm' function. */ #undef HAVE_ALARM @@ -24,9 +30,6 @@ /* Define to 1 if you have the `config' library (-lconfig). */ #undef HAVE_LIBCONFIG -/* Define to 1 if you have the `edit' library (-ledit). */ -#undef HAVE_LIBEDIT - /* Define to 1 if you have the `event' library (-levent). */ #undef HAVE_LIBEVENT @@ -143,12 +146,6 @@ /* Use custom prog name */ #undef PROG_NAME -/* Use libedit */ -#undef READLINE_EDIT - -/* Use gnu libreadline */ -#undef READLINE_GNU - /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS diff --git a/configure b/configure index 1393f6e..522bc71 100755 --- a/configure +++ b/configure @@ -634,13 +634,13 @@ LUA_PLATFORM LUA_SHORT_VERSION LUA_VERSION LUA -EGREP -GREP -CPP OPENSSL_LDFLAGS OPENSSL_LIBS OPENSSL_INCLUDES PKG_CONFIG +EGREP +GREP +CPP OBJEXT EXEEXT ac_ct_CC @@ -3535,162 +3535,8 @@ else as_fn_error $? "no libevent found" "$LINENO" 5 fi -EXTRA_LIBS="" - -# OPENSSL_INCLUDES to the include directives required -# OPENSSL_LIBS to the -l directives required -# OPENSSL_LDFLAGS to the -L or -R flags required - - - found=false - -# Check whether --with-openssl was given. -if test "${with_openssl+set}" = set; then : - withval=$with_openssl; - case "$withval" in - "" | y | ye | yes | n | no) - as_fn_error $? "Invalid --with-openssl value" "$LINENO" 5 - ;; - *) ssldirs="$withval" - ;; - esac - -else - - # if pkg-config is installed and openssl has installed a .pc file, - # then use that information and don't search ssldirs - # Extract the first word of "pkg-config", so it can be a program name with args. -set dummy pkg-config; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_PKG_CONFIG+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $PKG_CONFIG in - [\\/]* | ?:[\\/]*) - ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -PKG_CONFIG=$ac_cv_path_PKG_CONFIG -if test -n "$PKG_CONFIG"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 -$as_echo "$PKG_CONFIG" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - if test x"$PKG_CONFIG" != x""; then - OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null` - if test $? = 0; then - OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null` - OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null` - found=true - fi - fi - - # no such luck; use some default ssldirs - if ! $found; then - ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr" - fi - - -fi - - - - # note that we #include , so the OpenSSL headers have to be in - # an 'openssl' subdirectory - - if ! $found; then - OPENSSL_INCLUDES= - for ssldir in $ssldirs; do - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5 -$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; } - if test -f "$ssldir/include/openssl/ssl.h"; then - OPENSSL_INCLUDES="-I$ssldir/include" - OPENSSL_LDFLAGS="-L$ssldir/lib" - OPENSSL_LIBS="-lssl -lcrypto" - found=true - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - break - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - fi - done - - # if the file wasn't found, well, go ahead and try the link anyway -- maybe - # it will just work! - fi - - # try the preprocessor and linker with our new flags, - # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiling and linking against OpenSSL works" >&5 -$as_echo_n "checking whether compiling and linking against OpenSSL works... " >&6; } - echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \ - "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&5 - - save_LIBS="$LIBS" - save_LDFLAGS="$LDFLAGS" - save_CPPFLAGS="$CPPFLAGS" - LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS" - LIBS="$OPENSSL_LIBS $LIBS" - CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -SSL_new(NULL) - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - as_fn_error $? "No openssl found" "$LINENO" 5 - -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - LIBS="$save_LIBS" - - - +EVENT_VER="" ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -4089,6 +3935,185 @@ fi done +ac_fn_c_check_header_mongrel "$LINENO" "event2/event.h" "ac_cv_header_event2_event_h" "$ac_includes_default" +if test "x$ac_cv_header_event2_event_h" = xyes; then : + +$as_echo "#define EVENT_V2 1" >>confdefs.h + +else + + ac_fn_c_check_header_mongrel "$LINENO" "event.h" "ac_cv_header_event_h" "$ac_includes_default" +if test "x$ac_cv_header_event_h" = xyes; then : + +$as_echo "#define EVENT_V1 1" >>confdefs.h + +else + as_fn_error $? "no libevent found" "$LINENO" 5 +fi + + + +fi + + + +EXTRA_LIBS="" + +# OPENSSL_INCLUDES to the include directives required +# OPENSSL_LIBS to the -l directives required +# OPENSSL_LDFLAGS to the -L or -R flags required + + + found=false + +# Check whether --with-openssl was given. +if test "${with_openssl+set}" = set; then : + withval=$with_openssl; + case "$withval" in + "" | y | ye | yes | n | no) + as_fn_error $? "Invalid --with-openssl value" "$LINENO" 5 + ;; + *) ssldirs="$withval" + ;; + esac + +else + + # if pkg-config is installed and openssl has installed a .pc file, + # then use that information and don't search ssldirs + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_PKG_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +$as_echo "$PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + if test x"$PKG_CONFIG" != x""; then + OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null` + if test $? = 0; then + OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null` + OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null` + found=true + fi + fi + + # no such luck; use some default ssldirs + if ! $found; then + ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr" + fi + + +fi + + + + # note that we #include , so the OpenSSL headers have to be in + # an 'openssl' subdirectory + + if ! $found; then + OPENSSL_INCLUDES= + for ssldir in $ssldirs; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5 +$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; } + if test -f "$ssldir/include/openssl/ssl.h"; then + OPENSSL_INCLUDES="-I$ssldir/include" + OPENSSL_LDFLAGS="-L$ssldir/lib" + OPENSSL_LIBS="-lssl -lcrypto" + found=true + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + done + + # if the file wasn't found, well, go ahead and try the link anyway -- maybe + # it will just work! + fi + + # try the preprocessor and linker with our new flags, + # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiling and linking against OpenSSL works" >&5 +$as_echo_n "checking whether compiling and linking against OpenSSL works... " >&6; } + echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \ + "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&5 + + save_LIBS="$LIBS" + save_LDFLAGS="$LDFLAGS" + save_CPPFLAGS="$CPPFLAGS" + LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS" + LIBS="$OPENSSL_LIBS $LIBS" + CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +SSL_new(NULL) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + as_fn_error $? "No openssl found" "$LINENO" 5 + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + + + + + # # Handle user hints # @@ -4260,121 +4285,9 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_save_prompt" >&5 $as_echo "$ac_cv_lib_readline_rl_save_prompt" >&6; } if test "x$ac_cv_lib_readline_rl_save_prompt" = xyes; then : - - -$as_echo "#define READLINE_GNU 1" >>confdefs.h - - EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; - + EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; else - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tgetnum" >&5 -$as_echo_n "checking for library containing tgetnum... " >&6; } -if ${ac_cv_search_tgetnum+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$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 tgetnum (); -int -main () -{ -return tgetnum (); - ; - return 0; -} -_ACEOF -for ac_lib in '' ncursesw ncurses curses; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_tgetnum=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_tgetnum+:} false; then : - break -fi -done -if ${ac_cv_search_tgetnum+:} false; then : - -else - ac_cv_search_tgetnum=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_tgetnum" >&5 -$as_echo "$ac_cv_search_tgetnum" >&6; } -ac_res=$ac_cv_search_tgetnum -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_set_prompt in -ledit" >&5 -$as_echo_n "checking for rl_set_prompt in -ledit... " >&6; } -if ${ac_cv_lib_edit_rl_set_prompt+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-ledit $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 rl_set_prompt (); -int -main () -{ -return rl_set_prompt (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_edit_rl_set_prompt=yes -else - ac_cv_lib_edit_rl_set_prompt=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_edit_rl_set_prompt" >&5 -$as_echo "$ac_cv_lib_edit_rl_set_prompt" >&6; } -if test "x$ac_cv_lib_edit_rl_set_prompt" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBEDIT 1 -_ACEOF - - LIBS="-ledit $LIBS" - -fi - - -$as_echo "#define READLINE_EDIT 1" >>confdefs.h - - EXTRA_LIBS="${EXTRA_LIBS} -ledit" ; - - + as_fn_error $? "no libreadline found" "$LINENO" 5 fi diff --git a/configure.ac b/configure.ac index d52cad7..753848c 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,13 @@ AC_CHECK_LIB([m], [sqrt]) AC_SEARCH_LIBS([clock_gettime], [rt]) AC_SEARCH_LIBS([backtrace], [execinfo]) AC_CHECK_LIB([event], [event_base_new], [], [AC_MSG_ERROR([no libevent found])]) + +EVENT_VER="" + +AC_CHECK_HEADER(event2/event.h, [AC_DEFINE([EVENT_V2], [1], [Use libevent v2])], [ + AC_CHECK_HEADER(event.h, [AC_DEFINE([EVENT_V1], [1], [Use libevent v1])], [AC_MSG_ERROR([no libevent found])]) + ]) + EXTRA_LIBS="" # OPENSSL_INCLUDES to the include directives required @@ -28,18 +35,7 @@ EXTRA_LIBS="" AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found])]) AX_CHECK_ZLIB(, [AC_MSG_ERROR([No zlib found])]) -AC_CHECK_LIB([readline], [rl_save_prompt], - [ - AC_DEFINE([READLINE_GNU], [1], [Use gnu libreadline]) - [ EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; ] - ], - [ - AC_SEARCH_LIBS([tgetnum], [ncursesw ncurses curses]) - AC_CHECK_LIB([edit], [rl_set_prompt]) - AC_DEFINE([READLINE_EDIT], [1], [Use libedit]) - [ EXTRA_LIBS="${EXTRA_LIBS} -ledit" ; ] - ] -) +AC_CHECK_LIB([readline], [rl_save_prompt], [ EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; ], [AC_MSG_ERROR([no libreadline found])]) AC_MSG_CHECKING([for libconfig]) AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig], diff --git a/event-old.h b/event-old.h new file mode 100644 index 0000000..ac03e27 --- /dev/null +++ b/event-old.h @@ -0,0 +1,20 @@ +#ifndef __EVENT_OLD_H__ +#define __EVENT_OLD_H__ + +typedef evutil_socket_t int + +static inline struct event *event_new (struct event_base *base, int fd, int what, void(*callback)(int, short, void *), void *arg) { + struct event *ev = malloc (sizeof (*ec)); + event_set (ev, base, fd, what, callback, arg); +} + +static inline struct event *evtimer_new (struct event_base *base, void(*callback)(int, short, void *), void *arg) { + struct event *ev = malloc (sizeof (*ec)); + evtimer_set (ev, base, callback, arg); +} + +static void event_free (struct event *ev) { + event_del (ev); + free (ev); +} +#endif diff --git a/interface.c b/interface.c index 422723a..d8da3c8 100644 --- a/interface.c +++ b/interface.c @@ -42,7 +42,13 @@ #include "interface.h" #include "telegram.h" + +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif //#include "auto/constants.h" //#include "tools.h" //#include "structures.h" diff --git a/loop.c b/loop.c index 668e733..f4b602e 100644 --- a/loop.c +++ b/loop.c @@ -43,7 +43,12 @@ #include #include +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif #include "interface.h" #include "telegram.h" diff --git a/lua-tg.c b/lua-tg.c index 3c8bf7d..31d6800 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -32,7 +32,12 @@ #include #include #include +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif lua_State *luaState; //#include "interface.h" diff --git a/mtproto-client.c b/mtproto-client.c index 66f5426..4703ec6 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -58,7 +58,12 @@ #include "tools.h" #include "tree.h" #include "updates.h" +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif #if defined(__FreeBSD__) #define __builtin_bswap32(x) bswap32(x) diff --git a/net.c b/net.c index ba20b13..7563c04 100644 --- a/net.c +++ b/net.c @@ -38,7 +38,12 @@ #include #include #include +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif #include #include diff --git a/queries.c b/queries.c index 9e41f44..7a6e7e8 100644 --- a/queries.c +++ b/queries.c @@ -54,7 +54,12 @@ #include "updates.h" #include "auto.h" #include "tgl.h" +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif #define sha1 SHA1 diff --git a/tgl.c b/tgl.c index 05b3e4d..24b0e9d 100644 --- a/tgl.c +++ b/tgl.c @@ -28,7 +28,12 @@ #include "structures.h" #include "net.h" +#ifdef EVENT_V2 #include +#else +#include +#include "event-old.h" +#endif #include