1
0
Fork 0

Added C plugin code from plugins branch

This commit is contained in:
James Booth 2016-02-14 22:28:55 +00:00
parent f887a35c0c
commit 41fe8c22b1
70 changed files with 2668 additions and 287 deletions

2
.gitignore vendored
View File

@ -33,9 +33,11 @@ m4/
src/config.h
src/config.h.in
src/config.h.in~
src/prof_config.h
src/gitversion.h
src/gitversion.h.in
src/stamp-h1
src/plugins/profapi.lo
# binaries
profanity

View File

@ -4,6 +4,7 @@ install:
- uname -a
- sudo apt-get update
- sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev libgpgme11-dev expect-dev tcl-dev
- sudo apt-get -y install autoconf-archive libtool
- git clone git://github.com/boothj5/libmesode.git
- cd libmesode
- mkdir m4
@ -33,4 +34,4 @@ install:
- cd ..
- rm -rf stabber
- ./bootstrap.sh
script: ./configure && make && make check
script: ./configure --enable-c-plugins && make && make check

View File

@ -41,7 +41,11 @@ core_sources = \
src/config/account.c src/config/account.h \
src/config/preferences.c src/config/preferences.h \
src/config/theme.c src/config/theme.h \
src/config/scripts.c src/config/scripts.h
src/config/scripts.c src/config/scripts.h \
src/plugins/plugins.h src/plugins/plugins.c \
src/plugins/api.h src/plugins/api.c \
src/plugins/callbacks.h src/plugins/callbacks.c \
src/plugins/autocompleters.c src/plugins/autocompleters.h
unittest_sources = \
src/contact.c src/contact.h src/common.c \
@ -69,6 +73,10 @@ unittest_sources = \
src/config/theme.c src/config/theme.h \
src/config/scripts.c src/config/scripts.h \
src/config/conflists.c src/config/conflists.h \
src/plugins/plugins.h src/plugins/plugins.c \
src/plugins/api.h src/plugins/api.c \
src/plugins/callbacks.h src/plugins/callbacks.c \
src/plugins/autocompleters.c src/plugins/autocompleters.h \
src/window_list.c src/window_list.h \
src/event/server_events.c src/event/server_events.h \
src/event/client_events.c src/event/client_events.h \
@ -120,6 +128,10 @@ functionaltest_sources = \
main_source = src/main.c
c_sources = \
src/plugins/c_plugins.h src/plugins/c_plugins.c \
src/plugins/c_api.h src/plugins/c_api.c
git_include = src/gitversion.h
pgp_sources = \
@ -134,6 +146,11 @@ otr3_sources = \
otr4_sources = \
src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c
if BUILD_C_API
core_sources += $(c_sources)
unittest_sources += $(c_sources)
endif
otr_unittest_sources = \
tests/unittests/otr/stub_otr.c
@ -168,6 +185,15 @@ if INCLUDE_GIT_VERSION
BUILT_SOURCES = $(git_include)
endif
if BUILD_C_API
lib_LTLIBRARIES = libprofanity.la
libprofanity_la_LDFLAGS=-avoid-version -shared
libprofanity_la_SOURCES = src/plugins/profapi.c
library_includedir=$(includedir)
library_include_HEADERS = src/plugins/profapi.h
endif
TESTS = tests/unittests/unittests
check_PROGRAMS = tests/unittests/unittests
tests_unittests_unittests_SOURCES = $(unittest_sources)

View File

@ -1,3 +1,3 @@
#!/bin/sh
autoreconf --install
autoreconf -fiv

View File

@ -2,14 +2,16 @@
# Process this file with autoconf to produce a configure script.
AC_INIT([profanity], [0.5.0], [boothj5web@gmail.com])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AX_PREFIX_CONFIG_H([src/prof_config.h], [PROF], [src/config.h])
### Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
## Check for LFS
AC_SYS_LARGEFILE
@ -43,6 +45,10 @@ AS_IF([test "x$PLATFORM" = xosx],
### Options
AC_ARG_ENABLE([notifications],
[AS_HELP_STRING([--enable-notifications], [enable desktop notifications])])
AC_ARG_ENABLE([c-plugins],
[AS_HELP_STRING([--enable-c-plugins], [enable C plugins])])
AC_ARG_ENABLE([plugins],
[AS_HELP_STRING([--enable-plugins], [enable plugins])])
AC_ARG_ENABLE([otr],
[AS_HELP_STRING([--enable-otr], [enable otr encryption])])
AC_ARG_ENABLE([pgp],
@ -52,6 +58,23 @@ AC_ARG_WITH([xscreensaver],
AC_ARG_WITH([themes],
[AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])])
### plugins
# c
LT_INIT
if test "x$enable_plugins" = xno; then
AM_CONDITIONAL([BUILD_C_API], [false])
elif test "x$enable_c_plugins" != xno; then
AC_CHECK_LIB([dl], [main],
[AM_CONDITIONAL([BUILD_C_API], [true]) LIBS="$LIBS -ldl" AC_DEFINE([HAVE_C], [1], [C support])],
[AS_IF(
[test "x$enable_c_plugins" = xyes],
[AC_MSG_ERROR([dl library needed to run C plugins])],
[AM_CONDITIONAL([BUILD_C_API], [false])])
])
else
AM_CONDITIONAL([BUILD_C_API], [false])
fi
### 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])],
@ -208,10 +231,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"])
AM_LDFLAGS="$AM_LDFLAGS -export-dynamic"
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS"
AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\""
LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS"
AC_SUBST(AM_LDFLAGS)
AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_CPPFLAGS)
@ -226,6 +251,7 @@ echo "PLATFORM : $host_os"
echo "PACKAGE_STATUS : $PACKAGE_STATUS"
echo "AM_CFLAGS : $AM_CFLAGS"
echo "AM_CPPFLAGS : $AM_CPPFLAGS"
echo "AM_LDFLAGS : $AM_LDFLAGS"
echo "LIBS : $LIBS"
echo "XML Parser : $PARSER"
echo "Install themes : $THEMES_INSTALL"

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <assert.h>
#include <errno.h>
@ -58,10 +58,11 @@
#include "xmpp/form.h"
#include "log.h"
#include "muc.h"
#ifdef HAVE_LIBOTR
#include "plugins/plugins.h"
#ifdef PROF_HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
#include "profanity.h"
@ -1733,6 +1734,17 @@ static struct cmd_t command_defs[] =
"/account rename me gtalk")
},
{ "/plugins",
cmd_plugins, parse_args, 0, 0, NULL,
CMD_NOTAGS
CMD_SYN(
"/plugins")
CMD_DESC(
"Show currently installed plugins. ")
CMD_NOARGS
CMD_NOEXAMPLES
},
{ "/prefs",
cmd_prefs, parse_args, 0, 1, NULL,
CMD_NOTAGS
@ -2641,7 +2653,7 @@ cmd_exists(char *cmd)
}
void
cmd_autocomplete_add(char *value)
cmd_autocomplete_add(const char *const value)
{
if (commands_ac) {
autocomplete_add(commands_ac, value);
@ -2687,7 +2699,7 @@ cmd_autocomplete_remove_form_fields(DataForm *form)
}
void
cmd_autocomplete_remove(char *value)
cmd_autocomplete_remove(const char *const value)
{
if (commands_ac) {
autocomplete_remove(commands_ac, value);
@ -2756,7 +2768,7 @@ cmd_reset_autocomplete(ProfWin *window)
tlscerts_reset_ac();
prefs_reset_boolean_choice();
presence_reset_sub_request_search();
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
p_gpg_autocomplete_key_reset();
#endif
autocomplete_reset(help_ac);
@ -2867,6 +2879,7 @@ cmd_reset_autocomplete(ProfWin *window)
prefs_reset_room_trigger_ac();
win_reset_search_attempts();
win_close_reset_search_attempts();
plugins_reset_autocomplete();
}
gboolean
@ -2968,6 +2981,8 @@ _cmd_execute(ProfWin *window, const char *const command, const char *const inp)
g_strfreev(args);
return result;
}
} else if (plugins_run_command(inp)) {
return TRUE;
} else {
gboolean ran_alias = FALSE;
gboolean alias_result = cmd_execute_alias(window, inp, &ran_alias);
@ -3128,6 +3143,11 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
}
g_hash_table_destroy(ac_funcs);
result = plugins_autocomplete(input);
if (result) {
return result;
}
if (g_str_has_prefix(input, "/field")) {
result = _form_field_autocomplete(window, input);
if (result) {
@ -3190,7 +3210,7 @@ _who_autocomplete(ProfWin *window, const char *const input)
}
}
return NULL;
return result;
}
static char*
@ -3647,7 +3667,7 @@ _pgp_autocomplete(ProfWin *window, const char *const input)
return found;
}
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
gboolean result;
gchar **args = parse_args(input, 2, 3, &result);
if ((strncmp(input, "/pgp", 4) == 0) && (result == TRUE)) {
@ -4568,7 +4588,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
if (found) {
return found;
}
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);

View File

@ -47,8 +47,8 @@ void cmd_uninit(void);
char* cmd_autocomplete(ProfWin *window, const char *const input);
void cmd_reset_autocomplete(ProfWin *window);
void cmd_autocomplete_add(char *value);
void cmd_autocomplete_remove(char *value);
void cmd_autocomplete_add(const char *const value);
void cmd_autocomplete_remove(const char *const value);
void cmd_autocomplete_add_form_fields(DataForm *form);
void cmd_autocomplete_remove_form_fields(DataForm *form);
void cmd_alias_add(char *value);

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <string.h>
#include <stdlib.h>
@ -61,13 +61,14 @@
#include "jid.h"
#include "log.h"
#include "muc.h"
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
#include "profanity.h"
#include "plugins/plugins.h"
#include "tools/autocomplete.h"
#include "tools/parser.h"
#include "tools/tinyurl.h"
@ -100,12 +101,19 @@ cmd_execute_default(ProfWin *window, const char *inp)
return TRUE;
}
// handle non commands in non chat windows
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE) {
// handle non commands in non chat or plugin windows
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE && window->type != WIN_PLUGIN) {
cons_show("Unknown command: %s", inp);
return TRUE;
}
// handle plugin window
if (window->type == WIN_PLUGIN) {
ProfPluginWin *pluginwin = (ProfPluginWin*)window;
plugins_win_process_line(pluginwin->tag, inp);
return TRUE;
}
jabber_conn_status_t status = jabber_get_connection_status();
if (status != JABBER_CONNECTED) {
ui_current_print_line("You are not currently connected.");
@ -167,7 +175,7 @@ gboolean
cmd_tls(ProfWin *window, const char *const command, gchar **args)
{
if (g_strcmp0(args[0], "certpath") == 0) {
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
if (g_strcmp0(args[1], "set") == 0) {
if (args[2] == NULL) {
cons_bad_cmd_usage(command);
@ -203,7 +211,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
return TRUE;
#endif
} else if (g_strcmp0(args[0], "trust") == 0) {
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
@ -232,7 +240,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
return TRUE;
#endif
} else if (g_strcmp0(args[0], "trusted") == 0) {
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
GList *certs = tlscerts_list();
GList *curr = certs;
@ -255,7 +263,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
return TRUE;
#endif
} else if (g_strcmp0(args[0], "revoke") == 0) {
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
} else {
@ -274,7 +282,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
} else if (g_strcmp0(args[0], "show") == 0) {
return _cmd_set_boolean_preference(args[1], command, "TLS titlebar indicator", PREF_TLS_SHOW);
} else if (g_strcmp0(args[0], "cert") == 0) {
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
if (args[1]) {
TLSCertificate *cert = tlscerts_get_trusted(args[1]);
if (!cert) {
@ -654,7 +662,7 @@ cmd_account(ProfWin *window, const char *const command, gchar **args)
}
cons_show("");
} else if (strcmp(property, "pgpkeyid") == 0) {
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
char *err_str = NULL;
if (!p_gpg_valid_key(value, &err_str)) {
cons_show("Invalid PGP key ID specified: %s, see /pgp keys", err_str);
@ -1886,7 +1894,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
if (msg) {
cl_ev_send_msg(chatwin, msg);
} else {
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
if (otr_is_secure(barejid)) {
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
}
@ -2774,7 +2782,7 @@ cmd_resource(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
if (otr_is_secure(chatwin->barejid)) {
cons_show("Cannot choose resource during an OTR session.");
return TRUE;
@ -5602,10 +5610,31 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gboolean
cmd_plugins(ProfWin *window, const char *const command, gchar **args)
{
GSList *plugins = plugins_get_list();
GSList *curr = plugins;
if (curr == NULL) {
cons_show("No plugins installed.");
} else {
cons_show("Installed plugins:");
while (curr) {
ProfPlugin *plugin = curr->data;
char *lang = plugins_get_lang_string(plugin);
cons_show(" %s (%s)", plugin->name, lang);
curr = g_slist_next(curr);
}
}
g_slist_free(curr);
return TRUE;
}
gboolean
cmd_pgp(ProfWin *window, const char *const command, gchar **args)
{
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
if (args[0] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
@ -5837,13 +5866,12 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args)
cons_show("This version of Profanity has not been built with PGP support enabled");
return TRUE;
#endif
}
gboolean
cmd_otr(ProfWin *window, const char *const command, gchar **args)
{
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
if (args[0] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;

View File

@ -153,6 +153,7 @@ gboolean cmd_script(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_export(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_charset(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_console(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_plugins(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);

View File

@ -31,7 +31,7 @@
* source files in the program, then also delete it here.
*
*/
#include "config.h"
#include "prof_config.h"
#include <sys/select.h>
#include <assert.h>
@ -46,6 +46,12 @@
#include <curl/easy.h>
#include <glib.h>
#ifdef PROF_HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif PROF_HAVE_NCURSES_H
#include <ncurses.h>
#endif
#include "tools/p_sha1.h"
#include "log.h"
@ -341,7 +347,7 @@ release_is_new(char *found_version)
{
int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch;
int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
int parse_curr = sscanf(PROF_PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
&curr_patch);
int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min,
&found_patch);
@ -651,10 +657,10 @@ is_notify_enabled(void)
{
gboolean notify_enabled = FALSE;
#ifdef HAVE_OSXNOTIFY
#ifdef PROF_HAVE_OSXNOTIFY
notify_enabled = TRUE;
#endif
#ifdef HAVE_LIBNOTIFY
#ifdef PROF_HAVE_LIBNOTIFY
notify_enabled = TRUE;
#endif
#ifdef PLATFORM_CYGWIN

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <stdlib.h>
#include <stdio.h>
@ -591,6 +591,19 @@ prefs_set_autoxa_time(gint value)
_save_prefs();
}
gchar **
prefs_get_plugins(void)
{
if (!g_key_file_has_group(prefs, "plugins")) {
return NULL;
}
if (!g_key_file_has_key(prefs, "plugins", "load", NULL)) {
return NULL;
}
return g_key_file_get_string_list(prefs, "plugins", "load", NULL, NULL);
}
void
prefs_set_occupants_size(gint value)
{

View File

@ -35,7 +35,7 @@
#ifndef PREFERENCES_H
#define PREFERENCES_H
#include "config.h"
#include "prof_config.h"
#include <glib.h>
@ -183,6 +183,8 @@ void prefs_set_autoaway_time(gint value);
gint prefs_get_autoxa_time(void);
void prefs_set_autoxa_time(gint value);
gchar** prefs_get_plugins(void);
char prefs_get_otr_char(void);
void prefs_set_otr_char(char ch);
char prefs_get_pgp_char(void);

View File

@ -32,15 +32,15 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#ifdef PROF_HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif HAVE_NCURSES_H
#elif PROF_HAVE_NCURSES_H
#include <ncurses.h>
#endif

View File

@ -35,7 +35,7 @@
#ifndef THEME_H
#define THEME_H
#include "config.h"
#include "prof_config.h"
#include <glib.h>

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <stdlib.h>
#include <glib.h>
@ -43,10 +43,11 @@
#include "xmpp/xmpp.h"
#include "roster_list.h"
#include "chat_session.h"
#ifdef HAVE_LIBOTR
#include "plugins/plugins.h"
#ifdef PROF_HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
@ -80,7 +81,7 @@ cl_ev_disconnect(void)
muc_invites_clear();
chat_sessions_clear();
tlscerts_clear_current();
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
p_gpg_on_disconnect();
#endif
}
@ -90,7 +91,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
{
char *signed_status = NULL;
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
char *account_name = jabber_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
if (account->pgp_keyid) {
@ -108,21 +109,22 @@ void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
{
chat_state_active(chatwin->state);
char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBOTR
#ifdef PROF_HAVE_LIBGPGME
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP);
free(id);
} else {
gboolean handled = otr_on_message_send(chatwin, msg);
gboolean handled = otr_on_message_send(chatwin, plugin_msg);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
char *id = message_send_chat(chatwin->barejid, plugin_msg);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
free(id);
}
}
@ -131,13 +133,13 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
#endif
// OTR supported, PGP unsupported
#ifdef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
gboolean handled = otr_on_message_send(chatwin, msg);
#ifdef PROF_HAVE_LIBOTR
#ifndef PROF_HAVE_LIBGPGME
gboolean handled = otr_on_message_send(chatwin, plugin_msg);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
char *id = message_send_chat(chatwin->barejid, plugin_msg);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
free(id);
}
return;
@ -145,17 +147,17 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
#endif
// OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
#ifndef PROF_HAVE_LIBOTR
#ifdef PROF_HAVE_LIBGPGME
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
char *id = message_send_chat(chatwin->barejid, plugin_msg);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
free(id);
}
return;
@ -163,21 +165,29 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
#endif
// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
#ifndef PROF_HAVE_LIBOTR
#ifndef PROF_HAVE_LIBGPGME
char *id = message_send_chat(chatwin->barejid, plugin_msg);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
free(id);
return;
#endif
#endif
plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
free(plugin_msg);
}
void
cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg)
{
message_send_groupchat(mucwin->roomjid, msg);
char *plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg);
message_send_groupchat(mucwin->roomjid, plugin_msg);
plugins_post_room_message_send(mucwin->roomjid, plugin_msg);
free(plugin_msg);
}
void
@ -188,7 +198,12 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg)
} else if (privwin->room_left) {
privwin_message_left_room(privwin);
} else {
message_send_private(privwin->fulljid, msg);
privwin_outgoing_msg(privwin, msg);
char *plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg);
message_send_private(privwin->fulljid, plugin_msg);
privwin_outgoing_msg(privwin, plugin_msg);
plugins_post_priv_message_send(privwin->fulljid, plugin_msg);
free(plugin_msg);
}
}

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <string.h>
#include <stdlib.h>
@ -45,15 +45,16 @@
#include "config/account.h"
#include "config/scripts.h"
#include "roster_list.h"
#include "plugins/plugins.h"
#include "window_list.h"
#include "config/tlscerts.h"
#include "profanity.h"
#include "event/client_events.h"
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
@ -66,11 +67,11 @@ sv_ev_login_account_success(char *account_name, int secured)
roster_create();
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
otr_on_connect(account);
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
p_gpg_on_connect(account->jid);
#endif
@ -106,7 +107,7 @@ sv_ev_roster_received(void)
char *account_name = jabber_get_account_name();
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
// check pgp key valid if specified
ProfAccount *account = accounts_get_account(account_name);
if (account && account->pgp_keyid) {
@ -146,6 +147,9 @@ sv_ev_roster_received(void)
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
const char *fulljid = jabber_get_fulljid();
plugins_on_connect(account_name, fulljid);
}
void
@ -153,7 +157,7 @@ sv_ev_lost_connection(void)
{
cons_show_error("Lost connection.");
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
GSList *recipients = wins_get_chat_recipients();
GSList *curr = recipients;
while (curr) {
@ -174,7 +178,7 @@ sv_ev_lost_connection(void)
chat_sessions_clear();
ui_disconnected();
roster_destroy();
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
p_gpg_on_disconnect();
#endif
}
@ -226,7 +230,10 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
{
ProfMucWin *mucwin = wins_get_muc(room_jid);
if (mucwin) {
mucwin_history(mucwin, nick, timestamp, message);
char *new_message = plugins_pre_room_message_display(room_jid, nick, message);
mucwin_history(mucwin, nick, timestamp, new_message);
plugins_post_room_message_display(room_jid, nick, new_message);
free(new_message);
}
}
@ -244,10 +251,11 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
return;
}
char *new_message = plugins_pre_room_message_display(room_jid, nick, message);
char *mynick = muc_nick(mucwin->roomjid);
gboolean mention = FALSE;
char *message_lower = g_utf8_strdown(message, -1);
char *message_lower = g_utf8_strdown(new_message, -1);
char *mynick_lower = g_utf8_strdown(mynick, -1);
if (g_strrstr(message_lower, mynick_lower)) {
mention = TRUE;
@ -255,9 +263,9 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
g_free(message_lower);
g_free(mynick_lower);
GList *triggers = prefs_message_get_triggers(message);
GList *triggers = prefs_message_get_triggers(new_message);
mucwin_message(mucwin, nick, message, mention, triggers);
mucwin_message(mucwin, nick, new_message, mention, triggers);
ProfWin *window = (ProfWin*)mucwin;
int num = wins_get_num(window);
@ -292,9 +300,9 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
}
}
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, nick, message, mention, triggers != NULL)) {
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, nick, new_message, mention, triggers != NULL)) {
Jid *jidp = jid_create(mucwin->roomjid);
notify_room_message(nick, jidp->localpart, num, message);
notify_room_message(nick, jidp->localpart, num, new_message);
jid_destroy(jidp);
}
@ -303,29 +311,44 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
}
rosterwin_roster();
plugins_post_room_message_display(room_jid, nick, new_message);
free(new_message);
}
void
sv_ev_incoming_private_message(const char *const fulljid, char *message)
{
char *plugin_message = plugins_pre_priv_message_display(fulljid, message);
ProfPrivateWin *privatewin = wins_get_private(fulljid);
if (privatewin == NULL) {
ProfWin *window = wins_new_private(fulljid);
privatewin = (ProfPrivateWin*)window;
}
privwin_incoming_msg(privatewin, message, NULL);
privwin_incoming_msg(privatewin, plugin_message, NULL);
plugins_post_priv_message_display(fulljid, plugin_message);
free(plugin_message);
rosterwin_roster();
}
void
sv_ev_delayed_private_message(const char *const fulljid, char *message, GDateTime *timestamp)
{
char *new_message = plugins_pre_priv_message_display(fulljid, message);
ProfPrivateWin *privatewin = wins_get_private(fulljid);
if (privatewin == NULL) {
ProfWin *window = wins_new_private(fulljid);
privatewin = (ProfPrivateWin*)window;
}
privwin_incoming_msg(privatewin, message, timestamp);
privwin_incoming_msg(privatewin, new_message, timestamp);
plugins_post_priv_message_display(fulljid, new_message);
free(new_message);
}
void
@ -356,7 +379,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
chat_log_msg_in(barejid, message, NULL);
}
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
static void
_sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp)
{
@ -374,7 +397,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
}
#endif
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
static void
_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp)
{
@ -394,7 +417,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
}
#endif
#ifndef HAVE_LIBOTR
#ifndef PROF_HAVE_LIBOTR
static void
_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp)
{
@ -416,8 +439,8 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
}
// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBOTR
#ifdef PROF_HAVE_LIBGPGME
if (pgp_message) {
if (chatwin->is_otr) {
win_println((ProfWin*)chatwin, 0, "PGP encrypted message received whilst in OTR session.");
@ -433,8 +456,8 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
#endif
// OTR supported, PGP unsupported
#ifdef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBOTR
#ifndef PROF_HAVE_LIBGPGME
_sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message, timestamp);
rosterwin_roster();
return;
@ -442,8 +465,8 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
#endif
// OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
#ifndef PROF_HAVE_LIBOTR
#ifdef PROF_HAVE_LIBGPGME
if (pgp_message) {
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, timestamp);
} else {
@ -455,8 +478,8 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
#endif
// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
#ifndef PROF_HAVE_LIBOTR
#ifndef PROF_HAVE_LIBGPGME
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, timestamp);
rosterwin_roster();
return;
@ -568,7 +591,7 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status)
ui_contact_offline(barejid, resource, status);
}
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin && otr_is_secure(barejid)) {
chatwin_otr_unsecured(chatwin);
@ -589,7 +612,7 @@ sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity
ui_contact_online(barejid, resource, last_activity);
}
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
if (pgpsig) {
p_gpg_verify(barejid, pgpsig);
}

View File

@ -32,12 +32,12 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <string.h>
#include <glib.h>
#ifdef HAVE_GIT_VERSION
#ifdef PROF_HAVE_GIT_VERSION
#include "gitversion.h"
#endif
@ -52,7 +52,7 @@ static char *account_name = NULL;
int
main(int argc, char **argv)
{
if (argc == 2 && g_strcmp0(argv[1], "docgen") == 0 && g_strcmp0(PACKAGE_STATUS, "development") == 0) {
if (argc == 2 && g_strcmp0(argv[1], "docgen") == 0 && g_strcmp0(PROF_PACKAGE_STATUS, "development") == 0) {
command_docgen();
return 0;
}
@ -80,17 +80,17 @@ main(int argc, char **argv)
g_option_context_free(context);
if (version == TRUE) {
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
g_print("Profanity, version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) {
#ifdef PROF_HAVE_GIT_VERSION
g_print("Profanity, version %sdev.%s.%s\n", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
g_print("Profanity, version %sdev\n", PACKAGE_VERSION);
g_print("Profanity, version %sdev\n", PROF_PACKAGE_VERSION);
#endif
} else {
g_print("Profanity, version %s\n", PACKAGE_VERSION);
g_print("Profanity, version %s\n", PROF_PACKAGE_VERSION);
}
g_print("Copyright (C) 2012 - 2015 James Booth <%s>.\n", PACKAGE_BUGREPORT);
g_print("Copyright (C) 2012 - 2015 James Booth <%s>.\n", PROF_PACKAGE_BUGREPORT);
g_print("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
g_print("\n");
g_print("This is free software; you are free to change and redistribute it.\n");
@ -99,10 +99,10 @@ main(int argc, char **argv)
g_print("Build information:\n");
#ifdef HAVE_LIBMESODE
#ifdef PROF_HAVE_LIBMESODE
g_print("XMPP library: libmesode\n");
#endif
#ifdef HAVE_LIBSTROPHE
#ifdef PROF_HAVE_LIBSTROPHE
g_print("XMPP library: libstrophe\n");
#endif
@ -112,13 +112,13 @@ main(int argc, char **argv)
g_print("Desktop notification support: Disabled\n");
}
#ifdef HAVE_LIBOTR
#ifdef PROF_HAVE_LIBOTR
g_print("OTR support: Enabled\n");
#else
g_print("OTR support: Disabled\n");
#endif
#ifdef HAVE_LIBGPGME
#ifdef PROF_HAVE_LIBGPGME
g_print("PGP support: Enabled\n");
#else
g_print("PGP support: Disabled\n");

View File

@ -32,7 +32,7 @@
*
*/
#include "config.h"
#include "prof_config.h"
#include <locale.h>
#include <string.h>

233
src/plugins/api.c Normal file
View File

@ -0,0 +1,233 @@
/*
* api.c
*
* Copyright (C) 2012 - 2015 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.
*
*/
#include <stdlib.h>
#include <assert.h>
#include <glib.h>
#include "log.h"
#include "plugins/callbacks.h"
#include "plugins/autocompleters.h"
#include "profanity.h"
#include "ui/ui.h"
#include "config/theme.h"
#include "command/command.h"
#include "window_list.h"
#include "common.h"
void
api_cons_alert(void)
{
cons_alert();
}
void
api_cons_show(const char * const message)
{
if (message) {
char *parsed = str_replace(message, "\r\n", "\n");
cons_show("%s", parsed);
free(parsed);
}
}
void
api_register_command(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void *callback,
void(*callback_func)(PluginCommand *command, gchar **args))
{
PluginCommand *command = malloc(sizeof(PluginCommand));
command->command_name = command_name;
command->min_args = min_args;
command->max_args = max_args;
command->usage = usage;
command->short_help = short_help;
command->long_help = long_help;
command->callback = callback;
command->callback_func = callback_func;
callbacks_add_command(command);
}
void
api_register_timed(void *callback, int interval_seconds,
void (*callback_func)(PluginTimedFunction *timed_function))
{
PluginTimedFunction *timed_function = malloc(sizeof(PluginTimedFunction));
timed_function->callback = callback;
timed_function->callback_func = callback_func;
timed_function->interval_seconds = interval_seconds;
timed_function->timer = g_timer_new();
callbacks_add_timed(timed_function);
}
void
api_register_ac(const char *key, char **items)
{
autocompleters_add(key, items);
}
void
api_notify(const char *message, const char *category, int timeout_ms)
{
notify(message, timeout_ms, category);
}
void
api_send_line(char *line)
{
ProfWin *current = wins_get_current();
cmd_process_input(current, line);
}
char *
api_get_current_recipient(void)
{
ProfWin *current = wins_get_current();
if (current->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin->barejid;
} else {
return NULL;
}
}
char *