diff --git a/.travis.yml b/.travis.yml index 00287f37..c716a55f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: c install: - sudo apt-get update - - sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev - - sudo apt-get -y install autoconf-archive libtool python-dev lua5.1 liblua5.1-0-dev + - sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev autoconf-archive libgcrypt11-dev + - sudo apt-get -y install libtool python-dev lua5.1 liblua5.1-0-dev - git clone git://github.com/strophe/libstrophe.git - cd libstrophe - ./bootstrap.sh diff --git a/configure.ac b/configure.ac index e5fd7fb5..142a83b8 100644 --- a/configure.ac +++ b/configure.ac @@ -221,8 +221,7 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) -PKG_CHECK_MODULES([LIBGNUTLS], [gnutls >= 2.8.0], [], - [AC_MSG_ERROR([gnutls is required for profanity])]) +AX_LIB_GCRYPT([yes]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="$LIBS -lcurl"]) @@ -319,9 +318,9 @@ AM_CFLAGS="-Wall -Wno-deprecated-declarations" AS_IF([test "x$PACKAGE_STATUS" = xdevelopment], [AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"]) AM_LDFLAGS="$AM_LDFLAGS $PYTHON_LDFLAGS $RUBY_LDFLAGS $LUA_LIB -export-dynamic" -AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $LIBGNUTLS_CFLAGS $PYTHON_CPPFLAGS $RUBY_CPPFLAGS $LUA_INCLUDE" +AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $GCRYPT_CFLAGS $PYTHON_CPPFLAGS $RUBY_CPPFLAGS $LUA_INCLUDE" AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" -LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS $LIBGNUTLS_LIBS" +LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS $GCRYPT_LIBS" AC_SUBST(AM_LDFLAGS) AC_SUBST(AM_CFLAGS) diff --git a/install-all.sh b/install-all.sh index 5717ddb0..6c07b580 100755 --- a/install-all.sh +++ b/install-all.sh @@ -24,7 +24,7 @@ debian_prepare() echo echo Profanity installer... installing dependencies echo - sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libgnutls-dev + sudo apt-get -y install git automake autoconf autoconf-archive libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libgcrypt11-dev } @@ -36,7 +36,7 @@ fedora_prepare() ARCH=`arch` - sudo yum -y install gcc git autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH gnutls-devel.$ARCH + sudo yum -y install gcc git autoconf autoconf-archive automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH libgcrypt-devel.$ARCH } opensuse_prepare() @@ -44,7 +44,7 @@ opensuse_prepare() echo echo Profanity installer...installing dependencies echo - sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel libgnutls-devel + sudo zypper -n in gcc git automake make autoconf autoconf-archive libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel libgcrypt-devel } cygwin_prepare() @@ -59,9 +59,9 @@ cygwin_prepare() mv apt-cyg /usr/local/bin/ if [ -n "$CYG_MIRROR" ]; then - apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel gnutls-devel + apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel else - apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel gnutls-devel + apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel fi diff --git a/src/common.c b/src/common.c index a45c4ff4..be29c70a 100644 --- a/src/common.c +++ b/src/common.c @@ -31,8 +31,7 @@ #include #include #include -#include -#include +#include #include "log.h" #include "common.h" @@ -65,7 +64,6 @@ p_utf8_substring(const gchar *str, glong start_pos, glong end_pos) return out; } -// backwards compatibility for GLib version < 2.28 void p_slist_free_full(GSList *items, GDestroyNotify free_func) { @@ -73,6 +71,31 @@ p_slist_free_full(GSList *items, GDestroyNotify free_func) g_slist_free (items); } +void +p_list_free_full(GList *items, GDestroyNotify free_func) +{ + g_list_foreach (items, (GFunc) free_func, NULL); + g_list_free (items); +} + +gboolean +p_hash_table_add(GHashTable *hash_table, gpointer key) +{ + // doesn't handle when key exists, but value == NULL + gpointer found = g_hash_table_lookup(hash_table, key); + g_hash_table_replace(hash_table, key, key); + + return (found == NULL); +} + +gboolean +p_hash_table_contains(GHashTable *hash_table, gconstpointer key) +{ + // doesn't handle when key exists, but value == NULL + gpointer found = g_hash_table_lookup(hash_table, key); + return (found != NULL); +} + gboolean create_dir(char *name) { @@ -393,16 +416,12 @@ generate_unique_id(char *prefix) char * sha1_hash(char *str) { - gnutls_hash_hd_t dig; - gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_SHA1; + int msg_length = strlen(str); + int hash_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1); + unsigned char hash[ hash_length ]; + gcry_md_hash_buffer(GCRY_MD_SHA1, hash, str, msg_length); - gnutls_hash_init(&dig, algorithm); - gnutls_hash(dig, str, strlen(str)); - - unsigned char output[20]; - gnutls_hash_output(dig, output); - - return g_base64_encode(output, sizeof(output)); + return g_base64_encode(hash, sizeof(hash)); } int diff --git a/src/common.h b/src/common.h index e6b0b267..d22992fd 100644 --- a/src/common.h +++ b/src/common.h @@ -29,12 +29,18 @@ #if !GLIB_CHECK_VERSION(2,28,0) #define g_slist_free_full(items, free_func) p_slist_free_full(items, free_func) +#define g_list_free_full(items, free_func) p_list_free_full(items, free_func) #endif #if !GLIB_CHECK_VERSION(2,30,0) #define g_utf8_substring(str, start_pos, end_pos) p_utf8_substring(str, start_pos, end_pos) #endif +#if !GLIB_CHECK_VERSION(2,32,0) +#define g_hash_table_add(hash_table, key) p_hash_table_add(hash_table, key) +#define g_hash_table_contains(hash_table, key) p_hash_table_contains(hash_table, key) +#endif + #ifndef NOTIFY_CHECK_VERSION #define notify_notification_new(summary, body, icon) notify_notification_new(summary, body, icon, NULL) #endif @@ -72,6 +78,10 @@ typedef enum { gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos); void p_slist_free_full(GSList *items, GDestroyNotify free_func); +void p_list_free_full(GList *items, GDestroyNotify free_func); +gboolean p_hash_table_add(GHashTable *hash_table, gpointer key); +gboolean p_hash_table_contains(GHashTable *hash_table, gconstpointer key); + gboolean create_dir(char *name); gboolean mkdir_recursive(const char *dir); char * str_replace(const char *string, const char *substr, diff --git a/src/config/account.c b/src/config/account.c index e019bf83..82e1a398 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -27,6 +27,7 @@ #include "jid.h" #include "config/account.h" +#include "common.h" ProfAccount* account_new(const gchar * const name, const gchar * const jid, diff --git a/src/muc.c b/src/muc.c index 369d19e1..3cf1f506 100644 --- a/src/muc.c +++ b/src/muc.c @@ -26,6 +26,7 @@ #include #include "contact.h" +#include "common.h" #include "jid.h" #include "tools/autocomplete.h" diff --git a/src/profanity.c b/src/profanity.c index f59208c8..4fe29fb1 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -31,7 +31,6 @@ #include #include -#include #include "profanity.h" #include "chat_session.h" @@ -262,7 +261,6 @@ _init(const int disable_tls, char *log_level) setlocale(LC_ALL, ""); // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); - gnutls_global_init(); _create_directories(); log_level_t prof_log_level = log_level_from_string(log_level); prefs_load(); @@ -314,7 +312,6 @@ _shutdown(void) cmd_uninit(); log_close(); plugins_shutdown(); - gnutls_global_deinit(); } static void diff --git a/src/tools/parser.c b/src/tools/parser.c index ba08416e..ea8e1da0 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -25,6 +25,8 @@ #include +#include "common.h" + /* * Take a full line of input and return an array of strings representing * the arguments of a command. diff --git a/tests/test_cmd_bookmark.c b/tests/test_cmd_bookmark.c index 3a78ba5b..f576196c 100644 --- a/tests/test_cmd_bookmark.c +++ b/tests/test_cmd_bookmark.c @@ -12,6 +12,7 @@ #include "xmpp/mock_xmpp.h" #include "muc.h" +#include "common.h" #include "command/commands.h"