mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge branch 'master' into osx-functional
This commit is contained in:
commit
aa9104644a
@ -3,6 +3,7 @@
|
||||
|
||||
- Plugins API supporting C and Python plugins
|
||||
- SSL certificate verification (requires libmesode) (/tls)
|
||||
- HTTP file uplaod (xep-0363) (/sendfile)
|
||||
- Allow auto extended away (/autoaway)
|
||||
- Include last acitvity in initial presence (xep-0256) (/lastactivity)
|
||||
- Last Activity (xep-0012) (/lastactivity)
|
||||
|
@ -32,6 +32,8 @@ core_sources = \
|
||||
src/command/commands.h src/command/commands.c \
|
||||
src/tools/parser.c \
|
||||
src/tools/parser.h \
|
||||
src/tools/http_upload.c \
|
||||
src/tools/http_upload.h \
|
||||
src/tools/p_sha1.h src/tools/p_sha1.c \
|
||||
src/tools/autocomplete.c src/tools/autocomplete.h \
|
||||
src/tools/tinyurl.c src/tools/tinyurl.h \
|
||||
@ -90,6 +92,7 @@ unittest_sources = \
|
||||
tests/unittests/ui/stub_ui.c \
|
||||
tests/unittests/log/stub_log.c \
|
||||
tests/unittests/config/stub_accounts.c \
|
||||
tests/unittests/tools/stub_http_upload.c \
|
||||
tests/unittests/helpers.c tests/unittests/helpers.h \
|
||||
tests/unittests/test_form.c tests/unittests/test_form.h \
|
||||
tests/unittests/test_common.c tests/unittests/test_common.h \
|
||||
|
10
configure.ac
10
configure.ac
@ -116,6 +116,12 @@ else
|
||||
AM_CONDITIONAL([BUILD_C_API], [false])
|
||||
fi
|
||||
|
||||
# threading
|
||||
ACX_PTHREAD
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
CC="$PTHREAD_CC"
|
||||
|
||||
### Check for libmesode, fall back to libstrophe
|
||||
PKG_CHECK_MODULES([libmesode], [libmesode],
|
||||
[LIBS="$libmesode_LIBS $LIBS" CFLAGS="$CFLAGS $libmesode_CFLAGS" AC_DEFINE([HAVE_LIBMESODE], [1], [libmesode])],
|
||||
@ -282,10 +288,12 @@ AC_CHECK_HEADERS([ncurses.h], [], [])
|
||||
AM_CFLAGS="-Wall -Wno-deprecated-declarations"
|
||||
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
|
||||
[AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"])
|
||||
AS_IF([test "x$PLATFORM" = xosx],
|
||||
[AM_CFLAGS="$AM_CFLAGS -Qunused-arguments"])
|
||||
AM_LDFLAGS="$AM_LDFLAGS -export-dynamic"
|
||||
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $PYTHON_CPPFLAGS ${GTK_CFLAGS}"
|
||||
AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\""
|
||||
LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $PYTHON_LIBS $PYTHON_LDFLAGS ${GTK_LIBS} $LIBS"
|
||||
LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $PYTHON_LIBS $PYTHON_LDFLAGS ${GTK_LIBS} -lgio-2.0 $LIBS"
|
||||
|
||||
AC_SUBST(AM_LDFLAGS)
|
||||
AC_SUBST(AM_CFLAGS)
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -50,27 +50,41 @@ typedef struct cmd_help_t {
|
||||
* Command structure
|
||||
*
|
||||
* cmd - The command string including leading '/'
|
||||
* func - The function to execute for the command
|
||||
* parser - The function used to parse arguments
|
||||
* min_args - Minimum number of arguments
|
||||
* max_args - Maximum number of arguments
|
||||
* setting_func - Function to display current settings to the console
|
||||
* sub_funcs - Optional list of functions mapped to the first argument
|
||||
* func - Main function to call when no arguments, or sub_funcs not implemented
|
||||
* help - A help struct containing usage info etc
|
||||
*/
|
||||
typedef struct cmd_t {
|
||||
gchar *cmd;
|
||||
gboolean (*func)(ProfWin *window, const char *const command, gchar **args);
|
||||
gchar** (*parser)(const char *const inp, int min, int max, gboolean *result);
|
||||
int min_args;
|
||||
int max_args;
|
||||
void (*setting_func)(void);
|
||||
void *sub_funcs[50][2];
|
||||
gboolean (*func)(ProfWin *window, const char *const command, gchar **args);
|
||||
CommandHelp help;
|
||||
} Command;
|
||||
|
||||
gboolean cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran);
|
||||
gboolean cmd_execute_default(ProfWin *window, const char *inp);
|
||||
|
||||
gboolean cmd_about(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_account(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_list(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_show(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_add(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_remove(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_enable(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_disable(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_rename(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_default(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_set(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_account_clear(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_autoaway(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_autoconnect(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_autoping(ProfWin *window, const char *const command, gchar **args);
|
||||
@ -82,13 +96,22 @@ gboolean cmd_chlog(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_clear(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_close(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_connect(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_tls_certpath(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls_trust(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls_trusted(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls_revoke(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls_show(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tls_cert(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_decline(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_disco(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_sendfile(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_lastactivity(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_disconnect(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_dnd(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_flash(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_tray(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_gone(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_grlog(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_group(ProfWin *window, const char *const command, gchar **args);
|
||||
@ -107,7 +130,22 @@ gboolean cmd_msg(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_nick(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_notify(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_online(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_otr_char(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_log(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_libver(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_policy(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_gen(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_myfp(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_theirfp(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_start(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_end(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_trust(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_untrust(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_secret(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_question(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_otr_answer(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_pgp(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_outtype(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_prefs(ProfWin *window, const char *const command, gchar **args);
|
||||
@ -130,7 +168,14 @@ gboolean cmd_titlebar(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_vercheck(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_who(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_win(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_wins_unread(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_wins_swap(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_xa(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_alias(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args);
|
||||
|
@ -1239,6 +1239,7 @@ _get_group(preference_t pref)
|
||||
case PREF_NOTIFY_SUB:
|
||||
case PREF_NOTIFY_MENTION_CASE_SENSITIVE:
|
||||
case PREF_NOTIFY_MENTION_WHOLE_WORD:
|
||||
case PREF_TRAY:
|
||||
return PREF_GROUP_NOTIFICATIONS;
|
||||
case PREF_CHLOG:
|
||||
case PREF_GRLOG:
|
||||
@ -1289,6 +1290,8 @@ _get_key(preference_t pref)
|
||||
return "titlebar.goodbye";
|
||||
case PREF_FLASH:
|
||||
return "flash";
|
||||
case PREF_TRAY:
|
||||
return "tray";
|
||||
case PREF_INTYPE:
|
||||
return "intype";
|
||||
case PREF_HISTORY:
|
||||
@ -1502,6 +1505,7 @@ _get_default_boolean(preference_t pref)
|
||||
case PREF_TLS_SHOW:
|
||||
case PREF_LASTACTIVITY:
|
||||
case PREF_NOTIFY_MENTION_WHOLE_WORD:
|
||||
case PREF_TRAY:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
|
@ -52,6 +52,7 @@ typedef enum {
|
||||
PREF_TITLEBAR_SHOW,
|
||||
PREF_TITLEBAR_GOODBYE,
|
||||
PREF_FLASH,
|
||||
PREF_TRAY,
|
||||
PREF_INTYPE,
|
||||
PREF_HISTORY,
|
||||
PREF_CARBONS,
|
||||
|
@ -106,7 +106,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
|
||||
}
|
||||
|
||||
void
|
||||
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
chat_state_active(chatwin->state);
|
||||
char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
|
||||
@ -122,7 +122,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
} else {
|
||||
gboolean handled = otr_on_message_send(chatwin, plugin_msg);
|
||||
if (!handled) {
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg);
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url);
|
||||
chat_log_msg_out(chatwin->barejid, plugin_msg);
|
||||
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
@ -140,7 +140,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
#ifndef HAVE_LIBGPGME
|
||||
gboolean handled = otr_on_message_send(chatwin, plugin_msg);
|
||||
if (!handled) {
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg);
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url);
|
||||
chat_log_msg_out(chatwin->barejid, plugin_msg);
|
||||
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
@ -161,7 +161,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP);
|
||||
free(id);
|
||||
} else {
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg);
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url);
|
||||
chat_log_msg_out(chatwin->barejid, plugin_msg);
|
||||
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
@ -176,7 +176,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
// OTR unsupported, PGP unsupported
|
||||
#ifndef HAVE_LIBOTR
|
||||
#ifndef HAVE_LIBGPGME
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg);
|
||||
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url);
|
||||
chat_log_msg_out(chatwin->barejid, plugin_msg);
|
||||
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
@ -189,18 +189,18 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
|
||||
}
|
||||
|
||||
void
|
||||
cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg)
|
||||
cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
char *plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg);
|
||||
|
||||
message_send_groupchat(mucwin->roomjid, plugin_msg);
|
||||
message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url);
|
||||
|
||||
plugins_post_room_message_send(mucwin->roomjid, plugin_msg);
|
||||
free(plugin_msg);
|
||||
}
|
||||
|
||||
void
|
||||
cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg)
|
||||
cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
if (privwin->occupant_offline) {
|
||||
privwin_message_occupant_offline(privwin);
|
||||
@ -209,7 +209,7 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg)
|
||||
} else {
|
||||
char *plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg);
|
||||
|
||||
message_send_private(privwin->fulljid, plugin_msg);
|
||||
message_send_private(privwin->fulljid, plugin_msg, oob_url);
|
||||
privwin_outgoing_msg(privwin, plugin_msg);
|
||||
|
||||
plugins_post_priv_message_send(privwin->fulljid, plugin_msg);
|
||||
|
@ -42,8 +42,8 @@ void cl_ev_disconnect(void);
|
||||
|
||||
void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs);
|
||||
|
||||
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg);
|
||||
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg);
|
||||
void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg);
|
||||
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url);
|
||||
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url);
|
||||
void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, const char *const oob_url);
|
||||
|
||||
#endif
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "window_list.h"
|
||||
#include "contact.h"
|
||||
#include "ui/ui.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "config/preferences.h"
|
||||
#include "chat_session.h"
|
||||
|
||||
|
@ -211,6 +211,42 @@ api_get_current_muc(void)
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
api_get_current_nick(void)
|
||||
{
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type == WIN_MUC) {
|
||||
ProfMucWin *mucwin = (ProfMucWin*)current;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
return muc_nick(mucwin->roomjid);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char**
|
||||
api_get_current_occupants(void)
|
||||
{
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type == WIN_MUC) {
|
||||
ProfMucWin *mucwin = (ProfMucWin*)current;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
GList *occupants_list = muc_roster(mucwin->roomjid);
|
||||
char **result = malloc((g_list_length(occupants_list) + 1) * sizeof(char*));
|
||||
GList *curr = occupants_list;
|
||||
int i = 0;
|
||||
while (curr) {
|
||||
Occupant *occupant = curr->data;
|
||||
result[i++] = strdup(occupant->nick);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
result[i] = NULL;
|
||||
return result;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
api_current_win_is_console(void)
|
||||
{
|
||||
|
@ -47,6 +47,8 @@ void api_send_line(char *line);
|
||||
char * api_get_current_recipient(void);
|
||||
char * api_get_current_muc(void);
|
||||
gboolean api_current_win_is_console(void);
|
||||
char* api_get_current_nick(void);
|
||||
char** api_get_current_occupants(void);
|
||||
|
||||
void api_register_command(const char *command_name, int min_args, int max_args,
|
||||
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
|
||||
|
@ -139,11 +139,23 @@ c_api_get_current_muc(void)
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_current_win_is_console()
|
||||
c_api_current_win_is_console(void)
|
||||
{
|
||||
return api_current_win_is_console();
|
||||
}
|
||||
|
||||
static char*
|
||||
c_api_get_current_nick(void)
|
||||
{
|
||||
return api_get_current_nick();
|
||||
}
|
||||
|
||||
static char**
|
||||
c_api_get_current_occupants(void)
|
||||
{
|
||||
return api_get_current_occupants();
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_log_debug(const char *message)
|
||||
{
|
||||
@ -289,6 +301,8 @@ c_api_init(void)
|
||||
prof_get_current_recipient = c_api_get_current_recipient;
|
||||
prof_get_current_muc = c_api_get_current_muc;
|
||||
prof_current_win_is_console = c_api_current_win_is_console;
|
||||
prof_get_current_nick = c_api_get_current_nick;
|
||||
prof_get_current_occupants = c_api_get_current_occupants;
|
||||
prof_log_debug = c_api_log_debug;
|
||||
prof_log_info = c_api_log_info;
|
||||
prof_log_warning = c_api_log_warning;
|
||||
|
@ -113,10 +113,12 @@ c_plugin_create(const char *const filename)
|
||||
}
|
||||
|
||||
void
|
||||
c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status)
|
||||
c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name,
|
||||
const char *const fulljid)
|
||||
{
|
||||
void *f = NULL;
|
||||
void (*func)(const char *const __version, const char *const __status);
|
||||
void (*func)(const char *const __version, const char *const __status, const char *const __account_name,
|
||||
const char *const __fulljid);
|
||||
|
||||
assert(plugin && plugin->module);
|
||||
|
||||
@ -125,10 +127,10 @@ c_init_hook(ProfPlugin *plugin, const char *const version, const char *const sta
|
||||
return;
|
||||
}
|
||||
|
||||
func = (void (*)(const char *const, const char *const))f;
|
||||
func = (void (*)(const char *const, const char *const, const char *const, const char *const))f;
|
||||
|
||||
// FIXME maybe we want to make it boolean to see if it succeeded or not?
|
||||
func(version, status);
|
||||
func(version, status, account_name, fulljid);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -43,7 +43,8 @@ ProfPlugin* c_plugin_create(const char *const filename);
|
||||
void c_plugin_destroy(ProfPlugin *plugin);
|
||||
void c_shutdown(void);
|
||||
|
||||
void c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status);
|
||||
void c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name,
|
||||
const char *const fulljid);
|
||||
void c_on_start_hook(ProfPlugin *plugin);
|
||||
void c_on_shutdown_hook(ProfPlugin *plugin);
|
||||
void c_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);
|
||||
|
@ -114,7 +114,7 @@ plugins_init(void)
|
||||
GSList *curr = plugins;
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS);
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
@ -155,7 +155,13 @@ plugins_load(const char *const name)
|
||||
#endif
|
||||
if (plugin) {
|
||||
plugins = g_slist_append(plugins, plugin);
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS);
|
||||
if (jabber_get_connection_status() == JABBER_CONNECTED) {
|
||||
const char *account_name = jabber_get_account_name();
|
||||
const char *fulljid = jabber_get_fulljid();
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, account_name, fulljid);
|
||||
} else {
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
}
|
||||
log_info("Loaded plugin: %s", name);
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -181,29 +187,30 @@ _get_plugins_dir(void)
|
||||
}
|
||||
|
||||
void
|
||||
_plugins_list_dir(const gchar *const dir, GSList **result)
|
||||
_plugins_unloaded_list_dir(const gchar *const dir, GSList **result)
|
||||
{
|
||||
GDir *plugins = g_dir_open(dir, 0, NULL);
|
||||
if (plugins == NULL) {
|
||||
GDir *plugins_dir = g_dir_open(dir, 0, NULL);
|
||||
if (plugins_dir == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const gchar *plugin = g_dir_read_name(plugins);
|
||||
const gchar *plugin = g_dir_read_name(plugins_dir);
|
||||
while (plugin) {
|
||||
if (g_str_has_suffix(plugin, ".so") || g_str_has_suffix(plugin, ".py")) {
|
||||
GSList *found = g_slist_find_custom(plugins, plugin, (GCompareFunc)_find_by_name);
|
||||
if ((g_str_has_suffix(plugin, ".so") || g_str_has_suffix(plugin, ".py")) && !found) {
|
||||
*result = g_slist_append(*result, strdup(plugin));
|
||||
}
|
||||
plugin = g_dir_read_name(plugins);
|
||||
plugin = g_dir_read_name(plugins_dir);
|
||||
}
|
||||
g_dir_close(plugins);
|
||||
g_dir_close(plugins_dir);
|
||||
}
|
||||
|
||||
GSList*
|
||||
plugins_file_list(void)
|
||||
plugins_unloaded_list(void)
|
||||
{
|
||||
GSList *result = NULL;
|
||||
char *plugins_dir = _get_plugins_dir();
|
||||
_plugins_list_dir(plugins_dir, &result);
|
||||
_plugins_unloaded_list_dir(plugins_dir, &result);
|
||||
free(plugins_dir);
|
||||
|
||||
return result;
|
||||
|
@ -47,7 +47,7 @@ typedef struct prof_plugin_t {
|
||||
lang_t lang;
|
||||
void *module;
|
||||
void (*init_func)(struct prof_plugin_t* plugin, const char * const version,
|
||||
const char * const status);
|
||||
const char * const status, const char *const account_name, const char *const fulljid);
|
||||
|
||||
void (*on_start_func)(struct prof_plugin_t* plugin);
|
||||
void (*on_shutdown_func)(struct prof_plugin_t* plugin);
|
||||
@ -99,7 +99,7 @@ typedef struct prof_plugin_t {
|
||||
|
||||
void plugins_init(void);
|
||||
GSList* plugins_get_list(void);
|
||||
GSList *plugins_file_list(void);
|
||||
GSList *plugins_unloaded_list(void);
|
||||
char* plugins_autocomplete(const char *const input);
|
||||
void plugins_reset_autocomplete(void);
|
||||
void plugins_shutdown(void);
|
||||
|
@ -59,6 +59,8 @@ void (*prof_send_line)(char *line) = NULL;
|
||||
char* (*prof_get_current_recipient)(void) = NULL;
|
||||
char* (*prof_get_current_muc)(void) = NULL;
|
||||
int (*prof_current_win_is_console)(void) = NULL;
|
||||
char* (*prof_get_current_nick)(void) = NULL;
|
||||
char** (*prof_get_current_occupants)(void) = NULL;
|
||||
|
||||
void (*prof_log_debug)(const char *message) = NULL;
|
||||
void (*prof_log_info)(const char *message) = NULL;
|
||||
|
@ -59,6 +59,8 @@ void (*prof_send_line)(char *line);
|
||||
char* (*prof_get_current_recipient)(void);
|
||||
char* (*prof_get_current_muc)(void);
|
||||
int (*prof_current_win_is_console)(void);
|
||||
char* (*prof_get_current_nick)(void);
|
||||
char** (*prof_get_current_occupants)(void);
|
||||
|
||||
void (*prof_log_debug)(const char *message);
|
||||
void (*prof_log_info)(const char *message);
|
||||
|
@ -316,6 +316,38 @@ python_api_get_current_muc(PyObject *self, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_get_current_nick(PyObject *self, PyObject *args)
|
||||
{
|
||||
allow_python_threads();
|
||||
char *nick = api_get_current_nick();
|
||||
disable_python_threads();
|
||||
if (nick) {
|
||||
return Py_BuildValue("s", nick);
|
||||
} else {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_get_current_occupants(PyObject *self, PyObject *args)
|
||||
{
|
||||
allow_python_threads();
|
||||
char **occupants = api_get_current_occupants();
|
||||
disable_python_threads();
|
||||
PyObject *result = PyList_New(0);
|
||||
if (occupants) {
|
||||
int len = g_strv_length(occupants);
|
||||
int i = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
PyList_Append(result, Py_BuildValue("s", occupants[i]));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_current_win_is_console(PyObject *self, PyObject *args)
|
||||
{
|
||||
@ -714,6 +746,8 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "notify", python_api_notify, METH_VARARGS, "Send desktop notification." },
|
||||
{ "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." },
|
||||
{ "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." },
|
||||
{ "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." },
|
||||
{ "get_current_occupants", python_api_get_current_occupants, METH_VARARGS, "Return list of occupants in current room." },
|
||||
{ "current_win_is_console", python_api_current_win_is_console, METH_VARARGS, "Returns whether the current window is the console." },
|
||||
{ "log_debug", python_api_log_debug, METH_VARARGS, "Log a debug message" },
|
||||
{ "log_info", python_api_log_info, METH_VARARGS, "Log an info message" },
|
||||
|
@ -62,27 +62,17 @@ python_env_init(void)
|
||||
Py_Initialize();
|
||||
PyEval_InitThreads();
|
||||
python_api_init();
|
||||
GString *path = g_string_new(Py_GetPath());
|
||||
|
||||
g_string_append(path, ":");
|
||||
GString *path = g_string_new("import sys\n");
|
||||
g_string_append(path, "sys.path.append(\"");
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
g_string_append(path, plugins_dir);
|
||||
g_string_append(path, "/");
|
||||
g_free(plugins_dir);
|
||||
g_string_append(path, "/\")\n");
|
||||
|
||||
PyRun_SimpleString(path->str);
|
||||
|
||||
PySys_SetPath(path->str);
|
||||
g_string_free(path, TRUE);
|
||||
|
||||
// add site packages paths
|
||||
PyRun_SimpleString(
|
||||
"import site\n"
|
||||
"import sys\n"
|
||||
"from distutils.sysconfig import get_python_lib\n"
|
||||
"sys.path.append(get_python_lib())\n"
|
||||
"for dir in site.getsitepackages():\n"
|
||||
" sys.path.append(dir)\n"
|
||||
);
|
||||
|
||||
allow_python_threads();
|
||||
}
|
||||
|
||||
@ -138,10 +128,11 @@ python_plugin_create(const char *const filename)
|
||||
}
|
||||
|
||||
void
|
||||
python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status)
|
||||
python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name,
|
||||
const char *const fulljid)
|
||||
{
|
||||
disable_python_threads();
|
||||
PyObject *p_args = Py_BuildValue("ss", version, status);
|
||||
PyObject *p_args = Py_BuildValue("ssss", version, status, account_name, fulljid);
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
@ -655,7 +646,7 @@ python_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyBool_Check(result)) {
|
||||
if (PyObject_IsTrue(result)) {
|
||||
allow_python_threads();
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -720,7 +711,7 @@ python_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const tex
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyBool_Check(result)) {
|
||||
if (PyObject_IsTrue(result)) {
|
||||
allow_python_threads();
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -785,7 +776,7 @@ python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyBool_Check(result)) {
|
||||
if (PyObject_IsTrue(result)) {
|
||||
allow_python_threads();
|
||||
return TRUE;
|
||||
} else {
|
||||
|
@ -43,7 +43,8 @@ void python_check_error(void);
|
||||
void allow_python_threads();
|
||||
void disable_python_threads();
|
||||
|
||||
void python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status);
|
||||
void python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status,
|
||||
const char *const account_name, const char *const fulljid);
|
||||
void python_on_start_hook(ProfPlugin *plugin);
|
||||
void python_on_shutdown_hook(ProfPlugin *plugin);
|
||||
void python_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);
|
||||
|
@ -38,7 +38,6 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GTK
|
||||
#include <gtk/gtk.h>
|
||||
#include "tray.h"
|
||||
#endif
|
||||
#include <locale.h>
|
||||
@ -96,21 +95,10 @@ char *saved_status;
|
||||
|
||||
static gboolean cont = TRUE;
|
||||
static gboolean force_quit = FALSE;
|
||||
#ifdef HAVE_GTK
|
||||
static gboolean gtk_ready = FALSE;
|
||||
#endif
|
||||
|
||||
void
|
||||
prof_run(char *log_level, char *account_name)
|
||||
{
|
||||
#ifdef HAVE_GTK
|
||||
gtk_ready = gtk_init_check(0, NULL);
|
||||
log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false");
|
||||
if (gtk_ready) {
|
||||
gtk_init(0, NULL);
|
||||
gtk_main_iteration_do(FALSE);
|
||||
}
|
||||
#endif
|
||||
_init(log_level);
|
||||
plugins_on_start();
|
||||
_connect_default(account_name);
|
||||
@ -146,9 +134,7 @@ prof_run(char *log_level, char *account_name)
|
||||
iq_autoping_check();
|
||||
ui_update();
|
||||
#ifdef HAVE_GTK
|
||||
if (gtk_ready) {
|
||||
gtk_main_iteration_do(FALSE);
|
||||
}
|
||||
tray_update();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -337,6 +323,11 @@ _init(char *log_level)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGWINCH, ui_sigwinch_handler);
|
||||
if (pthread_mutex_init(&lock, NULL) != 0) {
|
||||
log_error("Mutex init failed");
|
||||
exit(1);
|
||||
}
|
||||
pthread_mutex_lock(&lock);
|
||||
_create_directories();
|
||||
log_level_t prof_log_level = log_level_from_string(log_level);
|
||||
prefs_load();
|
||||
@ -373,10 +364,7 @@ _init(char *log_level)
|
||||
atexit(_shutdown);
|
||||
plugins_init();
|
||||
#ifdef HAVE_GTK
|
||||
if (gtk_ready) {
|
||||
log_debug("Building GTK icon");
|
||||
create_tray();
|
||||
}
|
||||
tray_init();
|
||||
#endif
|
||||
inp_nonblocking(TRUE);
|
||||
}
|
||||
@ -397,9 +385,7 @@ _shutdown(void)
|
||||
cl_ev_disconnect();
|
||||
}
|
||||
#ifdef HAVE_GTK
|
||||
if (gtk_ready) {
|
||||
destroy_tray();
|
||||
}
|
||||
tray_shutdown();
|
||||
#endif
|
||||
jabber_shutdown();
|
||||
plugins_on_shutdown();
|
||||
|
@ -35,6 +35,8 @@
|
||||
#ifndef PROFANITY_H
|
||||
#define PROFANITY_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "resource.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
@ -46,4 +48,6 @@ gboolean prof_process_input(char *inp);
|
||||
|
||||
void prof_set_quit(void);
|
||||
|
||||
pthread_mutex_t lock;
|
||||
|
||||
#endif
|
||||
|
338
src/tools/http_upload.c
Normal file
338
src/tools/http_upload.c
Normal file
@ -0,0 +1,338 @@
|
||||
/*
|
||||
* http_upload.c
|
||||
*
|
||||
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <curl/curl.h>
|
||||
#include <gio/gio.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "profanity.h"
|
||||
#include "ui/ui.h"
|
||||
#include "ui/window.h"
|
||||
#include "tools/http_upload.h"
|
||||
#include "event/client_events.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
#define FALLBACK_MIMETYPE "application/octet-stream"
|
||||
#define FALLBACK_CONTENTTYPE_HEADER "Content-Type: application/octet-stream"
|
||||
#define FALLBACK_MSG ""
|
||||
#define FILE_HEADER_BYTES 512
|
||||
|
||||
struct curl_data_t {
|
||||
char *buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
_xferinfo(void *userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
HTTPUpload *upload = (HTTPUpload *)userdata;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
|
||||
if (upload->cancel) {
|
||||
pthread_mutex_unlock(&lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (upload->bytes_sent == ulnow) {
|
||||
pthread_mutex_unlock(&lock);
|
||||
return 0;
|
||||
} else {
|
||||
upload->bytes_sent = ulnow;
|
||||
}
|
||||
|
||||
unsigned int ulperc = 0;
|
||||
if (ultotal != 0) {
|
||||
ulperc = (100 * ulnow) / ultotal;
|
||||
}
|
||||
|
||||
char *msg;
|
||||
if (asprintf(&msg, "Uploading '%s': %d%%", upload->filename, ulperc) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
free(msg);
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM < 0x072000
|
||||
static int
|
||||
_older_progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow)
|
||||
{
|
||||
return _xferinfo(p, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal, (curl_off_t)ulnow);
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void *
|
||||
http_file_put(void *userdata)
|
||||
{
|
||||
HTTPUpload *upload = (HTTPUpload *)userdata;
|
||||
|
||||
FILE *fd = NULL;
|
||||
|
||||
char *err = NULL;
|
||||
char *content_type_header;
|
||||
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
upload->cancel = 0;
|
||||
upload->bytes_sent = 0;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
char* msg;
|
||||
if (asprintf(&msg, "Uploading '%s': 0%%", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_print_with_receipt(upload->window, '!', 0, NULL, 0, THEME_TEXT_ME, NULL, msg, upload->put_url);
|
||||
free(msg);
|
||||
|
||||
char *cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, upload->put_url);
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
|
||||
struct curl_slist *headers = NULL;
|
||||
if (asprintf(&content_type_header, "Content-Type: %s", upload->mime_type) == -1) {
|
||||
content_type_header = strdup(FALLBACK_CONTENTTYPE_HEADER);
|
||||
}
|
||||
headers = curl_slist_append(headers, content_type_header);
|
||||
headers = curl_slist_append(headers, "Expect:");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x072000
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, _xferinfo);
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, upload);
|
||||
#else
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, _older_progress);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, upload);
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
|
||||
struct curl_data_t output;
|
||||
output.buffer = NULL;
|
||||
output.size = 0;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _data_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&output);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "profanity");
|
||||
|
||||
if (!(fd = fopen(upload->filename, "rb"))) {
|
||||
if (asprintf(&err, "failed to open '%s'", upload->filename) == -1) {
|
||||
err = NULL;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cert_path) {
|
||||
curl_easy_setopt(curl, CURLOPT_CAPATH, cert_path);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
|
||||
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)(upload->filesize));
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||
|
||||
if ((res = curl_easy_perform(curl)) != CURLE_OK) {
|
||||
err = strdup(curl_easy_strerror(res));
|
||||
} else {
|
||||
long http_code = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
|
||||
if (output.buffer) {
|
||||
output.buffer[output.size++] = '\0';
|
||||
}
|
||||
|
||||
// XEP-0363 specifies 201 but prosody returns 200
|
||||
if (http_code != 200 && http_code != 201) {
|
||||
if (asprintf(&err, "Server returned %lu", http_code) == -1) {
|
||||
err = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("HTTP Status: %lu\n", http_code);
|
||||
printf("%s\n", output.buffer);
|
||||
printf("%lu bytes retrieved\n", (long)output.size);
|
||||
#endif
|
||||
}
|
||||
|
||||
end:
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
curl_slist_free_all(headers);
|
||||
if (fd) {
|
||||
fclose(fd);
|
||||
}
|
||||
free(content_type_header);
|
||||
free(output.buffer);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
prefs_free_string(cert_path);
|
||||
|
||||
if (err) {
|
||||
char *msg;
|
||||
if (upload->cancel) {
|
||||
if (asprintf(&msg, "Uploading '%s' failed: Upload was canceled", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
} else {
|
||||
if (asprintf(&msg, "Uploading '%s' failed: %s", upload->filename, err) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
}
|
||||
cons_show_error(msg);
|
||||
free(msg);
|
||||
free(err);
|
||||
} else {
|
||||
if (!upload->cancel) {
|
||||
if (asprintf(&msg, "Uploading '%s': 100%%", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
//win_update_entry_theme(upload->window, upload->put_url, THEME_THEM);
|
||||
win_mark_received(upload->window, upload->put_url);
|
||||
free(msg);
|
||||
|
||||
switch (upload->window->type) {
|
||||
case WIN_CHAT:
|
||||
{
|
||||
ProfChatWin *chatwin = (ProfChatWin*)(upload->window);
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
cl_ev_send_msg(chatwin, upload->get_url, upload->get_url);
|
||||
break;
|
||||
}
|
||||
case WIN_PRIVATE:
|
||||
{
|
||||
ProfPrivateWin *privatewin = (ProfPrivateWin*)(upload->window);
|
||||
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
||||
cl_ev_send_priv_msg(privatewin, upload->get_url, upload->get_url);
|
||||
break;
|
||||
}
|
||||
case WIN_MUC:
|
||||
{
|
||||
ProfMucWin *mucwin = (ProfMucWin*)(upload->window);
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
cl_ev_send_muc_msg(mucwin, upload->get_url, upload->get_url);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
upload_processes = g_slist_remove(upload_processes, upload);
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
free(upload->filename);
|
||||
free(upload->mime_type);
|
||||
free(upload->get_url);
|
||||
free(upload->put_url);
|
||||
free(upload);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
file_mime_type(const char* const file_name)
|
||||
{
|
||||
char *out_mime_type;
|
||||
char file_header[FILE_HEADER_BYTES];
|
||||
FILE *fd;
|
||||
if (!(fd = fopen(file_name, "rb"))) {
|
||||
return strdup(FALLBACK_MIMETYPE);
|
||||
}
|
||||
size_t file_header_size = fread(file_header, 1, FILE_HEADER_BYTES, fd);
|
||||
fclose(fd);
|
||||
|
||||
char *content_type = g_content_type_guess(file_name, (unsigned char*)file_header, file_header_size, NULL);
|
||||
if (content_type != NULL) {
|
||||
char *mime_type = g_content_type_get_mime_type(content_type);
|
||||
out_mime_type = strdup(mime_type);
|
||||
g_free(mime_type);
|
||||
}
|
||||
else {
|
||||
return strdup(FALLBACK_MIMETYPE);
|
||||
}
|
||||
g_free(content_type);
|
||||
return out_mime_type;
|
||||
}
|
||||
|
||||
off_t file_size(const char* const filename)
|
||||
{
|
||||
struct stat st;
|
||||
stat(filename, &st);
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
int is_regular_file(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
stat(filename, &st);
|
||||
return S_ISREG(st.st_mode);
|
||||
}
|
66
src/tools/http_upload.h
Normal file
66
src/tools/http_upload.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* http_upload.h
|
||||
*
|
||||
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_HTTP_UPLOAD_H
|
||||
#define TOOLS_HTTP_UPLOAD_H
|
||||
|
||||
#ifdef PLATFORM_CYGWIN
|
||||
#define SOCKET int
|
||||
#endif
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <curl/curl.h>
|
||||
#include "ui/win_types.h"
|
||||
|
||||
typedef struct http_upload_t {
|
||||
char *filename;
|
||||
off_t filesize;
|
||||
curl_off_t bytes_sent;
|
||||
char *mime_type;
|
||||
char *get_url;
|
||||
char *put_url;
|
||||
ProfWin *window;
|
||||
pthread_t worker;
|
||||
int cancel;
|
||||
} HTTPUpload;
|
||||
|
||||
GSList *upload_processes;
|
||||
|
||||
void* http_file_put(void *userdata);
|
||||
|
||||
char* file_mime_type(const char* const file_name);
|
||||
off_t file_size(const char* const file_name);
|
||||
int is_regular_file(const char *filename);
|
||||
|
||||
#endif
|
45
src/tray.c
45
src/tray.c
@ -42,7 +42,9 @@
|
||||
#include "tray.h"
|
||||
#include "window_list.h"
|
||||
#include "log.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
static gboolean gtk_ready = FALSE;
|
||||
static GtkStatusIcon *prof_tray = NULL;
|
||||
static GString *icon_filename = NULL;
|
||||
static GString *icon_msg_filename = NULL;
|
||||
@ -141,16 +143,53 @@ _tray_change_icon(gpointer data)
|
||||
/* {{{ Public */
|
||||
|
||||
void
|
||||
create_tray(void)
|
||||
tray_init(void)
|
||||
{
|
||||
_get_icons();
|
||||
gtk_ready = gtk_init_check(0, NULL);
|
||||
log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false");
|
||||
if (!gtk_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_init(0, NULL);
|
||||
if (prefs_get_boolean(PREF_TRAY)) {
|
||||
log_debug("Building GTK icon");
|
||||
tray_enable();
|
||||
}
|
||||
|
||||
gtk_main_iteration_do(FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
tray_update(void)
|
||||
{
|
||||
if (gtk_ready) {
|
||||
gtk_main_iteration_do(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tray_shutdown(void)
|
||||
{
|
||||
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) {
|
||||
tray_disable();
|
||||
}
|
||||
g_string_free(icon_filename, TRUE);
|
||||
g_string_free(icon_msg_filename, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
tray_enable(void)
|
||||
{
|
||||
prof_tray = gtk_status_icon_new_from_file(icon_filename->str);
|
||||
shutting_down = FALSE;
|
||||
_tray_change_icon(NULL);
|
||||
timer = g_timeout_add(5000, _tray_change_icon, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
destroy_tray(void)
|
||||
tray_disable(void)
|
||||
{
|
||||
shutting_down = TRUE;
|
||||
g_source_remove(timer);
|
||||
@ -158,8 +197,6 @@ destroy_tray(void)
|
||||
g_clear_object(&prof_tray);
|
||||
prof_tray = NULL;
|
||||
}
|
||||
g_string_free(icon_filename, TRUE);
|
||||
g_string_free(icon_msg_filename, TRUE);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
@ -35,16 +35,20 @@
|
||||
#ifndef PROFANITY_TRAY_H
|
||||
#define PROFANITY_TRAY_H
|
||||
|
||||
void tray_init(void);
|
||||
void tray_update(void);
|
||||
void tray_shutdown(void);
|
||||
|
||||
/*
|
||||
* Create tray icon
|
||||
*
|
||||
* This will initialize the timer that will be called in order to change the icons
|
||||
* and will search the icons in the defaults paths
|
||||
*/
|
||||
void create_tray(void);
|
||||
void tray_enable(void);
|
||||
/*
|
||||
* Destroy tray icon
|
||||
*/
|
||||
void destroy_tray(void);
|
||||
void tray_disable(void);
|
||||
|
||||
#endif
|
||||
|
@ -125,6 +125,21 @@ buffer_yield_entry(ProfBuff buffer, int entry)
|
||||
return node->data;
|
||||
}
|
||||
|
||||
ProfBuffEntry*
|
||||
buffer_yield_entry_by_id(ProfBuff buffer, const char *const id)
|
||||
{
|
||||
GSList *entries = buffer->entries;
|
||||
while (entries) {
|
||||
ProfBuffEntry *entry = entries->data;
|
||||
if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) {
|
||||
return entry;
|
||||
}
|
||||
entries = g_slist_next(entries);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_entry(ProfBuffEntry *entry)
|
||||
{
|
||||
|
@ -64,6 +64,7 @@ void buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTim
|
||||
const char *const from, const char *const message, DeliveryReceipt *receipt);
|
||||
int buffer_size(ProfBuff buffer);
|
||||
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
|
||||
ProfBuffEntry* buffer_yield_entry_by_id(ProfBuff buffer, const char *const id);
|
||||
gboolean buffer_mark_received(ProfBuff buffer, const char *const id);
|
||||
|
||||
#endif
|
||||
|
@ -1182,6 +1182,15 @@ cons_flash_setting(void)
|
||||
cons_show("Terminal flash (/flash) : OFF");
|
||||
}
|
||||
|
||||
void
|
||||
cons_tray_setting(void)
|
||||
{
|
||||
if (prefs_get_boolean(PREF_TRAY))
|
||||
cons_show("Tray icon (/tray) : ON");
|
||||
else
|
||||
cons_show("Tray icon (/tray) : OFF");
|
||||
}
|
||||
|
||||
void
|
||||
cons_splash_setting(void)
|
||||
{
|
||||
@ -1611,6 +1620,7 @@ cons_show_desktop_prefs(void)
|
||||
cons_show("Desktop notification preferences:");
|
||||
cons_show("");
|
||||
cons_notify_setting();
|
||||
cons_tray_setting();
|
||||
|
||||
cons_alert();
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <wchar.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
@ -145,7 +146,9 @@ inp_readline(void)
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fileno(rl_instream), &fds);
|
||||
errno = 0;
|
||||
pthread_mutex_unlock(&lock);
|
||||
r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout);
|
||||
pthread_mutex_lock(&lock);
|
||||
if (r < 0) {
|
||||
if (errno != EINTR) {
|
||||
char *err_msg = strerror(errno);
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "ui/ui.h"
|
||||
#include "window_list.h"
|
||||
#include "config/preferences.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
static GTimer *remind_timer;
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "command/commands.h"
|
||||
#include "ui/win_types.h"
|
||||
#include "muc.h"
|
||||
#include "config/tlscerts.h"
|
||||
#ifdef HAVE_LIBOTR
|
||||
#include "otr/otr.h"
|
||||
#endif
|
||||
@ -284,6 +285,7 @@ void cons_privileges_setting(void);
|
||||
void cons_beep_setting(void);
|
||||
void cons_console_setting(void);
|
||||
void cons_flash_setting(void);
|
||||
void cons_tray_setting(void);
|
||||
void cons_splash_setting(void);
|
||||
void cons_encwarn_setting(void);
|
||||
void cons_tlsshow_setting(void);
|
||||
|
@ -45,9 +45,9 @@
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "ui/buffer.h"
|
||||
#include "chat_state.h"
|
||||
#include "tools/autocomplete.h"
|
||||
|
||||
#define LAYOUT_SPLIT_MEMCHECK 12345671
|
||||
#define PROFCHATWIN_MEMCHECK 22374522
|
||||
@ -57,6 +57,48 @@
|
||||
#define PROFXMLWIN_MEMCHECK 87333463
|
||||
#define PROFPLUGINWIN_MEMCHECK 43434777
|
||||
|
||||
typedef enum {
|
||||
FIELD_HIDDEN,
|
||||
FIELD_TEXT_SINGLE,
|
||||
FIELD_TEXT_PRIVATE,
|
||||
FIELD_TEXT_MULTI,
|
||||
FIELD_BOOLEAN,
|
||||
FIELD_LIST_SINGLE,
|
||||
FIELD_LIST_MULTI,
|
||||
FIELD_JID_SINGLE,
|
||||
FIELD_JID_MULTI,
|
||||
FIELD_FIXED,
|
||||
FIELD_UNKNOWN
|
||||
} form_field_type_t;
|
||||
|
||||
typedef struct form_option_t {
|
||||
char *label;
|
||||
char *value;
|
||||
} FormOption;
|
||||
|
||||
typedef struct form_field_t {
|
||||
char *label;
|
||||
char *type;
|
||||
form_field_type_t type_t;
|
||||
char *var;
|
||||
char *description;
|
||||
gboolean required;
|
||||
GSList *values;
|
||||
GSList *options;
|
||||
Autocomplete value_ac;
|
||||
} FormField;
|
||||
|
||||
typedef struct data_form_t {
|
||||
char *type;
|
||||
char *title;
|
||||
char *instructions;
|
||||
GSList *fields;
|
||||
GHashTable *var_to_tag;
|
||||
GHashTable *tag_to_var;
|
||||
Autocomplete tag_ac;
|
||||
gboolean modified;
|
||||
} DataForm;
|
||||
|
||||
typedef enum {
|
||||
LAYOUT_SIMPLE,
|
||||
LAYOUT_SPLIT
|
||||
|
@ -1054,6 +1054,27 @@ win_mark_received(ProfWin *window, const char *const id)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_update_entry_message(ProfWin *window, const char *const id, const char *const message)
|
||||
{
|
||||
ProfBuffEntry *entry = buffer_yield_entry_by_id(window->layout->buffer, id);
|
||||
if (entry) {
|
||||
free(entry->message);
|
||||
entry->message = strdup(message);
|
||||
win_redraw(window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item)
|
||||
{
|
||||
ProfBuffEntry *entry = buffer_yield_entry_by_id(window->layout->buffer, id);
|
||||
if (entry) {
|
||||
entry->theme_item = theme_item;
|
||||
win_redraw(window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_println(ProfWin *window, int pad, const char *const message)
|
||||
{
|
||||
|
@ -70,6 +70,8 @@ int win_occpuants_cols(void);
|
||||
void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent);
|
||||
void win_sub_newline_lazy(WINDOW *win);
|
||||
void win_mark_received(ProfWin *window, const char *const id);
|
||||
void win_update_entry_message(ProfWin *window, const char *const id, const char *const message);
|
||||
void win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item);
|
||||
|
||||
gboolean win_has_active_subwin(ProfWin *window);
|
||||
|
||||
|
@ -508,6 +508,17 @@ wins_close_by_num(int i)
|
||||
|
||||
ProfWin *window = wins_get_by_num(i);
|
||||
if (window) {
|
||||
// cancel upload proccesses of this window
|
||||
GSList *upload_process = upload_processes;
|
||||
while (upload_process) {
|
||||
HTTPUpload *upload = upload_process->data;
|
||||
if (upload->window == window) {
|
||||
upload->cancel = 1;
|
||||
break;
|
||||
}
|
||||
upload_process = g_slist_next(upload_process);
|
||||
}
|
||||
|
||||
switch (window->type) {
|
||||
case WIN_CHAT:
|
||||
{
|
||||
|
@ -75,6 +75,7 @@ static struct _jabber_conn_t {
|
||||
} jabber_conn;
|
||||
|
||||
static GHashTable *available_resources;
|
||||
static GSList *disco_items;
|
||||
|
||||
// for auto reconnect
|
||||
static struct {
|
||||
@ -113,6 +114,18 @@ void _connection_free_saved_account(void);
|
||||
void _connection_free_saved_details(void);
|
||||
void _connection_free_session_data(void);
|
||||
|
||||
static void
|
||||
_info_destroy(DiscoInfo *info)
|
||||
{
|
||||
if (info) {
|
||||
free(info->item);
|
||||
if (info->features) {
|
||||
g_hash_table_remove_all(info->features);
|
||||
}
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
jabber_init(void)
|
||||
{
|
||||
@ -125,6 +138,7 @@ jabber_init(void)
|
||||
presence_sub_requests_init();
|
||||
caps_init();
|
||||
available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
|
||||
disco_items = NULL;
|
||||
xmpp_initialize();
|
||||
}
|
||||
|
||||
@ -323,6 +337,18 @@ jabber_set_connection_status(jabber_conn_status_t status)
|
||||
jabber_conn.conn_status = status;
|
||||
}
|
||||
|
||||
GSList*
|
||||
jabber_get_disco_items(void)
|
||||
{
|
||||
return (disco_items);
|
||||
}
|
||||
|
||||
void
|
||||
jabber_set_disco_items(GSList *_disco_items)
|
||||
{
|
||||
disco_items = _disco_items;
|
||||
}
|
||||
|
||||
xmpp_conn_t*
|
||||
connection_get_conn(void)
|
||||
{
|
||||
@ -420,6 +446,8 @@ _connection_free_saved_details(void)
|
||||
void
|
||||
_connection_free_session_data(void)
|
||||
{
|
||||
g_slist_free_full(disco_items, (GDestroyNotify)_info_destroy);
|
||||
disco_items = NULL;
|
||||
g_hash_table_remove_all(available_resources);
|
||||
chat_sessions_clear();
|
||||
presence_clear_sub_requests();
|
||||
@ -651,6 +679,14 @@ _connection_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status, con
|
||||
roster_request();
|
||||
bookmark_request();
|
||||
|
||||
// items discovery
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = strdup(jabber_conn.domain);
|
||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
disco_items = g_slist_append(disco_items, info);
|
||||
iq_disco_info_request_onconnect(info->item);
|
||||
iq_disco_items_request_onconnect(jabber_conn.domain);
|
||||
|
||||
if (prefs_get_boolean(PREF_CARBONS)){
|
||||
iq_enable_carbons();
|
||||
}
|
||||
|
194
src/xmpp/iq.c
194
src/xmpp/iq.c
@ -64,6 +64,7 @@
|
||||
#include "roster_list.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "tools/http_upload.h"
|
||||
|
||||
typedef struct p_room_info_data_t {
|
||||
char *room;
|
||||
@ -87,6 +88,8 @@ static void _ping_get_handler(xmpp_stanza_t *const stanza);
|
||||
|
||||
static int _version_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _disco_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _http_upload_response_id_handler(xmpp_stanza_t *const stanza, void *const upload_ctx);
|
||||
static int _last_activity_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _room_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _destroy_room_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
@ -292,6 +295,42 @@ iq_disable_carbons(void)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_http_upload_request(HTTPUpload *upload)
|
||||
{
|
||||
GSList *disco_items = jabber_get_disco_items();
|
||||
DiscoInfo *disco_info;
|
||||
if (disco_items && (g_slist_length(disco_items) > 0)) {
|
||||
while (disco_items) {
|
||||
disco_info = disco_items->data;
|
||||
if (g_hash_table_lookup_extended(disco_info->features, STANZA_NS_HTTP_UPLOAD, NULL, NULL)) {
|
||||
break;
|
||||
}
|
||||
disco_items = g_slist_next(disco_items);
|
||||
if (!disco_items) {
|
||||
cons_show_error("XEP-0363 HTTP File Upload is not supported by the server");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cons_show_error("No disco items");
|
||||
return;
|
||||
}
|
||||
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = create_unique_id("http_upload_request");
|
||||
|
||||
xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, disco_info->item, upload);
|
||||
|
||||
id_handler_add(id, _http_upload_response_id_handler, upload);
|
||||
|
||||
free(id);
|
||||
|
||||
send_iq_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
iq_disco_info_request(gchar *jid)
|
||||
{
|
||||
@ -307,6 +346,21 @@ iq_disco_info_request(gchar *jid)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_disco_info_request_onconnect(gchar *jid)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = create_unique_id("disco_info_onconnect");
|
||||
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, jid, NULL);
|
||||
|
||||
id_handler_add(id, _disco_info_response_id_handler_onconnect, NULL);
|
||||
|
||||
free(id);
|
||||
|
||||
send_iq_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_last_activity_request(gchar *jid)
|
||||
{
|
||||
@ -428,6 +482,15 @@ iq_disco_items_request(gchar *jid)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_disco_items_request_onconnect(gchar *jid)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq_onconnect", jid);
|
||||
send_iq_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_send_software_version(const char *const fulljid)
|
||||
{
|
||||
@ -1817,6 +1880,122 @@ _disco_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdat
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
const char *type = xmpp_stanza_get_type(stanza);
|
||||
|
||||
if (from) {
|
||||
log_info("Received disco#info response from: %s", from);
|
||||
} else {
|
||||
log_info("Received disco#info response");
|
||||
}
|
||||
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
char *error_message = stanza_get_error_message(stanza);
|
||||
if (from) {
|
||||
log_error("Service discovery failed for %s: %s", from, error_message);
|
||||
} else {
|
||||
log_error("Service discovery failed: %s", error_message);
|
||||
}
|
||||
free(error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||
|
||||
if (query) {
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
|
||||
GSList *disco_items = jabber_get_disco_items();
|
||||
DiscoInfo *disco_info;
|
||||
if (disco_items && (g_slist_length(disco_items) > 0)) {
|
||||
while (disco_items) {
|
||||
disco_info = disco_items->data;
|
||||
if (g_strcmp0(disco_info->item, from) == 0) {
|
||||
break;
|
||||
}
|
||||
disco_items = g_slist_next(disco_items);
|
||||
if (!disco_items) {
|
||||
log_error("No matching disco item found for %s", from);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (child) {
|
||||
const char *stanza_name = xmpp_stanza_get_name(child);
|
||||
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
|
||||
const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
|
||||
if (var) {
|
||||
g_hash_table_add(disco_info->features, strdup(var));
|
||||
}
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_http_upload_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
HTTPUpload *upload = (HTTPUpload *)userdata;
|
||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
const char *type = xmpp_stanza_get_type(stanza);
|
||||
|
||||
if (from) {
|
||||
log_info("Received http_upload response from: %s", from);
|
||||
} else {
|
||||
log_info("Received http_upload response");
|
||||
}
|
||||
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
char *error_message = stanza_get_error_message(stanza);
|
||||
if (from) {
|
||||
cons_show_error("Uploading '%s' failed for %s: %s", upload->filename, from, error_message);
|
||||
} else {
|
||||
cons_show_error("Uploading '%s' failed: %s", upload->filename, error_message);
|
||||
}
|
||||
free(error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *slot = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SLOT);
|
||||
|
||||
if (slot && g_strcmp0(xmpp_stanza_get_ns(slot), STANZA_NS_HTTP_UPLOAD) == 0) {
|
||||
xmpp_stanza_t *put = xmpp_stanza_get_child_by_name(slot, STANZA_NAME_PUT);
|
||||
xmpp_stanza_t *get = xmpp_stanza_get_child_by_name(slot, STANZA_NAME_GET);
|
||||
|
||||
if (put && get) {
|
||||
char *put_url = xmpp_stanza_get_text(put);
|
||||
char *get_url = xmpp_stanza_get_text(get);
|
||||
|
||||
upload->put_url = strdup(put_url);
|
||||
upload->get_url = strdup(get_url);
|
||||
|
||||
xmpp_conn_t *conn = connection_get_conn();
|
||||
xmpp_ctx_t *ctx = xmpp_conn_get_context(conn);
|
||||
if (put_url) xmpp_free(ctx, put_url);
|
||||
if (get_url) xmpp_free(ctx, get_url);
|
||||
|
||||
pthread_create(&(upload->worker), NULL, &http_file_put, upload);
|
||||
upload_processes = g_slist_append(upload_processes, upload);
|
||||
} else {
|
||||
log_error("Invalid XML in HTTP Upload slot");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_disco_items_result_handler(xmpp_stanza_t *const stanza)
|
||||
{
|
||||
@ -1825,7 +2004,7 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
|
||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
GSList *items = NULL;
|
||||
|
||||
if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0)) {
|
||||
if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0) || (g_strcmp0(id, "discoitemsreq_onconnect") == 0)) {
|
||||
log_debug("Response to query: %s", id);
|
||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||
|
||||
@ -1857,6 +2036,19 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
|
||||
cons_show_room_list(items, from);
|
||||
} else if (g_strcmp0(id, "discoitemsreq") == 0) {
|
||||
cons_show_disco_items(items, from);
|
||||
} else if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
|
||||
GSList *res_items = items;
|
||||
if (res_items && (g_slist_length(res_items) > 0)) {
|
||||
while (res_items) {
|
||||
DiscoItem *item = res_items->data;
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = strdup(item->jid);
|
||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
jabber_set_disco_items(g_slist_append(jabber_get_disco_items(), info));
|
||||
iq_disco_info_request_onconnect(info->item);
|
||||
res_items = g_slist_next(res_items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
|
||||
|
@ -163,7 +163,7 @@ _session_state(const char *const barejid)
|
||||
}
|
||||
|
||||
char*
|
||||
message_send_chat(const char *const barejid, const char *const msg)
|
||||
message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
||||
@ -178,6 +178,10 @@ message_send_chat(const char *const barejid, const char *const msg)
|
||||
stanza_attach_state(ctx, message, state);
|
||||
}
|
||||
|
||||
if (oob_url) {
|
||||
stanza_attach_x_oob_url(ctx, message, oob_url);
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
@ -274,25 +278,33 @@ message_send_chat_otr(const char *const barejid, const char *const msg)
|
||||
}
|
||||
|
||||
void
|
||||
message_send_private(const char *const fulljid, const char *const msg)
|
||||
message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = create_unique_id("prv");
|
||||
xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg);
|
||||
free(id);
|
||||
|
||||
if (oob_url) {
|
||||
stanza_attach_x_oob_url(ctx, message, oob_url);
|
||||
}
|
||||
|
||||
_send_message_stanza(message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
||||
void
|
||||
message_send_groupchat(const char *const roomjid, const char *const msg)
|
||||
message_send_groupchat(const char *const roomjid, const char *const msg, const char *const oob_url)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = create_unique_id("muc");
|
||||
xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg);
|
||||
free(id);
|
||||
|
||||
if (oob_url) {
|
||||
stanza_attach_x_oob_url(ctx, message, oob_url);
|
||||
}
|
||||
|
||||
_send_message_stanza(message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
@ -32,10 +32,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -206,6 +211,61 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char *const jid,
|
||||
}
|
||||
#endif
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_http_upload_request(xmpp_ctx_t *ctx, const char *const id,
|
||||
const char *const jid, HTTPUpload *upload)
|
||||
{
|
||||
int i;
|
||||
|
||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
|
||||
xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, jid);
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
|
||||
xmpp_stanza_t *request = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(request, STANZA_NAME_REQUEST);
|
||||
xmpp_stanza_set_ns(request, STANZA_NS_HTTP_UPLOAD);
|
||||
|
||||
xmpp_stanza_t *filename = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(filename, STANZA_NAME_FILENAME);
|
||||
xmpp_stanza_t *filename_txt = xmpp_stanza_new(ctx);
|
||||
char* filename_cpy = strdup(upload->filename);
|
||||
// strip spaces from filename (servers don't spaces)
|
||||
for (i=0; i<strlen(filename_cpy); i++) {
|
||||
if (filename_cpy[i] == ' ') {
|
||||
filename_cpy[i] = '_';
|
||||
}
|
||||
}
|
||||
xmpp_stanza_set_text(filename_txt, basename(filename_cpy));
|
||||
free(filename_cpy);
|
||||
xmpp_stanza_add_child(filename, filename_txt);
|
||||
xmpp_stanza_add_child(request, filename);
|
||||
|
||||
xmpp_stanza_t *size = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(size, STANZA_NAME_SIZE);
|
||||
xmpp_stanza_t *size_txt = xmpp_stanza_new(ctx);
|
||||
char* filesize = NULL;
|
||||
if (asprintf(&filesize, "%jd", (intmax_t)(upload->filesize)) != -1) {
|
||||
xmpp_stanza_set_text(size_txt, filesize);
|
||||
free(filesize);
|
||||
}
|
||||
xmpp_stanza_add_child(size, size_txt);
|
||||
xmpp_stanza_add_child(request, size);
|
||||
|
||||
xmpp_stanza_t *content_type = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(content_type, STANZA_NAME_CONTENT_TYPE);
|
||||
xmpp_stanza_t *content_type_txt = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(content_type_txt, upload->mime_type);
|
||||
xmpp_stanza_add_child(content_type, content_type_txt);
|
||||
xmpp_stanza_add_child(request, content_type);
|
||||
|
||||
xmpp_stanza_add_child(iq, request);
|
||||
xmpp_stanza_release(request);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_enable_carbons(xmpp_ctx_t *ctx)
|
||||
{
|
||||
@ -353,6 +413,30 @@ stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza)
|
||||
return stanza;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url)
|
||||
{
|
||||
xmpp_stanza_t *x_oob = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(x_oob, STANZA_NAME_X);
|
||||
xmpp_stanza_set_ns(x_oob, STANZA_NS_X_OOB);
|
||||
|
||||
xmpp_stanza_t *surl = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(surl, STANZA_NAME_URL);
|
||||
|
||||
xmpp_stanza_t *surl_txt = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(surl_txt, url);
|
||||
xmpp_stanza_add_child(surl, surl_txt);
|
||||
xmpp_stanza_release(surl_txt);
|
||||
|
||||
xmpp_stanza_add_child(x_oob, surl);
|
||||
xmpp_stanza_release(surl);
|
||||
|
||||
xmpp_stanza_add_child(stanza, x_oob);
|
||||
xmpp_stanza_release(x_oob);
|
||||
|
||||
return stanza;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_message(xmpp_ctx_t *ctx, char *id, const char *const recipient,
|
||||
const char *const type, const char *const message)
|
||||
|
@ -61,6 +61,7 @@
|
||||
#define STANZA_NAME_STATUS "status"
|
||||
#define STANZA_NAME_IQ "iq"
|
||||
#define STANZA_NAME_QUERY "query"
|
||||
#define STANZA_NAME_REQUEST "request"
|
||||
#define STANZA_NAME_DELAY "delay"
|
||||
#define STANZA_NAME_ERROR "error"
|
||||
#define STANZA_NAME_PING "ping"
|
||||
@ -87,6 +88,13 @@
|
||||
#define STANZA_NAME_ACTOR "actor"
|
||||
#define STANZA_NAME_ENABLE "enable"
|
||||
#define STANZA_NAME_DISABLE "disable"
|
||||
#define STANZA_NAME_FILENAME "filename"
|
||||
#define STANZA_NAME_SIZE "size"
|
||||
#define STANZA_NAME_CONTENT_TYPE "content-type"
|
||||
#define STANZA_NAME_SLOT "slot"
|
||||
#define STANZA_NAME_PUT "put"
|
||||
#define STANZA_NAME_GET "get"
|
||||
#define STANZA_NAME_URL "url"
|
||||
|
||||
// error conditions
|
||||
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
||||
@ -171,6 +179,8 @@
|
||||
#define STANZA_NS_RECEIPTS "urn:xmpp:receipts"
|
||||
#define STANZA_NS_SIGNED "jabber:x:signed"
|
||||
#define STANZA_NS_ENCRYPTED "jabber:x:encrypted"
|
||||
#define STANZA_NS_HTTP_UPLOAD "urn:xmpp:http:upload"
|
||||
#define STANZA_NS_X_OOB "jabber:x:oob"
|
||||
|
||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||
|
||||
@ -195,6 +205,8 @@ typedef enum {
|
||||
|
||||
xmpp_stanza_t* stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx);
|
||||
|
||||
xmpp_stanza_t* stanza_create_http_upload_request(xmpp_ctx_t *ctx, const char *const id, const char *const jid, HTTPUpload *upload);
|
||||
|
||||
xmpp_stanza_t* stanza_enable_carbons(xmpp_ctx_t *ctx);
|
||||
|
||||
xmpp_stanza_t* stanza_disable_carbons(xmpp_ctx_t *ctx);
|
||||
@ -207,6 +219,7 @@ xmpp_stanza_t* stanza_attach_carbons_private(xmpp_ctx_t *ctx, xmpp_stanza_t *sta
|
||||
xmpp_stanza_t* stanza_attach_hints_no_copy(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
|
||||
xmpp_stanza_t* stanza_attach_hints_no_store(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
|
||||
xmpp_stanza_t* stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
|
||||
xmpp_stanza_t* stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url);
|
||||
|
||||
xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, char *id,
|
||||
const char *const recipient, const char *const type, const char *const message);
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "contact.h"
|
||||
#include "jid.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "tools/http_upload.h"
|
||||
|
||||
#define JABBER_PRIORITY_MIN -128
|
||||
#define JABBER_PRIORITY_MAX 127
|
||||
@ -95,47 +96,10 @@ typedef struct disco_identity_t {
|
||||
char *category;
|
||||
} DiscoIdentity;
|
||||
|
||||
typedef enum {
|
||||
FIELD_HIDDEN,
|
||||
FIELD_TEXT_SINGLE,
|
||||
FIELD_TEXT_PRIVATE,
|
||||
FIELD_TEXT_MULTI,
|
||||
FIELD_BOOLEAN,
|
||||
FIELD_LIST_SINGLE,
|
||||
FIELD_LIST_MULTI,
|
||||
FIELD_JID_SINGLE,
|
||||
FIELD_JID_MULTI,
|
||||
FIELD_FIXED,
|
||||
FIELD_UNKNOWN
|
||||
} form_field_type_t;
|
||||
|
||||
typedef struct form_option_t {
|
||||
char *label;
|
||||
char *value;
|
||||
} FormOption;
|
||||
|
||||
typedef struct form_field_t {
|
||||
char *label;
|
||||
char *type;
|
||||
form_field_type_t type_t;
|
||||
char *var;
|
||||
char *description;
|
||||
gboolean required;
|
||||
GSList *values;
|
||||
GSList *options;
|
||||
Autocomplete value_ac;
|
||||
} FormField;
|
||||
|
||||
typedef struct data_form_t {
|
||||
char *type;
|
||||
char *title;
|
||||
char *instructions;
|
||||
GSList *fields;
|
||||
GHashTable *var_to_tag;
|
||||
GHashTable *tag_to_var;
|
||||
Autocomplete tag_ac;
|
||||
gboolean modified;
|
||||
} DataForm;
|
||||
typedef struct disco_info_t {
|
||||
char *item;
|
||||
GHashTable *features;
|
||||
} DiscoInfo;
|
||||
|
||||
// connection functions
|
||||
void jabber_init(void);
|
||||
@ -150,6 +114,8 @@ const char* jabber_get_fulljid(void);
|
||||
const char* jabber_get_domain(void);
|
||||
jabber_conn_status_t jabber_get_connection_status(void);
|
||||
void jabber_set_connection_status(jabber_conn_status_t status);
|
||||
GSList* jabber_get_disco_items(void);
|
||||
void jabber_set_disco_items(GSList *disco_items);
|
||||
char* jabber_get_presence_message(void);
|
||||
char* jabber_get_account_name(void);
|
||||
GList* jabber_get_available_resources(void);
|
||||
@ -162,11 +128,11 @@ gboolean jabber_conn_is_secured(void);
|
||||
gboolean jabber_send_stanza(const char *const stanza);
|
||||
|
||||
// message functions
|
||||
char* message_send_chat(const char *const barejid, const char *const msg);
|
||||
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url);
|
||||
char* message_send_chat_otr(const char *const barejid, const char *const msg);
|
||||
char* message_send_chat_pgp(const char *const barejid, const char *const msg);
|
||||
void message_send_private(const char *const fulljid, const char *const msg);
|
||||
void message_send_groupchat(const char *const roomjid, const char *const msg);
|
||||
void message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url);
|
||||
void message_send_groupchat(const char *const roomjid, const char *const msg, const char *const oob_url);
|
||||
void message_send_groupchat_subject(const char *const roomjid, const char *const subject);
|
||||
|
||||
void message_send_inactive(const char *const jid);
|
||||
@ -194,7 +160,9 @@ void iq_disable_carbons(void);
|
||||
void iq_send_software_version(const char *const fulljid);
|
||||
void iq_room_list_request(gchar *conferencejid);
|
||||
void iq_disco_info_request(gchar *jid);
|
||||
void iq_disco_info_request_onconnect(gchar *jid);
|
||||
void iq_disco_items_request(gchar *jid);
|
||||
void iq_disco_items_request_onconnect(gchar *jid);
|
||||
void iq_last_activity_request(gchar *jid);
|
||||
void iq_set_autoping(int seconds);
|
||||
void iq_confirm_instant_room(const char *const room_jid);
|
||||
@ -216,6 +184,7 @@ void iq_room_kick_occupant(const char *const room, const char *const nick, const
|
||||
void iq_room_role_set(const char *const room, const char *const nick, char *role, const char *const reason);
|
||||
void iq_room_role_list(const char * const room, char *role);
|
||||
void iq_autoping_check(void);
|
||||
void iq_http_upload_request(HTTPUpload *upload);
|
||||
|
||||
// caps functions
|
||||
Capabilities* caps_lookup(const char *const jid);
|
||||
|
@ -95,8 +95,8 @@ shows_role_and_affiliation_on_join(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -115,8 +115,8 @@ shows_subject_on_join(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -143,8 +143,8 @@ shows_history_message(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -172,8 +172,8 @@ shows_occupant_join(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -201,8 +201,8 @@ shows_message(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -228,8 +228,8 @@ shows_all_messages_in_console_when_window_not_focussed(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -269,8 +269,8 @@ shows_first_message_in_console_when_window_not_focussed(void **state)
|
||||
prof_input("/console muc first");
|
||||
assert_true(prof_output_exact("Console MUC messages set: first"));
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
@ -315,8 +315,8 @@ shows_no_message_in_console_when_window_not_focussed(void **state)
|
||||
prof_input("/console muc none");
|
||||
assert_true(prof_output_exact("Console MUC messages set: none"));
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
stbbr_for_id("prof_join_3",
|
||||
"<presence id='prof_join_3' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
|
@ -14,18 +14,18 @@
|
||||
void
|
||||
ping_multiple(void **state)
|
||||
{
|
||||
stbbr_for_id("prof_ping_2",
|
||||
"<iq id='prof_ping_2' type='result' to='stabber@localhost/profanity'/>"
|
||||
);
|
||||
stbbr_for_id("prof_ping_3",
|
||||
"<iq id='prof_ping_3' type='result' to='stabber@localhost/profanity'/>"
|
||||
);
|
||||
stbbr_for_id("prof_ping_4",
|
||||
"<iq id='prof_ping_4' type='result' to='stabber@localhost/profanity'/>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_ping_2' type='get'>"
|
||||
"<iq id='prof_ping_3' type='get'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
@ -33,7 +33,7 @@ ping_multiple(void **state)
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='prof_ping_3' type='get'>"
|
||||
"<iq id='prof_ping_4' type='get'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
@ -26,7 +26,7 @@ presence_online(void **state)
|
||||
prof_input("/online");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
));
|
||||
@ -44,7 +44,7 @@ presence_online_with_message(void **state)
|
||||
prof_input("/online \"Hi there\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<status>Hi there</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -61,7 +61,7 @@ presence_away(void **state)
|
||||
prof_input("/away");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>away</show>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -78,7 +78,7 @@ presence_away_with_message(void **state)
|
||||
prof_input("/away \"I'm not here for a bit\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>away</show>"
|
||||
"<status>I'm not here for a bit</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
@ -96,7 +96,7 @@ presence_xa(void **state)
|
||||
prof_input("/xa");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>xa</show>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -113,7 +113,7 @@ presence_xa_with_message(void **state)
|
||||
prof_input("/xa \"Gone to the shops\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>xa</show>"
|
||||
"<status>Gone to the shops</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
@ -131,7 +131,7 @@ presence_dnd(void **state)
|
||||
prof_input("/dnd");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>dnd</show>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -148,7 +148,7 @@ presence_dnd_with_message(void **state)
|
||||
prof_input("/dnd \"Working\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>dnd</show>"
|
||||
"<status>Working</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
@ -166,7 +166,7 @@ presence_chat(void **state)
|
||||
prof_input("/chat");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>chat</show>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -183,7 +183,7 @@ presence_chat_with_message(void **state)
|
||||
prof_input("/chat \"Free to talk\"");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
@ -201,7 +201,7 @@ presence_set_priority(void **state)
|
||||
prof_input("/priority 25");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<priority>25</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -217,7 +217,7 @@ presence_includes_priority(void **state)
|
||||
|
||||
prof_input("/priority 25");
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_2'>"
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<priority>25</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
|
||||
"</presence>"
|
||||
@ -226,7 +226,7 @@ presence_includes_priority(void **state)
|
||||
|
||||
prof_input("/chat \"Free to talk\"");
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='prof_presence_3'>"
|
||||
"<presence id='prof_presence_4'>"
|
||||
"<priority>25</priority>"
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
|
@ -61,7 +61,7 @@ void cmd_account_list_shows_accounts(void **state)
|
||||
|
||||
expect_memory(cons_show_account_list, accounts, accounts, sizeof(accounts));
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_list(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ void cmd_account_show_shows_usage_when_no_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state)
|
||||
expect_cons_show("No such account.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ void cmd_account_show_shows_account_when_exists(void **state)
|
||||
|
||||
expect_memory(cons_show_account, account, account, sizeof(account));
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ void cmd_account_add_shows_usage_when_no_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_add(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ void cmd_account_add_adds_account(void **state)
|
||||
expect_cons_show("Account created.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_add(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ void cmd_account_enable_enables_account(void **state)
|
||||
expect_cons_show("Account enabled.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state)
|
||||
expect_cons_show("No such account: account_name");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ void cmd_account_disable_shows_usage_when_no_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ void cmd_account_disable_disables_account(void **state)
|
||||
expect_cons_show("Account disabled.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
|
||||
expect_cons_show("No such account: account_name");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ void cmd_account_rename_shows_usage_when_no_args(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ void cmd_account_rename_shows_usage_when_one_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ void cmd_account_rename_renames_account(void **state)
|
||||
expect_cons_show("Account renamed.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state)
|
||||
expect_cons_show("Either account original_name doesn't exist, or account new_name already exists.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ void cmd_account_set_shows_usage_when_no_args(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ void cmd_account_set_shows_usage_when_one_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ void cmd_account_set_shows_usage_when_two_args(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ void cmd_account_set_shows_message_when_account_doesnt_exist(void **state)
|
||||
expect_cons_show("Account a_account doesn't exist");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ void cmd_account_set_jid_shows_message_for_malformed_jid(void **state)
|
||||
|
||||
expect_cons_show("Malformed jid: @malformed");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -324,7 +324,7 @@ void cmd_account_set_jid_sets_barejid(void **state)
|
||||
expect_cons_show("Updated jid for account a_account: a_local@a_domain");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -346,7 +346,7 @@ void cmd_account_set_jid_sets_resource(void **state)
|
||||
expect_cons_show("Updated resource for account a_account: a_resource");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -363,7 +363,7 @@ void cmd_account_set_server_sets_server(void **state)
|
||||
expect_cons_show("Updated server for account a_account: a_server");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ void cmd_account_set_resource_sets_resource(void **state)
|
||||
expect_cons_show("Updated resource for account a_account: a_resource");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -401,7 +401,7 @@ void cmd_account_set_resource_sets_resource_with_online_message(void **state)
|
||||
expect_cons_show("Updated resource for account a_account: a_resource, you will need to reconnect to pick up the change.");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -424,7 +424,7 @@ void cmd_account_set_password_sets_password(void **state)
|
||||
expect_cons_show("Updated password for account a_account");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -446,7 +446,7 @@ void cmd_account_set_eval_password_sets_eval_password(void **state)
|
||||
expect_cons_show("Updated eval_password for account a_account");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -463,7 +463,7 @@ void cmd_account_set_password_when_eval_password_set(void **state) {
|
||||
|
||||
expect_cons_show("Cannot set password when eval_password is set.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -480,7 +480,7 @@ void cmd_account_set_eval_password_when_password_set(void **state) {
|
||||
|
||||
expect_cons_show("Cannot set eval_password when password is set.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -497,7 +497,7 @@ void cmd_account_set_muc_sets_muc(void **state)
|
||||
expect_cons_show("Updated muc service for account a_account: a_muc");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -514,7 +514,7 @@ void cmd_account_set_nick_sets_nick(void **state)
|
||||
expect_cons_show("Updated muc nick for account a_account: a_nick");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -524,7 +524,7 @@ void cmd_account_show_message_for_missing_otr_policy(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ void cmd_account_show_message_for_invalid_otr_policy(void **state)
|
||||
|
||||
expect_cons_show("OTR policy must be one of: manual, opportunistic or always.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -554,7 +554,7 @@ void cmd_account_set_otr_sets_otr(void **state)
|
||||
expect_cons_show("Updated OTR policy for account a_account: opportunistic");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -568,7 +568,7 @@ void cmd_account_set_status_shows_message_when_invalid_status(void **state)
|
||||
expect_cons_show("Invalid status: bad_status");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -585,7 +585,7 @@ void cmd_account_set_status_sets_status_when_valid(void **state)
|
||||
expect_cons_show("Updated login status for account a_account: away");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -602,7 +602,7 @@ void cmd_account_set_status_sets_status_when_last(void **state)
|
||||
expect_cons_show("Updated login status for account a_account: last");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -616,7 +616,7 @@ void cmd_account_set_invalid_presence_string_priority_shows_message(void **state
|
||||
expect_cons_show("Invalid property: blah");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -630,7 +630,7 @@ void cmd_account_set_last_priority_shows_message(void **state)
|
||||
expect_cons_show("Invalid property: last");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -649,7 +649,7 @@ void cmd_account_set_online_priority_sets_preference(void **state)
|
||||
expect_cons_show("Updated online priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -668,7 +668,7 @@ void cmd_account_set_chat_priority_sets_preference(void **state)
|
||||
expect_cons_show("Updated chat priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ void cmd_account_set_away_priority_sets_preference(void **state)
|
||||
expect_cons_show("Updated away priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -706,7 +706,7 @@ void cmd_account_set_xa_priority_sets_preference(void **state)
|
||||
expect_cons_show("Updated xa priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -725,7 +725,7 @@ void cmd_account_set_dnd_priority_sets_preference(void **state)
|
||||
expect_cons_show("Updated dnd priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -738,7 +738,7 @@ void cmd_account_set_priority_too_low_shows_message(void **state)
|
||||
|
||||
expect_cons_show("Value -150 out of range. Must be in -128..127.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -751,7 +751,7 @@ void cmd_account_set_priority_too_high_shows_message(void **state)
|
||||
|
||||
expect_cons_show("Value 150 out of range. Must be in -128..127.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -764,7 +764,7 @@ void cmd_account_set_priority_when_not_number_shows_message(void **state)
|
||||
|
||||
expect_cons_show("Could not convert \"abc\" to a number.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -777,7 +777,7 @@ void cmd_account_set_priority_when_empty_shows_message(void **state)
|
||||
|
||||
expect_cons_show("Could not convert \"\" to a number.");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -817,7 +817,7 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
|
||||
expect_cons_show("Updated online priority for account a_account: 10");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -827,7 +827,7 @@ void cmd_account_clear_shows_usage_when_no_args(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -837,7 +837,7 @@ void cmd_account_clear_shows_usage_when_one_arg(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -851,7 +851,7 @@ void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state)
|
||||
expect_cons_show("Account a_account doesn't exist");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -865,6 +865,6 @@ void cmd_account_clear_shows_message_when_invalid_property(void **state)
|
||||
expect_cons_show("Invalid property: badproperty");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
|
||||
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
@ -25,35 +25,13 @@
|
||||
#define CMD_OTR "/otr"
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
void cmd_otr_shows_usage_when_no_args(void **state)
|
||||
{
|
||||
gchar *args[] = { NULL };
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_otr_shows_usage_when_invalid_subcommand(void **state)
|
||||
{
|
||||
gchar *args[] = { "unknown", NULL };
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_otr_log_shows_usage_when_no_args(void **state)
|
||||
{
|
||||
gchar *args[] = { "log", NULL };
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -63,7 +41,7 @@ void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state)
|
||||
|
||||
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -75,7 +53,7 @@ void cmd_otr_log_on_enables_logging(void **state)
|
||||
|
||||
expect_cons_show("OTR messages will be logged as plaintext.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
@ -91,7 +69,7 @@ void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state)
|
||||
expect_cons_show("OTR messages will be logged as plaintext.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -103,7 +81,7 @@ void cmd_otr_log_off_disables_logging(void **state)
|
||||
|
||||
expect_cons_show("OTR message logging disabled.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
@ -118,7 +96,7 @@ void cmd_otr_redact_redacts_logging(void **state)
|
||||
|
||||
expect_cons_show("OTR messages will be logged as '[redacted]'.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
@ -134,7 +112,7 @@ void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state)
|
||||
expect_cons_show("OTR messages will be logged as '[redacted]'.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -149,7 +127,7 @@ void cmd_otr_libver_shows_libotr_version(void **state)
|
||||
|
||||
expect_cons_show(message->str);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_libver(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
|
||||
g_string_free(message, TRUE);
|
||||
@ -163,11 +141,11 @@ void cmd_otr_gen_shows_message_when_not_connected(void **state)
|
||||
|
||||
expect_cons_show("You must be connected with an account to load OTR information.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
static void test_with_command_and_connection_status(char *command, jabber_conn_status_t status)
|
||||
static void test_with_command_and_connection_status(char *command, void *cmd_func, jabber_conn_status_t status)
|
||||
{
|
||||
gchar *args[] = { command, NULL };
|
||||
|
||||
@ -175,33 +153,34 @@ static void test_with_command_and_connection_status(char *command, jabber_conn_s
|
||||
|
||||
expect_cons_show("You must be connected with an account to load OTR information.");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean (*func)(ProfWin *window, const char *const command, gchar **args) = cmd_func;
|
||||
gboolean result = func(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_shows_message_when_disconnected(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("gen", JABBER_DISCONNECTED);
|
||||
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTED);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_shows_message_when_undefined(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("gen", JABBER_UNDEFINED);
|
||||
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_UNDEFINED);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_shows_message_when_started(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("gen", JABBER_STARTED);
|
||||
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_STARTED);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_shows_message_when_connecting(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("gen", JABBER_CONNECTING);
|
||||
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_CONNECTING);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_shows_message_when_disconnecting(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("gen", JABBER_DISCONNECTING);
|
||||
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTING);
|
||||
}
|
||||
|
||||
void cmd_otr_gen_generates_key_for_connected_account(void **state)
|
||||
@ -220,33 +199,33 @@ void cmd_otr_gen_generates_key_for_connected_account(void **state)
|
||||
|
||||
expect_memory(otr_keygen, account, account, sizeof(ProfAccount));
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_disconnected(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTED);
|
||||
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTED);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_undefined(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("myfp", JABBER_UNDEFINED);
|
||||
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_UNDEFINED);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_started(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("myfp", JABBER_STARTED);
|
||||
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_STARTED);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_connecting(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("myfp", JABBER_CONNECTING);
|
||||
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_CONNECTING);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
|
||||
{
|
||||
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
|
||||
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTING);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_message_when_no_key(void **state)
|
||||
@ -258,7 +237,7 @@ void cmd_otr_myfp_shows_message_when_no_key(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -275,7 +254,7 @@ void cmd_otr_myfp_shows_my_fingerprint(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, message->str);
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
|
||||
g_string_free(message, TRUE);
|
||||
@ -292,7 +271,7 @@ test_cmd_otr_theirfp_from_wintype(win_type_t wintype)
|
||||
|
||||
expect_ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint.");
|
||||
|
||||
gboolean result = cmd_otr(&window, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_theirfp(&window, CMD_OTR, args);
|
||||
|
||||
assert_true(result);
|
||||
}
|
||||
@ -328,7 +307,7 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
|
||||
assert_true(result);
|
||||
}
|
||||
@ -358,7 +337,7 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, message->str);
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
|
||||
g_string_free(message, TRUE);
|
||||
@ -375,7 +354,7 @@ test_cmd_otr_start_from_wintype(win_type_t wintype)
|
||||
|
||||
expect_ui_current_print_line("You must be in a regular chat window to start an OTR session.");
|
||||
|
||||
gboolean result = cmd_otr(&window, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_start(&window, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -412,7 +391,7 @@ void cmd_otr_start_shows_message_when_already_started(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -435,7 +414,7 @@ void cmd_otr_start_shows_message_when_no_key(void **state)
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -462,7 +441,7 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
|
||||
expect_string(message_send_chat_otr, barejid, recipient);
|
||||
expect_string(message_send_chat_otr, msg, query_message);
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
|
||||
@ -473,7 +452,7 @@ void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
||||
|
||||
expect_cons_show("This version of Profanity has not been built with OTR support enabled");
|
||||
|
||||
gboolean result = cmd_otr(NULL, CMD_OTR, args);
|
||||
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
}
|
||||
#endif
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
void cmd_otr_shows_usage_when_no_args(void **state);
|
||||
void cmd_otr_shows_usage_when_invalid_subcommand(void **state);
|
||||
void cmd_otr_log_shows_usage_when_no_args(void **state);
|
||||
void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state);
|
||||
void cmd_otr_log_on_enables_logging(void **state);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "command/commands.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
#include "ui/stub_ui.h"
|
||||
|
||||
|
63
tests/unittests/tools/stub_http_upload.c
Normal file
63
tests/unittests/tools/stub_http_upload.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* http_upload.h
|
||||
*
|
||||
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_HTTP_UPLOAD_H
|
||||
#define TOOLS_HTTP_UPLOAD_H
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
// forward -> ui/win_types.h
|
||||
typedef struct prof_win_t ProfWin;
|
||||
|
||||
typedef struct http_upload_t {
|
||||
char *filename;
|
||||
off_t filesize;
|
||||
curl_off_t bytes_sent;
|
||||
char *mime_type;
|
||||
char *get_url;
|
||||
char *put_url;
|
||||
ProfWin *window;
|
||||
pthread_t worker;
|
||||
int cancel;
|
||||
} HTTPUpload;
|
||||
|
||||
//GSList *upload_processes;
|
||||
|
||||
void* http_file_put(void *userdata) {}
|
||||
|
||||
char* file_mime_type(const char* const file_name) {}
|
||||
off_t file_size(const char* const file_name) {}
|
||||
int is_regular_file(const char *filename) {}
|
||||
|
||||
#endif
|
@ -444,6 +444,7 @@ void cons_reconnect_setting(void) {}
|
||||
void cons_autoping_setting(void) {}
|
||||
void cons_autoconnect_setting(void) {}
|
||||
void cons_inpblock_setting(void) {}
|
||||
void cons_tray_setting(void) {}
|
||||
|
||||
void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
|
||||
{
|
||||
|
@ -497,8 +497,6 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark),
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
unit_test(cmd_otr_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_shows_usage_when_invalid_subcommand),
|
||||
unit_test(cmd_otr_log_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_log_shows_usage_when_invalid_subcommand),
|
||||
unit_test_setup_teardown(cmd_otr_log_on_enables_logging,
|
||||
|
@ -71,7 +71,7 @@ jabber_send_stanza(const char *const stanza)
|
||||
}
|
||||
|
||||
// message functions
|
||||
char* message_send_chat(const char * const barejid, const char * const msg)
|
||||
char* message_send_chat(const char * const barejid, const char * const msg, const char *const oob_url)
|
||||
{
|
||||
check_expected(barejid);
|
||||
check_expected(msg);
|
||||
@ -90,8 +90,8 @@ char* message_send_chat_pgp(const char * const barejid, const char * const msg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void message_send_private(const char * const fulljid, const char * const msg) {}
|
||||
void message_send_groupchat(const char * const roomjid, const char * const msg) {}
|
||||
void message_send_private(const char * const fulljid, const char * const msg, const char *const oob_url) {}
|
||||
void message_send_groupchat(const char * const roomjid, const char * const msg, const char *const oob_url) {}
|
||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {}
|
||||
|
||||
void message_send_inactive(const char * const barejid) {}
|
||||
@ -158,6 +158,7 @@ void iq_room_list_request(gchar *conferencejid)
|
||||
void iq_disco_info_request(gchar *jid) {}
|
||||
void iq_disco_items_request(gchar *jid) {}
|
||||
void iq_set_autoping(int seconds) {}
|
||||
void iq_http_upload_request(HTTPUpload *upload) {}
|
||||
void iq_confirm_instant_room(const char * const room_jid) {}
|
||||
void iq_destroy_room(const char * const room_jid) {}
|
||||
void iq_request_room_config_form(const char * const room_jid) {}
|
||||
|
Loading…
Reference in New Issue
Block a user