From f5f7b99e1a7ce8494f263f7019131aa2f8f681c9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 22 Oct 2012 23:30:20 +0100 Subject: [PATCH 01/19] Escape key clears input line --- src/input_win.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/input_win.c b/src/input_win.c index 107d6985..408bd45a 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -72,6 +72,9 @@ static void _parameter_autocomplete(char *input, int *size, char *command, void create_input_window(void) { + if (getenv("ESCDELAY") == NULL) + ESCDELAY = 25; + int rows, cols; getmaxyx(stdscr, rows, cols); @@ -220,6 +223,11 @@ _handle_edit(const int ch, char *input, int *size) switch(ch) { + case 27: // ESC + *size = 0; + inp_clear(); + return 1; + case 127: case KEY_BACKSPACE: contact_list_reset_search_attempts(); From 15de3d4a8f019d4115ba0b9ea5850ff8225e8574 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 22 Oct 2012 23:58:47 +0100 Subject: [PATCH 02/19] Split help into sections Most of the time complete help was too big for the screen --- src/command.c | 20 +++++++++++++++++--- src/ui.h | 4 ++++ src/windows.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 79b92ffc..b536cc80 100644 --- a/src/command.c +++ b/src/command.c @@ -91,13 +91,15 @@ static struct cmd_t main_commands[] = { { "/help", _cmd_help, - { "/help [command]", "Show help summary, or help on a specific command", - { "/help [command]", + { "/help [area|command]", "Show help summary, or help on a specific area or command", + { "/help [area|command]", "---------------", - "List all commands with short help on what they do.", + "Show help options.", + "Specify an area (basic, status, settings, navigation) for more help on that area.", "Specify the command if you want more detailed help on a specific command.", "", "Example : /help connect", + "Example : /help settings", NULL } } }, { "/connect", @@ -363,6 +365,10 @@ cmd_init(void) log_info("Initialising commands"); commands_ac = p_autocomplete_new(); help_ac = p_autocomplete_new(); + p_autocomplete_add(help_ac, strdup("basic")); + p_autocomplete_add(help_ac, strdup("status")); + p_autocomplete_add(help_ac, strdup("settings")); + p_autocomplete_add(help_ac, strdup("navigation")); unsigned int i; for (i = 0; i < ARRAY_SIZE(main_commands); i++) { @@ -551,6 +557,14 @@ _cmd_help(const char * const inp, struct cmd_help_t help) { if (strcmp(inp, "/help") == 0) { cons_help(); + } else if (strcmp(inp, "/help basic") == 0) { + cons_basic_help(); + } else if (strcmp(inp, "/help status") == 0) { + cons_status_help(); + } else if (strcmp(inp, "/help settings") == 0) { + cons_settings_help(); + } else if (strcmp(inp, "/help navigation") == 0) { + cons_navigation_help(); } else { char *cmd = strndup(inp+6, strlen(inp)-6); char cmd_with_slash[1 + strlen(cmd) + 1]; diff --git a/src/ui.h b/src/ui.h index 671ca703..8b2e5163 100644 --- a/src/ui.h +++ b/src/ui.h @@ -104,6 +104,10 @@ void win_remind(void); // console window actions void cons_help(void); +void cons_basic_help(void); +void cons_settings_help(void); +void cons_status_help(void); +void cons_navigation_help(void); void cons_prefs(void); void cons_bad_command(const char * const cmd); void cons_show(const char * const cmd, ...); diff --git a/src/windows.c b/src/windows.c index 8fe78365..7daf9f1b 100644 --- a/src/windows.c +++ b/src/windows.c @@ -573,11 +573,35 @@ _cons_show_basic_help(void) void cons_help(void) +{ + cons_show(""); + cons_show("Choose an area you need help with:"); + cons_show(""); + cons_show("/help basic - Basic commands, for connecting, chatting etc."); + cons_show("/help status - How to change your status."); + cons_show("/help settings - Commands for configuring Profanity."); + cons_show("/help navigation - How to navigate around Profanity."); + cons_show(""); + + if (_curr_prof_win == 0) + dirty = TRUE; +} + +void +cons_basic_help(void) { cons_show(""); cons_show("Basic Commands:"); _cons_show_basic_help(); + if (_curr_prof_win == 0) + dirty = TRUE; +} + +void +cons_settings_help(void) +{ + cons_show(""); cons_show("Settings:"); cons_show(""); @@ -587,7 +611,16 @@ cons_help(void) cons_show("%-25s: %s", help->usage, help->short_help); settings_helpers = g_slist_next(settings_helpers); } + + cons_show(""); + if (_curr_prof_win == 0) + dirty = TRUE; +} + +void +cons_status_help(void) +{ cons_show(""); cons_show("Status changes:"); cons_show(""); @@ -599,6 +632,15 @@ cons_help(void) status_helpers = g_slist_next(status_helpers); } + cons_show(""); + + if (_curr_prof_win == 0) + dirty = TRUE; +} + +void +cons_navigation_help(void) +{ cons_show(""); cons_show("Navigation:"); cons_show(""); From 907b5cf801f78ed41a95da04cbdc6b95b5e4a451 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 00:00:10 +0100 Subject: [PATCH 03/19] Trailing whitespace --- src/command.c | 2 +- src/windows.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index b536cc80..66547525 100644 --- a/src/command.c +++ b/src/command.c @@ -561,7 +561,7 @@ _cmd_help(const char * const inp, struct cmd_help_t help) cons_basic_help(); } else if (strcmp(inp, "/help status") == 0) { cons_status_help(); - } else if (strcmp(inp, "/help settings") == 0) { + } else if (strcmp(inp, "/help settings") == 0) { cons_settings_help(); } else if (strcmp(inp, "/help navigation") == 0) { cons_navigation_help(); diff --git a/src/windows.c b/src/windows.c index 7daf9f1b..cc1f660e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -611,7 +611,7 @@ cons_settings_help(void) cons_show("%-25s: %s", help->usage, help->short_help); settings_helpers = g_slist_next(settings_helpers); } - + cons_show(""); if (_curr_prof_win == 0) From d19afc35075c7b614ee243eb00805c1eba68fc35 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 00:18:28 +0100 Subject: [PATCH 04/19] Added /about command Useful for showing version --- src/command.c | 18 +++++++++++++++++- src/ui.h | 1 + src/windows.c | 44 +++++++++++++++++++++++++++----------------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/command.c b/src/command.c index 66547525..2ae038c5 100644 --- a/src/command.c +++ b/src/command.c @@ -61,6 +61,7 @@ static gboolean _cmd_set_boolean_preference(const char * const inp, // command prototypes static gboolean _cmd_quit(const char * const inp, struct cmd_help_t help); static gboolean _cmd_help(const char * const inp, struct cmd_help_t help); +static gboolean _cmd_about(const char * const inp, struct cmd_help_t help); static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help); static gboolean _cmd_who(const char * const inp, struct cmd_help_t help); static gboolean _cmd_connect(const char * const inp, struct cmd_help_t help); @@ -93,7 +94,7 @@ static struct cmd_t main_commands[] = _cmd_help, { "/help [area|command]", "Show help summary, or help on a specific area or command", { "/help [area|command]", - "---------------", + "--------------------", "Show help options.", "Specify an area (basic, status, settings, navigation) for more help on that area.", "Specify the command if you want more detailed help on a specific command.", @@ -102,6 +103,14 @@ static struct cmd_t main_commands[] = "Example : /help settings", NULL } } }, + { "/about", + _cmd_about, + { "/about", "About Profanity", + { "/about", + "------", + "Show versioning and license information.", + NULL } } }, + { "/connect", _cmd_connect, { "/connect user@host", "Login to jabber.", @@ -594,6 +603,13 @@ _cmd_help(const char * const inp, struct cmd_help_t help) return TRUE; } +static gboolean +_cmd_about(const char * const inp, struct cmd_help_t help) +{ + cons_about(); + return TRUE; +} + static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help) { diff --git a/src/ui.h b/src/ui.h index 8b2e5163..9d32602a 100644 --- a/src/ui.h +++ b/src/ui.h @@ -103,6 +103,7 @@ void win_bad_show(const char * const msg); void win_remind(void); // console window actions +void cons_about(void); void cons_help(void); void cons_basic_help(void); void cons_settings_help(void); diff --git a/src/windows.c b/src/windows.c index cc1f660e..3183222f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -648,6 +648,7 @@ cons_navigation_help(void) cons_show("F2-F10 : Chat windows."); cons_show("UP, DOWN : Navigate input history."); cons_show("LEFT, RIGHT, HOME, END : Edit current input."); + cons_show("ESC : Clear current input."); cons_show("TAB : Autocomplete command/recipient/login"); cons_show("PAGE UP, PAGE DOWN : Page the main window."); cons_show(""); @@ -772,8 +773,7 @@ win_page_off(void) static void _create_windows(void) { - int rows, cols; - getmaxyx(stdscr, rows, cols); + int cols = getmaxx(stdscr); max_cols = cols; // create the console window in 0 @@ -788,6 +788,31 @@ _create_windows(void) scrollok(cons.win, TRUE); _wins[0] = cons; + + cons_about(); + + // create the chat windows + int i; + for (i = 1; i < NUM_WINS; i++) { + struct prof_win chat; + strcpy(chat.from, ""); + chat.win = newpad(PAD_SIZE, cols); + wbkgd(chat.win, COLOUR_TEXT); + chat.y_pos = 0; + chat.paged = 0; + chat.unread = 0; + chat.history_shown = 0; + scrollok(chat.win, TRUE); + _wins[i] = chat; + } +} + +void +cons_about(void) +{ + int rows, cols; + getmaxyx(stdscr, rows, cols); + _cons_win = _wins[0].win; if (prefs_get_showsplash()) { @@ -817,21 +842,6 @@ _create_windows(void) prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); dirty = TRUE; - - // create the chat windows - int i; - for (i = 1; i < NUM_WINS; i++) { - struct prof_win chat; - strcpy(chat.from, ""); - chat.win = newpad(PAD_SIZE, cols); - wbkgd(chat.win, COLOUR_TEXT); - chat.y_pos = 0; - chat.paged = 0; - chat.unread = 0; - chat.history_shown = 0; - scrollok(chat.win, TRUE); - _wins[i] = chat; - } } static void From cf4a38a852ba390c643814ec8020b0957ec36f78 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 00:33:29 +0100 Subject: [PATCH 05/19] Removed dependency on libxml2 expat is used by default in libstrophe --- configure.ac | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 921885cf..eeb704a0 100644 --- a/configure.ac +++ b/configure.ac @@ -20,8 +20,6 @@ AC_CHECK_LIB([ssl], [main], [], [AC_MSG_ERROR([openssl is required for profanity])]) AC_CHECK_LIB([expat], [main], [], [AC_MSG_ERROR([expat is required for profanity])]) -AC_CHECK_LIB([xml2], [main], [], - [AC_MSG_ERROR([libxml2 is required for profanity])]) AC_CHECK_LIB([strophe], [main], [], [AC_MSG_ERROR([libstrophe is required for profanity])]) AC_CHECK_LIB([glib-2.0], [main], [], @@ -43,7 +41,7 @@ PKG_CHECK_MODULES([NOTIFY], [libnotify], [], [AC_MSG_NOTICE([libnotify module not found])]) AM_CFLAGS="-Wall " -AM_CFLAGS="$AM_CFLAGS -lstrophe -lxml2 -lexpat -lncurses -lcurl -lresolv " +AM_CFLAGS="$AM_CFLAGS -lstrophe -lexpat -lncurses -lcurl -lresolv " AM_CFLAGS="$AM_CFLAGS $DEPS_LIBS $NOTIFY_LIBS" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" From abec6ae07c765c6bbb8ac84199a6cc3dbd3f3cb3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 00:35:45 +0100 Subject: [PATCH 06/19] Removed libxml2 from install-all.sh --- install-all.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install-all.sh b/install-all.sh index 5bc8fbab..73f2b67d 100755 --- a/install-all.sh +++ b/install-all.sh @@ -10,7 +10,7 @@ debian_prepare() echo echo Profanity installer... installing dependencies echo - sudo apt-get -y install g++ autoconf libssl-dev libexpat1-dev libncurses5-dev libxml2-dev libglib2.0-dev libnotify-dev libcurl3-dev + sudo apt-get -y install g++ autoconf libssl-dev libexpat1-dev libncurses5-dev libglib2.0-dev libnotify-dev libcurl3-dev } @@ -22,7 +22,7 @@ fedora_prepare() ARCH=`arch` - sudo yum -y install gcc gcc-c++ autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH libxml2-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH + sudo yum -y install gcc gcc-c++ autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH } cygwin_prepare() @@ -35,7 +35,7 @@ cygwin_prepare() chmod +x apt-cyg mv apt-cyg /usr/local/bin/ - apt-cyg install make gcc automake autoconf pkg-config openssl-devel expat zlib-devel libncurses-devel libncurses-devel libxml2-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel + apt-cyg install make gcc automake autoconf pkg-config openssl-devel expat zlib-devel libncurses-devel libncurses-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel ln -s /usr/bin/gcc-3.exe /usr/bin/gcc.exe ln -s /usr/bin/g++-3.exe /usr/bin/g++.exe From 07f41e646fddef61b5e53cbd7fc504d96cbbda1a Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 01:31:19 +0100 Subject: [PATCH 07/19] Check for method of setting ESCDELAY --- src/input_win.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/input_win.c b/src/input_win.c index 408bd45a..9ee71ce1 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -72,8 +72,11 @@ static void _parameter_autocomplete(char *input, int *size, char *command, void create_input_window(void) { - if (getenv("ESCDELAY") == NULL) - ESCDELAY = 25; +#ifdef NCURSES_REENTRANT + set_escdelay(25); +#else + ESCDELAY = 25; +#endif int rows, cols; getmaxyx(stdscr, rows, cols); From a16c53f53a434464f49315c1943c9b64e9cfcefc Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Tue, 23 Oct 2012 13:34:30 +0300 Subject: [PATCH 08/19] autotools: introduce choice among libxml2 and expat Now profanity is linked with expat only. This breaks build when libstrophe is build with libxml2 support. This patch introduce --with-libxml2 option to ./configure in the same way as it is done in libstrophe. --- configure.ac | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index eeb704a0..246029cc 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,10 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) # Checks for programs. AC_PROG_CC +# Options +AC_ARG_WITH([libxml2], + [AS_HELP_STRING([--with-libxml2], [link with libxml2 instead of expat])]) + # Checks for libraries. AC_CHECK_LIB([ncurses], [main], [], [AC_MSG_ERROR([ncurses is required for profanity])]) @@ -18,8 +22,6 @@ AC_CHECK_LIB([resolv], [main], [], [AC_MSG_ERROR([libresolv is required for profanity])]) AC_CHECK_LIB([ssl], [main], [], [AC_MSG_ERROR([openssl is required for profanity])]) -AC_CHECK_LIB([expat], [main], [], - [AC_MSG_ERROR([expat is required for profanity])]) AC_CHECK_LIB([strophe], [main], [], [AC_MSG_ERROR([libstrophe is required for profanity])]) AC_CHECK_LIB([glib-2.0], [main], [], @@ -31,6 +33,14 @@ AC_CHECK_LIB([notify], [main], [], AC_CHECK_LIB([headunit], [main], [], [AC_MSG_NOTICE([headunit not found, will not be able to run tests])]) +if test "x$with_libxml2" = xyes; then + AC_CHECK_LIB([xml2], [main], [], + [AC_MSG_ERROR([libxml2 is required for profanity])]) +else + AC_CHECK_LIB([expat], [main], [], + [AC_MSG_ERROR([expat is required for profanity])]) +fi + # Checks for header files. AC_CHECK_HEADERS([stdlib.h string.h]) AC_CHECK_HEADERS([ncurses.h], [], []) @@ -41,7 +51,7 @@ PKG_CHECK_MODULES([NOTIFY], [libnotify], [], [AC_MSG_NOTICE([libnotify module not found])]) AM_CFLAGS="-Wall " -AM_CFLAGS="$AM_CFLAGS -lstrophe -lexpat -lncurses -lcurl -lresolv " +AM_CFLAGS="$AM_CFLAGS -lstrophe -lncurses -lcurl -lresolv " AM_CFLAGS="$AM_CFLAGS $DEPS_LIBS $NOTIFY_LIBS" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" From c2e94bfb20ad67a9f4986757a0672adf943e35f4 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Tue, 23 Oct 2012 13:45:33 +0300 Subject: [PATCH 09/19] autotools: move libraries to LIBS instead of AM_CFLAGS Libraries are agruments for linker. So move them to LIBS vatiable. AC_CHECK_LIB adds library to LIBS on success and we don't have to add them manually. --- configure.ac | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 246029cc..9e4b18c6 100644 --- a/configure.ac +++ b/configure.ac @@ -51,8 +51,7 @@ PKG_CHECK_MODULES([NOTIFY], [libnotify], [], [AC_MSG_NOTICE([libnotify module not found])]) AM_CFLAGS="-Wall " -AM_CFLAGS="$AM_CFLAGS -lstrophe -lncurses -lcurl -lresolv " -AM_CFLAGS="$AM_CFLAGS $DEPS_LIBS $NOTIFY_LIBS" +LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" From f8a4d21ab394dcad5aa1778c68c31107ccfb70b0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 23:30:01 +0100 Subject: [PATCH 10/19] Added check for latest release --- Makefile.am | 2 +- src/windows.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index d4a8da4d..f28807d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,7 @@ profanity_SOURCES = src/command.c src/contact.c src/history.c src/jabber.h \ src/contact_list.c src/input_win.c src/log.h src/profanity.c \ src/prof_history.c src/ui.h src/common.h src/ contact_list.h src/jabber.c \ src/main.c src/profanity.h src/prof_history.h src/chat_log.c \ - src/chat_log.h src/tinyurl.c src/tinyurl.h + src/chat_log.h src/tinyurl.c src/tinyurl.h src/release.c src/release.h TESTS = tests/testsuite check_PROGRAMS = tests/testsuite diff --git a/src/windows.c b/src/windows.c index 3183222f..46b924ee 100644 --- a/src/windows.c +++ b/src/windows.c @@ -42,6 +42,7 @@ #include "contact_list.h" #include "log.h" #include "preferences.h" +#include "release.h" #include "ui.h" #define CONS_WIN_TITLE "_cons" @@ -838,6 +839,13 @@ cons_about(void) wprintw(_cons_win, "Type '/help' to show complete help.\n"); _win_show_time(_cons_win); wprintw(_cons_win, "\n"); + + char *latest_release = release_get_latest(); + _win_show_time(_cons_win); + wprintw(_cons_win, "RELEASE: %s", latest_release); + free(latest_release); + _win_show_time(_cons_win); + wprintw(_cons_win, "\n"); prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); From 7d6e64a53a40da1896ebaa17ffbbbe6cd2d02786 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 24 Oct 2012 01:50:16 +0300 Subject: [PATCH 11/19] libraries order does matter when --as-needed is passed to linker This fixes linking error when --as-needed option is used. --- configure.ac | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 9e4b18c6..bc376558 100644 --- a/configure.ac +++ b/configure.ac @@ -16,14 +16,22 @@ AC_ARG_WITH([libxml2], [AS_HELP_STRING([--with-libxml2], [link with libxml2 instead of expat])]) # Checks for libraries. -AC_CHECK_LIB([ncurses], [main], [], - [AC_MSG_ERROR([ncurses is required for profanity])]) +if test "x$with_libxml2" = xyes; then + AC_CHECK_LIB([xml2], [main], [], + [AC_MSG_ERROR([libxml2 is required for profanity])]) +else + AC_CHECK_LIB([expat], [main], [], + [AC_MSG_ERROR([expat is required for profanity])]) +fi + AC_CHECK_LIB([resolv], [main], [], [AC_MSG_ERROR([libresolv is required for profanity])]) AC_CHECK_LIB([ssl], [main], [], [AC_MSG_ERROR([openssl is required for profanity])]) AC_CHECK_LIB([strophe], [main], [], [AC_MSG_ERROR([libstrophe is required for profanity])]) +AC_CHECK_LIB([ncurses], [main], [], + [AC_MSG_ERROR([ncurses is required for profanity])]) AC_CHECK_LIB([glib-2.0], [main], [], [AC_MSG_ERROR([glib-2.0 is required for profanity])]) AC_CHECK_LIB([curl], [main], [], @@ -33,14 +41,6 @@ AC_CHECK_LIB([notify], [main], [], AC_CHECK_LIB([headunit], [main], [], [AC_MSG_NOTICE([headunit not found, will not be able to run tests])]) -if test "x$with_libxml2" = xyes; then - AC_CHECK_LIB([xml2], [main], [], - [AC_MSG_ERROR([libxml2 is required for profanity])]) -else - AC_CHECK_LIB([expat], [main], [], - [AC_MSG_ERROR([expat is required for profanity])]) -fi - # Checks for header files. AC_CHECK_HEADERS([stdlib.h string.h]) AC_CHECK_HEADERS([ncurses.h], [], []) From a8e985144914681bb97d9f60a4487590a29c7b8a Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 23:52:40 +0100 Subject: [PATCH 12/19] Added PACKAGE_STATUS to configure.ac --- configure.ac | 3 ++- src/windows.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 9e4b18c6..b7bbc7e2 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.65]) -AC_INIT([profanity], [0.1.9dev], [boothj5web@gmail.com]) +AC_INIT([profanity], [0.1.9], [boothj5web@gmail.com]) +AC_DEFINE([PACKAGE_STATUS], ["release"], [Status of this build]) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_AUX_DIR([build-aux]) diff --git a/src/windows.c b/src/windows.c index 46b924ee..0d87c378 100644 --- a/src/windows.c +++ b/src/windows.c @@ -820,7 +820,12 @@ cons_about(void) _cons_splash_logo(); } else { _win_show_time(_cons_win); - wprintw(_cons_win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); + + if (strcmp(PACKAGE_STATUS, "dev") == 0) { + wprintw(_cons_win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); + } else { + wprintw(_cons_win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); + } } _win_show_time(_cons_win); @@ -858,7 +863,6 @@ _cons_splash_logo(void) _win_show_time(_cons_win); wprintw(_cons_win, "Welcome to\n"); - _win_show_time(_cons_win); wattron(_cons_win, COLOUR_OFFLINE); wprintw(_cons_win, " ___ _ \n"); @@ -897,7 +901,11 @@ _cons_splash_logo(void) _win_show_time(_cons_win); wprintw(_cons_win, "\n"); _win_show_time(_cons_win); - wprintw(_cons_win, "Version %s\n", PACKAGE_VERSION); + if (strcmp(PACKAGE_STATUS, "dev") == 0) { + wprintw(_cons_win, "Version %sdev\n", PACKAGE_VERSION); + } else { + wprintw(_cons_win, "Version %s\n", PACKAGE_VERSION); + } } static int From 83b0dc9f6d83827c3c8af67b060c632f9b099307 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Oct 2012 23:53:22 +0100 Subject: [PATCH 13/19] Added missing files --- src/release.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/release.h | 25 +++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/release.c create mode 100644 src/release.h diff --git a/src/release.c b/src/release.c new file mode 100644 index 00000000..fb08b8ba --- /dev/null +++ b/src/release.c @@ -0,0 +1,76 @@ +/* + * release.c + * + * Copyright (C) 2012 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#include +#include + +#include +#include +#include + +struct curl_data_t +{ + char *buffer; + size_t size; +}; + +static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data); + +char * +release_get_latest() +{ + char *url = "http://www.boothj5.com/profanity_version.txt"; + + CURL *handle = curl_easy_init(); + struct curl_data_t output; + output.buffer = NULL; + output.size = 0; + + curl_easy_setopt(handle, CURLOPT_URL, url); + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, _data_callback); + curl_easy_setopt(handle, CURLOPT_TIMEOUT, 2); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&output); + + curl_easy_perform(handle); + curl_easy_cleanup(handle); + + output.buffer[output.size++] = '\0'; + + return output.buffer; +} + +static size_t +_data_callback(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + struct curl_data_t *mem = (struct curl_data_t *) data; + mem->buffer = realloc(mem->buffer, mem->size + realsize + 1); + + if ( mem->buffer ) + { + memcpy( &( mem->buffer[ mem->size ] ), ptr, realsize ); + mem->size += realsize; + mem->buffer[ mem->size ] = 0; + } + + return realsize; +} diff --git a/src/release.h b/src/release.h new file mode 100644 index 00000000..c106d622 --- /dev/null +++ b/src/release.h @@ -0,0 +1,25 @@ +/* + * release.h + * + * Copyright (C) 2012 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#include + +char * release_get_latest(void); From f1d641b5e13c16d5c5bb1cea528efdf929f2b7d3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 00:18:32 +0100 Subject: [PATCH 14/19] Only check for new release if release build --- src/windows.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/windows.c b/src/windows.c index 0d87c378..97d85192 100644 --- a/src/windows.c +++ b/src/windows.c @@ -844,13 +844,23 @@ cons_about(void) wprintw(_cons_win, "Type '/help' to show complete help.\n"); _win_show_time(_cons_win); wprintw(_cons_win, "\n"); - - char *latest_release = release_get_latest(); - _win_show_time(_cons_win); - wprintw(_cons_win, "RELEASE: %s", latest_release); - free(latest_release); - _win_show_time(_cons_win); - wprintw(_cons_win, "\n"); + + // check for new version if this is a release build + if (strcmp(PACKAGE_STATUS, "release") == 0) { + char *latest_release = release_get_latest(); + + if (latest_release != NULL) { + gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + + if (relase_valid) { + _win_show_time(_cons_win); + wprintw(_cons_win, "RELEASE: %s", latest_release); + free(latest_release); + _win_show_time(_cons_win); + wprintw(_cons_win, "\n"); + } + } + } prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); From ff335f80a9218a0d46d9b5790b452cc09125efa9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 00:59:18 +0100 Subject: [PATCH 15/19] Check for later release --- configure.ac | 2 +- src/windows.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index c0590d44..41d59087 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.65]) AC_INIT([profanity], [0.1.9], [boothj5web@gmail.com]) -AC_DEFINE([PACKAGE_STATUS], ["release"], [Status of this build]) +AC_DEFINE([PACKAGE_STATUS], ["development"], [Status of this build]) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_AUX_DIR([build-aux]) diff --git a/src/windows.c b/src/windows.c index 97d85192..ff11bb7f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -87,6 +87,7 @@ static void _win_resize_all(void); static gint _win_get_unread(void); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); +static gboolean _new_release(char *found_version); #ifdef HAVE_LIBNOTIFY static void _win_notify(const char * const message, int timeout, @@ -821,7 +822,7 @@ cons_about(void) } else { _win_show_time(_cons_win); - if (strcmp(PACKAGE_STATUS, "dev") == 0) { + if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(_cons_win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); } else { wprintw(_cons_win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); @@ -853,11 +854,13 @@ cons_about(void) gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); if (relase_valid) { - _win_show_time(_cons_win); - wprintw(_cons_win, "RELEASE: %s", latest_release); - free(latest_release); - _win_show_time(_cons_win); - wprintw(_cons_win, "\n"); + if (_new_release(latest_release)) { + _win_show_time(_cons_win); + wprintw(_cons_win, "RELEASE: %s", latest_release); + free(latest_release); + _win_show_time(_cons_win); + wprintw(_cons_win, "\n"); + } } } } @@ -867,6 +870,32 @@ cons_about(void) dirty = TRUE; } +static gboolean +_new_release(char *found_version) +{ + int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch; + + int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min, + &curr_patch); + int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min, + &found_patch); + + if (parse_found == 3 && parse_curr == 3) { + if (found_maj > curr_maj) { + return TRUE; + } else if (found_maj == curr_maj && found_min > curr_min) { + return TRUE; + } else if (found_maj == curr_maj && found_min == curr_min + && found_patch > curr_patch) { + return TRUE; + } else { + return FALSE; + } + } else { + return FALSE; + } +} + static void _cons_splash_logo(void) { From 2ca8f5b62eb0d35e570a3c3c9418cf1c00a202fa Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 01:35:36 +0100 Subject: [PATCH 16/19] Made version check a user preference --- src/command.c | 23 ++++++++++++++++++++ src/preferences.c | 13 +++++++++++ src/preferences.h | 2 ++ src/ui.h | 1 + src/windows.c | 55 ++++++++++++++++++++++++++++++++--------------- 5 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/command.c b/src/command.c index 2ae038c5..adf3ddf0 100644 --- a/src/command.c +++ b/src/command.c @@ -76,6 +76,7 @@ static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t he static gboolean _cmd_set_chlog(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_history(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_remind(const char * const inp, struct cmd_help_t help); +static gboolean _cmd_vercheck(const char * const inp, struct cmd_help_t help); static gboolean _cmd_away(const char * const inp, struct cmd_help_t help); static gboolean _cmd_online(const char * const inp, struct cmd_help_t help); static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help); @@ -271,6 +272,16 @@ static struct cmd_t setting_commands[] = "Config file section : [ui]", "Config file value : showsplash=true|false", NULL } } }, + + { "/vercheck", + _cmd_vercheck, + { "/vercheck [on|off]", "Check for a new release.", + { "/vercheck [on|off]", + "------------------", + "Without a parameter will check for a new release.", + "Switching on or off will enable/disable a version check when Profanity starts,", + "and each time the /about command is run.", + NULL } } }, { "/chlog", _cmd_set_chlog, @@ -812,6 +823,18 @@ _cmd_set_typing(const char * const inp, struct cmd_help_t help) "Incoming typing notifications", prefs_set_typing); } +static gboolean +_cmd_vercheck(const char * const inp, struct cmd_help_t help) +{ + if (strcmp(inp, "/vercheck") == 0) { + cons_check_version(TRUE); + return TRUE; + } else { + return _cmd_set_boolean_preference(inp, help, "/vercheck", + "Version checking", prefs_set_vercheck); + } +} + static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help) { diff --git a/src/preferences.c b/src/preferences.c index 67f9345a..706ad4d3 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -261,6 +261,19 @@ prefs_set_typing(gboolean value) _save_prefs(); } +gboolean +prefs_get_vercheck(void) +{ + return g_key_file_get_boolean(prefs, "ui", "vercheck", NULL); +} + +void +prefs_set_vercheck(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "vercheck", value); + _save_prefs(); +} + gboolean prefs_get_flash(void) { diff --git a/src/preferences.h b/src/preferences.h index e816b7c0..885b895d 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -58,6 +58,8 @@ gboolean prefs_get_showsplash(void); void prefs_set_showsplash(gboolean value); gint prefs_get_remind(void); void prefs_set_remind(gint value); +gboolean prefs_get_vercheck(void); +void prefs_set_vercheck(gboolean value); void prefs_add_login(const char *jid); diff --git a/src/ui.h b/src/ui.h index 9d32602a..df42a191 100644 --- a/src/ui.h +++ b/src/ui.h @@ -115,6 +115,7 @@ void cons_show(const char * const cmd, ...); void cons_bad_show(const char * const cmd); void cons_highlight_show(const char * const cmd); void cons_show_contacts(GSList * list); +void cons_check_version(gboolean not_available_msg); // status bar actions void status_bar_refresh(void); diff --git a/src/windows.c b/src/windows.c index ff11bb7f..bd06165d 100644 --- a/src/windows.c +++ b/src/windows.c @@ -543,6 +543,11 @@ cons_prefs(void) else cons_show("Chat history : OFF"); + if (prefs_get_vercheck()) + cons_show("Version checking : ON"); + else + cons_show("Version checking : OFF"); + gint remind_period = prefs_get_remind(); if (remind_period == 0) { cons_show("Message reminder period : OFF"); @@ -846,23 +851,8 @@ cons_about(void) _win_show_time(_cons_win); wprintw(_cons_win, "\n"); - // check for new version if this is a release build - if (strcmp(PACKAGE_STATUS, "release") == 0) { - char *latest_release = release_get_latest(); - - if (latest_release != NULL) { - gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); - - if (relase_valid) { - if (_new_release(latest_release)) { - _win_show_time(_cons_win); - wprintw(_cons_win, "RELEASE: %s", latest_release); - free(latest_release); - _win_show_time(_cons_win); - wprintw(_cons_win, "\n"); - } - } - } + if (prefs_get_vercheck()) { + cons_check_version(FALSE); } prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); @@ -870,6 +860,37 @@ cons_about(void) dirty = TRUE; } +void +cons_check_version(gboolean not_available_msg) +{ + char *latest_release = release_get_latest(); + + if (latest_release != NULL) { + gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + + if (relase_valid) { + if (_new_release(latest_release)) { + _win_show_time(_cons_win); + wattron(_cons_win, COLOUR_ONLINE); + wprintw(_cons_win, "A new version of Profanity is available: %s", latest_release); + wattroff(_cons_win, COLOUR_ONLINE); + _win_show_time(_cons_win); + wattron(_cons_win, COLOUR_ONLINE); + wprintw(_cons_win, "Check http://www.boothj5.com/profanity.shtml for details.\n"); + wattroff(_cons_win, COLOUR_ONLINE); + free(latest_release); + _win_show_time(_cons_win); + wprintw(_cons_win, "\n"); + } else { + if (not_available_msg) { + cons_show("No new version available."); + cons_show(""); + } + } + } + } +} + static gboolean _new_release(char *found_version) { From 8322c48d3e580e3f098b031554932924cde2fc00 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 01:39:52 +0100 Subject: [PATCH 17/19] Added autocomplete for version checking parameter --- src/command.c | 1 + src/input_win.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/command.c b/src/command.c index adf3ddf0..bedadfda 100644 --- a/src/command.c +++ b/src/command.c @@ -617,6 +617,7 @@ _cmd_help(const char * const inp, struct cmd_help_t help) static gboolean _cmd_about(const char * const inp, struct cmd_help_t help) { + cons_show(""); cons_about(); return TRUE; } diff --git a/src/input_win.c b/src/input_win.c index 9ee71ce1..3cb903e1 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -372,6 +372,8 @@ _handle_edit(const int ch, char *input, int *size) prefs_autocomplete_boolean_choice); _parameter_autocomplete(input, size, "/history", prefs_autocomplete_boolean_choice); + _parameter_autocomplete(input, size, "/vercheck", + prefs_autocomplete_boolean_choice); return 1; From e49bea4d6bffd87b6631e84f03a35e47e5b35bd9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 02:18:20 +0100 Subject: [PATCH 18/19] Fixed possible NULL pointer references when offline --- src/command.c | 24 +++++++++++++++--------- src/release.c | 9 ++++++--- src/tinyurl.c | 8 ++++++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/command.c b/src/command.c index bedadfda..d22458a6 100644 --- a/src/command.c +++ b/src/command.c @@ -765,17 +765,23 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) free(url); } else if (win_in_chat()) { char *tiny = tinyurl_get(url); - char *recipient = win_get_recipient(); - jabber_send(tiny, recipient); + + if (tiny != NULL) { + char *recipient = win_get_recipient(); + jabber_send(tiny, recipient); - if (prefs_get_chlog()) { - const char *jid = jabber_get_jid(); - chat_log_chat(jid, recipient, tiny, OUT); + if (prefs_get_chlog()) { + const char *jid = jabber_get_jid(); + chat_log_chat(jid, recipient, tiny, OUT); + } + + win_show_outgoing_msg("me", recipient, tiny); + free(recipient); + free(tiny); + } else { + cons_bad_show("Couldn't get tinyurl."); } - - win_show_outgoing_msg("me", recipient, tiny); - free(recipient); - free(tiny); + free(url); } else { cons_bad_command(inp); diff --git a/src/release.c b/src/release.c index fb08b8ba..f585e8fc 100644 --- a/src/release.c +++ b/src/release.c @@ -53,9 +53,12 @@ release_get_latest() curl_easy_perform(handle); curl_easy_cleanup(handle); - output.buffer[output.size++] = '\0'; - - return output.buffer; + if (output.buffer != NULL) { + output.buffer[output.size++] = '\0'; + return output.buffer; + } else { + return NULL; + } } static size_t diff --git a/src/tinyurl.c b/src/tinyurl.c index 9b572319..9ee64977 100644 --- a/src/tinyurl.c +++ b/src/tinyurl.c @@ -60,10 +60,14 @@ tinyurl_get(char *url) curl_easy_perform(handle); curl_easy_cleanup(handle); - output.buffer[output.size++] = '\0'; g_string_free(full_url, TRUE); - return output.buffer; + if (output.buffer != NULL) { + output.buffer[output.size++] = '\0'; + return output.buffer; + } else { + return NULL; + } } static size_t From d6f87e7a1605f5d2086f2fcaa084b258f620f435 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 24 Oct 2012 13:43:25 +0300 Subject: [PATCH 19/19] _cmd_tiny: fix possible NULL pointer dereference Check 'url' for NULL and move free(url) out of if-else structure --- src/command.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/command.c b/src/command.c index d22458a6..b30e9cae 100644 --- a/src/command.c +++ b/src/command.c @@ -753,6 +753,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) { if (strlen(inp) > 6) { char *url = strndup(inp+6, strlen(inp)-6); + if (url == NULL) { + log_error("Not enough memory."); + return FALSE; + } if (!tinyurl_valid(url)) { GString *error = g_string_new("/tiny, badly formed URL: "); @@ -762,10 +766,9 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) win_bad_show(error->str); } g_string_free(error, TRUE); - free(url); } else if (win_in_chat()) { char *tiny = tinyurl_get(url); - + if (tiny != NULL) { char *recipient = win_get_recipient(); jabber_send(tiny, recipient); @@ -781,12 +784,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) } else { cons_bad_show("Couldn't get tinyurl."); } - - free(url); } else { cons_bad_command(inp); - free(url); } + free(url); } else { cons_show("Usage: %s", help.usage);