1
0
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:
James Booth 2016-04-30 23:31:16 +01:00
commit 5bf9777468
19 changed files with 489 additions and 199 deletions

View File

@ -50,6 +50,7 @@ core_sources = \
src/plugins/autocompleters.c src/plugins/autocompleters.h \ src/plugins/autocompleters.c src/plugins/autocompleters.h \
src/plugins/themes.c src/plugins/themes.h \ src/plugins/themes.c src/plugins/themes.h \
src/plugins/settings.c src/plugins/settings.h \ src/plugins/settings.c src/plugins/settings.h \
src/plugins/disco.c src/plugins/disco.h \
src/tray.h src/tray.c src/tray.h src/tray.c
unittest_sources = \ unittest_sources = \
@ -84,6 +85,7 @@ unittest_sources = \
src/plugins/autocompleters.c src/plugins/autocompleters.h \ src/plugins/autocompleters.c src/plugins/autocompleters.h \
src/plugins/themes.c src/plugins/themes.h \ src/plugins/themes.c src/plugins/themes.h \
src/plugins/settings.c src/plugins/settings.h \ src/plugins/settings.c src/plugins/settings.h \
src/plugins/disco.c src/plugins/disco.h \
src/window_list.c src/window_list.h \ src/window_list.c src/window_list.h \
src/event/server_events.c src/event/server_events.h \ src/event/server_events.c src/event/server_events.h \
src/event/client_events.c src/event/client_events.h \ src/event/client_events.c src/event/client_events.h \

View File

@ -64,7 +64,7 @@ AC_ARG_WITH([xscreensaver],
AC_ARG_WITH([themes], AC_ARG_WITH([themes],
[AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])]) [AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])])
AC_ARG_ENABLE([icons], AC_ARG_ENABLE([icons],
[AS_HELP_STRING([--enable-icons], [enable icons])]) [AS_HELP_STRING([--enable-icons], [enable GTK tray icons])])
### plugins ### plugins
@ -120,7 +120,7 @@ fi
ACX_PTHREAD ACX_PTHREAD
LIBS="$PTHREAD_LIBS $LIBS" LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC" AS_IF([test "x$PTHREAD_CC" != x], [ CC="$PTHREAD_CC" ])
### Check for libmesode, fall back to libstrophe ### Check for libmesode, fall back to libstrophe
PKG_CHECK_MODULES([libmesode], [libmesode], PKG_CHECK_MODULES([libmesode], [libmesode],
@ -166,12 +166,12 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [],
PKG_CHECK_MODULES([curl], [libcurl], [], PKG_CHECK_MODULES([curl], [libcurl], [],
[AC_MSG_ERROR([libcurl is required for profanity])]) [AC_MSG_ERROR([libcurl is required for profanity])])
# Checks GTK+ 2.0 AS_IF([test "x$enable_icons" != xno],
PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.24.10], [PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.24.10],
[AC_DEFINE([HAVE_GTK], [1], [libgtk module])], [AC_DEFINE([HAVE_GTK], [1], [libgtk module])],
[AS_IF([test "x$enable_icons" = xyes], [AS_IF([test "x$enable_icons" = xyes],
[AC_MSG_ERROR([gtk+-2.0 or higher is required for icons])], [AC_MSG_ERROR([gtk+-2.0 or higher is required for icons])],
[AC_MSG_NOTICE([gtk+-2.0 not found, icons not enabled])])]) [AC_MSG_NOTICE([gtk+-2.0 not found, icons not enabled])])])])
AS_IF([test "x$PLATFORM" != xosx], AS_IF([test "x$PLATFORM" != xosx],
[AC_CHECK_LIB([readline], [main], [], [AC_CHECK_LIB([readline], [main], [],

View File

@ -3288,7 +3288,7 @@ _cmd_execute(ProfWin *window, const char *const command, const char *const inp)
ui_invalid_command_usage(cmd->cmd, cmd->setting_func); ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE; return TRUE;
} }
if (args[0] && cmd->sub_funcs) { if (args[0] && cmd->sub_funcs[0][0]) {
int i = 0; int i = 0;
while (cmd->sub_funcs[i][0]) { while (cmd->sub_funcs[i][0]) {
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i][0]) == 0) { if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i][0]) == 0) {

View File

@ -635,6 +635,264 @@ cmd_account_default(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
gboolean
_account_set_jid(char *account_name, char *jid)
{
Jid *jidp = jid_create(jid);
if (jidp == NULL) {
cons_show("Malformed jid: %s", jid);
} else {
accounts_set_jid(account_name, jidp->barejid);
cons_show("Updated jid for account %s: %s", account_name, jidp->barejid);
if (jidp->resourcepart) {
accounts_set_resource(account_name, jidp->resourcepart);
cons_show("Updated resource for account %s: %s", account_name, jidp->resourcepart);
}
cons_show("");
}
jid_destroy(jidp);
return TRUE;
}
gboolean
_account_set_server(char *account_name, char *server)
{
accounts_set_server(account_name, server);
cons_show("Updated server for account %s: %s", account_name, server);
cons_show("");
return TRUE;
}
gboolean
_account_set_port(char *account_name, char *port)
{
int porti;
char *err_msg = NULL;
gboolean res = strtoi_range(port, &porti, 1, 65535, &err_msg);
if (!res) {
cons_show(err_msg);
cons_show("");
free(err_msg);
} else {
accounts_set_port(account_name, porti);
cons_show("Updated port for account %s: %s", account_name, port);
cons_show("");
}
return TRUE;
}
gboolean
_account_set_resource(char *account_name, char *resource)
{
accounts_set_resource(account_name, resource);
if (jabber_get_connection_status() == JABBER_CONNECTED) {
cons_show("Updated resource for account %s: %s, reconnect to pick up the change.", account_name, resource);
} else {
cons_show("Updated resource for account %s: %s", account_name, resource);
}
cons_show("");
return TRUE;
}
gboolean
_account_set_password(char *account_name, char *password)
{
ProfAccount *account = accounts_get_account(account_name);
if (account->eval_password) {
cons_show("Cannot set password when eval_password is set.");
} else {
accounts_set_password(account_name, password);
cons_show("Updated password for account %s", account_name);
cons_show("");
}
account_free(account);
return TRUE;
}
gboolean
_account_set_eval_password(char *account_name, char *eval_password)
{
ProfAccount *account = accounts_get_account(account_name);
if(account->password) {
cons_show("Cannot set eval_password when password is set.");
} else {
accounts_set_eval_password(account_name, eval_password);
cons_show("Updated eval_password for account %s", account_name);
cons_show("");
}
account_free(account);
return TRUE;
}
gboolean
_account_set_muc(char *account_name, char *muc)
{
accounts_set_muc_service(account_name, muc);
cons_show("Updated muc service for account %s: %s", account_name, muc);
cons_show("");
return TRUE;
}
gboolean
_account_set_nick(char *account_name, char *nick)
{
accounts_set_muc_nick(account_name, nick);
cons_show("Updated muc nick for account %s: %s", account_name, nick);
cons_show("");
return TRUE;
}
gboolean
_account_set_otr(char *account_name, char *policy)
{
if ((g_strcmp0(policy, "manual") != 0)
&& (g_strcmp0(policy, "opportunistic") != 0)
&& (g_strcmp0(policy, "always") != 0)) {
cons_show("OTR policy must be one of: manual, opportunistic or always.");
} else {
accounts_set_otr_policy(account_name, policy);
cons_show("Updated OTR policy for account %s: %s", account_name, policy);
cons_show("");
}
return TRUE;
}
gboolean
_account_set_status(char *account_name, char *status)
{
if (!valid_resource_presence_string(status) && (strcmp(status, "last") != 0)) {
cons_show("Invalid status: %s", status);
} else {
accounts_set_login_presence(account_name, status);
cons_show("Updated login status for account %s: %s", account_name, status);
}
cons_show("");
return TRUE;
}
gboolean
_account_set_pgpkeyid(char *account_name, char *pgpkeyid)
{
#ifdef HAVE_LIBGPGME
char *err_str = NULL;
if (!p_gpg_valid_key(pgpkeyid, &err_str)) {
cons_show("Invalid PGP key ID specified: %s, see /pgp keys", err_str);
} else {
accounts_set_pgp_keyid(account_name, pgpkeyid);
cons_show("Updated PGP key ID for account %s: %s", account_name, pgpkeyid);
}
free(err_str);
#else
cons_show("PGP support is not included in this build.");
#endif
cons_show("");
return TRUE;
}
gboolean
_account_set_startscript(char *account_name, char *script)
{
accounts_set_script_start(account_name, script);
cons_show("Updated start script for account %s: %s", account_name, script);
return TRUE;
}
gboolean
_account_set_theme(char *account_name, char *theme)
{
if (!theme_exists(theme)) {
cons_show("Theme does not exist: %s", theme);
return TRUE;
}
accounts_set_theme(account_name, theme);
if (jabber_get_connection_status() == JABBER_CONNECTED) {
ProfAccount *account = accounts_get_account(jabber_get_account_name());
if (account) {
if (g_strcmp0(account->name, account_name) == 0) {
theme_load(theme);
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
} else {
ui_hide_roster();
}
if (prefs_get_boolean(PREF_OCCUPANTS)) {
ui_show_all_room_rosters();
} else {
ui_hide_all_room_rosters();
}
ui_redraw();
}
account_free(account);
}
}
cons_show("Updated theme for account %s: %s", account_name, theme);
return TRUE;
}
gboolean
_account_set_tls(char *account_name, char *policy)
{
if ((g_strcmp0(policy, "force") != 0)
&& (g_strcmp0(policy, "allow") != 0)
&& (g_strcmp0(policy, "disable") != 0)) {
cons_show("TLS policy must be one of: force, allow or disable.");
} else {
accounts_set_tls_policy(account_name, policy);
cons_show("Updated TLS policy for account %s: %s", account_name, policy);
cons_show("");
}
return TRUE;
}
gboolean
_account_set_presence_priority(char *account_name, char *presence, char *priority)
{
int intval;
char *err_msg = NULL;
gboolean res = strtoi_range(priority, &intval, -128, 127, &err_msg);
if (!res) {
cons_show(err_msg);
free(err_msg);
return TRUE;
}
resource_presence_t presence_type = resource_presence_from_string(presence);
switch (presence_type)
{
case (RESOURCE_ONLINE):
accounts_set_priority_online(account_name, intval);
break;
case (RESOURCE_CHAT):
accounts_set_priority_chat(account_name, intval);
break;
case (RESOURCE_AWAY):
accounts_set_priority_away(account_name, intval);
break;
case (RESOURCE_XA):
accounts_set_priority_xa(account_name, intval);
break;
case (RESOURCE_DND):
accounts_set_priority_dnd(account_name, intval);
break;
}
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status == JABBER_CONNECTED) {
char *connected_account = jabber_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
if (presence_type == last_presence) {
char *message = jabber_get_presence_message();
cl_ev_presence_send(last_presence, message, 0);
}
}
cons_show("Updated %s priority for account %s: %s", presence, account_name, priority);
cons_show("");
return TRUE;
}
gboolean gboolean
cmd_account_set(ProfWin *window, const char *const command, gchar **args) cmd_account_set(ProfWin *window, const char *const command, gchar **args)
{ {
@ -644,197 +902,36 @@ cmd_account_set(ProfWin *window, const char *const command, gchar **args)
} }
char *account_name = args[1]; char *account_name = args[1];
char *property = args[2];
char *value = args[3];
if (!accounts_account_exists(account_name)) { if (!accounts_account_exists(account_name)) {
cons_show("Account %s doesn't exist", account_name); cons_show("Account %s doesn't exist", account_name);
cons_show(""); cons_show("");
return TRUE; return TRUE;
} }
if (strcmp(property, "jid") == 0) { char *property = args[2];
Jid *jid = jid_create(args[3]); char *value = args[3];
if (jid == NULL) { if (strcmp(property, "jid") == 0) return _account_set_jid(account_name, value);
cons_show("Malformed jid: %s", value); if (strcmp(property, "server") == 0) return _account_set_server(account_name, value);
} else { if (strcmp(property, "port") == 0) return _account_set_port(account_name, value);
accounts_set_jid(account_name, jid->barejid); if (strcmp(property, "resource") == 0) return _account_set_resource(account_name, value);
cons_show("Updated jid for account %s: %s", account_name, jid->barejid); if (strcmp(property, "password") == 0) return _account_set_password(account_name, value);
if (jid->resourcepart) { if (strcmp(property, "eval_password") == 0) return _account_set_eval_password(account_name, value);
accounts_set_resource(account_name, jid->resourcepart); if (strcmp(property, "muc") == 0) return _account_set_muc(account_name, value);
cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart); if (strcmp(property, "nick") == 0) return _account_set_nick(account_name, value);
} if (strcmp(property, "otr") == 0) return _account_set_otr(account_name, value);
cons_show(""); if (strcmp(property, "status") == 0) return _account_set_status(account_name, value);
} if (strcmp(property, "pgpkeyid") == 0) return _account_set_pgpkeyid(account_name, value);
jid_destroy(jid); if (strcmp(property, "startscript") == 0) return _account_set_startscript(account_name, value);
} else if (strcmp(property, "server") == 0) { if (strcmp(property, "theme") == 0) return _account_set_theme(account_name, value);
accounts_set_server(account_name, value); if (strcmp(property, "tls") == 0) return _account_set_tls(account_name, value);
cons_show("Updated server for account %s: %s", account_name, value);
cons_show("");
} else if (strcmp(property, "port") == 0) {
int port;
char *err_msg = NULL;
gboolean res = strtoi_range(value, &port, 1, 65535, &err_msg);
if (!res) {
cons_show(err_msg);
cons_show("");
free(err_msg);
return TRUE;
} else {
accounts_set_port(account_name, port);
cons_show("Updated port for account %s: %s", account_name, value);
cons_show("");
}
} else if (strcmp(property, "resource") == 0) {
accounts_set_resource(account_name, value);
if (jabber_get_connection_status() == JABBER_CONNECTED) {
cons_show("Updated resource for account %s: %s, you will need to reconnect to pick up the change.", account_name, value);
} else {
cons_show("Updated resource for account %s: %s", account_name, value);
}
cons_show("");
} else if (strcmp(property, "password") == 0) {
if(accounts_get_account(account_name)->eval_password) {
cons_show("Cannot set password when eval_password is set.");
} else {
accounts_set_password(account_name, value);
cons_show("Updated password for account %s", account_name);
cons_show("");
}
} else if (strcmp(property, "eval_password") == 0) {
if(accounts_get_account(account_name)->password) {
cons_show("Cannot set eval_password when password is set.");
} else {
accounts_set_eval_password(account_name, value);
cons_show("Updated eval_password for account %s", account_name);
cons_show("");
}
} else if (strcmp(property, "muc") == 0) {
accounts_set_muc_service(account_name, value);
cons_show("Updated muc service for account %s: %s", account_name, value);
cons_show("");
} else if (strcmp(property, "nick") == 0) {
accounts_set_muc_nick(account_name, value);
cons_show("Updated muc nick for account %s: %s", account_name, value);
cons_show("");
} else if (strcmp(property, "otr") == 0) {
if ((g_strcmp0(value, "manual") != 0)
&& (g_strcmp0(value, "opportunistic") != 0)
&& (g_strcmp0(value, "always") != 0)) {
cons_show("OTR policy must be one of: manual, opportunistic or always.");
} else {
accounts_set_otr_policy(account_name, value);
cons_show("Updated OTR policy for account %s: %s", account_name, value);
cons_show("");
}
} else if (strcmp(property, "status") == 0) {
if (!valid_resource_presence_string(value) && (strcmp(value, "last") != 0)) {
cons_show("Invalid status: %s", value);
} else {
accounts_set_login_presence(account_name, value);
cons_show("Updated login status for account %s: %s", account_name, value);
}
cons_show("");
} else if (strcmp(property, "pgpkeyid") == 0) {
#ifdef 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);
} else {
accounts_set_pgp_keyid(account_name, value);
cons_show("Updated PGP key ID for account %s: %s", account_name, value);
}
free(err_str);
#else
cons_show("PGP support is not included in this build.");
#endif
cons_show("");
} else if (strcmp(property, "startscript") == 0) {
accounts_set_script_start(account_name, value);
cons_show("Updated start script for account %s: %s", account_name, value);
} else if (strcmp(property, "theme") == 0) {
if (theme_exists(value)) {
accounts_set_theme(account_name, value);
if (jabber_get_connection_status() == JABBER_CONNECTED) {
ProfAccount *account = accounts_get_account(jabber_get_account_name());
if (account) {
if (g_strcmp0(account->name, account_name) == 0) {
theme_load(value);
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
} else {
ui_hide_roster();
}
if (prefs_get_boolean(PREF_OCCUPANTS)) {
ui_show_all_room_rosters();
} else {
ui_hide_all_room_rosters();
}
ui_redraw();
}
account_free(account);
}
}
cons_show("Updated theme for account %s: %s", account_name, value);
} else {
cons_show("Theme does not exist: %s", value);
}
} else if (strcmp(property, "tls") == 0) {
if ((g_strcmp0(value, "force") != 0)
&& (g_strcmp0(value, "allow") != 0)
&& (g_strcmp0(value, "disable") != 0)) {
cons_show("TLS policy must be one of: force, allow or disable.");
} else {
accounts_set_tls_policy(account_name, value);
cons_show("Updated TLS policy for account %s: %s", account_name, value);
cons_show("");
}
} else if (valid_resource_presence_string(property)) {
int intval;
char *err_msg = NULL;
gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg);
if (res) {
resource_presence_t presence_type = resource_presence_from_string(property);
switch (presence_type)
{
case (RESOURCE_ONLINE):
accounts_set_priority_online(account_name, intval);
break;
case (RESOURCE_CHAT):
accounts_set_priority_chat(account_name, intval);
break;
case (RESOURCE_AWAY):
accounts_set_priority_away(account_name, intval);
break;
case (RESOURCE_XA):
accounts_set_priority_xa(account_name, intval);
break;
case (RESOURCE_DND):
accounts_set_priority_dnd(account_name, intval);
break;
}
jabber_conn_status_t conn_status = jabber_get_connection_status(); if (valid_resource_presence_string(property)) {
if (conn_status == JABBER_CONNECTED) { return _account_set_presence_priority(account_name, property, value);
char *connected_account = jabber_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
if (presence_type == last_presence) {
char *message = jabber_get_presence_message();
cl_ev_presence_send(last_presence, message, 0);
}
}
cons_show("Updated %s priority for account %s: %s", property, account_name, value);
cons_show("");
} else {
cons_show(err_msg);
free(err_msg);
}
} else {
cons_show("Invalid property: %s", property);
cons_show("");
} }
cons_show("Invalid property: %s", property);
cons_show("");
return TRUE; return TRUE;
} }

View File

@ -138,7 +138,7 @@ cb_write_fingerprints(void *opdata)
GString *fpsfilename = g_string_new(basedir->str); GString *fpsfilename = g_string_new(basedir->str);
g_string_append(fpsfilename, "fingerprints.txt"); g_string_append(fpsfilename, "fingerprints.txt");
err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
log_error("Failed to write fingerprints file"); log_error("Failed to write fingerprints file");
cons_show_error("Failed to create fingerprints file"); cons_show_error("Failed to create fingerprints file");
} }
@ -243,7 +243,7 @@ otr_on_connect(ProfAccount *account)
} else { } else {
log_info("Loading OTR private key %s", keysfilename->str); log_info("Loading OTR private key %s", keysfilename->str);
err = otrl_privkey_read(user_state, keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
log_warning("Failed to read OTR private key file: %s", keysfilename->str); log_warning("Failed to read OTR private key file: %s", keysfilename->str);
cons_show_error("Failed to read OTR private key file: %s", keysfilename->str); cons_show_error("Failed to read OTR private key file: %s", keysfilename->str);
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
@ -271,7 +271,7 @@ otr_on_connect(ProfAccount *account)
} else { } else {
log_info("Loading OTR fingerprints %s", fpsfilename->str); log_info("Loading OTR fingerprints %s", fpsfilename->str);
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str); log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str);
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
g_string_free(keysfilename, TRUE); g_string_free(keysfilename, TRUE);
@ -415,7 +415,7 @@ otr_keygen(ProfAccount *account)
cons_show("Moving the mouse randomly around the screen may speed up the process!"); cons_show("Moving the mouse randomly around the screen may speed up the process!");
ui_update(); ui_update();
err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp"); err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp");
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
g_string_free(keysfilename, TRUE); g_string_free(keysfilename, TRUE);
log_error("Failed to generate private key"); log_error("Failed to generate private key");
@ -430,7 +430,7 @@ otr_keygen(ProfAccount *account)
g_string_append(fpsfilename, "fingerprints.txt"); g_string_append(fpsfilename, "fingerprints.txt");
log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid); log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid);
err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
g_string_free(keysfilename, TRUE); g_string_free(keysfilename, TRUE);
log_error("Failed to create fingerprints file"); log_error("Failed to create fingerprints file");
@ -440,7 +440,7 @@ otr_keygen(ProfAccount *account)
log_info("Fingerprints file created"); log_info("Fingerprints file created");
err = otrl_privkey_read(user_state, keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
g_string_free(keysfilename, TRUE); g_string_free(keysfilename, TRUE);
log_error("Failed to load private key"); log_error("Failed to load private key");
@ -449,7 +449,7 @@ otr_keygen(ProfAccount *account)
} }
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
if (!err == GPG_ERR_NO_ERROR) { if (err != GPG_ERR_NO_ERROR) {
g_string_free(basedir, TRUE); g_string_free(basedir, TRUE);
g_string_free(keysfilename, TRUE); g_string_free(keysfilename, TRUE);
log_error("Failed to load fingerprints"); log_error("Failed to load fingerprints");

View File

@ -40,10 +40,12 @@
#include "log.h" #include "log.h"
#include "event/server_events.h" #include "event/server_events.h"
#include "event/client_events.h"
#include "plugins/callbacks.h" #include "plugins/callbacks.h"
#include "plugins/autocompleters.h" #include "plugins/autocompleters.h"
#include "plugins/themes.h" #include "plugins/themes.h"
#include "plugins/settings.h" #include "plugins/settings.h"
#include "plugins/disco.h"
#include "profanity.h" #include "profanity.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "config/theme.h" #include "config/theme.h"
@ -426,3 +428,21 @@ api_incoming_message(const char *const barejid, const char *const resource, cons
// TODO handle all states // TODO handle all states
sv_ev_activity((char*)barejid, (char*)resource, FALSE); sv_ev_activity((char*)barejid, (char*)resource, FALSE);
} }
void
api_disco_add_feature(char *feature)
{
if (feature == NULL) {
return;
}
disco_add_feature(feature);
caps_reset_ver();
// resend presence to update server's disco info data for this client
if (jabber_get_connection_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name());
cl_ev_presence_send(last_presence, jabber_get_presence_message(), 0);
}
}

View File

@ -86,4 +86,6 @@ void api_settings_set_int(const char *const group, const char *const key, int va
void api_incoming_message(const char *const barejid, const char *const resource, const char *const message); void api_incoming_message(const char *const barejid, const char *const resource, const char *const message);
void api_disco_add_feature(char *feature);
#endif #endif

View File

@ -260,6 +260,12 @@ c_api_incoming_message(char *barejid, char *resource, char *message)
api_incoming_message(barejid, resource, message); api_incoming_message(barejid, resource, message);
} }
static void
c_api_disco_add_feature(char *feature)
{
api_disco_add_feature(feature);
}
void void
c_command_callback(PluginCommand *command, gchar **args) c_command_callback(PluginCommand *command, gchar **args)
{ {
@ -320,4 +326,5 @@ c_api_init(void)
prof_settings_get_int = c_api_settings_get_int; prof_settings_get_int = c_api_settings_get_int;
prof_settings_set_int = c_api_settings_set_int; prof_settings_set_int = c_api_settings_set_int;
prof_incoming_message = c_api_incoming_message; prof_incoming_message = c_api_incoming_message;
prof_disco_add_feature = c_api_disco_add_feature;
} }

65
src/plugins/disco.c Normal file
View File

@ -0,0 +1,65 @@
/*
* disco.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.
*
*/
#include <string.h>
#include <stdlib.h>
#include <glib.h>
static GList *disco_features = NULL;
void
disco_add_feature(char* feature)
{
if (feature == NULL) {
return;
}
disco_features = g_list_append(disco_features, strdup(feature));
}
GList*
disco_get_features(void)
{
return disco_features;
}
void
disco_close(void)
{
if (disco_features) {
g_list_free_full(disco_features, free);
disco_features = NULL;
}
}

43
src/plugins/disco.h Normal file
View File

@ -0,0 +1,43 @@
/*
* disco.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 DISCO_H
#define DISCO_H
void disco_add_feature(char *feature);
GList* disco_get_features(void);
void disco_close(void);
#endif

View File

@ -45,6 +45,7 @@
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "plugins/themes.h" #include "plugins/themes.h"
#include "plugins/settings.h" #include "plugins/settings.h"
#include "plugins/disco.h"
#ifdef HAVE_PYTHON #ifdef HAVE_PYTHON
#include "plugins/python_plugins.h" #include "plugins/python_plugins.h"
@ -665,6 +666,12 @@ plugins_on_room_win_focus(const char *const roomjid)
} }
} }
GList*
plugins_get_disco_features(void)
{
return disco_get_features();
}
void void
plugins_shutdown(void) plugins_shutdown(void)
{ {
@ -695,6 +702,7 @@ plugins_shutdown(void)
plugin_themes_close(); plugin_themes_close();
plugin_settings_close(); plugin_settings_close();
callbacks_close(); callbacks_close();
disco_close();
} }
gchar * gchar *

View File

@ -153,4 +153,6 @@ GList* plugins_get_command_names(void);
gchar * plugins_get_dir(void); gchar * plugins_get_dir(void);
CommandHelp* plugins_get_help(const char *const cmd); CommandHelp* plugins_get_help(const char *const cmd);
GList* plugins_get_disco_features(void);
#endif #endif

View File

@ -83,3 +83,5 @@ int (*prof_settings_get_int)(char *group, char *key, int def) = NULL;
void (*prof_settings_set_int)(char *group, char *key, int value) = NULL; void (*prof_settings_set_int)(char *group, char *key, int value) = NULL;
void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL; void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;
void (*prof_disco_add_feature)(char *feature) = NULL;

View File

@ -84,4 +84,6 @@ void (*prof_settings_set_int)(char *group, char *key, int value);
void (*prof_incoming_message)(char *barejid, char *resource, char *message); void (*prof_incoming_message)(char *barejid, char *resource, char *message);
void (*prof_disco_add_feature)(char *feature);
#endif #endif

View File

@ -665,6 +665,21 @@ python_api_incoming_message(PyObject *self, PyObject *args)
return Py_BuildValue(""); return Py_BuildValue("");
} }
static PyObject*
python_api_disco_add_feature(PyObject *self, PyObject *args)
{
char *feature = NULL;
if (!PyArg_ParseTuple(args, "s", &feature)) {
return Py_BuildValue("");
}
allow_python_threads();
api_disco_add_feature(feature);
disable_python_threads();
return Py_BuildValue("");
}
void void
python_command_callback(PluginCommand *command, gchar **args) python_command_callback(PluginCommand *command, gchar **args)
{ {
@ -766,6 +781,7 @@ static PyMethodDef apiMethods[] = {
{ "settings_get_int", python_api_settings_get_int, METH_VARARGS, "Get a integer setting." }, { "settings_get_int", python_api_settings_get_int, METH_VARARGS, "Get a integer setting." },
{ "settings_set_int", python_api_settings_set_int, METH_VARARGS, "Set a integer setting." }, { "settings_set_int", python_api_settings_set_int, METH_VARARGS, "Set a integer setting." },
{ "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." }, { "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." },
{ "disco_add_feature", python_api_disco_add_feature, METH_VARARGS, "Add a feature to disco info response." },
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };

View File

@ -57,6 +57,7 @@
#include "xmpp/stanza.h" #include "xmpp/stanza.h"
#include "xmpp/form.h" #include "xmpp/form.h"
#include "xmpp/capabilities.h" #include "xmpp/capabilities.h"
#include "plugins/plugins.h"
static gchar *cache_loc; static gchar *cache_loc;
static GKeyFile *cache; static GKeyFile *cache;
@ -552,6 +553,15 @@ caps_get_my_sha1(xmpp_ctx_t *const ctx)
return my_sha1; return my_sha1;
} }
void
caps_reset_ver(void)
{
if (my_sha1) {
g_free(my_sha1);
my_sha1 = NULL;
}
}
xmpp_stanza_t* xmpp_stanza_t*
caps_create_query_response_stanza(xmpp_ctx_t *const ctx) caps_create_query_response_stanza(xmpp_ctx_t *const ctx)
{ {
@ -632,6 +642,18 @@ caps_create_query_response_stanza(xmpp_ctx_t *const ctx)
xmpp_stanza_add_child(query, feature_ping); xmpp_stanza_add_child(query, feature_ping);
xmpp_stanza_add_child(query, feature_receipts); xmpp_stanza_add_child(query, feature_receipts);
GList *plugin_features = plugins_get_disco_features();
GList *curr = plugin_features;
while (curr) {
xmpp_stanza_t *feature = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(feature, STANZA_NAME_FEATURE);
xmpp_stanza_set_attribute(feature, STANZA_ATTR_VAR, curr->data);
xmpp_stanza_add_child(query, feature);
xmpp_stanza_release(feature);
curr = g_list_next(curr);
}
xmpp_stanza_release(feature_receipts); xmpp_stanza_release(feature_receipts);
xmpp_stanza_release(feature_ping); xmpp_stanza_release(feature_ping);
xmpp_stanza_release(feature_conference); xmpp_stanza_release(feature_conference);

View File

@ -190,6 +190,7 @@ void iq_http_upload_request(HTTPUpload *upload);
Capabilities* caps_lookup(const char *const jid); Capabilities* caps_lookup(const char *const jid);
void caps_close(void); void caps_close(void);
void caps_destroy(Capabilities *caps); void caps_destroy(Capabilities *caps);
void caps_reset_ver(void);
gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str); gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str);
gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str); gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str);

View File

@ -398,7 +398,7 @@ void cmd_account_set_resource_sets_resource_with_online_message(void **state)
expect_string(accounts_set_resource, account_name, "a_account"); expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource"); expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource, you will need to reconnect to pick up the change."); expect_cons_show("Updated resource for account a_account: a_resource, reconnect to pick up the change.");
expect_cons_show(""); expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args); gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);

View File

@ -190,6 +190,7 @@ Capabilities* caps_lookup(const char * const jid)
void caps_close(void) {} void caps_close(void) {}
void caps_destroy(Capabilities *caps) {} void caps_destroy(Capabilities *caps) {}
void caps_reset_ver(void) {}
gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str) gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str)
{ {