1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge remote-tracking branch 'origin/master' into plugins

Conflicts:
	.gitignore
	.travis.yml
	Makefile.am
	src/main.c
	src/profanity.c
	src/ui/console.c
	src/ui/core.c
	src/xmpp/capabilities.c
	src/xmpp/iq.c
This commit is contained in:
James Booth 2014-03-06 19:46:53 +00:00
commit 917a0c7867
27 changed files with 409 additions and 107 deletions

5
.gitignore vendored
View File

@ -33,6 +33,11 @@ core
bugs/
*.pyc
TODO
plugins/
*_key.txt
*_fingerprints.txt
src/gitversion.h
src/gitversion.h.in
_configs.sed
gource.sh
.libs/

View File

@ -3,7 +3,6 @@ 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 python-dev ruby1.8-dev liblualib50
- ./bootstrap.sh
- git clone git://github.com/strophe/libstrophe.git
- cd libstrophe
- ./bootstrap.sh

View File

@ -1,17 +1,3 @@
if INCLUDE_GIT_VERSION
src/gitversion.c: .git/HEAD .git/index
rm -f src/gitversion.c src/gitversion.o
echo "#ifndef PROF_GIT_BRANCH" >> $@
echo "#define PROF_GIT_BRANCH \"$(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)\"" >> $@
echo "#endif" >> $@
echo "#ifndef PROF_GIT_REVISION" >> $@
echo "#define PROF_GIT_REVISION \"$(shell git log --pretty=format:'%h' -n 1)\"" >> $@
echo "#endif" >> $@
clean-local:
rm -f src/gitversion.c src/gitversion.o
endif
core_sources = \
src/contact.c src/contact.h src/log.c src/common.c \
src/log.h src/profanity.c src/common.h \
@ -25,11 +11,11 @@ core_sources = \
src/xmpp/capabilities.h src/xmpp/connection.h \
src/xmpp/roster.c src/xmpp/roster.h \
src/xmpp/bookmark.c src/xmpp/bookmark.h \
src/server_events.c src/server_events.h \
src/server_events.c src/server_events.h \
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/console.c src/ui/notifier.c \
src/ui/windows.c src/ui/windows.h \
src/ui/windows.c src/ui/windows.h \
src/command/command.h src/command/command.c src/command/history.c \
src/command/commands.h src/command/commands.c \
src/command/history.h src/tools/parser.c \
@ -45,7 +31,7 @@ core_sources = \
src/plugins/api.h src/plugins/api.c \
src/plugins/callbacks.h src/plugins/callbacks.c
test_sources = \
tests_sources = \
src/contact.c src/contact.h src/common.c \
src/log.h src/profanity.c src/common.h \
src/profanity.h src/chat_session.c \
@ -94,7 +80,7 @@ test_sources = \
tests/test_preferences.c \
tests/test_server_events.c \
tests/test_muc.c \
tests/testsuite.c
tests/testsuite.c
main_source = src/main.c
@ -114,71 +100,50 @@ c_sources = \
src/plugins/c_plugins.h src/plugins/c_plugins.c \
src/plugins/c_api.h src/plugins/c_api.c
git_sources = \
src/gitversion.c
git_include = src/gitversion.h
otr3_sources = \
src/otr/otrlib.h src/otr/otrlibv3.c src/otr/otr.h src/otr/otr.c
src/otr/otrlib.h src/otr/otrlibv3.c src/otr/otr.h src/otr/otr.c
otr4_sources = \
src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c
if BUILD_PYTHON_API
with_python_sources = $(core_sources) $(python_sources)
tests_with_python_sources = $(test_sources) $(python_sources)
else
with_python_sources = $(core_sources)
tests_with_python_sources = $(test_sources)
core_sources += $(python_sources)
tests_sources += $(python_sources)
endif
if BUILD_RUBY_API
with_ruby_sources = $(with_python_sources) $(ruby_sources)
tests_with_ruby_sources = $(tests_with_python_sources) $(ruby_sources)
else
with_ruby_sources = $(with_python_sources)
tests_with_ruby_sources = $(tests_with_python_sources)
core_sources += $(ruby_sources)
tests_sources += $(ruby_sources)
endif
if BUILD_LUA_API
with_lua_sources = $(with_ruby_sources) $(lua_sources)
tests_with_lua_sources = $(tests_with_ruby_sources) $(lua_sources)
else
with_lua_sources = $(with_ruby_sources)
test_with_lua_sources = $(tests_with_ruby_sources)
core_sources += $(lua_sources)
tests_sources += $(lua_sources)
endif
if BUILD_C_API
with_c_sources = $(with_lua_sources) $(c_sources)
tests_with_c_sources = $(tests_with_lua_sources) $(c_sources)
else
with_c_sources = $(with_lua_sources)
test_with_c_sources = $(tests_with_lua_sources)
endif
if INCLUDE_GIT_VERSION
with_git_sources = $(git_sources) $(with_c_sources)
tests_with_git_sources = $(git_sources) $(tests_with_c_sources)
else
with_git_sources = $(with_c_sources)
tests_with_git_sources = $(tests_with_c_sources)
core_sources += $(c_sources)
tests_sources += $(c_sources)
endif
if BUILD_OTR
if BUILD_OTR3
with_otr_sources = $(with_git_sources) $(otr3_sources)
tests_with_otr_sources = $(tests_with_git_sources) $(otr3_sources)
core_sources += $(otr3_sources)
tests_sources += $(otr3_sources)
endif
if BUILD_OTR4
with_otr_sources = $(with_git_sources) $(otr4_sources)
tests_with_otr_sources = $(tests_with_git_sources) $(otr4_sources)
core_sources += $(otr4_sources)
tests_sources += $(otr4_sources)
endif
else
with_otr_sources = $(with_git_sources)
tests_with_otr_sources = $(tests_with_git_sources)
endif
bin_PROGRAMS = profanity
profanity_SOURCES = $(with_otr_sources) $(main_source)
profanity_SOURCES = $(core_sources) $(main_source)
if INCLUDE_GIT_VERSION
BUILT_SOURCES = $(git_include)
endif
if BUILD_C_API
lib_LTLIBRARIES = libprofanity.la
@ -191,7 +156,29 @@ endif
TESTS = tests/testsuite
check_PROGRAMS = tests/testsuite
tests_testsuite_SOURCES = $(tests_with_otr_sources)
tests_testsuite_SOURCES = $(tests_sources)
tests_testsuite_LDADD = -lcmocka
man_MANS = docs/profanity.1
if INCLUDE_GIT_VERSION
$(git_include).in: .git/HEAD .git/index
rm -f $@
echo "#ifndef PROF_GIT_BRANCH" >> $@
echo "#define PROF_GIT_BRANCH \"$(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)\"" >> $@
echo "#endif" >> $@
echo "#ifndef PROF_GIT_REVISION" >> $@
echo "#define PROF_GIT_REVISION \"$(shell git log --pretty=format:'%h' -n 1)\"" >> $@
echo "#endif" >> $@
#
# Create $(git_include) atomically to catch possible race. The race can occur
# when $(git_include) is generated in parallel with building of src/profanity.c.
# So this hack allows to find and fix the problem earlier.
#
$(git_include): $(git_include).in
cp $< $@
clean-local:
rm -f $(git_include) $(git_include).in
endif

View File

@ -1,4 +1,4 @@
Profanity
Profanity [![Build Status](https://travis-ci.org/boothj5/profanity.png?branch=master)](https://travis-ci.org/boothj5/profanity)
=========
Profanity is a console based XMPP client inspired by [Irssi](http://www.irssi.org/),

View File

@ -24,7 +24,13 @@ AC_PROG_CC
### Get canonical host
AC_CANONICAL_HOST
AS_IF([test "x$host_os" = xcygwin],
PLATFORM="unknown"
AS_CASE([$host_os],
[darwin*], [PLATFORM="osx"],
[cygwin], [PLATFORM="cygwin"],
[PLATFORM="nix"])
AS_IF([test "x$PLATFORM" = xcygwin],
[AC_DEFINE([PLATFORM_CYGWIN], [1], [Cygwin])])
### Options
@ -210,12 +216,28 @@ 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])])
AS_IF([test "x$enable_notifications" != xno],
[PKG_CHECK_MODULES([libnotify], [libnotify],
[AC_DEFINE([HAVE_LIBNOTIFY], [1], [libnotify module])],
[AS_IF([test "x$enable_notifications" = xyes],
[AC_MSG_ERROR([libnotify is required but does not exist])],
[AC_MSG_NOTICE([libnotify support will be disabled])])])])
### Check for desktop notification support
### Linux requires libnotify
### Windows uses native OS calls
### OSX requires terminal-notifier
AS_IF([test "x$PLATFORM" = xosx],
[AS_IF([test "x$enable_notifications" != xno],
[NOTIFIER_PATH="no"
AC_PATH_PROG(NOTIFIER_PATH, terminal-notifier, no)
AS_IF([test "x$NOTIFIER_PATH" = xno],
[AS_IF([test "x$enable_notifications" = xyes],
[AC_MSG_ERROR([terminal-notifier not found, required for desktop notifications.])],
[AC_MSG_NOTICE([Desktop notifications not supported.])])],
[AC_DEFINE([HAVE_OSXNOTIFY], [1], [terminal notifier])])])],
[test "x$PLATFORM" = xnix],
[AS_IF([test "x$enable_notifications" != xno],
[PKG_CHECK_MODULES([libnotify], [libnotify],
[AC_DEFINE([HAVE_LIBNOTIFY], [1], [libnotify module])],
[AS_IF([test "x$enable_notifications" = xyes],
[AC_MSG_ERROR([libnotify is required but does not exist])],
[AC_MSG_NOTICE([libnotify support will be disabled])])])])])
# TODO: rewrite this
if test "x$with_xscreensaver" = xyes; then
@ -262,7 +284,7 @@ elif test "x$enable_otr" = x; then
]])],
[AM_CONDITIONAL([BUILD_OTR], [true]) AM_CONDITIONAL([BUILD_OTR4], [true]) AC_DEFINE([HAVE_LIBOTR], [1], [Have libotr])],
[AM_CONDITIONAL([BUILD_OTR], [true]) AM_CONDITIONAL([BUILD_OTR3], [true]) AC_DEFINE([HAVE_LIBOTR], [1], [Have libotr])])],
[AC_MSG_NOTICE([libotr not found, otr entryption support not enabled])])
[AC_MSG_NOTICE([libotr not found, otr encryption support not enabled])])
fi
### cmocka is required only for tests, profanity shouldn't be linked with it
@ -294,6 +316,7 @@ AC_CONFIG_FILES([Makefile])
AC_OUTPUT
echo ""
echo "PLATFORM : $host_os"
echo "PACKAGE_STATUS : $PACKAGE_STATUS"
echo "AM_CFLAGS : $AM_CFLAGS"
echo "AM_CPPFLAGS : $AM_CPPFLAGS"

View File

@ -1,7 +1,19 @@
#!/bin/sh
#!/bin/bash
set -o errtrace
STATUS=development
error_handler()
{
ERR_CODE=$?
echo "Error $ERR_CODE with command '$BASH_COMMAND' on line ${BASH_LINENO[0]}. Exiting."
exit $ERR_CODE
}
trap error_handler ERR
debian_prepare()
{
echo
@ -23,7 +35,7 @@ fedora_prepare()
echo
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
}
@ -39,14 +51,12 @@ 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
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
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
ln -s /usr/bin/gcc-3.exe /usr/bin/gcc.exe
export LIBRARY_PATH=/usr/local/lib/
}

View File

@ -68,6 +68,7 @@ static char * _otr_autocomplete(char *input, int *size);
static char * _connect_autocomplete(char *input, int *size);
static char * _statuses_autocomplete(char *input, int *size);
static char * _alias_autocomplete(char *input, int *size);
static char * _join_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -234,9 +235,9 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/join",
cmd_join, parse_args_with_freetext, 1, 2, NULL,
{ "/join room[@server] [nick]", "Join a chat room.",
{ "/join room[@server] [nick]",
cmd_join, parse_args, 1, 5, NULL,
{ "/join room[@server] [nick value] [passwd value]", "Join a chat room.",
{ "/join room[@server] [nick value] [passwd value]",
"--------------------------",
"Join a chat room at the conference server.",
"If nick is specified you will join with this nickname.",
@ -245,7 +246,8 @@ static struct cmd_t command_defs[] =
"If the room doesn't exist, and the server allows it, a new one will be created.",
"",
"Example : /join jdev@conference.jabber.org",
"Example : /join jdev@conference.jabber.org mynick",
"Example : /join jdev@conference.jabber.org nick mynick",
"Example : /join private@conference.jabber.org nick mynick passwd mypassword",
"Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
NULL } } },
@ -887,6 +889,7 @@ static Autocomplete statuses_ac;
static Autocomplete statuses_cons_chat_ac;
static Autocomplete alias_ac;
static Autocomplete aliases_ac;
static Autocomplete join_property_ac;
/*
* Initialise command autocompleter and history
@ -1075,6 +1078,10 @@ cmd_init(void)
autocomplete_add(connect_property_ac, "server");
autocomplete_add(connect_property_ac, "port");
join_property_ac = autocomplete_new();
autocomplete_add(join_property_ac, "nick");
autocomplete_add(join_property_ac, "passwd");
statuses_ac = autocomplete_new();
autocomplete_add(statuses_ac, "console");
autocomplete_add(statuses_ac, "chat");
@ -1127,6 +1134,7 @@ cmd_uninit(void)
autocomplete_free(statuses_cons_chat_ac);
autocomplete_free(alias_ac);
autocomplete_free(aliases_ac);
autocomplete_free(join_property_ac);
}
gboolean
@ -1249,6 +1257,7 @@ cmd_reset_autocomplete()
autocomplete_reset(statuses_cons_chat_ac);
autocomplete_reset(alias_ac);
autocomplete_reset(aliases_ac);
autocomplete_reset(join_property_ac);
bookmark_autocomplete_reset();
}
@ -1514,13 +1523,6 @@ _cmd_complete_parameters(char *input, int *size)
}
}
result = autocomplete_param_with_func(input, size, "/join", bookmark_find);
if (result != NULL) {
inp_replace_input(input, result, size);
g_free(result);
return;
}
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac };
@ -1537,7 +1539,8 @@ _cmd_complete_parameters(char *input, int *size)
_autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete,
_connect_autocomplete, _statuses_autocomplete, _alias_autocomplete };
_connect_autocomplete, _statuses_autocomplete, _alias_autocomplete,
_join_autocomplete };
for (i = 0; i < ARRAY_SIZE(acs); i++) {
result = acs[i](input, size);
@ -1892,6 +1895,33 @@ _connect_autocomplete(char *input, int *size)
return NULL;
}
static char *
_join_autocomplete(char *input, int *size)
{
char *result = NULL;
input[*size] = '\0';
gchar **args = parse_args(input, 2, 4);
if ((strncmp(input, "/join", 5) == 0) && (args != NULL)) {
GString *beginning = g_string_new("/join ");
g_string_append(beginning, args[0]);
if (args[1] != NULL && args[2] != NULL) {
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
result = autocomplete_param_with_ac(input, size, beginning->str, join_property_ac);
g_string_free(beginning, TRUE);
if (result != NULL) {
return result;
}
}
return NULL;
}
static char *
_account_autocomplete(char *input, int *size)
{

View File

@ -1597,6 +1597,7 @@ cmd_join(gchar **args, struct cmd_help_t help)
int num_args = g_strv_length(args);
char *room = NULL;
char *nick = NULL;
char *passwd = NULL;
GString *room_str = g_string_new("");
Jid *my_jid = jid_create(jabber_get_fulljid());
@ -1612,19 +1613,50 @@ cmd_join(gchar **args, struct cmd_help_t help)
room = room_str->str;
}
// nick supplied
if (num_args == 2) {
nick = args[1];
// Additional args supplied
if (num_args > 1) {
char *opt1 = args[1];
char *opt1val = args[2];
char *opt2 = args[3];
char *opt2val = args[4];
if (opt1 != NULL) {
if (opt1val == NULL) {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (strcmp(opt1, "nick") == 0) {
nick = opt1val;
} else if (strcmp(opt1, "passwd") == 0) {
passwd = opt1val;
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
if (opt2 != NULL) {
if (strcmp(opt2, "nick") == 0) {
nick = opt2val;
} else if (strcmp(opt2, "passwd") == 0) {
passwd = opt2val;
} else {
cons_show("Usage: %s", help.usage);
cons_show("");
return TRUE;
}
}
}
}
// otherwise use account preference
} else {
// In the case that a nick wasn't provided by the optional args...
if (nick == NULL) {
nick = account->muc_nick;
}
Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
if (!muc_room_is_active(room_jid)) {
presence_join_room(room_jid);
presence_join_room(room_jid, passwd);
}
ui_room_join(room_jid);
muc_remove_invite(room);
@ -2642,9 +2674,13 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_keygen(account);
return TRUE;
} else if (strcmp(args[0], "myfp") == 0) {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "theirfp") == 0) {
win_type_t win_type = ui_current_win_type();

View File

@ -24,7 +24,7 @@
#include "prof_config.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
#include "profanity.h"

View File

@ -22,7 +22,7 @@
#include "prof_config.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
#include <locale.h>

View File

@ -41,7 +41,7 @@
#include "xmpp/bookmark.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
static void _cons_splash_logo(void);

View File

@ -23,7 +23,7 @@
#include "prof_config.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
#include <stdlib.h>

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#ifdef PROF_HAVE_LIBNOTIFY
@ -202,6 +203,31 @@ _notify(const char * const message, int timeout,
Shell_NotifyIcon(NIM_MODIFY, &nid);
#endif
#ifdef HAVE_OSXNOTIFY
GString *notify_command = g_string_new("terminal-notifier -title 'Profanity' -message '");
g_string_append(notify_command, message);
g_string_append(notify_command, "'");
char *term_name = getenv("TERM_PROGRAM");
char *app_id = NULL;
if (g_strcmp0(term_name, "Apple_Terminal") == 0) {
app_id = "com.apple.Terminal";
} else if (g_strcmp0(term_name, "iTerm.app") == 0) {
app_id = "com.googlecode.iterm2";
}
if (app_id != NULL) {
g_string_append(notify_command, " -sender ");
g_string_append(notify_command, app_id);
}
int res = system(notify_command->str);
if (res == -1) {
log_error("Could not send desktop notificaion.");
}
g_string_free(notify_command, TRUE);
#endif
}
void

View File

@ -301,7 +301,7 @@ _bookmark_handle_result(xmpp_conn_t * const conn,
log_debug("Autojoin %s with nick=%s", jid, name);
room_jid = jid_create_from_bare_and_resource(jid, name);
if (!muc_room_is_active(room_jid)) {
presence_join_room(room_jid);
presence_join_room(room_jid, NULL);
/* TODO: this should be removed after fixing #195 */
ui_room_join(room_jid);
}

View File

@ -23,7 +23,7 @@
#include "prof_config.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
#include <stdlib.h>

View File

@ -23,7 +23,7 @@
#include "prof_config.h"
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.c"
#include "gitversion.h"
#endif
#include <stdlib.h>

View File

@ -260,7 +260,7 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence)
}
static void
_presence_join_room(Jid *jid)
_presence_join_room(Jid *jid, char * passwd)
{
assert(jid != NULL);
assert(jid->fulljid != NULL);
@ -275,7 +275,7 @@ _presence_join_room(Jid *jid)
int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),
presence_type);
xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid);
xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid, passwd);
stanza_attach_show(ctx, presence, show);
stanza_attach_status(ctx, presence, status);
stanza_attach_priority(ctx, presence, pri);

View File

@ -249,7 +249,7 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
xmpp_stanza_t *
stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
const char * const full_room_jid)
const char * const full_room_jid, const char * const passwd)
{
xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
@ -260,6 +260,19 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(x, STANZA_NAME_X);
xmpp_stanza_set_ns(x, STANZA_NS_MUC);
// if a password was given
if (passwd != NULL) {
xmpp_stanza_t *pass = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(pass, "password");
xmpp_stanza_t *text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(text, strdup(passwd));
xmpp_stanza_add_child(pass, text);
xmpp_stanza_add_child(x, pass);
xmpp_stanza_release(text);
xmpp_stanza_release(pass);
}
xmpp_stanza_add_child(presence, x);
xmpp_stanza_release(x);

View File

@ -158,7 +158,7 @@ xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx,
const char * const message, const char * const state);
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
const char * const full_room_jid);
const char * const full_room_jid, const char * const passwd);
xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx,
const char * const full_room_jid);

View File

@ -114,7 +114,7 @@ GSList* (*presence_get_subscription_requests)(void);
gint (*presence_sub_request_count)(void);
void (*presence_reset_sub_request_search)(void);
char * (*presence_sub_request_find)(char * search_str);
void (*presence_join_room)(Jid *jid);
void (*presence_join_room)(Jid *jid, char * passwd);
void (*presence_change_room_nick)(const char * const room, const char * const nick);
void (*presence_leave_chat_room)(const char * const room_jid);
void (*presence_update)(resource_presence_t status, const char * const msg,

View File

@ -34,6 +34,18 @@ _mock_otr_get_their_fingerprint(const char * const recipient)
return (char *)mock();
}
static gboolean
_mock_otr_key_loaded(void)
{
return (gboolean)mock();
}
static char *
_mock_otr_start_query(void)
{
return (char *)mock();
}
void
otr_keygen_expect(ProfAccount *account)
{
@ -62,3 +74,17 @@ otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint)
expect_string(_mock_otr_get_their_fingerprint, recipient, recipient);
will_return(_mock_otr_get_their_fingerprint, fingerprint);
}
void
otr_key_loaded_returns(gboolean loaded)
{
otr_key_loaded = _mock_otr_key_loaded;
will_return(_mock_otr_key_loaded, loaded);
}
void
otr_start_query_returns(char *query)
{
otr_start_query = _mock_otr_start_query;
will_return(_mock_otr_start_query, query);
}

View File

@ -4,10 +4,13 @@
#include "config/account.h"
void otr_keygen_expect(ProfAccount *account);
void otr_key_loaded_returns(gboolean loaded);
void otr_libotr_version_returns(char *version);
void otr_get_my_fingerprint_returns(char *fingerprint);
void otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint);
void otr_start_query_returns(char *query);
#endif

View File

@ -366,12 +366,29 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
}
void cmd_otr_myfp_shows_message_when_no_key(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "myfp", NULL };
mock_connection_status(JABBER_CONNECTED);
otr_key_loaded_returns(FALSE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_myfp_shows_my_fingerprint(void **state)
{
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "myfp", NULL };
mock_connection_status(JABBER_CONNECTED);
otr_key_loaded_returns(TRUE);
otr_get_my_fingerprint_returns(strdup(fingerprint));
mock_ui_current_print_formatted_line();
@ -468,6 +485,100 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
free(help);
}
static void
test_cmd_otr_start_from_wintype(win_type_t wintype)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(wintype);
mock_ui_current_print_line();
ui_current_print_line_expect("You must be in a regular chat window to start an OTR session.");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_start_shows_message_when_in_console(void **state)
{
test_cmd_otr_start_from_wintype(WIN_CONSOLE);
}
void cmd_otr_start_shows_message_when_in_muc(void **state)
{
test_cmd_otr_start_from_wintype(WIN_MUC);
}
void cmd_otr_start_shows_message_when_in_private(void **state)
{
test_cmd_otr_start_from_wintype(WIN_PRIVATE);
}
void cmd_otr_start_shows_message_when_in_duck(void **state)
{
test_cmd_otr_start_from_wintype(WIN_DUCK);
}
void cmd_otr_start_shows_message_when_already_started(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(TRUE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You are already in an OTR session.");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_start_shows_message_when_no_key(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(FALSE);
otr_key_loaded_returns(FALSE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void
cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
{
char *recipient = "buddy@chat.com";
char *query_message = "?OTR?";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(FALSE);
otr_key_loaded_returns(TRUE);
ui_current_recipient_returns(recipient);
otr_start_query_returns(query_message);
message_send_expect(query_message, recipient);
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
#else
void cmd_otr_shows_message_when_otr_unsupported(void **state)
{

View File

@ -27,6 +27,7 @@ void cmd_otr_myfp_shows_message_when_undefined(void **state);
void cmd_otr_myfp_shows_message_when_started(void **state);
void cmd_otr_myfp_shows_message_when_connecting(void **state);
void cmd_otr_myfp_shows_message_when_disconnecting(void **state);
void cmd_otr_myfp_shows_message_when_no_key(void **state);
void cmd_otr_myfp_shows_my_fingerprint(void **state);
void cmd_otr_theirfp_shows_message_when_in_console(void **state);
void cmd_otr_theirfp_shows_message_when_in_muc(void **state);
@ -34,6 +35,13 @@ void cmd_otr_theirfp_shows_message_when_in_private(void **state);
void cmd_otr_theirfp_shows_message_when_in_duck(void **state);
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state);
void cmd_otr_theirfp_shows_fingerprint(void **state);
void cmd_otr_start_shows_message_when_in_console(void **state);
void cmd_otr_start_shows_message_when_in_muc(void **state);
void cmd_otr_start_shows_message_when_in_private(void **state);
void cmd_otr_start_shows_message_when_in_duck(void **state);
void cmd_otr_start_shows_message_when_already_started(void **state);
void cmd_otr_start_shows_message_when_no_key(void **state);
void cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state);
#else
void cmd_otr_shows_message_when_otr_unsupported(void **state);
#endif

View File

@ -468,6 +468,7 @@ int main(int argc, char* argv[]) {
unit_test(cmd_otr_myfp_shows_message_when_started),
unit_test(cmd_otr_myfp_shows_message_when_connecting),
unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
unit_test(cmd_otr_myfp_shows_message_when_no_key),
unit_test(cmd_otr_myfp_shows_my_fingerprint),
unit_test(cmd_otr_theirfp_shows_message_when_in_console),
unit_test(cmd_otr_theirfp_shows_message_when_in_muc),
@ -475,6 +476,13 @@ int main(int argc, char* argv[]) {
unit_test(cmd_otr_theirfp_shows_message_when_in_duck),
unit_test(cmd_otr_theirfp_shows_message_when_non_otr_chat_window),
unit_test(cmd_otr_theirfp_shows_fingerprint),
unit_test(cmd_otr_start_shows_message_when_in_console),
unit_test(cmd_otr_start_shows_message_when_in_muc),
unit_test(cmd_otr_start_shows_message_when_in_private),
unit_test(cmd_otr_start_shows_message_when_in_duck),
unit_test(cmd_otr_start_shows_message_when_already_started),
unit_test(cmd_otr_start_shows_message_when_no_key),
unit_test(cmd_otr_start_sends_otr_query_message_to_current_recipeint),
#else
unit_test(cmd_otr_shows_message_when_otr_unsupported),
#endif

View File

@ -81,6 +81,13 @@ _mock_bookmark_remove(const char *jid, gboolean autojoin)
return (gboolean)mock();
}
static void
_mock_message_send(const char * const msg, const char * const recipient)
{
check_expected(msg);
check_expected(recipient);
}
void
mock_jabber_connect_with_details(void)
{
@ -219,3 +226,11 @@ expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin
will_return(_mock_bookmark_remove, removed);
}
void
message_send_expect(char *message, char *recipient)
{
message_send = _mock_message_send;
expect_string(_mock_message_send, msg, message);
expect_string(_mock_message_send, recipient, recipient);
}

View File

@ -31,4 +31,6 @@ void mock_bookmark_remove(void);
void expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin,
gboolean removed);
void message_send_expect(char *message, char *recipient);
#endif